[MPlayer-dev-eng] MNG demuxer for MPlayer

Nico Sabbi Nicola.Sabbi at poste.it
Mon Jul 28 12:49:51 CEST 2008


On Friday 25 July 2008 21:39:18 Stefan Schuermans wrote:
> Hello MPlayer developers,
>
> MNG animations do not seem to be supported by MPlayer 1.0rc2.
> Because I wanted to play back MNG animations using MPlayer, I tried
> to implement a demuxer in libmpdemux using libmng 1.0.9.
>
> It worked out and I've been able to play the MNG animations using
> the new demuxer. Perhaps the code is useful for other people, so
> I'm sending in the patchfile.
>
> I've not yet managed to add MNG auto detection to the configure
> script, so you'll have to add "MNG = yes" to config.mak and
> "#define HAVE_MNG" in config.h by hand to use the code. It's also
> needed to add "-lmng" to EXTRA_LIB in config.mak.
>
> Best regards,
> Stefan

new demuxers should be developed for libavformat; libmpdemux
is supposed to RIP. Anyway a short review follows

> +
> + // default time for a frame in the show process (in milliseconds)
> + unsigned int demux_mng_frame_ms = 40; // 25 frames per second

make it at least file-static, but why a default value? doesn't mng 
specify
one?

> +
> + // MNG library callback: allocate a new memmory block and fill it
> with zeros + static mng_ptr demux_mng_alloc(mng_size_t size)
> + {
> +   void * ptr = malloc(size);
> +   if (ptr != NULL)
> +     memset(ptr, 0, size);
> +   return (mng_ptr)ptr;
> + }


calloc()

> +
> + // MNG libarary callback: (a part of) the canvas should be shown
> + static mng_bool demux_mng_refresh(mng_handle
> __attribute__((unused)) h_mng, +                                  
> mng_uint32 __attribute__((unused)) x, +                            
>       mng_uint32 __attribute__((unused)) y, +                      
>             mng_uint32 __attribute__((unused)) width, +            
>                       mng_uint32 __attribute__((unused)) height) +
> {
> +   // nothing to do here, the image data is already on the canvas
> +   // (maybe, we could create a packet for the codec here and
> return it from mng_fill_buffer(), +   //  but how can we get
> mng_display() called from there to return before the next wait?) +
>   return MNG_TRUE;
> + }


ugly


> +
> + // MPlayer callback: open MNG stream
> + static demuxer_t * demux_mng_open(demuxer_t * demuxer)
> + {
> +   mng_priv_t * mng_priv;
> +   mng_handle h_mng;
> +   sh_video_t * sh_video;
> +
> +   // create and initialize private data structure
> +   mng_priv = (mng_priv_t *)malloc(sizeof(mng_priv_t));
> +   mng_priv->header_processed = 0;
> +   mng_priv->canvas = NULL;
> +   mng_priv->displaying = 0;
> +   mng_priv->finished = 0;
> +   mng_priv->frame_ms = demux_mng_frame_ms;
> +   mng_priv->global_time_ms = 0;
> +   mng_priv->anim_time_ms = 0;
> +   mng_priv->anim_frame_duration_ms = 0;
> +   mng_priv->show_time_ms = 0;

calloc()

> +
> +   // remember pointer to demuxer in private data
> +   mng_priv->demuxer = demuxer;
> +
> +   // initialize MNG image instance
> +   h_mng = mng_initialize((mng_ptr)mng_priv, demux_mng_alloc,
> demux_mng_free, MNG_NULL); +   if (!h_mng) {
> +     mp_msg(MSGT_DEMUX, MSGL_ERR, "demux_mng: could not initialize
> MNG image instance\n"); +     free(mng_priv);
> +     return NULL;
> +   }
> +
> +   // remember handle to MNG image in private data
> +   mng_priv->h_mng = h_mng;
> +
> +   // set MNG callbacks
> +   if(mng_setcb_openstream(h_mng, demux_mng_openstream) != 0 ||
> +      mng_setcb_closestream(h_mng, demux_mng_closestream) != 0 ||
> +      mng_setcb_readdata(h_mng, demux_mng_readdata) != 0 ||
> +      mng_setcb_processheader(h_mng, demux_mng_processheader) != 0
> || +      mng_setcb_getcanvasline(h_mng, demux_mng_getcanvasline)
> != 0 || +      mng_setcb_refresh(h_mng, demux_mng_refresh) != 0 ||
> +      mng_setcb_gettickcount(h_mng, demux_mng_gettickcount) != 0
> || +      mng_setcb_settimer(h_mng, demux_mng_settimer) != 0 || +  
>    mng_set_canvasstyle(h_mng, MNG_CANVAS_RGB8) != 0) { +    
> mp_msg(MSGT_DEMUX, MSGL_ERR, "demux_mng: could not set MNG
> callbacks\n"); +     mng_cleanup(&h_mng);


all those != 0 are useless



More information about the MPlayer-dev-eng mailing list