annotate libmpdemux/demux_mf.c @ 8067:482666d4c729

- cleanup - add fixed-vo support please test, this is working for me
author pontscho
date Sun, 03 Nov 2002 00:39:28 +0000
parents 8780415baa87
children 946b14a9e743
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
1
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
2 #include <stdio.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
3 #include <stdlib.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
4 #include <unistd.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
5 #include <sys/types.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
6 #include <sys/stat.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
7 #include <unistd.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
8
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
9 #include "config.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
10 #include "mp_msg.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
11 #include "help_mp.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
12
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
13 #include "stream.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
14 #include "demuxer.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
15 #include "stheader.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
16 #include "mf.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
17
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
18 void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags){
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
19 mf_t * mf = (mf_t *)demuxer->priv;
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
20 sh_video_t * sh_video = demuxer->video->sh;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
21 int newpos = (flags & 1)?0:mf->curr_frame;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
22
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
23 if ( flags & 2 ) newpos+=rel_seek_secs*mf->nr_of_files;
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
24 else newpos+=rel_seek_secs * sh_video->fps;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
25 if ( newpos < 0 ) newpos=0;
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
26 if( newpos > mf->nr_of_files) newpos=mf->nr_of_files;
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
27 mf->curr_frame=newpos;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
28 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
29
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
30 // return value:
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
31 // 0 = EOF or no stream found
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
32 // 1 = successfully read a packet
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
33 int demux_mf_fill_buffer(demuxer_t *demuxer){
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
34 mf_t * mf;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
35 struct stat fs;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
36 FILE * f;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
37
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
38 mf=(mf_t*)demuxer->priv;
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
39 if ( mf->curr_frame >= mf->nr_of_files ) return 0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
40
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
41 stat( mf->names[mf->curr_frame],&fs );
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
42 // printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
43
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
44 if ( !( f=fopen( mf->names[mf->curr_frame],"r" ) ) ) return 0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
45 {
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
46 sh_video_t * sh_video = demuxer->video->sh;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
47 demux_packet_t * dp = new_demux_packet( fs.st_size );
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
48 if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
49 dp->pts=mf->curr_frame / sh_video->fps;
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
50 dp->pos=mf->curr_frame;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
51 dp->flags=0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
52 // append packet to DS stream:
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
53 ds_add_packet( demuxer->video,dp );
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
54 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
55 fclose( f );
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
56
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
57 mf->curr_frame++;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
58 return 1;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
59 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
60
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
61 demuxer_t* demux_open_mf(demuxer_t* demuxer){
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
62 sh_video_t *sh_video = NULL;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
63 mf_t *mf = NULL;
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
64
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
65 if(!demuxer->stream->url) return NULL;
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
66 mf=open_mf(demuxer->stream->url);
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
67 if(!mf) return NULL;
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
68 mf->curr_frame=0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
69
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
70 demuxer->movi_start = 0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
71 demuxer->movi_end = mf->nr_of_files - 1;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
72
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
73 // create a new video stream header
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
74 sh_video = new_sh_video(demuxer, 0);
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
75 // make sure the demuxer knows about the new video stream header
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
76 // (even though new_sh_video() ought to take care of it)
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
77 demuxer->video->sh = sh_video;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
78
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
79 // make sure that the video demuxer stream header knows about its
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
80 // parent video demuxer stream (this is getting wacky), or else
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
81 // video_read_properties() will choke
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
82 sh_video->ds = demuxer->video;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
83
4656
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
84 if ( !strcasecmp( mf_type,"jpg" ) ||
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents: 4656
diff changeset
85 !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('I', 'J', 'P', 'G');
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents: 5810
diff changeset
86 else
4656
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
87 if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' );
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents: 5810
diff changeset
88 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents: 5810
diff changeset
89 if ( !strcasecmp( mf_type,"tga" )) sh_video->format = mmioFOURCC('M', 'T', 'G', 'A' );
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
90 else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( mf ); return NULL; }
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
91
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
92 sh_video->disp_w = mf_w;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
93 sh_video->disp_h = mf_h;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
94 sh_video->fps = mf_fps;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
95 sh_video->frametime = 1 / sh_video->fps;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
96
4556
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
97 // emulate BITMAPINFOHEADER:
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
98 sh_video->bih=malloc(sizeof(BITMAPINFOHEADER));
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
99 memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER));
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
100 sh_video->bih->biSize=40;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
101 sh_video->bih->biWidth = mf_w;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
102 sh_video->bih->biHeight = mf_h;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
103 sh_video->bih->biPlanes=1;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
104 sh_video->bih->biBitCount=24;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
105 sh_video->bih->biCompression=sh_video->format;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
106 sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
107
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
108 /* disable seeking */
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
109 // demuxer->seekable = 0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
110
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
111 demuxer->priv=(void*)mf;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
112
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
113 return demuxer;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
114 }
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5029
diff changeset
115
8a357300d0ec Added demuxer uninit
albeu
parents: 5029
diff changeset
116 void demux_close_mf(demuxer_t* demuxer) {
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
117 mf_t *mf = demuxer->priv;
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5029
diff changeset
118
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
119 if(!mf)
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5029
diff changeset
120 return;
7407
8780415baa87 stream layer cleanup - part 1
arpi
parents: 7362
diff changeset
121 free(mf);
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5029
diff changeset
122 }