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