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