[MPlayer-dev-eng] FLI file demuxing support

Mike Melanson melanson at pcisys.net
Sat Nov 24 06:39:49 CET 2001


Hi team,
	Arpi, when you wrote "1. needs implementing a new demuxer, it is
not easy," you weren't kidding! But I'm pleased to report that MPlayer's
demuxing subsystem was not able to thwart my efforts when it came to
implementing a FLI file demuxer. You'll be glad to know that the MPlayer
codebase put up a valiant struggle, though.

	When the attached changes are applied, MPlayer will (should) pop
up a placeholder window of the proper resolution and print messages
instead of decoding the frames.

	I made up an internal fourcc for the FLI compression format
('FLIC') as a placeholder for the actual decompression which should be
done soon. Hopefully, the contrived fourcc won't cause any conflicts.
Here's the codecs.conf entry:
videocodec fli
  info "FLI File Decoder"
  status buggy
  fourcc FLIC
  driver fli
  out BGR24
Also, I updated all of the various language help files. Not bad,
considering I only speak one language.

	I have attached the necessary file diffs, as well as
libmpdemux/demux_fli.c. I hope I got the diff format right. I followed
the developers' Q+A email to the MPlayer list.

-- 
	-Mike Melanson

-------------- next part --------------
Index: codec-cfg.c
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.c,v
retrieving revision 1.47
diff -r1.47 codec-cfg.c
230a231
> 		"fli",
Index: codec-cfg.h
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.h,v
retrieving revision 1.23
diff -r1.23 codec-cfg.h
45a46
> #define VFM_FLI 12
Index: dec_video.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_video.c,v
retrieving revision 1.67
diff -r1.67 dec_video.c
558a559,564
>  case VFM_FLI: {
>    int bpp=((out_fmt&255)+7)/8; // RGB only
>    sh_video->our_out_buffer = 
>      (char*)memalign(64, sh_video->disp_w*sh_video->disp_h*bpp); // FIXME!!!
>    }
>    break;
805a812,815
>     blit_frame = 3;
>     break;
>   case VFM_FLI:
> printf ("This is the part where MPlayer decodes a FLI frame (data chunk is %d bytes)\n", in_size);
Index: help_mp-cz.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-cz.h,v
retrieving revision 1.3
diff -r1.3 help_mp-cz.h
134a135
> #define MSGTR_DetectedFLIfile "Detekov?n FLI form?t souboru!\n"
Index: help_mp-de.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-de.h,v
retrieving revision 1.14
diff -r1.14 help_mp-de.h
133a134
> #define MSGTR_DetectedFLIfile "FLI Dateiformat erkannt!\n"
Index: help_mp-dk.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-dk.h,v
retrieving revision 1.1
diff -r1.1 help_mp-dk.h
132a133
> #define MSGTR_DetectedFLIfile "Detecterede FLI fil format!\n"
Index: help_mp-en.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-en.h,v
retrieving revision 1.12
diff -r1.12 help_mp-en.h
137a138
> #define MSGTR_DetectedFLIfile "Detected FLI file format!\n"
Index: help_mp-es.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-es.h,v
retrieving revision 1.1
diff -r1.1 help_mp-es.h
134a135
> #define MSGTR_DetectedFLIfile "Detectado formato de archivo FLI!\n"
Index: help_mp-fr.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-fr.h,v
retrieving revision 1.4
diff -r1.4 help_mp-fr.h
143a144
> #define MSGTR_DetectedFLIfile "Format de fichier FLI d?tect?!\n"
Index: help_mp-hu.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-hu.h,v
retrieving revision 1.17
diff -r1.17 help_mp-hu.h
133a134
> #define MSGTR_DetectedFLIfile "Ez egy FLI form?tum? file!\n"
Index: help_mp-nl.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-nl.h,v
retrieving revision 1.3
diff -r1.3 help_mp-nl.h
133a134
> #define MSGTR_DetectedFLIfile "FLI bestandsformaat gedetecteerd!\n"
Index: help_mp-no.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-no.h,v
retrieving revision 1.1
diff -r1.1 help_mp-no.h
132a133
> #define MSGTR_DetectedFLIfile "Detekterte FLI filformat!\n"
Index: help_mp-pl.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-pl.h,v
retrieving revision 1.13
diff -r1.13 help_mp-pl.h
136a137
> #define MSGTR_DetectedFLIfile "Wykryto format FLI!\n"
Index: help_mp-ro.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-ro.h,v
retrieving revision 1.1
diff -r1.1 help_mp-ro.h
132a133
> #define MSGTR_DetectedFLIfile "Format fi?ier detectat: FLI\n"
Index: help_mp-ru.h
===================================================================
RCS file: /cvsroot/mplayer/main/help_mp-ru.h,v
retrieving revision 1.2
diff -r1.2 help_mp-ru.h
132a133
> #define MSGTR_DetectedFLIfile "????????? FLI ?????? ?????!\n"
Index: libmpdemux/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.10
diff -r1.10 Makefile
6c6
< SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c demux_mpg.c demux_viv.c demuxer.c dvdauth.c open.c parse_es.c stream.c tv.c tvi_dummy.c tvi_v4l.c frequencies.c
---
> SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c demux_mpg.c demux_viv.c demuxer.c dvdauth.c open.c parse_es.c stream.c tv.c tvi_dummy.c tvi_v4l.c frequencies.c demux_fli.c
Index: libmpdemux/demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.50
diff -r1.50 demuxer.c
151a152
> int demux_fli_fill_buffer(demuxer_t *demux);
172a174
>     case DEMUXER_TYPE_FLI: return demux_fli_fill_buffer(demux);
356a359
> int demux_open_fli(demuxer_t* demuxer);
383a387,400
> //=============== Try to open as FLI file: =================
> if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_FLI){
>   demuxer=new_demuxer(stream,DEMUXER_TYPE_FLI,audio_id,video_id,dvdsub_id);
>   {
>     int size=stream_read_dword_le(demuxer->stream);
>     int id=stream_read_word_le(demuxer->stream);
>     // chech for the FLI file magic number
>     if((id==0xAF11) || (id==0xAF12)){ 
>       mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedFLIfile);
>       file_format=DEMUXER_TYPE_FLI;
>     }
>   }
> }
> 
483a501,504
>  case DEMUXER_TYPE_FLI: {
>   if (!demux_open_fli(demuxer)) return NULL;
>   break;
>  }
Index: libmpdemux/demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.21
diff -r1.21 demuxer.h
14a15
> #define DEMUXER_TYPE_FLI 10
-------------- next part --------------
/*
	FLI file parser for the MPlayer program
	by Mike Melanson
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "config.h"
#include "mp_msg.h"
#include "help_mp.h"

#include "stream.h"
#include "demuxer.h"
#include "stheader.h"

typedef struct _fli_frames_t {
  int num_frames;
  int current_frame;
  off_t *filepos;
  unsigned int *frame_size;
} fli_frames_t;

// return value:
//     0 = EOF or no stream found
//     1 = successfully read a packet
int demux_fli_fill_buffer(demuxer_t *demuxer){
  fli_frames_t *frames = (fli_frames_t *)demuxer->priv;

  // advance the frame and see if the end has been reached
  frames->current_frame++;
  if (frames->current_frame == frames->num_frames)
    return 0;

  // fetch the frame from the file
  // first, position the file properly since ds_read_packet() doesn't
  // seem to do it, even though it takes a file offset as a parameter
  stream_seek(demuxer->stream, frames->filepos[frames->current_frame]);
  ds_read_packet(demuxer->video,
    demuxer->stream, 
    frames->frame_size[frames->current_frame],
    0, /* not sure what pts is for */
    frames->filepos[frames->current_frame],
    0 /* what flags? */
  );

  return 1;
}

