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.
27 #include "osdep/timer.h"
28 #include "input/input.h"
30 #include "libmpdemux/demuxer.h"
31 #include <dvdnav/dvdnav.h>
32 #include "stream_dvdnav.h"
33 #include "libvo/video_out.h"
34 #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");
136 /* report the title?! */
137 if (dvdnav_get_title_string(priv
->dvdnav
,&title_str
)==DVDNAV_STATUS_OK
) {
138 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
,"Title: '%s'\n",title_str
);
142 //dvdnav_event_clear(priv);
147 static void dvdnav_get_highlight (dvdnav_priv_t
*priv
, int display_mode
) {
148 pci_t
*pnavpci
= NULL
;
149 dvdnav_highlight_event_t
*hlev
= &(priv
->hlev
);
152 if (!priv
|| !priv
->dvdnav
)
155 pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
159 dvdnav_get_current_highlight (priv
->dvdnav
, &(hlev
->buttonN
));
160 hlev
->display
= display_mode
; /* show */
162 if (hlev
->buttonN
> 0 && pnavpci
->hli
.hl_gi
.btn_ns
> 0 && hlev
->display
) {
163 for (btnum
= 0; btnum
< pnavpci
->hli
.hl_gi
.btn_ns
; btnum
++) {
164 btni_t
*btni
= &(pnavpci
->hli
.btnit
[btnum
]);
166 if (hlev
->buttonN
== btnum
+ 1) {
167 hlev
->sx
= FFMIN (btni
->x_start
, btni
->x_end
);
168 hlev
->ex
= FFMAX (btni
->x_start
, btni
->x_end
);
169 hlev
->sy
= FFMIN (btni
->y_start
, btni
->y_end
);
170 hlev
->ey
= FFMAX (btni
->y_start
, btni
->y_end
);
172 hlev
->palette
= (btni
->btn_coln
== 0) ? 0 :
173 pnavpci
->hli
.btn_colit
.btn_coli
[btni
->btn_coln
- 1][0];
177 } else { /* hide button or no button */
178 hlev
->sx
= hlev
->ex
= 0;
179 hlev
->sy
= hlev
->ey
= 0;
180 hlev
->palette
= hlev
->buttonN
= 0;
184 static inline int dvdnav_get_duration (int length
) {
185 return (length
== 255) ? 0 : length
* 1000;
188 static int dvdnav_stream_read(dvdnav_priv_t
* priv
, unsigned char *buf
, int *len
) {
189 int event
= DVDNAV_NOP
;
192 if (dvdnav_get_next_block(priv
->dvdnav
,buf
,&event
,len
)!=DVDNAV_STATUS_OK
) {
193 mp_msg(MSGT_OPEN
,MSGL_V
, "Error getting next block from DVD %d (%s)\n",event
, dvdnav_err_to_string(priv
->dvdnav
) );
196 else if (event
!=DVDNAV_BLOCK_OK
) {
197 // need to handle certain events internally (like skipping stills)
199 case DVDNAV_NAV_PACKET
:
201 case DVDNAV_STILL_FRAME
: {
202 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*) buf
;
203 priv
->still_length
= still_event
->length
;
204 /* set still frame duration */
205 priv
->duration
= dvdnav_get_duration (priv
->still_length
);
206 if (priv
->still_length
<= 1) {
207 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
208 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
212 case DVDNAV_HIGHLIGHT
: {
213 dvdnav_get_highlight (priv
, 1);
216 case DVDNAV_CELL_CHANGE
: {
217 dvdnav_cell_change_event_t
*ev
= (dvdnav_cell_change_event_t
*)buf
;
220 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
221 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
223 priv
->duration
= ev
->pgc_length
/90;
225 if (dvdnav_is_domain_vts(priv
->dvdnav
)) {
226 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MOVIE\n");
227 priv
->state
&= ~NAV_FLAG_VTS_DOMAIN
;
229 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "DVDNAV_TITLE_IS_MENU\n");
230 priv
->state
|= NAV_FLAG_VTS_DOMAIN
;
233 nextstill
= dvdnav_get_next_still_flag (priv
->dvdnav
);
235 priv
->duration
= dvdnav_get_duration (nextstill
);
236 priv
->still_length
= nextstill
;
237 if (priv
->still_length
<= 1) {
238 pci_t
*pnavpci
= dvdnav_get_current_nav_pci (priv
->dvdnav
);
239 priv
->duration
= mp_dvdtimetomsec (&pnavpci
->pci_gi
.e_eltm
);
245 case DVDNAV_SPU_CLUT_CHANGE
: {
246 memcpy(priv
->spu_clut
, buf
, 16*sizeof(unsigned int));
247 priv
->state
|= NAV_FLAG_SPU_SET
;
251 if ((priv
->state
& NAV_FLAG_WAIT_SKIP
) &&
252 !(priv
->state
& NAV_FLAG_WAIT
))
253 dvdnav_wait_skip (priv
->dvdnav
);
255 priv
->state
|= NAV_FLAG_WAIT
;
258 case DVDNAV_VTS_CHANGE
: {
259 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
260 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
263 case DVDNAV_SPU_STREAM_CHANGE
: {
264 priv
->state
|= NAV_FLAG_STREAM_CHANGE
;
274 static void update_title_len(stream_t
*stream
) {
275 dvdnav_priv_t
*priv
= stream
->priv
;
276 dvdnav_status_t status
;
277 uint32_t pos
= 0, len
= 0;
279 status
= dvdnav_get_position(priv
->dvdnav
, &pos
, &len
);
280 if(status
== DVDNAV_STATUS_OK
&& len
) {
281 stream
->end_pos
= (off_t
) len
* 2048;
290 static int seek(stream_t
*s
, off_t newpos
) {
292 dvdnav_priv_t
*priv
= s
->priv
;
294 if(s
->end_pos
&& newpos
> s
->end_pos
)
296 sector
= newpos
/ 2048ULL;
297 if(dvdnav_sector_search(priv
->dvdnav
, (uint64_t) sector
, SEEK_SET
) != DVDNAV_STATUS_OK
)
305 mp_msg(MSGT_STREAM
,MSGL_INFO
,"dvdnav_stream, seeking to %"PRIu64
" failed: %s\n", newpos
, dvdnav_err_to_string(priv
->dvdnav
));
310 static void stream_dvdnav_close(stream_t
*s
) {
311 dvdnav_priv_t
*priv
= s
->priv
;
312 dvdnav_close(priv
->dvdnav
);
314 dvd_set_speed(priv
->filename
, -1);
319 static int fill_buffer(stream_t
*s
, char *but
, int len
)
323 dvdnav_priv_t
* priv
=s
->priv
;
324 if (priv
->state
& NAV_FLAG_WAIT_READ
) /* read is suspended */
329 while(!len
) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
331 event
=dvdnav_stream_read(priv
, s
->buffer
, &len
);
332 if(event
==-1 || len
==-1)
334 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "DVDNAV stream read error!\n");
337 if (event
!= DVDNAV_BLOCK_OK
)
338 dvdnav_get_highlight (priv
, 1);
341 priv
->state
|= NAV_FLAG_EOF
;
344 case DVDNAV_BLOCK_OK
:
345 case DVDNAV_NAV_PACKET
:
346 case DVDNAV_STILL_FRAME
:
349 if (priv
->state
& NAV_FLAG_WAIT
)
353 case DVDNAV_VTS_CHANGE
: {
354 int tit
= 0, part
= 0;
355 dvdnav_vts_change_event_t
*vts_event
= (dvdnav_vts_change_event_t
*)s
->buffer
;
356 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "DVDNAV, switched to title: %d\r\n", vts_event
->new_vtsN
);
357 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
358 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
359 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
360 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
361 priv
->state
&= ~NAV_FLAG_WAIT
;
364 show_audio_subs_languages(priv
->dvdnav
);
365 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
366 priv
->state
|= NAV_FLAG_WAIT_READ
;
367 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
) {
368 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nDVDNAV, NEW TITLE %d\r\n", tit
);
369 dvdnav_get_highlight (priv
, 0);
370 if(priv
->title
> 0 && tit
!= priv
->title
) {
371 priv
->state
|= NAV_FLAG_EOF
;
377 case DVDNAV_CELL_CHANGE
: {
378 priv
->state
|= NAV_FLAG_CELL_CHANGE
;
379 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
380 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
381 priv
->state
&= ~NAV_FLAG_WAIT_SKIP
;
382 priv
->state
&= ~NAV_FLAG_WAIT
;
383 if (priv
->state
& NAV_FLAG_WAIT_READ_AUTO
)
384 priv
->state
|= NAV_FLAG_WAIT_READ
;
385 if(priv
->title
> 0 && dvd_last_chapter
> 0) {
387 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) == DVDNAV_STATUS_OK
&& part
> dvd_last_chapter
) {
388 priv
->state
|= NAV_FLAG_EOF
;
392 dvdnav_get_highlight (priv
, 1);
395 case DVDNAV_AUDIO_STREAM_CHANGE
:
396 priv
->state
|= NAV_FLAG_AUDIO_CHANGE
;
398 case DVDNAV_SPU_STREAM_CHANGE
:
399 priv
->state
|= NAV_FLAG_SPU_CHANGE
;
403 mp_msg(MSGT_STREAM
,MSGL_DBG2
,"DVDNAV fill_buffer len: %d\n",len
);
407 static int control(stream_t
*stream
, int cmd
, void* arg
) {
408 dvdnav_priv_t
* priv
=stream
->priv
;
413 case STREAM_CTRL_SEEK_TO_CHAPTER
:
415 int chap
= *((unsigned int *)arg
)+1;
417 if(chap
< 1 || dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
419 if(dvdnav_part_play(priv
->dvdnav
, tit
, chap
) != DVDNAV_STATUS_OK
)
423 case STREAM_CTRL_GET_NUM_CHAPTERS
:
425 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
427 if(dvdnav_get_number_of_parts(priv
->dvdnav
, tit
, &part
) != DVDNAV_STATUS_OK
)
431 *((unsigned int *)arg
) = part
;
434 case STREAM_CTRL_GET_CURRENT_CHAPTER
:
436 if(dvdnav_current_title_info(priv
->dvdnav
, &tit
, &part
) != DVDNAV_STATUS_OK
)
438 *((unsigned int *)arg
) = part
- 1;
441 case STREAM_CTRL_GET_TIME_LENGTH
:
443 if(priv
->duration
|| priv
->still_length
)
445 *((double *)arg
) = (double)priv
->duration
/ 1000.0;
450 case STREAM_CTRL_GET_ASPECT_RATIO
:
452 uint8_t ar
= dvdnav_get_video_aspect(priv
->dvdnav
);
453 *((double *)arg
) = !ar
? 4.0/3.0 : 16.0/9.0;
456 case STREAM_CTRL_GET_CURRENT_TIME
:
459 tm
= dvdnav_get_current_time(priv
->dvdnav
)/90000.0f
;
462 *((double *)arg
) = tm
;
467 case STREAM_CTRL_SEEK_TO_TIME
:
469 uint64_t tm
= (uint64_t) (*((double*)arg
) * 90000);
470 if(dvdnav_time_search(priv
->dvdnav
, tm
) == DVDNAV_STATUS_OK
)
474 case STREAM_CTRL_GET_NUM_ANGLES
:
476 uint32_t curr
, angles
;
477 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
479 *((int *)arg
) = angles
;
482 case STREAM_CTRL_GET_ANGLE
:
484 uint32_t curr
, angles
;
485 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
487 *((int *)arg
) = curr
;
490 case STREAM_CTRL_SET_ANGLE
:
492 uint32_t curr
, angles
;
493 int new_angle
= *((int *)arg
);
494 if(dvdnav_get_angle_info(priv
->dvdnav
, &curr
, &angles
) != DVDNAV_STATUS_OK
)
496 if(new_angle
>angles
|| new_angle
<1)
498 if(dvdnav_angle_change(priv
->dvdnav
, new_angle
) != DVDNAV_STATUS_OK
)
503 return STREAM_UNSUPPORTED
;
506 static void identify_chapters(dvdnav_t
*nav
, uint32_t title
)
508 uint64_t *parts
=NULL
, duration
=0;
510 n
= dvdnav_describe_title_chapters(nav
, title
, &parts
, &duration
);
513 mp_msg(MSGT_IDENTIFY
, MSGL_V
, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title
, t
/ 1000, t
% 1000);
514 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "TITLE %u, CHAPTERS: ", title
);
516 t
= parts
[i
] / 90000;
517 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "%02d:%02d:%02d,", t
/3600, (t
/60)%60, t
%60);
520 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "\n");
524 static void identify(dvdnav_priv_t
*priv
, struct stream_priv_s
*p
)
526 uint32_t titles
=0, i
;
528 dvdnav_get_number_of_titles(priv
->dvdnav
, &titles
);
529 for(i
=0; i
<titles
; i
++)
530 identify_chapters(priv
->dvdnav
, i
);
533 identify_chapters(priv
->dvdnav
, p
->track
);
536 static void show_audio_subs_languages(dvdnav_t
*nav
)
539 uint16_t i
, lang
, format
, id
, channels
;
540 int base
[7] = {128, 0, 0, 0, 160, 136, 0};
543 char tmp
[] = "unknown";
544 lg
= dvdnav_get_audio_logical_stream(nav
, i
);
545 if(lg
== 0xff) continue;
546 channels
= dvdnav_audio_stream_channels(nav
, lg
);
547 if(channels
== 0xFFFF)
548 channels
= 2; //unknown
551 lang
= dvdnav_audio_stream_to_lang(nav
, lg
);
555 tmp
[1] = lang
& 0xFF;
558 format
= dvdnav_audio_stream_format(nav
, lg
);
559 if(format
== 0xFFFF || format
> 6)
560 format
= 1; //unknown
561 id
= i
+ base
[format
];
562 mp_tmsg(MSGT_OPEN
,MSGL_STATUS
,"audio stream: %d format: %s (%s) language: %s aid: %d.\n", i
,
563 dvd_audio_stream_types
[format
], dvd_audio_stream_channels
[channels
], tmp
, id
);
564 if (lang
!= 0xFFFF && lang
&& tmp
[0])
565 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AID_%d_LANG=%s\n", id
, tmp
);
570 char tmp
[] = "unknown";
571 lg
= dvdnav_get_spu_logical_stream(nav
, i
);
572 if(lg
== 0xff) continue;
573 lang
= dvdnav_spu_stream_to_lang(nav
, i
);
577 tmp
[1] = lang
& 0xFF;
580 mp_msg(MSGT_OPEN
,MSGL_STATUS
,"subtitle ( sid ): %d language: %s\n", lg
, tmp
);
581 if (lang
!= 0xFFFF && lang
&& tmp
[0])
582 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SID_%d_LANG=%s\n", lg
, tmp
);
586 static int open_s(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
587 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
591 if(p
->device
) filename
= p
->device
;
592 else if(dvd_device
) filename
= dvd_device
;
593 else filename
= DEFAULT_DVD_DEVICE
;
594 if(!(priv
=new_dvdnav_stream(filename
))) {
595 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Couldn't open DVD device: %s (%s)\n",filename
, strerror(errno
));
596 return STREAM_UNSUPPORTED
;
600 priv
->title
= p
->track
;
601 if(dvdnav_title_play(priv
->dvdnav
, p
->track
) != DVDNAV_STATUS_OK
) {
602 mp_msg(MSGT_OPEN
,MSGL_FATAL
,"dvdnav_stream, couldn't select title %d, error '%s'\n", p
->track
, dvdnav_err_to_string(priv
->dvdnav
));
603 return STREAM_UNSUPPORTED
;
605 } else if (p
->track
== 0) {
606 if(dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Root
) != DVDNAV_STATUS_OK
)
607 dvdnav_menu_call(priv
->dvdnav
, DVD_MENU_Title
);
609 if(mp_msg_test(MSGT_IDENTIFY
, MSGL_INFO
))
612 show_audio_subs_languages(priv
->dvdnav
);
614 dvdnav_angle_change(priv
->dvdnav
, dvd_angle
);
616 stream
->sector_size
= 2048;
617 stream
->flags
= STREAM_READ
| MP_STREAM_SEEK
;
618 stream
->fill_buffer
= fill_buffer
;
620 stream
->control
= control
;
621 stream
->close
= stream_dvdnav_close
;
622 stream
->type
= STREAMTYPE_DVDNAV
;
623 stream
->priv
=(void*)priv
;
624 *file_format
= DEMUXER_TYPE_MPEG_PS
;
626 update_title_len(stream
);
627 if(!stream
->pos
&& p
->track
> 0)
628 mp_msg(MSGT_OPEN
,MSGL_ERR
, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv
->dvdnav
));
630 mp_msg(MSGT_OPEN
,MSGL_INFO
, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
636 void mp_dvdnav_handle_input(stream_t
*stream
, int cmd
, int *button
) {
637 dvdnav_priv_t
* priv
= stream
->priv
;
638 dvdnav_t
*nav
= priv
->dvdnav
;
639 dvdnav_status_t status
=DVDNAV_STATUS_ERR
;
640 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
642 if(cmd
!= MP_CMD_DVDNAV_SELECT
&& !pci
)
646 case MP_CMD_DVDNAV_UP
:
647 status
= dvdnav_upper_button_select(nav
, pci
);
649 case MP_CMD_DVDNAV_DOWN
:
650 status
= dvdnav_lower_button_select(nav
, pci
);
652 case MP_CMD_DVDNAV_LEFT
:
653 status
= dvdnav_left_button_select(nav
, pci
);
655 case MP_CMD_DVDNAV_RIGHT
:
656 status
= dvdnav_right_button_select(nav
, pci
);
658 case MP_CMD_DVDNAV_MENU
:
659 status
= dvdnav_menu_call(nav
,DVD_MENU_Root
);
661 case MP_CMD_DVDNAV_PREVMENU
: {
664 dvdnav_current_title_info(nav
, &title
, &part
);
666 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Part
)) == DVDNAV_STATUS_OK
)
669 if((status
=dvdnav_menu_call(nav
, DVD_MENU_Title
)) == DVDNAV_STATUS_OK
)
671 status
=dvdnav_menu_call(nav
, DVD_MENU_Root
);
674 case MP_CMD_DVDNAV_SELECT
:
675 status
= dvdnav_button_activate(nav
, pci
);
677 case MP_CMD_DVDNAV_MOUSECLICK
:
679 this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
680 should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
681 and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
682 the coodinates saved by mp_dvdnav_update_mouse_pos().
683 This last call always works well
685 status
= dvdnav_mouse_activate(nav
, pci
, priv
->mousex
, priv
->mousey
);
688 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Unknown DVDNAV cmd %d\n", cmd
);
692 if(status
== DVDNAV_STATUS_OK
)
693 dvdnav_get_current_highlight(nav
, button
);
696 void mp_dvdnav_update_mouse_pos(stream_t
*stream
, int32_t x
, int32_t y
, int* button
) {
697 dvdnav_priv_t
* priv
= stream
->priv
;
698 dvdnav_t
*nav
= priv
->dvdnav
;
699 dvdnav_status_t status
;
700 pci_t
*pci
= dvdnav_get_current_nav_pci(nav
);
704 status
= dvdnav_mouse_select(nav
, pci
, x
, y
);
705 if(status
== DVDNAV_STATUS_OK
) dvdnav_get_current_highlight(nav
, button
);
711 static int mp_dvdnav_get_aid_from_format (stream_t
*stream
, int index
, uint8_t lg
) {
712 dvdnav_priv_t
* priv
= stream
->priv
;
715 format
= dvdnav_audio_stream_format(priv
->dvdnav
, lg
);
717 case DVDNAV_FORMAT_AC3
:
719 case DVDNAV_FORMAT_DTS
:
721 case DVDNAV_FORMAT_LPCM
:
723 case DVDNAV_FORMAT_MPEGAUDIO
:
733 * \brief mp_dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
734 * \param stream: - stream pointer
735 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
736 * \return -1 on error, current subtitle id if successful
738 int mp_dvdnav_aid_from_lang(stream_t
*stream
, unsigned char *language
) {
739 dvdnav_priv_t
* priv
= stream
->priv
;
742 uint16_t lang
, lcode
;
744 while(language
&& strlen(language
)>=2) {
745 lcode
= (language
[0] << 8) | (language
[1]);
746 for(k
=0; k
<32; k
++) {
747 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, k
);
748 if(lg
== 0xff) continue;
749 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
750 if(lang
!= 0xFFFF && lang
== lcode
)
751 return mp_dvdnav_get_aid_from_format (stream
, k
, lg
);
754 while(language
[0]==',' || language
[0]==' ') ++language
;
760 * \brief mp_dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
761 * \param stream: - stream pointer
762 * \param sid: physical subtitle id
763 * \param buf: buffer to contain the 2-chars language string
764 * \return 0 on error, 1 if successful
766 int mp_dvdnav_lang_from_aid(stream_t
*stream
, int aid
, unsigned char *buf
) {
769 dvdnav_priv_t
* priv
= stream
->priv
;
773 lg
= dvdnav_get_audio_logical_stream(priv
->dvdnav
, aid
& 0x7);
774 if(lg
== 0xff) return 0;
775 lang
= dvdnav_audio_stream_to_lang(priv
->dvdnav
, lg
);
776 if(lang
== 0xffff) return 0;
778 buf
[1] = lang
& 0xFF;
785 * \brief mp_dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
786 * \param stream: - stream pointer
787 * \param lang: 2-characters language code[s], eventually separated by spaces of commas
788 * \return -1 on error, current subtitle id if successful
790 int mp_dvdnav_sid_from_lang(stream_t
*stream
, unsigned char *language
) {
791 dvdnav_priv_t
* priv
= stream
->priv
;
793 uint16_t lang
, lcode
;
795 while(language
&& strlen(language
)>=2) {
796 lcode
= (language
[0] << 8) | (language
[1]);
797 for(k
=0; k
<32; k
++) {
798 lg
= dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
);
799 if(lg
== 0xff) continue;
800 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, k
);
801 if(lang
!= 0xFFFF && lang
== lcode
) {
806 while(language
[0]==',' || language
[0]==' ') ++language
;
812 * \brief mp_dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
813 * \param stream: - stream pointer
814 * \param sid: physical subtitle id
815 * \param buf: buffer to contain the 2-chars language string
816 * \return 0 on error, 1 if successful
818 int mp_dvdnav_lang_from_sid(stream_t
*stream
, int sid
, unsigned char *buf
) {
821 dvdnav_priv_t
*priv
= stream
->priv
;
822 if(sid
< 0) return 0;
824 if (dvdnav_get_spu_logical_stream(priv
->dvdnav
, k
) == sid
)
828 lang
= dvdnav_spu_stream_to_lang(priv
->dvdnav
, k
);
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;
849 if(lg
>= n
) n
= lg
+ 1;
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