Mercurial > mplayer.hg
annotate libmpdemux/open.c @ 4918:8e6ccd3e5325
-master is obsoleted
author | gabucino |
---|---|
date | Sun, 03 Mar 2002 09:01:47 +0000 |
parents | f51bd827ed1c |
children | 8a01cde9cf39 |
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; |
1596 | 34 |
35 #ifdef USE_DVDREAD | |
36 | |
37 #include <dvdread/dvd_reader.h> | |
38 #include <dvdread/ifo_types.h> | |
39 #include <dvdread/ifo_read.h> | |
40 #include <dvdread/nav_read.h> | |
1875 | 41 |
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 ============== |
113 #ifdef USE_DVDREAD | |
114 if(dvd_title){ | |
2050 | 115 // int ret,ret2; |
1596 | 116 dvd_priv_t *d; |
117 int ttn,pgc_id,pgn; | |
118 dvd_reader_t *dvd; | |
119 dvd_file_t *title; | |
120 ifo_handle_t *vmg_file; | |
121 tt_srpt_t *tt_srpt; | |
122 ifo_handle_t *vts_file; | |
123 /** | |
124 * Open the disc. | |
125 */ | |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
126 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
|
127 dvd = DVDOpen(dvd_device); |
1596 | 128 if( !dvd ) { |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
129 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device); |
1596 | 130 return NULL; |
131 } | |
132 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
133 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDwait); |
1596 | 134 |
135 /** | |
136 * Load the video manager to find out the information about the titles on | |
137 * this disc. | |
138 */ | |
139 vmg_file = ifoOpen( dvd, 0 ); | |
140 if( !vmg_file ) { | |
141 mp_msg(MSGT_OPEN,MSGL_ERR, "Can't open VMG info!\n"); | |
142 DVDClose( dvd ); | |
143 return NULL; | |
144 } | |
145 tt_srpt = vmg_file->tt_srpt; | |
146 /** | |
147 * Make sure our title number is valid. | |
148 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
149 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumTitles, |
1596 | 150 tt_srpt->nr_of_srpts ); |
151 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
|
152 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidTitle, dvd_title); |
1596 | 153 ifoClose( vmg_file ); |
154 DVDClose( dvd ); | |
155 return NULL; | |
156 } | |
157 --dvd_title; // remap 1.. -> 0.. | |
158 /** | |
159 * Make sure the chapter number is valid for this title. | |
160 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
161 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumChapters, |
1596 | 162 tt_srpt->title[dvd_title].nr_of_ptts ); |
163 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
|
164 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidChapter, dvd_chapter); |
1596 | 165 ifoClose( vmg_file ); |
166 DVDClose( dvd ); | |
167 return NULL; | |
168 } | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
169 if( dvd_last_chapter>0 ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
170 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
|
171 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
|
172 ifoClose( vmg_file ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
173 DVDClose( dvd ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
174 return NULL; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
175 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
176 } |
1596 | 177 --dvd_chapter; // remap 1.. -> 0.. |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
178 /* XXX No need to remap dvd_last_chapter */ |
1596 | 179 /** |
180 * Make sure the angle 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_DVDnumAngles, |
1596 | 183 tt_srpt->title[dvd_title].nr_of_angles ); |
184 if( dvd_angle<1 || dvd_angle>tt_srpt->title[dvd_title].nr_of_angles ) { | |
1977 | 185 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidAngle, dvd_angle); |
1596 | 186 ifoClose( vmg_file ); |
187 DVDClose( dvd ); | |
188 return NULL; | |
189 } | |
1617 | 190 --dvd_angle; // remap 1.. -> 0.. |
1596 | 191 /** |
192 * Load the VTS information for the title set our title is in. | |
193 */ | |
194 vts_file = ifoOpen( dvd, tt_srpt->title[dvd_title].title_set_nr ); | |
195 if( !vts_file ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
196 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoIFO, |
1596 | 197 tt_srpt->title[dvd_title].title_set_nr ); |
198 ifoClose( vmg_file ); | |
199 DVDClose( dvd ); | |
200 return NULL; | |
201 } | |
202 /** | |
203 * We've got enough info, time to open the title set data. | |
204 */ | |
205 title = DVDOpenFile( dvd, tt_srpt->title[dvd_title].title_set_nr, | |
206 DVD_READ_TITLE_VOBS ); | |
207 if( !title ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
208 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoVOBs, |
1596 | 209 tt_srpt->title[dvd_title].title_set_nr ); |
210 ifoClose( vts_file ); | |
211 ifoClose( vmg_file ); | |
212 DVDClose( dvd ); | |
213 return NULL; | |
214 } | |
215 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
216 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDopenOk); |
1596 | 217 // store data |
218 d=malloc(sizeof(dvd_priv_t)); memset(d,0,sizeof(dvd_priv_t)); | |
219 d->dvd=dvd; | |
220 d->title=title; | |
221 d->vmg_file=vmg_file; | |
222 d->tt_srpt=tt_srpt; | |
223 d->vts_file=vts_file; | |
224 | |
225 /** | |
2935 | 226 * Check number of audio channels and types |
227 */ | |
228 { | |
229 int ac3aid = 128; | |
230 int mpegaid = 0; | |
231 int pcmaid = 160; | |
232 | |
233 d->nr_of_channels=0; | |
234 | |
235 if ( vts_file->vts_pgcit ) | |
236 { | |
237 int i; | |
238 for ( i=0;i<8;i++ ) | |
239 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->audio_control[i] & 0x8000 ) | |
240 { | |
241 audio_attr_t * audio = &vts_file->vtsi_mat->vts_audio_attr[i]; | |
242 int language = 0; | |
243 char tmp[] = "unknown"; | |
244 | |
245 if ( audio->lang_type == 1 ) | |
246 { | |
247 language=audio->lang_code; | |
248 tmp[0]=language>>8; | |
249 tmp[1]=language&0xff; | |
250 tmp[2]=0; | |
251 } | |
252 | |
253 d->audio_streams[d->nr_of_channels].language=language; | |
254 d->audio_streams[d->nr_of_channels].id=0; | |
255 switch ( audio->audio_format ) | |
256 { | |
257 case 0: // ac3 | |
258 case 6: // dts | |
259 d->audio_streams[d->nr_of_channels].id=ac3aid; | |
260 ac3aid++; | |
261 break; | |
262 case 2: // mpeg layer 1/2/3 | |
263 case 3: // mpeg2 ext | |
264 d->audio_streams[d->nr_of_channels].id=mpegaid; | |
265 mpegaid++; | |
266 break; | |
267 case 4: // lpcm | |
268 d->audio_streams[d->nr_of_channels].id=pcmaid; | |
269 pcmaid++; | |
270 break; | |
271 } | |
272 | |
273 mp_msg(MSGT_OPEN,MSGL_V,"[open] audio stream: %d audio format: %s language: %s aid: %d\n", | |
274 d->nr_of_channels, | |
275 dvd_audio_stream_types[ audio->audio_format ], | |
276 tmp, | |
277 d->audio_streams[d->nr_of_channels].id | |
278 ); | |
3753 | 279 |
2935 | 280 d->nr_of_channels++; |
281 } | |
282 } | |
3048 | 283 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of audio channels on disk: %d.\n",d->nr_of_channels ); |
284 } | |
285 | |
286 /** | |
287 * Check number of subtitles and language | |
288 */ | |
289 { | |
290 int i; | |
291 | |
292 d->nr_of_subtitles=0; | |
293 for ( i=0;i<32;i++ ) | |
294 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->subp_control[i] & 0x80000000 ) | |
295 { | |
296 subp_attr_t * subtitle = &vts_file->vtsi_mat->vts_subp_attr[i]; | |
297 int language = 0; | |
298 char tmp[] = "unknown"; | |
299 | |
300 if ( subtitle->type == 1 ) | |
301 { | |
302 language=subtitle->lang_code; | |
303 tmp[0]=language>>8; | |
304 tmp[1]=language&0xff; | |
305 tmp[2]=0; | |
306 } | |
307 | |
308 d->subtitles[ d->nr_of_subtitles ].language=language; | |
309 d->subtitles[ d->nr_of_subtitles ].id=d->nr_of_subtitles; | |
310 | |
311 mp_msg(MSGT_OPEN,MSGL_V,"[open] subtitle ( sid ): %d language: %s\n", | |
312 d->nr_of_subtitles, | |
313 tmp | |
314 ); | |
315 d->nr_of_subtitles++; | |
316 } | |
317 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of subtitles on disk: %d\n",d->nr_of_subtitles ); | |
2935 | 318 } |
319 | |
320 /** | |
1596 | 321 * Determine which program chain we want to watch. This is based on the |
322 * chapter number. | |
323 */ | |
324 ttn = tt_srpt->title[ dvd_title ].vts_ttn; // local | |
325 pgc_id = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgcn; // local | |
326 pgn = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgn; // local | |
327 d->cur_pgc = vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
328 d->cur_cell = d->cur_pgc->program_map[pgn-1] - 1; // start playback here | |
329 d->packs_left=-1; // for Navi stuff | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
330 d->angle_seek=0; |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
331 /* 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
|
332 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
|
333 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
|
334 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
|
335 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
336 else |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
337 d->last_cell=d->cur_pgc->nr_of_cells; |
1596 | 338 |
339 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
340 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
341 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
342 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
343 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); | |
344 | |
345 // ... (unimplemented) | |
346 // return NULL; | |
347 stream=new_stream(-1,STREAMTYPE_DVD); | |
348 stream->start_pos=(off_t)d->cur_pack*2048; | |
4390 | 349 stream->end_pos=(off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; |
350 printf("DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector); | |
1596 | 351 stream->priv=(void*)d; |
352 return stream; | |
353 } | |
354 #endif | |
355 | |
2790 | 356 #ifdef USE_TV |
357 //============ Check for TV-input ==== | |
2931 | 358 if (tv_param_on == 1) |
2790 | 359 { |
2931 | 360 /* create stream */ |
361 stream = new_stream(-1, STREAMTYPE_TV); | |
362 if (!stream) | |
363 return(NULL); | |
364 | |
365 /* create tvi handler */ | |
2790 | 366 tv_handler = tv_begin(); |
367 if (!tv_handler) | |
368 return(NULL); | |
2931 | 369 |
370 /* preinit */ | |
371 if (!tv_init(tv_handler)) | |
372 goto tv_err; | |
373 | |
374 if (!stream_open_tv(stream, tv_handler)) | |
375 goto tv_err; | |
376 | |
377 return(stream); | |
378 | |
379 /* something went wrong - uninit */ | |
380 tv_err: | |
2837 | 381 tv_uninit(tv_handler); |
2802 | 382 return(NULL); |
2790 | 383 } |
384 #endif | |
385 | |
4551 | 386 //============ Check for multi file-input ==== |
387 if (mf_support == 1) | |
388 { | |
389 /* create stream */ | |
390 stream = new_stream(-1, STREAMTYPE_MF); | |
391 if (!stream) | |
392 return(NULL); | |
393 | |
394 if (!stream_open_mf(filename, stream)) | |
395 return(NULL); | |
396 | |
397 return(stream); | |
398 } | |
399 | |
1467 | 400 //============ Open STDIN ============ |
401 if(!strcmp(filename,"-")){ | |
402 // read from stdin | |
1584 | 403 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN); |
1467 | 404 f=0; // 0=stdin |
405 stream=new_stream(f,STREAMTYPE_STREAM); | |
406 return stream; | |
407 } | |
408 | |
409 #ifdef STREAMING | |
410 url = url_new(filename); | |
411 if(url) { | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
412 stream=new_stream(f,STREAMTYPE_STREAM); |
4729
f51bd827ed1c
fixed MP3 ICY detection, return detected file format for open_stream
alex
parents:
4551
diff
changeset
|
413 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
|
414 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
|
415 url_free(url); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
416 return NULL; |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
3753
diff
changeset
|
417 } |
1584 | 418 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
|
419 url_free(url); |
2315 | 420 return stream; |
1467 | 421 } |
422 #endif | |
423 | |
424 //============ Open plain FILE ============ | |
425 f=open(filename,O_RDONLY); | |
1584 | 426 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; } |
1467 | 427 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); |
428 if (len == -1) | |
429 perror("Error: lseek failed to obtain video file size"); | |
430 else | |
431 #ifdef _LARGEFILE_SOURCE | |
1567 | 432 mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len); |
1467 | 433 #else |
1567 | 434 mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len); |
1467 | 435 #endif |
436 stream=new_stream(f,STREAMTYPE_FILE); | |
437 stream->end_pos=len; | |
438 return stream; | |
439 | |
440 } | |
1596 | 441 |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
442 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
|
443 char *s, *t; |
4344 | 444 conf; /* prevent warning from GCC */ |
445 s = range; | |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
446 dvd_chapter = 1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
447 dvd_last_chapter = 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
448 if (*range && isdigit(*range)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
449 dvd_chapter = strtol(range, &s, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
450 if (range == s) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
451 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
|
452 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
453 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
454 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
455 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
456 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
457 else if (*s != '-') { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
458 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
|
459 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
460 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
461 ++s; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
462 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
463 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
464 if (! isdigit(*s)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
465 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
|
466 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
467 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
468 dvd_last_chapter = strtol(s, &t, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
469 if (s == t || *t) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
470 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
|
471 return -1; |
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 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
474 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
475 |
3753 | 476 #ifdef USE_DVDREAD |
1596 | 477 |
3753 | 478 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang){ |
479 dvd_priv_t *d=stream->priv; | |
480 int code,i; | |
481 while(lang && strlen(lang)>=2){ | |
482 code=lang[1]|(lang[0]<<8); | |
483 for(i=0;i<d->nr_of_channels;i++){ | |
484 if(d->audio_streams[i].language==code){ | |
485 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD audio channel: %d language: %c%c\n", | |
486 d->audio_streams[i].id, lang[0],lang[1]); | |
487 return d->audio_streams[i].id; | |
488 } | |
489 // printf("%X != %X (%c%c)\n",code,d->audio_streams[i].language,lang[0],lang[1]); | |
490 } | |
491 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
492 } | |
493 mp_msg(MSGT_OPEN,MSGL_INFO,"No matching DVD audio language found!\n"); | |
494 return -1; | |
495 } | |
496 | |
497 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){ | |
498 dvd_priv_t *d=stream->priv; | |
499 int code,i; | |
500 while(lang && strlen(lang)>=2){ | |
501 code=lang[1]|(lang[0]<<8); | |
502 for(i=0;i<d->nr_of_subtitles;i++){ | |
503 if(d->subtitles[i].language==code){ | |
504 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", | |
505 d->subtitles[i].id, lang[0],lang[1]); | |
506 return d->subtitles[i].id; | |
507 } | |
508 } | |
509 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
510 } | |
511 mp_msg(MSGT_OPEN,MSGL_INFO,"No matching DVD subtitle language found!\n"); | |
512 return -1; | |
513 } | |
1596 | 514 |
515 static int dvd_next_cell(dvd_priv_t *d){ | |
516 int next_cell=d->cur_cell; | |
1616 | 517 |
518 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next1=0x%X \n",next_cell); | |
1596 | 519 |
520 if( d->cur_pgc->cell_playback[ next_cell ].block_type | |
521 == BLOCK_TYPE_ANGLE_BLOCK ) { | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
522 while(next_cell<d->last_cell){ |
1596 | 523 if( d->cur_pgc->cell_playback[next_cell].block_mode |
524 == BLOCK_MODE_LAST_CELL ) break; | |
525 ++next_cell; | |
526 } | |
527 } | |
1616 | 528 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next2=0x%X \n",next_cell); |
1596 | 529 |
530 ++next_cell; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
531 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 532 if( d->cur_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ){ |
533 next_cell+=dvd_angle; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
534 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 535 } |
1616 | 536 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next3=0x%X \n",next_cell); |
1596 | 537 return next_cell; |
538 } | |
539 | |
540 int dvd_read_sector(dvd_priv_t *d,unsigned char* data){ | |
541 int len; | |
542 | |
543 if(d->packs_left==0){ | |
544 /** | |
545 * If we're not at the end of this cell, we can determine the next | |
546 * VOBU to display using the VOBU_SRI information section of the | |
547 * DSI. Using this value correctly follows the current angle, | |
548 * avoiding the doubled scenes in The Matrix, and makes our life | |
549 * really happy. | |
550 * | |
551 * Otherwise, we set our next address past the end of this cell to | |
552 * force the code above to go to the next cell in the program. | |
553 */ | |
554 if( d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { | |
555 d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + | |
556 ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); | |
557 mp_msg(MSGT_DVD,MSGL_DBG2, "Navi new pos=0x%X \n",d->cur_pack); | |
558 } else { | |
559 // end of cell! find next cell! | |
560 mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n"); | |
561 d->cur_pack=d->cell_last_pack+1; | |
562 } | |
563 } | |
564 | |
565 read_next: | |
566 | |
567 if(d->cur_pack>d->cell_last_pack){ | |
568 // end of cell! | |
569 int next=dvd_next_cell(d); | |
570 if(next>=0){ | |
571 d->cur_cell=next; | |
572 | |
1615 | 573 // if( d->cur_pgc->cell_playback[d->cur_cell].block_type |
574 // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
1596 | 575 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; |
576 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
577 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); | |
578 | |
579 } else return -1; // EOF | |
580 } | |
581 | |
582 len = DVDReadBlocks( d->title, d->cur_pack, 1, data ); | |
583 if(!len) return -1; //error | |
584 | |
585 if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF && | |
586 data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF){ | |
587 // found a Navi packet!!! | |
1875 | 588 #if LIBDVDREAD_VERSION >= DVDREAD_VERSION(0,9,0) |
589 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]) ); | |
590 #else | |
1596 | 591 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t) ); |
1875 | 592 #endif |
1596 | 593 if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ){ |
594 mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X navi=0x%X \n", | |
595 d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn); | |
596 } else { | |
597 // process! | |
598 d->packs_left = d->dsi_pack.dsi_gi.vobu_ea; | |
599 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
|
600 if(d->angle_seek){ |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
601 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
|
602 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
|
603 d->angle_seek=0; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
604 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
|
605 } |
1596 | 606 } |
607 ++d->cur_pack; | |
608 goto read_next; | |
609 } | |
610 | |
611 ++d->cur_pack; | |
612 if(d->packs_left>=0) --d->packs_left; | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
613 |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
614 if(d->angle_seek) goto read_next; // searching for Navi packet |
1596 | 615 |
616 return d->cur_pack-1; | |
617 } | |
618 | |
619 void dvd_seek(dvd_priv_t *d,int pos){ | |
620 d->packs_left=-1; | |
621 d->cur_pack=pos; | |
622 | |
623 // 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
|
624 if(d->cur_pack>d->cell_last_pack || |
1596 | 625 d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ |
626 | |
627 // ok, cell change, find the right cell! | |
628 d->cur_cell=0; | |
629 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
630 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
631 | |
632 while(1){ | |
633 int next; | |
634 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
635 if(d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ | |
636 d->cur_pack=d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
637 break; | |
638 } | |
639 if(d->cur_pack<=d->cell_last_pack) break; // ok, we find it! :) | |
640 next=dvd_next_cell(d); | |
641 if(next<0){ | |
642 // d->cur_pack=d->cell_last_pack+1; | |
643 break; // we're after the last cell | |
644 } | |
645 d->cur_cell=next; | |
646 } | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
647 |
1596 | 648 } |
649 | |
650 mp_msg(MSGT_DVD,MSGL_V, "DVD Seek! lba=0x%X cell=%d packs: 0x%X-0x%X \n", | |
651 d->cur_pack,d->cur_cell,d->cur_pgc->cell_playback[ d->cur_cell ].first_sector,d->cell_last_pack); | |
652 | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
653 // if we're in interleaved multi-angle cell, find the right angle chain! |
1596 | 654 // (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
|
655 d->angle_seek=1; |
1596 | 656 |
657 } | |
658 | |
659 #endif |