mirror of https://github.com/mpv-player/mpv
stream: remove old chapter handling code
Stream-level chapters (like DVD etc.) did potentially not have timestamps for each chapter, so STREAM_CTRL_SEEK_TO_CHAPTER and STREAM_CTRL_GET_CURRENT_CHAPTER were needed to navigate chapters. We've switched everything to use timestamps and that seems to work, so we can simplify the code and remove this old mechanism.
This commit is contained in:
parent
7bd3f26481
commit
2c693a4732
|
@ -902,46 +902,23 @@ static void add_stream_chapters(struct demuxer *demuxer)
|
|||
|
||||
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts)
|
||||
{
|
||||
int ris = STREAM_UNSUPPORTED;
|
||||
if (chapter >= demuxer->num_chapters)
|
||||
return -1;
|
||||
if (chapter < 0)
|
||||
chapter = 0;
|
||||
|
||||
if (demuxer->num_chapters == 0)
|
||||
ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER,
|
||||
&chapter);
|
||||
*seek_pts = demuxer->chapters[chapter].start / 1e9;
|
||||
|
||||
if (ris != STREAM_UNSUPPORTED) {
|
||||
demux_flush(demuxer);
|
||||
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
||||
|
||||
// exit status may be ok, but main() doesn't have to seek itself
|
||||
// (because e.g. dvds depend on sectors, not on pts)
|
||||
*seek_pts = -1.0;
|
||||
|
||||
return chapter;
|
||||
} else {
|
||||
if (chapter >= demuxer->num_chapters)
|
||||
return -1;
|
||||
if (chapter < 0)
|
||||
chapter = 0;
|
||||
|
||||
*seek_pts = demuxer->chapters[chapter].start / 1e9;
|
||||
|
||||
return chapter;
|
||||
}
|
||||
return chapter;
|
||||
}
|
||||
|
||||
int demuxer_get_current_chapter(demuxer_t *demuxer, double time_now)
|
||||
{
|
||||
int chapter = -2;
|
||||
if (!demuxer->num_chapters || !demuxer->chapters) {
|
||||
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
||||
&chapter) == STREAM_UNSUPPORTED)
|
||||
chapter = -2;
|
||||
} else {
|
||||
uint64_t now = time_now * 1e9 + 0.5;
|
||||
for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
|
||||
if (demuxer->chapters[chapter].start <= now)
|
||||
break;
|
||||
}
|
||||
uint64_t now = time_now * 1e9 + 0.5;
|
||||
for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
|
||||
if (demuxer->chapters[chapter].start <= now)
|
||||
break;
|
||||
}
|
||||
return chapter;
|
||||
}
|
||||
|
|
|
@ -570,8 +570,7 @@ int get_chapter_count(struct MPContext *mpctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Seek to a given chapter. Tries to queue the seek, but might seek immediately
|
||||
// in some cases. Returns success, no matter if seek is queued or immediate.
|
||||
// Seek to a given chapter. Queues the seek.
|
||||
bool mp_seek_chapter(struct MPContext *mpctx, int chapter)
|
||||
{
|
||||
int num = get_chapter_count(mpctx);
|
||||
|
@ -592,12 +591,6 @@ bool mp_seek_chapter(struct MPContext *mpctx, int chapter)
|
|||
} else if (mpctx->master_demuxer) {
|
||||
int res = demuxer_seek_chapter(mpctx->master_demuxer, chapter, &pts);
|
||||
if (res >= 0) {
|
||||
if (pts == -1) {
|
||||
// for DVD/BD - seek happened via stream layer
|
||||
seek_reset(mpctx, true, true);
|
||||
mpctx->seek = (struct seek_params){0};
|
||||
return true;
|
||||
}
|
||||
chapter = res;
|
||||
goto do_seek;
|
||||
}
|
||||
|
|
|
@ -407,7 +407,6 @@ static bool control_needs_flush(int stream_ctrl)
|
|||
{
|
||||
switch (stream_ctrl) {
|
||||
case STREAM_CTRL_SEEK_TO_TIME:
|
||||
case STREAM_CTRL_SEEK_TO_CHAPTER:
|
||||
case STREAM_CTRL_SET_ANGLE:
|
||||
case STREAM_CTRL_SET_CURRENT_TITLE:
|
||||
return true;
|
||||
|
|
|
@ -70,8 +70,6 @@ enum streamtype {
|
|||
|
||||
enum stream_ctrl {
|
||||
STREAM_CTRL_GET_TIME_LENGTH = 1,
|
||||
STREAM_CTRL_SEEK_TO_CHAPTER,
|
||||
STREAM_CTRL_GET_CURRENT_CHAPTER,
|
||||
STREAM_CTRL_GET_NUM_CHAPTERS,
|
||||
STREAM_CTRL_GET_CURRENT_TIME,
|
||||
STREAM_CTRL_SEEK_TO_TIME,
|
||||
|
|
|
@ -161,33 +161,6 @@ static int bluray_stream_control(stream_t *s, int cmd, void *arg)
|
|||
return 1;
|
||||
}
|
||||
|
||||
case STREAM_CTRL_GET_CURRENT_CHAPTER: {
|
||||
*((unsigned int *) arg) = bd_get_current_chapter(b->bd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case STREAM_CTRL_SEEK_TO_CHAPTER: {
|
||||
BLURAY_TITLE_INFO *ti;
|
||||
int chapter = *((unsigned int *) arg);
|
||||
int64_t pos;
|
||||
int r;
|
||||
|
||||
ti = bd_get_title_info(b->bd, b->current_title, b->current_angle);
|
||||
if (!ti)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
||||
if (chapter < 0 || chapter > ti->chapter_count) {
|
||||
bd_free_title_info(ti);
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
pos = bd_chapter_pos(b->bd, chapter);
|
||||
r = bluray_stream_seek(s, pos);
|
||||
bd_free_title_info(ti);
|
||||
|
||||
return r ? 1 : STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
case STREAM_CTRL_GET_TIME_LENGTH: {
|
||||
BLURAY_TITLE_INFO *ti;
|
||||
|
||||
|
|
|
@ -427,49 +427,6 @@ static int get_num_chapter(ifo_handle_t *vts_file, tt_srpt_t *tt_srpt, int title
|
|||
return vts_file->vts_ptt_srpt->title[title_no].nr_of_ptts;
|
||||
}
|
||||
|
||||
static int seek_to_chapter(stream_t *stream, ifo_handle_t *vts_file, tt_srpt_t *tt_srpt, int title_no, int chapter)
|
||||
{
|
||||
dvd_priv_t *d = stream->priv;
|
||||
ptt_info_t ptt;
|
||||
pgc_t *pgc;
|
||||
int64_t pos;
|
||||
|
||||
if(!vts_file || !tt_srpt)
|
||||
return 0;
|
||||
|
||||
if(title_no < 0 || title_no >= tt_srpt->nr_of_srpts)
|
||||
return 0;
|
||||
|
||||
// map global title to vts title
|
||||
title_no = tt_srpt->title[title_no].vts_ttn - 1;
|
||||
|
||||
if(title_no < 0 || title_no >= vts_file->vts_ptt_srpt->nr_of_srpts)
|
||||
return 0;
|
||||
|
||||
if(chapter < 0 || chapter > vts_file->vts_ptt_srpt->title[title_no].nr_of_ptts-1) //no such chapter
|
||||
return 0;
|
||||
|
||||
ptt = vts_file->vts_ptt_srpt->title[title_no].ptt[chapter];
|
||||
pgc = vts_file->vts_pgcit->pgci_srp[ptt.pgcn-1].pgc;
|
||||
|
||||
d->cur_cell = pgc->program_map[ptt.pgn - 1] - 1;
|
||||
if(pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK)
|
||||
d->cur_cell += dvd_angle-1;
|
||||
d->cur_pack = pgc->cell_playback[d->cur_cell].first_sector;
|
||||
d->cell_last_pack = pgc->cell_playback[d->cur_cell].last_sector;
|
||||
|
||||
d->packs_left = -1;
|
||||
d->angle_seek = 0;
|
||||
|
||||
pos = (int64_t) d->cur_pack * 2048;
|
||||
stream_seek(stream, pos);
|
||||
|
||||
MP_VERBOSE(stream, "\r\nSTREAM_DVD, seeked to chapter: %d, cell: %u, pos: %"PRIu64"\n",
|
||||
chapter, d->cur_pack, pos);
|
||||
|
||||
return chapter;
|
||||
}
|
||||
|
||||
// p: in=chapter number, out=PTS
|
||||
static int get_chapter_time(ifo_handle_t *vts_file, tt_srpt_t *tt_srpt, int title_no, double *p)
|
||||
{
|
||||
|
@ -642,24 +599,11 @@ static int control(stream_t *stream,int cmd,void* arg)
|
|||
if(! r) return STREAM_UNSUPPORTED;
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_SEEK_TO_CHAPTER:
|
||||
{
|
||||
int r;
|
||||
r = seek_to_chapter(stream, d->vts_file, d->tt_srpt, d->cur_title, *((unsigned int *)arg));
|
||||
if(! r) return STREAM_UNSUPPORTED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_CURRENT_TITLE:
|
||||
{
|
||||
*((unsigned int *)arg) = d->cur_title;
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_CURRENT_CHAPTER:
|
||||
{
|
||||
*((unsigned int *)arg) = dvd_chapter_from_cell(d, d->cur_title, d->cur_cell);
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_CURRENT_TIME:
|
||||
{
|
||||
double tm;
|
||||
|
|
|
@ -466,17 +466,6 @@ static int control(stream_t *stream, int cmd, void *arg)
|
|||
int tit, part;
|
||||
|
||||
switch (cmd) {
|
||||
case STREAM_CTRL_SEEK_TO_CHAPTER: {
|
||||
int chap = *(unsigned int *)arg + 1;
|
||||
|
||||
if (chap < 1)
|
||||
break;
|
||||
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
||||
break;
|
||||
if (dvdnav_part_play(dvdnav, tit, chap) != DVDNAV_STATUS_OK)
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_NUM_CHAPTERS: {
|
||||
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
||||
break;
|
||||
|
@ -502,12 +491,6 @@ static int control(stream_t *stream, int cmd, void *arg)
|
|||
free(parts);
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_CURRENT_CHAPTER: {
|
||||
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
||||
break;
|
||||
*(unsigned int *)arg = part - 1;
|
||||
return 1;
|
||||
}
|
||||
case STREAM_CTRL_GET_TIME_LENGTH: {
|
||||
if (priv->duration) {
|
||||
*(double *)arg = (double)priv->duration / 1000.0;
|
||||
|
|
Loading…
Reference in New Issue