summaryrefslogtreecommitdiffstats
path: root/stream/stream_dvdnav.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-03 00:22:18 +0200
committerwm4 <wm4@nowhere>2019-10-03 00:22:18 +0200
commit1c63869d0ae01fd8e720353719e4c8b8da12e0b5 (patch)
tree942771789b91389636d2d65baa1238ab9b992a86 /stream/stream_dvdnav.c
parent8c58375dbd968fff22c9ef5a473c456657c5fc78 (diff)
downloadmpv-1c63869d0ae01fd8e720353719e4c8b8da12e0b5.tar.bz2
mpv-1c63869d0ae01fd8e720353719e4c8b8da12e0b5.tar.xz
demux: restore some of the DVD/BD/CDDA interaction layers
This partially reverts commit a9d83eac40c94f44d19fab7b6955331f10efe301 ("Remove optical disc fancification layers"). Mostly due to the timestamp crap, this was never really going to work. The playback layer is sensitive to timestamps, and derives the playback time directly from the low level packet timestamps. DVD/BD works differently, and libdvdnav/libbluray do not make it easy at all to compensate for this. Which is why it never worked well, but not doing it at all is even more awful. demux_disc.c tried this and rewrote packet timestamps from low level TS to playback time. So restore demux_disc.c, which should bring behavior back to the old often non-working but slightly better state. I did not revert anything that affects components above the demuxer layer. For example, the properties for switching DVD angles or listing disc titles are still gone. (Disc titles could be reimplemented as editions. But not by me.) This commit modifies the reverted code a bit; this can't be avoided, because the internal API changed quite a bit. The old seek resync in demux_lavf.c (which was a hack) is replaced with a hack. SEEK_FORCE and demux_params.external_stream are new additions. Some of this could/should be further cleaned up. If you don't want "proper" DVD/BD support to disappear, you should probably volunteer. Now why am I wasting my time for this? Just because some idiot users are too lazy to rip their ever-wearing out shitty physical discs? Then why should I not be lazy and drop support completely? They won't even be thankful for me maintaining this horrible garbage for no compensation.
Diffstat (limited to 'stream/stream_dvdnav.c')
-rw-r--r--stream/stream_dvdnav.c207
1 files changed, 204 insertions, 3 deletions
diff --git a/stream/stream_dvdnav.c b/stream/stream_dvdnav.c
index 9a95446455..b4b0dc21b2 100644
--- a/stream/stream_dvdnav.c
+++ b/stream/stream_dvdnav.c
@@ -190,6 +190,73 @@ static int dvd_probe(const char *path, const char *ext, const char *sig)
return r;
}
+/**
+ * \brief mp_dvdnav_lang_from_aid() returns the language corresponding to audio id 'aid'
+ * \param stream: - stream pointer
+ * \param sid: physical subtitle id
+ * \return 0 on error, otherwise language id
+ */
+static int mp_dvdnav_lang_from_aid(stream_t *stream, int aid)
+{
+ uint8_t lg;
+ uint16_t lang;
+ struct priv *priv = stream->priv;
+
+ if (aid < 0)
+ return 0;
+ lg = dvdnav_get_audio_logical_stream(priv->dvdnav, aid & 0x7);
+ if (lg == 0xff)
+ return 0;
+ lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
+ if (lang == 0xffff)
+ return 0;
+ return lang;
+}
+
+/**
+ * \brief mp_dvdnav_lang_from_sid() returns the language corresponding to subtitle id 'sid'
+ * \param stream: - stream pointer
+ * \param sid: physical subtitle id
+ * \return 0 on error, otherwise language id
+ */
+static int mp_dvdnav_lang_from_sid(stream_t *stream, int sid)
+{
+ uint8_t k;
+ uint16_t lang;
+ struct priv *priv = stream->priv;
+ if (sid < 0)
+ return 0;
+ for (k = 0; k < 32; k++)
+ if (dvdnav_get_spu_logical_stream(priv->dvdnav, k) == sid)
+ break;
+ if (k == 32)
+ return 0;
+ lang = dvdnav_spu_stream_to_lang(priv->dvdnav, k);
+ if (lang == 0xffff)
+ return 0;
+ return lang;
+}
+
+/**
+ * \brief mp_dvdnav_number_of_subs() returns the count of available subtitles
+ * \param stream: - stream pointer
+ * \return 0 on error, something meaningful otherwise
+ */
+static int mp_dvdnav_number_of_subs(stream_t *stream)
+{
+ struct priv *priv = stream->priv;
+ uint8_t lg, k, n = 0;
+
+ for (k = 0; k < 32; k++) {
+ lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
+ if (lg == 0xff)
+ continue;
+ if (lg >= n)
+ n = lg + 1;
+ }
+ return n;
+}
+
static int fill_buffer(stream_t *s, char *buf, int max_len)
{
struct priv *priv = s->priv;
@@ -209,7 +276,7 @@ static int fill_buffer(stream_t *s, char *buf, int max_len)
}
if (event != DVDNAV_BLOCK_OK) {
const char *name = LOOKUP_NAME(mp_dvdnav_events, event);
- MP_VERBOSE(s, "DVDNAV: event %s (%d).\n", name, event);
+ MP_TRACE(s, "DVDNAV: event %s (%d).\n", name, event);
}
switch (event) {
case DVDNAV_BLOCK_OK:
@@ -273,16 +340,92 @@ static int control(stream_t *stream, int cmd, void *arg)
{
struct priv *priv = stream->priv;
dvdnav_t *dvdnav = priv->dvdnav;
+ int tit, part;
switch (cmd) {
- case STREAM_CTRL_OPTICAL_CRAP_HACK1: {
+ case STREAM_CTRL_GET_NUM_CHAPTERS: {
+ if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
+ break;
+ if (dvdnav_get_number_of_parts(dvdnav, tit, &part) != DVDNAV_STATUS_OK)
+ break;
+ if (!part)
+ break;
+ *(unsigned int *)arg = part;
+ return 1;
+ }
+ case STREAM_CTRL_GET_CHAPTER_TIME: {
+ double *ch = arg;
+ int chapter = *ch;
+ if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
+ break;
+ uint64_t *parts = NULL, duration = 0;
+ int n = dvdnav_describe_title_chapters(dvdnav, tit, &parts, &duration);
+ if (!parts)
+ break;
+ if (chapter < 0 || chapter + 1 > n)
+ break;
+ *ch = chapter > 0 ? parts[chapter - 1] / 90000.0 : 0;
+ free(parts);
+ return 1;
+ }
+ case STREAM_CTRL_GET_TIME_LENGTH: {
if (priv->duration) {
*(double *)arg = (double)priv->duration / 1000.0;
return 1;
}
break;
}
- case STREAM_CTRL_OPTICAL_CRAP_HACK2: {
+ case STREAM_CTRL_GET_ASPECT_RATIO: {
+ uint8_t ar = dvdnav_get_video_aspect(dvdnav);
+ *(double *)arg = !ar ? 4.0 / 3.0 : 16.0 / 9.0;
+ return 1;
+ }
+ case STREAM_CTRL_GET_CURRENT_TIME: {
+ double tm;
+ tm = dvdnav_get_current_time(dvdnav) / 90000.0f;
+ if (tm != -1) {
+ *(double *)arg = tm;
+ return 1;
+ }
+ break;
+ }
+ case STREAM_CTRL_GET_NUM_TITLES: {
+ int32_t num_titles = 0;
+ if (dvdnav_get_number_of_titles(dvdnav, &num_titles) != DVDNAV_STATUS_OK)
+ break;
+ *((unsigned int*)arg)= num_titles;
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_GET_TITLE_LENGTH: {
+ int t = *(double *)arg;
+ int32_t num_titles = 0;
+ if (dvdnav_get_number_of_titles(dvdnav, &num_titles) != DVDNAV_STATUS_OK)
+ break;
+ if (t < 0 || t >= num_titles)
+ break;
+ uint64_t duration = 0;
+ uint64_t *parts = NULL;
+ dvdnav_describe_title_chapters(dvdnav, t + 1, &parts, &duration);
+ if (!parts)
+ break;
+ free(parts);
+ *(double *)arg = duration / 90000.0;
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_GET_CURRENT_TITLE: {
+ if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
+ break;
+ *((unsigned int *) arg) = tit - 1;
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_SET_CURRENT_TITLE: {
+ int title = *((unsigned int *) arg);
+ if (dvdnav_title_play(priv->dvdnav, title + 1) != DVDNAV_STATUS_OK)
+ break;
+ stream_drop_buffers(stream);
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_SEEK_TO_TIME: {
double *args = arg;
double d = args[0]; // absolute target timestamp
int flags = args[1]; // from SEEK_* flags (demux.h)
@@ -306,6 +449,63 @@ static int control(stream_t *stream, int cmd, void *arg)
MP_VERBOSE(stream, "block: %lu\n", (unsigned long)pos);
return STREAM_OK;
}
+ case STREAM_CTRL_GET_NUM_ANGLES: {
+ uint32_t curr, angles;
+ if (dvdnav_get_angle_info(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(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(dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
+ break;
+ if (new_angle > angles || new_angle < 1)
+ break;
+ if (dvdnav_angle_change(dvdnav, new_angle) != DVDNAV_STATUS_OK)
+ return 1;
+ }
+ case STREAM_CTRL_GET_LANG: {
+ struct stream_lang_req *req = arg;
+ int lang = 0;
+ switch (req->type) {
+ case STREAM_AUDIO:
+ lang = mp_dvdnav_lang_from_aid(stream, req->id);
+ break;
+ case STREAM_SUB:
+ lang = mp_dvdnav_lang_from_sid(stream, req->id);
+ break;
+ }
+ if (!lang)
+ break;
+ snprintf(req->name, sizeof(req->name), "%c%c", lang >> 8, lang);
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_GET_DVD_INFO: {
+ struct stream_dvd_info_req *req = arg;
+ memset(req, 0, sizeof(*req));
+ req->num_subs = mp_dvdnav_number_of_subs(stream);
+ assert(sizeof(uint32_t) == sizeof(unsigned int));
+ memcpy(req->palette, priv->spu_clut, sizeof(req->palette));
+ return STREAM_OK;
+ }
+ case STREAM_CTRL_GET_DISC_NAME: {
+ const char *volume = NULL;
+ if (dvdnav_get_title_string(dvdnav, &volume) != DVDNAV_STATUS_OK)
+ break;
+ if (!volume || !volume[0])
+ break;
+ *(char**)arg = talloc_strdup(NULL, volume);
+ return STREAM_OK;
+ }
}
return STREAM_UNSUPPORTED;
@@ -420,6 +620,7 @@ static int open_s_internal(stream_t *stream)
stream->fill_buffer = fill_buffer;
stream->control = control;
stream->close = stream_dvdnav_close;
+ stream->demuxer = "+disc";
stream->lavf_type = "mpeg";
return STREAM_OK;