annotate searching.c @ 408:7923e813ec61 src

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