On Sat, Dec 23, 2017 at 11:15:35PM +0100, Tomas Härdin wrote:
> 

[...]
> +static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
> +{
> +    int mode = avpriv_codec2_mode_from_extradata(st->codecpar->extradata);
> +
> +    st->codecpar->codec_type        = AVMEDIA_TYPE_AUDIO;
> +    st->codecpar->codec_id          = AV_CODEC_ID_CODEC2;
> +    st->codecpar->sample_rate       = 8000;
> +    st->codecpar->channels          = 1;
> +    st->codecpar->format            = AV_SAMPLE_FMT_S16;
> +    st->codecpar->channel_layout    = AV_CH_LAYOUT_MONO;
> +    st->codecpar->bit_rate          = avpriv_codec2_mode_bit_rate(s, mode);
> +    st->codecpar->frame_size        = avpriv_codec2_mode_frame_size(s, mode);
> +    st->codecpar->block_align       = avpriv_codec2_mode_block_align(s, 
> mode);
> +

> +    if (st->codecpar->bit_rate <= 0 ||
> +        st->codecpar->frame_size <= 0 ||
> +        st->codecpar->block_align <= 0) {
> +        return AVERROR(EINVAL);
> +    }

This should be AVERROR_INVALIDDATA i think


> +
> +    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
> +
> +    //replicating estimate_timings_from_bit_rate() in utils.c to avoid 
> warnings
> +    if (s->pb && st->codecpar->bit_rate > 0) {
> +        int64_t filesize = avio_size(s->pb);
> +        if (filesize > s->internal->data_offset) {
> +            filesize -= s->internal->data_offset;
> +            st->duration = av_rescale(8 * filesize,
> +                                      st->time_base.den,
> +                                      st->codecpar->bit_rate * (int64_t) 
> st->time_base.num);
> +        }
> +    }

Is this exact ?
or is a calculation from frame_size / block_align more accurate ?
the most accurate one should be used


> +
> +    return 0;
> +}
> +
> +static int codec2_read_header(AVFormatContext *s)
> +{
> +    AVStream *st = avformat_new_stream(s, NULL);
> +    int ret, version;
> +    uint8_t magic[3];
> +
> +    if (!st) {
> +        return AVERROR(ENOMEM);
> +    }
> +

> +    avio_read(s->pb, magic, 3);
> +    if (check_magic(magic)) {
> +        av_log(s, AV_LOG_ERROR, "not a .c2 file\n");
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    ret = ff_alloc_extradata(st->codecpar, AVPRIV_CODEC2_EXTRADATA_SIZE);
> +    if (ret) {
> +        return ret;
> +    }
> +
> +    avio_read(s->pb, st->codecpar->extradata, AVPRIV_CODEC2_EXTRADATA_SIZE);

The return codes from avio_read and not checked

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu

Attachment: signature.asc
Description: PGP signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to