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