From 0826fb95b7b6b9019f0dc18a769a88d71487ce4b Mon Sep 17 00:00:00 2001 From: Havard Graff Date: Fri, 14 Jun 2019 10:14:23 +0200 Subject: [PATCH] audio: video: Optimize by using cached quark for meta tag Avoid taking the global quark lock for every single buffer. Part-of: --- gst-libs/gst/audio/gstaudiodecoder.c | 9 +++++++-- gst-libs/gst/audio/gstaudioencoder.c | 9 +++++++-- gst-libs/gst/audio/gstaudiofilter.c | 9 +++++++-- gst-libs/gst/rtp/gstrtpbaseaudiopayload.c | 9 +++++++-- gst-libs/gst/video/gstvideodecoder.c | 9 +++++++-- gst-libs/gst/video/gstvideoencoder.c | 9 +++++++-- gst-libs/gst/video/gstvideofilter.c | 9 +++++++-- gst/audioconvert/gstaudioconvert.c | 8 ++++++-- gst/audioresample/gstaudioresample.c | 9 +++++++-- 9 files changed, 62 insertions(+), 18 deletions(-) diff --git a/gst-libs/gst/audio/gstaudiodecoder.c b/gst-libs/gst/audio/gstaudiodecoder.c index cef4cbb..8f6e5ab 100644 --- a/gst-libs/gst/audio/gstaudiodecoder.c +++ b/gst-libs/gst/audio/gstaudiodecoder.c @@ -273,6 +273,10 @@ struct _GstAudioDecoderPrivate gboolean use_default_pad_acceptcaps; }; +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; + static void gst_audio_decoder_finalize (GObject * object); static void gst_audio_decoder_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -440,6 +444,8 @@ gst_audio_decoder_class_init (GstAudioDecoderClass * klass) GST_DEBUG_FUNCPTR (gst_audio_decoder_src_query_default); audiodecoder_class->transform_meta = GST_DEBUG_FUNCPTR (gst_audio_decoder_transform_meta_default); + + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); } static void @@ -1206,8 +1212,7 @@ gst_audio_decoder_transform_meta_default (GstAudioDecoder * tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO))) return TRUE; return FALSE; diff --git a/gst-libs/gst/audio/gstaudioencoder.c b/gst-libs/gst/audio/gstaudioencoder.c index 33f1a563..10c1b67 100644 --- a/gst-libs/gst/audio/gstaudioencoder.c +++ b/gst-libs/gst/audio/gstaudioencoder.c @@ -245,6 +245,10 @@ struct _GstAudioEncoderPrivate static GstElementClass *parent_class = NULL; static gint private_offset = 0; +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; + static void gst_audio_encoder_class_init (GstAudioEncoderClass * klass); static void gst_audio_encoder_init (GstAudioEncoder * parse, GstAudioEncoderClass * klass); @@ -391,6 +395,8 @@ gst_audio_encoder_class_init (GstAudioEncoderClass * klass) klass->decide_allocation = gst_audio_encoder_decide_allocation_default; klass->negotiate = gst_audio_encoder_negotiate_default; klass->transform_meta = gst_audio_encoder_transform_meta_default; + + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); } static void @@ -668,8 +674,7 @@ gst_audio_encoder_transform_meta_default (GstAudioEncoder * tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO))) return TRUE; return FALSE; diff --git a/gst-libs/gst/audio/gstaudiofilter.c b/gst-libs/gst/audio/gstaudiofilter.c index d13109a..6f12159 100644 --- a/gst-libs/gst/audio/gstaudiofilter.c +++ b/gst-libs/gst/audio/gstaudiofilter.c @@ -50,6 +50,10 @@ GST_DEBUG_CATEGORY_STATIC (audiofilter_dbg); #define GST_CAT_DEFAULT audiofilter_dbg +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; + static GstStateChangeReturn gst_audio_filter_change_state (GstElement * element, GstStateChange transition); static gboolean gst_audio_filter_set_caps (GstBaseTransform * btrans, @@ -76,8 +80,7 @@ gst_audio_filter_transform_meta (GstBaseTransform * trans, GstBuffer * inbuf, tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO))) return TRUE; return @@ -98,6 +101,8 @@ gst_audio_filter_class_init (GstAudioFilterClass * klass) GST_DEBUG_FUNCPTR (gst_audio_filter_get_unit_size); basetrans_class->transform_meta = gst_audio_filter_transform_meta; basetrans_class->submit_input_buffer = gst_audio_filter_submit_input_buffer; + + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); } static void diff --git a/gst-libs/gst/rtp/gstrtpbaseaudiopayload.c b/gst-libs/gst/rtp/gstrtpbaseaudiopayload.c index 433eece..23ed8b0 100644 --- a/gst-libs/gst/rtp/gstrtpbaseaudiopayload.c +++ b/gst-libs/gst/rtp/gstrtpbaseaudiopayload.c @@ -153,6 +153,10 @@ static GstStateChangeReturn gst_rtp_base_payload_audio_change_state (GstElement static gboolean gst_rtp_base_payload_audio_sink_event (GstRTPBasePayload * payload, GstEvent * event); +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; + #define gst_rtp_base_audio_payload_parent_class parent_class G_DEFINE_TYPE_WITH_PRIVATE (GstRTPBaseAudioPayload, gst_rtp_base_audio_payload, GST_TYPE_RTP_BASE_PAYLOAD); @@ -164,6 +168,8 @@ gst_rtp_base_audio_payload_class_init (GstRTPBaseAudioPayloadClass * klass) GstElementClass *gstelement_class; GstRTPBasePayloadClass *gstrtpbasepayload_class; + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); + gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass; @@ -488,8 +494,7 @@ foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data) const gchar *const *tags = gst_meta_api_type_get_tags (info->api); if (info->transform_func && (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR))))) { + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO)))) { GstMetaTransformCopy copy_data = { FALSE, 0, -1 }; GST_DEBUG_OBJECT (pay, "copy metadata %s", g_type_name (info->api)); /* simply copy then */ diff --git a/gst-libs/gst/video/gstvideodecoder.c b/gst-libs/gst/video/gstvideodecoder.c index 2610f56..300d181 100644 --- a/gst-libs/gst/video/gstvideodecoder.c +++ b/gst-libs/gst/video/gstvideodecoder.c @@ -426,6 +426,10 @@ struct _GstVideoDecoderPrivate static GstElementClass *parent_class = NULL; static gint private_offset = 0; +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_VIDEO meta_tag_video_quark +static GQuark meta_tag_video_quark; + static void gst_video_decoder_class_init (GstVideoDecoderClass * klass); static void gst_video_decoder_init (GstVideoDecoder * dec, GstVideoDecoderClass * klass); @@ -589,6 +593,8 @@ gst_video_decoder_class_init (GstVideoDecoderClass * klass) "Max consecutive decoder errors before returning flow error", -1, G_MAXINT, DEFAULT_MAX_ERRORS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + meta_tag_video_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_STR); } static void @@ -3030,8 +3036,7 @@ gst_video_decoder_transform_meta_default (GstVideoDecoder * tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_VIDEO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_VIDEO))) return TRUE; return FALSE; diff --git a/gst-libs/gst/video/gstvideoencoder.c b/gst-libs/gst/video/gstvideoencoder.c index ec386aa..a3b5549 100644 --- a/gst-libs/gst/video/gstvideoencoder.c +++ b/gst-libs/gst/video/gstvideoencoder.c @@ -236,6 +236,10 @@ forced_key_unit_event_compare (const ForcedKeyUnitEvent * a, static GstElementClass *parent_class = NULL; static gint private_offset = 0; +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_VIDEO meta_tag_video_quark +static GQuark meta_tag_video_quark; + static void gst_video_encoder_class_init (GstVideoEncoderClass * klass); static void gst_video_encoder_init (GstVideoEncoder * enc, GstVideoEncoderClass * klass); @@ -418,6 +422,8 @@ gst_video_encoder_class_init (GstVideoEncoderClass * klass) "Minimum interval between force-keyunit requests in nanoseconds", 0, G_MAXUINT64, DEFAULT_MIN_FORCE_KEY_UNIT_INTERVAL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + meta_tag_video_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_STR); } static GList * @@ -2137,8 +2143,7 @@ gst_video_encoder_transform_meta_default (GstVideoEncoder * tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_VIDEO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_VIDEO))) return TRUE; return FALSE; diff --git a/gst-libs/gst/video/gstvideofilter.c b/gst-libs/gst/video/gstvideofilter.c index 4d63eea..66a1887 100644 --- a/gst-libs/gst/video/gstvideofilter.c +++ b/gst-libs/gst/video/gstvideofilter.c @@ -47,6 +47,10 @@ GST_DEBUG_CATEGORY_STATIC (gst_video_filter_debug); G_DEFINE_ABSTRACT_TYPE (GstVideoFilter, gst_video_filter, GST_TYPE_BASE_TRANSFORM); +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_VIDEO meta_tag_video_quark +static GQuark meta_tag_video_quark; + /* Answer the allocation query downstream. */ static gboolean gst_video_filter_propose_allocation (GstBaseTransform * trans, @@ -353,8 +357,7 @@ gst_video_filter_transform_meta (GstBaseTransform * trans, GstBuffer * inbuf, tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_VIDEO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_VIDEO))) return TRUE; return GST_BASE_TRANSFORM_CLASS (parent_class)->transform_meta (trans, inbuf, @@ -386,6 +389,8 @@ gst_video_filter_class_init (GstVideoFilterClass * g_class) GST_DEBUG_CATEGORY_INIT (gst_video_filter_debug, "videofilter", 0, "videofilter"); + + meta_tag_video_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_STR); } static void diff --git a/gst/audioconvert/gstaudioconvert.c b/gst/audioconvert/gstaudioconvert.c index d2f58c5..01231e0 100644 --- a/gst/audioconvert/gstaudioconvert.c +++ b/gst/audioconvert/gstaudioconvert.c @@ -184,6 +184,9 @@ GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_ALWAYS, STATIC_CAPS); +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; /*** TYPE FUNCTIONS ***********************************************************/ static void @@ -248,6 +251,8 @@ gst_audio_convert_class_init (GstAudioConvertClass * klass) GST_DEBUG_FUNCPTR (gst_audio_convert_prepare_output_buffer); basetransform_class->transform_ip_on_passthrough = FALSE; + + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); } static void @@ -897,8 +902,7 @@ gst_audio_convert_transform_meta (GstBaseTransform * trans, GstBuffer * outbuf, tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO))) return TRUE; return FALSE; diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index 470746f..de8bd80 100644 --- a/gst/audioresample/gstaudioresample.c +++ b/gst/audioresample/gstaudioresample.c @@ -97,6 +97,10 @@ GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS (SUPPORTED_CAPS)); +/* cached quark to avoid contention on the global quark table lock */ +#define META_TAG_AUDIO meta_tag_audio_quark +static GQuark meta_tag_audio_quark; + static void gst_audio_resample_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_audio_resample_get_property (GObject * object, @@ -215,6 +219,8 @@ gst_audio_resample_class_init (GstAudioResampleClass * klass) gst_type_mark_as_plugin_api (GST_TYPE_AUDIO_RESAMPLER_FILTER_INTERPOLATION, 0); gst_type_mark_as_plugin_api (GST_TYPE_AUDIO_RESAMPLER_FILTER_MODE, 0); + + meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR); } static void @@ -943,8 +949,7 @@ gst_audio_resample_transform_meta (GstBaseTransform * trans, GstBuffer * outbuf, tags = gst_meta_api_type_get_tags (info->api); if (!tags || (g_strv_length ((gchar **) tags) == 1 - && gst_meta_api_type_has_tag (info->api, - g_quark_from_string (GST_META_TAG_AUDIO_STR)))) + && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO))) return TRUE; return FALSE; -- 2.7.4