Re: [FFmpeg-devel] [PATCH 1/6] lavf/brstm: add support for BFSTM files
Dana 17. 6. 2015. 00:28 osoba Rodger Combs rodger.co...@gmail.com napisala je: --- libavcodec/utils.c | 4 ++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/brstm.c | 129 +++ 4 files changed, 115 insertions(+), 20 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 558afeb..a444a5e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3430,6 +3430,10 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) return (frame_bytes - 4) * 2 / ch; case AV_CODEC_ID_ADPCM_IMA_AMV: return (frame_bytes - 8) * 2 / ch; +case AV_CODEC_ID_ADPCM_THP: +if (avctx-extradata) +return frame_bytes * 14 / (8 * ch); +break; case AV_CODEC_ID_ADPCM_XA: return (frame_bytes / 128) * 224 / ch; case AV_CODEC_ID_INTERPLAY_DPCM: diff --git a/libavformat/Makefile b/libavformat/Makefile index b9169d9..3c2cf9f 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -106,6 +106,7 @@ OBJS-$(CONFIG_BIT_MUXER) += bit.o OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o OBJS-$(CONFIG_BRSTM_DEMUXER) += brstm.o +OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o Not in alphabetical order. OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ isom.o replaygain.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 3a49650..cc77d1c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -93,6 +93,7 @@ void av_register_all(void) REGISTER_MUXDEMUX(BIT, bit); REGISTER_DEMUXER (BMV, bmv); REGISTER_DEMUXER (BRSTM,brstm); +REGISTER_DEMUXER (BFSTM, bfstm); not in alphabetical order REGISTER_DEMUXER (BOA, boa); REGISTER_DEMUXER (C93, c93); REGISTER_MUXDEMUX(CAF, caf); diff --git a/libavformat/brstm.c b/libavformat/brstm.c index 19a4a2a..1eba943 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -32,6 +32,7 @@ typedef struct BRSTMDemuxContext { uint32_tlast_block_used_bytes; uint8_t *table; uint8_t *adpc; +int bfstm; } BRSTMDemuxContext; static int probe(AVProbeData *p) @@ -43,6 +44,15 @@ static int probe(AVProbeData *p) return 0; } +static int probe_bfstm(AVProbeData *p) +{ +if (AV_RL32(p-buf) == MKTAG('F','S','T','M') +(AV_RL16(p-buf + 4) == 0xFFFE || + AV_RL16(p-buf + 4) == 0xFEFF)) +return AVPROBE_SCORE_MAX / 3 * 2; +return 0; +} + static int read_close(AVFormatContext *s) { BRSTMDemuxContext *b = s-priv_data; @@ -57,11 +67,13 @@ static int read_header(AVFormatContext *s) { BRSTMDemuxContext *b = s-priv_data; int bom, major, minor, codec, chunk; -int64_t pos, h1offset, toffset; +int64_t h1offset, pos, toffset, data_offset = 0; uint32_t size, start, asize; AVStream *st; int ret = AVERROR_EOF; +b-bfstm = !strcmp(bfstm, s-iformat-name); + st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); @@ -79,19 +91,65 @@ static int read_header(AVFormatContext *s) return AVERROR_PATCHWELCOME; } -major = avio_r8(s-pb); -minor = avio_r8(s-pb); -avio_skip(s-pb, 4); // size of file -size = avio_rb16(s-pb); -if (size 14) -return AVERROR_INVALIDDATA; +if (!b-bfstm) { +major = avio_r8(s-pb); +minor = avio_r8(s-pb); +avio_skip(s-pb, 4); // size of file +size = avio_rb16(s-pb); +if (size 14) +return AVERROR_INVALIDDATA; + +avio_skip(s-pb, size - 14); +pos = avio_tell(s-pb); +if (avio_rl32(s-pb) != MKTAG('H','E','A','D')) +return AVERROR_INVALIDDATA; +} else { +uint32_t info_offset = 0, info_size; +uint16_t section_count, header_size, i; + +header_size = avio_rb16(s-pb); // 6 + +avio_skip(s-pb, 4); // Unknown constant 0x0003 +avio_skip(s-pb, 4); // size of file +section_count = avio_rb16(s-pb); +avio_skip(s-pb, 2); // padding +for (i = 0; avio_tell(s-pb) header_size + !(data_offset info_offset) + i section_count; i++) { +uint32_t flag = avio_rb32(s-pb); +switch (flag) { +case 0x4000: +info_offset = avio_rb32(s-pb); +info_size = avio_rb32(s-pb); +break; +case 0x4001:
[FFmpeg-devel] [PATCH 1/6] lavf/brstm: add support for BFSTM files
--- libavcodec/utils.c | 4 ++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/brstm.c | 129 +++ 4 files changed, 115 insertions(+), 20 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 558afeb..a444a5e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3430,6 +3430,10 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) return (frame_bytes - 4) * 2 / ch; case AV_CODEC_ID_ADPCM_IMA_AMV: return (frame_bytes - 8) * 2 / ch; +case AV_CODEC_ID_ADPCM_THP: +if (avctx-extradata) +return frame_bytes * 14 / (8 * ch); +break; case AV_CODEC_ID_ADPCM_XA: return (frame_bytes / 128) * 224 / ch; case AV_CODEC_ID_INTERPLAY_DPCM: diff --git a/libavformat/Makefile b/libavformat/Makefile index b9169d9..3c2cf9f 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -106,6 +106,7 @@ OBJS-$(CONFIG_BIT_MUXER) += bit.o OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o OBJS-$(CONFIG_BOA_DEMUXER) += boadec.o OBJS-$(CONFIG_BRSTM_DEMUXER) += brstm.o +OBJS-$(CONFIG_BFSTM_DEMUXER) += brstm.o OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ isom.o replaygain.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 3a49650..cc77d1c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -93,6 +93,7 @@ void av_register_all(void) REGISTER_MUXDEMUX(BIT, bit); REGISTER_DEMUXER (BMV, bmv); REGISTER_DEMUXER (BRSTM,brstm); +REGISTER_DEMUXER (BFSTM,bfstm); REGISTER_DEMUXER (BOA, boa); REGISTER_DEMUXER (C93, c93); REGISTER_MUXDEMUX(CAF, caf); diff --git a/libavformat/brstm.c b/libavformat/brstm.c index 19a4a2a..1eba943 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -32,6 +32,7 @@ typedef struct BRSTMDemuxContext { uint32_tlast_block_used_bytes; uint8_t *table; uint8_t *adpc; +int bfstm; } BRSTMDemuxContext; static int probe(AVProbeData *p) @@ -43,6 +44,15 @@ static int probe(AVProbeData *p) return 0; } +static int probe_bfstm(AVProbeData *p) +{ +if (AV_RL32(p-buf) == MKTAG('F','S','T','M') +(AV_RL16(p-buf + 4) == 0xFFFE || + AV_RL16(p-buf + 4) == 0xFEFF)) +return AVPROBE_SCORE_MAX / 3 * 2; +return 0; +} + static int read_close(AVFormatContext *s) { BRSTMDemuxContext *b = s-priv_data; @@ -57,11 +67,13 @@ static int read_header(AVFormatContext *s) { BRSTMDemuxContext *b = s-priv_data; int bom, major, minor, codec, chunk; -int64_t pos, h1offset, toffset; +int64_t h1offset, pos, toffset, data_offset = 0; uint32_t size, start, asize; AVStream *st; int ret = AVERROR_EOF; +b-bfstm = !strcmp(bfstm, s-iformat-name); + st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); @@ -79,19 +91,65 @@ static int read_header(AVFormatContext *s) return AVERROR_PATCHWELCOME; } -major = avio_r8(s-pb); -minor = avio_r8(s-pb); -avio_skip(s-pb, 4); // size of file -size = avio_rb16(s-pb); -if (size 14) -return AVERROR_INVALIDDATA; +if (!b-bfstm) { +major = avio_r8(s-pb); +minor = avio_r8(s-pb); +avio_skip(s-pb, 4); // size of file +size = avio_rb16(s-pb); +if (size 14) +return AVERROR_INVALIDDATA; + +avio_skip(s-pb, size - 14); +pos = avio_tell(s-pb); +if (avio_rl32(s-pb) != MKTAG('H','E','A','D')) +return AVERROR_INVALIDDATA; +} else { +uint32_t info_offset = 0, info_size; +uint16_t section_count, header_size, i; + +header_size = avio_rb16(s-pb); // 6 + +avio_skip(s-pb, 4); // Unknown constant 0x0003 +avio_skip(s-pb, 4); // size of file +section_count = avio_rb16(s-pb); +avio_skip(s-pb, 2); // padding +for (i = 0; avio_tell(s-pb) header_size + !(data_offset info_offset) + i section_count; i++) { +uint32_t flag = avio_rb32(s-pb); +switch (flag) { +case 0x4000: +info_offset = avio_rb32(s-pb); +info_size = avio_rb32(s-pb); +break; +case 0x4001: +avio_skip(s-pb, 4); // seek offset +avio_skip(s-pb, 4); // seek size +break; +case 0x4002: +data_offset = avio_rb32(s-pb); +avio_skip(s-pb, 4); //data_size =