Mercurial > mplayer.hg
annotate libmpdemux/demux_mf.c @ 30043:6e9c29e16658
Set fast_bilinear functions in sws_init_swScale().
author | ramiro |
---|---|
date | Sun, 20 Dec 2009 17:09:46 +0000 |
parents | 6f7e97c44353 |
children | e6373560edd1 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
2 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
3 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
7 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
8 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
12 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
13 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28990
diff
changeset
|
17 */ |
4550 | 18 |
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> | |
25 | |
26 #include "config.h" | |
27 #include "mp_msg.h" | |
28 #include "help_mp.h" | |
29 | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22083
diff
changeset
|
30 #include "stream/stream.h" |
4550 | 31 #include "demuxer.h" |
32 #include "stheader.h" | |
33 #include "mf.h" | |
34 | |
17636 | 35 static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
7407 | 36 mf_t * mf = (mf_t *)demuxer->priv; |
4565 | 37 sh_video_t * sh_video = demuxer->video->sh; |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
38 int newpos = (flags & SEEK_ABSOLUTE)?0:mf->curr_frame - 1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
39 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
40 if ( flags & SEEK_FACTOR ) newpos+=rel_seek_secs*(mf->nr_of_files - 1); |
4565 | 41 else newpos+=rel_seek_secs * sh_video->fps; |
42 if ( newpos < 0 ) newpos=0; | |
19180 | 43 if( newpos >= mf->nr_of_files) newpos=mf->nr_of_files - 1; |
29488
6f7e97c44353
Set demuxer->filepos in mf demuxer, since the stream_tell fallback is not
reimar
parents:
29447
diff
changeset
|
44 demuxer->filepos=mf->curr_frame=newpos; |
4550 | 45 } |
46 | |
47 // return value: | |
48 // 0 = EOF or no stream found | |
49 // 1 = successfully read a packet | |
16175 | 50 static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){ |
4550 | 51 mf_t * mf; |
52 struct stat fs; | |
53 FILE * f; | |
54 | |
7407 | 55 mf=(mf_t*)demuxer->priv; |
56 if ( mf->curr_frame >= mf->nr_of_files ) return 0; | |
4550 | 57 |
7407 | 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 ); | |
4550 | 60 |
9992 | 61 if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0; |
4550 | 62 { |
63 sh_video_t * sh_video = demuxer->video->sh; | |
64 demux_packet_t * dp = new_demux_packet( fs.st_size ); | |
4565 | 65 if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0; |
7407 | 66 dp->pts=mf->curr_frame / sh_video->fps; |
67 dp->pos=mf->curr_frame; | |
4550 | 68 dp->flags=0; |
69 // append packet to DS stream: | |
70 ds_add_packet( demuxer->video,dp ); | |
71 } | |
72 fclose( f ); | |
73 | |
29488
6f7e97c44353
Set demuxer->filepos in mf demuxer, since the stream_tell fallback is not
reimar
parents:
29447
diff
changeset
|
74 demuxer->filepos=mf->curr_frame++; |
4550 | 75 return 1; |
76 } | |
77 | |
28990
e2552a27678c
map jls (jpeg-ls), thm and db (thumbnails) files to jpg
compn
parents:
26711
diff
changeset
|
78 // force extension/type to have a fourcc |
e2552a27678c
map jls (jpeg-ls), thm and db (thumbnails) files to jpg
compn
parents:
26711
diff
changeset
|
79 |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
80 static const struct { |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
81 const char *type; |
25062
25ee4d06a2df
100l, fix uint32_t* instead of uint32_t typo in demux_mf type->fourcc table
reimar
parents:
25034
diff
changeset
|
82 uint32_t format; |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
83 } type2format[] = { |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
84 { "bmp", mmioFOURCC('b', 'm', 'p', ' ') }, |
29447 | 85 { "dpx", mmioFOURCC('d', 'p', 'x', ' ') }, |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
86 { "jpeg", mmioFOURCC('I', 'J', 'P', 'G') }, |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
87 { "jpg", mmioFOURCC('I', 'J', 'P', 'G') }, |
28990
e2552a27678c
map jls (jpeg-ls), thm and db (thumbnails) files to jpg
compn
parents:
26711
diff
changeset
|
88 { "jls", mmioFOURCC('I', 'J', 'P', 'G') }, |
e2552a27678c
map jls (jpeg-ls), thm and db (thumbnails) files to jpg
compn
parents:
26711
diff
changeset
|
89 { "thm", mmioFOURCC('I', 'J', 'P', 'G') }, |
e2552a27678c
map jls (jpeg-ls), thm and db (thumbnails) files to jpg
compn
parents:
26711
diff
changeset
|
90 { "db", mmioFOURCC('I', 'J', 'P', 'G') }, |
25961 | 91 { "pcx", mmioFOURCC('p', 'c', 'x', ' ') }, |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
92 { "png", mmioFOURCC('M', 'P', 'N', 'G') }, |
26711 | 93 { "ptx", mmioFOURCC('p', 't', 'x', ' ') }, |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
94 { "tga", mmioFOURCC('M', 'T', 'G', 'A') }, |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
95 { "tif", mmioFOURCC('t', 'i', 'f', 'f') }, |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
96 { "sgi", mmioFOURCC('S', 'G', 'I', '1') }, |
26070 | 97 { "sun", mmioFOURCC('s', 'u', 'n', ' ') }, |
98 { "ras", mmioFOURCC('s', 'u', 'n', ' ') }, | |
99 { "ra", mmioFOURCC('s', 'u', 'n', ' ') }, | |
100 { "im1", mmioFOURCC('s', 'u', 'n', ' ') }, | |
101 { "im8", mmioFOURCC('s', 'u', 'n', ' ') }, | |
102 { "im24", mmioFOURCC('s', 'u', 'n', ' ') }, | |
103 { "sunras", mmioFOURCC('s', 'u', 'n', ' ') }, | |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
104 { NULL, 0 } |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
105 }; |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
106 |
16175 | 107 static demuxer_t* demux_open_mf(demuxer_t* demuxer){ |
4550 | 108 sh_video_t *sh_video = NULL; |
109 mf_t *mf = NULL; | |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
110 int i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
111 |
7407 | 112 if(!demuxer->stream->url) return NULL; |
22083
59982606e602
mf demuxer only works with mf:// urls, so check for that.
reimar
parents:
19794
diff
changeset
|
113 if(strncmp(demuxer->stream->url, "mf://", 5)) return NULL; |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
114 |
17624
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
115 |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
116 mf=open_mf(demuxer->stream->url + 5); |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
117 if(!mf) return NULL; |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
118 |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
119 if(!mf_type){ |
17624
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
120 char* p=strrchr(mf->names[0],'.'); |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
121 if(!p){ |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
122 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! (try -mf type=xxx)\n" ); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
123 free( mf ); return NULL; |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
124 } |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
125 mf_type=strdup(p+1); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
126 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
127 } |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
128 |
29488
6f7e97c44353
Set demuxer->filepos in mf demuxer, since the stream_tell fallback is not
reimar
parents:
29447
diff
changeset
|
129 demuxer->filepos=mf->curr_frame=0; |
4550 | 130 |
131 demuxer->movi_start = 0; | |
132 demuxer->movi_end = mf->nr_of_files - 1; | |
133 | |
134 // create a new video stream header | |
135 sh_video = new_sh_video(demuxer, 0); | |
136 // make sure the demuxer knows about the new video stream header | |
137 // (even though new_sh_video() ought to take care of it) | |
138 demuxer->video->sh = sh_video; | |
139 | |
140 // make sure that the video demuxer stream header knows about its | |
141 // parent video demuxer stream (this is getting wacky), or else | |
142 // video_read_properties() will choke | |
143 sh_video->ds = demuxer->video; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
144 |
25033
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
145 for (i = 0; type2format[i].type; i++) |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
146 if (strcasecmp(mf_type, type2format[i].type) == 0) |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
147 break; |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
148 if (!type2format[i].type) { |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
149 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknown input file type.\n" ); |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
150 free(mf); |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
151 return NULL; |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
152 } |
3dceb6c96307
Replace if-else constructs for type -> fourcc mapping by a table in demux_mf
reimar
parents:
25020
diff
changeset
|
153 sh_video->format = type2format[i].format; |
4550 | 154 |
155 sh_video->disp_w = mf_w; | |
156 sh_video->disp_h = mf_h; | |
157 sh_video->fps = mf_fps; | |
158 sh_video->frametime = 1 / sh_video->fps; | |
159 | |
4556 | 160 // emulate BITMAPINFOHEADER: |
161 sh_video->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
162 memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER)); | |
163 sh_video->bih->biSize=40; | |
164 sh_video->bih->biWidth = mf_w; | |
165 sh_video->bih->biHeight = mf_h; | |
166 sh_video->bih->biPlanes=1; | |
167 sh_video->bih->biBitCount=24; | |
168 sh_video->bih->biCompression=sh_video->format; | |
169 sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3; | |
170 | |
4550 | 171 /* disable seeking */ |
4565 | 172 // demuxer->seekable = 0; |
4550 | 173 |
7407 | 174 demuxer->priv=(void*)mf; |
4550 | 175 |
176 return demuxer; | |
177 } | |
5810 | 178 |
16175 | 179 static void demux_close_mf(demuxer_t* demuxer) { |
7407 | 180 mf_t *mf = demuxer->priv; |
5810 | 181 |
7407 | 182 if(!mf) |
5810 | 183 return; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
184 free(mf); |
5810 | 185 } |
16175 | 186 |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
187 static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg) { |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
188 mf_t *mf = (mf_t *)demuxer->priv; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
189 sh_video_t *sh_video = demuxer->video->sh; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
190 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
191 switch(cmd) { |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
192 case DEMUXER_CTRL_GET_TIME_LENGTH: |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
193 *((double *)arg) = (double)mf->nr_of_files / sh_video->fps; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
194 return DEMUXER_CTRL_OK; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
195 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
196 case DEMUXER_CTRL_GET_PERCENT_POS: |
19794
0951c3e8864b
Avoid division by zero DEMUXER_CTRL_GET_PERCENT_POS with only one frame by just
reimar
parents:
19220
diff
changeset
|
197 if (mf->nr_of_files <= 1) |
0951c3e8864b
Avoid division by zero DEMUXER_CTRL_GET_PERCENT_POS with only one frame by just
reimar
parents:
19220
diff
changeset
|
198 return DEMUXER_CTRL_DONTKNOW; |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
199 *((int *)arg) = 100 * mf->curr_frame / (mf->nr_of_files - 1); |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
200 return DEMUXER_CTRL_OK; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
201 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
202 default: |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
203 return DEMUXER_CTRL_NOTIMPL; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
204 } |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
205 } |
16175 | 206 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25062
diff
changeset
|
207 const demuxer_desc_t demuxer_desc_mf = { |
16175 | 208 "mf demuxer", |
209 "mf", | |
210 "MF", | |
211 "?", | |
212 "multiframe?, pictures demuxer", | |
213 DEMUXER_TYPE_MF, | |
214 0, // no autodetect | |
215 NULL, | |
216 demux_mf_fill_buffer, | |
217 demux_open_mf, | |
218 demux_close_mf, | |
219 demux_seek_mf, | |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
220 demux_control_mf |
16175 | 221 }; |