video-frame: Add GST_VIDEO_FRAME_MAP_FLAG_NO_REF

This makes sure that the buffer is not reffed another time when
storing it in the GstVideoFrame, keeping it writable if it was
writable.

https://bugzilla.gnome.org/show_bug.cgi?id=736118
This commit is contained in:
Sebastian Dröge 2014-09-12 14:39:16 +03:00
parent f711288c7c
commit 40a293d44d
2 changed files with 26 additions and 1 deletions

View file

@ -106,6 +106,9 @@ gst_video_frame_map_id (GstVideoFrame * frame, GstVideoInfo * info,
} }
} }
frame->buffer = gst_buffer_ref (buffer); frame->buffer = gst_buffer_ref (buffer);
if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
gst_buffer_ref (frame->buffer);
frame->meta = meta; frame->meta = meta;
/* buffer flags enhance the frame flags */ /* buffer flags enhance the frame flags */
@ -189,11 +192,13 @@ gst_video_frame_unmap (GstVideoFrame * frame)
GstBuffer *buffer; GstBuffer *buffer;
GstVideoMeta *meta; GstVideoMeta *meta;
gint i; gint i;
GstMapFlags flags;
g_return_if_fail (frame != NULL); g_return_if_fail (frame != NULL);
buffer = frame->buffer; buffer = frame->buffer;
meta = frame->meta; meta = frame->meta;
flags = frame->map[0].flags;
if (meta) { if (meta) {
for (i = 0; i < frame->info.finfo->n_planes; i++) { for (i = 0; i < frame->info.finfo->n_planes; i++) {
@ -202,7 +207,9 @@ gst_video_frame_unmap (GstVideoFrame * frame)
} else { } else {
gst_buffer_unmap (buffer, &frame->map[0]); gst_buffer_unmap (buffer, &frame->map[0]);
} }
gst_buffer_unref (buffer);
if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
gst_buffer_unref (frame->buffer);
} }
/** /**

View file

@ -149,6 +149,24 @@ typedef enum {
GST_VIDEO_BUFFER_FLAG_LAST = (GST_BUFFER_FLAG_LAST << 8) GST_VIDEO_BUFFER_FLAG_LAST = (GST_BUFFER_FLAG_LAST << 8)
} GstVideoBufferFlags; } GstVideoBufferFlags;
/**
* GstVideoBufferFlags:
* @GST_VIDEO_FRAME_MAP_FLAG_NO_REF: Don't take another reference of the buffer and store it in
* the GstVideoFrame. This makes sure that the buffer stays
* writable while the frame is mapped, but requires that the
* buffer reference stays valid until the frame is unmapped again.
* @GST_VIDEO_FRAME_MAP_FLAG_LAST: Offset to define more flags
*
* Additional mapping flags for gst_video_frame_map().
*
* Since: 1.6
*/
typedef enum {
GST_VIDEO_FRAME_MAP_FLAG_NO_REF = (GST_MAP_FLAG_LAST << 0),
GST_VIDEO_FRAME_MAP_FLAG_LAST = (GST_MAP_FLAG_LAST << 8)
/* 8 more flags possible afterwards */
} GstVideoFrameMapFlags;
G_END_DECLS G_END_DECLS
#endif /* __GST_VIDEO_FRAME_H__ */ #endif /* __GST_VIDEO_FRAME_H__ */