summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorThomas Volkert <thomas@homer-conferencing.com>2014-12-19 21:57:05 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-19 22:39:29 +0100
commit1a971d33ebedff3cae01ee81da4fa74302a91492 (patch)
treea71580346d8d3a6b1b9c64da9d2e1014cdf95000 /libavformat
parentc3e6a55956fd4a8b59c8c7a52a64af24dfed7a5a (diff)
wavdec: refactor wav_read_header()
Make it more readable and display an error message in case an invalid header is detected (the current version just returns AVERROR_INVALIDDATA) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/wavdec.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 8a7f84b17c..4b452a62e8 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -248,7 +248,7 @@ static int wav_read_header(AVFormatContext *s)
{
int64_t size, av_uninit(data_size);
int64_t sample_count = 0;
- int rf64;
+ int rf64 = 0;
uint32_t tag;
AVIOContext *pb = s->pb;
AVStream *st = NULL;
@@ -260,17 +260,30 @@ static int wav_read_header(AVFormatContext *s)
wav->smv_data_ofs = -1;
- /* check RIFF header */
+ /* read chunk ID */
tag = avio_rl32(pb);
-
- rf64 = tag == MKTAG('R', 'F', '6', '4');
- wav->rifx = tag == MKTAG('R', 'I', 'F', 'X');
- if (!rf64 && !wav->rifx && tag != MKTAG('R', 'I', 'F', 'F'))
+ switch (tag) {
+ case MKTAG('R', 'I', 'F', 'F'):
+ break;
+ case MKTAG('R', 'I', 'F', 'X'):
+ wav->rifx = 1;
+ break;
+ case MKTAG('R', 'F', '6', '4'):
+ rf64 = 1;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "invalid start code %c%c%c%c in RIFF header\n", tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF);
return AVERROR_INVALIDDATA;
- avio_rl32(pb); /* file size */
- tag = avio_rl32(pb);
- if (tag != MKTAG('W', 'A', 'V', 'E'))
+ }
+
+ /* read chunk size */
+ avio_rl32(pb);
+
+ /* read format */
+ if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) {
+ av_log(s, AV_LOG_ERROR, "invalid format in RIFF header\n");
return AVERROR_INVALIDDATA;
+ }
if (rf64) {
if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))