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