encoding-profile: Add a way to copy an encoding profile
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Wed, 4 Jan 2017 17:27:40 +0000 (14:27 -0300)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Fri, 6 Jan 2017 14:40:20 +0000 (11:40 -0300)
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
gst-libs/gst/pbutils/encoding-profile.c
gst-libs/gst/pbutils/encoding-profile.h

index 58781a0..2edfd63 100644 (file)
@@ -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
 <SUBSECTION container>
 GstEncodingContainerProfile
 gst_encoding_container_profile_new
index f9f4d3e..eebda35 100644 (file)
@@ -355,6 +355,8 @@ struct _GstEncodingProfile
 struct _GstEncodingProfileClass
 {
   GObjectClass parent_class;
+
+  void (*copy) (GstEncodingProfile * self, GstEncodingProfile * copy);
 };
 
 enum
@@ -816,11 +818,27 @@ gst_encoding_container_profile_finalize (GObject * object)
 }
 
 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;
 }
 
 /**
@@ -858,6 +876,17 @@ 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)
 {
   /* Nothing to initialize */
@@ -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;
+}
index 847d926..60210f2 100644 (file)
@@ -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)