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>
32 #include "stream/stream.h"
37 static void demux_seek_mf(demuxer_t
*demuxer
,float rel_seek_secs
,float audio_delay
,int flags
){
38 mf_t
* mf
= (mf_t
*)demuxer
->priv
;
39 sh_video_t
* sh_video
= demuxer
->video
->sh
;
40 int newpos
= (flags
& SEEK_ABSOLUTE
)?0:mf
->curr_frame
- 1;
42 if ( flags
& SEEK_FACTOR
) newpos
+=rel_seek_secs
*(mf
->nr_of_files
- 1);
43 else newpos
+=rel_seek_secs
* sh_video
->fps
;
44 if ( newpos
< 0 ) newpos
=0;
45 if( newpos
>= mf
->nr_of_files
) newpos
=mf
->nr_of_files
- 1;
46 demuxer
->filepos
=mf
->curr_frame
=newpos
;
50 // 0 = EOF or no stream found
51 // 1 = successfully read a packet
52 static int demux_mf_fill_buffer(demuxer_t
*demuxer
, demux_stream_t
*ds
){
56 mf
=(mf_t
*)demuxer
->priv
;
57 if ( mf
->curr_frame
>= mf
->nr_of_files
) return 0;
59 if ( !( f
=fopen( mf
->names
[mf
->curr_frame
],"rb" ) ) ) return 0;
61 sh_video_t
* sh_video
= demuxer
->video
->sh
;
62 fseek(f
, 0, SEEK_END
);
63 long file_size
= ftell(f
);
64 fseek(f
, 0, SEEK_SET
);
65 demux_packet_t
* dp
= new_demux_packet( file_size
);
66 if ( !fread( dp
->buffer
,file_size
,1,f
) ) return 0;
67 dp
->pts
=mf
->curr_frame
/ sh_video
->fps
;
68 dp
->pos
=mf
->curr_frame
;
70 // append packet to DS stream:
71 ds_add_packet( demuxer
->video
,dp
);
75 demuxer
->filepos
=mf
->curr_frame
++;
79 // force extension/type to have a fourcc
85 { "bmp", mmioFOURCC('b', 'm', 'p', ' ') },
86 { "dpx", mmioFOURCC('d', 'p', 'x', ' ') },
87 { "j2k", mmioFOURCC('M', 'J', '2', 'C') },
88 { "jp2", mmioFOURCC('M', 'J', '2', 'C') },
89 { "jpeg", mmioFOURCC('I', 'J', 'P', 'G') },
90 { "jpg", mmioFOURCC('I', 'J', 'P', 'G') },
91 { "jls", mmioFOURCC('I', 'J', 'P', 'G') },
92 { "thm", mmioFOURCC('I', 'J', 'P', 'G') },
93 { "db", mmioFOURCC('I', 'J', 'P', 'G') },
94 { "pcx", mmioFOURCC('p', 'c', 'x', ' ') },
95 { "png", mmioFOURCC('M', 'P', 'N', 'G') },
96 { "ptx", mmioFOURCC('p', 't', 'x', ' ') },
97 { "tga", mmioFOURCC('M', 'T', 'G', 'A') },
98 { "tif", mmioFOURCC('t', 'i', 'f', 'f') },
99 { "sgi", mmioFOURCC('S', 'G', 'I', '1') },
100 { "sun", mmioFOURCC('s', 'u', 'n', ' ') },
101 { "ras", mmioFOURCC('s', 'u', 'n', ' ') },
102 { "ra", mmioFOURCC('s', 'u', 'n', ' ') },
103 { "im1", mmioFOURCC('s', 'u', 'n', ' ') },
104 { "im8", mmioFOURCC('s', 'u', 'n', ' ') },
105 { "im24", mmioFOURCC('s', 'u', 'n', ' ') },
106 { "sunras", mmioFOURCC('s', 'u', 'n', ' ') },
110 static demuxer_t
* demux_open_mf(demuxer_t
* demuxer
){
111 sh_video_t
*sh_video
= NULL
;
115 if(!demuxer
->stream
->url
) return NULL
;
116 if(strncmp(demuxer
->stream
->url
, "mf://", 5)) return NULL
;
119 mf
=open_mf(demuxer
->stream
->url
+ 5);
123 char* p
=strrchr(mf
->names
[0],'.');
125 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] file type was not set! (try -mf type=xxx)\n" );
126 free( mf
); return NULL
;
128 mf_type
= talloc_strdup(NULL
, p
+1);
129 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type
);
132 demuxer
->filepos
=mf
->curr_frame
=0;
134 demuxer
->movi_start
= 0;
135 demuxer
->movi_end
= mf
->nr_of_files
- 1;
137 // create a new video stream header
138 sh_video
= new_sh_video(demuxer
, 0);
139 // make sure the demuxer knows about the new video stream header
140 // (even though new_sh_video() ought to take care of it)
141 demuxer
->video
->sh
= sh_video
;
143 // make sure that the video demuxer stream header knows about its
144 // parent video demuxer stream (this is getting wacky), or else
145 // video_read_properties() will choke
146 sh_video
->ds
= demuxer
->video
;
148 for (i
= 0; type2format
[i
].type
; i
++)
149 if (strcasecmp(mf_type
, type2format
[i
].type
) == 0)
151 if (!type2format
[i
].type
) {
152 mp_msg(MSGT_DEMUX
, MSGL_INFO
, "[demux_mf] unknown input file type.\n" );
156 sh_video
->format
= type2format
[i
].format
;
158 sh_video
->disp_w
= mf_w
;
159 sh_video
->disp_h
= mf_h
;
160 sh_video
->fps
= mf_fps
;
161 sh_video
->frametime
= 1 / sh_video
->fps
;
163 // emulate BITMAPINFOHEADER:
164 sh_video
->bih
=calloc(1, sizeof(*sh_video
->bih
));
165 sh_video
->bih
->biSize
=40;
166 sh_video
->bih
->biWidth
= mf_w
;
167 sh_video
->bih
->biHeight
= mf_h
;
168 sh_video
->bih
->biPlanes
=1;
169 sh_video
->bih
->biBitCount
=24;
170 sh_video
->bih
->biCompression
=sh_video
->format
;
171 sh_video
->bih
->biSizeImage
=sh_video
->bih
->biWidth
*sh_video
->bih
->biHeight
*3;
173 /* disable seeking */
174 // demuxer->seekable = 0;
176 demuxer
->priv
=(void*)mf
;
181 static void demux_close_mf(demuxer_t
* demuxer
) {
182 mf_t
*mf
= demuxer
->priv
;
187 static int demux_control_mf(demuxer_t
*demuxer
, int cmd
, void *arg
) {
188 mf_t
*mf
= (mf_t
*)demuxer
->priv
;
189 sh_video_t
*sh_video
= demuxer
->video
->sh
;
192 case DEMUXER_CTRL_GET_TIME_LENGTH
:
193 *((double *)arg
) = (double)mf
->nr_of_files
/ sh_video
->fps
;
194 return DEMUXER_CTRL_OK
;
196 case DEMUXER_CTRL_GET_PERCENT_POS
:
197 if (mf
->nr_of_files
<= 1)
198 return DEMUXER_CTRL_DONTKNOW
;
199 *((int *)arg
) = 100 * mf
->curr_frame
/ (mf
->nr_of_files
- 1);
200 return DEMUXER_CTRL_OK
;
203 return DEMUXER_CTRL_NOTIMPL
;
207 const demuxer_desc_t demuxer_desc_mf
= {
212 "multiframe?, pictures demuxer",
216 demux_mf_fill_buffer
,