1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
/*
* Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net>
*
* This file is part of libdvdnav, a DVD navigation library.
*
* libdvdnav is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* libdvdnav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with libdvdnav; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <inttypes.h>
#include <limits.h>
#include <string.h>
#include <sys/time.h>
#include "dvdnav/dvdnav.h"
#include <dvdread/nav_types.h>
#include "vm/decoder.h"
#include "vm/vm.h"
#include "dvdnav_internal.h"
/* Navigation API calls */
dvdnav_status_t dvdnav_still_skip(dvdnav_t *this) {
pthread_mutex_lock(&this->vm_lock);
this->position_current.still = 0;
pthread_mutex_unlock(&this->vm_lock);
this->skip_still = 1;
this->sync_wait = 0;
this->sync_wait_skip = 1;
return DVDNAV_STATUS_OK;
}
dvdnav_status_t dvdnav_wait_skip(dvdnav_t *this) {
this->sync_wait = 0;
this->sync_wait_skip = 1;
return DVDNAV_STATUS_OK;
}
dvdnav_status_t dvdnav_get_number_of_titles(dvdnav_t *this, int32_t *titles) {
if (!this->vm->vmgi) {
printerr("Bad VM state.");
return DVDNAV_STATUS_ERR;
}
(*titles) = vm_get_vmgi(this->vm)->tt_srpt->nr_of_srpts;
return DVDNAV_STATUS_OK;
}
static dvdnav_status_t get_title_by_number(dvdnav_t *this, int32_t title,
const title_info_t **pp_title)
{
int32_t titlescount;
dvdnav_status_t status = dvdnav_get_number_of_titles(this, &titlescount);
if(status == DVDNAV_STATUS_OK)
{
if ((title < 1) || (title > titlescount)) {
printerr("Passed a title number out of range.");
status = DVDNAV_STATUS_ERR;
}
else {
*pp_title = &vm_get_vmgi(this->vm)->tt_srpt->title[title-1];
}
}
return status;
}
dvdnav_status_t dvdnav_get_number_of_parts(dvdnav_t *this, int32_t title, int32_t *parts) {
const title_info_t *info;
dvdnav_status_t status = get_title_by_number(this, title, &info);
if(status == DVDNAV_STATUS_OK)
(*parts) = info->nr_of_ptts;
return status;
}
dvdnav_status_t dvdnav_get_number_of_angles(dvdnav_t *this, int32_t title, int32_t *angles) {
const title_info_t *info;
dvdnav_status_t status = get_title_by_number(this, title, &info);
if(status == DVDNAV_STATUS_OK)
(*angles) = info->nr_of_angles;
return status;
}
dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int32_t *title, int32_t *part) {
int32_t retval;
pthread_mutex_lock(&this->vm_lock);
if (!this->vm->vtsi || !this->vm->vmgi) {
printerr("Bad VM state.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->started) {
printerr("Virtual DVD machine not started.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->vm->state.pgc) {
printerr("No current PGC.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if ( (this->vm->state.domain == DVD_DOMAIN_VTSMenu)
|| (this->vm->state.domain == DVD_DOMAIN_VMGM) ) {
/* Get current Menu ID: into *part. */
if(! vm_get_current_menu(this->vm, part)) {
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (*part > -1) {
*title = 0;
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_OK;
}
}
if (this->vm->state.domain == DVD_DOMAIN_VTSTitle) {
retval = vm_get_current_title_part(this->vm, title, part);
pthread_mutex_unlock(&this->vm_lock);
return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR;
}
printerr("Not in a title or menu.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_current_title_program(dvdnav_t *this, int32_t *title, int32_t *pgcn, int32_t *pgn) {
int32_t retval;
int32_t part;
pthread_mutex_lock(&this->vm_lock);
if (!this->vm->vtsi || !this->vm->vmgi) {
printerr("Bad VM state.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->started) {
printerr("Virtual DVD machine not started.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->vm->state.pgc) {
printerr("No current PGC.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if ( (this->vm->state.domain == DVD_DOMAIN_VTSMenu)
|| (this->vm->state.domain == DVD_DOMAIN_VMGM) ) {
/* Get current Menu ID: into *part. */
if(! vm_get_current_menu(this->vm, &part)) {
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (part > -1) {
*title = 0;
*pgcn = this->vm->state.pgcN;
*pgn = this->vm->state.pgN;
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_OK;
}
}
if (this->vm->state.domain == DVD_DOMAIN_VTSTitle) {
retval = vm_get_current_title_part(this->vm, title, &part);
*pgcn = this->vm->state.pgcN;
*pgn = this->vm->state.pgN;
pthread_mutex_unlock(&this->vm_lock);
return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR;
}
printerr("Not in a title or menu.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_title_play(dvdnav_t *this, int32_t title) {
return dvdnav_part_play(this, title, 1);
}
dvdnav_status_t dvdnav_program_play(dvdnav_t *this, int32_t title, int32_t pgcn, int32_t pgn) {
int32_t retval;
pthread_mutex_lock(&this->vm_lock);
if (!this->vm->vmgi) {
printerr("Bad VM state.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->started) {
/* don't report an error but be nice */
vm_start(this->vm);
this->started = 1;
}
if (!this->vm->state.pgc) {
printerr("No current PGC.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if((title < 1) || (title > this->vm->vmgi->tt_srpt->nr_of_srpts)) {
printerr("Title out of range.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
retval = vm_jump_title_program(this->vm, title, pgcn, pgn);
if (retval)
this->vm->hop_channel++;
pthread_mutex_unlock(&this->vm_lock);
return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_part_play(dvdnav_t *this, int32_t title, int32_t part) {
int32_t retval;
pthread_mutex_lock(&this->vm_lock);
if (!this->vm->vmgi) {
printerr("Bad VM state.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if (!this->started) {
/* don't report an error but be nice */
vm_start(this->vm);
this->started = 1;
}
if (!this->vm->state.pgc) {
printerr("No current PGC.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if((title < 1) || (title > this->vm->vmgi->tt_srpt->nr_of_srpts)) {
printerr("Title out of range.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
if((part < 1) || (part > this->vm->vmgi->tt_srpt->title[title-1].nr_of_ptts)) {
printerr("Part out of range.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
retval = vm_jump_title_part(this->vm, title, part);
if (retval)
this->vm->hop_channel++;
pthread_mutex_unlock(&this->vm_lock);
return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_part_play_auto_stop(dvdnav_t *this, int32_t title,
int32_t part, int32_t parts_to_play) {
/* FIXME: Implement auto-stop */
if (dvdnav_part_play(this, title, part) == DVDNAV_STATUS_OK)
printerr("Not implemented yet.");
return DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_time_play(dvdnav_t *this, int32_t title,
uint64_t time) {
/* FIXME: Implement */
printerr("Not implemented yet.");
return DVDNAV_STATUS_ERR;
}
dvdnav_status_t dvdnav_stop(dvdnav_t *this) {
pthread_mutex_lock(&this->vm_lock);
this->vm->stopped = 1;
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_OK;
}
dvdnav_status_t dvdnav_go_up(dvdnav_t *this) {
/* A nice easy function... delegate to the VM */
int retval;
pthread_mutex_lock(&this->vm_lock);
if (!this->vm->state.pgc) {
printerr("No current PGC.");
pthread_mutex_unlock(&this->vm_lock);
return DVDNAV_STATUS_ERR;
}
retval = vm_jump_up(this->vm);
pthread_mutex_unlock(&this->vm_lock);
return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR;
}
|