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