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