Mercurial > libdvdnav.hg
annotate searching.c @ 281:6853c398600c src
support for dvdcss in Darwin; patch by Diego Petteno' and Reimar
author | nicodvb |
---|---|
date | Wed, 18 Apr 2007 22:34:52 +0000 |
parents | ef3b33441db5 |
children | 52877d182e96 |
rev | line source |
---|---|
131 | 1 /* |
0 | 2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> |
3 * | |
4 * This file is part of libdvdnav, a DVD navigation library. | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
19 * | |
20 * $Id$ | |
21 * | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
114 | 28 #include <assert.h> |
278 | 29 #include <inttypes.h> |
0 | 30 #include "dvdnav_internal.h" |
31 | |
114 | 32 /* |
33 #define LOG_DEBUG | |
34 */ | |
35 | |
0 | 36 /* Searching API calls */ |
37 | |
24 | 38 /* Scan the ADMAP for a particular block number. */ |
39 /* Return placed in vobu. */ | |
40 /* Returns error status */ | |
114 | 41 /* FIXME: Maybe need to handle seeking outside current cell. */ |
195 | 42 static dvdnav_status_t dvdnav_scan_admap(dvdnav_t *this, int32_t domain, uint32_t seekto_block, uint32_t *vobu) { |
24 | 43 vobu_admap_t *admap = NULL; |
114 | 44 |
45 #ifdef LOG_DEBUG | |
46 fprintf(MSG_OUT, "libdvdnav: Seeking to target %u ...\n", seekto_block); | |
47 #endif | |
24 | 48 *vobu = -1; |
49 | |
50 /* Search through the VOBU_ADMAP for the nearest VOBU | |
51 * to the target block */ | |
52 switch(domain) { | |
114 | 53 case FP_DOMAIN: |
54 case VMGM_DOMAIN: | |
55 admap = this->vm->vmgi->menu_vobu_admap; | |
56 break; | |
57 case VTSM_DOMAIN: | |
58 admap = this->vm->vtsi->menu_vobu_admap; | |
59 break; | |
60 case VTS_DOMAIN: | |
61 admap = this->vm->vtsi->vts_vobu_admap; | |
62 break; | |
63 default: | |
64 fprintf(MSG_OUT, "libdvdnav: Error: Unknown domain for seeking.\n"); | |
24 | 65 } |
66 if(admap) { | |
166 | 67 uint32_t address = 0; |
68 uint32_t vobu_start, next_vobu; | |
195 | 69 int32_t found = 0; |
24 | 70 |
71 /* Search through ADMAP for best sector */ | |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
72 vobu_start = SRI_END_OF_CELL; |
24 | 73 /* FIXME: Implement a faster search algorithm */ |
74 while((!found) && ((address<<2) < admap->last_byte)) { | |
75 next_vobu = admap->vobu_start_sectors[address]; | |
76 | |
76 | 77 /* fprintf(MSG_OUT, "libdvdnav: Found block %u\n", next_vobu); */ |
24 | 78 |
79 if(vobu_start <= seekto_block && | |
80 next_vobu > seekto_block) { | |
81 found = 1; | |
82 } else { | |
83 vobu_start = next_vobu; | |
84 } | |
85 address ++; | |
86 } | |
87 if(found) { | |
88 *vobu = vobu_start; | |
193 | 89 return DVDNAV_STATUS_OK; |
24 | 90 } else { |
76 | 91 fprintf(MSG_OUT, "libdvdnav: Could not locate block\n"); |
193 | 92 return DVDNAV_STATUS_ERR; |
24 | 93 } |
94 } | |
76 | 95 fprintf(MSG_OUT, "libdvdnav: admap not located\n"); |
193 | 96 return DVDNAV_STATUS_ERR; |
24 | 97 } |
98 | |
265 | 99 /* FIXME: right now, this function does not use the time tables but interpolates |
100 only the cell times */ | |
101 dvdnav_status_t dvdnav_time_search(dvdnav_t *this, | |
102 uint64_t time) { | |
103 | |
104 uint64_t target = time; | |
105 uint64_t length = 0; | |
106 uint32_t first_cell_nr, last_cell_nr, cell_nr; | |
107 int32_t found; | |
108 cell_playback_t *cell; | |
109 dvd_state_t *state; | |
110 | |
111 if(this->position_current.still != 0) { | |
112 printerr("Cannot seek in a still frame."); | |
113 return DVDNAV_STATUS_ERR; | |
114 } | |
115 | |
116 pthread_mutex_lock(&this->vm_lock); | |
117 state = &(this->vm->state); | |
118 if(!state->pgc) { | |
119 printerr("No current PGC."); | |
120 pthread_mutex_unlock(&this->vm_lock); | |
121 return DVDNAV_STATUS_ERR; | |
122 } | |
123 | |
124 | |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
125 this->cur_cell_time = 0; |
265 | 126 if (this->pgc_based) { |
127 first_cell_nr = 1; | |
128 last_cell_nr = state->pgc->nr_of_cells; | |
129 } else { | |
130 /* Find start cell of program. */ | |
131 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
132 /* Find end cell of program */ | |
133 if(state->pgN < state->pgc->nr_of_programs) | |
134 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
135 else | |
136 last_cell_nr = state->pgc->nr_of_cells; | |
137 } | |
138 | |
139 found = 0; | |
140 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { | |
141 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
|
142 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
|
143 continue; |
265 | 144 length = dvdnav_convert_time(&cell->playback_time); |
145 if (target >= length) { | |
146 target -= length; | |
147 } else { | |
148 /* FIXME: there must be a better way than interpolation */ | |
149 target = target * (cell->last_sector - cell->first_sector + 1) / length; | |
150 target += cell->first_sector; | |
151 | |
152 found = 1; | |
153 break; | |
154 } | |
155 } | |
156 | |
157 if(found) { | |
275
f8ba866996f9
in dvdnav_time_search() vobu and start are uint32_t
nicodvb
parents:
273
diff
changeset
|
158 uint32_t vobu; |
265 | 159 #ifdef LOG_DEBUG |
160 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", | |
161 cell_nr, first_cell_nr, last_cell_nr); | |
162 #endif | |
163 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
|
164 uint32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
265 | 165 |
166 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { | |
167 #ifdef LOG_DEBUG | |
168 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , | |
169 state->cellN, state->blockN, target, vobu, start); | |
170 #endif | |
171 this->vm->hop_channel += HOP_SEEK; | |
172 pthread_mutex_unlock(&this->vm_lock); | |
173 return DVDNAV_STATUS_OK; | |
174 } | |
175 } | |
176 } | |
177 | |
178 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); | |
179 printerr("Error when seeking."); | |
180 pthread_mutex_unlock(&this->vm_lock); | |
181 return DVDNAV_STATUS_ERR; | |
182 } | |
183 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
184 dvdnav_status_t dvdnav_sector_search(dvdnav_t *this, |
195 | 185 uint64_t offset, int32_t origin) { |
0 | 186 uint32_t target = 0; |
187 uint32_t length = 0; | |
114 | 188 uint32_t first_cell_nr, last_cell_nr, cell_nr; |
195 | 189 int32_t found; |
114 | 190 cell_playback_t *cell; |
0 | 191 dvd_state_t *state; |
192 dvdnav_status_t result; | |
193 | |
114 | 194 if(this->position_current.still != 0) { |
195 printerr("Cannot seek in a still frame."); | |
193 | 196 return DVDNAV_STATUS_ERR; |
114 | 197 } |
0 | 198 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
199 result = dvdnav_get_position(this, &target, &length); |
0 | 200 if(!result) { |
193 | 201 return DVDNAV_STATUS_ERR; |
0 | 202 } |
203 | |
114 | 204 pthread_mutex_lock(&this->vm_lock); |
205 state = &(this->vm->state); | |
206 if(!state->pgc) { | |
207 printerr("No current PGC."); | |
208 pthread_mutex_unlock(&this->vm_lock); | |
193 | 209 return DVDNAV_STATUS_ERR; |
114 | 210 } |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
211 #ifdef LOG_DEBUG |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
212 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
213 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
|
214 #endif |
114 | 215 |
0 | 216 switch(origin) { |
217 case SEEK_SET: | |
218 if(offset > length) { | |
114 | 219 printerr("Request to seek behind end."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
220 pthread_mutex_unlock(&this->vm_lock); |
193 | 221 return DVDNAV_STATUS_ERR; |
0 | 222 } |
223 target = offset; | |
224 break; | |
225 case SEEK_CUR: | |
226 if(target + offset > length) { | |
114 | 227 printerr("Request to seek behind end."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
228 pthread_mutex_unlock(&this->vm_lock); |
193 | 229 return DVDNAV_STATUS_ERR; |
0 | 230 } |
231 target += offset; | |
232 break; | |
233 case SEEK_END: | |
234 if(length - offset < 0) { | |
114 | 235 printerr("Request to seek before start."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
236 pthread_mutex_unlock(&this->vm_lock); |
193 | 237 return DVDNAV_STATUS_ERR; |
0 | 238 } |
239 target = length - offset; | |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
240 break; |
0 | 241 default: |
242 /* Error occured */ | |
114 | 243 printerr("Illegal seek mode."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
244 pthread_mutex_unlock(&this->vm_lock); |
193 | 245 return DVDNAV_STATUS_ERR; |
0 | 246 } |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
247 |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
248 this->cur_cell_time = 0; |
132 | 249 if (this->pgc_based) { |
250 first_cell_nr = 1; | |
251 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 252 } else { |
132 | 253 /* Find start cell of program. */ |
254 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
255 /* Find end cell of program */ | |
256 if(state->pgN < state->pgc->nr_of_programs) | |
257 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
258 else | |
259 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 260 } |
132 | 261 |
114 | 262 found = 0; |
0 | 263 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { |
264 cell = &(state->pgc->cell_playback[cell_nr-1]); | |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
265 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
|
266 if (target >= length) { |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
267 target -= length; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
268 } else { |
131 | 269 /* 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
|
270 target += cell->first_sector; |
114 | 271 found = 1; |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
272 break; |
0 | 273 } |
274 } | |
275 | |
114 | 276 if(found) { |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
277 int32_t vobu; |
114 | 278 #ifdef LOG_DEBUG |
76 | 279 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
|
280 cell_nr, first_cell_nr, last_cell_nr); |
114 | 281 #endif |
193 | 282 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
|
283 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
284 |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
285 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
114 | 286 #ifdef LOG_DEBUG |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
287 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
|
288 state->cellN, state->blockN, target, vobu, start); |
114 | 289 #endif |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
290 this->vm->hop_channel += HOP_SEEK; |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
291 pthread_mutex_unlock(&this->vm_lock); |
193 | 292 return DVDNAV_STATUS_OK; |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
293 } |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
294 } |
0 | 295 } |
114 | 296 |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
132
diff
changeset
|
297 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
76 | 298 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); |
114 | 299 printerr("Error when seeking."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
300 pthread_mutex_unlock(&this->vm_lock); |
193 | 301 return DVDNAV_STATUS_ERR; |
0 | 302 } |
303 | |
195 | 304 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int32_t part) { |
305 int32_t title, old_part; | |
114 | 306 |
193 | 307 if (dvdnav_current_title_info(this, &title, &old_part) == DVDNAV_STATUS_OK) |
114 | 308 return dvdnav_part_play(this, title, part); |
193 | 309 return DVDNAV_STATUS_ERR; |
0 | 310 } |
311 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
312 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *this) { |
114 | 313 pthread_mutex_lock(&this->vm_lock); |
314 if(!this->vm->state.pgc) { | |
315 printerr("No current PGC."); | |
316 pthread_mutex_unlock(&this->vm_lock); | |
193 | 317 return DVDNAV_STATUS_ERR; |
114 | 318 } |
68
3b45c78f061e
Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents:
63
diff
changeset
|
319 |
114 | 320 #ifdef LOG_DEBUG |
113 | 321 fprintf(MSG_OUT, "libdvdnav: previous chapter\n"); |
114 | 322 #endif |
323 if (!vm_jump_prev_pg(this->vm)) { | |
324 fprintf(MSG_OUT, "libdvdnav: previous chapter failed.\n"); | |
325 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
|
326 pthread_mutex_unlock(&this->vm_lock); |
193 | 327 return DVDNAV_STATUS_ERR; |
0 | 328 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
329 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
|
330 this->position_current.still = 0; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
331 this->vm->hop_channel++; |
114 | 332 #ifdef LOG_DEBUG |
76 | 333 fprintf(MSG_OUT, "libdvdnav: previous chapter done\n"); |
114 | 334 #endif |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
335 pthread_mutex_unlock(&this->vm_lock); |
0 | 336 |
193 | 337 return DVDNAV_STATUS_OK; |
0 | 338 } |
339 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
340 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *this) { |
114 | 341 pthread_mutex_lock(&this->vm_lock); |
342 if(!this->vm->state.pgc) { | |
343 printerr("No current PGC."); | |
344 pthread_mutex_unlock(&this->vm_lock); | |
193 | 345 return DVDNAV_STATUS_ERR; |
114 | 346 } |
68
3b45c78f061e
Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents:
63
diff
changeset
|
347 |
114 | 348 #ifdef LOG_DEBUG |
349 fprintf(MSG_OUT, "libdvdnav: top chapter\n"); | |
350 #endif | |
351 if (!vm_jump_top_pg(this->vm)) { | |
352 fprintf(MSG_OUT, "libdvdnav: top chapter failed.\n"); | |
353 printerr("Skip to top chapter failed."); | |
113 | 354 pthread_mutex_unlock(&this->vm_lock); |
193 | 355 return DVDNAV_STATUS_ERR; |
0 | 356 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
357 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
|
358 this->position_current.still = 0; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
359 this->vm->hop_channel++; |
114 | 360 #ifdef LOG_DEBUG |
361 fprintf(MSG_OUT, "libdvdnav: top chapter done\n"); | |
362 #endif | |
363 pthread_mutex_unlock(&this->vm_lock); | |
364 | |
193 | 365 return DVDNAV_STATUS_OK; |
114 | 366 } |
367 | |
368 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
|
369 vm_t *try_vm; |
114 | 370 |
371 pthread_mutex_lock(&this->vm_lock); | |
372 if(!this->vm->state.pgc) { | |
373 printerr("No current PGC."); | |
374 pthread_mutex_unlock(&this->vm_lock); | |
193 | 375 return DVDNAV_STATUS_ERR; |
114 | 376 } |
377 | |
378 #ifdef LOG_DEBUG | |
379 fprintf(MSG_OUT, "libdvdnav: next chapter\n"); | |
380 #endif | |
122
29b046894eac
use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents:
119
diff
changeset
|
381 /* 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
|
382 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
|
383 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
|
384 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
|
385 /* 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 pthread_mutex_unlock(&this->vm_lock); |
193 | 393 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
|
394 } |
114 | 395 } |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
396 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
|
397 /* 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
|
398 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
|
399 vm_free_copy(try_vm); |
114 | 400 this->position_current.still = 0; |
401 this->vm->hop_channel++; | |
402 #ifdef LOG_DEBUG | |
76 | 403 fprintf(MSG_OUT, "libdvdnav: next chapter done\n"); |
114 | 404 #endif |
102
3e6970dbe8d6
- allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents:
90
diff
changeset
|
405 pthread_mutex_unlock(&this->vm_lock); |
0 | 406 |
193 | 407 return DVDNAV_STATUS_OK; |
0 | 408 } |
409 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
410 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) { |
125 | 411 vm_t *try_vm; |
114 | 412 |
413 pthread_mutex_lock(&this->vm_lock); | |
414 if(!this->vm->state.pgc) { | |
415 printerr("No current PGC."); | |
416 pthread_mutex_unlock(&this->vm_lock); | |
193 | 417 return DVDNAV_STATUS_ERR; |
114 | 418 } |
419 | |
269
77e472cef5f8
implemented dvdnav_get_current_time() with obvious meaning
nicodvb
parents:
265
diff
changeset
|
420 this->cur_cell_time = 0; |
125 | 421 /* make a copy of current VM and try to navigate the copy to the menu */ |
422 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
|
423 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
|
424 /* Try resume */ |
167 | 425 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
|
426 /* merge changes on success */ |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
427 vm_merge(this->vm, try_vm); |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
428 vm_free_copy(try_vm); |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
429 this->position_current.still = 0; |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
430 this->vm->hop_channel++; |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
431 pthread_mutex_unlock(&this->vm_lock); |
193 | 432 return DVDNAV_STATUS_OK; |
162
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
433 } |
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
434 } |
166 | 435 if (menu == DVD_MENU_Escape) menu = DVD_MENU_Root; |
162
0fd70a257b44
Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents:
136
diff
changeset
|
436 |
125 | 437 if (vm_jump_menu(try_vm, menu) && !try_vm->stopped) { |
438 /* merge changes on success */ | |
439 vm_merge(this->vm, try_vm); | |
440 vm_free_copy(try_vm); | |
129 | 441 this->position_current.still = 0; |
114 | 442 this->vm->hop_channel++; |
443 pthread_mutex_unlock(&this->vm_lock); | |
193 | 444 return DVDNAV_STATUS_OK; |
114 | 445 } else { |
125 | 446 vm_free_copy(try_vm); |
447 printerr("No such menu or menu not reachable."); | |
114 | 448 pthread_mutex_unlock(&this->vm_lock); |
193 | 449 return DVDNAV_STATUS_ERR; |
114 | 450 } |
0 | 451 } |
452 | |
195 | 453 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, uint32_t *pos, |
454 uint32_t *len) { | |
0 | 455 uint32_t cur_sector; |
195 | 456 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
|
457 cell_playback_t *cell; |
0 | 458 dvd_state_t *state; |
114 | 459 |
460 if(!this->started) { | |
461 printerr("Virtual DVD machine not started."); | |
193 | 462 return DVDNAV_STATUS_ERR; |
114 | 463 } |
464 | |
465 pthread_mutex_lock(&this->vm_lock); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
466 state = &(this->vm->state); |
224
f19fce15577b
fix assertion failure when someone asks for the position between an Exit
mroi
parents:
195
diff
changeset
|
467 if(!state->pgc || this->vm->stopped) { |
114 | 468 printerr("No current PGC."); |
469 pthread_mutex_unlock(&this->vm_lock); | |
193 | 470 return DVDNAV_STATUS_ERR; |
0 | 471 } |
181
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
472 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
|
473 this->position_current.domain != state->domain || |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
474 this->position_current.vts != state->vtsN || |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
475 this->position_current.cell_restart != state->cell_restart) { |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
476 printerr("New position not yet determined."); |
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
477 pthread_mutex_unlock(&this->vm_lock); |
193 | 478 return DVDNAV_STATUS_ERR; |
181
5d9770cb2961
fix some conditions where the following assertion would fail
mroi
parents:
167
diff
changeset
|
479 } |
114 | 480 |
0 | 481 /* Get current sector */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
482 cur_sector = this->vobu.vobu_start + this->vobu.blockN; |
0 | 483 |
132 | 484 if (this->pgc_based) { |
485 first_cell_nr = 1; | |
486 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 487 } else { |
132 | 488 /* Find start cell of program. */ |
489 first_cell_nr = state->pgc->program_map[state->pgN-1]; | |
490 /* Find end cell of program */ | |
491 if(state->pgN < state->pgc->nr_of_programs) | |
492 last_cell_nr = state->pgc->program_map[state->pgN] - 1; | |
493 else | |
494 last_cell_nr = state->pgc->nr_of_cells; | |
0 | 495 } |
132 | 496 |
130
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
497 *pos = -1; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
498 *len = 0; |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
499 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
|
500 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
|
501 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
|
502 /* 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
|
503 * 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
|
504 *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
|
505 } |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
506 *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
|
507 } |
f47065513ad8
do not assume PGs to be physically layed out in sequence on the disc
mroi
parents:
129
diff
changeset
|
508 |
166 | 509 assert((signed)*pos != -1); |
0 | 510 |
114 | 511 pthread_mutex_unlock(&this->vm_lock); |
0 | 512 |
193 | 513 return DVDNAV_STATUS_OK; |
0 | 514 } |
515 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
516 dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this, |
195 | 517 uint32_t *pos, |
518 uint32_t *len) { | |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
519 uint32_t cur_sector; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
520 uint32_t first_cell_nr; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
521 uint32_t last_cell_nr; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
522 cell_playback_t *first_cell; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
523 cell_playback_t *last_cell; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
524 dvd_state_t *state; |
114 | 525 |
526 state = &(this->vm->state); | |
527 if(!state->pgc) { | |
528 printerr("No current PGC."); | |
193 | 529 return DVDNAV_STATUS_ERR; |
114 | 530 } |
531 | |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
532 /* Get current sector */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
8
diff
changeset
|
533 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
|
534 |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
535 /* 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
|
536 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
|
537 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
|
538 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
|
539 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]); |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
540 |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
541 *pos = cur_sector - first_cell->first_sector; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
542 *len = last_cell->last_sector - first_cell->first_sector; |
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
543 |
193 | 544 return DVDNAV_STATUS_OK; |
8
66708b4a1b5e
Stop C++ bitching about some things and extend the menus example
richwareham
parents:
3
diff
changeset
|
545 } |