gst/auparse/gstauparse.c: limit caps to the formats we announce in the template

Original commit message from CVS:
* gst/auparse/gstauparse.c: (gst_au_parse_parse_header):
limit caps to the formats we announce in the template
* gst/wavparse/gstwavparse.c: (uint64_ceiling_scale_int),
(gst_wavparse_perform_seek), (gst_wavparse_stream_headers),
(gst_wavparse_add_src_pad), (gst_wavparse_stream_data):
fix some crashers/asserts when dealing with broken files
This commit is contained in:
Stefan Kost 2007-04-10 12:01:33 +00:00
parent 50f88db3ad
commit 497d589d56
3 changed files with 65 additions and 25 deletions

View file

@ -1,3 +1,13 @@
2007-04-10 Stefan Kost <ensonic@users.sf.net>
* gst/auparse/gstauparse.c: (gst_au_parse_parse_header):
limit caps to the formats we announce in the template
* gst/wavparse/gstwavparse.c: (uint64_ceiling_scale_int),
(gst_wavparse_perform_seek), (gst_wavparse_stream_headers),
(gst_wavparse_add_src_pad), (gst_wavparse_stream_data):
fix some crashers/asserts when dealing with broken files
2007-04-10 Wim Taymans <wim@fluendo.com> 2007-04-10 Wim Taymans <wim@fluendo.com>
Patch by: Peter Kjellerstedt <pkj at axis com> Patch by: Peter Kjellerstedt <pkj at axis com>

View file

