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