1 From 40a293d44d1aeccf5eb8e86f23a0b13666111c5c Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
3 Date: Fri, 12 Sep 2014 14:39:16 +0300
4 Subject: [PATCH 2/3] video-frame: Add GST_VIDEO_FRAME_MAP_FLAG_NO_REF
6 This makes sure that the buffer is not reffed another time when
7 storing it in the GstVideoFrame, keeping it writable if it was
10 Upstream-Status: Backport [1.5.1]
11 https://bugzilla.gnome.org/show_bug.cgi?id=736118
13 gst-libs/gst/video/video-frame.c | 9 ++++++++-
14 gst-libs/gst/video/video-frame.h | 18 ++++++++++++++++++
15 2 files changed, 26 insertions(+), 1 deletion(-)
17 diff --git a/gst-libs/gst/video/video-frame.c b/gst-libs/gst/video/video-frame.c
18 index 537cf70..01f23c0 100644
19 --- a/gst-libs/gst/video/video-frame.c
20 +++ b/gst-libs/gst/video/video-frame.c
21 @@ -106,6 +106,9 @@ gst_video_frame_map_id (GstVideoFrame * frame, GstVideoInfo * info,
24 frame->buffer = gst_buffer_ref (buffer);
25 + if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
26 + gst_buffer_ref (frame->buffer);
30 /* buffer flags enhance the frame flags */
31 @@ -189,11 +192,13 @@ gst_video_frame_unmap (GstVideoFrame * frame)
37 g_return_if_fail (frame != NULL);
39 buffer = frame->buffer;
41 + flags = frame->map[0].flags;
44 for (i = 0; i < frame->info.finfo->n_planes; i++) {
45 @@ -202,7 +207,9 @@ gst_video_frame_unmap (GstVideoFrame * frame)
47 gst_buffer_unmap (buffer, &frame->map[0]);
49 - gst_buffer_unref (buffer);
51 + if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
52 + gst_buffer_unref (frame->buffer);
56 diff --git a/gst-libs/gst/video/video-frame.h b/gst-libs/gst/video/video-frame.h
57 index 627fab0..f8e6304 100644
58 --- a/gst-libs/gst/video/video-frame.h
59 +++ b/gst-libs/gst/video/video-frame.h
60 @@ -149,6 +149,24 @@ typedef enum {
61 GST_VIDEO_BUFFER_FLAG_LAST = (GST_BUFFER_FLAG_LAST << 8)
62 } GstVideoBufferFlags;
65 + * GstVideoBufferFlags:
66 + * @GST_VIDEO_FRAME_MAP_FLAG_NO_REF: Don't take another reference of the buffer and store it in
67 + * the GstVideoFrame. This makes sure that the buffer stays
68 + * writable while the frame is mapped, but requires that the
69 + * buffer reference stays valid until the frame is unmapped again.
70 + * @GST_VIDEO_FRAME_MAP_FLAG_LAST: Offset to define more flags
72 + * Additional mapping flags for gst_video_frame_map().
77 + GST_VIDEO_FRAME_MAP_FLAG_NO_REF = (GST_MAP_FLAG_LAST << 0),
78 + GST_VIDEO_FRAME_MAP_FLAG_LAST = (GST_MAP_FLAG_LAST << 8)
79 + /* 8 more flags possible afterwards */
80 +} GstVideoFrameMapFlags;
84 #endif /* __GST_VIDEO_FRAME_H__ */