Mercurial > mplayer.hg
annotate libmpdemux/open.c @ 6356:b54d7fd6471a
This script has no bash specific stuff, it's all standard bourne shell, so execute with sh.
Also see mail from Michaela.
author | atmos4 |
---|---|
date | Sun, 09 Jun 2002 14:48:16 +0000 |
parents | 12136df07dbd |
children | f0b933918a22 |
rev | line source |
---|---|
1467 | 1 |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
2 #include <ctype.h> |
1467 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #include <unistd.h> | |
7 #include <fcntl.h> | |
8 | |
9 #include "config.h" | |
1567 | 10 #include "mp_msg.h" |
1584 | 11 #include "help_mp.h" |
1467 | 12 |
1468 | 13 #ifdef __FreeBSD__ |
14 #include <sys/cdrio.h> | |
15 #endif | |
16 | |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
17 #include "../cfgparser.h" |
1467 | 18 #include "stream.h" |
1482 | 19 #include "demuxer.h" |
4551 | 20 #include "mf.h" |
1467 | 21 |
22 #ifdef STREAMING | |
23 #include "url.h" | |
24 #include "network.h" | |
25 static URL_t* url; | |
26 #endif | |
27 | |
1596 | 28 int dvd_title=0; |
29 int dvd_chapter=1; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
30 int dvd_last_chapter=0; |
1596 | 31 int dvd_angle=1; |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
32 char* dvd_device=NULL; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
33 char* cdrom_device=NULL; |
5472 | 34 int dvd_nav=0; /* use libdvdnav? */ |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
35 |
5381 | 36 #ifdef USE_DVDNAV |
5472 | 37 #include "dvdnav_stream.h" |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
38 #endif |
1596 | 39 |
40 #ifdef USE_DVDREAD | |
41 | |
1875 | 42 #define DVDREAD_VERSION(maj,min,micro) ((maj)*10000 + (min)*100 + (micro)) |
43 | |
44 /* | |
45 * Try to autodetect the libdvd-0.9.0 library | |
46 * (0.9.0 removed the <dvdread/dvd_udf.h> header, and moved the two defines | |
47 * DVD_VIDEO_LB_LEN and MAX_UDF_FILE_NAME_LEN from it to | |
48 * <dvdread/dvd_reader.h>) | |
49 */ | |
50 #if defined(DVD_VIDEO_LB_LEN) && defined(MAX_UDF_FILE_NAME_LEN) | |
51 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,9,0) | |
52 #else | |
53 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,8,0) | |
54 #endif | |
55 | |
2935 | 56 char * dvd_audio_stream_types[8] = |
57 { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" }; | |
1596 | 58 |
59 #endif | |
60 | |
1467 | 61 extern int vcd_get_track_end(int fd,int track); |
62 | |
2790 | 63 #ifdef USE_TV |
64 #include "tv.h" | |
2802 | 65 tvi_handle_t *tv_handler; |
2931 | 66 |
67 extern int stream_open_tv(stream_t *stream, tvi_handle_t *tvh); | |
2790 | 68 #endif |
69 | |
1467 | 70 // Open a new stream (stdin/file/vcd/url) |
71 | |
72 stream_t* open_stream(char* filename,int vcd_track,int* file_format){ | |
73 stream_t* stream=NULL; | |
74 int f=-1; | |
75 off_t len; | |
76 #ifdef VCD_CACHE | |
77 int vcd_cache_size=128; | |
78 #endif | |
79 #ifdef __FreeBSD__ | |
80 int bsize = VCD_SECTOR_SIZE; | |
81 #endif | |
82 | |
83 //============ Open VideoCD track ============== | |
3261 | 84 #ifdef HAVE_VCD |
1467 | 85 if(vcd_track){ |
86 int ret,ret2; | |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
87 if(!cdrom_device) cdrom_device=DEFAULT_CDROM_DEVICE; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
88 f=open(cdrom_device,O_RDONLY); |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
89 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,cdrom_device);return NULL; } |
1467 | 90 vcd_read_toc(f); |
91 ret2=vcd_get_track_end(f,vcd_track); | |
1584 | 92 if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");return NULL;} |
1467 | 93 ret=vcd_seek_to_track(f,vcd_track); |
1584 | 94 if(ret<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");return NULL;} |
1467 | 95 // seek_to_byte+=ret; |
1567 | 96 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); |
1467 | 97 #ifdef VCD_CACHE |
98 vcd_cache_init(vcd_cache_size); | |
99 #endif | |
100 #ifdef __FreeBSD__ | |
101 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { | |
102 perror ( "Error in CDRIOCSETBLOCKSIZE"); | |
103 } | |
104 #endif | |
105 stream=new_stream(f,STREAMTYPE_VCD); | |
106 stream->start_pos=ret; | |
107 stream->end_pos=ret2; | |
108 return stream; | |
109 } | |
3261 | 110 #endif |
1467 | 111 |
1596 | 112 //============ Open DVD title ============== |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
113 #ifdef USE_DVDNAV |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
114 if(dvd_nav){ |
5472 | 115 dvdnav_priv_t *dvdnav_priv; |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
116 int event,len,tmplen=0; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
117 |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
118 stream=new_stream(-1,STREAMTYPE_DVDNAV); |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
119 if (!stream) { |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
120 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_Exit_error); |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
121 return NULL; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
122 } |
5472 | 123 |
124 if(!filename) filename=DEFAULT_DVD_DEVICE; | |
125 if (!(dvdnav_priv=new_dvdnav_stream(filename))) { | |
126 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,filename); | |
127 return NULL; | |
128 } | |
129 | |
130 stream->priv=(void*)dvdnav_priv; | |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
131 return stream; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
132 } |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
133 #endif |
1596 | 134 #ifdef USE_DVDREAD |
135 if(dvd_title){ | |
2050 | 136 // int ret,ret2; |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
137 dvd_priv_t *d; |
1596 | 138 int ttn,pgc_id,pgn; |
139 dvd_reader_t *dvd; | |
140 dvd_file_t *title; | |
141 ifo_handle_t *vmg_file; | |
142 tt_srpt_t *tt_srpt; | |
143 ifo_handle_t *vts_file; | |
144 /** | |
145 * Open the disc. | |
146 */ | |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
147 if(!dvd_device) dvd_device=DEFAULT_DVD_DEVICE; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
148 dvd = DVDOpen(dvd_device); |
1596 | 149 if( !dvd ) { |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
150 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device); |
1596 | 151 return NULL; |
152 } | |
153 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
154 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDwait); |
1596 | 155 |
156 /** | |
157 * Load the video manager to find out the information about the titles on | |
158 * this disc. | |
159 */ | |
160 vmg_file = ifoOpen( dvd, 0 ); | |
161 if( !vmg_file ) { | |
162 mp_msg(MSGT_OPEN,MSGL_ERR, "Can't open VMG info!\n"); | |
163 DVDClose( dvd ); | |
164 return NULL; | |
165 } | |
166 tt_srpt = vmg_file->tt_srpt; | |
167 /** | |
168 * Make sure our title number is valid. | |
169 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
170 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumTitles, |
1596 | 171 tt_srpt->nr_of_srpts ); |
172 if( dvd_title < 1 || dvd_title > tt_srpt->nr_of_srpts ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
173 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidTitle, dvd_title); |
1596 | 174 ifoClose( vmg_file ); |
175 DVDClose( dvd ); | |
176 return NULL; | |
177 } | |
178 --dvd_title; // remap 1.. -> 0.. | |
179 /** | |
180 * Make sure the chapter number is valid for this title. | |
181 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
182 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumChapters, |
1596 | 183 tt_srpt->title[dvd_title].nr_of_ptts ); |
184 if( dvd_chapter<1 || dvd_chapter>tt_srpt->title[dvd_title].nr_of_ptts ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
185 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidChapter, dvd_chapter); |
1596 | 186 ifoClose( vmg_file ); |
187 DVDClose( dvd ); | |
188 return NULL; | |
189 } | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
190 if( dvd_last_chapter>0 ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
191 if ( dvd_last_chapter<dvd_chapter || dvd_last_chapter>tt_srpt->title[dvd_title].nr_of_ptts ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
192 mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid DVD last chapter number: %d\n", dvd_last_chapter); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
193 ifoClose( vmg_file ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
194 DVDClose( dvd ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
195 return NULL; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
196 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
197 } |
1596 | 198 --dvd_chapter; // remap 1.. -> 0.. |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
199 /* XXX No need to remap dvd_last_chapter */ |
1596 | 200 /** |
201 * Make sure the angle number is valid for this title. | |
202 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
203 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumAngles, |
1596 | 204 tt_srpt->title[dvd_title].nr_of_angles ); |
205 if( dvd_angle<1 || dvd_angle>tt_srpt->title[dvd_title].nr_of_angles ) { | |
1977 | 206 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidAngle, dvd_angle); |
1596 | 207 ifoClose( vmg_file ); |
208 DVDClose( dvd ); | |
209 return NULL; | |
210 } | |
1617 | 211 --dvd_angle; // remap 1.. -> 0.. |
1596 | 212 /** |
213 * Load the VTS information for the title set our title is in. | |
214 */ | |
215 vts_file = ifoOpen( dvd, tt_srpt->title[dvd_title].title_set_nr ); | |
216 if( !vts_file ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
217 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoIFO, |
1596 | 218 tt_srpt->title[dvd_title].title_set_nr ); |
219 ifoClose( vmg_file ); | |
220 DVDClose( dvd ); | |
221 return NULL; | |
222 } | |
223 /** | |
224 * We've got enough info, time to open the title set data. | |
225 */ | |
226 title = DVDOpenFile( dvd, tt_srpt->title[dvd_title].title_set_nr, | |
227 DVD_READ_TITLE_VOBS ); | |
228 if( !title ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
229 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoVOBs, |
1596 | 230 tt_srpt->title[dvd_title].title_set_nr ); |
231 ifoClose( vts_file ); | |
232 ifoClose( vmg_file ); | |
233 DVDClose( dvd ); | |
234 return NULL; | |
235 } | |
236 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
237 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDopenOk); |
1596 | 238 // store data |
239 d=malloc(sizeof(dvd_priv_t)); memset(d,0,sizeof(dvd_priv_t)); | |
240 d->dvd=dvd; | |
241 d->title=title; | |
242 d->vmg_file=vmg_file; | |
243 d->tt_srpt=tt_srpt; | |
244 d->vts_file=vts_file; | |
245 | |
246 /** | |
2935 | 247 * Check number of audio channels and types |
248 */ | |
249 { | |
250 int ac3aid = 128; | |
251 int mpegaid = 0; | |
252 int pcmaid = 160; | |
253 | |
254 d->nr_of_channels=0; | |
255 | |
256 if ( vts_file->vts_pgcit ) | |
257 { | |
258 int i; | |
259 for ( i=0;i<8;i++ ) | |
260 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->audio_control[i] & 0x8000 ) | |
261 { | |
262 audio_attr_t * audio = &vts_file->vtsi_mat->vts_audio_attr[i]; | |
263 int language = 0; | |
264 char tmp[] = "unknown"; | |
265 | |
266 if ( audio->lang_type == 1 ) | |
267 { | |
268 language=audio->lang_code; | |
269 tmp[0]=language>>8; | |
270 tmp[1]=language&0xff; | |
271 tmp[2]=0; | |
272 } | |
273 | |
274 d->audio_streams[d->nr_of_channels].language=language; | |
275 d->audio_streams[d->nr_of_channels].id=0; | |
276 switch ( audio->audio_format ) | |
277 { | |
278 case 0: // ac3 | |
279 case 6: // dts | |
280 d->audio_streams[d->nr_of_channels].id=ac3aid; | |
281 ac3aid++; | |
282 break; | |
283 case 2: // mpeg layer 1/2/3 | |
284 case 3: // mpeg2 ext | |
285 d->audio_streams[d->nr_of_channels].id=mpegaid; | |
286 mpegaid++; | |
287 break; | |
288 case 4: // lpcm | |
289 d->audio_streams[d->nr_of_channels].id=pcmaid; | |
290 pcmaid++; | |
291 break; | |
292 } | |
293 | |
294 mp_msg(MSGT_OPEN,MSGL_V,"[open] audio stream: %d audio format: %s language: %s aid: %d\n", | |
295 d->nr_of_channels, | |
296 dvd_audio_stream_types[ audio->audio_format ], | |
297 tmp, | |
298 d->audio_streams[d->nr_of_channels].id | |
299 ); | |
3753 | 300 |
2935 | 301 d->nr_of_channels++; |
302 } | |
303 } | |
3048 | 304 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of audio channels on disk: %d.\n",d->nr_of_channels ); |
305 } | |
306 | |
307 /** | |
308 * Check number of subtitles and language | |
309 */ | |
310 { | |
311 int i; | |
312 | |
313 d->nr_of_subtitles=0; | |
314 for ( i=0;i<32;i++ ) | |
315 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->subp_control[i] & 0x80000000 ) | |
316 { | |
317 subp_attr_t * subtitle = &vts_file->vtsi_mat->vts_subp_attr[i]; | |
318 int language = 0; | |
319 char tmp[] = "unknown"; | |
320 | |
321 if ( subtitle->type == 1 ) | |
322 { | |
323 language=subtitle->lang_code; | |
324 tmp[0]=language>>8; | |
325 tmp[1]=language&0xff; | |
326 tmp[2]=0; | |
327 } | |
328 | |
329 d->subtitles[ d->nr_of_subtitles ].language=language; | |
330 d->subtitles[ d->nr_of_subtitles ].id=d->nr_of_subtitles; | |
331 | |
332 mp_msg(MSGT_OPEN,MSGL_V,"[open] subtitle ( sid ): %d language: %s\n", | |
333 d->nr_of_subtitles, | |
334 tmp | |
335 ); | |
336 d->nr_of_subtitles++; | |
337 } | |
338 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of subtitles on disk: %d\n",d->nr_of_subtitles ); | |
2935 | 339 } |
340 | |
341 /** | |
1596 | 342 * Determine which program chain we want to watch. This is based on the |
343 * chapter number. | |
344 */ | |
345 ttn = tt_srpt->title[ dvd_title ].vts_ttn; // local | |
346 pgc_id = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgcn; // local | |
347 pgn = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgn; // local | |
348 d->cur_pgc = vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
349 d->cur_cell = d->cur_pgc->program_map[pgn-1] - 1; // start playback here | |
350 d->packs_left=-1; // for Navi stuff | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
351 d->angle_seek=0; |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
352 /* XXX dvd_last_chapter is in the range 1..nr_of_ptts */ |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
353 if ( dvd_last_chapter > 0 && dvd_last_chapter < tt_srpt->title[ttn-1].nr_of_ptts ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
354 pgn=vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_last_chapter].pgn; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
355 d->last_cell=d->cur_pgc->program_map[pgn-1] - 1; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
356 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
357 else |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
358 d->last_cell=d->cur_pgc->nr_of_cells; |
1596 | 359 |
360 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
361 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
362 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
363 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
364 mp_msg(MSGT_DVD,MSGL_V, "DVD start cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); | |
365 | |
366 // ... (unimplemented) | |
367 // return NULL; | |
368 stream=new_stream(-1,STREAMTYPE_DVD); | |
369 stream->start_pos=(off_t)d->cur_pack*2048; | |
4390 | 370 stream->end_pos=(off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; |
5932
1ebeebca86f3
printf to mp_msg + warning msg from MSGL_INFO to MSGT_WARN
albeu
parents:
5819
diff
changeset
|
371 mp_msg(MSGT_DVD,MSGL_V,"DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector); |
1596 | 372 stream->priv=(void*)d; |
373 return stream; | |
374 } | |
375 #endif | |
376 | |
2790 | 377 #ifdef USE_TV |
378 //============ Check for TV-input ==== | |
2931 | 379 if (tv_param_on == 1) |
2790 | 380 { |
2931 | 381 /* create stream */ |
382 stream = new_stream(-1, STREAMTYPE_TV); | |
383 if (!stream) | |
384 return(NULL); | |
385 | |
386 /* create tvi handler */ | |
2790 | 387 tv_handler = tv_begin(); |
388 if (!tv_handler) | |
389 return(NULL); | |
2931 | 390 |
391 /* preinit */ | |
392 if (!tv_init(tv_handler)) | |
393 goto tv_err; | |
394 | |
395 if (!stream_open_tv(stream, tv_handler)) | |
396 goto tv_err; | |
397 | |
398 return(stream); | |
399 | |
400 /* something went wrong - uninit */ | |
401 tv_err: | |
2837 | 402 tv_uninit(tv_handler); |
2802 | 403 return(NULL); |
2790 | 404 } |
405 #endif | |
406 | |
4551 | 407 //============ Check for multi file-input ==== |
408 if (mf_support == 1) | |
409 { | |
410 /* create stream */ | |
411 stream = new_stream(-1, STREAMTYPE_MF); | |
412 if (!stream) | |
413 return(NULL); | |
414 | |
415 if (!stream_open_mf(filename, stream)) | |
416 return(NULL); | |
417 | |
418 return(stream); | |
419 } | |
1467 | 420 |
421 #ifdef STREAMING | |
422 url = url_new(filename); | |
423 if(url) { | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
424 stream=new_stream(f,STREAMTYPE_STREAM); |
4729
f51bd827ed1c
fixed MP3 ICY detection, return detected file format for open_stream
alex
parents:
4551
diff
changeset
|
425 if( streaming_start( stream, file_format, url )<0){ |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
426 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, filename); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
427 url_free(url); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
428 return NULL; |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
3753
diff
changeset
|
429 } |
1584 | 430 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ConnToServer, url->hostname ); |
3045
6c14fd789ba5
Changed the order of processing the network opening.
bertrand
parents:
2935
diff
changeset
|
431 url_free(url); |
2315 | 432 return stream; |
1467 | 433 } |
434 #endif | |
435 | |
6320
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
436 //============ Open STDIN or plain FILE ============ |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
437 if(!strcmp(filename,"-")){ |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
438 // read from stdin |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
439 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN); |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
440 f=0; // 0=stdin |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
441 } else { |
1467 | 442 f=open(filename,O_RDONLY); |
1584 | 443 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; } |
6320
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
444 } |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
445 |
1467 | 446 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); |
447 if (len == -1) | |
6320
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
448 return new_stream(f,STREAMTYPE_STREAM); // open as stream |
12136df07dbd
common code to handle file/stdin/fifo opening, allows using named pipes and
arpi
parents:
5932
diff
changeset
|
449 |
1467 | 450 #ifdef _LARGEFILE_SOURCE |
1567 | 451 mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len); |
1467 | 452 #else |
1567 | 453 mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len); |
1467 | 454 #endif |
455 stream=new_stream(f,STREAMTYPE_FILE); | |
456 stream->end_pos=len; | |
457 return stream; | |
458 } | |
1596 | 459 |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
460 int dvd_parse_chapter_range(struct config *conf, const char *range){ |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
461 char *s, *t; |
4344 | 462 conf; /* prevent warning from GCC */ |
463 s = range; | |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
464 dvd_chapter = 1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
465 dvd_last_chapter = 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
466 if (*range && isdigit(*range)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
467 dvd_chapter = strtol(range, &s, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
468 if (range == s) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
469 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
470 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
471 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
472 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
473 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
474 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
475 else if (*s != '-') { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
476 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
477 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
478 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
479 ++s; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
480 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
481 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
482 if (! isdigit(*s)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
483 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
484 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
485 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
486 dvd_last_chapter = strtol(s, &t, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
487 if (s == t || *t) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
488 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
489 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
490 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
491 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
492 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
493 |
3753 | 494 #ifdef USE_DVDREAD |
1596 | 495 |
3753 | 496 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang){ |
497 dvd_priv_t *d=stream->priv; | |
498 int code,i; | |
499 while(lang && strlen(lang)>=2){ | |
500 code=lang[1]|(lang[0]<<8); | |
501 for(i=0;i<d->nr_of_channels;i++){ | |
502 if(d->audio_streams[i].language==code){ | |
503 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD audio channel: %d language: %c%c\n", | |
504 d->audio_streams[i].id, lang[0],lang[1]); | |
505 return d->audio_streams[i].id; | |
506 } | |
507 // printf("%X != %X (%c%c)\n",code,d->audio_streams[i].language,lang[0],lang[1]); | |
508 } | |
509 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
510 } | |
5932
1ebeebca86f3
printf to mp_msg + warning msg from MSGL_INFO to MSGT_WARN
albeu
parents:
5819
diff
changeset
|
511 mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD audio language found!\n"); |
3753 | 512 return -1; |
513 } | |
514 | |
515 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){ | |
516 dvd_priv_t *d=stream->priv; | |
517 int code,i; | |
518 while(lang && strlen(lang)>=2){ | |
519 code=lang[1]|(lang[0]<<8); | |
520 for(i=0;i<d->nr_of_subtitles;i++){ | |
521 if(d->subtitles[i].language==code){ | |
522 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", | |
523 d->subtitles[i].id, lang[0],lang[1]); | |
524 return d->subtitles[i].id; | |
525 } | |
526 } | |
527 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
528 } | |
5932
1ebeebca86f3
printf to mp_msg + warning msg from MSGL_INFO to MSGT_WARN
albeu
parents:
5819
diff
changeset
|
529 mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD subtitle language found!\n"); |
3753 | 530 return -1; |
531 } | |
1596 | 532 |
533 static int dvd_next_cell(dvd_priv_t *d){ | |
534 int next_cell=d->cur_cell; | |
1616 | 535 |
536 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next1=0x%X \n",next_cell); | |
1596 | 537 |
538 if( d->cur_pgc->cell_playback[ next_cell ].block_type | |
539 == BLOCK_TYPE_ANGLE_BLOCK ) { | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
540 while(next_cell<d->last_cell){ |
1596 | 541 if( d->cur_pgc->cell_playback[next_cell].block_mode |
542 == BLOCK_MODE_LAST_CELL ) break; | |
543 ++next_cell; | |
544 } | |
545 } | |
1616 | 546 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next2=0x%X \n",next_cell); |
1596 | 547 |
548 ++next_cell; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
549 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 550 if( d->cur_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ){ |
551 next_cell+=dvd_angle; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
552 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 553 } |
1616 | 554 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next3=0x%X \n",next_cell); |
1596 | 555 return next_cell; |
556 } | |
557 | |
558 int dvd_read_sector(dvd_priv_t *d,unsigned char* data){ | |
559 int len; | |
560 | |
561 if(d->packs_left==0){ | |
562 /** | |
563 * If we're not at the end of this cell, we can determine the next | |
564 * VOBU to display using the VOBU_SRI information section of the | |
565 * DSI. Using this value correctly follows the current angle, | |
566 * avoiding the doubled scenes in The Matrix, and makes our life | |
567 * really happy. | |
568 * | |
569 * Otherwise, we set our next address past the end of this cell to | |
570 * force the code above to go to the next cell in the program. | |
571 */ | |
572 if( d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { | |
573 d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + | |
574 ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); | |
575 mp_msg(MSGT_DVD,MSGL_DBG2, "Navi new pos=0x%X \n",d->cur_pack); | |
576 } else { | |
577 // end of cell! find next cell! | |
578 mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n"); | |
579 d->cur_pack=d->cell_last_pack+1; | |
580 } | |
581 } | |
582 | |
583 read_next: | |
584 | |
585 if(d->cur_pack>d->cell_last_pack){ | |
586 // end of cell! | |
587 int next=dvd_next_cell(d); | |
588 if(next>=0){ | |
589 d->cur_cell=next; | |
590 | |
1615 | 591 // if( d->cur_pgc->cell_playback[d->cur_cell].block_type |
592 // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
1596 | 593 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; |
594 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
595 mp_msg(MSGT_DVD,MSGL_V, "DVD next cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); | |
596 | |
597 } else return -1; // EOF | |
598 } | |
599 | |
600 len = DVDReadBlocks( d->title, d->cur_pack, 1, data ); | |
601 if(!len) return -1; //error | |
602 | |
603 if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF && | |
604 data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF){ | |
605 // found a Navi packet!!! | |
1875 | 606 #if LIBDVDREAD_VERSION >= DVDREAD_VERSION(0,9,0) |
607 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]) ); | |
608 #else | |
1596 | 609 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t) ); |
1875 | 610 #endif |
1596 | 611 if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ){ |
612 mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X navi=0x%X \n", | |
613 d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn); | |
614 } else { | |
615 // process! | |
616 d->packs_left = d->dsi_pack.dsi_gi.vobu_ea; | |
617 mp_msg(MSGT_DVD,MSGL_DBG2, "Found NAVI packet! lba=0x%X len=%d \n",d->cur_pack,d->packs_left); | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
618 if(d->angle_seek){ |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
619 int skip=d->dsi_pack.sml_agli.data[dvd_angle].address; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
620 if(skip) d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+skip; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
621 d->angle_seek=0; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
622 mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced! skip=%d new_lba=0x%X \n",skip,d->cur_pack); |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
623 } |
1596 | 624 } |
625 ++d->cur_pack; | |
626 goto read_next; | |
627 } | |
628 | |
629 ++d->cur_pack; | |
630 if(d->packs_left>=0) --d->packs_left; | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
631 |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
632 if(d->angle_seek) goto read_next; // searching for Navi packet |
1596 | 633 |
634 return d->cur_pack-1; | |
635 } | |
636 | |
637 void dvd_seek(dvd_priv_t *d,int pos){ | |
638 d->packs_left=-1; | |
639 d->cur_pack=pos; | |
640 | |
641 // check if we stay in current cell (speedup things, and avoid angle skip) | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
642 if(d->cur_pack>d->cell_last_pack || |
1596 | 643 d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ |
644 | |
645 // ok, cell change, find the right cell! | |
646 d->cur_cell=0; | |
647 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
648 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
649 | |
650 while(1){ | |
651 int next; | |
652 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
653 if(d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ | |
654 d->cur_pack=d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
655 break; | |
656 } | |
657 if(d->cur_pack<=d->cell_last_pack) break; // ok, we find it! :) | |
658 next=dvd_next_cell(d); | |
659 if(next<0){ | |
660 // d->cur_pack=d->cell_last_pack+1; | |
661 break; // we're after the last cell | |
662 } | |
663 d->cur_cell=next; | |
664 } | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
665 |
1596 | 666 } |
667 | |
668 mp_msg(MSGT_DVD,MSGL_V, "DVD Seek! lba=0x%X cell=%d packs: 0x%X-0x%X \n", | |
669 d->cur_pack,d->cur_cell,d->cur_pgc->cell_playback[ d->cur_cell ].first_sector,d->cell_last_pack); | |
670 | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
671 // if we're in interleaved multi-angle cell, find the right angle chain! |
1596 | 672 // (read Navi block, and use the seamless angle jump table) |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
673 d->angle_seek=1; |
1596 | 674 |
675 } | |
676 | |
677 #endif |