Mercurial > mplayer.hg
annotate libmpdemux/stream_dvd.c @ 15689:80494fefb7ea
mingw gcc 4.1 support patch by Gianluigi Tiesi <mplayer at netfarm.it>
author | faust3 |
---|---|
date | Tue, 07 Jun 2005 13:36:21 +0000 |
parents | f62be65f7df3 |
children | a10adcba312f |
rev | line source |
---|---|
15518 | 1 |
2 | |
3 #include <ctype.h> | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 #include <unistd.h> | |
8 #include <fcntl.h> | |
9 #include <string.h> | |
10 | |
11 #include "config.h" | |
12 #include "mp_msg.h" | |
13 #include "help_mp.h" | |
14 | |
15 #ifdef __FreeBSD__ | |
16 #include <sys/cdrio.h> | |
17 #endif | |
18 | |
19 #include "stream.h" | |
20 #include "../m_option.h" | |
21 #include "../m_struct.h" | |
22 | |
23 /// We keep these 2 for the gui atm, but they will be removed. | |
24 int dvd_title=0; | |
25 int dvd_chapter=1; | |
26 int dvd_last_chapter=0; | |
27 int dvd_angle=1; | |
28 char* dvd_device=NULL; | |
29 | |
30 #ifdef USE_DVDREAD | |
31 #define DVDREAD_VERSION(maj,min,micro) ((maj)*10000 + (min)*100 + (micro)) | |
32 /* | |
33 * Try to autodetect the libdvd-0.9.0 library | |
34 * (0.9.0 removed the <dvdread/dvd_udf.h> header, and moved the two defines | |
35 * DVD_VIDEO_LB_LEN and MAX_UDF_FILE_NAME_LEN from it to | |
36 * <dvdread/dvd_reader.h>) | |
37 */ | |
38 #if defined(DVD_VIDEO_LB_LEN) && defined(MAX_UDF_FILE_NAME_LEN) | |
39 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,9,0) | |
40 #else | |
41 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,8,0) | |
42 #endif | |
43 | |
44 char * dvd_audio_stream_types[8] = { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" }; | |
45 char * dvd_audio_stream_channels[6] = { "mono", "stereo", "unknown", "unknown", "5.1/6.1", "5.1" }; | |
46 #endif | |
47 | |
48 | |
49 static struct stream_priv_s { | |
50 int title; | |
51 } stream_priv_dflts = { | |
52 1 | |
53 }; | |
54 | |
55 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
56 /// URL definition | |
57 static m_option_t stream_opts_fields[] = { | |
58 { "hostname", ST_OFF(title), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
59 { NULL, NULL, 0, 0, 0, 0, NULL } | |
60 }; | |
61 static struct m_struct_st stream_opts = { | |
62 "dvd", | |
63 sizeof(struct stream_priv_s), | |
64 &stream_priv_dflts, | |
65 stream_opts_fields | |
66 }; | |
67 | |
68 int dvd_parse_chapter_range(m_option_t *conf, const char *range) { | |
69 const char *s; | |
70 char *t; | |
71 if (!range) | |
72 return M_OPT_MISSING_PARAM; | |
73 s = range; | |
74 dvd_chapter = 1; | |
75 dvd_last_chapter = 0; | |
76 if(*range && isdigit(*range)) { | |
77 dvd_chapter = strtol(range, &s, 10); | |
78 if(range == s) { | |
79 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); | |
80 return M_OPT_INVALID; | |
81 } | |
82 } | |
83 if(*s == 0) | |
84 return 0; | |
85 else if(*s != '-') { | |
86 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); | |
87 return M_OPT_INVALID; | |
88 } | |
89 ++s; | |
90 if(*s == 0) | |
91 return 0; | |
92 if(! isdigit(*s)) { | |
93 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); | |
94 return M_OPT_INVALID; | |
95 } | |
96 dvd_last_chapter = strtol(s, &t, 10); | |
97 if (s == t || *t) { | |
98 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); | |
99 return M_OPT_INVALID; | |
100 } | |
101 return 0; | |
102 } | |
103 | |
104 #ifdef USE_DVDREAD | |
105 int dvd_chapter_from_cell(dvd_priv_t* dvd,int title,int cell) | |
106 { | |
107 pgc_t * cur_pgc; | |
108 ptt_info_t* ptt; | |
109 int chapter = cell; | |
110 int pgc_id,pgn; | |
111 if(title < 0 || cell < 0){ | |
112 return 0; | |
113 } | |
114 /* for most DVD's chapter == cell */ | |
115 /* but there are more complecated cases... */ | |
116 if(chapter >= dvd->vmg_file->tt_srpt->title[title].nr_of_ptts) { | |
117 chapter = dvd->vmg_file->tt_srpt->title[title].nr_of_ptts-1; | |
118 } | |
119 title = dvd->tt_srpt->title[title].vts_ttn-1; | |
120 ptt = dvd->vts_file->vts_ptt_srpt->title[title].ptt; | |
121 while(chapter >= 0) { | |
122 pgc_id = ptt[chapter].pgcn; | |
123 pgn = ptt[chapter].pgn; | |
124 cur_pgc = dvd->vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
125 if(cell >= cur_pgc->program_map[pgn-1]-1) { | |
126 return chapter; | |
127 } | |
128 --chapter; | |
129 } | |
130 /* didn't find a chapter ??? */ | |
131 return chapter; | |
132 } | |
133 | |
134 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang) { | |
135 dvd_priv_t *d=stream->priv; | |
136 int code,i; | |
137 if(lang) { | |
138 while(strlen(lang)>=2) { | |
139 code=lang[1]|(lang[0]<<8); | |
140 for(i=0;i<d->nr_of_channels;i++) { | |
141 if(d->audio_streams[i].language==code) { | |
142 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD audio channel: %d language: %c%c\n", | |
143 d->audio_streams[i].id, lang[0],lang[1]); | |
144 return d->audio_streams[i].id; | |
145 } | |
146 //printf("%X != %X (%c%c)\n",code,d->audio_streams[i].language,lang[0],lang[1]); | |
147 } | |
148 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
149 } | |
150 mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD audio language found!\n"); | |
151 } | |
152 return -1; | |
153 } | |
154 | |
155 int dvd_number_of_subs(stream_t *stream) { | |
156 dvd_priv_t *d; | |
157 if (!stream) return -1; | |
158 d = stream->priv; | |
159 if (!d) return -1; | |
160 return d->nr_of_subtitles; | |
161 } | |
162 | |
163 int dvd_lang_from_sid(stream_t *stream, int id) { | |
164 dvd_priv_t *d; | |
165 if (!stream) return 0; | |
166 d = stream->priv; | |
167 if (!d) return 0; | |
168 if (id >= d->nr_of_subtitles) return 0; | |
169 return d->subtitles[id].language; | |
170 } | |
171 | |
172 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang) { | |
173 dvd_priv_t *d=stream->priv; | |
174 int code,i; | |
175 while(lang && strlen(lang)>=2) { | |
176 code=lang[1]|(lang[0]<<8); | |
177 for(i=0;i<d->nr_of_subtitles;i++) { | |
178 if(d->subtitles[i].language==code) { | |
179 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", d->subtitles[i].id, lang[0],lang[1]); | |
180 return d->subtitles[i].id; | |
181 } | |
182 } | |
183 lang+=2; | |
184 while (lang[0]==',' || lang[0]==' ') ++lang; | |
185 } | |
186 mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD subtitle language found!\n"); | |
187 return -1; | |
188 } | |
189 | |
190 static int dvd_next_cell(dvd_priv_t *d) { | |
191 int next_cell=d->cur_cell; | |
192 | |
15551
f62be65f7df3
Reduce senseless spamminess of DVD playback in verbose mode.
diego
parents:
15518
diff
changeset
|
193 mp_msg(MSGT_DVD,MSGL_DBG2, "dvd_next_cell: next1=0x%X \n",next_cell); |
15518 | 194 if( d->cur_pgc->cell_playback[ next_cell ].block_type == BLOCK_TYPE_ANGLE_BLOCK ) { |
195 while(next_cell<d->last_cell) { | |
196 if( d->cur_pgc->cell_playback[next_cell].block_mode == BLOCK_MODE_LAST_CELL ) | |
197 break; | |
198 ++next_cell; | |
199 } | |
200 } | |
15551
f62be65f7df3
Reduce senseless spamminess of DVD playback in verbose mode.
diego
parents:
15518
diff
changeset
|
201 mp_msg(MSGT_DVD,MSGL_DBG2, "dvd_next_cell: next2=0x%X \n",next_cell); |
15518 | 202 |
203 ++next_cell; | |
204 if(next_cell>=d->last_cell) | |
205 return -1; // EOF | |
206 if(d->cur_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) { | |
207 next_cell+=dvd_angle; | |
208 if(next_cell>=d->last_cell) | |
209 return -1; // EOF | |
210 } | |
15551
f62be65f7df3
Reduce senseless spamminess of DVD playback in verbose mode.
diego
parents:
15518
diff
changeset
|
211 mp_msg(MSGT_DVD,MSGL_DBG2, "dvd_next_cell: next3=0x%X \n",next_cell); |
15518 | 212 return next_cell; |
213 } | |
214 | |
215 int dvd_read_sector(dvd_priv_t *d,unsigned char* data) { | |
216 int len; | |
217 | |
218 if(d->packs_left==0) { | |
219 /** | |
220 * If we're not at the end of this cell, we can determine the next | |
221 * VOBU to display using the VOBU_SRI information section of the | |
222 * DSI. Using this value correctly follows the current angle, | |
223 * avoiding the doubled scenes in The Matrix, and makes our life | |
224 * really happy. | |
225 * | |
226 * Otherwise, we set our next address past the end of this cell to | |
227 * force the code above to go to the next cell in the program. | |
228 */ | |
229 if(d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) { | |
230 d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); | |
231 mp_msg(MSGT_DVD,MSGL_DBG2, "Navi new pos=0x%X \n",d->cur_pack); | |
232 } else { | |
233 // end of cell! find next cell! | |
234 mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n"); | |
235 d->cur_pack=d->cell_last_pack+1; | |
236 } | |
237 } | |
238 | |
239 read_next: | |
240 if(d->cur_pack>d->cell_last_pack) { | |
241 // end of cell! | |
242 int next=dvd_next_cell(d); | |
243 if(next>=0) { | |
244 d->cur_cell=next; | |
245 // if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
246 // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
247 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
248 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
249 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); | |
250 } else | |
251 return -1; // EOF | |
252 } | |
253 | |
254 len = DVDReadBlocks(d->title, d->cur_pack, 1, data); | |
255 if(!len) return -1; //error | |
256 | |
257 if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF && | |
258 data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF) { | |
259 // found a Navi packet!!! | |
260 #if LIBDVDREAD_VERSION >= DVDREAD_VERSION(0,9,0) | |
261 navRead_DSI(&d->dsi_pack, &(data[ DSI_START_BYTE ])); | |
262 #else | |
263 navRead_DSI(&d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t)); | |
264 #endif | |
265 if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ) { | |
266 mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X navi=0x%X \n", | |
267 d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn); | |
268 } else { | |
269 // process! | |
270 d->packs_left = d->dsi_pack.dsi_gi.vobu_ea; | |
271 mp_msg(MSGT_DVD,MSGL_DBG2, "Found NAVI packet! lba=0x%X len=%d \n",d->cur_pack,d->packs_left); | |
272 //navPrint_DSI(&d->dsi_pack); | |
273 mp_msg(MSGT_DVD,MSGL_DBG3,"\r### CELL %d: Navi: %d/%d IFO: %d/%d \n",d->cur_cell, | |
274 d->dsi_pack.dsi_gi.vobu_c_idn,d->dsi_pack.dsi_gi.vobu_vob_idn, | |
275 d->cur_pgc->cell_position[d->cur_cell].cell_nr, | |
276 d->cur_pgc->cell_position[d->cur_cell].vob_id_nr); | |
277 | |
278 if(d->angle_seek) { | |
279 int i,skip=0; | |
280 #if defined(__GNUC__) && ( defined(__sparc__) || defined(hpux) ) | |
281 // workaround for a bug in the sparc/hpux version of gcc 2.95.X ... 3.2, | |
282 // it generates incorrect code for unaligned access to a packed | |
283 // structure member, resulting in an mplayer crash with a SIGBUS | |
284 // signal. | |
285 // | |
286 // See also gcc problem report PR c/7847: | |
287 // http://gcc.gnu.org/cgi-bin/gnatsweb.pl?database=gcc&cmd=view+audit-trail&pr=7847 | |
288 for(i=0;i<9;i++) { // check if all values zero: | |
289 typeof(d->dsi_pack.sml_agli.data[i].address) tmp_addr; | |
290 memcpy(&tmp_addr,&d->dsi_pack.sml_agli.data[i].address,sizeof(tmp_addr)); | |
291 if((skip=tmp_addr)!=0) break; | |
292 } | |
293 #else | |
294 for(i=0;i<9;i++) // check if all values zero: | |
295 if((skip=d->dsi_pack.sml_agli.data[i].address)!=0) break; | |
296 #endif | |
297 if(skip) { | |
298 // sml_agli table has valid data (at least one non-zero): | |
299 d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+ | |
300 d->dsi_pack.sml_agli.data[dvd_angle].address; | |
301 d->angle_seek=0; | |
302 mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced using sml_agli map! new_lba=0x%X \n",d->cur_pack); | |
303 } else { | |
304 // check if we're in the right cell, jump otherwise: | |
305 if( (d->dsi_pack.dsi_gi.vobu_c_idn==d->cur_pgc->cell_position[d->cur_cell].cell_nr) && | |
306 (d->dsi_pack.dsi_gi.vobu_vob_idn==d->cur_pgc->cell_position[d->cur_cell].vob_id_nr) ){ | |
307 d->angle_seek=0; | |
308 mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced by cell/vob IDN search! \n"); | |
309 } else { | |
310 // wrong angle, skip this vobu: | |
311 d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+ | |
312 d->dsi_pack.dsi_gi.vobu_ea; | |
313 d->angle_seek=2; // DEBUG | |
314 } | |
315 } | |
316 } | |
317 } | |
318 ++d->cur_pack; | |
319 goto read_next; | |
320 } | |
321 | |
322 ++d->cur_pack; | |
323 if(d->packs_left>=0) --d->packs_left; | |
324 | |
325 if(d->angle_seek) { | |
326 if(d->angle_seek==2) mp_msg(MSGT_DVD,MSGL_V, "!!! warning! reading packet while angle_seek !!!\n"); | |
327 goto read_next; // searching for Navi packet | |
328 } | |
329 | |
330 return d->cur_pack-1; | |
331 } | |
332 | |
333 void dvd_seek(dvd_priv_t *d,int pos) { | |
334 d->packs_left=-1; | |
335 d->cur_pack=pos; | |
336 | |
337 // check if we stay in current cell (speedup things, and avoid angle skip) | |
338 if(d->cur_pack>d->cell_last_pack || | |
339 d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector) { | |
340 | |
341 // ok, cell change, find the right cell! | |
342 d->cur_cell=0; | |
343 if(d->cur_pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) | |
344 d->cur_cell+=dvd_angle; | |
345 | |
346 while(1) { | |
347 int next; | |
348 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
349 if(d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector) { | |
350 d->cur_pack=d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
351 break; | |
352 } | |
353 if(d->cur_pack<=d->cell_last_pack) break; // ok, we find it! :) | |
354 next=dvd_next_cell(d); | |
355 if(next<0) { | |
356 //d->cur_pack=d->cell_last_pack+1; | |
357 break; // we're after the last cell | |
358 } | |
359 d->cur_cell=next; | |
360 } | |
361 } | |
362 | |
363 mp_msg(MSGT_DVD,MSGL_V, "DVD Seek! lba=0x%X cell=%d packs: 0x%X-0x%X \n", | |
364 d->cur_pack,d->cur_cell,d->cur_pgc->cell_playback[ d->cur_cell ].first_sector,d->cell_last_pack); | |
365 | |
366 // if we're in interleaved multi-angle cell, find the right angle chain! | |
367 // (read Navi block, and use the seamless angle jump table) | |
368 d->angle_seek=1; | |
369 } | |
370 | |
371 void dvd_close(dvd_priv_t *d) { | |
372 ifoClose(d->vts_file); | |
373 ifoClose(d->vmg_file); | |
374 DVDCloseFile(d->title); | |
375 DVDClose(d->dvd); | |
376 dvd_chapter = 1; | |
377 dvd_last_chapter = 0; | |
378 } | |
379 | |
380 #endif | |
381 | |
382 static int fill_buffer(stream_t *s, char *but, int len) | |
383 { | |
384 #ifdef USE_DVDREAD | |
385 if(s->type == STREAMTYPE_DVD) { | |
386 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
387 if(pos>=0) { | |
388 len=2048; // full sector | |
389 s->pos=2048*pos-len; | |
390 } else len=-1; // error | |
391 } | |
392 #endif | |
393 return len; | |
394 } | |
395 | |
396 static int seek(stream_t *s, off_t newpos) { | |
397 #ifdef USE_DVDREAD | |
398 s->pos=newpos; // real seek | |
399 dvd_seek(s->priv,s->pos/2048); | |
400 #endif | |
401 return 1; | |
402 } | |
403 | |
404 static void stream_dvd_close(stream_t *s) { | |
405 #ifdef USE_DVDREAD | |
406 dvd_close(s->priv); | |
407 #endif | |
408 } | |
409 | |
410 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
411 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
412 char *filename; | |
413 | |
414 filename = strdup(stream->url); | |
415 mp_msg(MSGT_OPEN,MSGL_V,"URL: %s\n", filename); | |
416 dvd_title = p->title; | |
417 #ifdef USE_DVDREAD | |
418 if(1){ | |
419 //int ret,ret2; | |
420 dvd_priv_t *d; | |
421 int ttn,pgc_id,pgn; | |
422 dvd_reader_t *dvd; | |
423 dvd_file_t *title; | |
424 ifo_handle_t *vmg_file; | |
425 tt_srpt_t *tt_srpt; | |
426 ifo_handle_t *vts_file; | |
427 /** | |
428 * Open the disc. | |
429 */ | |
430 if(!dvd_device) dvd_device=strdup(DEFAULT_DVD_DEVICE); | |
431 #ifdef SYS_DARWIN | |
432 /* Dynamic DVD drive selection on Darwin */ | |
433 if(!strcmp(dvd_device, "/dev/rdiskN")) { | |
434 int i; | |
435 char *temp_device = malloc((strlen(dvd_device)+1)*sizeof(char)); | |
436 | |
437 for (i = 1; i < 10; i++) { | |
438 sprintf(temp_device, "/dev/rdisk%d", i); | |
439 dvd = DVDOpen(temp_device); | |
440 if(!dvd) { | |
441 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,temp_device); | |
442 } else { | |
443 free(temp_device); | |
444 break; | |
445 } | |
446 } | |
447 | |
448 if(!dvd) { | |
449 m_struct_free(&stream_opts,opts); | |
450 return STREAM_UNSUPORTED; | |
451 } | |
452 } else | |
453 #endif /* SYS_DARWIN */ | |
454 { | |
455 dvd = DVDOpen(dvd_device); | |
456 if(!dvd) { | |
457 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device); | |
458 m_struct_free(&stream_opts,opts); | |
459 return STREAM_UNSUPORTED; | |
460 } | |
461 } | |
462 | |
463 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDwait); | |
464 | |
465 /** | |
466 * Load the video manager to find out the information about the titles on | |
467 * this disc. | |
468 */ | |
469 vmg_file = ifoOpen(dvd, 0); | |
470 if(!vmg_file) { | |
471 mp_msg(MSGT_OPEN,MSGL_ERR, "Can't open VMG info!\n"); | |
472 DVDClose( dvd ); | |
473 m_struct_free(&stream_opts,opts); | |
474 return STREAM_UNSUPORTED; | |
475 } | |
476 tt_srpt = vmg_file->tt_srpt; | |
477 /** | |
478 * Make sure our title number is valid. | |
479 */ | |
480 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumTitles, tt_srpt->nr_of_srpts ); | |
481 if(dvd_title < 1 || dvd_title > tt_srpt->nr_of_srpts) { | |
482 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidTitle, dvd_title); | |
483 ifoClose( vmg_file ); | |
484 DVDClose( dvd ); | |
485 m_struct_free(&stream_opts,opts); | |
486 return STREAM_UNSUPORTED; | |
487 } | |
488 --dvd_title; // remap 1.. -> 0.. | |
489 /** | |
490 * Make sure the chapter number is valid for this title. | |
491 */ | |
492 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumChapters, tt_srpt->title[dvd_title].nr_of_ptts); | |
493 if(dvd_chapter<1 || dvd_chapter>tt_srpt->title[dvd_title].nr_of_ptts) { | |
494 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidChapter, dvd_chapter); | |
495 ifoClose( vmg_file ); | |
496 DVDClose( dvd ); | |
497 m_struct_free(&stream_opts,opts); | |
498 return STREAM_UNSUPORTED; | |
499 } | |
500 if(dvd_last_chapter>0) { | |
501 if(dvd_last_chapter<dvd_chapter || dvd_last_chapter>tt_srpt->title[dvd_title].nr_of_ptts) { | |
502 mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid DVD last chapter number: %d\n", dvd_last_chapter); | |
503 ifoClose( vmg_file ); | |
504 DVDClose( dvd ); | |
505 m_struct_free(&stream_opts,opts); | |
506 return STREAM_UNSUPORTED; | |
507 } | |
508 } | |
509 --dvd_chapter; // remap 1.. -> 0.. | |
510 /* XXX No need to remap dvd_last_chapter */ | |
511 /** | |
512 * Make sure the angle number is valid for this title. | |
513 */ | |
514 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumAngles, tt_srpt->title[dvd_title].nr_of_angles); | |
515 if(dvd_angle<1 || dvd_angle>tt_srpt->title[dvd_title].nr_of_angles) { | |
516 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidAngle, dvd_angle); | |
517 ifoClose( vmg_file ); | |
518 DVDClose( dvd ); | |
519 m_struct_free(&stream_opts,opts); | |
520 return STREAM_UNSUPORTED; | |
521 } | |
522 --dvd_angle; // remap 1.. -> 0.. | |
523 /** | |
524 * Load the VTS information for the title set our title is in. | |
525 */ | |
526 vts_file = ifoOpen( dvd, tt_srpt->title[dvd_title].title_set_nr ); | |
527 if(!vts_file) { | |
528 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoIFO, tt_srpt->title[dvd_title].title_set_nr ); | |
529 ifoClose( vmg_file ); | |
530 DVDClose( dvd ); | |
531 m_struct_free(&stream_opts,opts); | |
532 return STREAM_UNSUPORTED; | |
533 } | |
534 /** | |
535 * We've got enough info, time to open the title set data. | |
536 */ | |
537 title = DVDOpenFile(dvd, tt_srpt->title[dvd_title].title_set_nr, DVD_READ_TITLE_VOBS); | |
538 if(!title) { | |
539 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoVOBs, tt_srpt->title[dvd_title].title_set_nr); | |
540 ifoClose( vts_file ); | |
541 ifoClose( vmg_file ); | |
542 DVDClose( dvd ); | |
543 m_struct_free(&stream_opts,opts); | |
544 return STREAM_UNSUPORTED; | |
545 } | |
546 | |
547 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDopenOk); | |
548 // store data | |
549 d=malloc(sizeof(dvd_priv_t)); memset(d,0,sizeof(dvd_priv_t)); | |
550 d->dvd=dvd; | |
551 d->title=title; | |
552 d->vmg_file=vmg_file; | |
553 d->tt_srpt=tt_srpt; | |
554 d->vts_file=vts_file; | |
555 | |
556 /** | |
557 * Check number of audio channels and types | |
558 */ | |
559 { | |
560 int ac3aid = 128; | |
561 int mpegaid = 0; | |
562 int pcmaid = 160; | |
563 | |
564 d->nr_of_channels=0; | |
565 if(vts_file->vts_pgcit) { | |
566 int i; | |
567 for(i=0;i<8;i++) | |
568 if(vts_file->vts_pgcit->pgci_srp[0].pgc->audio_control[i] & 0x8000) { | |
569 audio_attr_t * audio = &vts_file->vtsi_mat->vts_audio_attr[i]; | |
570 int language = 0; | |
571 char tmp[] = "unknown"; | |
572 | |
573 if(audio->lang_type == 1) { | |
574 language=audio->lang_code; | |
575 tmp[0]=language>>8; | |
576 tmp[1]=language&0xff; | |
577 tmp[2]=0; | |
578 } | |
579 | |
580 d->audio_streams[d->nr_of_channels].language=language; | |
581 d->audio_streams[d->nr_of_channels].id=0; | |
582 switch(audio->audio_format) { | |
583 case 0: // ac3 | |
584 d->audio_streams[d->nr_of_channels].id=ac3aid; | |
585 ac3aid++; | |
586 break; | |
587 case 6: // dts | |
588 d->audio_streams[d->nr_of_channels].id=ac3aid+8; | |
589 ac3aid++; | |
590 break; | |
591 case 2: // mpeg layer 1/2/3 | |
592 case 3: // mpeg2 ext | |
593 d->audio_streams[d->nr_of_channels].id=mpegaid; | |
594 mpegaid++; | |
595 break; | |
596 case 4: // lpcm | |
597 d->audio_streams[d->nr_of_channels].id=pcmaid; | |
598 pcmaid++; | |
599 break; | |
600 } | |
601 | |
602 d->audio_streams[d->nr_of_channels].type=audio->audio_format; | |
603 // Pontscho: to my mind, tha channels: | |
604 // 1 - stereo | |
605 // 5 - 5.1 | |
606 d->audio_streams[d->nr_of_channels].channels=audio->channels; | |
607 mp_msg(MSGT_OPEN,MSGL_V,"[open] audio stream: %d audio format: %s (%s) language: %s aid: %d\n", | |
608 d->nr_of_channels, | |
609 dvd_audio_stream_types[ audio->audio_format ], | |
610 dvd_audio_stream_channels[ audio->channels ], | |
611 tmp, | |
612 d->audio_streams[d->nr_of_channels].id | |
613 ); | |
614 if(identify) { | |
615 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_ID=%d\n", d->audio_streams[d->nr_of_channels].id); | |
616 if(language && tmp[0]) | |
617 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AID_%d_LANG=%s\n", d->audio_streams[d->nr_of_channels].id, tmp); | |
618 } | |
619 | |
620 d->nr_of_channels++; | |
621 } | |
622 } | |
623 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of audio channels on disk: %d.\n",d->nr_of_channels ); | |
624 } | |
625 | |
626 /** | |
627 * Check number of subtitles and language | |
628 */ | |
629 { | |
630 int i; | |
631 | |
632 d->nr_of_subtitles=0; | |
633 for(i=0;i<32;i++) | |
634 if(vts_file->vts_pgcit->pgci_srp[0].pgc->subp_control[i] & 0x80000000) { | |
635 subp_attr_t * subtitle = &vts_file->vtsi_mat->vts_subp_attr[i]; | |
636 int language = 0; | |
637 char tmp[] = "unknown"; | |
638 | |
639 if(subtitle->type == 1) { | |
640 language=subtitle->lang_code; | |
641 tmp[0]=language>>8; | |
642 tmp[1]=language&0xff; | |
643 tmp[2]=0; | |
644 } | |
645 | |
646 d->subtitles[ d->nr_of_subtitles ].language=language; | |
647 d->subtitles[ d->nr_of_subtitles ].id=d->nr_of_subtitles; | |
648 | |
649 mp_msg(MSGT_OPEN,MSGL_V,"[open] subtitle ( sid ): %d language: %s\n", d->nr_of_subtitles, tmp); | |
650 if(identify) { | |
651 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", d->nr_of_subtitles); | |
652 if(language && tmp[0]) | |
653 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_SID_%d_LANG=%s\n", d->nr_of_subtitles, tmp); | |
654 } | |
655 d->nr_of_subtitles++; | |
656 } | |
657 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of subtitles on disk: %d\n",d->nr_of_subtitles ); | |
658 } | |
659 | |
660 /** | |
661 * Determine which program chain we want to watch. This is based on the | |
662 * chapter number. | |
663 */ | |
664 ttn = tt_srpt->title[ dvd_title ].vts_ttn; // local | |
665 pgc_id = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgcn; // local | |
666 pgn = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgn; // local | |
667 d->cur_pgc = vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
668 d->cur_cell = d->cur_pgc->program_map[pgn-1] - 1; // start playback here | |
669 d->packs_left=-1; // for Navi stuff | |
670 d->angle_seek=0; | |
671 /* XXX dvd_last_chapter is in the range 1..nr_of_ptts */ | |
672 if(dvd_last_chapter > 0 && dvd_last_chapter < tt_srpt->title[dvd_title].nr_of_ptts) { | |
673 pgn=vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_last_chapter].pgn; | |
674 d->last_cell=d->cur_pgc->program_map[pgn-1] - 1; | |
675 } else | |
676 d->last_cell=d->cur_pgc->nr_of_cells; | |
677 | |
678 if(d->cur_pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) | |
679 d->cur_cell+=dvd_angle; | |
680 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
681 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
682 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); | |
683 | |
684 // ... (unimplemented) | |
685 // return NULL; | |
686 stream->type = STREAMTYPE_DVD; | |
687 stream->sector_size = 2048; | |
688 stream->flags = STREAM_READ | STREAM_SEEK; | |
689 stream->fill_buffer = fill_buffer; | |
690 stream->seek = seek; | |
691 stream->close = stream_dvd_close; | |
692 stream->start_pos = (off_t)d->cur_pack*2048; | |
693 stream->end_pos = (off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; | |
694 mp_msg(MSGT_DVD,MSGL_V,"DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector); | |
695 stream->priv = (void*)d; | |
696 return STREAM_OK; | |
697 } | |
698 #endif | |
699 mp_msg(MSGT_DVD,MSGL_ERR,"MPlayer was compiled without dvd support, exit\n"); | |
700 m_struct_free(&stream_opts,opts); | |
701 return STREAM_UNSUPORTED; | |
702 } | |
703 | |
704 | |
705 stream_info_t stream_info_dvd = { | |
706 "DVD stream", | |
707 "null", | |
708 "", | |
709 "", | |
710 open_s, | |
711 { "dvd", NULL }, | |
712 &stream_opts, | |
713 1 // Urls are an option string | |
714 }; |