| 2042 | } |
| 2043 | |
| 2044 | static int TitleOpenIfo(hb_dvdnav_t * d, int t) |
| 2045 | { |
| 2046 | int pgcn, pgn, pgcn_end, i, c; |
| 2047 | pgc_t * pgc; |
| 2048 | int cell_cur; |
| 2049 | hb_dvd_chapter_t * dvd_chapter; |
| 2050 | uint64_t duration; |
| 2051 | |
| 2052 | if (d->title == t && d->ifo != NULL) |
| 2053 | { |
| 2054 | // Already opened |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
| 2058 | // Close previous if open |
| 2059 | TitleCloseIfo(d); |
| 2060 | |
| 2061 | /* VTS which our title is in */ |
| 2062 | d->vts = d->vmg->tt_srpt->title[t-1].title_set_nr; |
| 2063 | |
| 2064 | if (!d->vts) |
| 2065 | { |
| 2066 | /* A VTS of 0 means the title wasn't found in the title set */ |
| 2067 | hb_log("Invalid VTS (title set) number: %i", d->vts); |
| 2068 | goto fail; |
| 2069 | } |
| 2070 | |
| 2071 | if(!(d->ifo = ifoOpen(d->reader, d->vts))) |
| 2072 | { |
| 2073 | hb_log( "ifoOpen failed" ); |
| 2074 | goto fail; |
| 2075 | } |
| 2076 | |
| 2077 | int title_ttn = d->vmg->tt_srpt->title[t-1].vts_ttn; |
| 2078 | if ( title_ttn < 1 || title_ttn > d->ifo->vts_ptt_srpt->nr_of_srpts ) |
| 2079 | { |
| 2080 | hb_log( "invalid VTS PTT offset %d for title %d, skipping", title_ttn, t ); |
| 2081 | goto fail; |
| 2082 | } |
| 2083 | |
| 2084 | d->duration = 0LL; |
| 2085 | d->pgcn = -1; |
| 2086 | d->pgn = 1; |
| 2087 | for (i = 0; i < d->ifo->vts_ptt_srpt->title[title_ttn-1].nr_of_ptts; i++) |
| 2088 | { |
| 2089 | int blocks = 0; |
| 2090 | |
| 2091 | duration = PttDuration(d->ifo, title_ttn, i+1, &blocks, &pgcn_end); |
| 2092 | pgcn = d->ifo->vts_ptt_srpt->title[title_ttn-1].ptt[i].pgcn; |
| 2093 | pgn = d->ifo->vts_ptt_srpt->title[title_ttn-1].ptt[i].pgn; |
| 2094 | if (duration > d->duration) |
| 2095 | { |
| 2096 | d->pgcn = pgcn; |
| 2097 | d->pgn = pgn; |
| 2098 | d->duration = duration; |
| 2099 | d->title_block_count = blocks; |
| 2100 | } |
| 2101 | else if (pgcn == d->pgcn && pgn < d->pgn) |
no test coverage detected