9 #include "osdep/timer.h"
10 #include "input/input.h"
12 #include "libmpdemux/demuxer.h"
13 #include <dvdnav/dvdnav.h>
14 #include "stream_dvdnav.h"
15 #include "libvo/video_out.h"
16 #include "libavutil/common.h"
21 #include "stream_dvd_common.h"
25 NAV_FLAG_EOF
= 1 << 0, /* end of stream has been reached */
26 NAV_FLAG_WAIT
= 1 << 1, /* wait event */
27 NAV_FLAG_WAIT_SKIP
= 1 << 2, /* wait skip disable */
28 NAV_FLAG_CELL_CHANGE
= 1 << 3, /* cell change event */
29 NAV_FLAG_WAIT_READ_AUTO
= 1 << 4, /* wait read auto mode */
30 NAV_FLAG_WAIT_READ
= 1 << 5, /* suspend read from stream */
31 NAV_FLAG_VTS_DOMAIN
= 1 << 6, /* vts domain */
32 NAV_FLAG_SPU_SET
= 1 << 7, /* spu_clut is valid */
33 NAV_FLAG_STREAM_CHANGE
= 1 << 8, /* title, chapter, audio or SPU */
34 NAV_FLAG_AUDIO_CHANGE
= 1 << 9, /* audio stream change event */
35 NAV_FLAG_SPU_CHANGE
= 1 << 10, /* spu stream change event */
39 dvdnav_t
* dvdnav
; /* handle to libdvdnav stuff */
40 char * filename
; /* path */
41 unsigned int duration
; /* in milliseconds */
44 unsigned int spu_clut
[16];
45 dvdnav_highlight_event_t hlev
;
46 int still_length
; /* still frame duration */
50 extern char *dvd_device
;
51 extern char *audio_lang
, *dvdsub_lang
;
52 extern char *dvd_audio_stream_channels
[6], *dvd_audio_stream_types
[8];
54 static struct stream_priv_s
{
57 } stream_priv_dflts
= {
62 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
64 static const m_option_t stream_opts_fields
[] = {
65 {"filename", ST_OFF(device
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
66 {"hostname", ST_OFF(track
), CONF_TYPE_INT
, M_OPT_RANGE
, 1, 99, NULL
},
67 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
69 static const struct m_struct_st stream_opts
= {
71 sizeof(struct stream_priv_s
),
76 static int seek(stream_t
*s
, off_t newpos
);
77 static void show_audio_subs_languages(dvdnav_t
*nav
);
79 static dvdnav_priv_t
* new_dvdnav_stream(char * filename
) {
80 const char * title_str
;
86 if (!(priv
=calloc(1,sizeof(dvdnav_priv_t
))))
89 if (!(priv
->filename
=strdup(filename
))) {
94 if(dvdnav_open(&(priv
->dvdnav
),priv
->filename
)!=DVDNAV_STATUS_OK
)
106 if(1) //from vlc: if not used dvdnav from cvs will fail
111 dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,&len
);
112 dvdnav_sector_search(priv
->dvdnav
, 0, SEEK_SET
);
115 /* turn off dvdnav caching */
116 dvdnav_set_readahead_flag(priv
->dvdnav
, 0);
117 if(dvdnav_set_PGC_positioning_flag(priv
->dvdnav
, 1) != DVDNAV_STATUS_OK
)
118 mp_msg(MSGT_OPEN
,MSGL_ERR
,"stream_dvdnav, failed to set PGC positioning\n");
120 /* report the title?! */
121 if (dvdnav_get_title_string(priv
->dvdnav
,&title_str
)==DVDNAV_STATUS_OK
) {
122 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
,"Title: '%s'\n",title_str
);
126 //dvdnav_event_clear(priv);
131 static void dvdnav_get_highlight (dvdnav_priv_t
*priv
, int display_mode
) {
132 pci_t
*pnavpci
= NULL
;
133 dvdnav_highlight_event_t
*hlev
= &(priv
->hlev
);
136 if (!priv
|| !priv
->dvdnav
)
139 pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
143 dvdnav_get_current_highlight (priv
->dvdnav
, &(hlev
->buttonN
));
144 hlev
->display
= display_mode
; /* show */
146 if (hlev
->buttonN
> 0 && pnavpci
->hli
.hl_gi
.btn_ns
> 0 && hlev
->display
) {
147 for (btnum
= 0; btnum
< pnavpci
->hli
.hl_gi
.btn_ns
; btnum
++) {
148 btni_t
*btni
= &(pnavpci
->hli
.btnit
[btnum
]);
150 if (hlev
->buttonN
== btnum
+ 1) {
151 hlev
->sx
= FFMIN (btni
->x_start
, btni
->x_end
);
152 hlev
->ex
= FFMAX (btni
->x_start
, btni
->x_end
);
153 hlev
->sy
= FFMIN (btni
->y_start
, btni
->y_end
);
154 hlev
->ey
= FFMAX (btni
->y_start
, btni
->y_end
);
156 hlev
->palette
= (btni
->btn_coln
== 0) ? 0 :
157 pnavpci
->hli
.btn_colit
.btn_coli
[btni
->btn_coln
- 1][0];
161 } else { /* hide button or no button */
162 hlev
->sx
= hlev
->ex
= 0;
163 hlev
->sy
= hlev
->ey
= 0;
164 hlev
->palette
= hlev
->buttonN
= 0;
168 static inline int dvdnav_get_duration (int length
) {
169 return (length
== 255) ? 0 : length
* 1000;
172 static int dvdnav_stream_read(dvdnav_priv_t
* priv
, unsigned char *buf
, int *len
) {
173 int event
= DVDNAV_NOP
;
176 if (dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,len
)!=DVDNAV_STATUS_OK
) {
177 mp_msg(MSGT_OPEN
,MSGL_V
, "Error getting next block from DVD %d (%s)\n",event
, dvdnav_err_to_string(priv
->dvdnav
) );
180 else if (event
!=DVDNAV_BLOCK_OK
) {
181 // need to handle certain events internally (like skipping stills)
183 case DVDNAV_NAV_PACKET
:
185 case DVDNAV_STILL_FRAME
: {
186 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*) buf
;
187 priv
->still_length
= still_event
->length
;
188 /* set still frame duration */
189 priv
->duration
= dvdnav_get_duration (priv
->still_length
);
190 if (priv
->still_length
<= 1) {
191 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
192 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
196 case DVDNAV_HIGHLIGHT
: {
197 dvdnav_get_highlight (priv
, 1);
200 case DVDNAV_CELL_CHANGE
: {
201 dvdnav_cell_change_event_t
*ev
= (dvdnav_cell_change_event_t
*)buf
;
204 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
205 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
207 priv
->duration
= ev
->pgc_length
/90;
209 if (dvdnav_is_domain_vts(priv
->dvdnav
)) {
210 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MOVIE\n");
211 priv
->state
&= ~NAV_FLAG_VTS_DOMAIN
;
213 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MENU\n");
214 priv
->state
|= NAV_FLAG_VTS_DOMAIN
;
217 nextstill
= dvdnav_get_next_still_flag (priv
->dvdnav
);
219 priv
->duration
= dvdnav_get_duration (nextstill
);
220 priv
->still_length
= nextstill
;
221 if (priv
->still_length
<= 1) {
222 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
223 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
229 case DVDNAV_SPU_CLUT_CHANGE
: {
230 memcpy(priv
->spu_clut
, buf
, 16*sizeof(unsigned int));
231 priv
->state
|= NAV_FLAG_SPU_SET
;
235 if ((priv
->state
& NAV_FLAG_WAIT_SKIP
) &&
236 !(priv
->state
& NAV_FLAG_WAIT
))
237 dvdnav_wait_skip (priv
->dvdnav
);
239 priv
->state
|= NAV_FLAG_WAIT
;
242 case DVDNAV_VTS_CHANGE
: {
243 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
244 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
247 case DVDNAV_SPU_STREAM_CHANGE
: {
248 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
258 static void update_title_len(stream_t
*stream
) {
259 dvdnav_priv_t
*priv
= stream
->priv
;
260 dvdnav_status_t status
;
261 uint32_t pos
= 0, len
= 0;
263 status
= dvdnav_get_position(priv
->dvdnav
, &pos
, &len
);
264 if(status
== DVDNAV_STATUS_OK
&& len
) {
265 stream
->end_pos
= (off_t
) len
* 2048;
274 static int seek(stream_t
*s
, off_t newpos
) {
276 dvdnav_priv_t
*priv
= s
->priv
;
278 if(s
->end_pos
&& newpos
> s
->end_pos
)
280 sector
= newpos
/ 2048ULL;
281 if(dvdnav_sector_search(priv
->dvdnav
, (uint64_t) sector
, SEEK_SET
) != DVDNAV_STATUS_OK
)
289 mp_msg(MSGT_STREAM
,MSGL_INFO
,"dvdnav_stream, seeking to %"PRIu64
" failed: %s\n", newpos
, dvdnav_err_to_string(priv
->dvdnav
));
294 static void stream_dvdnav_close(stream_t
*s
) {
295 dvdnav_priv_t
*priv
= s
->priv
;
296 dvdnav_close(priv
->dvdnav
);
302 static int fill_buffer(stream_t
*s
, char *but
, int len
)
306 dvdnav_priv_t
* priv
=s
->priv
;
307 if (priv
->state
& NAV_FLAG_WAIT_READ
) /* read is suspended */
312 while(!len
) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
314 event
=dvdnav_stream_read(priv
, s
->buffer
, &len
);
315 if(event
==-1 || len
==-1)
317 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "DVDNAV stream read error!\n");
320 if (event
!= DVDNAV_BLOCK_OK
)
321 dvdnav_get_highlight (priv
, 1);
324 priv
->state
|= NAV_FLAG_EOF
;
327 case DVDNAV_BLOCK_OK
:
328 case DVDNAV_NAV_PACKET
:
329 case DVDNAV_STILL_FRAME
:
332 if (priv
->state
& NAV_FLAG_WAIT
)
336 case DVDNAV_VTS_CHANGE
: {
337 int tit
= 0, part
= 0;
338 dvdnav_vts_change_event_t
*vts_event
= (dvdnav_vts_change_event_t
*)s
->buffer
;
339 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "DVDNAV, switched to title: %d\r\n", vts_event
->new_vtsN
);
340 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
341 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
342 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
343 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
344 priv
->state
&= ~NAV_FLAG_WAIT
;
347 show_audio_subs_languages(priv
->dvdnav
);
348 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
349 priv
->state
|= NAV_FLAG_WAIT_READ
;
350 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
) {
351 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nDVDNAV, NEW TITLE %d\r\n", tit
);
352 dvdnav_get_highlight (priv
, 0);
353 if(priv
->title
> 0 && tit
!= priv
->title
)
358 case DVDNAV_CELL_CHANGE
: {
359 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
360 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
361 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
362 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
363 priv
->state
&= ~NAV_FLAG_WAIT
;
364 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
365 priv
->state
|= NAV_FLAG_WAIT_READ
;
366 if(priv
->title
> 0 && dvd_last_chapter
> 0) {
368 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
&& part
> dvd_last_chapter
)
371 dvdnav_get_highlight (priv
, 1);
374 case DVDNAV_AUDIO_STREAM_CHANGE
:
375 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
377 case DVDNAV_SPU_STREAM_CHANGE
:
378 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
382 mp_msg(MSGT_STREAM
,MSGL_DBG2
,"DVDNAV fill_buffer len: %d\n",len
);
386 static int control(stream_t
*stream
, int cmd
, void* arg
) {
387 dvdnav_priv_t
* priv
=stream
->priv
;
392 case STREAM_CTRL_SEEK_TO_CHAPTER
:
394 int chap
= *((unsigned int *)arg
)+1;
396 if(chap
< 1 || dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
398 if(dvdnav_part_play(priv
->dvdnav
, tit
, chap
) != DVDNAV_STATUS_OK
)
402 case STREAM_CTRL_GET_NUM_CHAPTERS
:
404 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
406 if(dvdnav_get_number_of_parts(priv
->dvdnav
, tit
, &part
) != DVDNAV_STATUS_OK
)
410 *((unsigned int *)arg
) = part
;
413 case STREAM_CTRL_GET_CURRENT_CHAPTER
:
415 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
417 *((unsigned int *)arg
) = part
- 1;
420 case STREAM_CTRL_GET_TIME_LENGTH
:
422 if(priv
->duration
|| priv
->still_length
)
424 *((double *)arg
) = (double)priv
->duration
/ 1000.0;
429 case STREAM_CTRL_GET_ASPECT_RATIO
:
431 uint8_t ar
= dvdnav_get_video_aspect(priv
->dvdnav
);
432 *((double *)arg
) = !ar
? 4.0/3.0 : 16.0/9.0;
435 case STREAM_CTRL_GET_CURRENT_TIME
:
438 tm
= dvdnav_get_current_time(priv
->dvdnav
)/90000.0f
;
441 *((double *)arg
) = tm
;
446 case STREAM_CTRL_SEEK_TO_TIME
:
448 uint64_t tm
= (uint64_t) (*((double*)arg
) * 90000);
449 if(dvdnav_time_search(priv
->dvdnav
, tm
) == DVDNAV_STATUS_OK
)
453 case STREAM_CTRL_GET_NUM_ANGLES
:
455 uint32_t curr
, angles
;
456 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
458 *((int *)arg
) = angles
;
461 case STREAM_CTRL_GET_ANGLE
:
463 uint32_t curr
, angles
;
464 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
466 *((int *)arg
) = curr
;
469 case STREAM_CTRL_SET_ANGLE
:
471 uint32_t curr
, angles
;
472 int new_angle
= *((int *)arg
);
473 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
475 if(new_angle
>angles
|| new_angle
<1)
477 if(dvdnav_angle_change(priv
->dvdnav
, new_angle
) != DVDNAV_STATUS_OK
)
482 return STREAM_UNSUPPORTED
;
485 static void identify_chapters(dvdnav_t
*nav
, uint32_t title
)
487 uint64_t *parts
=NULL
, duration
=0;
489 n
= dvdnav_describe_title_chapters(nav
, title
, &parts
, &duration
);
492 mp_msg(MSGT_IDENTIFY
, MSGL_V
, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title
, t
/ 1000, t
% 1000);
493 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "TITLE %u, CHAPTERS: ", title
);
495 t
= parts
[i
] / 90000;
496 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "%02d:%02d:%02d,", t
/3600, (t
/60)%60, t
%60);
499 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "\n");
503 static void identify(dvdnav_priv_t
*priv
, struct stream_priv_s
*p
)
505 uint32_t titles
=0, i
;
507 dvdnav_get_number_of_titles(priv
->dvdnav
, &titles
);
508 for(i
=0; i
<titles
; i
++)
509 identify_chapters(priv
->dvdnav
, i
);
512 identify_chapters(priv
->dvdnav
, p
->track
);
515 static void show_audio_subs_languages(dvdnav_t
*nav
)
518 uint16_t i
, lang
, format
, id
, channels
;
519 int base
[7] = {128, 0, 0, 0, 160, 136, 0};
523 lg
= dvdnav_get_audio_logical_stream(nav
, i
);
524 if(lg
== 0xff) continue;
525 channels
= dvdnav_audio_stream_channels(nav
, lg
);
526 if(channels
== 0xFFFF)
527 channels
= 2; //unknown
530 lang
= dvdnav_audio_stream_to_lang(nav
, lg
);
532 tmp
[0] = tmp
[1] = '?';
536 tmp
[1] = lang
& 0xFF;
539 format
= dvdnav_audio_stream_format(nav
, lg
);
540 if(format
== 0xFFFF || format
> 6)
541 format
= 1; //unknown
542 id
= i
+ base
[format
];
543 if (lang
!= 0xFFFF) {
544 mp_tmsg(MSGT_OPEN
,MSGL_STATUS
,"audio stream: %d format: %s (%s) language: %s aid: %d.\n", i
,
545 dvd_audio_stream_types
[format
], dvd_audio_stream_channels
[channels
], tmp
, id
);
547 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AID_%d_LANG=%s\n", id
, tmp
);
553 lg
= dvdnav_get_spu_logical_stream(nav
, i
);
554 if(lg
== 0xff) continue;
555 lang
= dvdnav_spu_stream_to_lang(nav
, lg
);
557 tmp
[0] = tmp
[1] = '?';
561 tmp
[1] = lang
& 0xFF;
565 mp_tmsg(MSGT_OPEN
,MSGL_STATUS
,"subtitle ( sid ): %d language: %s\n", i
+0x20, tmp
);
569 static int open_s(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
570 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
574 if(p
->device
) filename
= p
->device
;
575 else if(dvd_device
) filename
= dvd_device
;
576 else filename
= DEFAULT_DVD_DEVICE
;
577 if(!(priv
=new_dvdnav_stream(filename
))) {
578 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Couldn't open DVD device: %s (%s)\n",filename
, strerror(errno
));
579 return STREAM_UNSUPPORTED
;
583 priv
->title
= p
->track
;
584 if(dvdnav_title_play(priv
->dvdnav
, p
->track
) != DVDNAV_STATUS_OK
) {
585 mp_msg(MSGT_OPEN
,MSGL_FATAL
,"dvdnav_stream, couldn't select title %d, error '%s'\n", p
->track
, dvdnav_err_to_string(priv
->dvdnav
));
586 return STREAM_UNSUPPORTED
;
588 } else if (p
->track
== 0) {
589 if(dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Root
) != DVDNAV_STATUS_OK
)
590 dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Title
);
592 if(mp_msg_test(MSGT_IDENTIFY
, MSGL_INFO
))
595 show_audio_subs_languages(priv
->dvdnav
);
597 dvdnav_angle_change(priv
->dvdnav
, dvd_angle
);
599 stream
->sector_size
= 2048;
600 stream
->flags
= STREAM_READ
| STREAM_SEEK
;
601 stream
->fill_buffer
= fill_buffer
;
603 stream
->control
= control
;
604 stream
->close
= stream_dvdnav_close
;
605 stream
->type
= STREAMTYPE_DVDNAV
;
606 stream
->priv
=(void*)priv
;
607 *file_format
= DEMUXER_TYPE_MPEG_PS
;
609 update_title_len(stream
);
610 if(!stream
->pos
&& p
->track
> 0)
611 mp_msg(MSGT_OPEN
,MSGL_ERR
, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv
->dvdnav
));
613 mp_msg(MSGT_OPEN
,MSGL_INFO
, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
619 void mp_dvdnav_handle_input(stream_t
*stream
, int cmd
, int *button
) {
620 dvdnav_priv_t
* priv
= stream
->priv
;
621 dvdnav_t
*nav
= priv
->dvdnav
;
622 dvdnav_status_t status
=DVDNAV_STATUS_ERR
;
623 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
625 if(cmd
!= MP_CMD_DVDNAV_SELECT
&& !pci
)
629 case MP_CMD_DVDNAV_UP
:
630 status
= dvdnav_upper_button_select(nav
, pci
);
632 case MP_CMD_DVDNAV_DOWN
:
633 status
= dvdnav_lower_button_select(nav
, pci
);
635 case MP_CMD_DVDNAV_LEFT
:
636 status
= dvdnav_left_button_select(nav
, pci
);
638 case MP_CMD_DVDNAV_RIGHT
:
639 status
= dvdnav_right_button_select(nav
, pci
);
641 case MP_CMD_DVDNAV_MENU
:
642 status
= dvdnav_menu_call(nav
,DVD_MENU_Root
);
644 case MP_CMD_DVDNAV_PREVMENU
: {
647 dvdnav_current_title_info(nav
, &title
, &part
);
649 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Part
)) == DVDNAV_STATUS_OK
)
652 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Title
)) == DVDNAV_STATUS_OK
)
654 status
=dvdnav_menu_call(nav
, DVD_MENU_Root
);
657 case MP_CMD_DVDNAV_SELECT
:
658 status
= dvdnav_button_activate(nav
, pci
);
660 case MP_CMD_DVDNAV_MOUSECLICK
:
662 this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
663 should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
664 and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
665 the coodinates saved by mp_dvdnav_update_mouse_pos().
666 This last call always works well
668 status
= dvdnav_mouse_activate(nav
, pci
, priv
->mousex
, priv
->mousey
);
671 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Unknown DVDNAV cmd %d\n", cmd
);
675 if(status
== DVDNAV_STATUS_OK
)
676 dvdnav_get_current_highlight(nav
, button
);
679 void mp_dvdnav_update_mouse_pos(stream_t
*stream
, int32_t x
, int32_t y
, int* button
) {
680 dvdnav_priv_t
* priv
= stream
->priv
;
681 dvdnav_t
*nav
= priv
->dvdnav
;
682 dvdnav_status_t status
;
683 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
687 status
= dvdnav_mouse_select(nav
, pci
, x
, y
);
688 if(status
== DVDNAV_STATUS_OK
) dvdnav_get_current_highlight(nav
, button
);
694 static int mp_dvdnav_get_aid_from_format (stream_t
*stream
, int index
, uint8_t lg
) {
695 dvdnav_priv_t
* priv
= stream
->priv
;
698 format
= dvdnav_audio_stream_format(priv
->dvdnav
, lg
);
700 case DVDNAV_FORMAT_AC3
:
701 return (index
+ 128);
702 case DVDNAV_FORMAT_DTS
:
703 return (index
+ 136);
704 case DVDNAV_FORMAT_LPCM
:
705 return (index
+ 160);
706 case DVDNAV_FORMAT_MPEGAUDIO
:
716 * \brief mp_dvdnav_aid_from_audio_num() returns the audio id corresponding to the logical number
717 * \param stream: - stream pointer
718 * \param audio_num: - logical number
719 * \return -1 on error, current subtitle id if successful
721 int mp_dvdnav_aid_from_audio_num(stream_t
*stream
, int audio_num
) {
722 dvdnav_priv_t
* priv
= stream
->priv
;
726 for(k
=0; k
<32; k
++) {
727 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
728 if (lg
== 0xff) continue;
729 if (lg
!= audio_num
) continue;
731 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
737 * \brief mp_dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
738 * \param stream: - stream pointer
739 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
740 * \return -1 on error, current subtitle id if successful
742 int mp_dvdnav_aid_from_lang(stream_t
*stream
, unsigned char *language
) {
743 dvdnav_priv_t
* priv
= stream
->priv
;
746 uint16_t lang
, lcode
;
748 while(language
&& strlen(language
)>=2) {
749 lcode
= (language
[0] << 8) | (language
[1]);
750 for(k
=0; k
<32; k
++) {
751 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
752 if(lg
== 0xff) continue;
753 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
754 if(lang
!= 0xFFFF && lang
== lcode
)
755 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
758 while(language
[0]==',' || language
[0]==' ') ++language
;
764 * \brief mp_dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
765 * \param stream: - stream pointer
766 * \param sid: physical subtitle id
767 * \param buf: buffer to contain the 2-chars language string
768 * \return 0 on error, 1 if successful
770 int mp_dvdnav_lang_from_aid(stream_t
*stream
, int aid
, unsigned char *buf
) {
773 dvdnav_priv_t
* priv
= stream
->priv
;
777 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, aid
& 0x7);
778 if(lg
== 0xff) return 0;
779 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
780 if(lang
== 0xffff) return 0;
782 buf
[1] = lang
& 0xFF;
789 * \brief mp_dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
790 * \param stream: - stream pointer
791 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
792 * \return -1 on error, current subtitle id if successful
794 int mp_dvdnav_sid_from_lang(stream_t
*stream
, unsigned char *language
) {
795 dvdnav_priv_t
* priv
= stream
->priv
;
797 uint16_t lang
, lcode
;
799 while(language
&& strlen(language
)>=2) {
800 lcode
= (language
[0] << 8) | (language
[1]);
801 for(k
=0; k
<32; k
++) {
802 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
803 if(lg
== 0xff) continue;
804 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, lg
);
805 if(lang
!= 0xFFFF && lang
== lcode
) {
810 while(language
[0]==',' || language
[0]==' ') ++language
;
816 * \brief mp_dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
817 * \param stream: - stream pointer
818 * \param sid: physical subtitle id
819 * \param buf: buffer to contain the 2-chars language string
820 * \return 0 on error, 1 if successful
822 int mp_dvdnav_lang_from_sid(stream_t
*stream
, int sid
, unsigned char *buf
) {
825 dvdnav_priv_t
*priv
= stream
->priv
;
826 if(sid
< 0) return 0;
827 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, sid
);
828 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, lg
);
829 if(lang
== 0xffff) return 0;
831 buf
[1] = lang
& 0xFF;
837 * \brief mp_dvdnav_number_of_subs() returns the count of available subtitles
838 * \param stream: - stream pointer
839 * \return 0 on error, something meaningful otherwise
841 int mp_dvdnav_number_of_subs(stream_t
*stream
) {
842 dvdnav_priv_t
* priv
= stream
->priv
;
845 if (priv
->state
& NAV_FLAG_VTS_DOMAIN
) return 0;
846 for(k
=0; k
<32; k
++) {
847 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
848 if(lg
== 0xff) continue;
855 * \brief mp_dvdnav_get_spu_clut() returns the spu clut
856 * \param stream: - stream pointer
857 * \return spu clut pointer
859 unsigned int *mp_dvdnav_get_spu_clut(stream_t
*stream
) {
860 dvdnav_priv_t
*priv
= stream
->priv
;
861 return (priv
->state
& NAV_FLAG_SPU_SET
) ? priv
->spu_clut
: NULL
;
865 * \brief mp_dvdnav_get_highlight() get dvdnav highlight struct
866 * \param stream: - stream pointer
867 * \param hl : - highlight struct pointer
869 void mp_dvdnav_get_highlight (stream_t
*stream
, nav_highlight_t
*hl
) {
870 dvdnav_priv_t
*priv
= stream
->priv
;
871 dvdnav_highlight_event_t hlev
= priv
->hlev
;
877 hl
->palette
= hlev
.palette
;
880 void mp_dvdnav_switch_title (stream_t
*stream
, int title
) {
881 dvdnav_priv_t
*priv
= stream
->priv
;
884 dvdnav_get_number_of_titles (priv
->dvdnav
, &titles
);
885 if (title
> 0 && title
<= titles
)
886 dvdnav_title_play (priv
->dvdnav
, title
);
890 * \brief Check if end of stream has been reached
891 * \param stream: - stream pointer
892 * \return 1 on really eof
894 int mp_dvdnav_is_eof (stream_t
*stream
) {
895 return ((dvdnav_priv_t
*) stream
->priv
)->state
& NAV_FLAG_EOF
;
899 * \brief Skip still frame
900 * \param stream: - stream pointer
901 * \return 0 on success
903 int mp_dvdnav_skip_still (stream_t
*stream
) {
904 dvdnav_priv_t
*priv
= stream
->priv
;
905 if (priv
->still_length
== 0xff)
907 dvdnav_still_skip(priv
->dvdnav
);
912 * \brief Skip wait event
913 * \param stream: - stream pointer
914 * \return 0 on success
916 int mp_dvdnav_skip_wait (stream_t
*stream
) {
917 dvdnav_priv_t
*priv
= stream
->priv
;
918 if (!(priv
->state
& NAV_FLAG_WAIT
))
920 priv
->state
&= ~NAV_FLAG_WAIT
;
921 dvdnav_wait_skip(priv
->dvdnav
);
926 * \brief Set wait mode
927 * \param stream : - stream pointer
928 * \param mode : - if true, then suspend block read
929 * \param automode: - if true, then VTS or cell change set wait mode
931 void mp_dvdnav_read_wait (stream_t
*stream
, int mode
, int automode
) {
932 dvdnav_priv_t
*priv
= stream
->priv
;
934 priv
->state
&= ~NAV_FLAG_WAIT_READ
;
936 priv
->state
|= NAV_FLAG_WAIT_READ
;
938 priv
->state
&= ~NAV_FLAG_WAIT_READ_AUTO
;
940 priv
->state
|= NAV_FLAG_WAIT_READ_AUTO
;
944 * \brief Check if cell has changed
945 * \param stream: - stream pointer
946 * \param clear : - if true, then clear cell change flag
947 * \return 1 if cell has changed
949 int mp_dvdnav_cell_has_changed (stream_t
*stream
, int clear
) {
950 dvdnav_priv_t
*priv
= stream
->priv
;
951 if (!(priv
->state
& NAV_FLAG_CELL_CHANGE
))
954 priv
->state
&= ~NAV_FLAG_CELL_CHANGE
;
955 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
961 * \brief Check if audio has changed
962 * \param stream: - stream pointer
963 * \param clear : - if true, then clear audio change flag
964 * \return 1 if audio has changed
966 int mp_dvdnav_audio_has_changed (stream_t
*stream
, int clear
) {
967 dvdnav_priv_t
*priv
= stream
->priv
;
969 if (!(priv
->state
& NAV_FLAG_AUDIO_CHANGE
))
973 priv
->state
&= ~NAV_FLAG_AUDIO_CHANGE
;
979 * \brief Check if SPU has changed
980 * \param stream: - stream pointer
981 * \param clear : - if true, then clear spu change flag
982 * \return 1 if spu has changed
984 int mp_dvdnav_spu_has_changed (stream_t
*stream
, int clear
) {
985 dvdnav_priv_t
*priv
= stream
->priv
;
987 if (!(priv
->state
& NAV_FLAG_SPU_CHANGE
))
991 priv
->state
&= ~NAV_FLAG_SPU_CHANGE
;
996 /* Notify if something has changed in stream
997 * Can be related to title, chapter, audio or SPU
999 int mp_dvdnav_stream_has_changed (stream_t
*stream
) {
1000 dvdnav_priv_t
*priv
= stream
->priv
;
1002 if (!(priv
->state
& NAV_FLAG_STREAM_CHANGE
))
1005 priv
->state
&= ~NAV_FLAG_STREAM_CHANGE
;
1009 const stream_info_t stream_info_dvdnav
= {
1017 1 // Urls are an option string