2009-05-08 23:51:13 +02:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-02-06 21:15:36 +01: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"
|
|
|
|
|
2007-03-15 19:36:36 +01:00
|
|
|
#include "stream/stream.h"
|
2002-02-06 21:15:36 +01:00
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
#include "mf.h"
|
|
|
|
|
2006-02-17 02:57:41 +01:00
|
|
|
static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
|
2002-09-15 21:47:49 +02:00
|
|
|
mf_t * mf = (mf_t *)demuxer->priv;
|
2002-02-07 13:07:47 +01:00
|
|
|
sh_video_t * sh_video = demuxer->video->sh;
|
2008-01-29 16:11:38 +01:00
|
|
|
int newpos = (flags & SEEK_ABSOLUTE)?0:mf->curr_frame - 1;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2008-01-29 16:11:38 +01:00
|
|
|
if ( flags & SEEK_FACTOR ) newpos+=rel_seek_secs*(mf->nr_of_files - 1);
|
2002-02-07 13:07:47 +01:00
|
|
|
else newpos+=rel_seek_secs * sh_video->fps;
|
|
|
|
if ( newpos < 0 ) newpos=0;
|
2006-07-26 11:30:43 +02:00
|
|
|
if( newpos >= mf->nr_of_files) newpos=mf->nr_of_files - 1;
|
2009-08-17 08:14:12 +02:00
|
|
|
demuxer->filepos=mf->curr_frame=newpos;
|
2002-02-06 21:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found
|
|
|
|
// 1 = successfully read a packet
|
2005-08-05 21:57:47 +02:00
|
|
|
static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){
|
2002-02-06 21:15:36 +01:00
|
|
|
mf_t * mf;
|
|
|
|
struct stat fs;
|
|
|
|
FILE * f;
|
|
|
|
|
2002-09-15 21:47:49 +02:00
|
|
|
mf=(mf_t*)demuxer->priv;
|
|
|
|
if ( mf->curr_frame >= mf->nr_of_files ) return 0;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2002-09-15 21:47:49 +02: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 21:15:36 +01:00
|
|
|
|
2003-04-26 14:27:56 +02:00
|
|
|
if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0;
|
2002-02-06 21:15:36 +01:00
|
|
|
{
|
|
|
|
sh_video_t * sh_video = demuxer->video->sh;
|
|
|
|
demux_packet_t * dp = new_demux_packet( fs.st_size );
|
2002-02-07 13:07:47 +01:00
|
|
|
if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
|
2002-09-15 21:47:49 +02:00
|
|
|
dp->pts=mf->curr_frame / sh_video->fps;
|
|
|
|
dp->pos=mf->curr_frame;
|
2002-02-06 21:15:36 +01:00
|
|
|
dp->flags=0;
|
|
|
|
// append packet to DS stream:
|
|
|
|
ds_add_packet( demuxer->video,dp );
|
|
|
|
}
|
|
|
|
fclose( f );
|
|
|
|
|
2009-08-17 08:14:12 +02:00
|
|
|
demuxer->filepos=mf->curr_frame++;
|
2002-02-06 21:15:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-21 20:46:13 +01:00
|
|
|
// force extension/type to have a fourcc
|
|
|
|
|
2007-11-17 18:27:30 +01:00
|
|
|
static const struct {
|
|
|
|
const char *type;
|
2007-11-18 11:02:28 +01:00
|
|
|
uint32_t format;
|
2007-11-17 18:27:30 +01:00
|
|
|
} type2format[] = {
|
|
|
|
{ "bmp", mmioFOURCC('b', 'm', 'p', ' ') },
|
2009-08-11 19:56:19 +02:00
|
|
|
{ "dpx", mmioFOURCC('d', 'p', 'x', ' ') },
|
2010-01-03 01:58:56 +01:00
|
|
|
{ "j2k", mmioFOURCC('M', 'J', '2', 'C') },
|
|
|
|
{ "jp2", mmioFOURCC('M', 'J', '2', 'C') },
|
2007-11-17 18:27:30 +01:00
|
|
|
{ "jpeg", mmioFOURCC('I', 'J', 'P', 'G') },
|
|
|
|
{ "jpg", mmioFOURCC('I', 'J', 'P', 'G') },
|
2009-03-21 20:46:13 +01:00
|
|
|
{ "jls", mmioFOURCC('I', 'J', 'P', 'G') },
|
|
|
|
{ "thm", mmioFOURCC('I', 'J', 'P', 'G') },
|
|
|
|
{ "db", mmioFOURCC('I', 'J', 'P', 'G') },
|
2008-02-13 22:36:27 +01:00
|
|
|
{ "pcx", mmioFOURCC('p', 'c', 'x', ' ') },
|
2007-11-17 18:27:30 +01:00
|
|
|
{ "png", mmioFOURCC('M', 'P', 'N', 'G') },
|
2008-05-12 04:09:47 +02:00
|
|
|
{ "ptx", mmioFOURCC('p', 't', 'x', ' ') },
|
2007-11-17 18:27:30 +01:00
|
|
|
{ "tga", mmioFOURCC('M', 'T', 'G', 'A') },
|
|
|
|
{ "tif", mmioFOURCC('t', 'i', 'f', 'f') },
|
|
|
|
{ "sgi", mmioFOURCC('S', 'G', 'I', '1') },
|
2008-02-25 19:30:02 +01:00
|
|
|
{ "sun", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "ras", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "ra", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "im1", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "im8", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "im24", mmioFOURCC('s', 'u', 'n', ' ') },
|
|
|
|
{ "sunras", mmioFOURCC('s', 'u', 'n', ' ') },
|
2007-11-17 18:27:30 +01:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2005-08-05 21:57:47 +02:00
|
|
|
static demuxer_t* demux_open_mf(demuxer_t* demuxer){
|
2002-02-06 21:15:36 +01:00
|
|
|
sh_video_t *sh_video = NULL;
|
|
|
|
mf_t *mf = NULL;
|
2007-11-17 18:27:30 +01:00
|
|
|
int i;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2002-09-15 21:47:49 +02:00
|
|
|
if(!demuxer->stream->url) return NULL;
|
2007-02-01 21:31:40 +01:00
|
|
|
if(strncmp(demuxer->stream->url, "mf://", 5)) return NULL;
|
2003-01-28 23:00:57 +01:00
|
|
|
|
2006-02-14 10:34:30 +01:00
|
|
|
|
|
|
|
mf=open_mf(demuxer->stream->url + 5);
|
|
|
|
if(!mf) return NULL;
|
|
|
|
|
2003-01-28 23:00:57 +01:00
|
|
|
if(!mf_type){
|
2006-02-14 10:34:30 +01:00
|
|
|
char* p=strrchr(mf->names[0],'.');
|
2003-01-28 23:00:57 +01: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);
|
|
|
|
}
|
|
|
|
|
2009-08-17 08:14:12 +02:00
|
|
|
demuxer->filepos=mf->curr_frame=0;
|
2002-02-06 21:15:36 +01: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;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2007-11-17 18:27:30 +01:00
|
|
|
for (i = 0; type2format[i].type; i++)
|
|
|
|
if (strcasecmp(mf_type, type2format[i].type) == 0)
|
|
|
|
break;
|
|
|
|
if (!type2format[i].type) {
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknown input file type.\n" );
|
|
|
|
free(mf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sh_video->format = type2format[i].format;
|
2002-02-06 21:15:36 +01: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 23:03:19 +01: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 21:15:36 +01:00
|
|
|
/* disable seeking */
|
2002-02-07 13:07:47 +01:00
|
|
|
// demuxer->seekable = 0;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2002-09-15 21:47:49 +02:00
|
|
|
demuxer->priv=(void*)mf;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
|
|
|
return demuxer;
|
|
|
|
}
|
2002-04-24 17:36:07 +02:00
|
|
|
|
2005-08-05 21:57:47 +02:00
|
|
|
static void demux_close_mf(demuxer_t* demuxer) {
|
2002-09-15 21:47:49 +02:00
|
|
|
mf_t *mf = demuxer->priv;
|
2002-04-24 17:36:07 +02:00
|
|
|
|
2002-09-15 21:47:49 +02:00
|
|
|
if(!mf)
|
2002-04-24 17:36:07 +02:00
|
|
|
return;
|
2009-05-13 04:58:57 +02:00
|
|
|
free(mf);
|
2002-04-24 17:36:07 +02:00
|
|
|
}
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2006-07-28 20:19:44 +02:00
|
|
|
static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg) {
|
|
|
|
mf_t *mf = (mf_t *)demuxer->priv;
|
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
|
|
|
*((double *)arg) = (double)mf->nr_of_files / sh_video->fps;
|
|
|
|
return DEMUXER_CTRL_OK;
|
|
|
|
|
|
|
|
case DEMUXER_CTRL_GET_PERCENT_POS:
|
2006-09-11 21:01:20 +02:00
|
|
|
if (mf->nr_of_files <= 1)
|
|
|
|
return DEMUXER_CTRL_DONTKNOW;
|
2006-07-28 20:19:44 +02:00
|
|
|
*((int *)arg) = 100 * mf->curr_frame / (mf->nr_of_files - 1);
|
|
|
|
return DEMUXER_CTRL_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-01-13 17:00:39 +01:00
|
|
|
const demuxer_desc_t demuxer_desc_mf = {
|
2005-08-05 21:57:47 +02:00
|
|
|
"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,
|
2006-07-28 20:19:44 +02:00
|
|
|
demux_control_mf
|
2005-08-05 21:57:47 +02:00
|
|
|
};
|