demuxer_t* demux_open_fli(demuxer_t* demuxer){
  sh_video_t *sh_video = NULL;
  fli_frames_t *frames = (fli_frames_t *)malloc(sizeof(fli_frames_t));
  int frame_number;

  // go back to the beginning
  stream_reset(demuxer->stream);
  stream_seek(demuxer->stream, 0);
  demuxer->movi_start = 128;
  demuxer->movi_end = stream_read_dword_le(demuxer->stream);

  // skip the magic number
  stream_skip(demuxer->stream, 2);

  // fetch the number of frames
  frames->num_frames = stream_read_word_le(demuxer->stream);
  frames->current_frame = 0;

  // allocate enough entries for the indices
  frames->filepos = (off_t *)malloc(frames->num_frames * sizeof(off_t));
  frames->frame_size = (int *)malloc(frames->num_frames * sizeof(int));

  // create a new video stream header
  sh_video = new_sh_video(demuxer, 0);

  // make sure the demuxer knows about the new video stream header
  // (even though new_sh_video() ought to take care of it)
  demuxer->video->sh = sh_video;

  // make sure that the video demuxer stream header knows about its
  // parent video demuxer stream (this is getting wacky), or else
  // video_read_properties() will choke
  sh_video->ds = demuxer->video;

  // custom fourcc for internal MPlayer use
  sh_video->format = mmioFOURCC('F', 'L', 'I', 'C');

  sh_video->disp_w = stream_read_word_le(demuxer->stream);
  sh_video->disp_h = stream_read_word_le(demuxer->stream);

  // skip the video depth and flags
  stream_skip(demuxer->stream, 4);

  // probably not correct
  sh_video->fps = 10;
  sh_video->frametime = 1/10;

  // build the frame index
  stream_seek(demuxer->stream, demuxer->movi_start);
  frame_number = 0;
  while ((!stream_eof(demuxer->stream)) && (frame_number < frames->num_frames))
  {
    frames->filepos[frame_number] = stream_tell(demuxer->stream);
    frames->frame_size[frame_number] = stream_read_dword_le(demuxer->stream);
    stream_skip(demuxer->stream, frames->frame_size[frame_number] - 4);
    frame_number++;
  }

  demuxer->priv = frames;
}


More information about the MPlayer-dev-eng mailing list