Mercurial > libdvdnav.hg
annotate searching.c @ 392:0a5a6f03b029 src
Remove useless $Id$ and $Name$ keywords.
author | diego |
---|---|
date | Sun, 14 Sep 2008 20:31:43 +0000 |
parents | d3c273ced49c |
children | 9c5aef10d165 |
rev | line source |
---|---|
131 | 1 /* |
0 | 2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> |
388 | 3 * |
0 | 4 * This file is part of libdvdnav, a DVD navigation library. |
388 | 5 * |
0 | 6 * libdvdnav is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
388 | 10 * |
0 | 11 * libdvdnav is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
388 | 15 * |
389
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
17 * with libdvdnav; if not, write to the Free Software Foundation, Inc., |
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
0 | 19 */ |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 #include "config.h" | |
23 #endif | |
24 | |
114 | 25 #include <assert.h> |
278 | 26 #include <inttypes.h> |
294
2146ff691bcd
include limits.h; it was included in the previous dvdnav_internal.h and without it players segfault
nicodvb
parents:
290
diff
changeset
|
27 #include <limits.h> |
288
ce4230602517
moved away from dvdnav_internal.h inclusion of various system headers
nicodvb
parents:
285
diff
changeset
|
28 #include <stdio.h> |
ce4230602517
moved away from dvdnav_internal.h inclusion of various system headers
nicodvb
parents:
285
diff
changeset
|
29 #include <string.h> |
313 | 30 #include <stdlib.h> |
290 | 31 #include <sys/time.h> |
285
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
278
diff
changeset
|
32 #include "dvd_types.h" |
386 | 33 #include <dvdread/nav_types.h> |
34 #include <dvdread/ifo_types.h> | |
285
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
278
diff
changeset
|
35 #include "remap.h" |
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
278
diff
changeset
|
36 #include "vm/decoder.h" |
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
278
diff
changeset
|
37 #include "vm/vm.h" |
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
278
diff
changeset
|
38 #include "dvdnav.h" |
0 | 39 #include "dvdnav_internal.h" |
40 | |
114 | 41 /* |
42 #define LOG_DEBUG | |
43 */ | |
44 | |
0 | 45 /* Searching API calls */ |
46 | |
24 | 47 /* Scan the ADMAP for a particular block number. */ |
48 /* Return placed in vobu. */ | |
49 /* Returns error status */ | |
114 | 50 /* FIXME: Maybe need to handle seeking outside current cell. */ |
195 | 51 static dvdnav_status_t dvdnav_scan_admap(dvdnav_t *this, int32_t domain, uint32_t seekto_block, uint32_t *vobu) { |
24 | 52 vobu_admap_t *admap = NULL; |
114 | 53 |
54 #ifdef LOG_DEBUG | |
55 fprintf(MSG_OUT, "libdvdnav: Seeking to target %u ...\n", seekto_block); | |
56 #endif | |
24 | 57 *vobu = -1; |
58 | |
59 /* Search through the VOBU_ADMAP for the nearest VOBU | |
60 * to the target block */ | |
61 switch(domain) { | |
114 | 62 case FP_DOMAIN: |
63 case VMGM_DOMAIN: | |
64 admap = this->vm->vmgi->menu_vobu_admap; | |
65 break; | |
66 case VTSM_DOMAIN: | |
67 admap = this->vm->vtsi->menu_vobu_admap; | |
68 break; | |
69 case VTS_DOMAIN: | |
70 admap = this->vm->vtsi->vts_vobu_admap; | |
71 break; | |
72 default: | |
73 fprintf(MSG_OUT, "libdvdnav: Error: Unknown domain for seeking.\n"); | |
24 | 74 } |
75 if(admap) { | |
166 | 76 uint32_t address = 0; |
77 uint32_t vobu_start, next_vobu; | |
303
52cda7471a24
fixed off-by-one bug in scan_admap (copied reference code from ifo_print.c); reported by ggurov+abv-bg
nicodvb
parents:
302
diff
changeset
|
78 int admap_entries = (admap->last_byte + 1 - VOBU_ADMAP_SIZE)/VOBU_ADMAP_SIZE; |
24 | 79 |
80 /* Search through ADMAP for best sector */ | |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
81 vobu_start = SRI_END_OF_CELL; |
24 | 82 /* FIXME: Implement a faster search algorithm */ |
304
0110b591bf9c
make dvdnav_sector_search() work correctly for blocks in the last vobu; patch by ggurov+abv-bg
nicodvb
parents:
303
diff
changeset
|
83 while(address < admap_entries) { |
24 | 84 next_vobu = admap->vobu_start_sectors[address]; |
85 | |
76 | 86 /* fprintf(MSG_OUT, "libdvdnav: Found block %u\n", next_vobu); */ |
24 | 87 |
305 | 88 if(vobu_start <= seekto_block && next_vobu > seekto_block) |
304
0110b591bf9c
make dvdnav_sector_search() work correctly for blocks in the last vobu; patch by ggurov+abv-bg
nicodvb
parents:
303
diff
changeset
|
89 break; |
305 | 90 vobu_start = next_vobu; |
91 address++; | |
24 | 92 } |
305 | 93 *vobu = vobu_start; |
94 return DVDNAV_STATUS_OK; | |
24 | 95 } |
76 | 96 fprintf(MSG_OUT, "libdvdnav: admap not located\n"); |
193 | 97 return DVDNAV_STATUS_ERR; |
24 | 98 } |
99 | |
265 | 100 /* FIXME: right now, this function does not use the time tables but interpolates |
101 only the cell times */ | |
102 dvdnav_status_t dvdnav_time_search(dvdnav_t *this, | |
103 uint64_t time) { | |
388 | 104 |
265 | 105 uint64_t target = time; |
106 uint64_t length = 0; | |
107 uint32_t first_cell_nr, last_cell_nr, cell_nr; | |
108 int32_t found; | |
109 cell_playback_t *cell; | |
110 dvd_state_t *state; | |
111 | |
112 if(this->position_current.still != 0) { | |
113 printerr("Cannot seek in a still frame."); | |
114 return DVDNAV_STATUS_ERR; | |
115 } | |
388 | 116 |
265 | 117 pthread_mutex_lock(&this->vm_lock); |
118 state = &(this->vm->state); | |
119 if(!state->pgc) { | |
120 printerr("No current PGC."); | |
121 pthread_mutex_unlock(&this->vm_lock); | |
122 return DVDNAV_STATUS_ERR; | |
123 } | |
124 | |
388 | 125 |
126 this->cur_cell_time = 0; | |
265 | 127 if (this->pgc_based) { |
128 first_cell_nr = 1; | |
129 last_cell_nr = state->pgc->nr_of_cells; | |
130 } else { | |
131 /* Find start cell of program. */ | |
132 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
133 /* Find end cell of program */ | |
134 if(state->pgN < state->pgc->nr_of_programs) | |
135 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
136 else | |
137 last_cell_nr = state->pgc->nr_of_cells; | |
138 } | |
139 | |
140 found = 0; | |
141 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { | |
142 cell = &(state->pgc->cell_playback[cell_nr-1]); | |
270
5d091ebc4c3b
in dvdnav_time_search() skip secondary angles when searching the cell to hump to
nicodvb
parents:
269
diff
changeset
|
143 if(cell->block_type == BLOCK_TYPE_ANGLE_BLOCK && cell->block_mode != BLOCK_MODE_FIRST_CELL) |
5d091ebc4c3b
in dvdnav_time_search() skip secondary angles when searching the cell to hump to
nicodvb
parents:
269
diff
changeset
|
144 continue; |
265 | 145 length = dvdnav_convert_time(&cell->playback_time); |
146 if (target >= length) { | |
147 target -= length; | |
148 } else { | |
149 /* FIXME: there must be a better way than interpolation */ | |
150 target = target * (cell->last_sector - cell->first_sector + 1) / length; | |
151 target += cell->first_sector; | |
388 | 152 |
265 | 153 found = 1; |
154 break; | |
155 } | |
156 } | |
157 | |
158 if(found) { | |
275
f8ba866996f9
in dvdnav_time_search() vobu and start are uint32_t
nicodvb
parents:
273
diff
changeset
|
159 uint32_t vobu; |
265 | 160 #ifdef LOG_DEBUG |
161 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", | |
162 cell_nr, first_cell_nr, last_cell_nr); | |
163 #endif | |
164 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { | |
275
f8ba866996f9
in dvdnav_time_search() vobu and start are uint32_t
nicodvb
parents:
273
diff
changeset
|
165 uint32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
388 | 166 |
265 | 167 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
168 #ifdef LOG_DEBUG | |
169 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , | |
170 state->cellN, state->blockN, target, vobu, start); | |
171 #endif | |
172 this->vm->hop_channel += HOP_SEEK; | |
173 pthread_mutex_unlock(&this->vm_lock); | |
174 return DVDNAV_STATUS_OK; | |
175 } | |
176 } | |
177 } | |
388 | 178 |
265 | 179 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
180 printerr("Error when seeking."); | |
181 pthread_mutex_unlock(&this->vm_lock); | |
182 return DVDNAV_STATUS_ERR; | |
183 } | |
184 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
185 dvdnav_status_t dvdnav_sector_search(dvdnav_t *this, |
195 | 186 uint64_t offset, int32_t origin) { |
0 | 187 uint32_t target = 0; |
188 uint32_t length = 0; | |
114 | 189 uint32_t first_cell_nr, last_cell_nr, cell_nr; |
195 | 190 int32_t found; |
114 | 191 cell_playback_t *cell; |
0 | 192 dvd_state_t *state; |
193 dvdnav_status_t result; | |
194 | |
114 | 195 if(this->position_current.still != 0) { |
196 printerr("Cannot seek in a still frame."); | |
193 | 197 return DVDNAV_STATUS_ERR; |
114 | 198 } |
388 | 199 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
200 result = dvdnav_get_position(this, &target, &length); |
0 | 201 if(!result) { |
193 | 202 return DVDNAV_STATUS_ERR; |
0 | 203 } |
388 | 204 |
114 | 205 pthread_mutex_lock(&this->vm_lock); |
206 state = &(this->vm->state); | |
207 if(!state->pgc) { | |
208 printerr("No current PGC."); | |
209 pthread_mutex_unlock(&this->vm_lock); | |
193 | 210 return DVDNAV_STATUS_ERR; |
114 | 211 } |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
212 #ifdef LOG_DEBUG |
388 | 213 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
214 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN); |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
215 #endif |
114 | 216 |
0 | 217 switch(origin) { |
218 case SEEK_SET: | |
302
ef017423e37c
since sectors range in [0..len-1] the target offset must be validated not to exceed length-1; reported by ggurov@abv.bg
nicodvb
parents:
301
diff
changeset
|
219 if(offset >= length) { |
114 | 220 printerr("Request to seek behind end."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
221 pthread_mutex_unlock(&this->vm_lock); |
193 | 222 return DVDNAV_STATUS_ERR; |
0 | 223 } |
224 target = offset; | |
225 break; | |
226 case SEEK_CUR: | |
302
ef017423e37c
since sectors range in [0..len-1] the target offset must be validated not to exceed length-1; reported by ggurov@abv.bg
nicodvb
parents:
301
diff
changeset
|
227 if(target + offset >= length) { |
114 | 228 printerr("Request to seek behind end."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
229 pthread_mutex_unlock(&this->vm_lock); |
193 | 230 return DVDNAV_STATUS_ERR; |
0 | 231 } |
232 target += offset; | |
233 break; | |
234 case SEEK_END: | |
301
4e24652c5ddf
in dvdnav_sector_search() replaced check (length-offset<0) with safer (length<offset) ; patch by ggurob abv bg
nicodvb
parents:
297
diff
changeset
|
235 if(length < offset) { |
114 | 236 printerr("Request to seek before start."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
237 pthread_mutex_unlock(&this->vm_lock); |
193 | 238 return DVDNAV_STATUS_ERR; |
0 | 239 } |
240 target = length - offset; | |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
241 break; |
0 | 242 default: |
243 /* Error occured */ | |
114 | 244 printerr("Illegal seek mode."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
245 pthread_mutex_unlock(&this->vm_lock); |
193 | 246 return DVDNAV_STATUS_ERR; |
0 | 247 } |
388 | 248 |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
249 this->cur_cell_time = 0; |
132 | 250 if (this->pgc_based) { |
251 first_cell_nr = 1; | |
252 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 253 } else { |
132 | 254 /* Find start cell of program. */ |
255 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
256 /* Find end cell of program */ | |
257 if(state->pgN < state->pgc->nr_of_programs) | |
258 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
259 else | |
260 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 261 } |
132 | 262 |
114 | 263 found = 0; |
0 | 264 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { |
265 cell = &(state->pgc->cell_playback[cell_nr-1]); | |
297
eb96940d93e0
in dvdnav_sector_search() when playing multiangle titles skip cells not corresponding to BLOCK_MODE_FIRST_CELL
nicodvb
parents:
294
diff
changeset
|
266 if(cell->block_type == BLOCK_TYPE_ANGLE_BLOCK && cell->block_mode != BLOCK_MODE_FIRST_CELL) |
eb96940d93e0
in dvdnav_sector_search() when playing multiangle titles skip cells not corresponding to BLOCK_MODE_FIRST_CELL
nicodvb
parents:
294
diff
changeset
|
267 continue; |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
268 length = cell->last_sector - cell->first_sector + 1; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
269 if (target >= length) { |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
270 target -= length; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
271 } else { |
131 | 272 /* convert the target sector from Cell-relative to absolute physical sector */ |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
273 target += cell->first_sector; |
114 | 274 found = 1; |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
275 break; |
0 | 276 } |
277 } | |
278 | |
114 | 279 if(found) { |
376
430d842f35bd
in dvdnav_sector_search() vobu is uint32_t it; patch by Erik Hovland org
nicodvb
parents:
332
diff
changeset
|
280 uint32_t vobu; |
114 | 281 #ifdef LOG_DEBUG |
76 | 282 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
283 cell_nr, first_cell_nr, last_cell_nr); |
114 | 284 #endif |
193 | 285 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
286 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
388 | 287 |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
288 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
114 | 289 #ifdef LOG_DEBUG |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
290 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
291 state->cellN, state->blockN, target, vobu, start); |
114 | 292 #endif |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
293 this->vm->hop_channel += HOP_SEEK; |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
294 pthread_mutex_unlock(&this->vm_lock); |
193 | 295 return DVDNAV_STATUS_OK; |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
296 } |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
297 } |
0 | 298 } |
388 | 299 |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
300 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
388 | 301 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); |
114 | 302 printerr("Error when seeking."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
303 pthread_mutex_unlock(&this->vm_lock); |
193 | 304 return DVDNAV_STATUS_ERR; |
0 | 305 } |
306 | |
195 | 307 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int32_t part) { |
308 int32_t title, old_part; | |
388 | 309 |
193 | 310 if (dvdnav_current_title_info(this, &title, &old_part) == DVDNAV_STATUS_OK) |
114 | 311 return dvdnav_part_play(this, title, part); |
193 | 312 return DVDNAV_STATUS_ERR; |
0 | 313 } |
314 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
315 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *this) { |
114 | 316 pthread_mutex_lock(&this->vm_lock); |
317 if(!this->vm->state.pgc) { | |
318 printerr("No current PGC."); | |
319 pthread_mutex_unlock(&this->vm_lock); | |
193 | 320 return DVDNAV_STATUS_ERR; |
114 | 321 } |
68
3b45c78f061e
Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents:
63
diff
changeset
|
322 |
114 | 323 #ifdef LOG_DEBUG |
113 | 324 fprintf(MSG_OUT, "libdvdnav: previous chapter\n"); |
114 | 325 #endif |
326 if (!vm_jump_prev_pg(this->vm)) { | |
327 fprintf(MSG_OUT, "libdvdnav: previous chapter failed.\n"); | |
328 printerr("Skip to previous chapter failed."); | |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
329 pthread_mutex_unlock(&this->vm_lock); |
193 | 330 return DVDNAV_STATUS_ERR; |
0 | 331 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
332 this->cur_cell_time = 0; |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
333 this->position_current.still = 0; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
334 this->vm->hop_channel++; |
114 | 335 #ifdef LOG_DEBUG |
76 | 336 fprintf(MSG_OUT, "libdvdnav: previous chapter done\n"); |
114 | 337 #endif |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
338 pthread_mutex_unlock(&this->vm_lock); |
0 | 339 |
193 | 340 return DVDNAV_STATUS_OK; |
0 | 341 } |
342 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
343 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *this) { |
114 | 344 pthread_mutex_lock(&this->vm_lock); |
345 if(!this->vm->state.pgc) { | |
346 printerr("No current PGC."); | |
347 pthread_mutex_unlock(&this->vm_lock); | |
193 | 348 return DVDNAV_STATUS_ERR; |
114 | 349 } |
68
3b45c78f061e
Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents:
63
diff
changeset
|
350 |
114 | 351 #ifdef LOG_DEBUG |
352 fprintf(MSG_OUT, "libdvdnav: top chapter\n"); | |
353 #endif | |
354 if (!vm_jump_top_pg(this->vm)) { | |
355 fprintf(MSG_OUT, "libdvdnav: top chapter failed.\n"); | |
356 printerr("Skip to top chapter failed."); | |
113 | 357 pthread_mutex_unlock(&this->vm_lock); |
193 | 358 return DVDNAV_STATUS_ERR; |
0 | 359 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
360 this->cur_cell_time = 0; |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
361 this->position_current.still = 0; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
362 this->vm->hop_channel++; |
114 | 363 #ifdef LOG_DEBUG |
364 fprintf(MSG_OUT, "libdvdnav: top chapter done\n"); | |
365 #endif | |
366 pthread_mutex_unlock(&this->vm_lock); | |
367 | |
193 | 368 return DVDNAV_STATUS_OK; |
114 | 369 } |
370 | |
371 dvdnav_status_t dvdnav_next_pg_search(dvdnav_t *this) { | |
122
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
372 vm_t *try_vm; |
114 | 373 |
374 pthread_mutex_lock(&this->vm_lock); | |
375 if(!this->vm->state.pgc) { | |
376 printerr("No current PGC."); | |
377 pthread_mutex_unlock(&this->vm_lock); | |
193 | 378 return DVDNAV_STATUS_ERR; |
114 | 379 } |
380 | |
381 #ifdef LOG_DEBUG | |
382 fprintf(MSG_OUT, "libdvdnav: next chapter\n"); | |
383 #endif | |
122
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
384 /* make a copy of current VM and try to navigate the copy to the next PG */ |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
385 try_vm = vm_new_copy(this->vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
386 if (!vm_jump_next_pg(try_vm) || try_vm->stopped) { |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
387 vm_free_copy(try_vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
388 /* next_pg failed, try to jump at least to the next cell */ |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
389 try_vm = vm_new_copy(this->vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
390 vm_get_next_cell(try_vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
391 if (try_vm->stopped) { |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
392 vm_free_copy(try_vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
393 fprintf(MSG_OUT, "libdvdnav: next chapter failed.\n"); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
394 printerr("Skip to next chapter failed."); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
395 pthread_mutex_unlock(&this->vm_lock); |
193 | 396 return DVDNAV_STATUS_ERR; |
122
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
397 } |
114 | 398 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
399 this->cur_cell_time = 0; |
122
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
400 /* merge changes on success */ |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
401 vm_merge(this->vm, try_vm); |
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
402 vm_free_copy(try_vm); |
114 | 403 this->position_current.still = 0; |
404 this->vm->hop_channel++; | |
405 #ifdef LOG_DEBUG | |
76 | 406 fprintf(MSG_OUT, "libdvdnav: next chapter done\n"); |
114 | 407 #endif |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
408 pthread_mutex_unlock(&this->vm_lock); |
0 | 409 |
193 | 410 return DVDNAV_STATUS_OK; |
0 | 411 } |
412 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
413 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) { |
125 | 414 vm_t *try_vm; |
388 | 415 |
114 | 416 pthread_mutex_lock(&this->vm_lock); |
417 if(!this->vm->state.pgc) { | |
418 printerr("No current PGC."); | |
419 pthread_mutex_unlock(&this->vm_lock); | |
193 | 420 return DVDNAV_STATUS_ERR; |
114 | 421 } |
388 | 422 |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
423 this->cur_cell_time = 0; |
125 | 424 /* make a copy of current VM and try to navigate the copy to the menu */ |
425 try_vm = vm_new_copy(this->vm); | |
162
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
426 if ( (menu == DVD_MENU_Escape) && (this->vm->state.domain != VTS_DOMAIN)) { |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
427 /* Try resume */ |
167 | 428 if (vm_jump_resume(try_vm) && !try_vm->stopped) { |
162
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
429 /* merge changes on success */ |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
430 vm_merge(this->vm, try_vm); |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
431 vm_free_copy(try_vm); |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
432 this->position_current.still = 0; |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
433 this->vm->hop_channel++; |
388 | 434 pthread_mutex_unlock(&this->vm_lock); |
193 | 435 return DVDNAV_STATUS_OK; |
162
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
436 } |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
437 } |
166 | 438 if (menu == DVD_MENU_Escape) menu = DVD_MENU_Root; |
388 | 439 |
125 | 440 if (vm_jump_menu(try_vm, menu) && !try_vm->stopped) { |
441 /* merge changes on success */ | |
442 vm_merge(this->vm, try_vm); | |
443 vm_free_copy(try_vm); | |
129 | 444 this->position_current.still = 0; |
114 | 445 this->vm->hop_channel++; |
388 | 446 pthread_mutex_unlock(&this->vm_lock); |
193 | 447 return DVDNAV_STATUS_OK; |
114 | 448 } else { |
125 | 449 vm_free_copy(try_vm); |
450 printerr("No such menu or menu not reachable."); | |
388 | 451 pthread_mutex_unlock(&this->vm_lock); |
193 | 452 return DVDNAV_STATUS_ERR; |
114 | 453 } |
0 | 454 } |
455 | |
195 | 456 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, uint32_t *pos, |
457 uint32_t *len) { | |
0 | 458 uint32_t cur_sector; |
195 | 459 int32_t cell_nr, first_cell_nr, last_cell_nr; |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
460 cell_playback_t *cell; |
0 | 461 dvd_state_t *state; |
114 | 462 |
463 if(!this->started) { | |
464 printerr("Virtual DVD machine not started."); | |
193 | 465 return DVDNAV_STATUS_ERR; |
114 | 466 } |
467 | |
468 pthread_mutex_lock(&this->vm_lock); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
469 state = &(this->vm->state); |
224
f19fce15577b
fix assertion failure when someone asks for the position between an Exit
mroi
parents:
195
diff
changeset
|
470 if(!state->pgc || this->vm->stopped) { |
114 | 471 printerr("No current PGC."); |
472 pthread_mutex_unlock(&this->vm_lock); | |
193 | 473 return DVDNAV_STATUS_ERR; |
0 | 474 } |
181
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
475 if (this->position_current.hop_channel != this->vm->hop_channel || |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
476 this->position_current.domain != state->domain || |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
477 this->position_current.vts != state->vtsN || |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
478 this->position_current.cell_restart != state->cell_restart) { |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
479 printerr("New position not yet determined."); |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
480 pthread_mutex_unlock(&this->vm_lock); |
193 | 481 return DVDNAV_STATUS_ERR; |
181
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
482 } |
114 | 483 |
0 | 484 /* Get current sector */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
485 cur_sector = this->vobu.vobu_start + this->vobu.blockN; |
0 | 486 |
132 | 487 if (this->pgc_based) { |
488 first_cell_nr = 1; | |
489 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 490 } else { |
132 | 491 /* Find start cell of program. */ |
492 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
493 /* Find end cell of program */ | |
494 if(state->pgN < state->pgc->nr_of_programs) | |
495 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
496 else | |
497 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 498 } |
132 | 499 |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
500 *pos = -1; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
501 *len = 0; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
502 for (cell_nr = first_cell_nr; cell_nr <= last_cell_nr; cell_nr++) { |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
503 cell = &(state->pgc->cell_playback[cell_nr-1]); |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
504 if (cell_nr == state->cellN) { |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
505 /* the current sector is in this cell, |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
506 * pos is length of PG up to here + sector's offset in this cell */ |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
507 *pos = *len + cur_sector - cell->first_sector; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
508 } |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
509 *len += cell->last_sector - cell->first_sector + 1; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
510 } |
388 | 511 |
166 | 512 assert((signed)*pos != -1); |
0 | 513 |
114 | 514 pthread_mutex_unlock(&this->vm_lock); |
0 | 515 |
193 | 516 return DVDNAV_STATUS_OK; |
0 | 517 } |
518 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
519 dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this, |
195 | 520 uint32_t *pos, |
521 uint32_t *len) { | |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
522 uint32_t cur_sector; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
523 uint32_t first_cell_nr; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
524 uint32_t last_cell_nr; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
525 cell_playback_t *first_cell; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
526 cell_playback_t *last_cell; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
527 dvd_state_t *state; |
114 | 528 |
529 state = &(this->vm->state); | |
530 if(!state->pgc) { | |
531 printerr("No current PGC."); | |
193 | 532 return DVDNAV_STATUS_ERR; |
114 | 533 } |
534 | |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
535 /* Get current sector */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
536 cur_sector = this->vobu.vobu_start + this->vobu.blockN; |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
537 |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
538 /* Now find first and last cells in title. */ |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
539 first_cell_nr = state->pgc->program_map[0]; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
540 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
541 last_cell_nr = state->pgc->nr_of_cells; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
542 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]); |
388 | 543 |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
544 *pos = cur_sector - first_cell->first_sector; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
545 *len = last_cell->last_sector - first_cell->first_sector; |
388 | 546 |
193 | 547 return DVDNAV_STATUS_OK; |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
548 } |
313 | 549 |
315
9abc06e356ff
now dvdnav_describe_title_chapters() also returns the duration of the title
nicodvb
parents:
314
diff
changeset
|
550 uint32_t dvdnav_describe_title_chapters(dvdnav_t *this, int32_t title, uint64_t **times, uint64_t *duration) { |
313 | 551 int32_t retval=0; |
552 uint16_t parts, i; | |
553 title_info_t *ptitle = NULL; | |
554 ptt_info_t *ptt = NULL; | |
555 ifo_handle_t *ifo; | |
556 pgc_t *pgc; | |
557 cell_playback_t *cell; | |
558 uint64_t length, *tmp=NULL; | |
559 | |
314
ba9c3555e92f
in dvdnav_describe_title_chapters() init *times to NULL, so if something fails we don't leave the ptr uninited
nicodvb
parents:
313
diff
changeset
|
560 *times = NULL; |
315
9abc06e356ff
now dvdnav_describe_title_chapters() also returns the duration of the title
nicodvb
parents:
314
diff
changeset
|
561 *duration = 0; |
313 | 562 pthread_mutex_lock(&this->vm_lock); |
563 if(!this->vm->vmgi) { | |
564 printerr("Bad VM state or missing VTSI."); | |
565 goto fail; | |
566 } | |
567 if(!this->started) { | |
568 /* don't report an error but be nice */ | |
569 vm_start(this->vm); | |
570 this->started = 1; | |
571 } | |
572 ifo = vm_get_title_ifo(this->vm, title); | |
573 if(!ifo || !ifo->vts_pgcit) { | |
574 printerr("Couldn't open IFO for chosen title, exit."); | |
575 goto fail; | |
576 } | |
388 | 577 |
313 | 578 ptitle = &this->vm->vmgi->tt_srpt->title[title-1]; |
579 parts = ptitle->nr_of_ptts; | |
580 ptt = ifo->vts_ptt_srpt->title[ptitle->vts_ttn-1].ptt; | |
388 | 581 |
313 | 582 tmp = calloc(1, sizeof(uint64_t)*parts); |
583 if(!tmp) | |
584 goto fail; | |
388 | 585 |
313 | 586 length = 0; |
587 for(i=0; i<parts; i++) { | |
588 uint32_t cellnr, endcellnr; | |
589 pgc = ifo->vts_pgcit->pgci_srp[ptt[i].pgcn-1].pgc; | |
590 if(ptt[i].pgn > pgc->nr_of_programs) { | |
591 printerr("WRONG part number."); | |
592 goto fail; | |
593 } | |
388 | 594 |
313 | 595 cellnr = pgc->program_map[ptt[i].pgn-1]; |
596 if(ptt[i].pgn < pgc->nr_of_programs) | |
597 endcellnr = pgc->program_map[ptt[i].pgn]; | |
598 else | |
599 endcellnr = 0; | |
388 | 600 |
313 | 601 do { |
602 cell = &pgc->cell_playback[cellnr-1]; | |
603 if(!(cell->block_type == BLOCK_TYPE_ANGLE_BLOCK && | |
604 cell->block_mode != BLOCK_MODE_FIRST_CELL | |
605 )) | |
606 { | |
607 tmp[i] = length + dvdnav_convert_time(&cell->playback_time); | |
608 length = tmp[i]; | |
609 } | |
610 cellnr++; | |
611 } while(cellnr < endcellnr); | |
612 } | |
315
9abc06e356ff
now dvdnav_describe_title_chapters() also returns the duration of the title
nicodvb
parents:
314
diff
changeset
|
613 *duration = length; |
313 | 614 vm_ifo_close(ifo); |
615 retval = parts; | |
616 *times = tmp; | |
617 | |
618 fail: | |
619 pthread_mutex_unlock(&this->vm_lock); | |
620 if(!retval && tmp) | |
621 free(tmp); | |
622 return retval; | |
623 } |