1 /* GStreamer AAC parser plugin
2 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
4 * Contact: Stefan Kost <stefan.kost@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * SECTION:element-aacparse
24 * @short_description: AAC parser
25 * @see_also: #GstAmrParse
27 * This is an AAC parser which handles both ADIF and ADTS stream formats.
29 * As ADIF format is not framed, it is not seekable and stream duration cannot
30 * be determined either. However, ADTS format AAC clips can be seeked, and parser
31 * can also estimate playback position and clip duration.
34 * <title>Example launch line</title>
36 * gst-launch-1.0 filesrc location=abc.aac ! aacparse ! faad ! audioresample ! audioconvert ! alsasink
47 #include <gst/base/gstbitreader.h>
48 #include <gst/pbutils/pbutils.h>
49 #include "gstaacparse.h"
52 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS ("audio/mpeg, "
56 "framed = (boolean) true, " "mpegversion = (int) { 2, 4 }, "
57 "stream-format = (string) { raw, adts, adif, loas };"));
59 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
62 GST_STATIC_CAPS ("audio/mpeg, mpegversion = (int) { 2, 4 };"));
64 GST_DEBUG_CATEGORY_STATIC (aacparse_debug);
65 #define GST_CAT_DEFAULT aacparse_debug
68 #define ADIF_MAX_SIZE 40 /* Should be enough */
69 #define ADTS_MAX_SIZE 10 /* Should be enough */
70 #define LOAS_MAX_SIZE 3 /* Should be enough */
72 #define ADTS_HEADERS_LENGTH 7UL /* Total byte-length of fixed and variable
73 headers prepended during raw to ADTS
76 #define AAC_FRAME_DURATION(parse) (GST_SECOND/parse->frames_per_sec)
78 static const gint loas_sample_rate_table[32] = {
79 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
80 16000, 12000, 11025, 8000, 7350, 0, 0, 0
83 static const gint loas_channels_table[32] = {
84 0, 1, 2, 3, 4, 5, 6, 8,
85 0, 0, 0, 0, 0, 0, 0, 0
88 static gboolean gst_aac_parse_start (GstBaseParse * parse);
89 static gboolean gst_aac_parse_stop (GstBaseParse * parse);
91 static gboolean gst_aac_parse_sink_setcaps (GstBaseParse * parse,
93 static GstCaps *gst_aac_parse_sink_getcaps (GstBaseParse * parse,
96 static GstFlowReturn gst_aac_parse_handle_frame (GstBaseParse * parse,
97 GstBaseParseFrame * frame, gint * skipsize);
98 static GstFlowReturn gst_aac_parse_pre_push_frame (GstBaseParse * parse,
99 GstBaseParseFrame * frame);
101 G_DEFINE_TYPE (GstAacParse, gst_aac_parse, GST_TYPE_BASE_PARSE);
104 * gst_aac_parse_class_init:
105 * @klass: #GstAacParseClass.
109 gst_aac_parse_class_init (GstAacParseClass * klass)
111 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
112 GstBaseParseClass *parse_class = GST_BASE_PARSE_CLASS (klass);
114 GST_DEBUG_CATEGORY_INIT (aacparse_debug, "aacparse", 0,
115 "AAC audio stream parser");
117 gst_element_class_add_pad_template (element_class,
118 gst_static_pad_template_get (&sink_template));
119 gst_element_class_add_pad_template (element_class,
120 gst_static_pad_template_get (&src_template));
122 gst_element_class_set_static_metadata (element_class,
123 "AAC audio stream parser", "Codec/Parser/Audio",
124 "Advanced Audio Coding parser", "Stefan Kost <stefan.kost@nokia.com>");
126 parse_class->start = GST_DEBUG_FUNCPTR (gst_aac_parse_start);
127 parse_class->stop = GST_DEBUG_FUNCPTR (gst_aac_parse_stop);
128 parse_class->set_sink_caps = GST_DEBUG_FUNCPTR (gst_aac_parse_sink_setcaps);
129 parse_class->get_sink_caps = GST_DEBUG_FUNCPTR (gst_aac_parse_sink_getcaps);
130 parse_class->handle_frame = GST_DEBUG_FUNCPTR (gst_aac_parse_handle_frame);
131 parse_class->pre_push_frame =
132 GST_DEBUG_FUNCPTR (gst_aac_parse_pre_push_frame);
137 * gst_aac_parse_init:
138 * @aacparse: #GstAacParse.
139 * @klass: #GstAacParseClass.
143 gst_aac_parse_init (GstAacParse * aacparse)
145 GST_DEBUG ("initialized");
146 GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (aacparse));
151 * gst_aac_parse_set_src_caps:
152 * @aacparse: #GstAacParse.
153 * @sink_caps: (proposed) caps of sink pad
155 * Set source pad caps according to current knowledge about the
158 * Returns: TRUE if caps were successfully set.
161 gst_aac_parse_set_src_caps (GstAacParse * aacparse, GstCaps * sink_caps)
164 GstCaps *src_caps = NULL, *allowed;
165 gboolean res = FALSE;
166 const gchar *stream_format;
167 guint8 codec_data[2];
168 guint16 codec_data_data;
169 gint sample_rate_idx;
171 GST_DEBUG_OBJECT (aacparse, "sink caps: %" GST_PTR_FORMAT, sink_caps);
173 src_caps = gst_caps_copy (sink_caps);
175 src_caps = gst_caps_new_empty_simple ("audio/mpeg");
177 gst_caps_set_simple (src_caps, "framed", G_TYPE_BOOLEAN, TRUE,
178 "mpegversion", G_TYPE_INT, aacparse->mpegversion, NULL);
180 aacparse->output_header_type = aacparse->header_type;
181 switch (aacparse->header_type) {
182 case DSPAAC_HEADER_NONE:
183 stream_format = "raw";
185 case DSPAAC_HEADER_ADTS:
186 stream_format = "adts";
188 case DSPAAC_HEADER_ADIF:
189 stream_format = "adif";
191 case DSPAAC_HEADER_LOAS:
192 stream_format = "loas";
195 stream_format = NULL;
198 /* Generate codec data to be able to set profile/level on the caps */
200 gst_codec_utils_aac_get_index_from_sample_rate (aacparse->sample_rate);
201 if (sample_rate_idx < 0)
202 goto not_a_known_rate;
204 (aacparse->object_type << 11) |
205 (sample_rate_idx << 7) | (aacparse->channels << 3);
206 GST_WRITE_UINT16_BE (codec_data, codec_data_data);
207 gst_codec_utils_aac_caps_set_level_and_profile (src_caps, codec_data, 2);
209 s = gst_caps_get_structure (src_caps, 0);
210 if (aacparse->sample_rate > 0)
211 gst_structure_set (s, "rate", G_TYPE_INT, aacparse->sample_rate, NULL);
212 if (aacparse->channels > 0)
213 gst_structure_set (s, "channels", G_TYPE_INT, aacparse->channels, NULL);
215 gst_structure_set (s, "stream-format", G_TYPE_STRING, stream_format, NULL);
217 allowed = gst_pad_get_allowed_caps (GST_BASE_PARSE (aacparse)->srcpad);
218 if (allowed && !gst_caps_can_intersect (src_caps, allowed)) {
219 GST_DEBUG_OBJECT (GST_BASE_PARSE (aacparse)->srcpad,
220 "Caps can not intersect");
221 if (aacparse->header_type == DSPAAC_HEADER_ADTS) {
222 GST_DEBUG_OBJECT (GST_BASE_PARSE (aacparse)->srcpad,
223 "Input is ADTS, trying raw");
224 gst_caps_set_simple (src_caps, "stream-format", G_TYPE_STRING, "raw",
226 if (gst_caps_can_intersect (src_caps, allowed)) {
227 GstBuffer *codec_data_buffer;
229 GST_DEBUG_OBJECT (GST_BASE_PARSE (aacparse)->srcpad,
230 "Caps can intersect, we will drop the ADTS layer");
231 aacparse->output_header_type = DSPAAC_HEADER_NONE;
233 /* The codec_data data is according to AudioSpecificConfig,
234 ISO/IEC 14496-3, 1.6.2.1 */
235 codec_data_buffer = gst_buffer_new_and_alloc (2);
236 gst_buffer_fill (codec_data_buffer, 0, codec_data, 2);
237 gst_caps_set_simple (src_caps, "codec_data", GST_TYPE_BUFFER,
238 codec_data_buffer, NULL);
240 } else if (aacparse->header_type == DSPAAC_HEADER_NONE) {
241 GST_DEBUG_OBJECT (GST_BASE_PARSE (aacparse)->srcpad,
242 "Input is raw, trying ADTS");
243 gst_caps_set_simple (src_caps, "stream-format", G_TYPE_STRING, "adts",
245 if (gst_caps_can_intersect (src_caps, allowed)) {
246 GST_DEBUG_OBJECT (GST_BASE_PARSE (aacparse)->srcpad,
247 "Caps can intersect, we will prepend ADTS headers");
248 aacparse->output_header_type = DSPAAC_HEADER_ADTS;
253 gst_caps_unref (allowed);
255 GST_DEBUG_OBJECT (aacparse, "setting src caps: %" GST_PTR_FORMAT, src_caps);
257 res = gst_pad_set_caps (GST_BASE_PARSE (aacparse)->srcpad, src_caps);
258 gst_caps_unref (src_caps);
262 GST_ERROR_OBJECT (aacparse, "Not a known sample rate: %d",
263 aacparse->sample_rate);
264 gst_caps_unref (src_caps);
270 * gst_aac_parse_sink_setcaps:
274 * Implementation of "set_sink_caps" vmethod in #GstBaseParse class.
276 * Returns: TRUE on success.
279 gst_aac_parse_sink_setcaps (GstBaseParse * parse, GstCaps * caps)
281 GstAacParse *aacparse;
282 GstStructure *structure;
286 aacparse = GST_AAC_PARSE (parse);
287 structure = gst_caps_get_structure (caps, 0);
288 caps_str = gst_caps_to_string (caps);
290 GST_DEBUG_OBJECT (aacparse, "setcaps: %s", caps_str);
293 /* This is needed at least in case of RTP
294 * Parses the codec_data information to get ObjectType,
295 * number of channels and samplerate */
296 value = gst_structure_get_value (structure, "codec_data");
298 GstBuffer *buf = gst_value_get_buffer (value);
304 gst_buffer_map (buf, &map, GST_MAP_READ);
306 sr_idx = ((map.data[0] & 0x07) << 1) | ((map.data[1] & 0x80) >> 7);
307 aacparse->object_type = (map.data[0] & 0xf8) >> 3;
308 aacparse->sample_rate =
309 gst_codec_utils_aac_get_sample_rate_from_index (sr_idx);
310 aacparse->channels = (map.data[1] & 0x78) >> 3;
311 aacparse->header_type = DSPAAC_HEADER_NONE;
312 aacparse->mpegversion = 4;
313 aacparse->frame_samples = (map.data[1] & 4) ? 960 : 1024;
314 gst_buffer_unmap (buf, &map);
316 GST_DEBUG ("codec_data: object_type=%d, sample_rate=%d, channels=%d, "
317 "samples=%d", aacparse->object_type, aacparse->sample_rate,
318 aacparse->channels, aacparse->frame_samples);
320 /* arrange for metadata and get out of the way */
321 gst_aac_parse_set_src_caps (aacparse, caps);
322 if (aacparse->header_type == aacparse->output_header_type)
323 gst_base_parse_set_passthrough (parse, TRUE);
327 /* caps info overrides */
328 gst_structure_get_int (structure, "rate", &aacparse->sample_rate);
329 gst_structure_get_int (structure, "channels", &aacparse->channels);
331 aacparse->sample_rate = 0;
332 aacparse->channels = 0;
333 aacparse->header_type = DSPAAC_HEADER_NOT_PARSED;
334 gst_base_parse_set_passthrough (parse, FALSE);
342 * gst_aac_parse_adts_get_frame_len:
343 * @data: block of data containing an ADTS header.
345 * This function calculates ADTS frame length from the given header.
347 * Returns: size of the ADTS frame.
350 gst_aac_parse_adts_get_frame_len (const guint8 * data)
352 return ((data[3] & 0x03) << 11) | (data[4] << 3) | ((data[5] & 0xe0) >> 5);
357 * gst_aac_parse_check_adts_frame:
358 * @aacparse: #GstAacParse.
359 * @data: Data to be checked.
360 * @avail: Amount of data passed.
361 * @framesize: If valid ADTS frame was found, this will be set to tell the
362 * found frame size in bytes.
363 * @needed_data: If frame was not found, this may be set to tell how much
364 * more data is needed in the next round to detect the frame
365 * reliably. This may happen when a frame header candidate
366 * is found but it cannot be guaranteed to be the header without
367 * peeking the following data.
369 * Check if the given data contains contains ADTS frame. The algorithm
370 * will examine ADTS frame header and calculate the frame size. Also, another
371 * consecutive ADTS frame header need to be present after the found frame.
372 * Otherwise the data is not considered as a valid ADTS frame. However, this
373 * "extra check" is omitted when EOS has been received. In this case it is
374 * enough when data[0] contains a valid ADTS header.
376 * This function may set the #needed_data to indicate that a possible frame
377 * candidate has been found, but more data (#needed_data bytes) is needed to
378 * be absolutely sure. When this situation occurs, FALSE will be returned.
380 * When a valid frame is detected, this function will use
381 * gst_base_parse_set_min_frame_size() function from #GstBaseParse class
382 * to set the needed bytes for next frame.This way next data chunk is already
385 * Returns: TRUE if the given data contains a valid ADTS header.
388 gst_aac_parse_check_adts_frame (GstAacParse * aacparse,
389 const guint8 * data, const guint avail, gboolean drain,
390 guint * framesize, guint * needed_data)
396 /* Absolute minimum to perform the ADTS syncword,
397 layer and sampling frequency tests */
398 if (G_UNLIKELY (avail < 3)) {
403 /* Syncword and layer tests */
404 if ((data[0] == 0xff) && ((data[1] & 0xf6) == 0xf0)) {
406 /* Sampling frequency test */
407 if (G_UNLIKELY ((data[2] & 0x3C) >> 2 == 15))
410 /* This looks like an ADTS frame header but
411 we need at least 6 bytes to proceed */
412 if (G_UNLIKELY (avail < 6)) {
417 *framesize = gst_aac_parse_adts_get_frame_len (data);
419 /* If frame has CRC, it needs 2 bytes
420 for it at the end of the header */
421 crc_size = (data[1] & 0x01) ? 0 : 2;
424 if (*framesize < 7 + crc_size) {
425 *needed_data = 7 + crc_size;
429 /* In EOS mode this is enough. No need to examine the data further.
430 We also relax the check when we have sync, on the assumption that
431 if we're not looking at random data, we have a much higher chance
432 to get the correct sync, and this avoids losing two frames when
433 a single bit corruption happens. */
434 if (drain || !GST_BASE_PARSE_LOST_SYNC (aacparse)) {
438 if (*framesize + ADTS_MAX_SIZE > avail) {
439 /* We have found a possible frame header candidate, but can't be
440 sure since we don't have enough data to check the next frame */
441 GST_DEBUG ("NEED MORE DATA: we need %d, available %d",
442 *framesize + ADTS_MAX_SIZE, avail);
443 *needed_data = *framesize + ADTS_MAX_SIZE;
444 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
445 *framesize + ADTS_MAX_SIZE);
449 if ((data[*framesize] == 0xff) && ((data[*framesize + 1] & 0xf6) == 0xf0)) {
450 guint nextlen = gst_aac_parse_adts_get_frame_len (data + (*framesize));
452 GST_LOG ("ADTS frame found, len: %d bytes", *framesize);
453 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
454 nextlen + ADTS_MAX_SIZE);
462 gst_aac_parse_latm_get_value (GstAacParse * aacparse, GstBitReader * br,
465 guint8 bytes, i, byte;
468 if (!gst_bit_reader_get_bits_uint8 (br, &bytes, 2))
470 for (i = 0; i < bytes; ++i) {
472 if (!gst_bit_reader_get_bits_uint8 (br, &byte, 8))
480 gst_aac_parse_get_audio_object_type (GstAacParse * aacparse, GstBitReader * br,
481 guint8 * audio_object_type)
483 if (!gst_bit_reader_get_bits_uint8 (br, audio_object_type, 5))
485 if (*audio_object_type == 31) {
486 if (!gst_bit_reader_get_bits_uint8 (br, audio_object_type, 6))
488 *audio_object_type += 32;
490 GST_LOG_OBJECT (aacparse, "audio object type %u", *audio_object_type);
495 gst_aac_parse_get_audio_sample_rate (GstAacParse * aacparse, GstBitReader * br,
498 guint8 sampling_frequency_index;
499 if (!gst_bit_reader_get_bits_uint8 (br, &sampling_frequency_index, 4))
501 GST_LOG_OBJECT (aacparse, "sampling_frequency_index: %u",
502 sampling_frequency_index);
503 if (sampling_frequency_index == 0xf) {
504 guint32 sampling_rate;
505 if (!gst_bit_reader_get_bits_uint32 (br, &sampling_rate, 24))
507 *sample_rate = sampling_rate;
509 *sample_rate = loas_sample_rate_table[sampling_frequency_index];
516 /* See table 1.13 in ISO/IEC 14496-3 */
518 gst_aac_parse_read_loas_audio_specific_config (GstAacParse * aacparse,
519 GstBitReader * br, gint * sample_rate, gint * channels, guint32 * bits)
521 guint8 audio_object_type, channel_configuration;
523 if (!gst_aac_parse_get_audio_object_type (aacparse, br, &audio_object_type))
526 if (!gst_aac_parse_get_audio_sample_rate (aacparse, br, sample_rate))
529 if (!gst_bit_reader_get_bits_uint8 (br, &channel_configuration, 4))
531 GST_LOG_OBJECT (aacparse, "channel_configuration: %d", channel_configuration);
532 *channels = loas_channels_table[channel_configuration];
536 if (audio_object_type == 5) {
537 GST_LOG_OBJECT (aacparse,
538 "Audio object type 5, so rereading sampling rate...");
539 if (!gst_aac_parse_get_audio_sample_rate (aacparse, br, sample_rate))
543 GST_INFO_OBJECT (aacparse, "Found LOAS config: %d Hz, %d channels",
544 *sample_rate, *channels);
546 /* There's LOTS of stuff next, but we ignore it for now as we have
547 what we want (sample rate and number of channels */
548 GST_DEBUG_OBJECT (aacparse,
549 "Need more code to parse humongous LOAS data, currently ignored");
557 gst_aac_parse_read_loas_config (GstAacParse * aacparse, const guint8 * data,
558 guint avail, gint * sample_rate, gint * channels, gint * version)
563 /* No version in the bitstream, but the spec has LOAS in the MPEG-4 section */
567 gst_bit_reader_init (&br, data, avail);
569 /* skip sync word (11 bits) and size (13 bits) */
570 if (!gst_bit_reader_skip (&br, 11 + 13))
573 /* First bit is "use last config" */
574 if (!gst_bit_reader_get_bits_uint8 (&br, &u8, 1))
577 GST_DEBUG_OBJECT (aacparse, "Frame uses previous config");
578 if (!aacparse->sample_rate || !aacparse->channels) {
579 GST_WARNING_OBJECT (aacparse, "No previous config to use");
581 *sample_rate = aacparse->sample_rate;
582 *channels = aacparse->channels;
586 GST_DEBUG_OBJECT (aacparse, "Frame contains new config");
588 if (!gst_bit_reader_get_bits_uint8 (&br, &v, 1))
591 if (!gst_bit_reader_get_bits_uint8 (&br, &vA, 1))
596 GST_LOG_OBJECT (aacparse, "v %d, vA %d", v, vA);
598 guint8 same_time, subframes, num_program, prog;
601 if (!gst_aac_parse_latm_get_value (aacparse, &br, &value))
604 if (!gst_bit_reader_get_bits_uint8 (&br, &same_time, 1))
606 if (!gst_bit_reader_get_bits_uint8 (&br, &subframes, 6))
608 if (!gst_bit_reader_get_bits_uint8 (&br, &num_program, 4))
610 GST_LOG_OBJECT (aacparse, "same_time %d, subframes %d, num_program %d",
611 same_time, subframes, num_program);
613 for (prog = 0; prog <= num_program; ++prog) {
614 guint8 num_layer, layer;
615 if (!gst_bit_reader_get_bits_uint8 (&br, &num_layer, 3))
617 GST_LOG_OBJECT (aacparse, "Program %d: %d layers", prog, num_layer);
619 for (layer = 0; layer <= num_layer; ++layer) {
620 guint8 use_same_config;
621 if (prog == 0 && layer == 0) {
624 if (!gst_bit_reader_get_bits_uint8 (&br, &use_same_config, 1))
627 if (!use_same_config) {
629 if (!gst_aac_parse_read_loas_audio_specific_config (aacparse, &br,
630 sample_rate, channels, NULL))
633 guint32 bits, asc_len;
634 if (!gst_aac_parse_latm_get_value (aacparse, &br, &asc_len))
636 if (!gst_aac_parse_read_loas_audio_specific_config (aacparse, &br,
637 sample_rate, channels, &bits))
640 if (!gst_bit_reader_skip (&br, asc_len))
646 GST_LOG_OBJECT (aacparse, "More data ignored");
648 GST_WARNING_OBJECT (aacparse, "Spec says \"TBD\"...");
654 * gst_aac_parse_loas_get_frame_len:
655 * @data: block of data containing a LOAS header.
657 * This function calculates LOAS frame length from the given header.
659 * Returns: size of the LOAS frame.
662 gst_aac_parse_loas_get_frame_len (const guint8 * data)
664 return (((data[1] & 0x1f) << 8) | data[2]) + 3;
669 * gst_aac_parse_check_loas_frame:
670 * @aacparse: #GstAacParse.
671 * @data: Data to be checked.
672 * @avail: Amount of data passed.
673 * @framesize: If valid LOAS frame was found, this will be set to tell the
674 * found frame size in bytes.
675 * @needed_data: If frame was not found, this may be set to tell how much
676 * more data is needed in the next round to detect the frame
677 * reliably. This may happen when a frame header candidate
678 * is found but it cannot be guaranteed to be the header without
679 * peeking the following data.
681 * Check if the given data contains contains LOAS frame. The algorithm
682 * will examine LOAS frame header and calculate the frame size. Also, another
683 * consecutive LOAS frame header need to be present after the found frame.
684 * Otherwise the data is not considered as a valid LOAS frame. However, this
685 * "extra check" is omitted when EOS has been received. In this case it is
686 * enough when data[0] contains a valid LOAS header.
688 * This function may set the #needed_data to indicate that a possible frame
689 * candidate has been found, but more data (#needed_data bytes) is needed to
690 * be absolutely sure. When this situation occurs, FALSE will be returned.
692 * When a valid frame is detected, this function will use
693 * gst_base_parse_set_min_frame_size() function from #GstBaseParse class
694 * to set the needed bytes for next frame.This way next data chunk is already
697 * LOAS can have three different formats, if I read the spec correctly. Only
698 * one of them is supported here, as the two samples I have use this one.
700 * Returns: TRUE if the given data contains a valid LOAS header.
703 gst_aac_parse_check_loas_frame (GstAacParse * aacparse,
704 const guint8 * data, const guint avail, gboolean drain,
705 guint * framesize, guint * needed_data)
710 if (G_UNLIKELY (avail < 3)) {
715 if ((data[0] == 0x56) && ((data[1] & 0xe0) == 0xe0)) {
716 *framesize = gst_aac_parse_loas_get_frame_len (data);
717 GST_DEBUG_OBJECT (aacparse, "Found %u byte LOAS frame", *framesize);
719 /* In EOS mode this is enough. No need to examine the data further.
720 We also relax the check when we have sync, on the assumption that
721 if we're not looking at random data, we have a much higher chance
722 to get the correct sync, and this avoids losing two frames when
723 a single bit corruption happens. */
724 if (drain || !GST_BASE_PARSE_LOST_SYNC (aacparse)) {
728 if (*framesize + LOAS_MAX_SIZE > avail) {
729 /* We have found a possible frame header candidate, but can't be
730 sure since we don't have enough data to check the next frame */
731 GST_DEBUG ("NEED MORE DATA: we need %d, available %d",
732 *framesize + LOAS_MAX_SIZE, avail);
733 *needed_data = *framesize + LOAS_MAX_SIZE;
734 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
735 *framesize + LOAS_MAX_SIZE);
739 if ((data[*framesize] == 0x56) && ((data[*framesize + 1] & 0xe0) == 0xe0)) {
740 guint nextlen = gst_aac_parse_loas_get_frame_len (data + (*framesize));
742 GST_LOG ("LOAS frame found, len: %d bytes", *framesize);
743 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
744 nextlen + LOAS_MAX_SIZE);
751 /* caller ensure sufficient data */
753 gst_aac_parse_parse_adts_header (GstAacParse * aacparse, const guint8 * data,
754 gint * rate, gint * channels, gint * object, gint * version)
758 gint sr_idx = (data[2] & 0x3c) >> 2;
760 *rate = gst_codec_utils_aac_get_sample_rate_from_index (sr_idx);
763 *channels = ((data[2] & 0x01) << 2) | ((data[3] & 0xc0) >> 6);
766 *version = (data[1] & 0x08) ? 2 : 4;
768 *object = ((data[2] & 0xc0) >> 6) + 1;
772 * gst_aac_parse_detect_stream:
773 * @aacparse: #GstAacParse.
774 * @data: A block of data that needs to be examined for stream characteristics.
775 * @avail: Size of the given datablock.
776 * @framesize: If valid stream was found, this will be set to tell the
777 * first frame size in bytes.
778 * @skipsize: If valid stream was found, this will be set to tell the first
779 * audio frame position within the given data.
781 * Examines the given piece of data and try to detect the format of it. It
782 * checks for "ADIF" header (in the beginning of the clip) and ADTS frame
783 * header. If the stream is detected, TRUE will be returned and #framesize
784 * is set to indicate the found frame size. Additionally, #skipsize might
785 * be set to indicate the number of bytes that need to be skipped, a.k.a. the
786 * position of the frame inside given data chunk.
788 * Returns: TRUE on success.
791 gst_aac_parse_detect_stream (GstAacParse * aacparse,
792 const guint8 * data, const guint avail, gboolean drain,
793 guint * framesize, gint * skipsize)
795 gboolean found = FALSE;
796 guint need_data_adts = 0, need_data_loas;
799 GST_DEBUG_OBJECT (aacparse, "Parsing header data");
801 /* FIXME: No need to check for ADIF if we are not in the beginning of the
804 /* Can we even parse the header? */
805 if (avail < MAX (ADTS_MAX_SIZE, LOAS_MAX_SIZE)) {
806 GST_DEBUG_OBJECT (aacparse, "Not enough data to check");
810 for (i = 0; i < avail - 4; i++) {
811 if (((data[i] == 0xff) && ((data[i + 1] & 0xf6) == 0xf0)) ||
812 ((data[0] == 0x56) && ((data[1] & 0xe0) == 0xe0)) ||
813 strncmp ((char *) data + i, "ADIF", 4) == 0) {
814 GST_DEBUG_OBJECT (aacparse, "Found signature at offset %u", i);
818 /* Trick: tell the parent class that we didn't find the frame yet,
819 but make it skip 'i' amount of bytes. Next time we arrive
820 here we have full frame in the beginning of the data. */
833 if (gst_aac_parse_check_adts_frame (aacparse, data, avail, drain,
834 framesize, &need_data_adts)) {
837 GST_INFO ("ADTS ID: %d, framesize: %d", (data[1] & 0x08) >> 3, *framesize);
839 gst_aac_parse_parse_adts_header (aacparse, data, &rate, &channels,
840 &aacparse->object_type, &aacparse->mpegversion);
842 if (!channels || !framesize) {
843 GST_DEBUG_OBJECT (aacparse, "impossible ADTS configuration");
847 aacparse->header_type = DSPAAC_HEADER_ADTS;
848 gst_base_parse_set_frame_rate (GST_BASE_PARSE (aacparse), rate,
849 aacparse->frame_samples, 2, 2);
851 GST_DEBUG ("ADTS: samplerate %d, channels %d, objtype %d, version %d",
852 rate, channels, aacparse->object_type, aacparse->mpegversion);
854 gst_base_parse_set_syncable (GST_BASE_PARSE (aacparse), TRUE);
859 if (gst_aac_parse_check_loas_frame (aacparse, data, avail, drain,
860 framesize, &need_data_loas)) {
863 GST_INFO ("LOAS, framesize: %d", *framesize);
865 aacparse->header_type = DSPAAC_HEADER_LOAS;
867 if (!gst_aac_parse_read_loas_config (aacparse, data, avail, &rate,
868 &channels, &aacparse->mpegversion)) {
869 GST_WARNING_OBJECT (aacparse, "Error reading LOAS config");
873 if (rate && channels) {
874 gst_base_parse_set_frame_rate (GST_BASE_PARSE (aacparse), rate,
875 aacparse->frame_samples, 2, 2);
877 GST_DEBUG ("LOAS: samplerate %d, channels %d, objtype %d, version %d",
878 rate, channels, aacparse->object_type, aacparse->mpegversion);
879 aacparse->sample_rate = rate;
880 aacparse->channels = channels;
883 gst_base_parse_set_syncable (GST_BASE_PARSE (aacparse), TRUE);
888 if (need_data_adts || need_data_loas) {
889 /* This tells the parent class not to skip any data */
894 if (avail < ADIF_MAX_SIZE)
897 if (memcmp (data + i, "ADIF", 4) == 0) {
904 aacparse->header_type = DSPAAC_HEADER_ADIF;
905 aacparse->mpegversion = 4;
907 /* Skip the "ADIF" bytes */
910 /* copyright string */
912 skip_size += 9; /* skip 9 bytes */
914 bitstream_type = adif[0 + skip_size] & 0x10;
916 ((unsigned int) (adif[0 + skip_size] & 0x0f) << 19) |
917 ((unsigned int) adif[1 + skip_size] << 11) |
918 ((unsigned int) adif[2 + skip_size] << 3) |
919 ((unsigned int) adif[3 + skip_size] & 0xe0);
922 if (bitstream_type == 0) {
924 /* Buffer fullness parsing. Currently not needed... */
928 num_elems = (adif[3 + skip_size] & 0x1e);
929 GST_INFO ("ADIF num_config_elems: %d", num_elems);
931 fullness = ((unsigned int) (adif[3 + skip_size] & 0x01) << 19) |
932 ((unsigned int) adif[4 + skip_size] << 11) |
933 ((unsigned int) adif[5 + skip_size] << 3) |
934 ((unsigned int) (adif[6 + skip_size] & 0xe0) >> 5);
936 GST_INFO ("ADIF buffer fullness: %d", fullness);
938 aacparse->object_type = ((adif[6 + skip_size] & 0x01) << 1) |
939 ((adif[7 + skip_size] & 0x80) >> 7);
940 sr_idx = (adif[7 + skip_size] & 0x78) >> 3;
944 aacparse->object_type = (adif[4 + skip_size] & 0x18) >> 3;
945 sr_idx = ((adif[4 + skip_size] & 0x07) << 1) |
946 ((adif[5 + skip_size] & 0x80) >> 7);
949 /* FIXME: This gives totally wrong results. Duration calculation cannot
951 aacparse->sample_rate =
952 gst_codec_utils_aac_get_sample_rate_from_index (sr_idx);
954 /* baseparse is not given any fps,
955 * so it will give up on timestamps, seeking, etc */
957 /* FIXME: Can we assume this? */
958 aacparse->channels = 2;
960 GST_INFO ("ADIF: br=%d, samplerate=%d, objtype=%d",
961 aacparse->bitrate, aacparse->sample_rate, aacparse->object_type);
963 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse), 512);
965 /* arrange for metadata and get out of the way */
966 sinkcaps = gst_pad_get_current_caps (GST_BASE_PARSE_SINK_PAD (aacparse));
967 gst_aac_parse_set_src_caps (aacparse, sinkcaps);
969 gst_caps_unref (sinkcaps);
971 /* not syncable, not easily seekable (unless we push data from start */
972 gst_base_parse_set_syncable (GST_BASE_PARSE_CAST (aacparse), FALSE);
973 gst_base_parse_set_passthrough (GST_BASE_PARSE_CAST (aacparse), TRUE);
974 gst_base_parse_set_average_bitrate (GST_BASE_PARSE_CAST (aacparse), 0);
980 /* This should never happen */
985 * gst_aac_parse_get_audio_profile_object_type
986 * @aacparse: #GstAacParse.
988 * Gets the MPEG-2 profile or the MPEG-4 object type value corresponding to the
989 * mpegversion and profile of @aacparse's src pad caps, according to the
990 * values defined by table 1.A.11 in ISO/IEC 14496-3.
992 * Returns: the profile or object type value corresponding to @aacparse's src
993 * pad caps, if such a value exists; otherwise G_MAXUINT8.
996 gst_aac_parse_get_audio_profile_object_type (GstAacParse * aacparse)
999 GstStructure *srcstruct;
1000 const gchar *profile;
1003 srccaps = gst_pad_get_current_caps (GST_BASE_PARSE_SRC_PAD (aacparse));
1004 srcstruct = gst_caps_get_structure (srccaps, 0);
1005 profile = gst_structure_get_string (srcstruct, "profile");
1006 if (G_UNLIKELY (profile == NULL)) {
1007 gst_caps_unref (srccaps);
1011 if (g_strcmp0 (profile, "main") == 0) {
1013 } else if (g_strcmp0 (profile, "lc") == 0) {
1015 } else if (g_strcmp0 (profile, "ssr") == 0) {
1017 } else if (g_strcmp0 (profile, "ltp") == 0) {
1018 if (G_LIKELY (aacparse->mpegversion == 4))
1021 ret = G_MAXUINT8; /* LTP Object Type allowed only for MPEG-4 */
1026 gst_caps_unref (srccaps);
1031 * gst_aac_parse_get_audio_channel_configuration
1032 * @num_channels: number of audio channels.
1034 * Gets the Channel Configuration value, as defined by table 1.19 in ISO/IEC
1035 * 14496-3, for a given number of audio channels.
1037 * Returns: the Channel Configuration value corresponding to @num_channels, if
1038 * such a value exists; otherwise G_MAXUINT8.
1041 gst_aac_parse_get_audio_channel_configuration (gint num_channels)
1043 if (num_channels >= 1 && num_channels <= 6) /* Mono up to & including 5.1 */
1044 return (guint8) num_channels;
1045 else if (num_channels == 8) /* 7.1 */
1052 * gst_aac_parse_get_audio_sampling_frequency_index:
1053 * @sample_rate: audio sampling rate.
1055 * Gets the Sampling Frequency Index value, as defined by table 1.18 in ISO/IEC
1056 * 14496-3, for a given sampling rate.
1058 * Returns: the Sampling Frequency Index value corresponding to @sample_rate,
1059 * if such a value exists; otherwise G_MAXUINT8.
1062 gst_aac_parse_get_audio_sampling_frequency_index (gint sample_rate)
1064 switch (sample_rate) {
1097 * gst_aac_parse_prepend_adts_headers:
1098 * @aacparse: #GstAacParse.
1099 * @frame: raw AAC frame to which ADTS headers shall be prepended.
1101 * Prepends ADTS headers to a raw AAC audio frame.
1103 * Returns: TRUE if ADTS headers were successfully prepended; FALSE otherwise.
1106 gst_aac_parse_prepend_adts_headers (GstAacParse * aacparse,
1107 GstBaseParseFrame * frame)
1110 guint8 *adts_headers;
1113 guint8 id, profile, channel_configuration, sampling_frequency_index;
1115 id = (aacparse->mpegversion == 4) ? 0x0U : 0x1U;
1116 profile = gst_aac_parse_get_audio_profile_object_type (aacparse);
1117 if (profile == G_MAXUINT8) {
1118 GST_ERROR_OBJECT (aacparse, "Unsupported audio profile or object type");
1121 channel_configuration =
1122 gst_aac_parse_get_audio_channel_configuration (aacparse->channels);
1123 if (channel_configuration == G_MAXUINT8) {
1124 GST_ERROR_OBJECT (aacparse, "Unsupported number of channels");
1127 sampling_frequency_index =
1128 gst_aac_parse_get_audio_sampling_frequency_index (aacparse->sample_rate);
1129 if (sampling_frequency_index == G_MAXUINT8) {
1130 GST_ERROR_OBJECT (aacparse, "Unsupported sampling frequency");
1134 frame->out_buffer = gst_buffer_copy (frame->buffer);
1135 buf_size = gst_buffer_get_size (frame->out_buffer);
1136 frame_size = buf_size + ADTS_HEADERS_LENGTH;
1138 if (G_UNLIKELY (frame_size >= 0x4000)) {
1139 GST_ERROR_OBJECT (aacparse, "Frame size is too big for ADTS");
1143 adts_headers = (guint8 *) g_malloc0 (ADTS_HEADERS_LENGTH);
1145 /* Note: no error correction bits are added to the resulting ADTS frames */
1146 adts_headers[0] = 0xFFU;
1147 adts_headers[1] = 0xF0U | (id << 3) | 0x1U;
1148 adts_headers[2] = (profile << 6) | (sampling_frequency_index << 2) | 0x2U |
1149 (channel_configuration & 0x4U);
1150 adts_headers[3] = ((channel_configuration & 0x3U) << 6) | 0x30U |
1151 (guint8) (frame_size >> 11);
1152 adts_headers[4] = (guint8) ((frame_size >> 3) & 0x00FF);
1153 adts_headers[5] = (guint8) (((frame_size & 0x0007) << 5) + 0x1FU);
1154 adts_headers[6] = 0xFCU;
1156 mem = gst_memory_new_wrapped (0, adts_headers, ADTS_HEADERS_LENGTH, 0,
1157 ADTS_HEADERS_LENGTH, adts_headers, g_free);
1158 gst_buffer_prepend_memory (frame->out_buffer, mem);
1164 * gst_aac_parse_check_valid_frame:
1165 * @parse: #GstBaseParse.
1166 * @frame: #GstBaseParseFrame.
1167 * @skipsize: How much data parent class should skip in order to find the
1170 * Implementation of "handle_frame" vmethod in #GstBaseParse class.
1172 * Also determines frame overhead.
1173 * ADTS streams have a 7 byte header in each frame. MP4 and ADIF streams don't have
1174 * a per-frame header. LOAS has 3 bytes.
1176 * We're making a couple of simplifying assumptions:
1178 * 1. We count Program Configuration Elements rather than searching for them
1179 * in the streams to discount them - the overhead is negligible.
1181 * 2. We ignore CRC. This has a worst-case impact of (num_raw_blocks + 1)*16
1182 * bits, which should still not be significant enough to warrant the
1183 * additional parsing through the headers
1185 * Returns: a #GstFlowReturn.
1187 static GstFlowReturn
1188 gst_aac_parse_handle_frame (GstBaseParse * parse,
1189 GstBaseParseFrame * frame, gint * skipsize)
1192 GstAacParse *aacparse;
1193 gboolean ret = FALSE;
1197 gint rate, channels;
1199 aacparse = GST_AAC_PARSE (parse);
1200 buffer = frame->buffer;
1202 gst_buffer_map (buffer, &map, GST_MAP_READ);
1205 lost_sync = GST_BASE_PARSE_LOST_SYNC (parse);
1207 if (aacparse->header_type == DSPAAC_HEADER_ADIF ||
1208 aacparse->header_type == DSPAAC_HEADER_NONE) {
1209 /* There is nothing to parse */
1210 framesize = map.size;
1213 } else if (aacparse->header_type == DSPAAC_HEADER_NOT_PARSED || lost_sync) {
1215 ret = gst_aac_parse_detect_stream (aacparse, map.data, map.size,
1216 GST_BASE_PARSE_DRAINING (parse), &framesize, skipsize);
1218 } else if (aacparse->header_type == DSPAAC_HEADER_ADTS) {
1219 guint needed_data = 1024;
1221 ret = gst_aac_parse_check_adts_frame (aacparse, map.data, map.size,
1222 GST_BASE_PARSE_DRAINING (parse), &framesize, &needed_data);
1224 if (!ret && needed_data) {
1225 GST_DEBUG ("buffer didn't contain valid frame");
1227 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
1231 } else if (aacparse->header_type == DSPAAC_HEADER_LOAS) {
1232 guint needed_data = 1024;
1234 ret = gst_aac_parse_check_loas_frame (aacparse, map.data,
1235 map.size, GST_BASE_PARSE_DRAINING (parse), &framesize, &needed_data);
1237 if (!ret && needed_data) {
1238 GST_DEBUG ("buffer didn't contain valid frame");
1240 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
1245 GST_DEBUG ("buffer didn't contain valid frame");
1246 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse),
1250 if (G_UNLIKELY (!ret))
1253 if (aacparse->header_type == DSPAAC_HEADER_ADTS) {
1255 frame->overhead = 7;
1257 gst_aac_parse_parse_adts_header (aacparse, map.data,
1258 &rate, &channels, NULL, NULL);
1260 GST_LOG_OBJECT (aacparse, "rate: %d, chans: %d", rate, channels);
1262 if (G_UNLIKELY (rate != aacparse->sample_rate
1263 || channels != aacparse->channels)) {
1264 aacparse->sample_rate = rate;
1265 aacparse->channels = channels;
1267 if (!gst_aac_parse_set_src_caps (aacparse, NULL)) {
1268 /* If linking fails, we need to return appropriate error */
1269 ret = GST_FLOW_NOT_LINKED;
1272 gst_base_parse_set_frame_rate (GST_BASE_PARSE (aacparse),
1273 aacparse->sample_rate, aacparse->frame_samples, 2, 2);
1275 } else if (aacparse->header_type == DSPAAC_HEADER_LOAS) {
1276 gboolean setcaps = FALSE;
1279 frame->overhead = 3;
1281 if (!gst_aac_parse_read_loas_config (aacparse, map.data, map.size, &rate,
1283 GST_WARNING_OBJECT (aacparse, "Error reading LOAS config");
1284 } else if (G_UNLIKELY (rate != aacparse->sample_rate
1285 || channels != aacparse->channels)) {
1286 aacparse->sample_rate = rate;
1287 aacparse->channels = channels;
1289 GST_INFO_OBJECT (aacparse, "New LOAS config: %d Hz, %d channels", rate,
1293 /* We want to set caps both at start, and when rate/channels change.
1294 Since only some LOAS frames have that info, we may receive frames
1295 before knowing about rate/channels. */
1297 || !gst_pad_has_current_caps (GST_BASE_PARSE_SRC_PAD (aacparse))) {
1298 if (!gst_aac_parse_set_src_caps (aacparse, NULL)) {
1299 /* If linking fails, we need to return appropriate error */
1300 ret = GST_FLOW_NOT_LINKED;
1303 gst_base_parse_set_frame_rate (GST_BASE_PARSE (aacparse),
1304 aacparse->sample_rate, aacparse->frame_samples, 2, 2);
1308 if (aacparse->header_type == DSPAAC_HEADER_NONE
1309 && aacparse->output_header_type == DSPAAC_HEADER_ADTS) {
1310 if (!gst_aac_parse_prepend_adts_headers (aacparse, frame)) {
1311 GST_ERROR_OBJECT (aacparse, "Failed to prepend ADTS headers to frame");
1312 ret = GST_FLOW_ERROR;
1317 gst_buffer_unmap (buffer, &map);
1320 /* found, skip if needed */
1329 if (ret && framesize <= map.size) {
1330 return gst_base_parse_finish_frame (parse, frame, framesize);
1336 static GstFlowReturn
1337 gst_aac_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
1339 GstAacParse *aacparse = GST_AAC_PARSE (parse);
1341 if (!aacparse->sent_codec_tag) {
1342 GstTagList *taglist;
1345 taglist = gst_tag_list_new_empty ();
1348 caps = gst_pad_get_current_caps (GST_BASE_PARSE_SRC_PAD (parse));
1349 gst_pb_utils_add_codec_description_to_tag_list (taglist,
1350 GST_TAG_AUDIO_CODEC, caps);
1351 gst_caps_unref (caps);
1353 gst_pad_push_event (GST_BASE_PARSE_SRC_PAD (aacparse),
1354 gst_event_new_tag (taglist));
1356 /* also signals the end of first-frame processing */
1357 aacparse->sent_codec_tag = TRUE;
1360 /* As a special case, we can remove the ADTS framing and output raw AAC. */
1361 if (aacparse->header_type == DSPAAC_HEADER_ADTS
1362 && aacparse->output_header_type == DSPAAC_HEADER_NONE) {
1365 gst_buffer_map (frame->buffer, &map, GST_MAP_READ);
1366 header_size = (map.data[1] & 1) ? 7 : 9; /* optional CRC */
1367 gst_buffer_unmap (frame->buffer, &map);
1368 gst_buffer_resize (frame->buffer, header_size,
1369 gst_buffer_get_size (frame->buffer) - header_size);
1377 * gst_aac_parse_start:
1378 * @parse: #GstBaseParse.
1380 * Implementation of "start" vmethod in #GstBaseParse class.
1382 * Returns: TRUE if startup succeeded.
1385 gst_aac_parse_start (GstBaseParse * parse)
1387 GstAacParse *aacparse;
1389 aacparse = GST_AAC_PARSE (parse);
1390 GST_DEBUG ("start");
1391 aacparse->frame_samples = 1024;
1392 gst_base_parse_set_min_frame_size (GST_BASE_PARSE (aacparse), ADTS_MAX_SIZE);
1393 aacparse->sent_codec_tag = FALSE;
1399 * gst_aac_parse_stop:
1400 * @parse: #GstBaseParse.
1402 * Implementation of "stop" vmethod in #GstBaseParse class.
1404 * Returns: TRUE is stopping succeeded.
1407 gst_aac_parse_stop (GstBaseParse * parse)
1414 remove_fields (GstCaps * caps)
1418 n = gst_caps_get_size (caps);
1419 for (i = 0; i < n; i++) {
1420 GstStructure *s = gst_caps_get_structure (caps, i);
1422 gst_structure_remove_field (s, "framed");
1427 add_conversion_fields (GstCaps * caps)
1431 n = gst_caps_get_size (caps);
1432 for (i = 0; i < n; i++) {
1433 GstStructure *s = gst_caps_get_structure (caps, i);
1435 if (gst_structure_has_field (s, "stream-format")) {
1436 const GValue *v = gst_structure_get_value (s, "stream-format");
1438 if (G_VALUE_HOLDS_STRING (v)) {
1439 const gchar *str = g_value_get_string (v);
1441 if (strcmp (str, "adts") == 0 || strcmp (str, "raw") == 0) {
1442 GValue va = G_VALUE_INIT;
1443 GValue vs = G_VALUE_INIT;
1445 g_value_init (&va, GST_TYPE_LIST);
1446 g_value_init (&vs, G_TYPE_STRING);
1447 g_value_set_string (&vs, "adts");
1448 gst_value_list_append_value (&va, &vs);
1449 g_value_set_string (&vs, "raw");
1450 gst_value_list_append_value (&va, &vs);
1451 gst_structure_set_value (s, "stream-format", &va);
1452 g_value_unset (&va);
1453 g_value_unset (&vs);
1455 } else if (GST_VALUE_HOLDS_LIST (v)) {
1456 gboolean contains_raw = FALSE;
1457 gboolean contains_adts = FALSE;
1458 guint m = gst_value_list_get_size (v), j;
1460 for (j = 0; j < m; j++) {
1461 const GValue *ve = gst_value_list_get_value (v, j);
1464 if (G_VALUE_HOLDS_STRING (ve) && (str = g_value_get_string (ve))) {
1465 if (strcmp (str, "adts") == 0)
1466 contains_adts = TRUE;
1467 else if (strcmp (str, "raw") == 0)
1468 contains_raw = TRUE;
1472 if (contains_adts || contains_raw) {
1473 GValue va = G_VALUE_INIT;
1474 GValue vs = G_VALUE_INIT;
1476 g_value_init (&va, GST_TYPE_LIST);
1477 g_value_init (&vs, G_TYPE_STRING);
1478 g_value_copy (v, &va);
1480 if (!contains_raw) {
1481 g_value_set_string (&vs, "raw");
1482 gst_value_list_append_value (&va, &vs);
1484 if (!contains_adts) {
1485 g_value_set_string (&vs, "adts");
1486 gst_value_list_append_value (&va, &vs);
1489 gst_structure_set_value (s, "stream-format", &va);
1491 g_value_unset (&vs);
1492 g_value_unset (&va);
1500 gst_aac_parse_sink_getcaps (GstBaseParse * parse, GstCaps * filter)
1502 GstCaps *peercaps, *templ;
1505 templ = gst_pad_get_pad_template_caps (GST_BASE_PARSE_SINK_PAD (parse));
1508 GstCaps *fcopy = gst_caps_copy (filter);
1509 /* Remove the fields we convert */
1510 remove_fields (fcopy);
1511 add_conversion_fields (fcopy);
1512 peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), fcopy);
1513 gst_caps_unref (fcopy);
1515 peercaps = gst_pad_peer_query_caps (GST_BASE_PARSE_SRC_PAD (parse), NULL);
1518 peercaps = gst_caps_make_writable (peercaps);
1519 /* Remove the fields we convert */
1520 remove_fields (peercaps);
1521 add_conversion_fields (peercaps);
1523 res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
1524 gst_caps_unref (peercaps);
1525 gst_caps_unref (templ);
1531 GstCaps *intersection;
1534 gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST);
1535 gst_caps_unref (res);