From f85c463b9397903895aaa46a67f272a5948b8f7b Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 26 Nov 2014 20:34:24 +0100 Subject: [PATCH] track: [API]: ges_track_update_restriction_caps. + 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 | 2 ++ ges/ges-audio-track.c | 28 ++++++++++++++++++++++++-- ges/ges-track.c | 41 ++++++++++++++++++++++++++++++++++++++ ges/ges-track.h | 1 + tests/check/Makefile.am | 1 + tests/check/ges/.gitignore | 1 + 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/docs/libs/ges-sections.txt b/docs/libs/ges-sections.txt index 15c8482697..5fb74f3e4f 100644 --- a/docs/libs/ges-sections.txt +++ b/docs/libs/ges-sections.txt @@ -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 diff --git a/ges/ges-audio-track.c b/ges/ges-audio-track.c index 53830ae546..7b603302fc 100644 --- a/ges/ges-audio-track.c +++ b/ges/ges-audio-track.c @@ -20,14 +20,36 @@ /** * 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; diff --git a/ges/ges-track.c b/ges/ges-track.c index 5897284dd0..35cc208928 100644 --- a/ges/ges-track.c +++ b/ges/ges-track.c @@ -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, @@ -749,6 +756,40 @@ ges_track_set_restriction_caps (GESTrack * track, const GstCaps * caps) g_object_notify (G_OBJECT (track), "restriction-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 diff --git a/ges/ges-track.h b/ges/ges-track.h index 6670b11f58..f22d0d701f 100644 --- a/ges/ges-track.h +++ b/ges/ges-track.h @@ -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); diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index c6914218fa..bd6d58d417 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -42,6 +42,7 @@ check_PROGRAMS = \ ges/mixers\ ges/group\ ges/project\ + ges/track\ nle/simple \ nle/complex \ nle/nleoperation \ diff --git a/tests/check/ges/.gitignore b/tests/check/ges/.gitignore index 930bcf363f..1df6509e5b 100644 --- a/tests/check/ges/.gitignore +++ b/tests/check/ges/.gitignore @@ -11,3 +11,4 @@ clip timelineedition titles transition +track