2002-02-06 20:15:36 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
#include "mf.h"
|
|
|
|
|
2006-02-17 01:57:41 +00:00
|
|
|
static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
|
2002-09-15 19:47:49 +00:00
|
|
|
mf_t * mf = (mf_t *)demuxer->priv;
|
2002-02-07 12:07:47 +00:00
|
|
|
sh_video_t * sh_video = demuxer->video->sh;
|
|
|
|
int newpos = (flags & 1)?0:mf->curr_frame;
|
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
if ( flags & 2 ) newpos+=rel_seek_secs*mf->nr_of_files;
|
2002-02-07 12:07:47 +00:00
|
|
|
else newpos+=rel_seek_secs * sh_video->fps;
|
|
|
|
if ( newpos < 0 ) newpos=0;
|
2002-09-15 19:47:49 +00:00
|
|
|
if( newpos > mf->nr_of_files) newpos=mf->nr_of_files;
|
2002-02-07 12:07:47 +00:00
|
|
|
mf->curr_frame=newpos;
|
2002-02-06 20:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found
|
|
|
|
// 1 = successfully read a packet
|
2005-08-05 19:57:47 +00:00
|
|
|
static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){
|
2002-02-06 20:15:36 +00:00
|
|
|
mf_t * mf;
|
|
|
|
struct stat fs;
|
|
|
|
FILE * f;
|
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
mf=(mf_t*)demuxer->priv;
|
|
|
|
if ( mf->curr_frame >= mf->nr_of_files ) return 0;
|
2002-02-06 20:15:36 +00:00
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
stat( mf->names[mf->curr_frame],&fs );
|
|
|
|
// printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
|
2002-02-06 20:15:36 +00:00
|
|
|
|
2003-04-26 12:27:56 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0;
|
|
|
|
#else
|
2002-09-15 19:47:49 +00:00
|
|
|
if ( !( f=fopen( mf->names[mf->curr_frame],"r" ) ) ) return 0;
|
2003-04-26 12:27:56 +00:00
|
|
|
#endif
|
2002-02-06 20:15:36 +00:00
|
|
|
{
|
|
|
|
sh_video_t * sh_video = demuxer->video->sh;
|
|
|
|
demux_packet_t * dp = new_demux_packet( fs.st_size );
|
2002-02-07 12:07:47 +00:00
|
|
|
if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
|
2002-09-15 19:47:49 +00:00
|
|
|
dp->pts=mf->curr_frame / sh_video->fps;
|
|
|
|
dp->pos=mf->curr_frame;
|
2002-02-06 20:15:36 +00:00
|
|
|
dp->flags=0;
|
|
|
|
// append packet to DS stream:
|
|
|
|
ds_add_packet( demuxer->video,dp );
|
|
|
|
}
|
|
|
|
fclose( f );
|
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
mf->curr_frame++;
|
2002-02-06 20:15:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static demuxer_t* demux_open_mf(demuxer_t* demuxer){
|
2002-02-06 20:15:36 +00:00
|
|
|
sh_video_t *sh_video = NULL;
|
|
|
|
mf_t *mf = NULL;
|
2002-09-15 19:47:49 +00:00
|
|
|
|
|
|
|
if(!demuxer->stream->url) return NULL;
|
2003-01-28 22:00:57 +00:00
|
|
|
|
2006-02-14 09:34:30 +00:00
|
|
|
|
|
|
|
mf=open_mf(demuxer->stream->url + 5);
|
|
|
|
if(!mf) return NULL;
|
|
|
|
|
2003-01-28 22:00:57 +00:00
|
|
|
if(!mf_type){
|
2006-02-14 09:34:30 +00:00
|
|
|
char* p=strrchr(mf->names[0],'.');
|
2003-01-28 22:00:57 +00:00
|
|
|
if(!p){
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! (try -mf type=xxx)\n" );
|
|
|
|
free( mf ); return NULL;
|
|
|
|
}
|
|
|
|
mf_type=strdup(p+1);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type);
|
|
|
|
}
|
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
mf->curr_frame=0;
|
2002-02-06 20:15:36 +00:00
|
|
|
|
|
|
|
demuxer->movi_start = 0;
|
|
|
|
demuxer->movi_end = mf->nr_of_files - 1;
|
|
|
|
|
|
|
|
// 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;
|
2003-01-28 22:00:57 +00:00
|
|
|
|
2002-02-11 09:15:59 +00:00
|
|
|
if ( !strcasecmp( mf_type,"jpg" ) ||
|
2002-03-10 22:49:18 +00:00
|
|
|
!(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('I', 'J', 'P', 'G');
|
2002-09-10 20:59:52 +00:00
|
|
|
else
|
2002-02-11 09:15:59 +00:00
|
|
|
if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' );
|
2002-09-10 20:59:52 +00:00
|
|
|
else
|
|
|
|
if ( !strcasecmp( mf_type,"tga" )) sh_video->format = mmioFOURCC('M', 'T', 'G', 'A' );
|
2003-03-05 10:38:56 +00:00
|
|
|
else
|
|
|
|
if (!strcasecmp( mf_type,"sgi" )) sh_video->format = mmioFOURCC('S', 'G', 'I', '1');
|
|
|
|
else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknown input file type.\n" ); free( mf ); return NULL; }
|
2002-02-06 20:15:36 +00:00
|
|
|
|
|
|
|
sh_video->disp_w = mf_w;
|
|
|
|
sh_video->disp_h = mf_h;
|
|
|
|
sh_video->fps = mf_fps;
|
|
|
|
sh_video->frametime = 1 / sh_video->fps;
|
|
|
|
|
2002-02-06 22:03:19 +00:00
|
|
|
// emulate BITMAPINFOHEADER:
|
|
|
|
sh_video->bih=malloc(sizeof(BITMAPINFOHEADER));
|
|
|
|
memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER));
|
|
|
|
sh_video->bih->biSize=40;
|
|
|
|
sh_video->bih->biWidth = mf_w;
|
|
|
|
sh_video->bih->biHeight = mf_h;
|
|
|
|
sh_video->bih->biPlanes=1;
|
|
|
|
sh_video->bih->biBitCount=24;
|
|
|
|
sh_video->bih->biCompression=sh_video->format;
|
|
|
|
sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3;
|
|
|
|
|
2002-02-06 20:15:36 +00:00
|
|
|
/* disable seeking */
|
2002-02-07 12:07:47 +00:00
|
|
|
// demuxer->seekable = 0;
|
2002-02-06 20:15:36 +00:00
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
demuxer->priv=(void*)mf;
|
2002-02-06 20:15:36 +00:00
|
|
|
|
|
|
|
return demuxer;
|
|
|
|
}
|
2002-04-24 15:36:07 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static void demux_close_mf(demuxer_t* demuxer) {
|
2002-09-15 19:47:49 +00:00
|
|
|
mf_t *mf = demuxer->priv;
|
2002-04-24 15:36:07 +00:00
|
|
|
|
2002-09-15 19:47:49 +00:00
|
|
|
if(!mf)
|
2002-04-24 15:36:07 +00:00
|
|
|
return;
|
2002-09-15 19:47:49 +00:00
|
|
|
free(mf);
|
2002-04-24 15:36:07 +00:00
|
|
|
}
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
demuxer_desc_t demuxer_desc_mf = {
|
|
|
|
"mf demuxer",
|
|
|
|
"mf",
|
|
|
|
"MF",
|
|
|
|
"?",
|
|
|
|
"multiframe?, pictures demuxer",
|
|
|
|
DEMUXER_TYPE_MF,
|
|
|
|
0, // no autodetect
|
|
|
|
NULL,
|
|
|
|
demux_mf_fill_buffer,
|
|
|
|
demux_open_mf,
|
|
|
|
demux_close_mf,
|
|
|
|
demux_seek_mf,
|
|
|
|
NULL
|
|
|
|
};
|