Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / stream / stream_dvdnav.c
blobaaf3c5a6900b6da33b32ea294ca54acd5bac4bbd
1 #include "config.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <errno.h>
8 #include "mp_msg.h"
9 #include "osdep/timer.h"
10 #include "input/input.h"
11 #include "stream.h"
12 #include "libmpdemux/demuxer.h"
13 #include "stream_dvdnav.h"
14 #include "libvo/video_out.h"
15 #include "libavutil/common.h"
16 #include "spudec.h"
17 #include "m_option.h"
18 #include "m_struct.h"
19 #include "help_mp.h"
21 extern char *dvd_device;
22 extern int dvd_chapter;
23 extern int dvd_last_chapter;
24 extern int dvd_angle;
25 extern char *audio_lang, *dvdsub_lang;
26 extern char *dvd_audio_stream_channels[6], *dvd_audio_stream_types[8];
28 static struct stream_priv_s {
29 int track;
30 char* device;
31 } stream_priv_dflts = {
33 NULL
36 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
37 /// URL definition
38 static const m_option_t stream_opts_fields[] = {
39 {"filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL },
40 {"hostname", ST_OFF(track), CONF_TYPE_INT, 0, 0, 0, NULL},
41 { NULL, NULL, 0, 0, 0, 0, NULL }
43 static struct m_struct_st stream_opts = {
44 "dvd",
45 sizeof(struct stream_priv_s),
46 &stream_priv_dflts,
47 stream_opts_fields
50 static int seek(stream_t *s, off_t newpos);
52 static dvdnav_priv_t * new_dvdnav_stream(char * filename) {
53 char * title_str;
54 dvdnav_priv_t *priv;
56 if (!filename)
57 return NULL;
59 if (!(priv=calloc(1,sizeof(dvdnav_priv_t))))
60 return NULL;
62 if (!(priv->filename=strdup(filename))) {
63 free(priv);
64 return NULL;
67 if(dvdnav_open(&(priv->dvdnav),priv->filename)!=DVDNAV_STATUS_OK)
69 free(priv->filename);
70 free(priv);
71 return NULL;
74 if (!priv->dvdnav) {
75 free(priv);
76 return NULL;
79 if(1) //from vlc: if not used dvdnav from cvs will fail
81 int len, event;
82 char buf[2048];
84 dvdnav_get_next_block(priv->dvdnav,buf,&event,&len);
85 dvdnav_sector_search(priv->dvdnav, 0, SEEK_SET);
88 /* turn off dvdnav caching */
89 dvdnav_set_readahead_flag(priv->dvdnav, 0);
90 if(dvdnav_set_PGC_positioning_flag(priv->dvdnav, 1) != DVDNAV_STATUS_OK)
91 mp_msg(MSGT_OPEN,MSGL_ERR,"stream_dvdnav, failed to set PGC positioning\n");
92 #if 1
93 /* report the title?! */
94 if (dvdnav_get_title_string(priv->dvdnav,&title_str)==DVDNAV_STATUS_OK) {
95 mp_msg(MSGT_IDENTIFY, MSGL_INFO,"Title: '%s'\n",title_str);
97 #endif
99 //dvdnav_event_clear(priv);
101 return priv;
104 static void dvdnav_get_highlight (dvdnav_priv_t *priv, int display_mode) {
105 pci_t *pnavpci = NULL;
106 dvdnav_highlight_event_t *hlev = &(priv->hlev);
107 int btnum;
109 if (!priv || !priv->dvdnav)
110 return;
112 pnavpci = dvdnav_get_current_nav_pci (priv->dvdnav);
113 if (!pnavpci)
114 return;
116 dvdnav_get_current_highlight (priv->dvdnav, &(hlev->buttonN));
117 hlev->display = display_mode; /* show */
119 if (hlev->buttonN > 0 && pnavpci->hli.hl_gi.btn_ns > 0 && hlev->display) {
120 for (btnum = 0; btnum < pnavpci->hli.hl_gi.btn_ns; btnum++) {
121 btni_t *btni = &(pnavpci->hli.btnit[btnum]);
123 if (hlev->buttonN == btnum + 1) {
124 hlev->sx = FFMIN (btni->x_start, btni->x_end);
125 hlev->ex = FFMAX (btni->x_start, btni->x_end);
126 hlev->sy = FFMIN (btni->y_start, btni->y_end);
127 hlev->ey = FFMAX (btni->y_start, btni->y_end);
129 hlev->palette = (btni->btn_coln == 0) ? 0 :
130 pnavpci->hli.btn_colit.btn_coli[btni->btn_coln - 1][0];
131 break;
134 } else { /* hide button or no button */
135 hlev->sx = hlev->ex = 0;
136 hlev->sy = hlev->ey = 0;
137 hlev->palette = hlev->buttonN = 0;
141 static int dvdnav_stream_read(dvdnav_priv_t * priv, unsigned char *buf, int *len) {
142 int event = DVDNAV_NOP;
144 *len=-1;
145 if (dvdnav_get_next_block(priv->dvdnav,buf,&event,len)!=DVDNAV_STATUS_OK) {
146 mp_msg(MSGT_OPEN,MSGL_V, "Error getting next block from DVD %d (%s)\n",event, dvdnav_err_to_string(priv->dvdnav) );
147 *len=-1;
149 else if (event!=DVDNAV_BLOCK_OK) {
150 // need to handle certain events internally (like skipping stills)
151 switch (event) {
152 case DVDNAV_NAV_PACKET:
153 return event;
154 case DVDNAV_STILL_FRAME: {
155 dvdnav_still_skip(priv->dvdnav); // don't let dvdnav stall on this image
156 break;
158 case DVDNAV_HIGHLIGHT: {
159 dvdnav_get_highlight (priv, 1);
160 break;
162 case DVDNAV_CELL_CHANGE: {
163 dvdnav_cell_change_event_t *ev = (dvdnav_cell_change_event_t*)buf;
164 if(ev->pgc_length)
165 priv->duration = ev->pgc_length/90;
166 break;
168 case DVDNAV_SPU_CLUT_CHANGE: {
169 memcpy(priv->spu_clut, buf, 16*sizeof(unsigned int));
170 priv->spu_set = 1;
171 break;
173 case DVDNAV_WAIT:
174 dvdnav_wait_skip(priv->dvdnav);
175 break;
178 *len=0;
180 return event;
183 static void update_title_len(stream_t *stream) {
184 dvdnav_priv_t *priv = stream->priv;
185 dvdnav_status_t status;
186 uint32_t pos = 0, len = 0;
188 status = dvdnav_get_position(priv->dvdnav, &pos, &len);
189 if(status == DVDNAV_STATUS_OK && len) {
190 stream->end_pos = (off_t) len * 2048;
191 stream->seek = seek;
192 } else {
193 stream->seek = NULL;
194 stream->end_pos = 0;
199 static int seek(stream_t *s, off_t newpos) {
200 uint32_t sector = 0;
201 dvdnav_priv_t *priv = s->priv;
203 if(s->end_pos && newpos > s->end_pos)
204 newpos = s->end_pos;
205 sector = newpos / 2048ULL;
206 if(dvdnav_sector_search(priv->dvdnav, (uint64_t) sector, SEEK_SET) != DVDNAV_STATUS_OK)
207 goto fail;
209 s->pos = newpos;
211 return 1;
213 fail:
214 mp_msg(MSGT_STREAM,MSGL_INFO,"dvdnav_stream, seeking to %"PRIu64" failed: %s\n", newpos, dvdnav_err_to_string(priv->dvdnav));
216 return 1;
219 static void stream_dvdnav_close(stream_t *s) {
220 dvdnav_priv_t *priv = s->priv;
221 dvdnav_close(priv->dvdnav);
222 priv->dvdnav = NULL;
223 free(priv);
227 static int fill_buffer(stream_t *s, char *but, int len)
229 int event;
231 dvdnav_priv_t* priv=s->priv;
232 len=0;
233 if(!s->end_pos)
234 update_title_len(s);
235 while(!len) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
237 event=dvdnav_stream_read(priv, s->buffer, &len);
238 if(event==-1 || len==-1)
240 mp_msg(MSGT_CPLAYER,MSGL_ERR, "DVDNAV stream read error!\n");
241 return 0;
243 switch (event) {
244 case DVDNAV_STOP:
245 case DVDNAV_BLOCK_OK:
246 case DVDNAV_NAV_PACKET:
247 return len;
248 case DVDNAV_VTS_CHANGE: {
249 int tit = 0, part = 0;
250 dvdnav_vts_change_event_t *vts_event = (dvdnav_vts_change_event_t *)s->buffer;
251 mp_msg(MSGT_CPLAYER,MSGL_INFO, "DVDNAV, switched to title: %d\r\n", vts_event->new_vtsN);
252 s->end_pos = 0;
253 update_title_len(s);
254 if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK) {
255 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nDVDNAV, NEW TITLE %d\r\n", tit);
256 dvdnav_get_highlight (priv, 0);
257 if(priv->title > 0 && tit != priv->title)
258 return 0;
260 break;
262 case DVDNAV_CELL_CHANGE: {
263 if(priv->title > 0 && dvd_last_chapter > 0) {
264 int tit=0, part=0;
265 if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK && part > dvd_last_chapter)
266 return 0;
269 break;
272 mp_msg(MSGT_STREAM,MSGL_DBG2,"DVDNAV fill_buffer len: %d\n",len);
273 return len;
276 static int control(stream_t *stream, int cmd, void* arg) {
277 dvdnav_priv_t* priv=stream->priv;
278 int tit, part;
280 switch(cmd)
282 case STREAM_CTRL_SEEK_TO_CHAPTER:
284 int chap = *((unsigned int *)arg)+1;
286 if(chap < 1 || dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
287 break;
288 if(dvdnav_part_play(priv->dvdnav, tit, chap) != DVDNAV_STATUS_OK)
289 break;
290 return 1;
292 case STREAM_CTRL_GET_NUM_CHAPTERS:
294 if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
295 break;
296 if(dvdnav_get_number_of_parts(priv->dvdnav, tit, &part) != DVDNAV_STATUS_OK)
297 break;
298 if(!part)
299 break;
300 *((unsigned int *)arg) = part;
301 return 1;
303 case STREAM_CTRL_GET_CURRENT_CHAPTER:
305 if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
306 break;
307 *((unsigned int *)arg) = part - 1;
308 return 1;
310 case STREAM_CTRL_GET_TIME_LENGTH:
312 if(priv->duration)
314 *((double *)arg) = (double)priv->duration / 1000.0;
315 return 1;
317 break;
319 case STREAM_CTRL_GET_ASPECT_RATIO:
321 uint8_t ar = dvdnav_get_video_aspect(priv->dvdnav);
322 *((double *)arg) = !ar ? 4.0/3.0 : 16.0/9.0;
323 return 1;
325 case STREAM_CTRL_GET_CURRENT_TIME:
327 double tm;
328 tm = dvdnav_get_current_time(priv->dvdnav)/90000.0f;
329 if(tm != -1)
331 *((double *)arg) = tm;
332 return 1;
334 break;
336 case STREAM_CTRL_SEEK_TO_TIME:
338 uint64_t tm = (uint64_t) (*((double*)arg) * 90000);
339 if(dvdnav_time_search(priv->dvdnav, tm) == DVDNAV_STATUS_OK)
340 return 1;
341 break;
345 return STREAM_UNSUPPORTED;
348 static void identify_chapters(dvdnav_t *nav, uint32_t title)
350 uint64_t *parts=NULL, duration=0;
351 uint32_t n, i, t;
352 n = dvdnav_describe_title_chapters(nav, title, &parts, &duration);
353 if(parts) {
354 t = duration / 90;
355 mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title, t / 1000, t % 1000);
356 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "TITLE %u, CHAPTERS: ", title);
357 for(i=0; i<n; i++) {
358 t = parts[i] / 90000;
359 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "%02d:%02d:%02d,", t/3600, (t/60)%60, t%60);
361 free(parts);
362 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "\n");
366 static void identify(dvdnav_priv_t *priv, struct stream_priv_s *p)
368 uint32_t titles=0, i;
369 if(p->track <= 0) {
370 dvdnav_get_number_of_titles(priv->dvdnav, &titles);
371 for(i=0; i<titles; i++)
372 identify_chapters(priv->dvdnav, i);
374 else
375 identify_chapters(priv->dvdnav, p->track);
378 static void show_audio_subs_languages(dvdnav_t *nav)
380 uint8_t lg;
381 uint16_t i, lang, format, id, channels;
382 int base[6] = {128, 0, 0, 0, 160, 136, 0};
383 char tmp[3];
384 for(i=0; i<8; i++)
386 lg = dvdnav_get_audio_logical_stream(nav, i);
387 if(lg == 0xff) continue;
388 channels = dvdnav_audio_stream_channels(nav, lg);
389 if(channels == 0xFFFF)
390 channels = 2; //unknown
391 else
392 channels--;
393 lang = dvdnav_audio_stream_to_lang(nav, lg);
394 if(lang == 0xFFFF)
395 tmp[0] = tmp[1] = '?';
396 else
398 tmp[0] = lang >> 8;
399 tmp[1] = lang & 0xFF;
401 tmp[2] = 0;
402 format = dvdnav_audio_stream_format(nav, lg);
403 if(format == 0xFFFF || format > 6)
404 format = 1; //unknown
405 id = i + base[format];
406 mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDaudioStreamInfo, i,
407 dvd_audio_stream_types[format], dvd_audio_stream_channels[channels], tmp, id);
410 for(i=0; i<32; i++)
412 lg = dvdnav_get_spu_logical_stream(nav, i);
413 if(lg == 0xff) continue;
414 lang = dvdnav_spu_stream_to_lang(nav, lg);
415 if(lang == 0xFFFF)
416 tmp[0] = tmp[1] = '?';
417 else
419 tmp[0] = lang >> 8;
420 tmp[1] = lang & 0xFF;
422 tmp[2] = 0;
423 mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDsubtitleLanguage, i+0x20, tmp);
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 dvdnav_priv_t *priv;
432 if(p->device) filename = p->device;
433 else if(dvd_device) filename= dvd_device;
434 else filename = DEFAULT_DVD_DEVICE;
435 if(!(priv=new_dvdnav_stream(filename))) {
436 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,filename, strerror(errno));
437 return STREAM_UNSUPPORTED;
440 if(p->track > 0) {
441 if(dvd_chapter > 0 && dvd_last_chapter > 0 && dvd_chapter > dvd_last_chapter) {
442 mp_msg(MSGT_OPEN,MSGL_FATAL,"dvdnav_stream, invalid chapter range: %d > %d\n", dvd_chapter, dvd_last_chapter);
443 return STREAM_UNSUPPORTED;
445 priv->title = p->track;
446 if(dvdnav_title_play(priv->dvdnav, p->track) != DVDNAV_STATUS_OK) {
447 mp_msg(MSGT_OPEN,MSGL_FATAL,"dvdnav_stream, couldn't select title %d, error '%s'\n", p->track, dvdnav_err_to_string(priv->dvdnav));
448 return STREAM_UNSUPPORTED;
450 if(dvd_chapter > 0)
451 dvdnav_part_play(priv->dvdnav, p->track, dvd_chapter);
452 } else if(p->track == -1)
453 dvdnav_menu_call(priv->dvdnav, DVD_MENU_Root);
454 else {
455 mp_msg(MSGT_OPEN,MSGL_INFO,"dvdnav_stream, you didn't specify a track number (as in dvdnav://1), playing whole disc\n");
456 dvdnav_menu_call(priv->dvdnav, DVD_MENU_Title);
458 if(mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
459 identify(priv, p);
460 if(p->track > 0)
461 show_audio_subs_languages(priv->dvdnav);
462 if(dvd_angle > 1)
463 dvdnav_angle_change(priv->dvdnav, dvd_angle);
465 stream->sector_size = 2048;
466 stream->flags = STREAM_READ | STREAM_SEEK;
467 stream->fill_buffer = fill_buffer;
468 stream->seek = seek;
469 stream->control = control;
470 stream->close = stream_dvdnav_close;
471 stream->type = STREAMTYPE_DVDNAV;
472 stream->priv=(void*)priv;
473 *file_format = DEMUXER_TYPE_MPEG_PS;
475 update_title_len(stream);
476 if(!stream->pos)
477 mp_msg(MSGT_OPEN,MSGL_ERR, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv->dvdnav));
479 mp_msg(MSGT_OPEN,MSGL_INFO, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
481 return STREAM_OK;
485 int mp_dvdnav_handle_input(stream_t *stream, int cmd, int *button) {
486 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
487 dvdnav_t *nav = priv->dvdnav;
488 dvdnav_status_t status=DVDNAV_STATUS_ERR;
489 pci_t *pci = dvdnav_get_current_nav_pci(nav);
490 int reset = 0;
492 if(cmd != MP_CMD_DVDNAV_SELECT && !pci)
493 return 0;
495 switch(cmd) {
496 case MP_CMD_DVDNAV_UP:
497 status = dvdnav_upper_button_select(nav, pci);
498 break;
499 case MP_CMD_DVDNAV_DOWN:
500 status = dvdnav_lower_button_select(nav, pci);
501 break;
502 case MP_CMD_DVDNAV_LEFT:
503 status = dvdnav_left_button_select(nav, pci);
504 break;
505 case MP_CMD_DVDNAV_RIGHT:
506 status = dvdnav_right_button_select(nav, pci);
507 break;
508 case MP_CMD_DVDNAV_MENU:
509 status = dvdnav_menu_call(nav,DVD_MENU_Root);
510 reset = 1;
511 break;
512 case MP_CMD_DVDNAV_PREVMENU: {
513 int title=0, part=0;
515 dvdnav_current_title_info(nav, &title, &part);
516 if(title) {
517 if(dvdnav_menu_call(nav, DVD_MENU_Part) == DVDNAV_STATUS_OK
518 || dvdnav_menu_call(nav, DVD_MENU_Title) == DVDNAV_STATUS_OK) {
519 reset = 1;
520 break;
523 if(dvdnav_menu_call(nav, DVD_MENU_Root) == DVDNAV_STATUS_OK)
524 reset = 1;
526 break;
527 case MP_CMD_DVDNAV_SELECT:
528 status = dvdnav_button_activate(nav, pci);
529 if(status == DVDNAV_STATUS_OK) reset = 1;
530 break;
531 case MP_CMD_DVDNAV_MOUSECLICK:
533 this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
534 should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
535 and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
536 the coodinates saved by mp_dvdnav_update_mouse_pos().
537 This last call always works well
539 status = dvdnav_mouse_activate(nav, pci, priv->mousex, priv->mousey);
540 if(status == DVDNAV_STATUS_OK) reset = 1;
541 break;
542 default:
543 mp_msg(MSGT_CPLAYER, MSGL_V, "Unknown DVDNAV cmd %d\n", cmd);
544 break;
547 if(status == DVDNAV_STATUS_OK)
548 dvdnav_get_current_highlight(nav, button);
550 return reset;
553 void mp_dvdnav_update_mouse_pos(stream_t *stream, int32_t x, int32_t y, int* button) {
554 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
555 dvdnav_t *nav = priv->dvdnav;
556 dvdnav_status_t status;
557 pci_t *pci = dvdnav_get_current_nav_pci(nav);
559 if(!pci) return;
561 status = dvdnav_mouse_select(nav, pci, x, y);
562 if(status == DVDNAV_STATUS_OK) dvdnav_get_current_highlight(nav, button);
563 else *button = -1;
564 priv->mousex = x;
565 priv->mousey = y;
569 * \brief dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
570 * \param stream: - stream pointer
571 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
572 * \return -1 on error, current subtitle id if successful
574 int dvdnav_aid_from_lang(stream_t *stream, unsigned char *language) {
575 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
576 int k;
577 uint8_t format, lg;
578 uint16_t lang, lcode;;
580 while(language && strlen(language)>=2) {
581 lcode = (language[0] << 8) | (language[1]);
582 for(k=0; k<32; k++) {
583 lg = dvdnav_get_audio_logical_stream(priv->dvdnav, k);
584 if(lg == 0xff) continue;
585 lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
586 if(lang != 0xFFFF && lang == lcode) {
587 format = dvdnav_audio_stream_format(priv->dvdnav, lg);
588 switch(format) {
589 case DVDNAV_FORMAT_AC3:
590 return k+128;
591 case DVDNAV_FORMAT_DTS:
592 return k+136;
593 case DVDNAV_FORMAT_LPCM:
594 return k+160;
595 case DVDNAV_FORMAT_MPEGAUDIO:
596 return k;
597 default:
598 return -1;
602 language += 2;
603 while(language[0]==',' || language[0]==' ') ++language;
605 return -1;
609 * \brief dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
610 * \param stream: - stream pointer
611 * \param sid: physical subtitle id
612 * \param buf: buffer to contain the 2-chars language string
613 * \return 0 on error, 1 if successful
615 int dvdnav_lang_from_aid(stream_t *stream, int aid, unsigned char *buf) {
616 uint8_t lg;
617 uint16_t lang;
618 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
620 if(aid < 0)
621 return 0;
622 lg = dvdnav_get_audio_logical_stream(priv->dvdnav, aid & 0x7);
623 if(lg == 0xff) return 0;
624 lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
625 if(lang == 0xffff) return 0;
626 buf[0] = lang >> 8;
627 buf[1] = lang & 0xFF;
628 buf[2] = 0;
629 return 1;
634 * \brief dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
635 * \param stream: - stream pointer
636 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
637 * \return -1 on error, current subtitle id if successful
639 int dvdnav_sid_from_lang(stream_t *stream, unsigned char *language) {
640 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
641 uint8_t lg, k;
642 uint16_t lang, lcode;
644 while(language && strlen(language)>=2) {
645 lcode = (language[0] << 8) | (language[1]);
646 for(k=0; k<32; k++) {
647 lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
648 if(lg == 0xff) continue;
649 lang = dvdnav_spu_stream_to_lang(priv->dvdnav, lg);
650 if(lang != 0xFFFF && lang == lcode) {
651 return k;
654 language += 2;
655 while(language[0]==',' || language[0]==' ') ++language;
657 return -1;
661 * \brief dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
662 * \param stream: - stream pointer
663 * \param sid: physical subtitle id
664 * \param buf: buffer to contain the 2-chars language string
665 * \return 0 on error, 1 if successful
667 int dvdnav_lang_from_sid(stream_t *stream, int sid, unsigned char *buf) {
668 uint8_t lg;
669 uint16_t lang;
670 dvdnav_priv_t *priv=(dvdnav_priv_t*)stream->priv;
671 if(sid < 0) return 0;
672 lg = dvdnav_get_spu_logical_stream(priv->dvdnav, sid);
673 lang = dvdnav_spu_stream_to_lang(priv->dvdnav, lg);
674 if(lang == 0xffff) return 0;
675 buf[0] = lang >> 8;
676 buf[1] = lang & 0xFF;
677 buf[2] = 0;
678 return 1;
682 * \brief dvdnav_number_of_subs() returns the count of available subtitles
683 * \param stream: - stream pointer
684 * \return 0 on error, something meaningful otherwise
686 int dvdnav_number_of_subs(stream_t *stream) {
687 dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
688 uint8_t lg, k, n=0;
690 for(k=0; k<32; k++) {
691 lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
692 if(lg == 0xff) continue;
693 n++;
695 return n;
699 * \brief mp_dvdnav_get_spu_clut() returns the spu clut
700 * \param stream: - stream pointer
701 * \return spu clut pointer
703 unsigned int *mp_dvdnav_get_spu_clut(stream_t *stream) {
704 dvdnav_priv_t *priv=(dvdnav_priv_t*)stream->priv;
705 if(!priv->spu_set) return NULL;
706 return priv->spu_clut;
710 * \brief mp_dvdnav_get_highlight() get dvdnav highlight struct
711 * \param stream: - stream pointer
712 * \param hl : - highlight struct pointer
714 void mp_dvdnav_get_highlight (stream_t *stream, nav_highlight_t *hl) {
715 dvdnav_priv_t *priv = (dvdnav_priv_t *) stream->priv;
716 dvdnav_highlight_event_t hlev = priv->hlev;
718 hl->sx = hlev.sx;
719 hl->sy = hlev.sy;
720 hl->ex = hlev.ex;
721 hl->ey = hlev.ey;
724 const stream_info_t stream_info_dvdnav = {
725 "DVDNAV stream",
726 "null",
729 open_s,
730 { "dvdnav", NULL },
731 &stream_opts,
732 1 // Urls are an option string