1 /* GStreamer Editing Services
2 * Copyright (C) <2013> Thibault Saunier <thibault.saunier@collabora.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * SECTION: gesaudiotrack
22 * @title: GESAudioTrack
23 * @short_description: A standard #GESTrack for raw audio
25 * A #GESAudioTrack is a default audio #GESTrack, with a
26 * #GES_TRACK_TYPE_AUDIO #GESTrack:track-type and "audio/x-raw(ANY)"
29 * By default, an audio track will have its #GESTrack:restriction-caps
30 * set to "audio/x-raw" with the following properties:
35 * - layout: "interleaved"
37 * These fields are needed for negotiation purposes, but you can change
38 * their values if you wish. It is advised that you do so using
39 * ges_track_update_restriction_caps() with new values for the fields you
40 * wish to change, and any additional fields you may want to add. Unlike
41 * using ges_track_set_restriction_caps(), this will ensure that these
42 * default fields will at least have some value set.
48 #include "ges-internal.h"
49 #include "ges-smart-adder.h"
50 #include "ges-audio-track.h"
52 #define DEFAULT_CAPS "audio/x-raw"
54 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
55 #define DEFAULT_RESTRICTION_CAPS "audio/x-raw, format=S32LE, channels=2, "\
56 "rate=44100, layout=interleaved"
58 #define DEFAULT_RESTRICTION_CAPS "audio/x-raw, format=S32BE, channels=2, "\
59 "rate=44100, layout=interleaved"
62 struct _GESAudioTrackPrivate
67 G_DEFINE_TYPE_WITH_PRIVATE (GESAudioTrack, ges_audio_track, GES_TYPE_TRACK);
69 /****************************************************
70 * Private methods and utils *
71 ****************************************************/
73 _sync_capsfilter_with_track (GESTrack * track, GstElement * capsfilter)
75 GstCaps *restriction, *caps;
77 GstStructure *structure;
79 g_object_get (track, "restriction-caps", &restriction, NULL);
80 if (restriction == NULL)
83 if (gst_caps_get_size (restriction) == 0)
86 structure = gst_caps_get_structure (restriction, 0);
87 if (!gst_structure_get_int (structure, "rate", &rate))
90 caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, rate, NULL);
92 g_object_set (capsfilter, "caps", caps, NULL);
93 gst_caps_unref (caps);
96 gst_caps_unref (restriction);
100 _track_restriction_changed_cb (GESTrack * track, GParamSpec * arg G_GNUC_UNUSED,
101 GstElement * capsfilter)
103 _sync_capsfilter_with_track (track, capsfilter);
107 _weak_notify_cb (GESTrack * track, GstElement * capsfilter)
109 g_signal_handlers_disconnect_by_func (track,
110 (GCallback) _track_restriction_changed_cb, capsfilter);
114 create_element_for_raw_audio_gap (GESTrack * track)
117 GstElement *capsfilter;
119 bin = gst_parse_bin_from_description
120 ("audiotestsrc wave=silence name=src ! audioconvert ! audioresample ! audioconvert ! capsfilter name=gapfilter caps=audio/x-raw",
123 capsfilter = gst_bin_get_by_name (GST_BIN (bin), "gapfilter");
124 g_object_weak_ref (G_OBJECT (capsfilter), (GWeakNotify) _weak_notify_cb,
126 g_signal_connect (track, "notify::restriction-caps",
127 (GCallback) _track_restriction_changed_cb, capsfilter);
129 _sync_capsfilter_with_track (track, capsfilter);
131 gst_object_unref (capsfilter);
137 /****************************************************
138 * GObject vmethods implementations *
139 ****************************************************/
142 ges_audio_track_init (GESAudioTrack * self)
144 self->priv = ges_audio_track_get_instance_private (self);
148 ges_audio_track_finalize (GObject * object)
150 /* TODO: Add deinitalization code here */
152 G_OBJECT_CLASS (ges_audio_track_parent_class)->finalize (object);
156 ges_audio_track_class_init (GESAudioTrackClass * klass)
158 GObjectClass *object_class = G_OBJECT_CLASS (klass);
159 /* GESTrackClass *parent_class = GES_TRACK_CLASS (klass);
162 object_class->finalize = ges_audio_track_finalize;
164 GES_TRACK_CLASS (klass)->get_mixing_element = ges_smart_adder_new;
167 /****************************************************
168 * API implementation *
169 ****************************************************/
171 * ges_audio_track_new:
173 * Creates a new audio track, with a #GES_TRACK_TYPE_AUDIO
174 * #GESTrack:track-type, "audio/x-raw(ANY)" #GESTrack:caps, and
175 * "audio/x-raw" #GESTrack:restriction-caps with the properties:
180 * - layout: "interleaved"
182 * You should use ges_track_update_restriction_caps() if you wish to
183 * modify these fields, or add additional ones.
185 * Returns: (transfer floating): The newly created audio track.
188 ges_audio_track_new (void)
191 GstCaps *caps = gst_caps_from_string (DEFAULT_CAPS);
192 GstCaps *restriction_caps = gst_caps_from_string (DEFAULT_RESTRICTION_CAPS);
194 ret = g_object_new (GES_TYPE_AUDIO_TRACK, "caps", caps,
195 "track-type", GES_TRACK_TYPE_AUDIO, NULL);
197 ges_track_set_create_element_for_gap_func (GES_TRACK (ret),
198 create_element_for_raw_audio_gap);
200 ges_track_set_restriction_caps (GES_TRACK (ret), restriction_caps);
202 gst_caps_unref (caps);
203 gst_caps_unref (restriction_caps);