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