2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <sys/types.h>
29 #include "stream/stream.h"
34 static void demux_seek_mf(demuxer_t
*demuxer
,float rel_seek_secs
,float audio_delay
,int flags
){
35 mf_t
* mf
= (mf_t
*)demuxer
->priv
;
36 sh_video_t
* sh_video
= demuxer
->video
->sh
;
37 int newpos
= (flags
& SEEK_ABSOLUTE
)?0:mf
->curr_frame
- 1;
39 if ( flags
& SEEK_FACTOR
) newpos
+=rel_seek_secs
*(mf
->nr_of_files
- 1);
40 else newpos
+=rel_seek_secs
* sh_video
->fps
;
41 if ( newpos
< 0 ) newpos
=0;
42 if( newpos
>= mf
->nr_of_files
) newpos
=mf
->nr_of_files
- 1;
43 demuxer
->filepos
=mf
->curr_frame
=newpos
;
47 // 0 = EOF or no stream found
48 // 1 = successfully read a packet
49 static int demux_mf_fill_buffer(demuxer_t
*demuxer
, demux_stream_t
*ds
){
54 mf
=(mf_t
*)demuxer
->priv
;
55 if ( mf
->curr_frame
>= mf
->nr_of_files
) return 0;
57 stat( mf
->names
[mf
->curr_frame
],&fs
);
58 // printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
60 if ( !( f
=fopen( mf
->names
[mf
->curr_frame
],"rb" ) ) ) return 0;
62 sh_video_t
* sh_video
= demuxer
->video
->sh
;
63 demux_packet_t
* dp
= new_demux_packet( fs
.st_size
);
64 if ( !fread( dp
->buffer
,fs
.st_size
,1,f
) ) return 0;
65 dp
->pts
=mf
->curr_frame
/ sh_video
->fps
;
66 dp
->pos
=mf
->curr_frame
;
68 // append packet to DS stream:
69 ds_add_packet( demuxer
->video
,dp
);
73 demuxer
->filepos
=mf
->curr_frame
++;
77 // force extension/type to have a fourcc
83 { "bmp", mmioFOURCC('b', 'm', 'p', ' ') },
84 { "dpx", mmioFOURCC('d', 'p', 'x', ' ') },
85 { "j2k", mmioFOURCC('M', 'J', '2', 'C') },
86 { "jp2", mmioFOURCC('M', 'J', '2', 'C') },
87 { "jpeg", mmioFOURCC('I', 'J', 'P', 'G') },
88 { "jpg", mmioFOURCC('I', 'J', 'P', 'G') },
89 { "jls", mmioFOURCC('I', 'J', 'P', 'G') },
90 { "thm", mmioFOURCC('I', 'J', 'P', 'G') },
91 { "db", mmioFOURCC('I', 'J', 'P', 'G') },
92 { "pcx", mmioFOURCC('p', 'c', 'x', ' ') },
93 { "png", mmioFOURCC('M', 'P', 'N', 'G') },
94 { "ptx", mmioFOURCC('p', 't', 'x', ' ') },
95 { "tga", mmioFOURCC('M', 'T', 'G', 'A') },
96 { "tif", mmioFOURCC('t', 'i', 'f', 'f') },
97 { "sgi", mmioFOURCC('S', 'G', 'I', '1') },
98 { "sun", mmioFOURCC('s', 'u', 'n', ' ') },
99 { "ras", mmioFOURCC('s', 'u', 'n', ' ') },
100 { "ra", mmioFOURCC('s', 'u', 'n', ' ') },
101 { "im1", mmioFOURCC('s', 'u', 'n', ' ') },
102 { "im8", mmioFOURCC('s', 'u', 'n', ' ') },
103 { "im24", mmioFOURCC('s', 'u', 'n', ' ') },
104 { "sunras", mmioFOURCC('s', 'u', 'n', ' ') },
108 static demuxer_t
* demux_open_mf(demuxer_t
* demuxer
){
109 sh_video_t
*sh_video
= NULL
;
113 if(!demuxer
->stream
->url
) return NULL
;
114 if(strncmp(demuxer
->stream
->url
, "mf://", 5)) return NULL
;
117 mf
=open_mf(demuxer
->stream
->url
+ 5);
121 char* p
=strrchr(mf
->names
[0],'.');
123 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] file type was not set! (try -mf type=xxx)\n" );
124 free( mf
); return NULL
;
127 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type
);
130 demuxer
->filepos
=mf
->curr_frame
=0;
132 demuxer
->movi_start
= 0;
133 demuxer
->movi_end
= mf
->nr_of_files
- 1;
135 // create a new video stream header
136 sh_video
= new_sh_video(demuxer
, 0);
137 // make sure the demuxer knows about the new video stream header
138 // (even though new_sh_video() ought to take care of it)
139 demuxer
->video
->sh
= sh_video
;
141 // make sure that the video demuxer stream header knows about its
142 // parent video demuxer stream (this is getting wacky), or else
143 // video_read_properties() will choke
144 sh_video
->ds
= demuxer
->video
;
146 for (i
= 0; type2format
[i
].type
; i
++)
147 if (strcasecmp(mf_type
, type2format
[i
].type
) == 0)
149 if (!type2format
[i
].type
) {
150 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] unknown input file type.\n" );
154 sh_video
->format
= type2format
[i
].format
;
156 sh_video
->disp_w
= mf_w
;
157 sh_video
->disp_h
= mf_h
;
158 sh_video
->fps
= mf_fps
;
159 sh_video
->frametime
= 1 / sh_video
->fps
;
161 // emulate BITMAPINFOHEADER:
162 sh_video
->bih
=malloc(sizeof(BITMAPINFOHEADER
));
163 memset(sh_video
->bih
,0,sizeof(BITMAPINFOHEADER
));
164 sh_video
->bih
->biSize
=40;
165 sh_video
->bih
->biWidth
= mf_w
;
166 sh_video
->bih
->biHeight
= mf_h
;
167 sh_video
->bih
->biPlanes
=1;
168 sh_video
->bih
->biBitCount
=24;
169 sh_video
->bih
->biCompression
=sh_video
->format
;
170 sh_video
->bih
->biSizeImage
=sh_video
->bih
->biWidth
*sh_video
->bih
->biHeight
*3;
172 /* disable seeking */
173 // demuxer->seekable = 0;
175 demuxer
->priv
=(void*)mf
;
180 static void demux_close_mf(demuxer_t
* demuxer
) {
181 mf_t
*mf
= demuxer
->priv
;
188 static int demux_control_mf(demuxer_t
*demuxer
, int cmd
, void *arg
) {
189 mf_t
*mf
= (mf_t
*)demuxer
->priv
;
190 sh_video_t
*sh_video
= demuxer
->video
->sh
;
193 case DEMUXER_CTRL_GET_TIME_LENGTH
:
194 *((double *)arg
) = (double)mf
->nr_of_files
/ sh_video
->fps
;
195 return DEMUXER_CTRL_OK
;
197 case DEMUXER_CTRL_GET_PERCENT_POS
:
198 if (mf
->nr_of_files
<= 1)
199 return DEMUXER_CTRL_DONTKNOW
;
200 *((int *)arg
) = 100 * mf
->curr_frame
/ (mf
->nr_of_files
- 1);
201 return DEMUXER_CTRL_OK
;
204 return DEMUXER_CTRL_NOTIMPL
;
208 const demuxer_desc_t demuxer_desc_mf
= {
213 "multiframe?, pictures demuxer",
217 demux_mf_fill_buffer
,