mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 14:08:56 +00:00
GstVideoFrame: Add g_auto() support
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2412>
This commit is contained in:
parent
8bf778bb1f
commit
18aa649f87
3 changed files with 47 additions and 0 deletions
|
@ -266,6 +266,12 @@ gst_video_frame_unmap (GstVideoFrame * frame)
|
||||||
meta = frame->meta;
|
meta = frame->meta;
|
||||||
flags = frame->map[0].flags;
|
flags = frame->map[0].flags;
|
||||||
|
|
||||||
|
/* Allow to unmap even if not mapped, to work nicely with
|
||||||
|
* g_auto (GstVideoFrame) frame = GST_VIDEO_FRAME_INIT;
|
||||||
|
* This is also more consistent with gst_buffer_unmap() */
|
||||||
|
if (G_UNLIKELY (buffer == NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
if (meta) {
|
if (meta) {
|
||||||
for (i = 0; i < frame->info.finfo->n_planes; i++) {
|
for (i = 0; i < frame->info.finfo->n_planes; i++) {
|
||||||
gst_video_meta_unmap (meta, i, &frame->map[i]);
|
gst_video_meta_unmap (meta, i, &frame->map[i]);
|
||||||
|
|
|
@ -93,6 +93,16 @@ struct _GstVideoFrame {
|
||||||
gpointer _gst_reserved[GST_PADDING];
|
gpointer _gst_reserved[GST_PADDING];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_VIDEO_FRAME_INIT:
|
||||||
|
*
|
||||||
|
* Initializer for #GstVideoFrame
|
||||||
|
*
|
||||||
|
* Since: 1.22
|
||||||
|
*/
|
||||||
|
#define GST_VIDEO_FRAME_INIT { { NULL, }, }
|
||||||
|
|
||||||
|
|
||||||
GST_VIDEO_API
|
GST_VIDEO_API
|
||||||
gboolean gst_video_frame_map (GstVideoFrame *frame, const GstVideoInfo *info,
|
gboolean gst_video_frame_map (GstVideoFrame *frame, const GstVideoInfo *info,
|
||||||
GstBuffer *buffer, GstMapFlags flags);
|
GstBuffer *buffer, GstMapFlags flags);
|
||||||
|
@ -249,6 +259,8 @@ typedef enum {
|
||||||
/* 8 more flags possible afterwards */
|
/* 8 more flags possible afterwards */
|
||||||
} GstVideoFrameMapFlags;
|
} GstVideoFrameMapFlags;
|
||||||
|
|
||||||
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GstVideoFrame, gst_video_frame_unmap)
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_VIDEO_FRAME_H__ */
|
#endif /* __GST_VIDEO_FRAME_H__ */
|
||||||
|
|
|
@ -4042,6 +4042,34 @@ GST_START_TEST (test_video_extrapolate_stride)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_auto_video_frame_unmap)
|
||||||
|
{
|
||||||
|
#ifdef g_auto
|
||||||
|
g_autoptr (GstBuffer) buf = NULL;
|
||||||
|
GstVideoInfo info;
|
||||||
|
|
||||||
|
fail_unless (gst_video_info_set_format (&info, GST_VIDEO_FORMAT_ENCODED, 10,
|
||||||
|
10));
|
||||||
|
buf = gst_buffer_new_and_alloc (info.size);
|
||||||
|
|
||||||
|
{
|
||||||
|
// unmap should be no-op
|
||||||
|
g_auto (GstVideoFrame) frame = GST_VIDEO_FRAME_INIT;
|
||||||
|
fail_unless (frame.buffer == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
g_auto (GstVideoFrame) frame = GST_VIDEO_FRAME_INIT;
|
||||||
|
gst_video_frame_map (&frame, &info, buf, GST_MAP_READ);
|
||||||
|
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (buf), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (buf), 1);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
video_suite (void)
|
video_suite (void)
|
||||||
|
@ -4098,6 +4126,7 @@ video_suite (void)
|
||||||
tcase_add_test (tc_chain, test_video_flags);
|
tcase_add_test (tc_chain, test_video_flags);
|
||||||
tcase_add_test (tc_chain, test_video_make_raw_caps);
|
tcase_add_test (tc_chain, test_video_make_raw_caps);
|
||||||
tcase_add_test (tc_chain, test_video_extrapolate_stride);
|
tcase_add_test (tc_chain, test_video_extrapolate_stride);
|
||||||
|
tcase_add_test (tc_chain, test_auto_video_frame_unmap);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue