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