diff options
Diffstat (limited to 'libavformat/riff.c')
-rw-r--r-- | libavformat/riff.c | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/libavformat/riff.c b/libavformat/riff.c index 99a8033732..c77d0225f7 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -2,20 +2,20 @@ * RIFF codec tags * Copyright (c) 2000 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -36,6 +36,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, { CODEC_ID_H264, MKTAG('D', 'A', 'V', 'C') }, { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') }, + { CODEC_ID_H264, MKTAG('Q', '2', '6', '4') }, /* QNAP surveillance system */ { CODEC_ID_H263, MKTAG('H', '2', '6', '3') }, { CODEC_ID_H263, MKTAG('X', '2', '6', '3') }, { CODEC_ID_H263, MKTAG('T', '2', '6', '3') }, @@ -88,6 +89,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') }, { CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') }, + { CODEC_ID_MPEG4, MKTAG('Q', 'M', 'P', '4') }, /* QNAP Systems */ { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, @@ -133,6 +135,8 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') }, { CODEC_ID_MPEG2VIDEO, MKTAG('M', '7', '0', '1') }, /* Matrox MPEG2 intra-only */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', 'v') }, + { CODEC_ID_MPEG1VIDEO, MKTAG('B', 'W', '1', '0') }, + { CODEC_ID_MPEG1VIDEO, MKTAG('X', 'M', 'P', 'G') }, /* Xing MPEG intra only */ { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') }, @@ -197,7 +201,11 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') }, { CODEC_ID_R210, MKTAG('r', '2', '1', '0') }, { CODEC_ID_V210, MKTAG('v', '2', '1', '0') }, + { CODEC_ID_V308, MKTAG('v', '3', '0', '8') }, + { CODEC_ID_V408, MKTAG('v', '4', '0', '8') }, + { CODEC_ID_AYUV, MKTAG('A', 'Y', 'U', 'V') }, { CODEC_ID_V410, MKTAG('v', '4', '1', '0') }, + { CODEC_ID_YUV4, MKTAG('y', 'u', 'v', '4') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') }, { CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') }, @@ -234,6 +242,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') }, { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') }, { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') }, + { CODEC_ID_FLV1, MKTAG('S', '2', '6', '3') }, { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') }, { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') }, @@ -277,12 +286,18 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, { CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') }, { CODEC_ID_LAGARITH, MKTAG('L', 'A', 'G', 'S') }, + { CODEC_ID_G2M, MKTAG('G', '2', 'M', '2') }, + { CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') }, + { CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') }, + { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') }, { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') }, { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') }, { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') }, { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') }, { CODEC_ID_VBLE, MKTAG('V', 'B', 'L', 'E') }, + { CODEC_ID_ESCAPE130, MKTAG('E', '1', '3', '0') }, { CODEC_ID_DXTORY, MKTAG('x', 't', 'o', 'r') }, + { CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') }, { CODEC_ID_NONE, 0 } }; @@ -302,6 +317,7 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_ADPCM_YAMAHA, 0x0020 }, { CODEC_ID_TRUESPEECH, 0x0022 }, { CODEC_ID_GSM_MS, 0x0031 }, + { CODEC_ID_AMR_NB, 0x0038 }, /* rogue format number */ { CODEC_ID_ADPCM_G726, 0x0045 }, { CODEC_ID_MP2, 0x0050 }, { CODEC_ID_MP3, 0x0055 }, @@ -327,6 +343,8 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_AAC_LATM, 0x1602 }, { CODEC_ID_AC3, 0x2000 }, { CODEC_ID_DTS, 0x2001 }, + { CODEC_ID_SONIC, 0x2048 }, + { CODEC_ID_SONIC_LS, 0x2048 }, { CODEC_ID_PCM_MULAW, 0x6c75 }, { CODEC_ID_AAC, 0x706d }, { CODEC_ID_AAC, 0x4143 }, @@ -343,6 +361,14 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_NONE, 0 }, }; +const AVCodecGuid ff_codec_wav_guids[] = { + {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, + {CODEC_ID_ATRAC3P, {0xBF,0xAA,0x23,0xE9,0x58,0xCB,0x71,0x44,0xA1,0x19,0xFF,0xFA,0x01,0xE4,0xCE,0x62}}, + {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}}, + {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, + {CODEC_ID_NONE} +}; + const AVMetadataConv ff_riff_info_conv[] = { { "IART", "artist" }, { "ICMT", "comment" }, @@ -471,7 +497,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) if(waveformatextensible) { /* write WAVEFORMATEXTENSIBLE extensions */ hdrsize += 22; avio_wl16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */ - avio_wl16(pb, enc->bits_per_coded_sample); /* ValidBitsPerSample || SamplesPerBlock || Reserved */ + avio_wl16(pb, bps); /* ValidBitsPerSample || SamplesPerBlock || Reserved */ avio_wl32(pb, enc->channel_layout); /* dwChannelMask */ avio_wl32(pb, enc->codec_tag); /* GUID + next 3 */ avio_wl32(pb, 0x00100000); @@ -501,7 +527,7 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *t avio_wl16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); /* depth */ /* compression type */ avio_wl32(pb, enc->codec_tag); - avio_wl32(pb, enc->width * enc->height * 3); + avio_wl32(pb, (enc->width * enc->height * (enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24)+7) / 8); avio_wl32(pb, 0); avio_wl32(pb, 0); avio_wl32(pb, 0); @@ -528,7 +554,6 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) id = avio_rl16(pb); codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->codec_tag = id; codec->channels = avio_rl16(pb); codec->sample_rate = avio_rl32(pb); codec->bit_rate = avio_rl32(pb) * 8; @@ -537,15 +562,29 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) codec->bits_per_coded_sample = 8; }else codec->bits_per_coded_sample = avio_rl16(pb); + if (id == 0xFFFE) { + codec->codec_tag = 0; + } else { + codec->codec_tag = id; + codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); + } if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */ int cbSize = avio_rl16(pb); /* cbSize */ size -= 18; cbSize = FFMIN(size, cbSize); if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */ + ff_asf_guid subformat; codec->bits_per_coded_sample = avio_rl16(pb); codec->channel_layout = avio_rl32(pb); /* dwChannelMask */ - id = avio_rl32(pb); /* 4 first bytes of GUID */ - avio_skip(pb, 12); /* skip end of GUID */ + ff_get_guid(pb, &subformat); + if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { + codec->codec_tag = AV_RL32(subformat); + codec->codec_id = ff_wav_codec_get_id(codec->codec_tag, codec->bits_per_coded_sample); + } else { + codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat); + if (!codec->codec_id) + av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat)); + } cbSize -= 22; size -= 22; } @@ -563,7 +602,6 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) if (size > 0) avio_skip(pb, size); } - codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); if (codec->codec_id == CODEC_ID_AAC_LATM) { /* channels and sample_rate values are those prior to applying SBR and/or PS */ codec->channels = 0; @@ -637,6 +675,23 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz *au_rate /= gcd; } +void ff_get_guid(AVIOContext *s, ff_asf_guid *g) +{ + assert(sizeof(*g) == 16); + if (avio_read(s, *g, sizeof(*g)) < (int)sizeof(*g)) + memset(*g, 0, sizeof(*g)); +} + +enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid) +{ + int i; + for (i = 0; guids[i].id != CODEC_ID_NONE; i++) { + if (!ff_guidcmp(guids[i].guid, guid)) + return guids[i].id; + } + return CODEC_ID_NONE; +} + int ff_read_riff_info(AVFormatContext *s, int64_t size) { int64_t start, end, cur; @@ -669,7 +724,7 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size) AV_WL32(key, chunk_code); if (avio_read(pb, value, chunk_size) != chunk_size) { - av_free(value); + av_freep(&value); av_log(s, AV_LOG_ERROR, "premature end of file while reading INFO tag\n"); return AVERROR_INVALIDDATA; } |