[Ffmpeg-devel] [PATCH] DXA demuxer and decoder

Michael Niedermayer michaelni
Mon Mar 12 13:22:08 CET 2007


Hi

On Mon, Mar 12, 2007 at 07:41:01AM +0200, Kostya wrote:
> Here is DXA demuxer and decoder. The main braindamaged decision
> of this format creators is that audio is stored as WAV file
> inside DXA just after the header so audio demuxing is a bit
> quirky.
> 
>  Original samples:
> http://samples.mplayerhq.hu/game-formats/dxa/
> 
>  ScummVM coding:
> http://www.scummvm.org/downloads.php
> Broken Sword [12] Demo Cutscene Pack (with a note
> "Requires ScummVM 0.10.0svn")

[...]

> +static int decode_12(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint8_t *src, uint8_t *ref)
[...]
> +static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint8_t *src, uint8_t *ref)

code duplication
actually after a quick look these look as if simply throwing all the cases
into one switch would work fine

[...]


> +    avctx->has_b_frames = 0;
> +
> +    c->pic.data[0] = NULL;

these shouldnt be needed


> +    avctx->pix_fmt = PIX_FMT_PAL8;
> +
> +    if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
> +        return -1;
> +    }
> +
> +    c->dsize = avctx->width * avctx->height * 2;
> +    if((c->decomp_buf = av_malloc(c->dsize)) == NULL) {
> +        av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
> +        return -1;
> +    }
> +    if((c->tmp_frame = av_malloc(c->dsize/2)) == NULL) {
> +        av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
> +        return -1;
> +    }

if you alloc a new frame with get_buffer() and free the old after decoding
the new then you
* avoid 1 frame memcpy by just switching the 2 buffers
* avoid dealing with 2 strides
* can copy 4 bytes by *(uint32*)dst= *(uint32*)src as linesize and data must
  be aligned


[...]
> +    // Parse WAV data header
> +    if(get_le32(pb) == MKTAG('W', 'A', 'V', 'E')){
> +        uint32_t size, fsize;
> +        c->has_sound = 1;
> +        size = get_be32(pb);
> +        c->vidpos = url_ftell(pb) + size;
> +        url_fskip(pb, 16);
> +        fsize = get_le32(pb);
> +
> +        st = av_new_stream(s, 0);
> +        if (!st)
> +            return -1;
> +        c->aindex = st->index;

aindex/vindex arent needed,the first stream created will be 0 the second 1

[...]
> +static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    DXAContext *c = s->priv_data;
> +    int ret, i, r, g, b;
> +    uint32_t size;
> +    uint8_t buf[DXA_EXTRA_SIZE];
> +
> +    if(!c->readvid && c->has_sound && c->bytes_left){
> +        c->readvid = 1;
> +        url_fseek(&s->pb, c->wavpos, SEEK_SET);
> +        size = FFMIN(c->bytes_left, c->bpc);
> +        if(av_new_packet(pkt, size) < 0)
> +            return AVERROR_NOMEM;
> +        ret = get_buffer(&s->pb, pkt->data, size);

av_get_packet()


[...]
> +        case MKTAG('C', 'M', 'A', 'P'):
> +            for(i = 0; i < 256; i++){
> +                r = get_byte(&s->pb);
> +                g = get_byte(&s->pb);
> +                b = get_byte(&s->pb);
> +                c->palctrl.palette[i] = (r << 16) | (g << 8) | b;
> +            }
> +            c->palctrl.palette_changed = 1;

this is not thread safe, please pass palette changes like any other packet

[...]

you also could update the Changelog (with svn rev)

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070312/f48b0d4b/attachment.pgp>



More information about the ffmpeg-devel mailing list