Mercurial > mplayer.hg
annotate libmpdemux/stream_dvd.c @ 16578:81c601f34fad
German man page review part V
("OSD-/\:UNTERTITEL-OPTIONEN")
author | kraymer |
---|---|
date | Sat, 24 Sep 2005 17:39:40 +0000 |
parents | a10adcba312f |
children | e1d6fbd607e0 |
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 | |
16544
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
410 /** |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
411 \brief Converts DVD time structure to milliseconds. |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
412 \param *dev the DVD time structure to convert |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
413 \return returns the time in milliseconds |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
414 */ |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
415 static int dvdtimetomsec(dvd_time_t *dt) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
416 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
417 static int framerates[4] = {0, 2500, 0, 2997}; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
418 int framerate = framerates[(dt->frame_u & 0xc0) >> 6]; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
419 int msec = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
420 msec += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
421 msec += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
422 if(framerate > 0) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
423 msec += (((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f)) * 100000 / framerate; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
424 return msec; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
425 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
426 |
15518 | 427 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { |
428 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
429 char *filename; | |
430 | |
431 filename = strdup(stream->url); | |
432 mp_msg(MSGT_OPEN,MSGL_V,"URL: %s\n", filename); | |
433 dvd_title = p->title; | |
434 #ifdef USE_DVDREAD | |
435 if(1){ | |
436 //int ret,ret2; | |
437 dvd_priv_t *d; | |
438 int ttn,pgc_id,pgn; | |
439 dvd_reader_t *dvd; | |
440 dvd_file_t *title; | |
441 ifo_handle_t *vmg_file; | |
442 tt_srpt_t *tt_srpt; | |
443 ifo_handle_t *vts_file; | |
444 /** | |
445 * Open the disc. | |
446 */ | |
447 if(!dvd_device) dvd_device=strdup(DEFAULT_DVD_DEVICE); | |
448 #ifdef SYS_DARWIN | |
449 /* Dynamic DVD drive selection on Darwin */ | |
450 if(!strcmp(dvd_device, "/dev/rdiskN")) { | |
451 int i; | |
452 char *temp_device = malloc((strlen(dvd_device)+1)*sizeof(char)); | |
453 | |
454 for (i = 1; i < 10; i++) { | |
455 sprintf(temp_device, "/dev/rdisk%d", i); | |
456 dvd = DVDOpen(temp_device); | |
457 if(!dvd) { | |
458 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,temp_device); | |
459 } else { | |
460 free(temp_device); | |
461 break; | |
462 } | |
463 } | |
464 | |
465 if(!dvd) { | |
466 m_struct_free(&stream_opts,opts); | |
467 return STREAM_UNSUPORTED; | |
468 } | |
469 } else | |
470 #endif /* SYS_DARWIN */ | |
471 { | |
472 dvd = DVDOpen(dvd_device); | |
473 if(!dvd) { | |
474 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device); | |
475 m_struct_free(&stream_opts,opts); | |
476 return STREAM_UNSUPORTED; | |
477 } | |
478 } | |
479 | |
480 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDwait); | |
481 | |
482 /** | |
483 * Load the video manager to find out the information about the titles on | |
484 * this disc. | |
485 */ | |
486 vmg_file = ifoOpen(dvd, 0); | |
487 if(!vmg_file) { | |
488 mp_msg(MSGT_OPEN,MSGL_ERR, "Can't open VMG info!\n"); | |
489 DVDClose( dvd ); | |
490 m_struct_free(&stream_opts,opts); | |
491 return STREAM_UNSUPORTED; | |
492 } | |
493 tt_srpt = vmg_file->tt_srpt; | |
16544
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
494 if (identify) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
495 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
496 unsigned char discid [16]; ///< disk ID, a 128 bit MD5 sum |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
497 int vts_no; ///< video title set number |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
498 int title_no; ///< title number |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
499 int vts_ttn; ///< title number within video title set |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
500 int pgc_no; ///< program chain number |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
501 int msec; ///< time length in milliseconds |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
502 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLES=%d\n", tt_srpt->nr_of_srpts); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
503 for (title_no = 0; title_no < tt_srpt->nr_of_srpts; title_no++) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
504 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
505 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_CHAPTERS=%d\n", title_no + 1, tt_srpt->title[title_no].nr_of_ptts); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
506 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_ANGLES=%d\n", title_no + 1, tt_srpt->title[title_no].nr_of_angles); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
507 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
508 for (vts_no = 1; vts_no <= vmg_file->vts_atrt->nr_of_vtss; vts_no++) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
509 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
510 vts_file = ifoOpen(dvd, vts_no); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
511 if (vts_file) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
512 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
513 if (vts_file->vtsi_mat && vts_file->vts_pgcit) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
514 for (title_no = 0; title_no < tt_srpt->nr_of_srpts; title_no++) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
515 if (tt_srpt->title[title_no].title_set_nr == vts_no) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
516 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
517 vts_ttn = tt_srpt->title[title_no].vts_ttn - 1; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
518 pgc_no = vts_file->vts_ptt_srpt->title[vts_ttn].ptt[0].pgcn - 1; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
519 msec = dvdtimetomsec(&vts_file->vts_pgcit->pgci_srp[pgc_no].pgc->playback_time); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
520 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title_no + 1, msec / 1000, msec % 1000); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
521 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
522 ifoClose(vts_file); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
523 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
524 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
525 if (DVDDiscID(dvd, discid) >= 0) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
526 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
527 int i; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
528 char buf[33]; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
529 for (i = 0; i < 16; i ++) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
530 sprintf(buf+2*i, "%02X", discid[i]); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
531 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_DISC_ID=%s\n", buf); |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
532 } |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
533 } |
15518 | 534 /** |
535 * Make sure our title number is valid. | |
536 */ | |
537 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumTitles, tt_srpt->nr_of_srpts ); | |
538 if(dvd_title < 1 || dvd_title > tt_srpt->nr_of_srpts) { | |
539 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidTitle, dvd_title); | |
540 ifoClose( vmg_file ); | |
541 DVDClose( dvd ); | |
542 m_struct_free(&stream_opts,opts); | |
543 return STREAM_UNSUPORTED; | |
544 } | |
545 --dvd_title; // remap 1.. -> 0.. | |
546 /** | |
547 * Make sure the chapter number is valid for this title. | |
548 */ | |
549 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumChapters, tt_srpt->title[dvd_title].nr_of_ptts); | |
550 if(dvd_chapter<1 || dvd_chapter>tt_srpt->title[dvd_title].nr_of_ptts) { | |
551 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidChapter, dvd_chapter); | |
552 ifoClose( vmg_file ); | |
553 DVDClose( dvd ); | |
554 m_struct_free(&stream_opts,opts); | |
555 return STREAM_UNSUPORTED; | |
556 } | |
557 if(dvd_last_chapter>0) { | |
558 if(dvd_last_chapter<dvd_chapter || dvd_last_chapter>tt_srpt->title[dvd_title].nr_of_ptts) { | |
559 mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid DVD last chapter number: %d\n", dvd_last_chapter); | |
560 ifoClose( vmg_file ); | |
561 DVDClose( dvd ); | |
562 m_struct_free(&stream_opts,opts); | |
563 return STREAM_UNSUPORTED; | |
564 } | |
565 } | |
566 --dvd_chapter; // remap 1.. -> 0.. | |
567 /* XXX No need to remap dvd_last_chapter */ | |
568 /** | |
569 * Make sure the angle number is valid for this title. | |
570 */ | |
571 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumAngles, tt_srpt->title[dvd_title].nr_of_angles); | |
572 if(dvd_angle<1 || dvd_angle>tt_srpt->title[dvd_title].nr_of_angles) { | |
573 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidAngle, dvd_angle); | |
574 ifoClose( vmg_file ); | |
575 DVDClose( dvd ); | |
576 m_struct_free(&stream_opts,opts); | |
577 return STREAM_UNSUPORTED; | |
578 } | |
579 --dvd_angle; // remap 1.. -> 0.. | |
580 /** | |
581 * Load the VTS information for the title set our title is in. | |
582 */ | |
583 vts_file = ifoOpen( dvd, tt_srpt->title[dvd_title].title_set_nr ); | |
584 if(!vts_file) { | |
585 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoIFO, tt_srpt->title[dvd_title].title_set_nr ); | |
586 ifoClose( vmg_file ); | |
587 DVDClose( dvd ); | |
588 m_struct_free(&stream_opts,opts); | |
589 return STREAM_UNSUPORTED; | |
590 } | |
591 /** | |
592 * We've got enough info, time to open the title set data. | |
593 */ | |
594 title = DVDOpenFile(dvd, tt_srpt->title[dvd_title].title_set_nr, DVD_READ_TITLE_VOBS); | |
595 if(!title) { | |
596 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoVOBs, tt_srpt->title[dvd_title].title_set_nr); | |
597 ifoClose( vts_file ); | |
598 ifoClose( vmg_file ); | |
599 DVDClose( dvd ); | |
600 m_struct_free(&stream_opts,opts); | |
601 return STREAM_UNSUPORTED; | |
602 } | |
603 | |
604 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDopenOk); | |
605 // store data | |
606 d=malloc(sizeof(dvd_priv_t)); memset(d,0,sizeof(dvd_priv_t)); | |
607 d->dvd=dvd; | |
608 d->title=title; | |
609 d->vmg_file=vmg_file; | |
610 d->tt_srpt=tt_srpt; | |
611 d->vts_file=vts_file; | |
612 | |
613 /** | |
614 * Check number of audio channels and types | |
615 */ | |
616 { | |
617 int ac3aid = 128; | |
618 int mpegaid = 0; | |
619 int pcmaid = 160; | |
620 | |
621 d->nr_of_channels=0; | |
622 if(vts_file->vts_pgcit) { | |
623 int i; | |
624 for(i=0;i<8;i++) | |
625 if(vts_file->vts_pgcit->pgci_srp[0].pgc->audio_control[i] & 0x8000) { | |
626 audio_attr_t * audio = &vts_file->vtsi_mat->vts_audio_attr[i]; | |
627 int language = 0; | |
628 char tmp[] = "unknown"; | |
629 | |
630 if(audio->lang_type == 1) { | |
631 language=audio->lang_code; | |
632 tmp[0]=language>>8; | |
633 tmp[1]=language&0xff; | |
634 tmp[2]=0; | |
635 } | |
636 | |
637 d->audio_streams[d->nr_of_channels].language=language; | |
638 d->audio_streams[d->nr_of_channels].id=0; | |
639 switch(audio->audio_format) { | |
640 case 0: // ac3 | |
641 d->audio_streams[d->nr_of_channels].id=ac3aid; | |
642 ac3aid++; | |
643 break; | |
644 case 6: // dts | |
645 d->audio_streams[d->nr_of_channels].id=ac3aid+8; | |
646 ac3aid++; | |
647 break; | |
648 case 2: // mpeg layer 1/2/3 | |
649 case 3: // mpeg2 ext | |
650 d->audio_streams[d->nr_of_channels].id=mpegaid; | |
651 mpegaid++; | |
652 break; | |
653 case 4: // lpcm | |
654 d->audio_streams[d->nr_of_channels].id=pcmaid; | |
655 pcmaid++; | |
656 break; | |
657 } | |
658 | |
659 d->audio_streams[d->nr_of_channels].type=audio->audio_format; | |
660 // Pontscho: to my mind, tha channels: | |
661 // 1 - stereo | |
662 // 5 - 5.1 | |
663 d->audio_streams[d->nr_of_channels].channels=audio->channels; | |
664 mp_msg(MSGT_OPEN,MSGL_V,"[open] audio stream: %d audio format: %s (%s) language: %s aid: %d\n", | |
665 d->nr_of_channels, | |
666 dvd_audio_stream_types[ audio->audio_format ], | |
667 dvd_audio_stream_channels[ audio->channels ], | |
668 tmp, | |
669 d->audio_streams[d->nr_of_channels].id | |
670 ); | |
671 if(identify) { | |
672 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_ID=%d\n", d->audio_streams[d->nr_of_channels].id); | |
673 if(language && tmp[0]) | |
674 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AID_%d_LANG=%s\n", d->audio_streams[d->nr_of_channels].id, tmp); | |
675 } | |
676 | |
677 d->nr_of_channels++; | |
678 } | |
679 } | |
680 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of audio channels on disk: %d.\n",d->nr_of_channels ); | |
681 } | |
682 | |
683 /** | |
684 * Check number of subtitles and language | |
685 */ | |
686 { | |
687 int i; | |
688 | |
689 d->nr_of_subtitles=0; | |
690 for(i=0;i<32;i++) | |
691 if(vts_file->vts_pgcit->pgci_srp[0].pgc->subp_control[i] & 0x80000000) { | |
692 subp_attr_t * subtitle = &vts_file->vtsi_mat->vts_subp_attr[i]; | |
693 int language = 0; | |
694 char tmp[] = "unknown"; | |
695 | |
696 if(subtitle->type == 1) { | |
697 language=subtitle->lang_code; | |
698 tmp[0]=language>>8; | |
699 tmp[1]=language&0xff; | |
700 tmp[2]=0; | |
701 } | |
702 | |
703 d->subtitles[ d->nr_of_subtitles ].language=language; | |
704 d->subtitles[ d->nr_of_subtitles ].id=d->nr_of_subtitles; | |
705 | |
706 mp_msg(MSGT_OPEN,MSGL_V,"[open] subtitle ( sid ): %d language: %s\n", d->nr_of_subtitles, tmp); | |
707 if(identify) { | |
708 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", d->nr_of_subtitles); | |
709 if(language && tmp[0]) | |
710 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_SID_%d_LANG=%s\n", d->nr_of_subtitles, tmp); | |
711 } | |
712 d->nr_of_subtitles++; | |
713 } | |
714 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of subtitles on disk: %d\n",d->nr_of_subtitles ); | |
715 } | |
716 | |
717 /** | |
718 * Determine which program chain we want to watch. This is based on the | |
719 * chapter number. | |
720 */ | |
721 ttn = tt_srpt->title[ dvd_title ].vts_ttn; // local | |
722 pgc_id = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgcn; // local | |
723 pgn = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgn; // local | |
724 d->cur_pgc = vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
725 d->cur_cell = d->cur_pgc->program_map[pgn-1] - 1; // start playback here | |
726 d->packs_left=-1; // for Navi stuff | |
727 d->angle_seek=0; | |
728 /* XXX dvd_last_chapter is in the range 1..nr_of_ptts */ | |
729 if(dvd_last_chapter > 0 && dvd_last_chapter < tt_srpt->title[dvd_title].nr_of_ptts) { | |
730 pgn=vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_last_chapter].pgn; | |
731 d->last_cell=d->cur_pgc->program_map[pgn-1] - 1; | |
732 } else | |
733 d->last_cell=d->cur_pgc->nr_of_cells; | |
734 | |
735 if(d->cur_pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) | |
736 d->cur_cell+=dvd_angle; | |
737 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
738 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
739 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); | |
740 | |
741 // ... (unimplemented) | |
742 // return NULL; | |
743 stream->type = STREAMTYPE_DVD; | |
744 stream->sector_size = 2048; | |
745 stream->flags = STREAM_READ | STREAM_SEEK; | |
746 stream->fill_buffer = fill_buffer; | |
747 stream->seek = seek; | |
748 stream->close = stream_dvd_close; | |
749 stream->start_pos = (off_t)d->cur_pack*2048; | |
750 stream->end_pos = (off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; | |
751 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); | |
752 stream->priv = (void*)d; | |
753 return STREAM_OK; | |
754 } | |
755 #endif | |
756 mp_msg(MSGT_DVD,MSGL_ERR,"MPlayer was compiled without dvd support, exit\n"); | |
757 m_struct_free(&stream_opts,opts); | |
758 return STREAM_UNSUPORTED; | |
759 } | |
760 | |
761 | |
762 stream_info_t stream_info_dvd = { | |
763 "DVD stream", | |
764 "null", | |
765 "", | |
766 "", | |
767 open_s, | |
768 { "dvd", NULL }, | |
769 &stream_opts, | |
770 1 // Urls are an option string | |
771 }; |