[FFmpeg-devel] [PATCH 2/3] avformat/iff: extend IFF demuxer to decode DSDIFF 64-bit chunks

Michael Niedermayer michaelni at gmx.at
Mon Apr 14 16:20:08 CEST 2014


On Mon, Apr 14, 2014 at 06:22:44PM +1000, Peter Ross wrote:
> Signed-off-by: Peter Ross <pross at xvid.org>
[...]

> +static int parse_dsd_diin(AVFormatContext *s, AVStream *st, uint64_t eof)
> +{
> +    AVIOContext *pb = s->pb;
> +
> +    while (avio_tell(pb) + 12 <= eof) {
> +        uint32_t tag      = avio_rl32(pb);
> +        uint64_t size     = avio_rb64(pb);
> +        uint64_t orig_pos = avio_tell(pb);
> +        const char * metadata_tag = NULL;
> +
> +        switch(tag) {
> +        case MKTAG('D','I','A','R'): metadata_tag = "artist"; break;
> +        case MKTAG('D','I','T','I'): metadata_tag = "title";  break;
> +        }
> +
> +        if (metadata_tag) {
> +            int ret = get_metadata(s, metadata_tag, avio_rb32(pb));
> +            if (ret < 0) {
> +                av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag);
> +                return ret;
> +            }
> +        }
> +
> +        avio_skip(pb, size - (avio_tell(pb) - orig_pos) + (size & 1));

this can inf-loop with an appropriate size value


> +    }
> +
> +    return 0;
> +}
> +
> +static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof)
> +{
> +    AVIOContext *pb = s->pb;
> +    char abss[24];
> +    int hour, min, sec, i, ret, config;
> +    int dsd_layout[6];
> +    ID3v2ExtraMeta *id3v2_extra_meta;
> +
> +    while (avio_tell(pb) + 12 <= eof) {
> +        uint32_t tag      = avio_rl32(pb);
> +        uint64_t size     = avio_rb64(pb);
> +        uint64_t orig_pos = avio_tell(pb);
> +
> +        switch(tag) {
> +        case MKTAG('A','B','S','S'):
> +            if (size < 8)
> +                return AVERROR_INVALIDDATA;
> +            hour = avio_rb16(pb);
> +            min  = avio_r8(pb);
> +            sec  = avio_r8(pb);
> +            snprintf(abss, sizeof(abss), "%02dh:%02dm:%02ds:%d", hour, min, sec, avio_rb32(pb));
> +            av_dict_set(&st->metadata, "absolute_start_time", abss, 0);
> +            break;
> +
> +        case MKTAG('C','H','N','L'):
> +            if (size < 8)
> +                return AVERROR_INVALIDDATA;
> +            st->codec->channels       = avio_rb16(pb);
> +            st->codec->channel_layout = 0;
> +            if (st->codec->channels > FF_ARRAY_ELEMS(dsd_layout)) {
> +                avpriv_request_sample(s, "channel layout");
> +                break;
> +            }
> +            for (i = 0; i < st->codec->channels; i++)
> +                dsd_layout[i] = avio_rl32(pb);
> +            for (i = 0; i < FF_ARRAY_ELEMS(dsd_channel_layout); i++) {
> +                const DSDLayoutDesc * d = &dsd_channel_layout[i];
> +                if (av_get_channel_layout_nb_channels(d->layout) == st->codec->channels &&
> +                    !memcmp(d->dsd_layout, dsd_layout, st->codec->channels * sizeof(uint32_t))) {
> +                    st->codec->channel_layout = d->layout;
> +                    break;
> +                }
> +            }
> +            break;
> +
> +        case MKTAG('C','M','P','R'):
> +            if (size < 4)
> +                return AVERROR_INVALIDDATA;
> +            st->codec->codec_id = ff_codec_get_id(dsd_codec_tags, avio_rl32(pb));
> +            break;
> +
> +        case MKTAG('F','S',' ',' '):
> +            if (size < 4)
> +                return AVERROR_INVALIDDATA;
> +            st->codec->sample_rate = avio_rb32(pb) / 8;
> +            break;
> +
> +        case MKTAG('I','D','3',' '):
> +            id3v2_extra_meta = NULL;
> +            ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
> +            if (id3v2_extra_meta) {
> +                if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0) {
> +                    ff_id3v2_free_extra_meta(&id3v2_extra_meta);
> +                    return ret;
> +                }
> +                ff_id3v2_free_extra_meta(&id3v2_extra_meta);
> +            }
> +            break;
> +
> +        case MKTAG('L','S','C','O'):
> +            if (size < 2)
> +                return AVERROR_INVALIDDATA;
> +            config = avio_rb16(pb);
> +            if (config != 0xFFFF) {
> +                if (config < FF_ARRAY_ELEMS(dsd_loudspeaker_config))
> +                    st->codec->channel_layout = dsd_loudspeaker_config[config];
> +                if (!st->codec->channel_layout)
> +                    avpriv_request_sample(s, "loudspeaker configuration %d", config);
> +            }
> +            break;
> +        }
> +        avio_skip(pb, size - (avio_tell(pb) - orig_pos) + (size & 1));

this can inf-loop with an appropriate size value too

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140414/c4aae17f/attachment.asc>


More information about the ffmpeg-devel mailing list