From 97ee4410e97a45a7f3c29ad117599a38e07e4dc2 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Wed, 16 Jan 2013 05:11:53 +0100 Subject: [PATCH] Add "thread-types" property. Allows selection of threaded decode method (slice / frame threading), defaults to slice threading only, as in the past. Slice threading seems to be a safe default choice, but it is unsupported or ineffective on some codecs, e.g., ffdec_h264 does not seem to support slice threading at all. Frame threading allows for high multi-threading performance, e.g., ffdec_h264, but is not always safe for all video formats or applications, e.g., due to introducing extra latency. This property allows high-performance apps to opt-in to frame threading. --- ext/ffmpeg/gstffmpegdec.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-) diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c index 159c8f0..3d7178f 100644 --- a/ext/ffmpeg/gstffmpegdec.c +++ b/ext/ffmpeg/gstffmpegdec.c @@ -122,6 +122,7 @@ struct _GstFFMpegDec gboolean debug_mv; gboolean crop; int max_threads; + guint thread_types; /* QoS stuff *//* with LOCK */ gdouble proportion; @@ -198,6 +199,7 @@ gst_ts_info_get (GstFFMpegDec * dec, gint idx) #define DEFAULT_DEBUG_MV FALSE #define DEFAULT_CROP TRUE #define DEFAULT_MAX_THREADS 1 +#define DEFAULT_THREAD_TYPES FF_THREAD_SLICE enum { @@ -209,6 +211,7 @@ enum PROP_DEBUG_MV, PROP_CROP, PROP_MAX_THREADS, + PROP_THREAD_TYPES, PROP_LAST }; @@ -291,6 +294,27 @@ gst_ffmpegdec_skipframe_get_type (void) return ffmpegdec_skipframe_type; } +#define GST_FFMPEGDEC_TYPE_THREAD_TYPES (gst_ffmpegdec_thread_types_get_type()) +static GType +gst_ffmpegdec_thread_types_get_type (void) +{ + static GType ffmpegdec_thread_types_type = 0; + + if (!ffmpegdec_thread_types_type) { + static const GFlagsValue ffmpegdec_thread_types[] = { + {FF_THREAD_FRAME, "Frame", "frame"}, + {FF_THREAD_SLICE, "Slice", "slice"}, + {0, NULL, NULL}, + }; + + ffmpegdec_thread_types_type = + g_flags_register_static ("GstFFMpegDecThreadTypes", + ffmpegdec_thread_types); + } + + return ffmpegdec_thread_types_type; +} + static void gst_ffmpegdec_base_init (GstFFMpegDecClass * klass) { @@ -400,6 +424,13 @@ gst_ffmpegdec_class_init (GstFFMpegDecClass * klass) "Maximum number of worker threads to spawn. (0 = auto)", 0, G_MAXINT, DEFAULT_MAX_THREADS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + PROP_THREAD_TYPES, + g_param_spec_flags ("thread-types", + "Thread Types", + "Which threaded decoding methods are allowed", + GST_FFMPEGDEC_TYPE_THREAD_TYPES, DEFAULT_THREAD_TYPES, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } } @@ -445,6 +476,7 @@ gst_ffmpegdec_init (GstFFMpegDec * ffmpegdec) ffmpegdec->debug_mv = DEFAULT_DEBUG_MV; ffmpegdec->crop = DEFAULT_CROP; ffmpegdec->max_threads = DEFAULT_MAX_THREADS; + ffmpegdec->thread_types = DEFAULT_THREAD_TYPES; ffmpegdec->format.video.par_n = -1; ffmpegdec->format.video.fps_n = -1; @@ -892,7 +924,7 @@ gst_ffmpegdec_setcaps (GstPad * pad, GstCaps * caps) } else ffmpegdec->context->thread_count = ffmpegdec->max_threads; - ffmpegdec->context->thread_type = FF_THREAD_SLICE; + ffmpegdec->context->thread_type = ffmpegdec->thread_types; /* open codec - we don't select an output pix_fmt yet, * simply because we don't know! We only get it @@ -2887,6 +2919,9 @@ gst_ffmpegdec_set_property (GObject * object, case PROP_MAX_THREADS: ffmpegdec->max_threads = g_value_get_int (value); break; + case PROP_THREAD_TYPES: + ffmpegdec->thread_types = g_value_get_flags (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2921,6 +2956,9 @@ gst_ffmpegdec_get_property (GObject * object, case PROP_MAX_THREADS: g_value_set_int (value, ffmpegdec->max_threads); break; + case PROP_THREAD_TYPES: + g_value_set_flags (value, ffmpegdec->thread_types); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; -- 1.7.7.5 (Apple Git-26)