annotate searching.c @ 167:e9987c07e255 src

some code beautification: * rename vm_resume to vm_jump_resume for consistency's sake * functions in vm.c do not return dvdnav_status_t, but simple C boolean (that is 1 or 0) * set the pgcN for the first play PGC
author mroi
date Mon, 21 Apr 2003 13:24:31 +0000
parents 3bfaec0c1288
children 5d9770cb2961
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>
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
3 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
4 * This file is part of libdvdnav, a DVD navigation library.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
5 *
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.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
10 *
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.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
15 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
19 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
20 * $Id$
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
21 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
22 */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
23
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
25 #include "config.h"
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
26 #endif
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
27
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
28 #include <assert.h>
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
29 #include "dvdnav_internal.h"
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
30
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
31 /*
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
32 #define LOG_DEBUG
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
33 */
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
34
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
35 /* Searching API calls */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
36
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
37 dvdnav_status_t dvdnav_time_search(dvdnav_t *this,
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
38 unsigned long int time) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
39 /* FIXME: Time search the current PGC based on the xxx table */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
40 return S_OK;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
41 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
42
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
43 /* Scan the ADMAP for a particular block number. */
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
44 /* Return placed in vobu. */
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
45 /* Returns error status */
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
46 /* FIXME: Maybe need to handle seeking outside current cell. */
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
47 static dvdnav_status_t dvdnav_scan_admap(dvdnav_t *this, int domain, uint32_t seekto_block, uint32_t *vobu) {
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
48 vobu_admap_t *admap = NULL;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
49
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
50 #ifdef LOG_DEBUG
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
51 fprintf(MSG_OUT, "libdvdnav: Seeking to target %u ...\n", seekto_block);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
52 #endif
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
53 *vobu = -1;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
54
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
55 /* Search through the VOBU_ADMAP for the nearest VOBU
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
56 * to the target block */
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
57 switch(domain) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
58 case FP_DOMAIN:
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
59 case VMGM_DOMAIN:
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
60 admap = this->vm->vmgi->menu_vobu_admap;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
61 break;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
62 case VTSM_DOMAIN:
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
63 admap = this->vm->vtsi->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 VTS_DOMAIN:
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
66 admap = this->vm->vtsi->vts_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 default:
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
69 fprintf(MSG_OUT, "libdvdnav: Error: Unknown domain for seeking.\n");
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
70 }
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
71 if(admap) {
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
72 uint32_t address = 0;
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
73 uint32_t vobu_start, next_vobu;
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
74 int found = 0;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
75
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
76 /* Search through ADMAP for best sector */
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
77 vobu_start = SRI_END_OF_CELL;
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
78 /* FIXME: Implement a faster search algorithm */
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
79 while((!found) && ((address<<2) < admap->last_byte)) {
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
80 next_vobu = admap->vobu_start_sectors[address];
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
81
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
82 /* fprintf(MSG_OUT, "libdvdnav: Found block %u\n", next_vobu); */
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
83
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
84 if(vobu_start <= seekto_block &&
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
85 next_vobu > seekto_block) {
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
86 found = 1;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
87 } else {
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
88 vobu_start = next_vobu;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
89 }
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
90 address ++;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
91 }
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
92 if(found) {
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
93 *vobu = vobu_start;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
94 return S_OK;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
95 } else {
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
96 fprintf(MSG_OUT, "libdvdnav: Could not locate block\n");
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
97 return S_ERR;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
98 }
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
99 }
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
100 fprintf(MSG_OUT, "libdvdnav: admap not located\n");
24
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
101 return S_ERR;
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
102 }
870a0a1eee41 Re-implemented seeking.
jcdutton
parents: 22
diff changeset
103
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
104 dvdnav_status_t dvdnav_sector_search(dvdnav_t *this,
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
105 unsigned long int offset, int origin) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
106 uint32_t target = 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
107 uint32_t length = 0;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
108 uint32_t first_cell_nr, last_cell_nr, cell_nr;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
109 int found;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
110 cell_playback_t *cell;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
111 dvd_state_t *state;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
112 dvdnav_status_t result;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
113
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
114 if(this->position_current.still != 0) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
115 printerr("Cannot seek in a still frame.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
116 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
117 }
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
118
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
119 result = dvdnav_get_position(this, &target, &length);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
120 if(!result) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
121 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
122 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
123
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
124 pthread_mutex_lock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
125 state = &(this->vm->state);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
126 if(!state->pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
127 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
128 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
129 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
130 }
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
131 #ifdef LOG_DEBUG
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
132 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
133 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
134 #endif
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
135
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
136 switch(origin) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
137 case SEEK_SET:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
138 if(offset > length) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
139 printerr("Request to seek behind end.");
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
140 pthread_mutex_unlock(&this->vm_lock);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
141 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
142 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
143 target = offset;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
144 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
145 case SEEK_CUR:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
146 if(target + offset > length) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
147 printerr("Request to seek behind end.");
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
148 pthread_mutex_unlock(&this->vm_lock);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
149 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
150 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
151 target += offset;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
152 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
153 case SEEK_END:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
154 if(length - offset < 0) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
155 printerr("Request to seek before start.");
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
156 pthread_mutex_unlock(&this->vm_lock);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
157 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
158 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
159 target = length - offset;
102
3e6970dbe8d6 - allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents: 90
diff changeset
160 break;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
161 default:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
162 /* Error occured */
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
163 printerr("Illegal seek mode.");
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
164 pthread_mutex_unlock(&this->vm_lock);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
165 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
166 }
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
167
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
168 if (this->pgc_based) {
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
169 first_cell_nr = 1;
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
170 last_cell_nr = state->pgc->nr_of_cells;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
171 } else {
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
172 /* Find start cell of program. */
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
173 first_cell_nr = state->pgc->program_map[state->pgN-1];
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
174 /* Find end cell of program */
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
175 if(state->pgN < state->pgc->nr_of_programs)
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
176 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
177 else
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
178 last_cell_nr = state->pgc->nr_of_cells;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
179 }
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
180
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
181 found = 0;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
182 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
183 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
184 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
185 if (target >= length) {
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
186 target -= length;
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
187 } else {
131
ada79e606d8d fix comment
mroi
parents: 130
diff changeset
188 /* 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
189 target += cell->first_sector;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
190 found = 1;
130
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
191 break;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
192 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
193 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
194
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
195 if(found) {
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
196 int32_t vobu;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
197 #ifdef LOG_DEBUG
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
198 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
199 cell_nr, first_cell_nr, last_cell_nr);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
200 #endif
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
201 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == S_OK) {
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
202 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
203
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
204 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
205 #ifdef LOG_DEBUG
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
206 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
207 state->cellN, state->blockN, target, vobu, start);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
208 #endif
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
209 this->vm->hop_channel += HOP_SEEK;
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
210 pthread_mutex_unlock(&this->vm_lock);
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
211 return S_OK;
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
212 }
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
213 }
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
214 }
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
215
133
d09a81cf65ce determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents: 132
diff changeset
216 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n");
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
217 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
218 printerr("Error when seeking.");
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
219 pthread_mutex_unlock(&this->vm_lock);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
220 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
221 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
222
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
223 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int part) {
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
224 int title, old_part;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
225
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
226 if (dvdnav_current_title_info(this, &title, &old_part) == S_OK)
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
227 return dvdnav_part_play(this, title, part);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
228 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
229 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
230
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
231 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *this) {
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
232
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
233 if(!this) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
234 printerr("Passed a NULL pointer.");
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
235 return S_ERR;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
236 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
237
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
238 pthread_mutex_lock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
239 if(!this->vm->state.pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
240 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
241 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
242 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
243 }
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
244
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
245 #ifdef LOG_DEBUG
113
ec2df154be56 slightly improved logic of program skipping:
mroi
parents: 104
diff changeset
246 fprintf(MSG_OUT, "libdvdnav: previous chapter\n");
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
247 #endif
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
248 if (!vm_jump_prev_pg(this->vm)) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
249 fprintf(MSG_OUT, "libdvdnav: previous chapter failed.\n");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
250 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
251 pthread_mutex_unlock(&this->vm_lock);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
252 return S_ERR;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
253 }
102
3e6970dbe8d6 - allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents: 90
diff changeset
254 this->position_current.still = 0;
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
255 this->vm->hop_channel++;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
256 #ifdef LOG_DEBUG
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
257 fprintf(MSG_OUT, "libdvdnav: previous chapter done\n");
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
258 #endif
102
3e6970dbe8d6 - allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents: 90
diff changeset
259 pthread_mutex_unlock(&this->vm_lock);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
260
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
261 return S_OK;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
262 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
263
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
264 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *this) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
265
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
266 if(!this) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
267 printerr("Passed a NULL pointer.");
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
268 return S_ERR;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
269 }
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
270
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
271 pthread_mutex_lock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
272 if(!this->vm->state.pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
273 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
274 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
275 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
276 }
68
3b45c78f061e Some NULL-pointer check from aschultz@cs.uni-magdeburg.de
richwareham
parents: 63
diff changeset
277
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
278 #ifdef LOG_DEBUG
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
279 fprintf(MSG_OUT, "libdvdnav: top chapter\n");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
280 #endif
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
281 if (!vm_jump_top_pg(this->vm)) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
282 fprintf(MSG_OUT, "libdvdnav: top chapter failed.\n");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
283 printerr("Skip to top chapter failed.");
113
ec2df154be56 slightly improved logic of program skipping:
mroi
parents: 104
diff changeset
284 pthread_mutex_unlock(&this->vm_lock);
ec2df154be56 slightly improved logic of program skipping:
mroi
parents: 104
diff changeset
285 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
286 }
102
3e6970dbe8d6 - allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents: 90
diff changeset
287 this->position_current.still = 0;
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
288 this->vm->hop_channel++;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
289 #ifdef LOG_DEBUG
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
290 fprintf(MSG_OUT, "libdvdnav: top chapter done\n");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
291 #endif
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
292 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
293
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
294 return S_OK;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
295 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
296
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
297 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
298 vm_t *try_vm;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
299
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
300 if(!this) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
301 printerr("Passed a NULL pointer.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
302 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
303 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
304
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
305 pthread_mutex_lock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
306 if(!this->vm->state.pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
307 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
308 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
309 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
310 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
311
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
312 #ifdef LOG_DEBUG
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
313 fprintf(MSG_OUT, "libdvdnav: next chapter\n");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
314 #endif
122
29b046894eac use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents: 119
diff changeset
315 /* 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
316 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
317 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
318 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
319 /* 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
320 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
321 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
322 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
323 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
324 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
325 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
326 pthread_mutex_unlock(&this->vm_lock);
29b046894eac use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents: 119
diff changeset
327 return S_ERR;
29b046894eac use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents: 119
diff changeset
328 }
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
329 }
122
29b046894eac use the new VM copy mechanism to try-run program skipping and report failure in case
mroi
parents: 119
diff changeset
330 /* 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
331 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
332 vm_free_copy(try_vm);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
333 this->position_current.still = 0;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
334 this->vm->hop_channel++;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
335 #ifdef LOG_DEBUG
76
0e2abe7083de more consistent console output
mroi
parents: 68
diff changeset
336 fprintf(MSG_OUT, "libdvdnav: next chapter done\n");
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
337 #endif
102
3e6970dbe8d6 - allow seeking to offset 0 (pressing '0' in xine won't work otherwise)
mroi
parents: 90
diff changeset
338 pthread_mutex_unlock(&this->vm_lock);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
339
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
340 return S_OK;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
341 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
342
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
343 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) {
125
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
344 vm_t *try_vm;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
345
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
346 if(!this) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
347 printerr("Passed a NULL pointer.");
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
348 return S_ERR;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
349 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
350
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
351 pthread_mutex_lock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
352 if(!this->vm->state.pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
353 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
354 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
355 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
356 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
357
125
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
358 /* 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
359 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
360 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
361 /* Try resume */
167
e9987c07e255 some code beautification:
mroi
parents: 166
diff changeset
362 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
363 /* merge changes on success */
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
364 vm_merge(this->vm, try_vm);
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
365 vm_free_copy(try_vm);
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
366 this->position_current.still = 0;
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
367 this->vm->hop_channel++;
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
368 pthread_mutex_unlock(&this->vm_lock);
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
369 return S_OK;
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
370 }
0fd70a257b44 Implement ESCAPE key jumping from TITLE to MENU and back again.
jcdutton
parents: 136
diff changeset
371 }
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
372 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
373
125
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
374 if (vm_jump_menu(try_vm, menu) && !try_vm->stopped) {
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
375 /* merge changes on success */
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
376 vm_merge(this->vm, try_vm);
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
377 vm_free_copy(try_vm);
129
b48f53f7cff2 release stills when jumping to a menu
mroi
parents: 125
diff changeset
378 this->position_current.still = 0;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
379 this->vm->hop_channel++;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
380 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
381 return S_OK;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
382 } else {
125
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
383 vm_free_copy(try_vm);
87400040e4a4 try-run menu jumps
mroi
parents: 122
diff changeset
384 printerr("No such menu or menu not reachable.");
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
385 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
386 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
387 }
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
388 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
389
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
390 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, unsigned int *pos,
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
391 unsigned int *len) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
392 uint32_t cur_sector;
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
393 int 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
394 cell_playback_t *cell;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
395 dvd_state_t *state;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
396
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
397 if(!this || !pos || !len) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
398 printerr("Passed a NULL pointer.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
399 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
400 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
401 if(!this->started) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
402 printerr("Virtual DVD machine not started.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
403 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
404 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
405
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
406 pthread_mutex_lock(&this->vm_lock);
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
407 state = &(this->vm->state);
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
408 if(!state->pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
409 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
410 pthread_mutex_unlock(&this->vm_lock);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
411 return S_ERR;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
412 }
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
413
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
414 /* Get current sector */
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
415 cur_sector = this->vobu.vobu_start + this->vobu.blockN;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
416
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
417 if (this->pgc_based) {
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
418 first_cell_nr = 1;
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
419 last_cell_nr = state->pgc->nr_of_cells;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
420 } else {
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
421 /* Find start cell of program. */
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
422 first_cell_nr = state->pgc->program_map[state->pgN-1];
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
423 /* Find end cell of program */
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
424 if(state->pgN < state->pgc->nr_of_programs)
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
425 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
426 else
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
427 last_cell_nr = state->pgc->nr_of_cells;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
428 }
132
f22458f928b8 PGC based positioning
mroi
parents: 131
diff changeset
429
130
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
430 *pos = -1;
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
431 *len = 0;
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
432 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
433 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
434 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
435 /* 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
436 * 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
437 *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
438 }
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
439 *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
440 }
f47065513ad8 do not assume PGs to be physically layed out in sequence on the disc
mroi
parents: 129
diff changeset
441
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 163
diff changeset
442 assert((signed)*pos != -1);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
443
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
444 pthread_mutex_unlock(&this->vm_lock);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
445
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
446 return S_OK;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
447 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
448
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
449 dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this,
8
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
450 unsigned int *pos,
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
451 unsigned int *len) {
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
452 uint32_t cur_sector;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
453 uint32_t first_cell_nr;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
454 uint32_t last_cell_nr;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
455 cell_playback_t *first_cell;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
456 cell_playback_t *last_cell;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
457 dvd_state_t *state;
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
458
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
459 if(!this || !pos || !len) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
460 printerr("Passed a NULL pointer.");
8
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
461 return S_ERR;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
462 }
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
463
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
464 state = &(this->vm->state);
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
465 if(!state->pgc) {
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
466 printerr("No current PGC.");
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
467 return S_ERR;
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
468 }
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 113
diff changeset
469
8
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
470 /* Get current sector */
22
3c1df0cb3aee Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents: 8
diff changeset
471 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
472
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
473 /* 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
474 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
475 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
476 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
477 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
478
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
479 *pos = cur_sector - first_cell->first_sector;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
480 *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
481
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
482 return S_OK;
66708b4a1b5e Stop C++ bitching about some things and extend the menus example
richwareham
parents: 3
diff changeset
483 }