Mercurial > libdvdnav.hg
changeset 409:9b8bfc56a7fe src
Add dvdnav_program_play & dvdnav_current_title_program
Using title parts w/ dvdnav_part_play and dvdnav_current_title_info
is not reliable for use as chapter marks in files made from
transcoding. The start of a part does not necessarily fall strictly
inside the main title. Parts can have an intro sequence before
getting into the title. So we use program boundaries instead of
part markers to test when we have reached a chapter point during
encoding of the title. The same would apply to displaying the
current chapter during playback. The program boundaries
should be checked instead of looking for a part.
Patch from John Stebbins. Thanks!
author | erik |
---|---|
date | Fri, 30 Jul 2010 23:34:16 +0000 |
parents | 7923e813ec61 |
children | 799f85209145 |
files | dvdnav/dvdnav.h navigation.c vm/vm.c vm/vm.h |
diffstat | 4 files changed, 149 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dvdnav/dvdnav.h Fri Jul 30 23:34:13 2010 +0000 +++ b/dvdnav/dvdnav.h Fri Jul 30 23:34:16 2010 +0000 @@ -279,6 +279,11 @@ dvdnav_status_t dvdnav_part_play(dvdnav_t *self, int32_t title, int32_t part); /* + * Plays the specified title, starting from the specified program + */ +dvdnav_status_t dvdnav_program_play(dvdnav_t *this, int32_t title, int32_t pgcn, int32_t pgn); + +/* * Stores in *times an array (that the application *must* free) of * dvdtimes corresponding to the chapter times for the chosen title. * *duration will have the duration of the title @@ -320,6 +325,13 @@ int32_t *part); /* + * Return the title number, pgcn and pgn currently being played. + * A title of 0 indicates, we are in a menu. + */ +dvdnav_status_t dvdnav_current_title_program(dvdnav_t *self, int32_t *title, + int32_t *pgcn, int32_t *pgn); + +/* * Return the current position (in blocks) within the current * title and the length (in blocks) of said title. *
--- a/navigation.c Fri Jul 30 23:34:13 2010 +0000 +++ b/navigation.c Fri Jul 30 23:34:16 2010 +0000 @@ -122,10 +122,90 @@ return DVDNAV_STATUS_ERR; } +dvdnav_status_t dvdnav_current_title_program(dvdnav_t *this, int32_t *title, int32_t *pgcn, int32_t *pgn) { + int32_t retval; + int32_t part; + + pthread_mutex_lock(&this->vm_lock); + if (!this->vm->vtsi || !this->vm->vmgi) { + printerr("Bad VM state."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if (!this->started) { + printerr("Virtual DVD machine not started."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if (!this->vm->state.pgc) { + printerr("No current PGC."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if ( (this->vm->state.domain == VTSM_DOMAIN) + || (this->vm->state.domain == VMGM_DOMAIN) ) { + /* Get current Menu ID: into *part. */ + if(! vm_get_current_menu(this->vm, &part)) { + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if (part > -1) { + *title = 0; + *pgcn = this->vm->state.pgcN; + *pgn = this->vm->state.pgN; + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_OK; + } + } + if (this->vm->state.domain == VTS_DOMAIN) { + retval = vm_get_current_title_part(this->vm, title, &part); + *pgcn = this->vm->state.pgcN; + *pgn = this->vm->state.pgN; + pthread_mutex_unlock(&this->vm_lock); + return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; + } + printerr("Not in a title or menu."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; +} + dvdnav_status_t dvdnav_title_play(dvdnav_t *this, int32_t title) { return dvdnav_part_play(this, title, 1); } +dvdnav_status_t dvdnav_program_play(dvdnav_t *this, int32_t title, int32_t pgcn, int32_t pgn) { + int32_t retval; + + pthread_mutex_lock(&this->vm_lock); + if (!this->vm->vmgi) { + printerr("Bad VM state."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if (!this->started) { + /* don't report an error but be nice */ + vm_start(this->vm); + this->started = 1; + } + if (!this->vm->state.pgc) { + printerr("No current PGC."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + if((title < 1) || (title > this->vm->vmgi->tt_srpt->nr_of_srpts)) { + printerr("Title out of range."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + + retval = vm_jump_title_program(this->vm, title, pgcn, pgn); + if (retval) + this->vm->hop_channel++; + pthread_mutex_unlock(&this->vm_lock); + + return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; +} + dvdnav_status_t dvdnav_part_play(dvdnav_t *this, int32_t title, int32_t part) { int32_t retval;
--- a/vm/vm.c Fri Jul 30 23:34:13 2010 +0000 +++ b/vm/vm.c Fri Jul 30 23:34:16 2010 +0000 @@ -85,6 +85,8 @@ static int set_PTT(vm_t *vm, int tt, int ptt); static int set_VTS_TT(vm_t *vm, int vtsN, int vts_ttn); static int set_VTS_PTT(vm_t *vm, int vtsN, int vts_ttn, int part); +static int set_PROG(vm_t *vm, int tt, int pgcn, int pgn); +static int set_VTS_PROG(vm_t *vm, int vtsN, int vts_ttn, int pgcn, int pgn); static int set_FP_PGC(vm_t *vm); static int set_MENU(vm_t *vm, int menu); static int set_PGCN(vm_t *vm, int pgcN); @@ -520,6 +522,24 @@ return 1; } +int vm_jump_title_program(vm_t *vm, int title, int pgcn, int pgn) { + link_t link; + + if(!set_PROG(vm, title, pgcn, pgn)) + return 0; + /* Some DVDs do not want us to jump directly into a title and have + * PGC pre commands taking us back to some menu. Since we do not like that, + * we do not execute PGC pre commands that would do a jump. */ + /* process_command(vm, play_PGC_PG(vm, (vm->state).pgN)); */ + link = play_PGC_PG(vm, (vm->state).pgN); + if (link.command != PlayThis) + /* jump occured -> ignore it and play the PG anyway */ + process_command(vm, play_PG(vm)); + else + process_command(vm, link); + return 1; +} + int vm_jump_title_part(vm_t *vm, int title, int part) { link_t link; @@ -1647,6 +1667,42 @@ return res; } +static int set_PROG(vm_t *vm, int tt, int pgcn, int pgn) { + assert(tt <= vm->vmgi->tt_srpt->nr_of_srpts); + return set_VTS_PROG(vm, vm->vmgi->tt_srpt->title[tt - 1].title_set_nr, + vm->vmgi->tt_srpt->title[tt - 1].vts_ttn, pgcn, pgn); +} + +static int set_VTS_PROG(vm_t *vm, int vtsN, int vts_ttn, int pgcn, int pgn) { + int pgcN, pgN, res, title, part = 0; + + (vm->state).domain = VTS_DOMAIN; + + if (vtsN != (vm->state).vtsN) + if (!ifoOpenNewVTSI(vm, vm->dvd, vtsN)) /* Also sets (vm->state).vtsN */ + return 0; + + if ((vts_ttn < 1) || (vts_ttn > vm->vtsi->vts_ptt_srpt->nr_of_srpts)) { + return 0; + } + + pgcN = pgcn; + pgN = pgn; + + (vm->state).TT_PGCN_REG = pgcN; + (vm->state).TTN_REG = get_TT(vm, vtsN, vts_ttn); + assert( (vm->state.TTN_REG) != 0 ); + (vm->state).VTS_TTN_REG = vts_ttn; + (vm->state).vtsN = vtsN; /* Not sure about this one. We can get to it easily from TTN_REG */ + /* Any other registers? */ + + res = set_PGCN(vm, pgcN); /* This clobber's state.pgN (sets it to 1), but we don't want clobbering here. */ + (vm->state).pgN = pgN; + vm_get_current_title_part(vm, &title, &part); + (vm->state).PTTN_REG = part; + return res; +} + static int set_FP_PGC(vm_t *vm) { (vm->state).domain = FP_DOMAIN; if (!vm->vmgi->first_play_pgc) {
--- a/vm/vm.h Fri Jul 30 23:34:13 2010 +0000 +++ b/vm/vm.h Fri Jul 30 23:34:16 2010 +0000 @@ -139,6 +139,7 @@ int vm_jump_pg(vm_t *vm, int pg); int vm_jump_cell_block(vm_t *vm, int cell, int block); int vm_jump_title_part(vm_t *vm, int title, int part); +int vm_jump_title_program(vm_t *vm, int title, int pgcn, int pgn); int vm_jump_top_pg(vm_t *vm); int vm_jump_next_pg(vm_t *vm); int vm_jump_prev_pg(vm_t *vm);