Fix compilation after FFmpeg r22522.
[mplayer/glamo.git] / libmpdemux / demux_mf.c
blobfa9b8ae630d6e9000543096d50ec6149eb69caf9
1 /*
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
26 #include "config.h"
27 #include "mp_msg.h"
28 #include "help_mp.h"
30 #include "stream/stream.h"
31 #include "demuxer.h"
32 #include "stheader.h"
33 #include "mf.h"
35 static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
36 mf_t * mf = (mf_t *)demuxer->priv;
37 sh_video_t * sh_video = demuxer->video->sh;
38 int newpos = (flags & SEEK_ABSOLUTE)?0:mf->curr_frame - 1;
40 if ( flags & SEEK_FACTOR ) newpos+=rel_seek_secs*(mf->nr_of_files - 1);
41 else newpos+=rel_seek_secs * sh_video->fps;
42 if ( newpos < 0 ) newpos=0;
43 if( newpos >= mf->nr_of_files) newpos=mf->nr_of_files - 1;
44 demuxer->filepos=mf->curr_frame=newpos;
47 // return value:
48 // 0 = EOF or no stream found
49 // 1 = successfully read a packet
50 static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){
51 mf_t * mf;
52 struct stat fs;
53 FILE * f;
55 mf=(mf_t*)demuxer->priv;
56 if ( mf->curr_frame >= mf->nr_of_files ) return 0;
58 stat( mf->names[mf->curr_frame],&fs );
59 // printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
61 if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0;
63 sh_video_t * sh_video = demuxer->video->sh;
64 demux_packet_t * dp = new_demux_packet( fs.st_size );
65 if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
66 dp->pts=mf->curr_frame / sh_video->fps;
67 dp->pos=mf->curr_frame;
68 dp->flags=0;
69 // append packet to DS stream:
70 ds_add_packet( demuxer->video,dp );
72 fclose( f );
74 demuxer->filepos=mf->curr_frame++;
75 return 1;
78 // force extension/type to have a fourcc
80 static const struct {
81 const char *type;
82 uint32_t format;
83 } type2format[] = {
84 { "bmp", mmioFOURCC('b', 'm', 'p', ' ') },
85 { "dpx", mmioFOURCC('d', 'p', 'x', ' ') },
86 { "j2k", mmioFOURCC('M', 'J', '2', 'C') },
87 { "jp2", mmioFOURCC('M', 'J', '2', 'C') },
88 { "jpeg", mmioFOURCC('I', 'J', 'P', 'G') },
89 { "jpg", mmioFOURCC('I', 'J', 'P', 'G') },
90 { "jls", mmioFOURCC('I', 'J', 'P', 'G') },
91 { "thm", mmioFOURCC('I', 'J', 'P', 'G') },
92 { "db", mmioFOURCC('I', 'J', 'P', 'G') },
93 { "pcx", mmioFOURCC('p', 'c', 'x', ' ') },
94 { "png", mmioFOURCC('M', 'P', 'N', 'G') },
95 { "ptx", mmioFOURCC('p', 't', 'x', ' ') },
96 { "tga", mmioFOURCC('M', 'T', 'G', 'A') },
97 { "tif", mmioFOURCC('t', 'i', 'f', 'f') },
98 { "sgi", mmioFOURCC('S', 'G', 'I', '1') },
99 { "sun", mmioFOURCC('s', 'u', 'n', ' ') },
100 { "ras", mmioFOURCC('s', 'u', 'n', ' ') },
101 { "ra", mmioFOURCC('s', 'u', 'n', ' ') },
102 { "im1", mmioFOURCC('s', 'u', 'n', ' ') },
103 { "im8", mmioFOURCC('s', 'u', 'n', ' ') },
104 { "im24", mmioFOURCC('s', 'u', 'n', ' ') },
105 { "sunras", mmioFOURCC('s', 'u', 'n', ' ') },
106 { NULL, 0 }
109 static demuxer_t* demux_open_mf(demuxer_t* demuxer){
110 sh_video_t *sh_video = NULL;
111 mf_t *mf = NULL;
112 int i;
114 if(!demuxer->stream->url) return NULL;
115 if(strncmp(demuxer->stream->url, "mf://", 5)) return NULL;
118 mf=open_mf(demuxer->stream->url + 5);
119 if(!mf) return NULL;
121 if(!mf_type){
122 char* p=strrchr(mf->names[0],'.');
123 if(!p){
124 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! (try -mf type=xxx)\n" );
125 free( mf ); return NULL;
127 mf_type=strdup(p+1);
128 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type);
131 demuxer->filepos=mf->curr_frame=0;
133 demuxer->movi_start = 0;
134 demuxer->movi_end = mf->nr_of_files - 1;
136 // create a new video stream header
137 sh_video = new_sh_video(demuxer, 0);
138 // make sure the demuxer knows about the new video stream header
139 // (even though new_sh_video() ought to take care of it)
140 demuxer->video->sh = sh_video;
142 // make sure that the video demuxer stream header knows about its
143 // parent video demuxer stream (this is getting wacky), or else
144 // video_read_properties() will choke
145 sh_video->ds = demuxer->video;
147 for (i = 0; type2format[i].type; i++)
148 if (strcasecmp(mf_type, type2format[i].type) == 0)
149 break;
150 if (!type2format[i].type) {
151 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknown input file type.\n" );
152 free(mf);
153 return NULL;
155 sh_video->format = type2format[i].format;
157 sh_video->disp_w = mf_w;
158 sh_video->disp_h = mf_h;
159 sh_video->fps = mf_fps;
160 sh_video->frametime = 1 / sh_video->fps;
162 // emulate BITMAPINFOHEADER:
163 sh_video->bih=malloc(sizeof(BITMAPINFOHEADER));
164 memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER));
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;
178 return demuxer;
181 static void demux_close_mf(demuxer_t* demuxer) {
182 mf_t *mf = demuxer->priv;
184 if(!mf)
185 return;
186 free(mf);
189 static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg) {
190 mf_t *mf = (mf_t *)demuxer->priv;
191 sh_video_t *sh_video = demuxer->video->sh;
193 switch(cmd) {
194 case DEMUXER_CTRL_GET_TIME_LENGTH:
195 *((double *)arg) = (double)mf->nr_of_files / sh_video->fps;
196 return DEMUXER_CTRL_OK;
198 case DEMUXER_CTRL_GET_PERCENT_POS:
199 if (mf->nr_of_files <= 1)
200 return DEMUXER_CTRL_DONTKNOW;
201 *((int *)arg) = 100 * mf->curr_frame / (mf->nr_of_files - 1);
202 return DEMUXER_CTRL_OK;
204 default:
205 return DEMUXER_CTRL_NOTIMPL;
209 const demuxer_desc_t demuxer_desc_mf = {
210 "mf demuxer",
211 "mf",
212 "MF",
213 "?",
214 "multiframe?, pictures demuxer",
215 DEMUXER_TYPE_MF,
216 0, // no autodetect
217 NULL,
218 demux_mf_fill_buffer,
219 demux_open_mf,
220 demux_close_mf,
221 demux_seek_mf,
222 demux_control_mf