@ -21,7 +21,7 @@
/** /**
* SECTION:element-auparse * SECTION:element-auparse
* @short_description: .au file parser * @short_description: .au file parser
* *
* <refsect2> * <refsect2>
* <para> * <para>
* Parses .au files. * Parses .au files.
@ -269,6 +269,12 @@ gst_au_parse_parse_header (GstAuParse * auparse)
auparse->samplerate = GST_READ_UINT32_BE (head + 16); auparse->samplerate = GST_READ_UINT32_BE (head + 16);
auparse->channels = GST_READ_UINT32_BE (head + 20); auparse->channels = GST_READ_UINT32_BE (head + 20);
if (auparse->samplerate < 8000 || auparse->samplerate > 192000)
goto unsupported_sample_rate;
if (auparse->channels < 1 || auparse->channels > 2)
goto unsupported_number_of_channels;
GST_DEBUG_OBJECT (auparse, "offset %" G_GINT64_FORMAT ", size %u, " GST_DEBUG_OBJECT (auparse, "offset %" G_GINT64_FORMAT ", size %u, "
"encoding %u, frequency %u, channels %u", auparse->offset, size, "encoding %u, frequency %u, channels %u", auparse->offset, size,
auparse->encoding, auparse->samplerate, auparse->channels); auparse->encoding, auparse->samplerate, auparse->channels);
@ -402,9 +408,22 @@ unknown_header:
GST_ELEMENT_ERROR (auparse, STREAM, WRONG_TYPE, (NULL), (NULL)); GST_ELEMENT_ERROR (auparse, STREAM, WRONG_TYPE, (NULL), (NULL));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
unsupported_sample_rate:
{
GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL),
("Unsupported samplerate: %u", auparse->samplerate));
return GST_FLOW_ERROR;
}
unsupported_number_of_channels:
{
GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL),
("Unsupported number of channels: %u", auparse->channels));
return GST_FLOW_ERROR;
}
unknown_format: unknown_format:
{ {
GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL), (NULL)); GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL),
("Unsupported encoding: %u", auparse->encoding));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
add_pad_failed: add_pad_failed:

View file

@ -133,11 +133,16 @@ static GstStaticPadTemplate src_template_factory =
"layer = (int) [ 1, 3 ], " "layer = (int) [ 1, 3 ], "
"rate = (int) [ 8000, 48000 ], " "rate = (int) [ 8000, 48000 ], "
"channels = (int) [ 1, 2 ]; " "channels = (int) [ 1, 2 ]; "
"audio/mpeg, "
"mpegversion = (int) 4, "
"rate = (int) [ 8000, 48000 ], "
"channels = (int) [ 1, 8 ]; "
"audio/x-alaw, " "audio/x-alaw, "
"rate = (int) [ 8000, 48000 ], " "rate = (int) [ 8000, 48000 ], "
"channels = (int) [ 1, 2 ]; " "channels = (int) [ 1, 2 ]; "
"audio/x-mulaw, " "audio/x-mulaw, "
"rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ];" "rate = (int) [ 8000, 48000 ], "
"channels = (int) [ 1, 2 ];"
"audio/x-adpcm, " "audio/x-adpcm, "
"layout = (string) microsoft, " "layout = (string) microsoft, "
"block_align = (int) [ 1, 8192 ], " "block_align = (int) [ 1, 8192 ], "
@ -146,7 +151,8 @@ static GstStaticPadTemplate src_template_factory =
"audio/x-adpcm, " "audio/x-adpcm, "
"layout = (string) dvi, " "layout = (string) dvi, "
"block_align = (int) [ 1, 8192 ], " "block_align = (int) [ 1, 8192 ], "
"rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ];" "rate = (int) [ 8000, 48000 ], "
"channels = (int) [ 1, 2 ];"
"audio/x-vnd.sony.atrac3;" "audio/x-vnd.sony.atrac3;"
"audio/x-dts;" "audio/x-wma, " "wmaversion = (int) [ 1, 2 ]") "audio/x-dts;" "audio/x-wma, " "wmaversion = (int) [ 1, 2 ]")
); );
@ -761,7 +767,7 @@ gst_wavparse_stream_init (GstWavParse * wav)
return GST_FLOW_OK; return GST_FLOW_OK;
} }
/* This function is used to perform seeks on the element in /* This function is used to perform seeks on the element in
* pull mode. * pull mode.
* *
* It also works when event is NULL, in which case it will just * It also works when event is NULL, in which case it will just
@ -979,8 +985,8 @@ no_format:
* @wav Wavparse object * @wav Wavparse object
* @tag holder for tag * @tag holder for tag
* @size holder for tag size * @size holder for tag size
* *
* Peek next chunk info (tag and size) * Peek next chunk info (tag and size)
* *
* Returns: %TRUE when one chunk info has been got from the adapter * Returns: %TRUE when one chunk info has been got from the adapter
*/ */
@ -1101,6 +1107,11 @@ gst_wavparse_stream_headers (GstWavParse * wav)
buf = NULL; /* parse_strf_auds() took ownership of buffer */ buf = NULL; /* parse_strf_auds() took ownership of buffer */
if (header->channels == 0)
goto no_channels;
GST_DEBUG_OBJECT (wav, "creating the caps");
/* Note: gst_riff_create_audio_caps might need to fix values in /* Note: gst_riff_create_audio_caps might need to fix values in
* the header header depending on the format, so call it first */ * the header header depending on the format, so call it first */
caps = gst_riff_create_audio_caps (header->format, NULL, header, extra, caps = gst_riff_create_audio_caps (header->format, NULL, header, extra,
@ -1109,6 +1120,9 @@ gst_wavparse_stream_headers (GstWavParse * wav)
if (extra) if (extra)
gst_buffer_unref (extra); gst_buffer_unref (extra);
if (!caps)
goto unknown_format;
wav->format = header->format; wav->format = header->format;
wav->rate = header->rate; wav->rate = header->rate;
wav->channels = header->channels; wav->channels = header->channels;
@ -1118,9 +1132,6 @@ gst_wavparse_stream_headers (GstWavParse * wav)
g_free (header); g_free (header);
if (wav->channels == 0)
goto no_channels;
/* do format specific handling */ /* do format specific handling */
switch (wav->format) { switch (wav->format) {
case GST_RIFF_WAVE_FORMAT_MPEGL12: case GST_RIFF_WAVE_FORMAT_MPEGL12:
@ -1144,9 +1155,6 @@ gst_wavparse_stream_headers (GstWavParse * wav)
if (wav->bytes_per_sample <= 0) if (wav->bytes_per_sample <= 0)
goto no_bytes_per_sample; goto no_bytes_per_sample;
if (!caps)
goto unknown_format;
GST_DEBUG_OBJECT (wav, "blockalign = %u", (guint) wav->blockalign); GST_DEBUG_OBJECT (wav, "blockalign = %u", (guint) wav->blockalign);
GST_DEBUG_OBJECT (wav, "width = %u", (guint) wav->width); GST_DEBUG_OBJECT (wav, "width = %u", (guint) wav->width);
GST_DEBUG_OBJECT (wav, "depth = %u", (guint) wav->depth); GST_DEBUG_OBJECT (wav, "depth = %u", (guint) wav->depth);
@ -1323,7 +1331,6 @@ parse_header_error:
{ {
GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL), GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL),
("Couldn't parse audio header")); ("Couldn't parse audio header"));
gst_buffer_unref (buf);
g_free (codec_name); g_free (codec_name);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -1339,7 +1346,6 @@ no_bytes_per_sample:
{ {
GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
("could not caluclate bytes per sample - invalid data")); ("could not caluclate bytes per sample - invalid data"));
g_free (header);
g_free (codec_name); g_free (codec_name);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -1348,6 +1354,7 @@ unknown_format:
GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL), GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL),
("No caps found for format 0x%x, %d channels, %d Hz", ("No caps found for format 0x%x, %d channels, %d Hz",
wav->format, wav->channels, wav->rate)); wav->format, wav->channels, wav->rate));
g_free (header);
g_free (codec_name); g_free (codec_name);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -1359,7 +1366,7 @@ header_read_error:
} }
} }
/* /*
* Read WAV file tag when streaming * Read WAV file tag when streaming
*/ */
static GstFlowReturn static GstFlowReturn
@ -1432,17 +1439,21 @@ gst_wavparse_add_src_pad (GstWavParse * wav, GstBuffer * buf)
GstStructure *s; GstStructure *s;
const guint8 dts_marker[] = { 0xFF, 0x1F, 0x00, 0xE8, 0xF1, 0x07 }; const guint8 dts_marker[] = { 0xFF, 0x1F, 0x00, 0xE8, 0xF1, 0x07 };
s = gst_caps_get_structure (wav->caps, 0); GST_DEBUG_OBJECT (wav, "adding src pad");
if (s && gst_structure_has_name (s, "audio/x-raw-int") && buf &&
GST_BUFFER_SIZE (buf) > 6 &&
memcmp (GST_BUFFER_DATA (buf), dts_marker, 6) == 0) {
GST_WARNING_OBJECT (wav, "Found DTS marker in file marked as raw PCM"); if (wav->caps) {
gst_caps_unref (wav->caps); s = gst_caps_get_structure (wav->caps, 0);
wav->caps = gst_caps_from_string ("audio/x-dts"); if (s && gst_structure_has_name (s, "audio/x-raw-int") && buf &&
GST_BUFFER_SIZE (buf) > 6 &&
memcmp (GST_BUFFER_DATA (buf), dts_marker, 6) == 0) {
gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE, GST_WARNING_OBJECT (wav, "Found DTS marker in file marked as raw PCM");
GST_TAG_AUDIO_CODEC, "dts", NULL); gst_caps_unref (wav->caps);
wav->caps = gst_caps_from_string ("audio/x-dts");
gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE,
GST_TAG_AUDIO_CODEC, "dts", NULL);
}
} }
gst_wavparse_create_sourcepad (wav); gst_wavparse_create_sourcepad (wav);