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
);
78 static dvdnav_priv_t
* new_dvdnav_stream(char * filename
) {
79 const char * title_str
;
85 if (!(priv
=calloc(1,sizeof(dvdnav_priv_t
))))
88 if (!(priv
->filename
=strdup(filename
))) {
93 if(dvdnav_open(&(priv
->dvdnav
),priv
->filename
)!=DVDNAV_STATUS_OK
)
105 if(1) //from vlc: if not used dvdnav from cvs will fail
110 dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,&len
);
111 dvdnav_sector_search(priv
->dvdnav
, 0, SEEK_SET
);
114 /* turn off dvdnav caching */
115 dvdnav_set_readahead_flag(priv
->dvdnav
, 0);
116 if(dvdnav_set_PGC_positioning_flag(priv
->dvdnav
, 1) != DVDNAV_STATUS_OK
)
117 mp_msg(MSGT_OPEN
,MSGL_ERR
,"stream_dvdnav, failed to set PGC positioning\n");
119 /* report the title?! */
120 if (dvdnav_get_title_string(priv
->dvdnav
,&title_str
)==DVDNAV_STATUS_OK
) {
121 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
,"Title: '%s'\n",title_str
);
125 //dvdnav_event_clear(priv);
130 static void dvdnav_get_highlight (dvdnav_priv_t
*priv
, int display_mode
) {
131 pci_t
*pnavpci
= NULL
;
132 dvdnav_highlight_event_t
*hlev
= &(priv
->hlev
);
135 if (!priv
|| !priv
->dvdnav
)
138 pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
142 dvdnav_get_current_highlight (priv
->dvdnav
, &(hlev
->buttonN
));
143 hlev
->display
= display_mode
; /* show */
145 if (hlev
->buttonN
> 0 && pnavpci
->hli
.hl_gi
.btn_ns
> 0 && hlev
->display
) {
146 for (btnum
= 0; btnum
< pnavpci
->hli
.hl_gi
.btn_ns
; btnum
++) {
147 btni_t
*btni
= &(pnavpci
->hli
.btnit
[btnum
]);
149 if (hlev
->buttonN
== btnum
+ 1) {
150 hlev
->sx
= FFMIN (btni
->x_start
, btni
->x_end
);
151 hlev
->ex
= FFMAX (btni
->x_start
, btni
->x_end
);
152 hlev
->sy
= FFMIN (btni
->y_start
, btni
->y_end
);
153 hlev
->ey
= FFMAX (btni
->y_start
, btni
->y_end
);
155 hlev
->palette
= (btni
->btn_coln
== 0) ? 0 :
156 pnavpci
->hli
.btn_colit
.btn_coli
[btni
->btn_coln
- 1][0];
160 } else { /* hide button or no button */
161 hlev
->sx
= hlev
->ex
= 0;
162 hlev
->sy
= hlev
->ey
= 0;
163 hlev
->palette
= hlev
->buttonN
= 0;
167 static inline int dvdnav_get_duration (int length
) {
168 return (length
== 255) ? 0 : length
* 1000;
171 static int dvdnav_stream_read(dvdnav_priv_t
* priv
, unsigned char *buf
, int *len
) {
172 int event
= DVDNAV_NOP
;
175 if (dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,len
)!=DVDNAV_STATUS_OK
) {
176 mp_msg(MSGT_OPEN
,MSGL_V
, "Error getting next block from DVD %d (%s)\n",event
, dvdnav_err_to_string(priv
->dvdnav
) );
179 else if (event
!=DVDNAV_BLOCK_OK
) {
180 // need to handle certain events internally (like skipping stills)
182 case DVDNAV_NAV_PACKET
:
184 case DVDNAV_STILL_FRAME
: {
185 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*) buf
;
186 priv
->still_length
= still_event
->length
;
187 /* set still frame duration */
188 priv
->duration
= dvdnav_get_duration (priv
->still_length
);
189 if (priv
->still_length
<= 1) {
190 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
191 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
195 case DVDNAV_HIGHLIGHT
: {
196 dvdnav_get_highlight (priv
, 1);
199 case DVDNAV_CELL_CHANGE
: {
200 dvdnav_cell_change_event_t
*ev
= (dvdnav_cell_change_event_t
*)buf
;
203 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
204 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
206 priv
->duration
= ev
->pgc_length
/90;
208 if (dvdnav_is_domain_vts(priv
->dvdnav
))
209 priv
->state
&= ~NAV_FLAG_VTS_DOMAIN
;
211 priv
->state
|= NAV_FLAG_VTS_DOMAIN
;
213 nextstill
= dvdnav_get_next_still_flag (priv
->dvdnav
);
215 priv
->duration
= dvdnav_get_duration (nextstill
);
216 priv
->still_length
= nextstill
;
217 if (priv
->still_length
<= 1) {
218 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
219 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
225 case DVDNAV_SPU_CLUT_CHANGE
: {
226 memcpy(priv
->spu_clut
, buf
, 16*sizeof(unsigned int));
227 priv
->state
|= NAV_FLAG_SPU_SET
;
231 if ((priv
->state
& NAV_FLAG_WAIT_SKIP
) &&
232 !(priv
->state
& NAV_FLAG_WAIT
))
233 dvdnav_wait_skip (priv
->dvdnav
);
235 priv
->state
|= NAV_FLAG_WAIT
;
238 case DVDNAV_VTS_CHANGE
: {
239 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
240 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
243 case DVDNAV_SPU_STREAM_CHANGE
: {
244 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
254 static void update_title_len(stream_t
*stream
) {
255 dvdnav_priv_t
*priv
= stream
->priv
;
256 dvdnav_status_t status
;
257 uint32_t pos
= 0, len
= 0;
259 status
= dvdnav_get_position(priv
->dvdnav
, &pos
, &len
);
260 if(status
== DVDNAV_STATUS_OK
&& len
) {
261 stream
->end_pos
= (off_t
) len
* 2048;
270 static int seek(stream_t
*s
, off_t newpos
) {
272 dvdnav_priv_t
*priv
= s
->priv
;
274 if(s
->end_pos
&& newpos
> s
->end_pos
)
276 sector
= newpos
/ 2048ULL;
277 if(dvdnav_sector_search(priv
->dvdnav
, (uint64_t) sector
, SEEK_SET
) != DVDNAV_STATUS_OK
)
285 mp_msg(MSGT_STREAM
,MSGL_INFO
,"dvdnav_stream, seeking to %"PRIu64
" failed: %s\n", newpos
, dvdnav_err_to_string(priv
->dvdnav
));
290 static void stream_dvdnav_close(stream_t
*s
) {
291 dvdnav_priv_t
*priv
= s
->priv
;
292 dvdnav_close(priv
->dvdnav
);
298 static int fill_buffer(stream_t
*s
, char *but
, int len
)
302 dvdnav_priv_t
* priv
=s
->priv
;
303 if (priv
->state
& NAV_FLAG_WAIT_READ
) /* read is suspended */
308 while(!len
) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
310 event
=dvdnav_stream_read(priv
, s
->buffer
, &len
);
311 if(event
==-1 || len
==-1)
313 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "DVDNAV stream read error!\n");
316 if (event
!= DVDNAV_BLOCK_OK
)
317 dvdnav_get_highlight (priv
, 1);
320 priv
->state
|= NAV_FLAG_EOF
;
323 case DVDNAV_BLOCK_OK
:
324 case DVDNAV_NAV_PACKET
:
325 case DVDNAV_STILL_FRAME
:
328 if (priv
->state
& NAV_FLAG_WAIT
)
332 case DVDNAV_VTS_CHANGE
: {
333 int tit
= 0, part
= 0;
334 dvdnav_vts_change_event_t
*vts_event
= (dvdnav_vts_change_event_t
*)s
->buffer
;
335 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "DVDNAV, switched to title: %d\r\n", vts_event
->new_vtsN
);
336 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
337 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
338 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
339 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
340 priv
->state
&= ~NAV_FLAG_WAIT
;
343 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
344 priv
->state
|= NAV_FLAG_WAIT_READ
;
345 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
) {
346 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nDVDNAV, NEW TITLE %d\r\n", tit
);
347 dvdnav_get_highlight (priv
, 0);
348 if(priv
->title
> 0 && tit
!= priv
->title
)
353 case DVDNAV_CELL_CHANGE
: {
354 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
355 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
356 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
357 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
358 priv
->state
&= ~NAV_FLAG_WAIT
;
359 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
360 priv
->state
|= NAV_FLAG_WAIT_READ
;
361 if(priv
->title
> 0 && dvd_last_chapter
> 0) {
363 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
&& part
> dvd_last_chapter
)
366 dvdnav_get_highlight (priv
, 1);
369 case DVDNAV_AUDIO_STREAM_CHANGE
:
370 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
372 case DVDNAV_SPU_STREAM_CHANGE
:
373 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
377 mp_msg(MSGT_STREAM
,MSGL_DBG2
,"DVDNAV fill_buffer len: %d\n",len
);
381 static int control(stream_t
*stream
, int cmd
, void* arg
) {
382 dvdnav_priv_t
* priv
=stream
->priv
;
387 case STREAM_CTRL_SEEK_TO_CHAPTER
:
389 int chap
= *((unsigned int *)arg
)+1;
391 if(chap
< 1 || dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
393 if(dvdnav_part_play(priv
->dvdnav
, tit
, chap
) != DVDNAV_STATUS_OK
)
397 case STREAM_CTRL_GET_NUM_CHAPTERS
:
399 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
401 if(dvdnav_get_number_of_parts(priv
->dvdnav
, tit
, &part
) != DVDNAV_STATUS_OK
)
405 *((unsigned int *)arg
) = part
;
408 case STREAM_CTRL_GET_CURRENT_CHAPTER
:
410 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
412 *((unsigned int *)arg
) = part
- 1;
415 case STREAM_CTRL_GET_TIME_LENGTH
:
417 if(priv
->duration
|| priv
->still_length
)
419 *((double *)arg
) = (double)priv
->duration
/ 1000.0;
424 case STREAM_CTRL_GET_ASPECT_RATIO
:
426 uint8_t ar
= dvdnav_get_video_aspect(priv
->dvdnav
);
427 *((double *)arg
) = !ar
? 4.0/3.0 : 16.0/9.0;
430 case STREAM_CTRL_GET_CURRENT_TIME
:
433 tm
= dvdnav_get_current_time(priv
->dvdnav
)/90000.0f
;
436 *((double *)arg
) = tm
;
441 case STREAM_CTRL_SEEK_TO_TIME
:
443 uint64_t tm
= (uint64_t) (*((double*)arg
) * 90000);
444 if(dvdnav_time_search(priv
->dvdnav
, tm
) == DVDNAV_STATUS_OK
)
448 case STREAM_CTRL_GET_NUM_ANGLES
:
450 uint32_t curr
, angles
;
451 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
453 *((int *)arg
) = angles
;
456 case STREAM_CTRL_GET_ANGLE
:
458 uint32_t curr
, angles
;
459 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
461 *((int *)arg
) = curr
;
464 case STREAM_CTRL_SET_ANGLE
:
466 uint32_t curr
, angles
;
467 int new_angle
= *((int *)arg
);
468 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
470 if(new_angle
>angles
|| new_angle
<1)
472 if(dvdnav_angle_change(priv
->dvdnav
, new_angle
) != DVDNAV_STATUS_OK
)
477 return STREAM_UNSUPPORTED
;
480 static void identify_chapters(dvdnav_t
*nav
, uint32_t title
)
482 uint64_t *parts
=NULL
, duration
=0;
484 n
= dvdnav_describe_title_chapters(nav
, title
, &parts
, &duration
);
487 mp_msg(MSGT_IDENTIFY
, MSGL_V
, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title
, t
/ 1000, t
% 1000);
488 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "TITLE %u, CHAPTERS: ", title
);
490 t
= parts
[i
] / 90000;
491 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "%02d:%02d:%02d,", t
/3600, (t
/60)%60, t
%60);
494 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "\n");
498 static void identify(dvdnav_priv_t
*priv
, struct stream_priv_s
*p
)
500 uint32_t titles
=0, i
;
502 dvdnav_get_number_of_titles(priv
->dvdnav
, &titles
);
503 for(i
=0; i
<titles
; i
++)
504 identify_chapters(priv
->dvdnav
, i
);
507 identify_chapters(priv
->dvdnav
, p
->track
);
510 static void show_audio_subs_languages(dvdnav_t
*nav
)
513 uint16_t i
, lang
, format
, id
, channels
;
514 int base
[7] = {128, 0, 0, 0, 160, 136, 0};
518 lg
= dvdnav_get_audio_logical_stream(nav
, i
);
519 if(lg
== 0xff) continue;
520 channels
= dvdnav_audio_stream_channels(nav
, lg
);
521 if(channels
== 0xFFFF)
522 channels
= 2; //unknown
525 lang
= dvdnav_audio_stream_to_lang(nav
, lg
);
527 tmp
[0] = tmp
[1] = '?';
531 tmp
[1] = lang
& 0xFF;
534 format
= dvdnav_audio_stream_format(nav
, lg
);
535 if(format
== 0xFFFF || format
> 6)
536 format
= 1; //unknown
537 id
= i
+ base
[format
];
538 mp_msg(MSGT_OPEN
,MSGL_STATUS
,MSGTR_DVDaudioStreamInfo
, i
,
539 dvd_audio_stream_types
[format
], dvd_audio_stream_channels
[channels
], tmp
, id
);
544 lg
= dvdnav_get_spu_logical_stream(nav
, i
);
545 if(lg
== 0xff) continue;
546 lang
= dvdnav_spu_stream_to_lang(nav
, lg
);
548 tmp
[0] = tmp
[1] = '?';
552 tmp
[1] = lang
& 0xFF;
555 mp_msg(MSGT_OPEN
,MSGL_STATUS
,MSGTR_DVDsubtitleLanguage
, i
+0x20, tmp
);
559 static int open_s(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
560 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
564 if(p
->device
) filename
= p
->device
;
565 else if(dvd_device
) filename
= dvd_device
;
566 else filename
= DEFAULT_DVD_DEVICE
;
567 if(!(priv
=new_dvdnav_stream(filename
))) {
568 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_CantOpenDVD
,filename
, strerror(errno
));
569 return STREAM_UNSUPPORTED
;
573 priv
->title
= p
->track
;
574 if(dvdnav_title_play(priv
->dvdnav
, p
->track
) != DVDNAV_STATUS_OK
) {
575 mp_msg(MSGT_OPEN
,MSGL_FATAL
,"dvdnav_stream, couldn't select title %d, error '%s'\n", p
->track
, dvdnav_err_to_string(priv
->dvdnav
));
576 return STREAM_UNSUPPORTED
;
578 } else if (p
->track
== 0) {
579 if(dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Root
) != DVDNAV_STATUS_OK
)
580 dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Title
);
582 if(mp_msg_test(MSGT_IDENTIFY
, MSGL_INFO
))
585 show_audio_subs_languages(priv
->dvdnav
);
587 dvdnav_angle_change(priv
->dvdnav
, dvd_angle
);
589 stream
->sector_size
= 2048;
590 stream
->flags
= STREAM_READ
| STREAM_SEEK
;
591 stream
->fill_buffer
= fill_buffer
;
593 stream
->control
= control
;
594 stream
->close
= stream_dvdnav_close
;
595 stream
->type
= STREAMTYPE_DVDNAV
;
596 stream
->priv
=(void*)priv
;
597 *file_format
= DEMUXER_TYPE_MPEG_PS
;
599 update_title_len(stream
);
600 if(!stream
->pos
&& p
->track
> 0)
601 mp_msg(MSGT_OPEN
,MSGL_ERR
, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv
->dvdnav
));
603 mp_msg(MSGT_OPEN
,MSGL_INFO
, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
609 void mp_dvdnav_handle_input(stream_t
*stream
, int cmd
, int *button
) {
610 dvdnav_priv_t
* priv
= stream
->priv
;
611 dvdnav_t
*nav
= priv
->dvdnav
;
612 dvdnav_status_t status
=DVDNAV_STATUS_ERR
;
613 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
615 if(cmd
!= MP_CMD_DVDNAV_SELECT
&& !pci
)
619 case MP_CMD_DVDNAV_UP
:
620 status
= dvdnav_upper_button_select(nav
, pci
);
622 case MP_CMD_DVDNAV_DOWN
:
623 status
= dvdnav_lower_button_select(nav
, pci
);
625 case MP_CMD_DVDNAV_LEFT
:
626 status
= dvdnav_left_button_select(nav
, pci
);
628 case MP_CMD_DVDNAV_RIGHT
:
629 status
= dvdnav_right_button_select(nav
, pci
);
631 case MP_CMD_DVDNAV_MENU
:
632 status
= dvdnav_menu_call(nav
,DVD_MENU_Root
);
634 case MP_CMD_DVDNAV_PREVMENU
: {
637 dvdnav_current_title_info(nav
, &title
, &part
);
639 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Part
)) == DVDNAV_STATUS_OK
)
642 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Title
)) == DVDNAV_STATUS_OK
)
644 status
=dvdnav_menu_call(nav
, DVD_MENU_Root
);
647 case MP_CMD_DVDNAV_SELECT
:
648 status
= dvdnav_button_activate(nav
, pci
);
650 case MP_CMD_DVDNAV_MOUSECLICK
:
652 this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
653 should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
654 and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
655 the coodinates saved by mp_dvdnav_update_mouse_pos().
656 This last call always works well
658 status
= dvdnav_mouse_activate(nav
, pci
, priv
->mousex
, priv
->mousey
);
661 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Unknown DVDNAV cmd %d\n", cmd
);
665 if(status
== DVDNAV_STATUS_OK
)
666 dvdnav_get_current_highlight(nav
, button
);
669 void mp_dvdnav_update_mouse_pos(stream_t
*stream
, int32_t x
, int32_t y
, int* button
) {
670 dvdnav_priv_t
* priv
= stream
->priv
;
671 dvdnav_t
*nav
= priv
->dvdnav
;
672 dvdnav_status_t status
;
673 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
677 status
= dvdnav_mouse_select(nav
, pci
, x
, y
);
678 if(status
== DVDNAV_STATUS_OK
) dvdnav_get_current_highlight(nav
, button
);
684 static int mp_dvdnav_get_aid_from_format (stream_t
*stream
, int index
, uint8_t lg
) {
685 dvdnav_priv_t
* priv
= stream
->priv
;
688 format
= dvdnav_audio_stream_format(priv
->dvdnav
, lg
);
690 case DVDNAV_FORMAT_AC3
:
691 return (index
+ 128);
692 case DVDNAV_FORMAT_DTS
:
693 return (index
+ 136);
694 case DVDNAV_FORMAT_LPCM
:
695 return (index
+ 160);
696 case DVDNAV_FORMAT_MPEGAUDIO
:
706 * \brief mp_dvdnav_aid_from_audio_num() returns the audio id corresponding to the logical number
707 * \param stream: - stream pointer
708 * \param audio_num: - logical number
709 * \return -1 on error, current subtitle id if successful
711 int mp_dvdnav_aid_from_audio_num(stream_t
*stream
, int audio_num
) {
712 dvdnav_priv_t
* priv
= stream
->priv
;
716 for(k
=0; k
<32; k
++) {
717 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
718 if (lg
== 0xff) continue;
719 if (lg
!= audio_num
) continue;
721 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
727 * \brief mp_dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
728 * \param stream: - stream pointer
729 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
730 * \return -1 on error, current subtitle id if successful
732 int mp_dvdnav_aid_from_lang(stream_t
*stream
, unsigned char *language
) {
733 dvdnav_priv_t
* priv
= stream
->priv
;
736 uint16_t lang
, lcode
;;
738 while(language
&& strlen(language
)>=2) {
739 lcode
= (language
[0] << 8) | (language
[1]);
740 for(k
=0; k
<32; k
++) {
741 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
742 if(lg
== 0xff) continue;
743 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
744 if(lang
!= 0xFFFF && lang
== lcode
)
745 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
748 while(language
[0]==',' || language
[0]==' ') ++language
;
754 * \brief mp_dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
755 * \param stream: - stream pointer
756 * \param sid: physical subtitle id
757 * \param buf: buffer to contain the 2-chars language string
758 * \return 0 on error, 1 if successful
760 int mp_dvdnav_lang_from_aid(stream_t
*stream
, int aid
, unsigned char *buf
) {
763 dvdnav_priv_t
* priv
= stream
->priv
;
767 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, aid
& 0x7);
768 if(lg
== 0xff) return 0;
769 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
770 if(lang
== 0xffff) return 0;
772 buf
[1] = lang
& 0xFF;
779 * \brief mp_dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
780 * \param stream: - stream pointer
781 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
782 * \return -1 on error, current subtitle id if successful
784 int mp_dvdnav_sid_from_lang(stream_t
*stream
, unsigned char *language
) {
785 dvdnav_priv_t
* priv
= stream
->priv
;
787 uint16_t lang
, lcode
;
789 while(language
&& strlen(language
)>=2) {
790 lcode
= (language
[0] << 8) | (language
[1]);
791 for(k
=0; k
<32; k
++) {
792 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
793 if(lg
== 0xff) continue;
794 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, lg
);
795 if(lang
!= 0xFFFF && lang
== lcode
) {
800 while(language
[0]==',' || language
[0]==' ') ++language
;
806 * \brief mp_dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
807 * \param stream: - stream pointer
808 * \param sid: physical subtitle id
809 * \param buf: buffer to contain the 2-chars language string
810 * \return 0 on error, 1 if successful
812 int mp_dvdnav_lang_from_sid(stream_t
*stream
, int sid
, unsigned char *buf
) {
815 dvdnav_priv_t
*priv
= stream
->priv
;
816 if(sid
< 0) return 0;
817 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, sid
);
818 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, lg
);
819 if(lang
== 0xffff) return 0;
821 buf
[1] = lang
& 0xFF;
827 * \brief mp_dvdnav_number_of_subs() returns the count of available subtitles
828 * \param stream: - stream pointer
829 * \return 0 on error, something meaningful otherwise
831 int mp_dvdnav_number_of_subs(stream_t
*stream
) {
832 dvdnav_priv_t
* priv
= stream
->priv
;
835 if (priv
->state
& NAV_FLAG_VTS_DOMAIN
) return 0;
836 for(k
=0; k
<32; k
++) {
837 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
838 if(lg
== 0xff) continue;
845 * \brief mp_dvdnav_get_spu_clut() returns the spu clut
846 * \param stream: - stream pointer
847 * \return spu clut pointer
849 unsigned int *mp_dvdnav_get_spu_clut(stream_t
*stream
) {
850 dvdnav_priv_t
*priv
= stream
->priv
;
851 return (priv
->state
& NAV_FLAG_SPU_SET
) ? priv
->spu_clut
: NULL
;
855 * \brief mp_dvdnav_get_highlight() get dvdnav highlight struct
856 * \param stream: - stream pointer
857 * \param hl : - highlight struct pointer
859 void mp_dvdnav_get_highlight (stream_t
*stream
, nav_highlight_t
*hl
) {
860 dvdnav_priv_t
*priv
= stream
->priv
;
861 dvdnav_highlight_event_t hlev
= priv
->hlev
;
867 hl
->palette
= hlev
.palette
;
870 void mp_dvdnav_switch_title (stream_t
*stream
, int title
) {
871 dvdnav_priv_t
*priv
= stream
->priv
;
874 dvdnav_get_number_of_titles (priv
->dvdnav
, &titles
);
875 if (title
> 0 && title
<= titles
)
876 dvdnav_title_play (priv
->dvdnav
, title
);
880 * \brief Check if end of stream has been reached
881 * \param stream: - stream pointer
882 * \return 1 on really eof
884 int mp_dvdnav_is_eof (stream_t
*stream
) {
885 return ((dvdnav_priv_t
*) stream
->priv
)->state
& NAV_FLAG_EOF
;
889 * \brief Skip still frame
890 * \param stream: - stream pointer
891 * \return 0 on success
893 int mp_dvdnav_skip_still (stream_t
*stream
) {
894 dvdnav_priv_t
*priv
= stream
->priv
;
895 if (priv
->still_length
== 0xff)
897 dvdnav_still_skip(priv
->dvdnav
);
902 * \brief Skip wait event
903 * \param stream: - stream pointer
904 * \return 0 on success
906 int mp_dvdnav_skip_wait (stream_t
*stream
) {
907 dvdnav_priv_t
*priv
= stream
->priv
;
908 if (!(priv
->state
& NAV_FLAG_WAIT
))
910 priv
->state
&= ~NAV_FLAG_WAIT
;
911 dvdnav_wait_skip(priv
->dvdnav
);
916 * \brief Set wait mode
917 * \param stream : - stream pointer
918 * \param mode : - if true, then suspend block read
919 * \param automode: - if true, then VTS or cell change set wait mode
921 void mp_dvdnav_read_wait (stream_t
*stream
, int mode
, int automode
) {
922 dvdnav_priv_t
*priv
= stream
->priv
;
924 priv
->state
&= ~NAV_FLAG_WAIT_READ
;
926 priv
->state
|= NAV_FLAG_WAIT_READ
;
928 priv
->state
&= ~NAV_FLAG_WAIT_READ_AUTO
;
930 priv
->state
|= NAV_FLAG_WAIT_READ_AUTO
;
934 * \brief Check if cell has changed
935 * \param stream: - stream pointer
936 * \param clear : - if true, then clear cell change flag
937 * \return 1 if cell has changed
939 int mp_dvdnav_cell_has_changed (stream_t
*stream
, int clear
) {
940 dvdnav_priv_t
*priv
= stream
->priv
;
941 if (!(priv
->state
& NAV_FLAG_CELL_CHANGE
))
944 priv
->state
&= ~NAV_FLAG_CELL_CHANGE
;
945 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
951 * \brief Check if audio has changed
952 * \param stream: - stream pointer
953 * \param clear : - if true, then clear audio change flag
954 * \return 1 if audio has changed
956 int mp_dvdnav_audio_has_changed (stream_t
*stream
, int clear
) {
957 dvdnav_priv_t
*priv
= stream
->priv
;
959 if (!(priv
->state
& NAV_FLAG_AUDIO_CHANGE
))
963 priv
->state
&= ~NAV_FLAG_AUDIO_CHANGE
;
969 * \brief Check if SPU has changed
970 * \param stream: - stream pointer
971 * \param clear : - if true, then clear spu change flag
972 * \return 1 if spu has changed
974 int mp_dvdnav_spu_has_changed (stream_t
*stream
, int clear
) {
975 dvdnav_priv_t
*priv
= stream
->priv
;
977 if (!(priv
->state
& NAV_FLAG_SPU_CHANGE
))
981 priv
->state
&= ~NAV_FLAG_SPU_CHANGE
;
986 /* Notify if something has changed in stream
987 * Can be related to title, chapter, audio or SPU
989 int mp_dvdnav_stream_has_changed (stream_t
*stream
) {
990 dvdnav_priv_t
*priv
= stream
->priv
;
992 if (!(priv
->state
& NAV_FLAG_STREAM_CHANGE
))
995 priv
->state
&= ~NAV_FLAG_STREAM_CHANGE
;
999 const stream_info_t stream_info_dvdnav
= {
1007 1 // Urls are an option string