From: Miguel F. <mig...@us...> - 2005-10-14 21:02:27
|
Update of /cvsroot/xine/xine-lib/src/input/libdvdnav In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16982/src/input/libdvdnav Modified Files: dvdnav.h searching.c Log Message: input plugin time seeking patch. hopefuly somebody will be able to help fixing the mess i did in dvdnav ;) Index: dvdnav.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/input/libdvdnav/dvdnav.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- dvdnav.h 19 Jul 2003 13:04:03 -0000 1.14 +++ dvdnav.h 14 Oct 2005 21:02:16 -0000 1.15 @@ -114,6 +114,8 @@ */ const char* dvdnav_err_to_string(dvdnav_t *self); +/* converts a dvd_time_t to PTS ticks */ +int64_t dvdnav_convert_time(dvd_time_t *time); /********************************************************************* * changing and reading DVD player characteristics * Index: searching.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/input/libdvdnav/searching.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- searching.c 16 Mar 2004 11:43:38 -0000 1.18 +++ searching.c 14 Oct 2005 21:02:16 -0000 1.19 @@ -27,6 +27,7 @@ #include <assert.h> #include "dvdnav_internal.h" +#include "dvdnav.h" /* #define LOG_DEBUG @@ -34,12 +35,6 @@ /* Searching API calls */ -dvdnav_status_t dvdnav_time_search(dvdnav_t *this, - uint64_t time) { - /* FIXME: Time search the current PGC based on the xxx table */ - return DVDNAV_STATUS_OK; -} - /* Scan the ADMAP for a particular block number. */ /* Return placed in vobu. */ /* Returns error status */ @@ -101,6 +96,87 @@ return DVDNAV_STATUS_ERR; } +dvdnav_status_t dvdnav_time_search(dvdnav_t *this, + uint64_t time) { + + uint64_t target = time; + uint64_t length = 0; + uint32_t first_cell_nr, last_cell_nr, cell_nr; + int32_t found; + cell_playback_t *cell; + dvd_state_t *state; + dvdnav_status_t result; + + if(this->position_current.still != 0) { + printerr("Cannot seek in a still frame."); + return DVDNAV_STATUS_ERR; + } + + pthread_mutex_lock(&this->vm_lock); + state = &(this->vm->state); + if(!state->pgc) { + printerr("No current PGC."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; + } + + + if (this->pgc_based) { + first_cell_nr = 1; + last_cell_nr = state->pgc->nr_of_cells; + } else { + /* Find start cell of program. */ + first_cell_nr = state->pgc->program_map[state->pgN-1]; + /* Find end cell of program */ + if(state->pgN < state->pgc->nr_of_programs) + last_cell_nr = state->pgc->program_map[state->pgN] - 1; + else + last_cell_nr = state->pgc->nr_of_cells; + } + + found = 0; + for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { + cell = &(state->pgc->cell_playback[cell_nr-1]); + length = dvdnav_convert_time(&cell->playback_time); + if (target >= length) { + target -= length; + } else { + /* FIXME: there must be a better way than interpolation */ + target = target * (cell->last_sector - cell->first_sector + 1) / length; + target += cell->first_sector; + + found = 1; + break; + } + } + + if(found) { + int32_t vobu; +#ifdef LOG_DEBUG + fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", + cell_nr, first_cell_nr, last_cell_nr); +#endif + if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { + int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; + + if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { +#ifdef LOG_DEBUG + fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , + state->cellN, state->blockN, target, vobu, start); +#endif + this->vm->hop_channel += HOP_SEEK; + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_OK; + } + } + } + + fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); + printerr("Error when seeking."); + pthread_mutex_unlock(&this->vm_lock); + return DVDNAV_STATUS_ERR; +} + dvdnav_status_t dvdnav_sector_search(dvdnav_t *this, uint64_t offset, int32_t origin) { uint32_t target = 0; |