[FFmpeg-devel] [PATCH] Windows Television (.wtv) demuxer

Michael Niedermayer michaelni
Tue Sep 28 21:03:33 CEST 2010


On Tue, Sep 28, 2010 at 12:28:19AM +1000, Peter Ross wrote:
[...]
> +/**
> + * parse VIDEOINFOHEADER2 structure
> + * @return bytes consumed
> + */
> +static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st)
> +{
> +    ByteIOContext *pb = s->pb;
> +
> +    // VIDEOINFOHEADER2 part
> +    url_fskip(pb, 32);
> +    st->codec->bit_rate = get_le32(pb);
> +    url_fskip(pb, 20);
> +    st->sample_aspect_ratio.num = get_le32(pb);
> +    st->sample_aspect_ratio.den = get_le32(pb);
> +    url_fskip(pb, 8);
> +
> +    // BITMAPINFOHEADER part

we have code to read BITMAPINFOHEADERs in  libavformat/avidec.c strf
maybe this can be factored?


> +    url_fskip(pb, 4); 
> +    st->codec->width  = get_le32(pb);
> +    st->codec->height = (int32_t)get_le32(pb);
> +    url_fskip(pb, 2);
> +    st->codec->bits_per_coded_sample = get_le16(pb);
> +    url_fskip(pb, 24);
> +    
> +    return 72 + 40;
> +}
> +

> +/**
> + * parse Media Type structure
> + * @param mediatype Mediatype guid
> + * @param subtype   Subtype guid
> + * @param foramt    Format guid
> + * @param size      Size of format buffer
> + */
> +static void parse_media_type(AVFormatContext *s, AVStream *st,
> +                             ff_asf_guid mediatype, ff_asf_guid subtype,
> +                             ff_asf_guid formattype, int size)
> +{
> +    ByteIOContext *pb = s->pb;
> +    if (!ff_guidcmp(subtype, mediasubtype_cpfilters_processed) &&
> +        !ff_guidcmp(formattype, format_cpfilters_processed)) {
> +        ff_asf_guid actual_subtype;
> +        ff_asf_guid actual_formattype;
> +
> +        if (size < 32) {
> +            av_log(s, AV_LOG_WARNING, "format buffer size underflow\n");
> +            url_fskip(pb, size);
> +            return;
> +        }
> +
> +        url_fskip(pb, size - 32);
> +        ff_get_guid(pb, &actual_subtype);
> +        ff_get_guid(pb, &actual_formattype);

> +        url_fseek(pb, -size, SEEK_CUR);

this wont work with non seekable protocols


> +
> +        parse_media_type(s, st, mediatype, actual_subtype, actual_formattype, size - 32);
> +        url_fskip(pb, 32);
> +        return;
> +    } else if (!ff_guidcmp(mediatype, mediatype_audio)) {
> +        if (!ff_guidcmp(formattype, format_waveformatex)) {
> +            ff_get_wav_header(pb, st->codec, size);
> +        } else {

> +            if (ff_guidcmp(formattype, format_none)) {
> +                av_log(s, AV_LOG_WARNING, "unknown formatype:");
> +                print_guid(AV_LOG_WARNING, formattype);
> +                av_log(0, AV_LOG_WARNING, "\n");
                          ^
why not s?


> +            }
> +            url_fskip(pb, size);
> +        }
> +
> +        st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +        if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) {
> +            st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample);
> +        } else {
> +            st->codec->codec_id = ff_codec_guid_get_id(audio_guids, subtype);
> +        }
> +        if (st->codec->codec_id == CODEC_ID_NONE) {
> +            av_log(s, AV_LOG_WARNING, "unknown subtype:");
> +            print_guid(AV_LOG_WARNING, subtype);
> +            av_log(0, AV_LOG_WARNING, "\n");
> +        }
> +        return;
> +    } else if (!ff_guidcmp(mediatype, mediatype_video)) {
> +        if (!ff_guidcmp(formattype, format_videoinfo2)) {
> +            int consumed = parse_videoinfoheader2(s, st);
> +            url_fskip(pb, FFMAX(size - consumed, 0));
> +        } else if (!ff_guidcmp(formattype, format_mpeg2_video)) {
> +            int consumed = parse_videoinfoheader2(s, st);
> +            url_fskip(pb, 4);
> +            st->codec->extradata_size = get_le32(pb);
> +            url_fskip(pb, 12);
> +#if 1
> +            //the extradata is rejected by the decoder
> +            st->codec->extradata_size = 0;
> +#endif
> +            if (st->codec->extradata_size) {
> +                st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
> +                if (!st->codec->extradata) {
> +                    st->codec->extradata_size = 0;
> +                }else {
> +                    memset(st->codec->extradata, 0,  st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
> +                    get_buffer(pb, st->codec->extradata, st->codec->extradata_size); 
> +                }

> +{ int i;
> +      av_log(0,0, "data [[\n");
> +  for(i=0; i<st->codec->extradata_size;i++) {
> +      av_log(0,0, " %02x", st->codec->extradata[i]);
> +  }
> +      av_log(0,0, "]]\n");
> +}

ehm


[...]
> +static int read_header(AVFormatContext *s, AVFormatParameters *ap)
> +{
> +    ByteIOContext *pb = s->pb;
> +    int ret;
> +
> +    url_fseek(pb, 0x40000, SEEK_SET);
> +    ret = parse_chunks(s, 0);
> +    if (ret < 0)
> +        return ret;
> +
> +    url_fseek(pb, -32, SEEK_CUR);

this too is not guranteed to work on non seekable input


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

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100928/0b4954de/attachment.pgp>



More information about the ffmpeg-devel mailing list