2002-04-03 17:50:48 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2007-11-16 21:32:09 +00:00
|
|
|
#include <errno.h>
|
2002-04-03 17:50:48 +00:00
|
|
|
#include "mp_msg.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "osdep/timer.h"
|
|
|
|
#include "input/input.h"
|
2002-04-03 17:50:48 +00:00
|
|
|
#include "stream.h"
|
2006-08-04 17:01:29 +00:00
|
|
|
#include "libmpdemux/demuxer.h"
|
2008-01-01 17:34:57 +00:00
|
|
|
#include <dvdnav/dvdnav.h>
|
2006-08-03 20:44:14 +00:00
|
|
|
#include "stream_dvdnav.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libvo/video_out.h"
|
2006-11-25 11:20:02 +00:00
|
|
|
#include "libavutil/common.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "spudec.h"
|
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
2006-06-14 21:58:17 +00:00
|
|
|
#include "help_mp.h"
|
2008-01-26 11:51:34 +00:00
|
|
|
#include "stream_dvd_common.h"
|
|
|
|
|
|
|
|
/* state flags */
|
|
|
|
typedef enum {
|
|
|
|
NAV_FLAG_EOF = 1 << 0, /* end of stream has been reached */
|
|
|
|
NAV_FLAG_WAIT = 1 << 1, /* wait event */
|
|
|
|
NAV_FLAG_WAIT_SKIP = 1 << 2, /* wait skip disable */
|
|
|
|
NAV_FLAG_CELL_CHANGED = 1 << 3, /* cell change event */
|
|
|
|
NAV_FLAG_WAIT_READ_AUTO = 1 << 4, /* wait read auto mode */
|
|
|
|
NAV_FLAG_WAIT_READ = 1 << 5, /* suspend read from stream */
|
|
|
|
NAV_FLAG_VTS_DOMAIN = 1 << 6, /* vts domain */
|
2008-01-26 13:06:42 +00:00
|
|
|
NAV_FLAG_SPU_SET = 1 << 7, /* spu_clut is valid */
|
2008-01-26 16:17:44 +00:00
|
|
|
NAV_FLAG_STREAM_CHANGE = 1 << 8, /* title, chapter, audio or SPU */
|
2008-01-26 11:51:34 +00:00
|
|
|
} dvdnav_state_t;
|
2006-06-14 21:58:17 +00:00
|
|
|
|
2008-01-01 17:01:03 +00:00
|
|
|
typedef struct {
|
|
|
|
dvdnav_t * dvdnav; /* handle to libdvdnav stuff */
|
|
|
|
char * filename; /* path */
|
|
|
|
unsigned int duration; /* in milliseconds */
|
|
|
|
int mousex, mousey;
|
|
|
|
int title;
|
2008-01-26 13:06:42 +00:00
|
|
|
unsigned int spu_clut[16];
|
2008-01-01 17:01:03 +00:00
|
|
|
dvdnav_highlight_event_t hlev;
|
2008-01-26 11:51:34 +00:00
|
|
|
int still_length; /* still frame duration */
|
|
|
|
unsigned int state;
|
2008-01-01 17:01:03 +00:00
|
|
|
} dvdnav_priv_t;
|
|
|
|
|
2006-06-14 21:58:17 +00:00
|
|
|
extern char *dvd_device;
|
|
|
|
extern char *audio_lang, *dvdsub_lang;
|
2007-12-01 11:35:03 +00:00
|
|
|
extern char *dvd_audio_stream_channels[6], *dvd_audio_stream_types[8];
|
2005-05-19 19:50:39 +00:00
|
|
|
|
|
|
|
static struct stream_priv_s {
|
|
|
|
int track;
|
|
|
|
char* device;
|
|
|
|
} stream_priv_dflts = {
|
2006-09-09 20:51:29 +00:00
|
|
|
0,
|
2005-05-19 19:50:39 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
|
|
|
|
/// URL definition
|
2007-12-02 21:37:08 +00:00
|
|
|
static const m_option_t stream_opts_fields[] = {
|
2006-06-14 21:58:17 +00:00
|
|
|
{"filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{"hostname", ST_OFF(track), CONF_TYPE_INT, 0, 0, 0, NULL},
|
2005-05-19 19:50:39 +00:00
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
2008-01-13 12:34:42 +00:00
|
|
|
static const struct m_struct_st stream_opts = {
|
2005-05-19 19:50:39 +00:00
|
|
|
"dvd",
|
|
|
|
sizeof(struct stream_priv_s),
|
|
|
|
&stream_priv_dflts,
|
|
|
|
stream_opts_fields
|
|
|
|
};
|
2002-04-03 17:50:48 +00:00
|
|
|
|
2006-09-18 21:12:22 +00:00
|
|
|
static int seek(stream_t *s, off_t newpos);
|
|
|
|
|
2006-09-20 21:09:32 +00:00
|
|
|
static dvdnav_priv_t * new_dvdnav_stream(char * filename) {
|
2008-01-24 19:18:15 +00:00
|
|
|
const char * title_str;
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_priv_t *priv;
|
2002-04-03 17:50:48 +00:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return NULL;
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
if (!(priv=calloc(1,sizeof(dvdnav_priv_t))))
|
2002-04-03 17:50:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
if (!(priv->filename=strdup(filename))) {
|
|
|
|
free(priv);
|
2002-04-03 17:50:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_open(&(priv->dvdnav),priv->filename)!=DVDNAV_STATUS_OK)
|
2002-04-03 17:50:48 +00:00
|
|
|
{
|
2006-11-09 22:24:57 +00:00
|
|
|
free(priv->filename);
|
|
|
|
free(priv);
|
2002-04-03 17:50:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
if (!priv->dvdnav) {
|
|
|
|
free(priv);
|
2002-04-03 17:50:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-14 21:58:17 +00:00
|
|
|
if(1) //from vlc: if not used dvdnav from cvs will fail
|
|
|
|
{
|
|
|
|
int len, event;
|
|
|
|
char buf[2048];
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_get_next_block(priv->dvdnav,buf,&event,&len);
|
|
|
|
dvdnav_sector_search(priv->dvdnav, 0, SEEK_SET);
|
2006-06-14 21:58:17 +00:00
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2006-08-19 20:06:10 +00:00
|
|
|
/* turn off dvdnav caching */
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_set_readahead_flag(priv->dvdnav, 0);
|
|
|
|
if(dvdnav_set_PGC_positioning_flag(priv->dvdnav, 1) != DVDNAV_STATUS_OK)
|
2006-06-14 21:58:17 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"stream_dvdnav, failed to set PGC positioning\n");
|
|
|
|
#if 1
|
2002-04-03 17:50:48 +00:00
|
|
|
/* report the title?! */
|
2006-11-09 22:24:57 +00:00
|
|
|
if (dvdnav_get_title_string(priv->dvdnav,&title_str)==DVDNAV_STATUS_OK) {
|
2006-06-14 21:58:17 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO,"Title: '%s'\n",title_str);
|
2002-04-03 17:50:48 +00:00
|
|
|
}
|
2006-06-14 21:58:17 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
//dvdnav_event_clear(priv);
|
2002-04-03 17:50:48 +00:00
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
return priv;
|
2002-04-03 17:50:48 +00:00
|
|
|
}
|
|
|
|
|
2006-11-25 17:44:22 +00:00
|
|
|
static void dvdnav_get_highlight (dvdnav_priv_t *priv, int display_mode) {
|
2006-11-25 11:20:02 +00:00
|
|
|
pci_t *pnavpci = NULL;
|
2006-11-25 17:44:22 +00:00
|
|
|
dvdnav_highlight_event_t *hlev = &(priv->hlev);
|
|
|
|
int btnum;
|
2006-11-25 12:19:15 +00:00
|
|
|
|
2006-11-25 17:44:22 +00:00
|
|
|
if (!priv || !priv->dvdnav)
|
2006-11-25 11:20:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pnavpci = dvdnav_get_current_nav_pci (priv->dvdnav);
|
|
|
|
if (!pnavpci)
|
|
|
|
return;
|
2006-11-25 12:19:15 +00:00
|
|
|
|
2006-11-25 11:20:02 +00:00
|
|
|
dvdnav_get_current_highlight (priv->dvdnav, &(hlev->buttonN));
|
|
|
|
hlev->display = display_mode; /* show */
|
2006-11-25 12:19:15 +00:00
|
|
|
|
2006-11-25 11:20:02 +00:00
|
|
|
if (hlev->buttonN > 0 && pnavpci->hli.hl_gi.btn_ns > 0 && hlev->display) {
|
|
|
|
for (btnum = 0; btnum < pnavpci->hli.hl_gi.btn_ns; btnum++) {
|
|
|
|
btni_t *btni = &(pnavpci->hli.btnit[btnum]);
|
|
|
|
|
|
|
|
if (hlev->buttonN == btnum + 1) {
|
|
|
|
hlev->sx = FFMIN (btni->x_start, btni->x_end);
|
|
|
|
hlev->ex = FFMAX (btni->x_start, btni->x_end);
|
|
|
|
hlev->sy = FFMIN (btni->y_start, btni->y_end);
|
|
|
|
hlev->ey = FFMAX (btni->y_start, btni->y_end);
|
|
|
|
|
|
|
|
hlev->palette = (btni->btn_coln == 0) ? 0 :
|
|
|
|
pnavpci->hli.btn_colit.btn_coli[btni->btn_coln - 1][0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* hide button or no button */
|
|
|
|
hlev->sx = hlev->ex = 0;
|
|
|
|
hlev->sy = hlev->ey = 0;
|
|
|
|
hlev->palette = hlev->buttonN = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-26 11:51:34 +00:00
|
|
|
static inline int dvdnav_get_duration (int length) {
|
|
|
|
return (length == 255) ? 0 : length * 1000;
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
static int dvdnav_stream_read(dvdnav_priv_t * priv, unsigned char *buf, int *len) {
|
2002-04-03 17:50:48 +00:00
|
|
|
int event = DVDNAV_NOP;
|
|
|
|
|
|
|
|
*len=-1;
|
2006-11-09 22:24:57 +00:00
|
|
|
if (dvdnav_get_next_block(priv->dvdnav,buf,&event,len)!=DVDNAV_STATUS_OK) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "Error getting next block from DVD %d (%s)\n",event, dvdnav_err_to_string(priv->dvdnav) );
|
2002-04-03 17:50:48 +00:00
|
|
|
*len=-1;
|
|
|
|
}
|
|
|
|
else if (event!=DVDNAV_BLOCK_OK) {
|
|
|
|
// need to handle certain events internally (like skipping stills)
|
|
|
|
switch (event) {
|
2006-11-27 23:21:23 +00:00
|
|
|
case DVDNAV_NAV_PACKET:
|
|
|
|
return event;
|
2006-11-08 23:05:33 +00:00
|
|
|
case DVDNAV_STILL_FRAME: {
|
2008-01-26 11:51:34 +00:00
|
|
|
dvdnav_still_event_t *still_event = (dvdnav_still_event_t *) buf;
|
|
|
|
priv->still_length = still_event->length;
|
|
|
|
/* set still frame duration */
|
|
|
|
priv->duration = dvdnav_get_duration (priv->still_length);
|
|
|
|
if (priv->still_length <= 1) {
|
|
|
|
pci_t *pnavpci = dvdnav_get_current_nav_pci (priv->dvdnav);
|
|
|
|
priv->duration = mp_dvdtimetomsec (&pnavpci->pci_gi.e_eltm);
|
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-11-25 11:20:02 +00:00
|
|
|
case DVDNAV_HIGHLIGHT: {
|
2006-11-25 17:44:22 +00:00
|
|
|
dvdnav_get_highlight (priv, 1);
|
2006-11-25 11:20:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
case DVDNAV_CELL_CHANGE: {
|
2006-08-19 19:41:04 +00:00
|
|
|
dvdnav_cell_change_event_t *ev = (dvdnav_cell_change_event_t*)buf;
|
2008-01-26 11:51:34 +00:00
|
|
|
uint32_t nextstill;
|
|
|
|
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_SKIP;
|
2008-01-26 16:17:44 +00:00
|
|
|
priv->state |= NAV_FLAG_STREAM_CHANGE;
|
2006-08-19 19:41:04 +00:00
|
|
|
if(ev->pgc_length)
|
2006-11-09 22:24:57 +00:00
|
|
|
priv->duration = ev->pgc_length/90;
|
2008-01-26 11:51:34 +00:00
|
|
|
|
|
|
|
if (dvdnav_is_domain_vts(priv->dvdnav))
|
|
|
|
priv->state &= ~NAV_FLAG_VTS_DOMAIN;
|
|
|
|
else
|
|
|
|
priv->state |= NAV_FLAG_VTS_DOMAIN;
|
|
|
|
|
|
|
|
nextstill = dvdnav_get_next_still_flag (priv->dvdnav);
|
|
|
|
if (nextstill) {
|
|
|
|
priv->duration = dvdnav_get_duration (nextstill);
|
|
|
|
priv->still_length = nextstill;
|
|
|
|
if (priv->still_length <= 1) {
|
|
|
|
pci_t *pnavpci = dvdnav_get_current_nav_pci (priv->dvdnav);
|
|
|
|
priv->duration = mp_dvdtimetomsec (&pnavpci->pci_gi.e_eltm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 19:41:04 +00:00
|
|
|
break;
|
2006-11-08 23:05:33 +00:00
|
|
|
}
|
2006-12-09 19:23:35 +00:00
|
|
|
case DVDNAV_SPU_CLUT_CHANGE: {
|
|
|
|
memcpy(priv->spu_clut, buf, 16*sizeof(unsigned int));
|
2008-01-26 13:06:42 +00:00
|
|
|
priv->state |= NAV_FLAG_SPU_SET;
|
2006-12-09 19:23:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-26 11:51:34 +00:00
|
|
|
case DVDNAV_WAIT: {
|
|
|
|
if ((priv->state & NAV_FLAG_WAIT_SKIP) &&
|
|
|
|
!(priv->state & NAV_FLAG_WAIT))
|
|
|
|
dvdnav_wait_skip (priv->dvdnav);
|
|
|
|
else
|
|
|
|
priv->state |= NAV_FLAG_WAIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DVDNAV_VTS_CHANGE: {
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_SKIP;
|
2008-01-26 16:17:44 +00:00
|
|
|
priv->state |= NAV_FLAG_STREAM_CHANGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DVDNAV_SPU_STREAM_CHANGE: {
|
|
|
|
priv->state |= NAV_FLAG_STREAM_CHANGE;
|
2006-07-04 21:12:12 +00:00
|
|
|
break;
|
2008-01-26 11:51:34 +00:00
|
|
|
}
|
2002-04-03 17:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*len=0;
|
|
|
|
}
|
2006-06-14 21:58:17 +00:00
|
|
|
return event;
|
2002-04-03 17:50:48 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 21:58:17 +00:00
|
|
|
static void update_title_len(stream_t *stream) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
dvdnav_status_t status;
|
|
|
|
uint32_t pos = 0, len = 0;
|
|
|
|
|
|
|
|
status = dvdnav_get_position(priv->dvdnav, &pos, &len);
|
2006-09-18 21:12:22 +00:00
|
|
|
if(status == DVDNAV_STATUS_OK && len) {
|
2006-06-14 21:58:17 +00:00
|
|
|
stream->end_pos = (off_t) len * 2048;
|
2006-09-18 21:12:22 +00:00
|
|
|
stream->seek = seek;
|
|
|
|
} else {
|
|
|
|
stream->seek = NULL;
|
|
|
|
stream->end_pos = 0;
|
|
|
|
}
|
2002-04-03 17:50:48 +00:00
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2005-05-19 19:50:39 +00:00
|
|
|
|
|
|
|
static int seek(stream_t *s, off_t newpos) {
|
2007-08-04 21:16:22 +00:00
|
|
|
uint32_t sector = 0;
|
2006-11-08 23:05:33 +00:00
|
|
|
dvdnav_priv_t *priv = s->priv;
|
|
|
|
|
|
|
|
if(s->end_pos && newpos > s->end_pos)
|
|
|
|
newpos = s->end_pos;
|
|
|
|
sector = newpos / 2048ULL;
|
|
|
|
if(dvdnav_sector_search(priv->dvdnav, (uint64_t) sector, SEEK_SET) != DVDNAV_STATUS_OK)
|
|
|
|
goto fail;
|
2006-06-14 21:58:17 +00:00
|
|
|
|
2006-11-08 23:05:33 +00:00
|
|
|
s->pos = newpos;
|
2006-06-14 21:58:17 +00:00
|
|
|
|
|
|
|
return 1;
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2006-06-14 21:58:17 +00:00
|
|
|
fail:
|
2006-11-08 23:05:33 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_INFO,"dvdnav_stream, seeking to %"PRIu64" failed: %s\n", newpos, dvdnav_err_to_string(priv->dvdnav));
|
2005-05-19 19:50:39 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-06-14 21:58:17 +00:00
|
|
|
static void stream_dvdnav_close(stream_t *s) {
|
|
|
|
dvdnav_priv_t *priv = s->priv;
|
|
|
|
dvdnav_close(priv->dvdnav);
|
|
|
|
priv->dvdnav = NULL;
|
|
|
|
free(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int fill_buffer(stream_t *s, char *but, int len)
|
|
|
|
{
|
|
|
|
int event;
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_priv_t* priv=s->priv;
|
2008-01-26 11:51:34 +00:00
|
|
|
if (priv->state & NAV_FLAG_WAIT_READ) /* read is suspended */
|
|
|
|
return -1;
|
2006-06-14 21:58:17 +00:00
|
|
|
len=0;
|
|
|
|
if(!s->end_pos)
|
|
|
|
update_title_len(s);
|
|
|
|
while(!len) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */
|
|
|
|
{
|
2006-11-09 22:41:45 +00:00
|
|
|
event=dvdnav_stream_read(priv, s->buffer, &len);
|
|
|
|
if(event==-1 || len==-1)
|
2006-11-08 23:05:33 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_ERR, "DVDNAV stream read error!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-26 12:54:14 +00:00
|
|
|
if (event != DVDNAV_BLOCK_OK)
|
|
|
|
dvdnav_get_highlight (priv, 1);
|
2006-11-08 23:05:33 +00:00
|
|
|
switch (event) {
|
2008-01-26 11:51:34 +00:00
|
|
|
case DVDNAV_STOP: {
|
|
|
|
priv->state |= NAV_FLAG_EOF;
|
|
|
|
return len;
|
|
|
|
}
|
2006-11-27 23:25:08 +00:00
|
|
|
case DVDNAV_BLOCK_OK:
|
|
|
|
case DVDNAV_NAV_PACKET:
|
2008-01-26 11:51:34 +00:00
|
|
|
case DVDNAV_STILL_FRAME:
|
2006-11-27 23:25:08 +00:00
|
|
|
return len;
|
2008-01-26 11:51:34 +00:00
|
|
|
case DVDNAV_WAIT: {
|
|
|
|
if (priv->state & NAV_FLAG_WAIT)
|
|
|
|
return len;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
case DVDNAV_VTS_CHANGE: {
|
|
|
|
int tit = 0, part = 0;
|
2007-04-22 10:27:44 +00:00
|
|
|
dvdnav_vts_change_event_t *vts_event = (dvdnav_vts_change_event_t *)s->buffer;
|
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_INFO, "DVDNAV, switched to title: %d\r\n", vts_event->new_vtsN);
|
2008-01-26 11:51:34 +00:00
|
|
|
priv->state |= NAV_FLAG_CELL_CHANGED;
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_SKIP;
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT;
|
2006-11-08 23:05:33 +00:00
|
|
|
s->end_pos = 0;
|
|
|
|
update_title_len(s);
|
2008-01-26 11:51:34 +00:00
|
|
|
if (priv->state & NAV_FLAG_WAIT_READ_AUTO)
|
|
|
|
priv->state |= NAV_FLAG_WAIT_READ;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK) {
|
2006-11-08 23:05:33 +00:00
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nDVDNAV, NEW TITLE %d\r\n", tit);
|
2006-11-25 17:44:22 +00:00
|
|
|
dvdnav_get_highlight (priv, 0);
|
2006-11-09 22:24:57 +00:00
|
|
|
if(priv->title > 0 && tit != priv->title)
|
2006-11-08 23:05:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-14 21:58:17 +00:00
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
case DVDNAV_CELL_CHANGE: {
|
2008-01-26 11:51:34 +00:00
|
|
|
priv->state |= NAV_FLAG_CELL_CHANGED;
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_SKIP;
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT;
|
|
|
|
if (priv->state & NAV_FLAG_WAIT_READ_AUTO)
|
|
|
|
priv->state |= NAV_FLAG_WAIT_READ;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(priv->title > 0 && dvd_last_chapter > 0) {
|
2006-11-08 23:05:33 +00:00
|
|
|
int tit=0, part=0;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK && part > dvd_last_chapter)
|
2006-11-08 23:05:33 +00:00
|
|
|
return 0;
|
2008-01-26 12:54:44 +00:00
|
|
|
}
|
2008-01-26 12:54:14 +00:00
|
|
|
dvdnav_get_highlight (priv, 1);
|
2006-06-14 21:58:17 +00:00
|
|
|
}
|
2006-11-08 23:05:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-06-14 21:58:17 +00:00
|
|
|
}
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_DBG2,"DVDNAV fill_buffer len: %d\n",len);
|
|
|
|
return len;
|
2005-05-19 19:50:39 +00:00
|
|
|
}
|
|
|
|
|
2006-08-19 11:49:04 +00:00
|
|
|
static int control(stream_t *stream, int cmd, void* arg) {
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_priv_t* priv=stream->priv;
|
2006-08-19 11:49:04 +00:00
|
|
|
int tit, part;
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case STREAM_CTRL_SEEK_TO_CHAPTER:
|
|
|
|
{
|
|
|
|
int chap = *((unsigned int *)arg)+1;
|
|
|
|
|
2006-11-09 22:24:57 +00:00
|
|
|
if(chap < 1 || dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
2006-08-19 11:49:04 +00:00
|
|
|
break;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_part_play(priv->dvdnav, tit, chap) != DVDNAV_STATUS_OK)
|
2006-08-19 11:49:04 +00:00
|
|
|
break;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-21 19:16:39 +00:00
|
|
|
case STREAM_CTRL_GET_NUM_CHAPTERS:
|
|
|
|
{
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
2006-08-21 19:16:39 +00:00
|
|
|
break;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_get_number_of_parts(priv->dvdnav, tit, &part) != DVDNAV_STATUS_OK)
|
2006-08-21 19:16:39 +00:00
|
|
|
break;
|
|
|
|
if(!part)
|
|
|
|
break;
|
|
|
|
*((unsigned int *)arg) = part;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-19 11:49:04 +00:00
|
|
|
case STREAM_CTRL_GET_CURRENT_CHAPTER:
|
|
|
|
{
|
2006-11-09 22:24:57 +00:00
|
|
|
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
2006-08-19 11:49:04 +00:00
|
|
|
break;
|
|
|
|
*((unsigned int *)arg) = part - 1;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-19 19:41:04 +00:00
|
|
|
case STREAM_CTRL_GET_TIME_LENGTH:
|
|
|
|
{
|
2008-01-26 11:51:34 +00:00
|
|
|
if(priv->duration || priv->still_length)
|
2006-11-08 23:05:33 +00:00
|
|
|
{
|
2006-11-12 17:19:56 +00:00
|
|
|
*((double *)arg) = (double)priv->duration / 1000.0;
|
2006-11-08 23:05:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2006-08-19 19:41:04 +00:00
|
|
|
}
|
2007-09-01 21:00:18 +00:00
|
|
|
case STREAM_CTRL_GET_ASPECT_RATIO:
|
|
|
|
{
|
|
|
|
uint8_t ar = dvdnav_get_video_aspect(priv->dvdnav);
|
|
|
|
*((double *)arg) = !ar ? 4.0/3.0 : 16.0/9.0;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-04-09 16:05:58 +00:00
|
|
|
case STREAM_CTRL_GET_CURRENT_TIME:
|
|
|
|
{
|
|
|
|
double tm;
|
|
|
|
tm = dvdnav_get_current_time(priv->dvdnav)/90000.0f;
|
|
|
|
if(tm != -1)
|
|
|
|
{
|
|
|
|
*((double *)arg) = tm;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SEEK_TO_TIME:
|
|
|
|
{
|
|
|
|
uint64_t tm = (uint64_t) (*((double*)arg) * 90000);
|
|
|
|
if(dvdnav_time_search(priv->dvdnav, tm) == DVDNAV_STATUS_OK)
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-05 14:22:48 +00:00
|
|
|
case STREAM_CTRL_GET_NUM_ANGLES:
|
|
|
|
{
|
|
|
|
uint32_t curr, angles;
|
|
|
|
if(dvdnav_get_angle_info(priv->dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*((int *)arg) = angles;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_ANGLE:
|
|
|
|
{
|
|
|
|
uint32_t curr, angles;
|
|
|
|
if(dvdnav_get_angle_info(priv->dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*((int *)arg) = curr;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SET_ANGLE:
|
|
|
|
{
|
|
|
|
uint32_t curr, angles;
|
|
|
|
int new_angle = *((int *)arg);
|
|
|
|
if(dvdnav_get_angle_info(priv->dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if(new_angle>angles || new_angle<1)
|
|
|
|
break;
|
|
|
|
if(dvdnav_angle_change(priv->dvdnav, new_angle) != DVDNAV_STATUS_OK)
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-19 11:49:04 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2006-08-19 11:49:04 +00:00
|
|
|
}
|
|
|
|
|
2007-11-28 23:50:05 +00:00
|
|
|
static void identify_chapters(dvdnav_t *nav, uint32_t title)
|
|
|
|
{
|
2007-11-29 23:25:14 +00:00
|
|
|
uint64_t *parts=NULL, duration=0;
|
2007-11-28 23:50:05 +00:00
|
|
|
uint32_t n, i, t;
|
2007-11-29 23:25:14 +00:00
|
|
|
n = dvdnav_describe_title_chapters(nav, title, &parts, &duration);
|
2007-11-28 23:50:05 +00:00
|
|
|
if(parts) {
|
2007-11-29 23:25:14 +00:00
|
|
|
t = duration / 90;
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title, t / 1000, t % 1000);
|
2007-11-29 00:13:11 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "TITLE %u, CHAPTERS: ", title);
|
2007-11-28 23:50:05 +00:00
|
|
|
for(i=0; i<n; i++) {
|
|
|
|
t = parts[i] / 90000;
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "%02d:%02d:%02d,", t/3600, (t/60)%60, t%60);
|
|
|
|
}
|
|
|
|
free(parts);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-29 23:01:46 +00:00
|
|
|
static void identify(dvdnav_priv_t *priv, struct stream_priv_s *p)
|
|
|
|
{
|
|
|
|
uint32_t titles=0, i;
|
|
|
|
if(p->track <= 0) {
|
|
|
|
dvdnav_get_number_of_titles(priv->dvdnav, &titles);
|
|
|
|
for(i=0; i<titles; i++)
|
|
|
|
identify_chapters(priv->dvdnav, i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
identify_chapters(priv->dvdnav, p->track);
|
|
|
|
}
|
|
|
|
|
2007-12-01 11:35:03 +00:00
|
|
|
static void show_audio_subs_languages(dvdnav_t *nav)
|
|
|
|
{
|
|
|
|
uint8_t lg;
|
|
|
|
uint16_t i, lang, format, id, channels;
|
2008-01-24 19:20:19 +00:00
|
|
|
int base[7] = {128, 0, 0, 0, 160, 136, 0};
|
2007-12-01 11:35:03 +00:00
|
|
|
char tmp[3];
|
|
|
|
for(i=0; i<8; i++)
|
|
|
|
{
|
|
|
|
lg = dvdnav_get_audio_logical_stream(nav, i);
|
|
|
|
if(lg == 0xff) continue;
|
|
|
|
channels = dvdnav_audio_stream_channels(nav, lg);
|
|
|
|
if(channels == 0xFFFF)
|
|
|
|
channels = 2; //unknown
|
|
|
|
else
|
|
|
|
channels--;
|
|
|
|
lang = dvdnav_audio_stream_to_lang(nav, lg);
|
|
|
|
if(lang == 0xFFFF)
|
|
|
|
tmp[0] = tmp[1] = '?';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp[0] = lang >> 8;
|
|
|
|
tmp[1] = lang & 0xFF;
|
|
|
|
}
|
|
|
|
tmp[2] = 0;
|
|
|
|
format = dvdnav_audio_stream_format(nav, lg);
|
|
|
|
if(format == 0xFFFF || format > 6)
|
|
|
|
format = 1; //unknown
|
|
|
|
id = i + base[format];
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDaudioStreamInfo, i,
|
|
|
|
dvd_audio_stream_types[format], dvd_audio_stream_channels[channels], tmp, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<32; i++)
|
|
|
|
{
|
|
|
|
lg = dvdnav_get_spu_logical_stream(nav, i);
|
|
|
|
if(lg == 0xff) continue;
|
|
|
|
lang = dvdnav_spu_stream_to_lang(nav, lg);
|
|
|
|
if(lang == 0xFFFF)
|
|
|
|
tmp[0] = tmp[1] = '?';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp[0] = lang >> 8;
|
|
|
|
tmp[1] = lang & 0xFF;
|
|
|
|
}
|
|
|
|
tmp[2] = 0;
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDsubtitleLanguage, i+0x20, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-19 19:50:39 +00:00
|
|
|
static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
|
|
|
|
struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
2006-06-14 21:58:17 +00:00
|
|
|
char *filename;
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_priv_t *priv;
|
2006-06-14 21:58:17 +00:00
|
|
|
|
|
|
|
if(p->device) filename = p->device;
|
|
|
|
else if(dvd_device) filename= dvd_device;
|
|
|
|
else filename = DEFAULT_DVD_DEVICE;
|
2006-11-09 22:24:57 +00:00
|
|
|
if(!(priv=new_dvdnav_stream(filename))) {
|
2007-11-16 21:32:09 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,filename, strerror(errno));
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2006-06-14 21:58:17 +00:00
|
|
|
}
|
2005-05-19 19:50:39 +00:00
|
|
|
|
2006-09-09 20:51:29 +00:00
|
|
|
if(p->track > 0) {
|
2006-11-09 22:24:57 +00:00
|
|
|
priv->title = p->track;
|
|
|
|
if(dvdnav_title_play(priv->dvdnav, p->track) != DVDNAV_STATUS_OK) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_FATAL,"dvdnav_stream, couldn't select title %d, error '%s'\n", p->track, dvdnav_err_to_string(priv->dvdnav));
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2006-11-08 23:05:33 +00:00
|
|
|
}
|
2008-01-26 11:51:34 +00:00
|
|
|
} else if (p->track == 0) {
|
|
|
|
if(dvdnav_menu_call(priv->dvdnav, DVD_MENU_Root) != DVDNAV_STATUS_OK)
|
|
|
|
dvdnav_menu_call(priv->dvdnav, DVD_MENU_Title);
|
2006-09-15 22:43:48 +00:00
|
|
|
}
|
2007-11-29 23:01:46 +00:00
|
|
|
if(mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
|
|
|
|
identify(priv, p);
|
2007-12-01 11:35:03 +00:00
|
|
|
if(p->track > 0)
|
|
|
|
show_audio_subs_languages(priv->dvdnav);
|
2006-11-08 00:11:42 +00:00
|
|
|
if(dvd_angle > 1)
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_angle_change(priv->dvdnav, dvd_angle);
|
2005-05-19 19:50:39 +00:00
|
|
|
|
|
|
|
stream->sector_size = 2048;
|
|
|
|
stream->flags = STREAM_READ | STREAM_SEEK;
|
|
|
|
stream->fill_buffer = fill_buffer;
|
|
|
|
stream->seek = seek;
|
2006-08-19 11:49:04 +00:00
|
|
|
stream->control = control;
|
2006-06-14 21:58:17 +00:00
|
|
|
stream->close = stream_dvdnav_close;
|
2005-05-19 19:50:39 +00:00
|
|
|
stream->type = STREAMTYPE_DVDNAV;
|
2006-11-09 22:24:57 +00:00
|
|
|
stream->priv=(void*)priv;
|
2006-06-14 21:58:17 +00:00
|
|
|
*file_format = DEMUXER_TYPE_MPEG_PS;
|
|
|
|
|
|
|
|
update_title_len(stream);
|
2008-01-26 11:51:34 +00:00
|
|
|
if(!stream->pos && p->track > 0)
|
2007-08-23 23:14:00 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR, "INIT ERROR: couldn't get init pos %s\r\n", dvdnav_err_to_string(priv->dvdnav));
|
2006-11-08 23:05:33 +00:00
|
|
|
|
2006-10-23 21:07:24 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_INFO, "Remember to disable MPlayer's cache when playing dvdnav:// streams (adding -nocache to your command line)\r\n");
|
2005-05-19 19:50:39 +00:00
|
|
|
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-09 21:37:57 +00:00
|
|
|
|
2008-01-26 11:51:34 +00:00
|
|
|
void mp_dvdnav_handle_input(stream_t *stream, int cmd, int *button) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_t *nav = priv->dvdnav;
|
2006-09-19 21:42:43 +00:00
|
|
|
dvdnav_status_t status=DVDNAV_STATUS_ERR;
|
2006-09-09 21:37:57 +00:00
|
|
|
pci_t *pci = dvdnav_get_current_nav_pci(nav);
|
|
|
|
|
|
|
|
if(cmd != MP_CMD_DVDNAV_SELECT && !pci)
|
2008-01-26 11:51:34 +00:00
|
|
|
return;
|
2006-09-09 21:37:57 +00:00
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case MP_CMD_DVDNAV_UP:
|
|
|
|
status = dvdnav_upper_button_select(nav, pci);
|
|
|
|
break;
|
|
|
|
case MP_CMD_DVDNAV_DOWN:
|
|
|
|
status = dvdnav_lower_button_select(nav, pci);
|
|
|
|
break;
|
|
|
|
case MP_CMD_DVDNAV_LEFT:
|
|
|
|
status = dvdnav_left_button_select(nav, pci);
|
|
|
|
break;
|
|
|
|
case MP_CMD_DVDNAV_RIGHT:
|
|
|
|
status = dvdnav_right_button_select(nav, pci);
|
|
|
|
break;
|
|
|
|
case MP_CMD_DVDNAV_MENU:
|
|
|
|
status = dvdnav_menu_call(nav,DVD_MENU_Root);
|
|
|
|
break;
|
2006-09-10 10:25:48 +00:00
|
|
|
case MP_CMD_DVDNAV_PREVMENU: {
|
|
|
|
int title=0, part=0;
|
|
|
|
|
|
|
|
dvdnav_current_title_info(nav, &title, &part);
|
|
|
|
if(title) {
|
2008-01-26 11:51:34 +00:00
|
|
|
if((status=dvdnav_menu_call(nav, DVD_MENU_Part)) == DVDNAV_STATUS_OK)
|
2006-09-10 10:25:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-26 11:51:34 +00:00
|
|
|
if((status=dvdnav_menu_call(nav, DVD_MENU_Title)) == DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
status=dvdnav_menu_call(nav, DVD_MENU_Root);
|
2006-09-10 10:25:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-09-09 21:37:57 +00:00
|
|
|
case MP_CMD_DVDNAV_SELECT:
|
|
|
|
status = dvdnav_button_activate(nav, pci);
|
|
|
|
break;
|
2006-09-19 23:50:21 +00:00
|
|
|
case MP_CMD_DVDNAV_MOUSECLICK:
|
|
|
|
/*
|
|
|
|
this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate()
|
|
|
|
should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select()
|
|
|
|
and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with
|
|
|
|
the coodinates saved by mp_dvdnav_update_mouse_pos().
|
|
|
|
This last call always works well
|
|
|
|
*/
|
2006-11-09 22:24:57 +00:00
|
|
|
status = dvdnav_mouse_activate(nav, pci, priv->mousex, priv->mousey);
|
2006-09-19 23:50:21 +00:00
|
|
|
break;
|
2006-09-09 21:37:57 +00:00
|
|
|
default:
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_V, "Unknown DVDNAV cmd %d\n", cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-09-15 17:50:10 +00:00
|
|
|
if(status == DVDNAV_STATUS_OK)
|
2006-11-08 23:05:33 +00:00
|
|
|
dvdnav_get_current_highlight(nav, button);
|
2006-09-09 21:37:57 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 15:25:31 +00:00
|
|
|
void mp_dvdnav_update_mouse_pos(stream_t *stream, int32_t x, int32_t y, int* button) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2006-11-09 22:24:57 +00:00
|
|
|
dvdnav_t *nav = priv->dvdnav;
|
2006-09-16 15:25:31 +00:00
|
|
|
dvdnav_status_t status;
|
|
|
|
pci_t *pci = dvdnav_get_current_nav_pci(nav);
|
|
|
|
|
|
|
|
if(!pci) return;
|
|
|
|
|
|
|
|
status = dvdnav_mouse_select(nav, pci, x, y);
|
|
|
|
if(status == DVDNAV_STATUS_OK) dvdnav_get_current_highlight(nav, button);
|
|
|
|
else *button = -1;
|
2006-11-09 22:24:57 +00:00
|
|
|
priv->mousex = x;
|
|
|
|
priv->mousey = y;
|
2006-09-16 15:25:31 +00:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:11:43 +00:00
|
|
|
/**
|
|
|
|
* \brief dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param lang: 2-characters language code[s], eventually separated by spaces of commas
|
|
|
|
* \return -1 on error, current subtitle id if successful
|
|
|
|
*/
|
|
|
|
int dvdnav_aid_from_lang(stream_t *stream, unsigned char *language) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2006-12-14 22:11:43 +00:00
|
|
|
int k;
|
|
|
|
uint8_t format, lg;
|
|
|
|
uint16_t lang, lcode;;
|
|
|
|
|
|
|
|
while(language && strlen(language)>=2) {
|
|
|
|
lcode = (language[0] << 8) | (language[1]);
|
|
|
|
for(k=0; k<32; k++) {
|
|
|
|
lg = dvdnav_get_audio_logical_stream(priv->dvdnav, k);
|
|
|
|
if(lg == 0xff) continue;
|
|
|
|
lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
|
|
|
|
if(lang != 0xFFFF && lang == lcode) {
|
|
|
|
format = dvdnav_audio_stream_format(priv->dvdnav, lg);
|
|
|
|
switch(format) {
|
|
|
|
case DVDNAV_FORMAT_AC3:
|
|
|
|
return k+128;
|
|
|
|
case DVDNAV_FORMAT_DTS:
|
|
|
|
return k+136;
|
|
|
|
case DVDNAV_FORMAT_LPCM:
|
|
|
|
return k+160;
|
|
|
|
case DVDNAV_FORMAT_MPEGAUDIO:
|
|
|
|
return k;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
language += 2;
|
|
|
|
while(language[0]==',' || language[0]==' ') ++language;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-14 23:08:09 +00:00
|
|
|
/**
|
|
|
|
* \brief dvdnav_lang_from_aid() assigns to buf the language corresponding to audio id 'aid'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param sid: physical subtitle id
|
|
|
|
* \param buf: buffer to contain the 2-chars language string
|
|
|
|
* \return 0 on error, 1 if successful
|
|
|
|
*/
|
|
|
|
int dvdnav_lang_from_aid(stream_t *stream, int aid, unsigned char *buf) {
|
|
|
|
uint8_t lg;
|
|
|
|
uint16_t lang;
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2006-12-14 23:08:09 +00:00
|
|
|
|
|
|
|
if(aid < 0)
|
|
|
|
return 0;
|
2006-12-15 23:12:50 +00:00
|
|
|
lg = dvdnav_get_audio_logical_stream(priv->dvdnav, aid & 0x7);
|
2006-12-14 23:08:09 +00:00
|
|
|
if(lg == 0xff) return 0;
|
|
|
|
lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
|
|
|
|
if(lang == 0xffff) return 0;
|
|
|
|
buf[0] = lang >> 8;
|
|
|
|
buf[1] = lang & 0xFF;
|
|
|
|
buf[2] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-12-14 22:11:43 +00:00
|
|
|
|
2006-12-02 14:50:12 +00:00
|
|
|
/**
|
|
|
|
* \brief dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param lang: 2-characters language code[s], eventually separated by spaces of commas
|
|
|
|
* \return -1 on error, current subtitle id if successful
|
|
|
|
*/
|
2006-11-25 12:17:34 +00:00
|
|
|
int dvdnav_sid_from_lang(stream_t *stream, unsigned char *language) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2007-08-04 21:16:22 +00:00
|
|
|
uint8_t lg, k;
|
2006-11-25 15:00:08 +00:00
|
|
|
uint16_t lang, lcode;
|
2006-11-25 12:17:34 +00:00
|
|
|
|
2006-11-25 15:00:08 +00:00
|
|
|
while(language && strlen(language)>=2) {
|
2006-11-27 23:25:08 +00:00
|
|
|
lcode = (language[0] << 8) | (language[1]);
|
|
|
|
for(k=0; k<32; k++) {
|
|
|
|
lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
|
|
|
|
if(lg == 0xff) continue;
|
|
|
|
lang = dvdnav_spu_stream_to_lang(priv->dvdnav, lg);
|
|
|
|
if(lang != 0xFFFF && lang == lcode) {
|
|
|
|
return k;
|
|
|
|
}
|
2006-11-25 12:17:34 +00:00
|
|
|
}
|
2006-11-27 23:25:08 +00:00
|
|
|
language += 2;
|
|
|
|
while(language[0]==',' || language[0]==' ') ++language;
|
2006-11-25 15:00:08 +00:00
|
|
|
}
|
2006-11-25 12:17:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-10 17:25:54 +00:00
|
|
|
/**
|
|
|
|
* \brief dvdnav_lang_from_sid() assigns to buf the language corresponding to subtitle id 'sid'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param sid: physical subtitle id
|
|
|
|
* \param buf: buffer to contain the 2-chars language string
|
|
|
|
* \return 0 on error, 1 if successful
|
|
|
|
*/
|
|
|
|
int dvdnav_lang_from_sid(stream_t *stream, int sid, unsigned char *buf) {
|
2007-08-04 21:16:22 +00:00
|
|
|
uint8_t lg;
|
2006-12-10 17:25:54 +00:00
|
|
|
uint16_t lang;
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
2006-12-10 17:25:54 +00:00
|
|
|
if(sid < 0) return 0;
|
|
|
|
lg = dvdnav_get_spu_logical_stream(priv->dvdnav, sid);
|
|
|
|
lang = dvdnav_spu_stream_to_lang(priv->dvdnav, lg);
|
|
|
|
if(lang == 0xffff) return 0;
|
|
|
|
buf[0] = lang >> 8;
|
|
|
|
buf[1] = lang & 0xFF;
|
|
|
|
buf[2] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-12-02 14:50:12 +00:00
|
|
|
/**
|
|
|
|
* \brief dvdnav_number_of_subs() returns the count of available subtitles
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return 0 on error, something meaningful otherwise
|
|
|
|
*/
|
2006-11-25 12:17:34 +00:00
|
|
|
int dvdnav_number_of_subs(stream_t *stream) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t * priv = stream->priv;
|
2006-11-25 12:17:34 +00:00
|
|
|
uint8_t lg, k, n=0;
|
|
|
|
|
2008-01-26 11:51:34 +00:00
|
|
|
if (priv->state & NAV_FLAG_VTS_DOMAIN) return 0;
|
2006-11-25 12:17:34 +00:00
|
|
|
for(k=0; k<32; k++) {
|
|
|
|
lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
|
|
|
|
if(lg == 0xff) continue;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-07-29 17:57:12 +00:00
|
|
|
/**
|
|
|
|
* \brief mp_dvdnav_get_spu_clut() returns the spu clut
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return spu clut pointer
|
|
|
|
*/
|
2006-12-09 19:23:35 +00:00
|
|
|
unsigned int *mp_dvdnav_get_spu_clut(stream_t *stream) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
2008-01-26 13:07:47 +00:00
|
|
|
return (priv->state & NAV_FLAG_SPU_SET) ? priv->spu_clut : NULL;
|
2006-12-09 19:23:35 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 17:57:12 +00:00
|
|
|
/**
|
|
|
|
* \brief mp_dvdnav_get_highlight() get dvdnav highlight struct
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param hl : - highlight struct pointer
|
|
|
|
*/
|
2006-11-25 17:44:22 +00:00
|
|
|
void mp_dvdnav_get_highlight (stream_t *stream, nav_highlight_t *hl) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
2006-11-25 17:44:22 +00:00
|
|
|
dvdnav_highlight_event_t hlev = priv->hlev;
|
|
|
|
|
|
|
|
hl->sx = hlev.sx;
|
|
|
|
hl->sy = hlev.sy;
|
|
|
|
hl->ex = hlev.ex;
|
|
|
|
hl->ey = hlev.ey;
|
2006-11-25 13:03:51 +00:00
|
|
|
}
|
2006-09-16 15:25:31 +00:00
|
|
|
|
2008-01-24 19:14:05 +00:00
|
|
|
void mp_dvdnav_switch_title (stream_t *stream, int title) {
|
2008-01-26 13:10:47 +00:00
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
2008-01-24 19:14:05 +00:00
|
|
|
uint32_t titles;
|
|
|
|
|
|
|
|
dvdnav_get_number_of_titles (priv->dvdnav, &titles);
|
|
|
|
if (title > 0 && title <= titles)
|
|
|
|
dvdnav_title_play (priv->dvdnav, title);
|
|
|
|
}
|
|
|
|
|
2008-01-26 11:51:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Check if end of stream has been reached
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return 1 on really eof
|
|
|
|
*/
|
|
|
|
int mp_dvdnav_is_eof (stream_t *stream) {
|
|
|
|
return ((dvdnav_priv_t *) stream->priv)->state & NAV_FLAG_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Skip still frame
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
int mp_dvdnav_skip_still (stream_t *stream) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
if (priv->still_length == 0xff)
|
|
|
|
return 1;
|
|
|
|
dvdnav_still_skip(priv->dvdnav);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Skip wait event
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
int mp_dvdnav_skip_wait (stream_t *stream) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
if (!(priv->state & NAV_FLAG_WAIT))
|
|
|
|
return 1;
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT;
|
|
|
|
dvdnav_wait_skip(priv->dvdnav);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set wait mode
|
|
|
|
* \param stream : - stream pointer
|
|
|
|
* \param mode : - if true, then suspend block read
|
|
|
|
* \param automode: - if true, then VTS or cell change set wait mode
|
|
|
|
*/
|
|
|
|
void mp_dvdnav_read_wait (stream_t *stream, int mode, int automode) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
if (mode == 0)
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_READ;
|
|
|
|
if (mode > 0)
|
|
|
|
priv->state |= NAV_FLAG_WAIT_READ;
|
|
|
|
if (automode == 0)
|
|
|
|
priv->state &= ~NAV_FLAG_WAIT_READ_AUTO;
|
|
|
|
if (automode > 0)
|
|
|
|
priv->state |= NAV_FLAG_WAIT_READ_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Check if cell has changed
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param clear : - if true, then clear cell change flag
|
|
|
|
* \return 1 if cell has changed
|
|
|
|
*/
|
|
|
|
int mp_dvdnav_cell_has_changed (stream_t *stream, int clear) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
if (!(priv->state & NAV_FLAG_CELL_CHANGED))
|
|
|
|
return 0;
|
2008-01-26 16:19:42 +00:00
|
|
|
if (clear) {
|
2008-01-26 11:51:34 +00:00
|
|
|
priv->state &= ~NAV_FLAG_CELL_CHANGED;
|
2008-01-26 16:19:42 +00:00
|
|
|
priv->state |= NAV_FLAG_STREAM_CHANGE;
|
|
|
|
}
|
2008-01-26 11:51:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-26 16:17:44 +00:00
|
|
|
/* Notify if something has changed in stream
|
|
|
|
* Can be related to title, chapter, audio or SPU
|
|
|
|
*/
|
|
|
|
int mp_dvdnav_stream_has_changed (stream_t *stream) {
|
|
|
|
dvdnav_priv_t *priv = stream->priv;
|
|
|
|
|
|
|
|
if (!(priv->state & NAV_FLAG_STREAM_CHANGE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
priv->state &= ~NAV_FLAG_STREAM_CHANGE;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-01-26 11:51:34 +00:00
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
const stream_info_t stream_info_dvdnav = {
|
2005-05-19 19:50:39 +00:00
|
|
|
"DVDNAV stream",
|
|
|
|
"null",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
open_s,
|
|
|
|
{ "dvdnav", NULL },
|
|
|
|
&stream_opts,
|
|
|
|
1 // Urls are an option string
|
|
|
|
};
|