2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "osdep/timer.h"
29 #include "input/input.h"
31 #include "libmpdemux/demuxer.h"
32 #include <dvdnav/dvdnav.h>
33 #include "stream_dvdnav.h"
34 #include "libvo/video_out.h"
35 #include "libavutil/common.h"
39 #include "stream_dvd_common.h"
43 NAV_FLAG_EOF
= 1 << 0, /* end of stream has been reached */
44 NAV_FLAG_WAIT
= 1 << 1, /* wait event */
45 NAV_FLAG_WAIT_SKIP
= 1 << 2, /* wait skip disable */
46 NAV_FLAG_CELL_CHANGE
= 1 << 3, /* cell change event */
47 NAV_FLAG_WAIT_READ_AUTO
= 1 << 4, /* wait read auto mode */
48 NAV_FLAG_WAIT_READ
= 1 << 5, /* suspend read from stream */
49 NAV_FLAG_VTS_DOMAIN
= 1 << 6, /* vts domain */
50 NAV_FLAG_SPU_SET
= 1 << 7, /* spu_clut is valid */
51 NAV_FLAG_STREAM_CHANGE
= 1 << 8, /* title, chapter, audio or SPU */
52 NAV_FLAG_AUDIO_CHANGE
= 1 << 9, /* audio stream change event */
53 NAV_FLAG_SPU_CHANGE
= 1 << 10, /* spu stream change event */
57 dvdnav_t
* dvdnav
; /* handle to libdvdnav stuff */
58 char * filename
; /* path */
59 unsigned int duration
; /* in milliseconds */
62 unsigned int spu_clut
[16];
63 dvdnav_highlight_event_t hlev
;
64 int still_length
; /* still frame duration */
68 static struct stream_priv_s
{
71 } stream_priv_dflts
= {
76 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
78 static const m_option_t stream_opts_fields
[] = {
79 {"filename", ST_OFF(device
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
80 {"hostname", ST_OFF(track
), CONF_TYPE_INT
, M_OPT_RANGE
, 1, 99, NULL
},
81 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
83 static const struct m_struct_st stream_opts
= {
85 sizeof(struct stream_priv_s
),
90 static int seek(stream_t
*s
, off_t newpos
);
91 static void show_audio_subs_languages(dvdnav_t
*nav
);
93 static dvdnav_priv_t
* new_dvdnav_stream(char * filename
) {
94 const char * title_str
;
100 if (!(priv
=calloc(1,sizeof(dvdnav_priv_t
))))
103 if (!(priv
->filename
=strdup(filename
))) {
108 dvd_set_speed(priv
->filename
, dvd_speed
);
110 if(dvdnav_open(&(priv
->dvdnav
),priv
->filename
)!=DVDNAV_STATUS_OK
)
112 free(priv
->filename
);
122 if(1) //from vlc: if not used dvdnav from cvs will fail
127 dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,&len
);
128 dvdnav_sector_search(priv
->dvdnav
, 0, SEEK_SET
);
131 /* turn off dvdnav caching */
132 dvdnav_set_readahead_flag(priv
->dvdnav
, 0);
133 if(dvdnav_set_PGC_positioning_flag(priv
->dvdnav
, 1) != DVDNAV_STATUS_OK
)
134 mp_msg(MSGT_OPEN
,MSGL_ERR
,"stream_dvdnav, failed to set PGC positioning\n");
135 /* report the title?! */
136 if (dvdnav_get_title_string(priv
->dvdnav
,&title_str
)==DVDNAV_STATUS_OK
) {
137 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
,"Title: '%s'\n",title_str
);
140 //dvdnav_event_clear(priv);
145 static void dvdnav_get_highlight (dvdnav_priv_t
*priv
, int display_mode
) {
146 pci_t
*pnavpci
= NULL
;
147 dvdnav_highlight_event_t
*hlev
= &(priv
->hlev
);
150 if (!priv
|| !priv
->dvdnav
)
153 pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
157 dvdnav_get_current_highlight (priv
->dvdnav
, &(hlev
->buttonN
));
158 hlev
->display
= display_mode
; /* show */
160 if (hlev
->buttonN
> 0 && pnavpci
->hli
.hl_gi
.btn_ns
> 0 && hlev
->display
) {
161 for (btnum
= 0; btnum
< pnavpci
->hli
.hl_gi
.btn_ns
; btnum
++) {
162 btni_t
*btni
= &(pnavpci
->hli
.btnit
[btnum
]);
164 if (hlev
->buttonN
== btnum
+ 1) {
165 hlev
->sx
= FFMIN (btni
->x_start
, btni
->x_end
);
166 hlev
->ex
= FFMAX (btni
->x_start
, btni
->x_end
);
167 hlev
->sy
= FFMIN (btni
->y_start
, btni
->y_end
);
168 hlev
->ey
= FFMAX (btni
->y_start
, btni
->y_end
);
170 hlev
->palette
= (btni
->btn_coln
== 0) ? 0 :
171 pnavpci
->hli
.btn_colit
.btn_coli
[btni
->btn_coln
- 1][0];
175 } else { /* hide button or no button */
176 hlev
->sx
= hlev
->ex
= 0;
177 hlev
->sy
= hlev
->ey
= 0;
178 hlev
->palette
= hlev
->buttonN
= 0;
182 static inline int dvdnav_get_duration (int length
) {
183 return (length
== 255) ? 0 : length
* 1000;
186 static int dvdnav_stream_read(dvdnav_priv_t
* priv
, unsigned char *buf
, int *len
) {
187 int event
= DVDNAV_NOP
;
190 if (dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,len
)!=DVDNAV_STATUS_OK
) {
191 mp_msg(MSGT_OPEN
,MSGL_V
, "Error getting next block from DVD %d (%s)\n",event
, dvdnav_err_to_string(priv
->dvdnav
) );
194 else if (event
!=DVDNAV_BLOCK_OK
) {
195 // need to handle certain events internally (like skipping stills)
197 case DVDNAV_NAV_PACKET
:
199 case DVDNAV_STILL_FRAME
: {
200 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*) buf
;
201 priv
->still_length
= still_event
->length
;
202 /* set still frame duration */
203 priv
->duration
= dvdnav_get_duration (priv
->still_length
);
204 if (priv
->still_length
<= 1) {
205 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
206 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
210 case DVDNAV_HIGHLIGHT
: {
211 dvdnav_get_highlight (priv
, 1);
214 case DVDNAV_CELL_CHANGE
: {
215 dvdnav_cell_change_event_t
*ev
= (dvdnav_cell_change_event_t
*)buf
;
218 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
219 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
221 priv
->duration
= ev
->pgc_length
/90;
223 if (dvdnav_is_domain_vts(priv
->dvdnav
)) {
224 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MOVIE\n");
225 priv
->state
&= ~NAV_FLAG_VTS_DOMAIN
;
227 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MENU\n");
228 priv
->state
|= NAV_FLAG_VTS_DOMAIN
;
231 nextstill
= dvdnav_get_next_still_flag (priv
->dvdnav
);
233 priv
->duration
= dvdnav_get_duration (nextstill
);
234 priv
->still_length
= nextstill
;
235 if (priv
->still_length
<= 1) {
236 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
237 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
243 case DVDNAV_SPU_CLUT_CHANGE
: {
244 memcpy(priv
->spu_clut
, buf
, 16*sizeof(unsigned int));
245 priv
->state
|= NAV_FLAG_SPU_SET
;
249 if ((priv
->state
& NAV_FLAG_WAIT_SKIP
) &&
250 !(priv
->state
& NAV_FLAG_WAIT
))
251 dvdnav_wait_skip (priv
->dvdnav
);
253 priv
->state
|= NAV_FLAG_WAIT
;
256 case DVDNAV_VTS_CHANGE
: {
257 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
258 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
261 case DVDNAV_SPU_STREAM_CHANGE
: {
262 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
272 static void update_title_len(stream_t
*stream
) {
273 dvdnav_priv_t
*priv
= stream
->priv
;
274 dvdnav_status_t status
;
275 uint32_t pos
= 0, len
= 0;
277 status
= dvdnav_get_position(priv
->dvdnav
, &pos
, &len
);
278 if(status
== DVDNAV_STATUS_OK
&& len
) {
279 stream
->end_pos
= (off_t
) len
* 2048;
288 static int seek(stream_t
*s
, off_t newpos
) {
290 dvdnav_priv_t
*priv
= s
->priv
;
292 if(s
->end_pos
&& newpos
> s
->end_pos
)
294 sector
= newpos
/ 2048ULL;
295 if(dvdnav_sector_search(priv
->dvdnav
, (uint64_t) sector
, SEEK_SET
) != DVDNAV_STATUS_OK
)
303 mp_msg(MSGT_STREAM
,MSGL_INFO
,"dvdnav_stream, seeking to %"PRIu64
" failed: %s\n", newpos
, dvdnav_err_to_string(priv
->dvdnav
));
308 static void stream_dvdnav_close(stream_t
*s
) {
309 dvdnav_priv_t
*priv
= s
->priv
;
310 dvdnav_close(priv
->dvdnav
);
312 dvd_set_speed(priv
->filename
, -1);
317 static int fill_buffer(stream_t
*s
, char *but
, int len
)
321 dvdnav_priv_t
* priv
=s
->priv
;
322 if (priv
->state
& NAV_FLAG_WAIT_READ
) /* read is suspended */
327 while(!len
) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
329 event
=dvdnav_stream_read(priv
, s
->buffer
, &len
);
330 if(event
==-1 || len
==-1)
332 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "DVDNAV stream read error!\n");
335 if (event
!= DVDNAV_BLOCK_OK
)
336 dvdnav_get_highlight (priv
, 1);
339 priv
->state
|= NAV_FLAG_EOF
;
342 case DVDNAV_BLOCK_OK
:
343 case DVDNAV_NAV_PACKET
:
344 case DVDNAV_STILL_FRAME
:
347 if (priv
->state
& NAV_FLAG_WAIT
)
351 case DVDNAV_VTS_CHANGE
: {
352 int tit
= 0, part
= 0;
353 dvdnav_vts_change_event_t
*vts_event
= (dvdnav_vts_change_event_t
*)s
->buffer
;
354 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "DVDNAV, switched to title: %d\r\n", vts_event
->new_vtsN
);
355 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
356 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
357 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
358 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
359 priv
->state
&= ~NAV_FLAG_WAIT
;
362 show_audio_subs_languages(priv
->dvdnav
);
363 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
364 priv
->state
|= NAV_FLAG_WAIT_READ
;
365 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
) {
366 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nDVDNAV, NEW TITLE %d\r\n", tit
);
367 dvdnav_get_highlight (priv
, 0);
368 if(priv
->title
> 0 && tit
!= priv
->title
) {
369 priv
->state
|= NAV_FLAG_EOF
;
375 case DVDNAV_CELL_CHANGE
: {
376 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
377 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
378 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
379 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
380 priv
->state
&= ~NAV_FLAG_WAIT
;
381 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
382 priv
->state
|= NAV_FLAG_WAIT_READ
;
383 if(priv
->title
> 0 && s
->opts
->chapterrange
[1] > 0) {
385 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
&& part
> s
->opts
->chapterrange
[1]) {
386 priv
->state
|= NAV_FLAG_EOF
;
390 dvdnav_get_highlight (priv
, 1);
393 case DVDNAV_AUDIO_STREAM_CHANGE
:
394 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
396 case DVDNAV_SPU_STREAM_CHANGE
:
397 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
401 mp_msg(MSGT_STREAM
,MSGL_DBG2
,"DVDNAV fill_buffer len: %d\n",len
);
405 static int control(stream_t
*stream
, int cmd
, void* arg
) {
406 dvdnav_priv_t
* priv
=stream
->priv
;
411 case STREAM_CTRL_SEEK_TO_CHAPTER
:
413 int chap
= *((unsigned int *)arg
)+1;
415 if(chap
< 1 || dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
417 if(dvdnav_part_play(priv
->dvdnav
, tit
, chap
) != DVDNAV_STATUS_OK
)
421 case STREAM_CTRL_GET_NUM_CHAPTERS
:
423 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
425 if(dvdnav_get_number_of_parts(priv
->dvdnav
, tit
, &part
) != DVDNAV_STATUS_OK
)
429 *((unsigned int *)arg
) = part
;
432 case STREAM_CTRL_GET_CURRENT_CHAPTER
:
434 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
436 *((unsigned int *)arg
) = part
- 1;
439 case STREAM_CTRL_GET_TIME_LENGTH
:
441 if(priv
->duration
|| priv
->still_length
)
443 *((double *)arg
) = (double)priv
->duration
/ 1000.0;
448 case STREAM_CTRL_GET_ASPECT_RATIO
:
450 uint8_t ar
= dvdnav_get_video_aspect(priv
->dvdnav
);
451 *((double *)arg
) = !ar
? 4.0/3.0 : 16.0/9.0;
454 case STREAM_CTRL_GET_CURRENT_TIME
:
457 tm
= dvdnav_get_current_time(priv
->dvdnav
)/90000.0f
;
460 *((double *)arg
) = tm
;
465 case STREAM_CTRL_SEEK_TO_TIME
:
467 uint64_t tm
= (uint64_t) (*((double*)arg
) * 90000);
468 if(dvdnav_time_search(priv
->dvdnav
, tm
) == DVDNAV_STATUS_OK
)
472 case STREAM_CTRL_GET_NUM_ANGLES
:
474 uint32_t curr
, angles
;
475 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
477 *((int *)arg
) = angles
;
480 case STREAM_CTRL_GET_ANGLE
:
482 uint32_t curr
, angles
;
483 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
485 *((int *)arg
) = curr
;
488 case STREAM_CTRL_SET_ANGLE
:
490 uint32_t curr
, angles
;
491 int new_angle
= *((int *)arg
);
492 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
494 if(new_angle
>angles
|| new_angle
<1)
496 if(dvdnav_angle_change(priv
->dvdnav
, new_angle
) != DVDNAV_STATUS_OK
)
501 return STREAM_UNSUPPORTED
;
504 static void identify_chapters(dvdnav_t
*nav
, uint32_t title
)
506 uint64_t *parts
=NULL
, duration
=0;
508 n
= dvdnav_describe_title_chapters(nav
, title
, &parts
, &duration
);
511 mp_msg(MSGT_IDENTIFY
, MSGL_V
, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title
, t
/ 1000, t
% 1000);
512 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "TITLE %u, CHAPTERS: ", title
);
514 t
= parts
[i
] / 90000;
515 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "%02d:%02d:%02d,", t
/3600, (t
/60)%60, t
%60);
518 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "\n");
522 static void identify(dvdnav_priv_t
*priv
, struct stream_priv_s
*p
)
524 uint32_t titles
=0, i
;
526 dvdnav_get_number_of_titles(priv
->dvdnav
, &titles
);
527 for(i
=0; i
<titles
; i
++)
528 identify_chapters(priv
->dvdnav
, i
);
531 identify_chapters(priv
->dvdnav
, p
->track
);
534 static void show_audio_subs_languages(dvdnav_t
*nav
)
537 uint16_t i
, lang
, format
, id
, channels
;
538 int base
[7] = {128, 0, 0, 0, 160, 136, 0};
541 char tmp
[] = "unknown";
542 lg
= dvdnav_get_audio_logical_stream(nav
, i
);
543 if(lg
== 0xff) continue;
544 channels
= dvdnav_audio_stream_channels(nav
, lg
);
545 if(channels
== 0xFFFF)
546 channels
= 2; //unknown
549 lang
= dvdnav_audio_stream_to_lang(nav
, lg
);
553 tmp
[1] = lang
& 0xFF;
556 format
= dvdnav_audio_stream_format(nav
, lg
);
557 if(format
== 0xFFFF || format
> 6)
558 format
= 1; //unknown
559 id
= i
+ base
[format
];
560 mp_tmsg(MSGT_OPEN
,MSGL_STATUS
,"audio stream: %d format: %s (%s) language: %s aid: %d.\n", i
,
561 dvd_audio_stream_types
[format
], dvd_audio_stream_channels
[channels
], tmp
, id
);
562 if (lang
!= 0xFFFF && lang
&& tmp
[0])
563 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AID_%d_LANG=%s\n", id
, tmp
);
568 char tmp
[] = "unknown";
569 lg
= dvdnav_get_spu_logical_stream(nav
, i
);
570 if(lg
== 0xff) continue;
571 lang
= dvdnav_spu_stream_to_lang(nav
, i
);
575 tmp
[1] = lang
& 0xFF;
578 mp_msg(MSGT_OPEN
,MSGL_STATUS
,"subtitle ( sid ): %d language: %s\n", lg
, tmp
);
579 if (lang
!= 0xFFFF && lang
&& tmp
[0])
580 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SID_%d_LANG=%s\n", lg
, tmp
);
584 static int open_s(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
585 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
589 if(p
->device
) filename
= p
->device
;
590 else if(dvd_device
) filename
= dvd_device
;
591 else filename
= DEFAULT_DVD_DEVICE
;
592 if(!(priv
=new_dvdnav_stream(filename
))) {
593 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Couldn't open DVD device: %s (%s)\n",filename
, strerror(errno
));
594 return STREAM_UNSUPPORTED
;
598 priv
->title
= p
->track
;
599 if(dvdnav_title_play(priv
->dvdnav
, p
->track
) != DVDNAV_STATUS_OK
) {
600 mp_msg(MSGT_OPEN
,MSGL_FATAL
,"dvdnav_stream, couldn't select title %d, error '%s'\n", p
->track
, dvdnav_err_to_string(priv
->dvdnav
));
601 return STREAM_UNSUPPORTED
;
603 } else if (p
->track
== 0) {
604 if(dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Root
) != DVDNAV_STATUS_OK
)
605 dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Title
);
607 if(mp_msg_test(MSGT_IDENTIFY
, MSGL_INFO
))
610 show_audio_subs_languages(priv
->dvdnav
);
612 dvdnav_angle_change(priv
->dvdnav
, dvd_angle
);
614 stream
->sector_size
= 2048;
615 stream
->flags
= STREAM_READ
| MP_STREAM_SEEK
;
616 stream
->fill_buffer
= fill_buffer
;
618 stream
->control
= control
;
619 stream
->close
= stream_dvdnav_close
;
620 stream
->type
= STREAMTYPE_DVDNAV
;
621 stream
->priv
=(void*)priv
;
622 *file_format
= DEMUXER_TYPE_MPEG_PS
;
624 update_title_len(stream
);
625 if(!stream
->pos
&& p
->track
> 0)
626 mp_msg(MSGT_OPEN
,MSGL_ERR
, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv
->dvdnav
));
628 mp_msg(MSGT_OPEN
,MSGL_INFO
, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
634 void mp_dvdnav_handle_input(stream_t
*stream
, int cmd
, int *button
) {
635 dvdnav_priv_t
* priv
= stream
->priv
;
636 dvdnav_t
*nav
= priv
->dvdnav
;
637 dvdnav_status_t status
=DVDNAV_STATUS_ERR
;
638 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
640 if(cmd
!= MP_CMD_DVDNAV_SELECT
&& !pci
)
644 case MP_CMD_DVDNAV_UP
:
645 status
= dvdnav_upper_button_select(nav
, pci
);
647 case MP_CMD_DVDNAV_DOWN
:
648 status
= dvdnav_lower_button_select(nav
, pci
);
650 case MP_CMD_DVDNAV_LEFT
:
651 status
= dvdnav_left_button_select(nav
, pci
);
653 case MP_CMD_DVDNAV_RIGHT
:
654 status
= dvdnav_right_button_select(nav
, pci
);
656 case MP_CMD_DVDNAV_MENU
:
657 status
= dvdnav_menu_call(nav
,DVD_MENU_Root
);
659 case MP_CMD_DVDNAV_PREVMENU
: {
662 dvdnav_current_title_info(nav
, &title
, &part
);
664 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Part
)) == DVDNAV_STATUS_OK
)
667 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Title
)) == DVDNAV_STATUS_OK
)
669 status
=dvdnav_menu_call(nav
, DVD_MENU_Root
);
672 case MP_CMD_DVDNAV_SELECT
:
673 status
= dvdnav_button_activate(nav
, pci
);
675 case MP_CMD_DVDNAV_MOUSECLICK
:
677 this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
678 should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
679 and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
680 the coodinates saved by mp_dvdnav_update_mouse_pos().
681 This last call always works well
683 status
= dvdnav_mouse_activate(nav
, pci
, priv
->mousex
, priv
->mousey
);
686 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Unknown DVDNAV cmd %d\n", cmd
);
690 if(status
== DVDNAV_STATUS_OK
)
691 dvdnav_get_current_highlight(nav
, button
);
694 void mp_dvdnav_update_mouse_pos(stream_t
*stream
, int32_t x
, int32_t y
, int* button
) {
695 dvdnav_priv_t
* priv
= stream
->priv
;
696 dvdnav_t
*nav
= priv
->dvdnav
;
697 dvdnav_status_t status
;
698 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
702 status
= dvdnav_mouse_select(nav
, pci
, x
, y
);
703 if(status
== DVDNAV_STATUS_OK
) dvdnav_get_current_highlight(nav
, button
);
709 static int mp_dvdnav_get_aid_from_format (stream_t
*stream
, int index
, uint8_t lg
) {
710 dvdnav_priv_t
* priv
= stream
->priv
;
713 format
= dvdnav_audio_stream_format(priv
->dvdnav
, lg
);
715 case DVDNAV_FORMAT_AC3
:
717 case DVDNAV_FORMAT_DTS
:
719 case DVDNAV_FORMAT_LPCM
:
721 case DVDNAV_FORMAT_MPEGAUDIO
:
731 * \brief mp_dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
732 * \param stream: - stream pointer
733 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
734 * \return -1 on error, current subtitle id if successful
736 int mp_dvdnav_aid_from_lang(stream_t
*stream
, unsigned char *language
) {
737 dvdnav_priv_t
* priv
= stream
->priv
;
740 uint16_t lang
, lcode
;
742 while(language
&& strlen(language
)>=2) {
743 lcode
= (language
[0] << 8) | (language
[1]);
744 for(k
=0; k
<32; k
++) {
745 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
746 if(lg
== 0xff) continue;
747 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
748 if(lang
!= 0xFFFF && lang
== lcode
)
749 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
752 while(language
[0]==',' || language
[0]==' ') ++language
;
758 * \brief mp_dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
759 * \param stream: - stream pointer
760 * \param sid: physical subtitle id
761 * \param buf: buffer to contain the 2-chars language string
762 * \return 0 on error, 1 if successful
764 int mp_dvdnav_lang_from_aid(stream_t
*stream
, int aid
, unsigned char *buf
) {
767 dvdnav_priv_t
* priv
= stream
->priv
;
771 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, aid
& 0x7);
772 if(lg
== 0xff) return 0;
773 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
774 if(lang
== 0xffff) return 0;
776 buf
[1] = lang
& 0xFF;
783 * \brief mp_dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
784 * \param stream: - stream pointer
785 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
786 * \return -1 on error, current subtitle id if successful
788 int mp_dvdnav_sid_from_lang(stream_t
*stream
, unsigned char *language
) {
789 dvdnav_priv_t
* priv
= stream
->priv
;
791 uint16_t lang
, lcode
;
793 while(language
&& strlen(language
)>=2) {
794 lcode
= (language
[0] << 8) | (language
[1]);
795 for(k
=0; k
<32; k
++) {
796 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
797 if(lg
== 0xff) continue;
798 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, k
);
799 if(lang
!= 0xFFFF && lang
== lcode
) {
804 while(language
[0]==',' || language
[0]==' ') ++language
;
810 * \brief mp_dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
811 * \param stream: - stream pointer
812 * \param sid: physical subtitle id
813 * \param buf: buffer to contain the 2-chars language string
814 * \return 0 on error, 1 if successful
816 int mp_dvdnav_lang_from_sid(stream_t
*stream
, int sid
, unsigned char *buf
) {
819 dvdnav_priv_t
*priv
= stream
->priv
;
820 if(sid
< 0) return 0;
822 if (dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
) == sid
)
826 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, k
);
827 if(lang
== 0xffff) return 0;
829 buf
[1] = lang
& 0xFF;
835 * \brief mp_dvdnav_number_of_subs() returns the count of available subtitles
836 * \param stream: - stream pointer
837 * \return 0 on error, something meaningful otherwise
839 int mp_dvdnav_number_of_subs(stream_t
*stream
) {
840 dvdnav_priv_t
* priv
= stream
->priv
;
843 if (priv
->state
& NAV_FLAG_VTS_DOMAIN
) return 0;
844 for(k
=0; k
<32; k
++) {
845 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
846 if(lg
== 0xff) continue;
847 if(lg
>= n
) n
= lg
+ 1;
853 * \brief mp_dvdnav_get_spu_clut() returns the spu clut
854 * \param stream: - stream pointer
855 * \return spu clut pointer
857 unsigned int *mp_dvdnav_get_spu_clut(stream_t
*stream
) {
858 dvdnav_priv_t
*priv
= stream
->priv
;
859 return (priv
->state
& NAV_FLAG_SPU_SET
) ? priv
->spu_clut
: NULL
;
863 * \brief mp_dvdnav_get_highlight() get dvdnav highlight struct
864 * \param stream: - stream pointer
865 * \param hl : - highlight struct pointer
867 void mp_dvdnav_get_highlight (stream_t
*stream
, nav_highlight_t
*hl
) {
868 dvdnav_priv_t
*priv
= stream
->priv
;
869 dvdnav_highlight_event_t hlev
= priv
->hlev
;
875 hl
->palette
= hlev
.palette
;
878 void mp_dvdnav_switch_title (stream_t
*stream
, int title
) {
879 dvdnav_priv_t
*priv
= stream
->priv
;
882 dvdnav_get_number_of_titles (priv
->dvdnav
, &titles
);
883 if (title
> 0 && title
<= titles
)
884 dvdnav_title_play (priv
->dvdnav
, title
);
888 * \brief Check if end of stream has been reached
889 * \param stream: - stream pointer
890 * \return 1 on really eof
892 int mp_dvdnav_is_eof (stream_t
*stream
) {
893 return ((dvdnav_priv_t
*) stream
->priv
)->state
& NAV_FLAG_EOF
;
897 * \brief Skip still frame
898 * \param stream: - stream pointer
899 * \return 0 on success
901 int mp_dvdnav_skip_still (stream_t
*stream
) {
902 dvdnav_priv_t
*priv
= stream
->priv
;
903 if (priv
->still_length
== 0xff)
905 dvdnav_still_skip(priv
->dvdnav
);
910 * \brief Skip wait event
911 * \param stream: - stream pointer
912 * \return 0 on success
914 int mp_dvdnav_skip_wait (stream_t
*stream
) {
915 dvdnav_priv_t
*priv
= stream
->priv
;
916 if (!(priv
->state
& NAV_FLAG_WAIT
))
918 priv
->state
&= ~NAV_FLAG_WAIT
;
919 dvdnav_wait_skip(priv
->dvdnav
);
924 * \brief Set wait mode
925 * \param stream : - stream pointer
926 * \param mode : - if true, then suspend block read
927 * \param automode: - if true, then VTS or cell change set wait mode
929 void mp_dvdnav_read_wait (stream_t
*stream
, int mode
, int automode
) {
930 dvdnav_priv_t
*priv
= stream
->priv
;
932 priv
->state
&= ~NAV_FLAG_WAIT_READ
;
934 priv
->state
|= NAV_FLAG_WAIT_READ
;
936 priv
->state
&= ~NAV_FLAG_WAIT_READ_AUTO
;
938 priv
->state
|= NAV_FLAG_WAIT_READ_AUTO
;
942 * \brief Check if cell has changed
943 * \param stream: - stream pointer
944 * \param clear : - if true, then clear cell change flag
945 * \return 1 if cell has changed
947 int mp_dvdnav_cell_has_changed (stream_t
*stream
, int clear
) {
948 dvdnav_priv_t
*priv
= stream
->priv
;
949 if (!(priv
->state
& NAV_FLAG_CELL_CHANGE
))
952 priv
->state
&= ~NAV_FLAG_CELL_CHANGE
;
953 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
959 * \brief Check if audio has changed
960 * \param stream: - stream pointer
961 * \param clear : - if true, then clear audio change flag
962 * \return 1 if audio has changed
964 int mp_dvdnav_audio_has_changed (stream_t
*stream
, int clear
) {
965 dvdnav_priv_t
*priv
= stream
->priv
;
967 if (!(priv
->state
& NAV_FLAG_AUDIO_CHANGE
))
971 priv
->state
&= ~NAV_FLAG_AUDIO_CHANGE
;
977 * \brief Check if SPU has changed
978 * \param stream: - stream pointer
979 * \param clear : - if true, then clear spu change flag
980 * \return 1 if spu has changed
982 int mp_dvdnav_spu_has_changed (stream_t
*stream
, int clear
) {
983 dvdnav_priv_t
*priv
= stream
->priv
;
985 if (!(priv
->state
& NAV_FLAG_SPU_CHANGE
))
989 priv
->state
&= ~NAV_FLAG_SPU_CHANGE
;
994 /* Notify if something has changed in stream
995 * Can be related to title, chapter, audio or SPU
997 int mp_dvdnav_stream_has_changed (stream_t
*stream
) {
998 dvdnav_priv_t
*priv
= stream
->priv
;
1000 if (!(priv
->state
& NAV_FLAG_STREAM_CHANGE
))
1003 priv
->state
&= ~NAV_FLAG_STREAM_CHANGE
;
1007 const stream_info_t stream_info_dvdnav
= {
1015 1 // Urls are an option string