track: [API]: ges_track_update_restriction_caps.
authorMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Wed, 26 Nov 2014 19:34:24 +0000 (20:34 +0100)
committerMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Fri, 5 Dec 2014 21:12:11 +0000 (22:12 +0100)
+ And specify default restriction caps for audio tracks.
+ Add ges_track_set_restriction_caps to the sections, it
  was missing.

https://bugzilla.gnome.org/show_bug.cgi?id=740726

docs/libs/ges-sections.txt
ges/ges-audio-track.c
ges/ges-track.c
ges/ges-track.h
tests/check/Makefile.am
tests/check/ges/.gitignore

index 15c8482..5fb74f3 100644 (file)
@@ -71,6 +71,8 @@ GESTrack
 GESCreateElementForGapFunc
 ges_track_new
 ges_track_add_element
+ges_track_set_restriction_caps
+ges_track_update_restriction_caps
 ges_track_remove_element
 ges_track_set_caps
 ges_track_get_caps
index 53830ae..7b60330 100644 (file)
 /**
  * SECTION: gesaudiotrack
  * @short_description: A standard GESTrack for raw audio
+ *
+ * Sane default properties to specify and fixate the output stream are
+ * set as restriction-caps.
+ * It is advised, to modify these properties, to use
+ * #ges_track_update_restriction_caps, setting them directly is
+ * possible through #ges_track_set_restriction_caps, but not specifying
+ * one of them can lead to negotiation issues, only use that function
+ * if you actually know what you're doing :)
+ *
+ * The default properties are:
+ * - format: S32LE
+ * - channels: 2
+ * - rate: 44100
+ * - layout: interleaved
  */
 
-#define DEFAULT_CAPS "audio/x-raw"
-
 #include "ges-internal.h"
 #include "ges-smart-adder.h"
 #include "ges-audio-track.h"
 
+#define DEFAULT_CAPS "audio/x-raw"
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define DEFAULT_RESTRICTION_CAPS "audio/x-raw, format=S32LE, channels=2, "\
+  "rate=44100, layout=interleaved"
+#else
+#define DEFAULT_RESTRICTION_CAPS "audio/x-raw, format=S32BE, channels=2, "\
+  "rate=44100, layout=interleaved"
+#endif
+
 struct _GESAudioTrackPrivate
 {
   gpointer nothing;
@@ -106,6 +128,8 @@ ges_audio_track_new (void)
   ges_track_set_create_element_for_gap_func (GES_TRACK (ret),
       create_element_for_raw_audio_gap);
 
+  ges_track_set_restriction_caps (GES_TRACK (ret),
+      gst_caps_from_string (DEFAULT_RESTRICTION_CAPS));
   gst_caps_unref (caps);
 
   return ret;
index 5897284..35cc208 100644 (file)
@@ -248,6 +248,13 @@ track_resort_and_fill_gaps (GESTrack * track)
   }
 }
 
+static gboolean
+update_field (GQuark field_id, const GValue * value, GstStructure * original)
+{
+  gst_structure_id_set_value (original, field_id, value);
+  return TRUE;
+}
+
 /* callbacks */
 static void
 sort_track_elements_cb (GESTrackElement * child,
@@ -750,6 +757,40 @@ ges_track_set_restriction_caps (GESTrack * track, const GstCaps * caps)
 }
 
 /**
+ * ges_track_update_restriction_caps:
+ * @track: a #GESTrack
+ * @caps: the #GstCaps to update with
+ *
+ * Updates the restriction caps by modifying all the fields present in @caps
+ * in the original restriction caps. If for example the current restriction caps
+ * are video/x-raw, format=I420, width=360 and @caps is video/x-raw, format=RGB,
+ * the restriction caps will be updated to video/x-raw, format=RGB, width=360.
+ *
+ * Modification happens for each structure in the new caps, and
+ * one can add new fields or structures through that function.
+ */
+void
+ges_track_update_restriction_caps (GESTrack * self, const GstCaps * caps)
+{
+  guint i;
+  GstCaps *new_restriction_caps = gst_caps_copy (self->priv->restriction_caps);
+
+  for (i = 0; i < gst_caps_get_size (caps); i++) {
+    GstStructure *new = gst_caps_get_structure (caps, i);
+
+    if (gst_caps_get_size (new_restriction_caps) > i) {
+      GstStructure *original = gst_caps_get_structure (new_restriction_caps, i);
+      gst_structure_foreach (new, (GstStructureForeachFunc) update_field,
+          original);
+    } else
+      gst_caps_append_structure (new_restriction_caps,
+          gst_structure_copy (new));
+  }
+
+  ges_track_set_restriction_caps (self, new_restriction_caps);
+}
+
+/**
  * ges_track_set_mixing:
  * @track: a #GESTrack
  * @mixing: TRUE if the track should be mixing, FALSE otherwise.
index 6670b11..f22d0d7 100644 (file)
@@ -92,6 +92,7 @@ void               ges_track_set_create_element_for_gap_func (GESTrack *track, G
 void               ges_track_set_mixing                      (GESTrack *track, gboolean mixing);
 gboolean           ges_track_get_mixing                      (GESTrack *track);
 void               ges_track_set_restriction_caps            (GESTrack *track, const GstCaps *caps);
+void               ges_track_update_restriction_caps         (GESTrack *track, const GstCaps *caps);
 
 /* standard methods */
 GType              ges_track_get_type                        (void);
index c691421..bd6d58d 100644 (file)
@@ -42,6 +42,7 @@ check_PROGRAMS = \
        ges/mixers\
        ges/group\
        ges/project\
+       ges/track\
        nle/simple      \
        nle/complex     \
        nle/nleoperation        \
index 930bcf3..1df6509 100644 (file)
@@ -11,3 +11,4 @@ clip
 timelineedition
 titles
 transition
+track