From 46b424a38b3e88432a77dad91da905d77b6be29f Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 4 Jan 2017 14:27:40 -0300 Subject: [PATCH] encoding-profile: Add a way to copy an encoding profile It is often usefull to make sure that you get a full copy of a profile. For example you want to let the user modify it in the user interface but still keep an unchanged version for later use. API: gst_encoding_profile_copy --- docs/libs/gst-plugins-base-libs-sections.txt | 1 + gst-libs/gst/pbutils/encoding-profile.c | 60 ++++++++++++++++++++ gst-libs/gst/pbutils/encoding-profile.h | 1 + 3 files changed, 62 insertions(+) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 58781a0e8a..2edfd6384d 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -2308,6 +2308,7 @@ gst_encoding_profile_is_equal gst_encoding_profile_is_enabled gst_encoding_profile_get_input_caps gst_encoding_profile_get_type_nick +gst_encoding_profile_copy GstEncodingContainerProfile gst_encoding_container_profile_new diff --git a/gst-libs/gst/pbutils/encoding-profile.c b/gst-libs/gst/pbutils/encoding-profile.c index f9f4d3e518..eebda35ee7 100644 --- a/gst-libs/gst/pbutils/encoding-profile.c +++ b/gst-libs/gst/pbutils/encoding-profile.c @@ -355,6 +355,8 @@ struct _GstEncodingProfile struct _GstEncodingProfileClass { GObjectClass parent_class; + + void (*copy) (GstEncodingProfile * self, GstEncodingProfile * copy); }; enum @@ -815,12 +817,28 @@ gst_encoding_container_profile_finalize (GObject * object) ((GObject *) prof); } +static void +gst_encoding_container_profile_copy (GstEncodingProfile * profile, + GstEncodingProfile * copy_profile) +{ + GstEncodingContainerProfile *self = GST_ENCODING_CONTAINER_PROFILE (profile), + *copy = GST_ENCODING_CONTAINER_PROFILE (copy_profile); + GList *tmp; + + for (tmp = self->encodingprofiles; tmp; tmp = tmp->next) { + gst_encoding_container_profile_add_profile (copy, + gst_encoding_profile_copy (tmp->data)); + } +} + static void gst_encoding_container_profile_class_init (GstEncodingContainerProfileClass * k) { GObjectClass *gobject_class = (GObjectClass *) k; gobject_class->finalize = gst_encoding_container_profile_finalize; + + ((GstEncodingProfileClass *) k)->copy = gst_encoding_container_profile_copy; } /** @@ -857,6 +875,17 @@ struct _GstEncodingVideoProfileClass G_DEFINE_TYPE (GstEncodingVideoProfile, gst_encoding_video_profile, GST_TYPE_ENCODING_PROFILE); +static void +gst_encoding_video_profile_copy (GstEncodingProfile * profile, + GstEncodingProfile * copy_profile) +{ + GstEncodingVideoProfile *self = GST_ENCODING_VIDEO_PROFILE (profile), + *copy = GST_ENCODING_VIDEO_PROFILE (copy_profile); + + copy->pass = self->pass; + copy->variableframerate = self->variableframerate; +} + static void gst_encoding_video_profile_init (GstEncodingVideoProfile * prof) { @@ -866,6 +895,7 @@ gst_encoding_video_profile_init (GstEncodingVideoProfile * prof) static void gst_encoding_video_profile_class_init (GstEncodingVideoProfileClass * klass) { + ((GstEncodingProfileClass *) klass)->copy = gst_encoding_video_profile_copy; } /** @@ -1903,3 +1933,33 @@ gst_encoding_profile_from_discoverer (GstDiscovererInfo * info) return (GstEncodingProfile *) profile; } + +/** + * gst_encoding_profile_copy: + * @self: The #GstEncodingProfile to copy + * + * Makes a deep copy of @self + * + * Returns: (transfer full): The copy of @self + * + * Since 1.12 + */ +GstEncodingProfile * +gst_encoding_profile_copy (GstEncodingProfile * self) +{ + GstEncodingProfileClass *klass = + (GstEncodingProfileClass *) G_OBJECT_GET_CLASS (self); + GstEncodingProfile *copy = + common_creation (G_OBJECT_TYPE (self), self->format, self->preset, + self->name, self->description, self->restriction, self->presence); + + copy->enabled = self->enabled; + copy->allow_dynamic_output = self->allow_dynamic_output; + gst_encoding_profile_set_preset_name (copy, self->preset_name); + gst_encoding_profile_set_description (copy, self->description); + + if (klass->copy) + klass->copy (self, copy); + + return copy; +} diff --git a/gst-libs/gst/pbutils/encoding-profile.h b/gst-libs/gst/pbutils/encoding-profile.h index 847d926955..60210f20a9 100644 --- a/gst-libs/gst/pbutils/encoding-profile.h +++ b/gst-libs/gst/pbutils/encoding-profile.h @@ -188,6 +188,7 @@ void gst_encoding_video_profile_set_variableframerate (GstEncodingVideoProfi gboolean variableframerate); GstEncodingProfile * gst_encoding_profile_from_discoverer (GstDiscovererInfo *info); +GstEncodingProfile * gst_encoding_profile_copy (GstEncodingProfile *self); #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstEncodingAudioProfile, gst_object_unref)