From dcfb8a83a53a083b84d14e5360cb42c7efc7bcf0 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 7 May 2015 10:26:47 +0200 Subject: [PATCH] encodebin: Add a way to enable/disabled a GstEncodingProfile Summary: So that the user can easily use the same encoding profile to render with/without audio/video stream. API: gst_encoding_profile_is_disabled gst_encoding_pofile_set_enabled https://bugzilla.gnome.org/show_bug.cgi?id=749056 --- docs/libs/gst-plugins-base-libs-sections.txt | 2 ++ gst-libs/gst/pbutils/encoding-profile.c | 32 ++++++++++++++++++++ gst-libs/gst/pbutils/encoding-profile.h | 3 ++ gst/encoding/gstencodebin.c | 14 +++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 02582501c8..22c8fe4768 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -2185,12 +2185,14 @@ gst_encoding_profile_get_restriction gst_encoding_profile_get_file_extension gst_encoding_profile_set_name gst_encoding_profile_set_description +gst_encoding_profile_set_enabled gst_encoding_profile_set_format gst_encoding_profile_set_preset gst_encoding_profile_set_preset_name gst_encoding_profile_set_restriction gst_encoding_profile_set_presence gst_encoding_profile_is_equal +gst_encoding_profile_is_enabled gst_encoding_profile_get_input_caps gst_encoding_profile_get_type_nick diff --git a/gst-libs/gst/pbutils/encoding-profile.c b/gst-libs/gst/pbutils/encoding-profile.c index 770e2ce36e..c1f502e33a 100644 --- a/gst-libs/gst/pbutils/encoding-profile.c +++ b/gst-libs/gst/pbutils/encoding-profile.c @@ -189,6 +189,7 @@ struct _GstEncodingProfile guint presence; GstCaps *restriction; gboolean allow_dynamic_output; + gboolean enabled; }; struct _GstEncodingProfileClass @@ -400,6 +401,20 @@ gst_encoding_profile_get_presence (GstEncodingProfile * profile) return profile->presence; } +/** + * gst_encoding_profile_get_enabled: + * @profile: a #GstEncodingProfile + * + * Returns: Whther @profile is enabled or not + */ +gboolean +gst_encoding_profile_is_enabled (GstEncodingProfile * profile) +{ + g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE); + + return profile->enabled; +} + /** * gst_encoding_profile_get_restriction: * @profile: a #GstEncodingProfile @@ -542,6 +557,22 @@ gst_encoding_profile_set_presence (GstEncodingProfile * profile, guint presence) profile->presence = presence; } +/** + * gst_encoding_profile_set_enabled: + * @profile: a #GstEncodingProfile + * @enabled: %FALSE to disable #profile, %TRUE to enable it + * + * Set whether the profile should be used or not. + */ +void +gst_encoding_profile_set_enabled (GstEncodingProfile * profile, + gboolean enabled) +{ + g_return_if_fail (GST_IS_ENCODING_PROFILE (profile)); + + profile->enabled = enabled; +} + /** * gst_encoding_profile_set_restriction: * @profile: a #GstEncodingProfile @@ -868,6 +899,7 @@ common_creation (GType objtype, GstCaps * format, const gchar * preset, prof->presence = presence; prof->preset_name = NULL; prof->allow_dynamic_output = TRUE; + prof->enabled = TRUE; return prof; } diff --git a/gst-libs/gst/pbutils/encoding-profile.h b/gst-libs/gst/pbutils/encoding-profile.h index 401c547f0a..a667f8c417 100644 --- a/gst-libs/gst/pbutils/encoding-profile.h +++ b/gst-libs/gst/pbutils/encoding-profile.h @@ -152,6 +152,9 @@ GstEncodingProfile * gst_encoding_profile_find (const gchar *targetname, const gchar *profilename, const gchar *category); +gboolean gst_encoding_profile_is_enabled (GstEncodingProfile *profile); +void gst_encoding_profile_set_enabled (GstEncodingProfile *profile, + gboolean enabled); /* GstEncodingContainerProfile API */ gboolean gst_encoding_container_profile_add_profile (GstEncodingContainerProfile *container, GstEncodingProfile *profile); diff --git a/gst/encoding/gstencodebin.c b/gst/encoding/gstencodebin.c index 212cb46ea1..88952085b4 100644 --- a/gst/encoding/gstencodebin.c +++ b/gst/encoding/gstencodebin.c @@ -659,8 +659,15 @@ next_unused_stream_profile (GstEncodeBin * ebin, GType ptype, if (profilename && !strcmp (name, profilename)) { guint presence = gst_encoding_profile_get_presence (sprof); + GST_DEBUG ("Found profile matching the requested name"); + if (!gst_encoding_profile_is_enabled (sprof)) { + GST_INFO_OBJECT (ebin, "%p is disabled, not using it", sprof); + + return NULL; + } + if (presence == 0 || presence > stream_profile_used_count (ebin, sprof)) return sprof; @@ -686,7 +693,9 @@ next_unused_stream_profile (GstEncodeBin * ebin, GType ptype, if (G_TYPE_FROM_INSTANCE (sprof) == ptype) { guint presence = gst_encoding_profile_get_presence (sprof); GST_DEBUG ("Found a stream profile with the same type"); - if (presence == 0 + if (!gst_encoding_profile_is_enabled (sprof)) { + GST_INFO_OBJECT (ebin, "%p is disabled, not using it", sprof); + } else if (presence == 0 || (presence > stream_profile_used_count (ebin, sprof))) return sprof; } else if (caps && ptype == G_TYPE_NONE) { @@ -1873,7 +1882,8 @@ create_elements_and_pads (GstEncodeBin * ebin) GST_DEBUG ("Trying stream profile with presence %d", gst_encoding_profile_get_presence (sprof)); - if (gst_encoding_profile_get_presence (sprof) != 0) { + if (gst_encoding_profile_get_presence (sprof) != 0 && + gst_encoding_profile_is_enabled (sprof)) { if (G_UNLIKELY (_create_stream_group (ebin, sprof, NULL, NULL) == NULL)) goto stream_error; }