Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more Buffer and Memory Fixes #7

Merged
merged 2 commits into from
Dec 31, 2020
Merged

Some more Buffer and Memory Fixes #7

merged 2 commits into from
Dec 31, 2020

Conversation

tinyzimmer
Copy link
Owner

  • Fixes Buffer.FillBytes to work on Windows as well with the same fixes from NewBufferFromBytes
  • Make calling Map on a Memory or Buffer safe to do multiple times (while still only requiring a single Unmap)

@tinyzimmer
Copy link
Owner Author

@vshashi01 I think this should suffice


// FillInt8Slice adds the given slice to the buffer at the given offset. The return value reflects the amount
// of data added to the buffer.
func (b *Buffer) FillInt8Slice(offset int64, data []int8) int64 {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of these as I am not sure if they were implemented correctly and I feel like most users would be working with []byte sequences anyway. May consider reimplementing in the future.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed I think keep just the FillBytes is good enough.

@vshashi01
Copy link

Another thing that I just thought of is as soon as the MapInfo is created, at the moment there is no way to check if its read only or writable as well. Do you think this should be available with the API as well. Though I think for small programs this is hardly ever a problem. The rest of it looks good.

@tinyzimmer
Copy link
Owner Author

tinyzimmer commented Dec 31, 2020

Well to be clear the user has to specify how they are mapping the data the first time. That being said, I can see what you mean if the user maps once read, and then goes again to map write. It's probably worth at the very least adding documentation saying that if you call it twice, the memory will remain mapped with the access provided the first time, at least until you Unmap and Map again.

I think these are edge cases, because how much processing would you really be doing in the context of a single buffer? In my head, most of the time you'd create your data, shove it in there and let gstreamer take over. Or on the receiving end, you'd just pull the buffer into go memory with Bytes() and work from there.

EDIT: I guess I'll add that the mode on the memory is accessible with something like...

mapInfo := buffer.Map(gst.MapWrite | gst.MapRead)
if mapInfo.Flags()&gst.MapWrite != 0 {
    fmt.Println("Map has write access")
}
if mapInfo.Flags()&gst.MapRead != 0 {
    fmt.Println("Map has read access")
}

If this is what you meant by exposing an API for determining how the memory is mapped.

@tinyzimmer tinyzimmer merged commit f1dec81 into main Dec 31, 2020
@tinyzimmer tinyzimmer deleted the mapinfo-fixes branch December 31, 2020 08:00
@vshashi01
Copy link

Yes this is good enough...

danjenkins referenced this pull request in everycastlabs/go-gst Aug 23, 2023
add the ability to unlink and unlink many elems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants