[Mplayer-cvslog] CVS: main/libmpdemux demux_film.c,NONE,1.1 stream.h,1.25,1.26 Makefile,1.16,1.17 demuxer.c,1.65,1.66 demuxer.h,1.25,1.26

Mike Melanson melanson at mplayer.dev.hu
Wed Jan 16 04:23:06 CET 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv31877

Modified Files:
	stream.h Makefile demuxer.c demuxer.h 
Added Files:
	demux_film.c 
Log Message:
initial support for FILM file demuxing


--- NEW FILE ---
/*
	FILM 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"

// chunk types found in a FILM file
#define CHUNK_FILM mmioFOURCC('F', 'I', 'L', 'M')
#define CHUNK_FDSC mmioFOURCC('F', 'D', 'S', 'C')
#define CHUNK_STAB mmioFOURCC('S', 'T', 'A', 'B')

typedef struct _film_frames_t {
  int num_frames;
  int current_frame;
  off_t *filepos;
  unsigned int *frame_size;
  unsigned int *flags1;
  unsigned int *flags2;
} film_frames_t;

void demux_seek_film(demuxer_t *demuxer,float rel_seek_secs,int flags){
  film_frames_t *frames = (film_frames_t *)demuxer->priv;
  sh_video_t *sh_video = demuxer->video->sh;
  int newpos=(flags&1)?0:frames->current_frame;
  if(flags&2){
      // float 0..1
      newpos+=rel_seek_secs*frames->num_frames;
  } else {
      // secs
      newpos+=rel_seek_secs*sh_video->fps;
  }
  if(newpos<0) newpos=0; else
  if(newpos>frames->num_frames) newpos=frames->num_frames;
  frames->current_frame=newpos;
}

// return value:
//     0 = EOF or no stream found
//     1 = successfully read a packet
int demux_film_fill_buffer(demuxer_t *demuxer){
  film_frames_t *frames = (film_frames_t *)demuxer->priv;
  sh_video_t *sh_video = demuxer->video->sh;

  // see if the end has been reached
  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],
    frames->current_frame/sh_video->fps,
    frames->filepos[frames->current_frame],
    0 /* what flags? -> demuxer.h (alex) */
  );

  // get the next frame ready
  frames->current_frame++;

  return 1;
}

demuxer_t* demux_open_film(demuxer_t* demuxer){
  sh_video_t *sh_video = NULL;
  film_frames_t *frames = (film_frames_t *)malloc(sizeof(film_frames_t));
  int header_size;
  unsigned int chunk_type;
  unsigned int chunk_size;
  int i;

  // go back to the beginning
  stream_reset(demuxer->stream);
  stream_seek(demuxer->stream, 0);

  // read the master chunk type
  chunk_type = stream_read_fourcc(demuxer->stream);
  // validate the chunk type
  if (chunk_type != CHUNK_FILM)
  {
    mp_msg(MSGT_DEMUX, MSGL_ERR, "Not a FILM file\n");
    return(NULL);    
  }

  // get the header size, which implicitly points past the header and
  // to the start of the data
  header_size = stream_read_dword(demuxer->stream);
  demuxer->movi_start = header_size;
  demuxer->movi_end = demuxer->stream->end_pos;
  header_size -= 16;

  // skip to where the next chunk should be
  stream_skip(demuxer->stream, 8);

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

  // make sure the demuxer knows about the new video stream header
  demuxer->video->sh = sh_video;

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

  // traverse through the header
  while (header_size > 0)
  {
    // fetch the chunk type and size
    chunk_type = stream_read_fourcc(demuxer->stream);
    chunk_size = stream_read_dword(demuxer->stream);
    header_size -= chunk_size;

    switch (chunk_type)
    {
    case CHUNK_FDSC:
printf ("parsing FDSC chunk\n");
      // fetch the video codec fourcc, height, then width
      sh_video->format = stream_read_fourcc(demuxer->stream);
      sh_video->disp_h = stream_read_dword(demuxer->stream);
      sh_video->disp_w = stream_read_dword(demuxer->stream);
// temporary; one of these fields has to specify FPS
stream_skip(demuxer->stream, 12);
      break;

    case CHUNK_STAB:
printf ("parsing STAB chunk\n");
      // skip unknown dword
      stream_skip(demuxer->stream, 4);

      // fetch the number of frames
      frames->num_frames = stream_read_dword(demuxer->stream);
      frames->current_frame = 1;
//      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));
      frames->flags1 = (int *)malloc(frames->num_frames * sizeof(int));
      frames->flags2 = (int *)malloc(frames->num_frames * sizeof(int));

      // build the frame index
      for (i = 0; i < frames->num_frames; i++)
      {
        frames->filepos[i] = demuxer->movi_start + stream_read_dword(demuxer->stream);
        frames->frame_size[i] = stream_read_dword(demuxer->stream);
        frames->flags1[i] = stream_read_dword(demuxer->stream);
        frames->flags2[i] = stream_read_dword(demuxer->stream);
      }
      break;

    default:
      mp_msg(MSGT_DEMUX, MSGL_ERR, "Unrecognized FILM header chunk: %08X\n",
        chunk_type);
      return(NULL);    
      break;
    }
  }

  // hard code the speed for now
  sh_video->fps = 1;
  sh_video->frametime = 1;

  demuxer->priv = frames;

  return demuxer;
}

Index: stream.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- stream.h	8 Jan 2002 01:19:54 -0000	1.25
+++ stream.h	16 Jan 2002 03:23:03 -0000	1.26
@@ -83,6 +83,8 @@
   return y;
 }
 
+#define stream_read_fourcc stream_read_dword_le
+
 inline static unsigned int stream_read_word_le(stream_t *s){
   int x,y;
   x=stream_read_char(s);

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Makefile	29 Dec 2001 00:09:29 -0000	1.16
+++ Makefile	16 Jan 2002 03:23:03 -0000	1.17
@@ -3,7 +3,7 @@
 
 include ../config.mak
 
-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 demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.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 demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c
 ifeq ($(STREAMING),yes)
 SRCS += asf_streaming.c url.c http.c network.c rtp.c
 endif

Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- demuxer.c	9 Jan 2002 17:09:21 -0000	1.65
+++ demuxer.c	16 Jan 2002 03:23:03 -0000	1.66
@@ -150,6 +150,7 @@
 // return value:
 //     0 = EOF or no stream found or invalid type
 //     1 = successfully read a packet
+int demux_film_fill_buffer(demuxer_t *demux);
 int demux_fli_fill_buffer(demuxer_t *demux);
 int demux_mpg_es_fill_buffer(demuxer_t *demux);
 int demux_mpg_fill_buffer(demuxer_t *demux);
@@ -175,6 +176,7 @@
   // Note: parameter 'ds' can be NULL!
 //  printf("demux->type=%d\n",demux->type);
   switch(demux->type){
+    case DEMUXER_TYPE_FILM: return demux_film_fill_buffer(demux);
     case DEMUXER_TYPE_FLI: return demux_fli_fill_buffer(demux);
     case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux);
     case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux);
@@ -364,6 +366,7 @@
 int mov_check_file(demuxer_t* demuxer);
 int mov_read_header(demuxer_t* demuxer);
 int demux_open_fli(demuxer_t* demuxer);
+int demux_open_film(demuxer_t* demuxer);
 
 extern int vivo_check_file(demuxer_t *demuxer);
 extern void demux_open_vivo(demuxer_t *demuxer);
@@ -467,15 +470,28 @@
 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
+    int id;
+    stream_seek(demuxer->stream, 4);
+    id=stream_read_word_le(demuxer->stream);
+    // check for the FLI file magic number
     if((id==0xAF11) || (id==0xAF12)){ 
       mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedFLIfile);
       file_format=DEMUXER_TYPE_FLI;
     }
   }
 }
+//=============== Try to open as FILM file: =================
+if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_FILM){
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_FILM,audio_id,video_id,dvdsub_id);
+  {
+    int signature=stream_read_fourcc(demuxer->stream);
+    // check for the FLI file magic number
+    if(signature==mmioFOURCC('F', 'I', 'L', 'M')){ 
+      mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedFILMfile);
+      file_format=DEMUXER_TYPE_FILM;
+    }
+  }
+}
 //=============== Try to open as MPEG-PS file: =================
 if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MPEG_PS){
  int pes=1;
@@ -554,6 +570,10 @@
   if (!demux_open_fli(demuxer)) return NULL;
   break;
  }
+ case DEMUXER_TYPE_FILM: {
+  if (!demux_open_film(demuxer)) return NULL;
+  break;
+ }
  case DEMUXER_TYPE_MOV: {
   if(!mov_read_header(demuxer)) return NULL;
 //  sh_video=d_video->sh;if(sh_video) sh_video->ds=d_video;
@@ -807,4 +827,6 @@
 	if (info->encoder)
 	    mp_msg(MSGT_DEMUX, MSGL_INFO, " Encoder: %s\n", info->encoder);
     }
+
+    return 0;
 }

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- demuxer.h	27 Dec 2001 21:24:56 -0000	1.25
+++ demuxer.h	16 Jan 2002 03:23:03 -0000	1.26
@@ -16,6 +16,7 @@
 #define DEMUXER_TYPE_REAL 11
 #define DEMUXER_TYPE_Y4M 12
 #define DEMUXER_TYPE_NUV 13
+#define DEMUXER_TYPE_FILM 14
 
 #define DEMUXER_TIME_NONE 0
 #define DEMUXER_TIME_PTS 1




More information about the MPlayer-cvslog mailing list