[FFmpeg-devel] [PATCH] R3D REDCODE demuxer

Michael Niedermayer michaelni
Fri Dec 19 02:04:19 CET 2008


On Wed, Dec 17, 2008 at 12:05:25AM -0800, Baptiste Coudurier wrote:
> Hi,
> 
> Here is the demuxer.
> 
> Basically, chunks contains jp2 frames which can be decoded in some way
> by openjpeg.
> 
> I'll add seeking as soon as code is in svn.
[...]
> +static int r3d_read_red1(AVFormatContext *s)
> +{
> +    AVStream *st = av_new_stream(s, 0);
> +    int tmp, tmp2, timebase;
> +
> +    if (!st)
> +        return -1;
> +    st->codec->codec_type = CODEC_TYPE_VIDEO;
> +    st->codec->codec_id = CODEC_ID_JPEG2000;
> +    tmp  = get_byte(s->pb); // major version
> +    tmp2 = get_byte(s->pb); // minor version
> +    dprintf(s, "version %d.%d\n", tmp, tmp2);
> +    get_be16(s->pb); // unknown

> +    timebase = get_be32(s->pb);
> +    dprintf(s, "timebase %d\n", timebase);
> +    st->time_base.num = 1;
> +    st->time_base.den = timebase;

av_set_pts_info()

also, i think the code would be more readable with an occasional empty
line :)


[...]
> +static int r3d_read_header(AVFormatContext *s, AVFormatParameters *ap)
> +{
> +    R3DContext *r3d = s->priv_data;
> +    Atom atom;
> +    int ret;
> +
> +    if (read_atom(s->pb, &atom) < 0) {
> +        av_log(s, AV_LOG_ERROR, "error reading atom\n");
> +        return -1;
> +    }
> +    dprintf(s, "atom %d %.4s offset %#llx\n",
> +            atom.size, (char*)&atom.tag, atom.offset);
> +    if (atom.tag == MKTAG('R','E','D','1')) {
> +        if ((ret = r3d_read_red1(s)) < 0) {
> +            av_log(s, AV_LOG_ERROR, "error parsing 'red1' atom\n");
> +            return ret;
> +        }
> +    } else {
> +        av_log(s, AV_LOG_ERROR, "could not find 'red1' atom\n");
> +        return -1;
> +    }
> +
> +    s->data_offset = url_ftell(s->pb);
> +    dprintf(s, "data offset %#llx\n", s->data_offset);
> +    if (url_is_streamed(s->pb))
> +        return 0;
> +    // find REOB/REOF/REOS to load index
> +    url_fseek(s->pb, url_fsize(s->pb)-48-8, SEEK_SET);

> +    if (read_atom(s->pb, &atom) < 0) {
> +        av_log(s, AV_LOG_ERROR, "error reading end atom\n");
> +        return -1;
> +    }

if return 0 was ok before when url_is_streamed() then it should be ok
here too after seeking back, same for the other failure cases below


> +    dprintf(s, "atom %d %.4s offset %#llx\n",
> +            atom.size, (char*)&atom.tag, atom.offset);

These dprintfs() could be put in read_atom()


[...]
> +static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
> +{
> +    int tmp, tmp2, samples, size;
> +    uint64_t pos = url_ftell(s->pb);
> +    unsigned dts;
> +
> +    if (s->nb_streams < 2)
> +        return -1;
> +    if (s->streams[1]->discard == AVDISCARD_ALL)
> +        return 0;
> +    dts = get_be32(s->pb);
> +    dprintf(s, "dts %d\n", dts);
> +    s->streams[1]->codec->sample_rate = get_be32(s->pb);
> +    samples = get_be32(s->pb);
> +    dprintf(s, "samples %d\n", samples);
> +    tmp = get_be32(s->pb);
> +    dprintf(s, "packet num %d\n", tmp);
> +    tmp = get_be16(s->pb); // unkown
> +    dprintf(s, "unknown %d\n", tmp);

> +    tmp  = get_byte(s->pb); // major version
> +    tmp2 = get_byte(s->pb); // minor version
> +    dprintf(s, "version %d.%d\n", tmp, tmp2);

id also suggest to either drop the dprintf() or write a
little macro that does get_* + dprintf() at once


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

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081219/be221fa9/attachment.pgp>



More information about the ffmpeg-devel mailing list