mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
video: Add a destroy notify parameter to gst_video_convert_frame_async()
Binding generators apparently need this as they can't really know that the callback is guaranteed to be called exactly once and that the user_data can be freed at the end of it.
This commit is contained in:
parent
129af0d8e6
commit
7ac1938f0f
3 changed files with 19 additions and 4 deletions
|
@ -369,6 +369,7 @@ typedef struct
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
GstVideoConvertFrameCallback callback;
|
GstVideoConvertFrameCallback callback;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
|
GDestroyNotify destroy_notify;
|
||||||
GMainContext *context;
|
GMainContext *context;
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
gulong timeout_id;
|
gulong timeout_id;
|
||||||
|
@ -381,6 +382,7 @@ typedef struct
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
GError *error;
|
GError *error;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
|
GDestroyNotify destroy_notify;
|
||||||
|
|
||||||
GstVideoConvertFrameContext *context;
|
GstVideoConvertFrameContext *context;
|
||||||
} GstVideoConvertFrameCallbackContext;
|
} GstVideoConvertFrameCallbackContext;
|
||||||
|
@ -418,6 +420,9 @@ convert_frame_dispatch_callback (GstVideoConvertFrameCallbackContext * ctx)
|
||||||
{
|
{
|
||||||
ctx->callback (ctx->buffer, ctx->error, ctx->user_data);
|
ctx->callback (ctx->buffer, ctx->error, ctx->user_data);
|
||||||
|
|
||||||
|
if (ctx->destroy_notify)
|
||||||
|
ctx->destroy_notify (ctx->user_data);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,6 +440,7 @@ convert_frame_finish (GstVideoConvertFrameContext * context, GstBuffer * buffer,
|
||||||
ctx = g_slice_new (GstVideoConvertFrameCallbackContext);
|
ctx = g_slice_new (GstVideoConvertFrameCallbackContext);
|
||||||
ctx->callback = context->callback;
|
ctx->callback = context->callback;
|
||||||
ctx->user_data = context->user_data;
|
ctx->user_data = context->user_data;
|
||||||
|
ctx->destroy_notify = context->destroy_notify;
|
||||||
ctx->buffer = buffer;
|
ctx->buffer = buffer;
|
||||||
ctx->error = error;
|
ctx->error = error;
|
||||||
ctx->context = context;
|
ctx->context = context;
|
||||||
|
@ -571,6 +577,7 @@ done:
|
||||||
* @to_caps: the #GstCaps to convert to
|
* @to_caps: the #GstCaps to convert to
|
||||||
* @timeout: the maximum amount of time allowed for the processing.
|
* @timeout: the maximum amount of time allowed for the processing.
|
||||||
* @callback: %GstVideoConvertFrameCallback that will be called after conversion.
|
* @callback: %GstVideoConvertFrameCallback that will be called after conversion.
|
||||||
|
* @destroy_notify: %GDestroyNotify to be called after @user_data is not needed anymore
|
||||||
*
|
*
|
||||||
* Converts a raw video buffer into the specified output caps.
|
* Converts a raw video buffer into the specified output caps.
|
||||||
*
|
*
|
||||||
|
@ -583,13 +590,16 @@ done:
|
||||||
* %GMainContext, see g_main_context_get_thread_default(). If GLib before 2.22 is used,
|
* %GMainContext, see g_main_context_get_thread_default(). If GLib before 2.22 is used,
|
||||||
* this will always be the global default main context.
|
* this will always be the global default main context.
|
||||||
*
|
*
|
||||||
|
* @destroy_notify will be called after the callback was called and @user_data is not needed
|
||||||
|
* anymore.
|
||||||
|
*
|
||||||
* Since: 0.10.31
|
* Since: 0.10.31
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gst_video_convert_frame_async (GstBuffer * buf, const GstCaps * to_caps,
|
gst_video_convert_frame_async (GstBuffer * buf, const GstCaps * to_caps,
|
||||||
GstClockTime timeout, GstVideoConvertFrameCallback callback,
|
GstClockTime timeout, GstVideoConvertFrameCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data, GDestroyNotify destroy_notify)
|
||||||
{
|
{
|
||||||
GMainContext *context = NULL;
|
GMainContext *context = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -603,6 +613,7 @@ gst_video_convert_frame_async (GstBuffer * buf, const GstCaps * to_caps,
|
||||||
g_return_if_fail (buf != NULL);
|
g_return_if_fail (buf != NULL);
|
||||||
g_return_if_fail (to_caps != NULL);
|
g_return_if_fail (to_caps != NULL);
|
||||||
g_return_if_fail (GST_BUFFER_CAPS (buf) != NULL);
|
g_return_if_fail (GST_BUFFER_CAPS (buf) != NULL);
|
||||||
|
g_return_if_fail (callback != NULL);
|
||||||
|
|
||||||
#if GLIB_CHECK_VERSION(2,22,0)
|
#if GLIB_CHECK_VERSION(2,22,0)
|
||||||
context = g_main_context_get_thread_default ();
|
context = g_main_context_get_thread_default ();
|
||||||
|
@ -635,6 +646,7 @@ gst_video_convert_frame_async (GstBuffer * buf, const GstCaps * to_caps,
|
||||||
ctx->buffer = gst_buffer_ref (buf);
|
ctx->buffer = gst_buffer_ref (buf);
|
||||||
ctx->callback = callback;
|
ctx->callback = callback;
|
||||||
ctx->user_data = user_data;
|
ctx->user_data = user_data;
|
||||||
|
ctx->destroy_notify = destroy_notify;
|
||||||
ctx->context = g_main_context_ref (context);
|
ctx->context = g_main_context_ref (context);
|
||||||
ctx->finished = FALSE;
|
ctx->finished = FALSE;
|
||||||
ctx->pipeline = pipeline;
|
ctx->pipeline = pipeline;
|
||||||
|
@ -675,6 +687,7 @@ no_pipeline:
|
||||||
ctx = g_slice_new0 (GstVideoConvertFrameCallbackContext);
|
ctx = g_slice_new0 (GstVideoConvertFrameCallbackContext);
|
||||||
ctx->callback = callback;
|
ctx->callback = callback;
|
||||||
ctx->user_data = user_data;
|
ctx->user_data = user_data;
|
||||||
|
ctx->destroy_notify = destroy_notify;
|
||||||
ctx->buffer = NULL;
|
ctx->buffer = NULL;
|
||||||
ctx->error = error;
|
ctx->error = error;
|
||||||
|
|
||||||
|
|
|
@ -421,7 +421,7 @@ GstBuffer *gst_video_convert_frame(GstBuffer *buf, const GstCaps *to_caps,
|
||||||
typedef void (*GstVideoConvertFrameCallback) (GstBuffer *buf, GError *error, gpointer user_data);
|
typedef void (*GstVideoConvertFrameCallback) (GstBuffer *buf, GError *error, gpointer user_data);
|
||||||
void gst_video_convert_frame_async(GstBuffer *buf, const GstCaps *to_caps,
|
void gst_video_convert_frame_async(GstBuffer *buf, const GstCaps *to_caps,
|
||||||
GstClockTime timeout, GstVideoConvertFrameCallback callback,
|
GstClockTime timeout, GstVideoConvertFrameCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data, GDestroyNotify destroy_notify);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -680,7 +680,8 @@ GST_START_TEST (test_convert_frame_async)
|
||||||
loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
|
loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
gst_video_convert_frame_async (from_buffer, to_caps, GST_CLOCK_TIME_NONE,
|
gst_video_convert_frame_async (from_buffer, to_caps, GST_CLOCK_TIME_NONE,
|
||||||
(GstVideoConvertFrameCallback) convert_frame_async_callback, &cf_data);
|
(GstVideoConvertFrameCallback) convert_frame_async_callback, &cf_data,
|
||||||
|
NULL);
|
||||||
|
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
|
|
||||||
|
@ -693,7 +694,8 @@ GST_START_TEST (test_convert_frame_async)
|
||||||
to_caps =
|
to_caps =
|
||||||
gst_video_format_new_caps (GST_VIDEO_FORMAT_I420, 240, 320, 25, 1, 1, 2);
|
gst_video_format_new_caps (GST_VIDEO_FORMAT_I420, 240, 320, 25, 1, 1, 2);
|
||||||
gst_video_convert_frame_async (from_buffer, to_caps, GST_CLOCK_TIME_NONE,
|
gst_video_convert_frame_async (from_buffer, to_caps, GST_CLOCK_TIME_NONE,
|
||||||
(GstVideoConvertFrameCallback) convert_frame_async_callback, &cf_data);
|
(GstVideoConvertFrameCallback) convert_frame_async_callback, &cf_data,
|
||||||
|
NULL);
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
fail_unless (cf_data.buffer != NULL);
|
fail_unless (cf_data.buffer != NULL);
|
||||||
fail_unless (gst_caps_can_intersect (to_caps,
|
fail_unless (gst_caps_can_intersect (to_caps,
|
||||||
|
|
Loading…
Reference in a new issue