Hi, patch attached.
From 1c46c6aec755b4e18be6c0f69f8c278c9de9a4b4 Mon Sep 17 00:00:00 2001 From: Peter Ross <pr...@xvid.org> Date: Thu, 5 May 2016 21:21:27 +0200 Subject: [PATCH] avcodec: add Direct Stream Transfer (DST) decoder
Signed-off-by: Paul B Mahol <one...@gmail.com> --- libavcodec/Makefile | 9 +- libavcodec/allcodecs.c | 1 + libavcodec/avcodec.h | 1 + libavcodec/codec_desc.c | 7 + libavcodec/dsd_tablegen.h | 18 +-- libavcodec/dsddec.c | 63 +------- libavcodec/dstdec.c | 394 ++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/utils.c | 2 + libavformat/iff.c | 71 ++++++++- 9 files changed, 483 insertions(+), 83 deletions(-) create mode 100644 libavcodec/dstdec.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 835b803..9a1578a 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -242,13 +242,14 @@ OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o -OBJS-$(CONFIG_DSD_LSBF_DECODER) += dsddec.o -OBJS-$(CONFIG_DSD_MSBF_DECODER) += dsddec.o -OBJS-$(CONFIG_DSD_LSBF_PLANAR_DECODER) += dsddec.o -OBJS-$(CONFIG_DSD_MSBF_PLANAR_DECODER) += dsddec.o +OBJS-$(CONFIG_DSD_LSBF_DECODER) += dsddec.o dsd.o +OBJS-$(CONFIG_DSD_MSBF_DECODER) += dsddec.o dsd.o +OBJS-$(CONFIG_DSD_LSBF_PLANAR_DECODER) += dsddec.o dsd.o +OBJS-$(CONFIG_DSD_MSBF_PLANAR_DECODER) += dsddec.o dsd.o OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinaudio.o OBJS-$(CONFIG_DSICINVIDEO_DECODER) += dsicinvideo.o OBJS-$(CONFIG_DSS_SP_DECODER) += dss_sp.o +OBJS-$(CONFIG_DST_DECODER) += dstdec.o dsd.o OBJS-$(CONFIG_DVBSUB_DECODER) += dvbsubdec.o OBJS-$(CONFIG_DVBSUB_ENCODER) += dvbsub.o OBJS-$(CONFIG_DVDSUB_DECODER) += dvdsubdec.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 2b46a13..a86516a 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -394,6 +394,7 @@ void avcodec_register_all(void) REGISTER_DECODER(DSD_MSBF_PLANAR, dsd_msbf_planar); REGISTER_DECODER(DSICINAUDIO, dsicinaudio); REGISTER_DECODER(DSS_SP, dss_sp); + REGISTER_DECODER(DST, dst); REGISTER_ENCDEC (EAC3, eac3); REGISTER_DECODER(EVRC, evrc); REGISTER_DECODER(FFWAVESYNTH, ffwavesynth); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 161ee9d..d81b78e 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -590,6 +590,7 @@ enum AVCodecID { AV_CODEC_ID_INTERPLAY_ACM, AV_CODEC_ID_XMA1, AV_CODEC_ID_XMA2, + AV_CODEC_ID_DST, /* subtitle codecs */ AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 7b48ee6..80fcf59 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -2676,6 +2676,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("Xbox Media Audio 2"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_DST, + .type = AVMEDIA_TYPE_AUDIO, + .name = "dst", + .long_name = NULL_IF_CONFIG_SMALL("DST (Direct Stream Transfer)"), + .props = AV_CODEC_PROP_LOSSLESS, + }, /* subtitle codecs */ { diff --git a/libavcodec/dsd_tablegen.h b/libavcodec/dsd_tablegen.h index 990d57a..e5da86a 100644 --- a/libavcodec/dsd_tablegen.h +++ b/libavcodec/dsd_tablegen.h @@ -25,6 +25,7 @@ #include <stdint.h> #include "libavutil/attributes.h" +#include "dsd.h" #define HTAPS 48 /** number of FIR constants */ #define CTABLES ((HTAPS + 7) / 8) /** number of "8 MACs" lookup tables */ @@ -71,21 +72,4 @@ static const double htaps[HTAPS] = { }; static float ctables[CTABLES][256]; - -static av_cold void dsd_ctables_tableinit(void) -{ - int t, e, m, sign; - double acc[CTABLES]; - for (e = 0; e < 256; ++e) { - memset(acc, 0, sizeof(acc)); - for (m = 0; m < 8; ++m) { - sign = (((e >> (7 - m)) & 1) * 2 - 1); - for (t = 0; t < CTABLES; ++t) - acc[t] += sign * htaps[t * 8 + m]; - } - for (t = 0; t < CTABLES; ++t) - ctables[CTABLES - 1 - t][e] = acc[t]; - } -} - #endif /* AVCODEC_DSD_TABLEGEN_H */ diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c index f1dfd4b..880d691 100644 --- a/libavcodec/dsddec.c +++ b/libavcodec/dsddec.c @@ -29,71 +29,14 @@ #include "libavcodec/internal.h" #include "libavcodec/mathops.h" #include "avcodec.h" -#include "dsd_tablegen.h" - -#define FIFOSIZE 16 /** must be a power of two */ -#define FIFOMASK (FIFOSIZE - 1) /** bit mask for FIFO offsets */ - -#if FIFOSIZE * 8 < HTAPS * 2 -#error "FIFOSIZE too small" -#endif - -/** - * Per-channel buffer - */ -typedef struct { - unsigned char buf[FIFOSIZE]; - unsigned pos; -} DSDContext; - -static void dsd2pcm_translate(DSDContext* s, size_t samples, int lsbf, - const unsigned char *src, ptrdiff_t src_stride, - float *dst, ptrdiff_t dst_stride) -{ - unsigned pos, i; - unsigned char* p; - double sum; - - pos = s->pos; - - while (samples-- > 0) { - s->buf[pos] = lsbf ? ff_reverse[*src] : *src; - src += src_stride; - - p = s->buf + ((pos - CTABLES) & FIFOMASK); - *p = ff_reverse[*p]; - - sum = 0.0; - for (i = 0; i < CTABLES; i++) { - unsigned char a = s->buf[(pos - i) & FIFOMASK]; - unsigned char b = s->buf[(pos - (CTABLES*2 - 1) + i) & FIFOMASK]; - sum += ctables[i][a] + ctables[i][b]; - } - - *dst = (float)sum; - dst += dst_stride; - - pos = (pos + 1) & FIFOMASK; - } - - s->pos = pos; -} - -static av_cold void init_static_data(void) -{ - static int done = 0; - if (done) - return; - dsd_ctables_tableinit(); - done = 1; -} +#include "dsd.h" static av_cold int decode_init(AVCodecContext *avctx) { DSDContext * s; int i; - init_static_data(); + ff_init_dsd_data(); s = av_malloc_array(sizeof(DSDContext), avctx->channels); if (!s) @@ -140,7 +83,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, for (i = 0; i < avctx->channels; i++) { float * dst = ((float **)frame->extended_data)[i]; - dsd2pcm_translate(&s[i], frame->nb_samples, lsbf, + ff_dsd2pcm_translate(&s[i], frame->nb_samples, lsbf, avpkt->data + i * src_next, src_stride, dst, 1); } diff --git a/libavcodec/dstdec.c b/libavcodec/dstdec.c new file mode 100644 index 0000000..533dba5 --- /dev/null +++ b/libavcodec/dstdec.c @@ -0,0 +1,394 @@ +/* + * Direct Stream Transfer (DST) decoder + * Copyright (c) 2014 Peter Ross <pr...@xvid.org> + * + * This file is part of FFmpeg. + * + * 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. + * + * 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Direct Stream Transfer (DST) decoder + * ISO/IEC 14496-3 Part 3 Subpart 10: Technical description of lossless coding of oversampled audio + */ + +#include "libavutil/avassert.h" +#include "internal.h" +#include "get_bits.h" +#include "avcodec.h" +#include "golomb.h" +#include "mathops.h" +#include "dsd.h" + +#define DST_MAX_CHANNELS 6 +#define DST_MAX_ELEMENTS (2 * DST_MAX_CHANNELS) + +#define DSD_FS44(sample_rate) (sample_rate * 8 / 44100) + +#define DST_SAMPLES_PER_FRAME(sample_rate) (588 * DSD_FS44(sample_rate)) + +static const int8_t fsets_code_pred_coeff[3][3] = { + { -8 }, + { -16, 8 }, + { -9, -5, 6 }, +}; + +static const int8_t probs_code_pred_coeff[3][3] = { + { -8 }, + { -16, 8 }, + { -24, 24, -8 }, +}; + +typedef struct Table { + unsigned int elements; + unsigned int length[DST_MAX_ELEMENTS]; + int coeff[DST_MAX_ELEMENTS][128]; +} Table; + +typedef struct DSTContext { + AVClass *class; + + Table fsets, probs; + uint8_t status[DST_MAX_CHANNELS][16]; + DECLARE_ALIGNED(16, int16_t, filter)[DST_MAX_ELEMENTS][16][256]; + DSDContext dsdctx[DST_MAX_CHANNELS]; + + uint8_t *dsddata; +} DSTContext; + +static int allocate_buffers(AVCodecContext *avctx) +{ + DSTContext *s = avctx->priv_data; + + s->dsddata = av_calloc(DST_SAMPLES_PER_FRAME(avctx->sample_rate), avctx->channels * sizeof(*s->dsddata)); + if (!s->dsddata) + return AVERROR(ENOMEM); + return 0; +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + DSTContext *s = avctx->priv_data; + int i, ret; + + if (avctx->channels > DST_MAX_CHANNELS) { + avpriv_request_sample(avctx, "Channel count %d", avctx->channels); + return AVERROR_PATCHWELCOME; + } + + if ((ret = allocate_buffers(avctx)) < 0) + return ret; + + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + + for (i = 0; i < avctx->channels; i++) + memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf)); + + ff_init_dsd_data(); + + return 0; +} + +static av_cold int decode_close(AVCodecContext *avctx) +{ + DSTContext *s = avctx->priv_data; + + av_freep(&s->dsddata); + + return 0; +} + +static int read_map(GetBitContext *gb, Table *t, unsigned int map[DST_MAX_CHANNELS], int channels) +{ + int ch; + t->elements = 1; + map[0] = 0; + if (!get_bits1(gb)) { + for (ch = 1; ch < channels; ch++) { + int bits = av_log2(t->elements) + 1; + map[ch] = get_bits(gb, bits); + if (map[ch] == t->elements) { + t->elements++; + if (t->elements >= DST_MAX_ELEMENTS) + return AVERROR_INVALIDDATA; + } else if (map[ch] > t->elements) { + return AVERROR_INVALIDDATA; + } + } + } else { + memset(map, 0, sizeof(*map) * DST_MAX_CHANNELS); + } + return 0; +} + +static av_always_inline int get_sr_golomb_dst(GetBitContext *gb, unsigned int k) +{ + int v = get_ur_golomb(gb, k, get_bits_left(gb), 0); + if (v && get_bits1(gb)) + v = -v; + return v; +} + +static void read_uncoded_coeff(GetBitContext *gb, int *dst, unsigned int elements, + int coeff_bits, int is_signed, int offset) +{ + int i; + + for (i = 0; i < elements; i++) { + dst[i] = (is_signed ? get_sbits(gb, coeff_bits) : get_bits(gb, coeff_bits)) + offset; + } +} + +static int read_table(GetBitContext *gb, Table *t, const int8_t code_pred_coeff[3][3], + int length_bits, int coeff_bits, int is_signed, int offset) +{ + unsigned int i, j, k; + for (i = 0; i < t->elements; i++) { + t->length[i] = get_bits(gb, length_bits) + 1; + if (!get_bits1(gb)) { + read_uncoded_coeff(gb, t->coeff[i], t->length[i], coeff_bits, is_signed, offset); + } else { + int method = get_bits(gb, 2), lsb_size; + if (method == 3) + return AVERROR_INVALIDDATA; + + read_uncoded_coeff(gb, t->coeff[i], method + 1, coeff_bits, is_signed, offset); + + lsb_size = get_bits(gb, 3); + for (j = method + 1; j < t->length[i]; j++) { + int c, x = 0; + for (k = 0; k < method + 1; k++) + x += code_pred_coeff[method][k] * t->coeff[i][j - k - 1]; + c = get_sr_golomb_dst(gb, lsb_size); + if (x >= 0) + c -= (x + 4) / 8; + else + c += (-x + 3) / 8; + t->coeff[i][j] = c; + } + } + } + return 0; +} + +typedef struct Arith { + unsigned int a; + unsigned int c; +} Arith; + +static void ac_init(Arith * ac, GetBitContext *gb) +{ + ac->a = 4095; + ac->c = get_bits(gb, 12); +} + +#define AC_GET(ac, re, gb, p, e) \ +{ \ + unsigned int k = ((ac)->a >> 8) | (((ac)->a >> 7) & 1); \ + unsigned int q = k * (p); \ + unsigned int a_q = (ac)->a - q; \ + (e) = (ac)->c < a_q; \ + if ((e)) { \ + (ac)->a = a_q; \ + } else { \ + (ac)->a = q; \ + (ac)->c -= a_q; \ + } \ + if ((ac)->a < 2048) { \ + int n = 11 - av_log2((ac)->a); \ + (ac)->a <<= n; \ + (ac)->c = ((ac)->c << n) | SHOW_UBITS(re, (gb), n); \ + SKIP_BITS(re, gb, n); \ + UPDATE_CACHE(re, (gb)); \ + } \ +} + +static uint8_t prob_dst_x_bit(int c) +{ + return (ff_reverse[c & 127] >> 1) + 1; +} + +static void build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets) +{ + int i, j, k, l; + + for (i = 0; i < fsets->elements; i++) { + int length = fsets->length[i]; + + for (j = 0; j < 16; j++) { + int total = av_clip(length - j * 8, 0, 8); + + for (k = 0; k < 256; k++) { + int v = 0; + + for (l = 0; l < total; l++) + v += (((k >> l) & 1) * 2 - 1) * fsets->coeff[i][j * 8 + l]; + table[i][j][k] = v; + } + } + } +} + +static int decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + unsigned int samples_per_frame = DST_SAMPLES_PER_FRAME(avctx->sample_rate); + unsigned map_ch_to_felem[DST_MAX_CHANNELS]; + unsigned map_ch_to_pelem[DST_MAX_CHANNELS]; + unsigned int i, ch, same_map, dst_x_bit; + unsigned half_prob[DST_MAX_CHANNELS]; + DSTContext *s = avctx->priv_data; + GetBitContext gb; + AVFrame *frame = data; + Arith ac; + int ret; + + if (avpkt->size <= 1) + return AVERROR_INVALIDDATA; + + frame->nb_samples = samples_per_frame / 8; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; + + if ((ret = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0) + return ret; + + if (!get_bits1(&gb)) { + skip_bits1(&gb); + if (get_bits(&gb, 6)) + return AVERROR_INVALIDDATA; + memcpy(s->dsddata, avpkt->data + 1, FFMIN(avpkt->size - 1, frame->nb_samples * avctx->channels)); + goto dsd; + } + + /* Segmentation (10.4, 10.5, 10.6) */ + + if (!get_bits1(&gb)) { + avpriv_request_sample(avctx, "Not Same Segmentation"); + return AVERROR_PATCHWELCOME; + } + + if (!get_bits1(&gb)) { + avpriv_request_sample(avctx, "Not Same Segmentation For All Channels"); + return AVERROR_PATCHWELCOME; + } + + if (!get_bits1(&gb)) { + avpriv_request_sample(avctx, "Not End Of Channel Segmentation"); + return AVERROR_PATCHWELCOME; + } + + /* Mapping (10.7, 10.8, 10.9) */ + + same_map = get_bits1(&gb); + + if ((ret = read_map(&gb, &s->fsets, map_ch_to_felem, avctx->channels)) < 0) + return ret; + + if (same_map) { + s->probs.elements = s->fsets.elements; + memcpy(map_ch_to_pelem, map_ch_to_felem, sizeof(map_ch_to_felem)); + } else { + avpriv_request_sample(avctx, "Not Same Mapping"); + if ((ret = read_map(&gb, &s->probs, map_ch_to_pelem, avctx->channels)) < 0) + return ret; + } + + /* Half Probability (10.10) */ + + for (ch = 0; ch < avctx->channels; ch++) + half_prob[ch] = get_bits1(&gb); + + /* Filter Coef Sets (10.12) */ + + read_table(&gb, &s->fsets, fsets_code_pred_coeff, 7, 9, 1, 0); + + /* Probability Tables (10.13) */ + + read_table(&gb, &s->probs, probs_code_pred_coeff, 6, 7, 0, 1); + + /* Arithmetic Coded Data (10.11) */ + + if (get_bits1(&gb)) + return AVERROR_INVALIDDATA; + ac_init(&ac, &gb); + + build_filter(s->filter, &s->fsets); + + memset(s->status, 0xAA, sizeof(s->status)); + memset(s->dsddata, 0, sizeof(*s->dsddata) * DST_SAMPLES_PER_FRAME(avctx->sample_rate) * avctx->channels); + + OPEN_READER(re, &gb); + UPDATE_CACHE(re, &gb); + AC_GET(&ac, re, &gb, prob_dst_x_bit(s->fsets.coeff[0][0]), dst_x_bit); + + for (i = 0; i < samples_per_frame; i++) { + for (ch = 0; ch < avctx->channels; ch++) { + unsigned int felem = map_ch_to_felem[ch], prob, residual, v; + uint64_t *st = (uint64_t*)s->status[ch]; + const uint8_t *status = s->status[ch]; + const int16_t (*filter)[256] = s->filter[felem]; + +#define F(x) filter[(x)][status[(x)]] + int16_t predict = F( 0) + F( 1) + F( 2) + F( 3) + + F( 4) + F( 5) + F( 6) + F( 7) + + F( 8) + F( 9) + F(10) + F(11) + + F(12) + F(13) + F(14) + F(15); +#undef F + + if (!half_prob[ch] || i >= s->fsets.length[felem]) { + unsigned int pelem = map_ch_to_pelem[ch]; + unsigned int index = FFABS(predict) >> 3; + prob = s->probs.coeff[pelem][FFMIN(index, s->probs.length[pelem] - 1)]; + } else { + prob = 128; + } + + AC_GET(&ac, re, &gb, prob, residual); + v = ((((uint16_t)predict) >> 15) ^ residual) & 1; + s->dsddata[(i >> 3) * avctx->channels + ch] |= v << (7 - (i & 0x7 )); + + st[1] = (st[1] << 1) | ((st[0] >> 63) & 1); + st[0] = (st[0] << 1) | v; + } + } + +dsd: + for (i = 0; i < avctx->channels; i++) { + float *dst = (float *)frame->data[0]; + + ff_dsd2pcm_translate(&s->dsdctx[i], frame->nb_samples, 0, + s->dsddata + i, avctx->channels, dst + i, avctx->channels); + } + + *got_frame_ptr = 1; + + return avpkt->size; +} + +AVCodec ff_dst_decoder = { + .name = "dst", + .long_name = NULL_IF_CONFIG_SMALL("DST (Digital Stream Transfer)"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_DST, + .priv_data_size = sizeof(DSTContext), + .init = decode_init, + .decode = decode_frame, + .close = decode_close, + .capabilities = AV_CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_NONE }, +}; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e6609ef..f706cca 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3490,6 +3490,8 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, /* calc from sample rate */ if (id == AV_CODEC_ID_TTA) return 256 * sr / 245; + else if (id == AV_CODEC_ID_DST) + return 588 * sr / 44100; if (ch > 0) { /* calc from sample rate and channels */ diff --git a/libavformat/iff.c b/libavformat/iff.c index 8b8bf01..c509ed5 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -59,6 +59,9 @@ #define ID_RGB8 MKTAG('R','G','B','8') #define ID_RGBN MKTAG('R','G','B','N') #define ID_DSD MKTAG('D','S','D',' ') +#define ID_DST MKTAG('D','S','T',' ') +#define ID_DSTC MKTAG('D','S','T','C') +#define ID_DSTF MKTAG('D','S','T','F') #define ID_ANIM MKTAG('A','N','I','M') #define ID_FORM MKTAG('F','O','R','M') @@ -157,6 +160,7 @@ static int iff_probe(AVProbeData *p) static const AVCodecTag dsd_codec_tags[] = { { AV_CODEC_ID_DSD_MSBF, ID_DSD }, + { AV_CODEC_ID_DST, ID_DST }, { AV_CODEC_ID_NONE, 0 }, }; @@ -285,7 +289,7 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) case MKTAG('C','M','P','R'): if (size < 4) return AVERROR_INVALIDDATA; - tag = avio_rl32(pb); + st->codecpar->codec_tag = tag = avio_rl32(pb); st->codecpar->codec_id = ff_codec_get_id(dsd_codec_tags, tag); if (!st->codecpar->codec_id) { av_log(s, AV_LOG_ERROR, "'%c%c%c%c' compression is not supported\n", @@ -336,6 +340,60 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) return 0; } +static int read_dst_frame(AVFormatContext *s, AVPacket *pkt) +{ + IffDemuxContext *iff = s->priv_data; + AVIOContext *pb = s->pb; + uint32_t chunk_id; + uint64_t chunk_pos, data_pos, data_size; + int ret = AVERROR_EOF; + + while (!avio_feof(pb)) { + chunk_pos = avio_tell(pb); + if (chunk_pos >= iff->body_end) + return AVERROR_EOF; + + chunk_id = avio_rl32(pb); + data_size = iff->is_64bit ? avio_rb64(pb) : avio_rb32(pb); + data_pos = avio_tell(pb); + + switch (chunk_id) { + case ID_DSTF: + if (!pkt) { + iff->body_pos = avio_tell(pb) - (iff->is_64bit ? 12 : 8); + iff->body_size = iff->body_end - iff->body_pos; + return 0; + } + ret = av_get_packet(pb, pkt, data_size); + if (ret < 0) + return ret; + if (data_size & 1) + avio_skip(pb, 1); + pkt->flags |= AV_PKT_FLAG_KEY; + pkt->stream_index = 0; + pkt->duration = 588 * s->streams[0]->codecpar->sample_rate / 44100; + pkt->pos = chunk_pos; + + chunk_pos = avio_tell(pb); + if (chunk_pos >= iff->body_end) + return 0; + + avio_seek(pb, chunk_pos, SEEK_SET); + return 0; + + case MKTAG('F','R','T','E'): + if (data_size < 4) + return AVERROR_INVALIDDATA; + s->streams[0]->duration = avio_rb32(pb) * 588LL * s->streams[0]->codecpar->sample_rate / 44100; + break; + } + + avio_skip(pb, data_size - (avio_tell(pb) - data_pos) + (data_size & 1)); + } + + return ret; +} + static const uint8_t deep_rgb24[] = {0, 0, 0, 3, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8}; static const uint8_t deep_rgba[] = {0, 0, 0, 4, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8}; static const uint8_t deep_bgra[] = {0, 0, 0, 4, 0, 3, 0, 8, 0, 2, 0, 8, 0, 1, 0, 8}; @@ -424,10 +482,16 @@ static int iff_read_header(AVFormatContext *s) case ID_BODY: case ID_DBOD: case ID_DSD: + case ID_DST: case ID_MDAT: iff->body_pos = avio_tell(pb); iff->body_end = iff->body_pos + data_size; iff->body_size = data_size; + if (chunk_id == ID_DST) { + int ret = read_dst_frame(s, NULL); + if (ret < 0) + return ret; + } break; case ID_CHAN: @@ -647,7 +711,8 @@ static int iff_read_header(AVFormatContext *s) avpriv_request_sample(s, "compression %d and bit depth %d", iff->maud_compression, iff->maud_bits); return AVERROR_PATCHWELCOME; } - } else if (st->codecpar->codec_tag != ID_DSD) { + } else if (st->codecpar->codec_tag != ID_DSD && + st->codecpar->codec_tag != ID_DST) { switch (iff->svx8_compression) { case COMP_NONE: st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; @@ -720,6 +785,8 @@ static int iff_read_packet(AVFormatContext *s, if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codecpar->codec_tag == ID_DSD || st->codecpar->codec_tag == ID_MAUD) { ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codecpar->block_align)); + } else if (st->codecpar->codec_tag == ID_DST) { + return read_dst_frame(s, pkt); } else { if (iff->body_size > INT_MAX) return AVERROR_INVALIDDATA; -- 2.5.0
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel