mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-04 23:52:55 +08:00
Buffer and Memory Optimizations (#6)
* Fixes for memory leaks when creating or mapping the contents of a buffer * Unmap methods on Buffer and Memory objects for required use after utilizing their Map methods * Optimize MapInfo.WriteData to use memcpy * Re-implement BufferFromBytes using GBytes and `gst_buffer_new_wrapped_bytes` instead of `gst_buffer_new_wrapped`.
This commit is contained in:
@@ -71,11 +71,11 @@ func createPipeline() (*gst.Pipeline, error) {
|
||||
fmt.Println("Producing frame:", i)
|
||||
|
||||
// Create a buffer that can hold exactly one video RGBA frame.
|
||||
buf := gst.NewBufferWithSize(videoInfo.Size())
|
||||
buffer := gst.NewBufferWithSize(videoInfo.Size())
|
||||
|
||||
// For each frame we produce, we set the timestamp when it should be displayed
|
||||
// The autovideosink will use this information to display the frame at the right time.
|
||||
buf.SetPresentationTimestamp(time.Duration(i) * 500 * time.Millisecond)
|
||||
buffer.SetPresentationTimestamp(time.Duration(i) * 500 * time.Millisecond)
|
||||
|
||||
// Produce an image frame for this iteration.
|
||||
pixels := produceImageFrame(palette[i])
|
||||
@@ -87,10 +87,11 @@ func createPipeline() (*gst.Pipeline, error) {
|
||||
//
|
||||
// There are convenience wrappers for building buffers directly from byte sequences as
|
||||
// well.
|
||||
buf.Map(gst.MapWrite).WriteData(pixels)
|
||||
buffer.Map(gst.MapWrite).WriteData(pixels)
|
||||
defer buffer.Unmap()
|
||||
|
||||
// Push the buffer onto the pipeline.
|
||||
self.PushBuffer(buf)
|
||||
self.PushBuffer(buffer)
|
||||
|
||||
i++
|
||||
},
|
||||
|
Reference in New Issue
Block a user