[FFmpeg-devel] [PATCH][RFC] QCP demuxer

Kenan Gillet kenan.gillet
Sun May 17 03:31:11 CEST 2009


On May 16, 2009, at 5:37 PM, Michael Niedermayer wrote:

> On Sat, May 16, 2009 at 05:04:36PM -0700, Kenan Gillet wrote:
>> On Sat, May 16, 2009 at 3:05 PM, Michael Niedermayer <michaelni at gmx.at 
>> > wrote:
>>> On Sat, May 16, 2009 at 12:01:09PM -0700, Kenan Gillet wrote:
>> [...]
>>>> +static int qcp_read_header(AVFormatContext *s,  
>>>> AVFormatParameters *ap)
>>>> +{
>>>> +    ByteIOContext *pb = s->pb;
>>>> +    QCPContext    *c  = s->priv_data;
>>>> +    AVStream      *st = av_new_stream(s, 0);
>>>> +    uint8_t       buf[16];
>>>> +    int           i, nb_rates;
>>>> +
>>>> +    if (!st)
>>>> +        return AVERROR(ENOMEM);
>>>> +
>>>> +    get_be32(pb);                    // "RIFF"
>>>> +    s->file_size = get_le32(pb) + 8;
>>>> +    url_fskip(pb, 8 + 4 + 1 + 1);    // "QLCMfmt " + chunk-size  
>>>> + major-version + minor-version
>>>> +
>>>> +    st->codec->codec_type = CODEC_TYPE_AUDIO;
>>>> +    st->codec->channels   = 1;
>>>> +    get_buffer(pb, buf, 16);
>>>> +    if (is_qcelp_13k_guid(buf)) {
>>>> +        st->codec->codec_id = CODEC_ID_QCELP;
>>>> +    } else if (!memcmp(buf, guid_evrc, 16)) {
>>>> +        av_log(s, AV_LOG_ERROR, "EVRC codec is not supported.\n");
>>>> +        return AVERROR_PATCHWELCOME;
>>>> +    } else if (!memcmp(buf, guid_smv, 16)) {
>>>> +        av_log(s, AV_LOG_ERROR, "SMV codec is not supported.\n");
>>>> +        return AVERROR_PATCHWELCOME;
>>>> +    } else {
>>>> +        av_log(s, AV_LOG_ERROR, "Unknown codec GUID.\n");
>>>> +        return AVERROR_INVALIDDATA;
>>>> +    }
>>>> +    url_fskip(pb, 2 + 80); // codec-version + codec-name
>>>> +    st->codec->bit_rate = get_le16(pb);
>>>> +
>>>
>>>> +    c->fixed_packet_size =
>>>> +    s->packet_size       = get_le16(pb);
>>>
>>> redundant?
>>
>> yes, fixed
>>
>>
>>>
>>> [...]
>>>> +static int qcp_read_packet(AVFormatContext *s, AVPacket *pkt)
>>>> +{
>>>> +    ByteIOContext *pb = s->pb;
>>>> +    QCPContext    *c  = s->priv_data;
>>>> +    unsigned int  chunk_size, tag;
>>>> +
>>>> +    while(!url_feof(pb)) {
>>>> +        if (c->data_size) {
>>>> +            int pkt_size, ret, mode = get_byte(pb);
>>>> +
>>>> +            if (c->fixed_packet_size) {
>>>> +                pkt_size = c->fixed_packet_size - 1;
>>>> +            } else {
>>>> +                int retry;
>>>> +
>>>
>>>> +                for (retry = 256; retry > 0 && !url_feof(pb) &&  
>>>> mode > QCP_MAX_MODE; retry--) {
>>>> +                    av_log(s, AV_LOG_WARNING, "wrong byte mode= 
>>>> %d@%llx\n", mode, url_ftell(pb) - 1);
>>>> +                    c->data_size--;
>>>> +                    mode = get_byte(pb);
>>>> +                }
>>>
>>> this doesnt even cover a single damaged sector of a disk
>>> besides it spams the user to death
>>>
>>> the normal way to do this is a
>>> if(mode > QCP_MAX_MODE)
>>>    continue;
>>
>> much simpler indeed :)
>> fixed
>>
>>
>>>
>>>> +                if (!retry || url_feof(pb))
>>>> +                    return AVERROR_INVALIDDATA;
>>>> +                pkt_size = c->rates_per_mode[mode];
>>>> +            }
>>>> +
>>>> +            if (c->data_size <= pkt_size) {
>>>> +                av_log(s, AV_LOG_WARNING, "Data chunk is too  
>>>> small.\n");
>>>> +                pkt_size = c->data_size - 1;
>>>> +            }
>>>> +
>>>> +            if ((ret = av_get_packet(pb, pkt, pkt_size)) >= 0) {
>>>
>>> pkt_size can be -1 this is ignored
>>>
>>
>> fixed
>>
>> thanks for the review,
>
> patch probably ok assuming its tested
>
> [...]

tested with all the samples at
http://samples.ffmpeg.org/A-codecs/qcp/
http://samples.ffmpeg.org/A-codecs/suite/QCP/
http://samples.ffmpeg.org/A-codecs/suite/EVRC/

Kenan




More information about the ffmpeg-devel mailing list