Mercurial > libdvdnav.hg
annotate navigation.c @ 389:d3c273ced49c src
Use consistent license headers everywhere: Fix wrong FSF address.
author | diego |
---|---|
date | Sun, 14 Sep 2008 15:40:51 +0000 |
parents | 90ca650854e0 |
children | 0a5a6f03b029 |
rev | line source |
---|---|
388 | 1 /* |
0 | 2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> |
388 | 3 * |
0 | 4 * This file is part of libdvdnav, a DVD navigation library. |
388 | 5 * |
0 | 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. | |
388 | 10 * |
0 | 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. | |
388 | 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 | 19 * |
20 * $Id$ | |
21 * | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
278 | 28 #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
|
29 #include <limits.h> |
288
ce4230602517
moved away from dvdnav_internal.h inclusion of various system headers
nicodvb
parents:
285
diff
changeset
|
30 #include <string.h> |
290 | 31 #include <sys/time.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
|
32 #include "dvd_types.h" |
386 | 33 #include <dvdread/nav_types.h> |
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" |
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
|
38 #include "dvdnav.h" |
0 | 39 #include "dvdnav_internal.h" |
40 | |
41 /* Navigation API calls */ | |
42 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
43 dvdnav_status_t dvdnav_still_skip(dvdnav_t *this) { |
387 | 44 pthread_mutex_lock(&this->vm_lock); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
45 this->position_current.still = 0; |
387 | 46 pthread_mutex_unlock(&this->vm_lock); |
23 | 47 this->skip_still = 1; |
116 | 48 this->sync_wait = 0; |
49 this->sync_wait_skip = 1; | |
50 | |
193 | 51 return DVDNAV_STATUS_OK; |
116 | 52 } |
53 | |
54 dvdnav_status_t dvdnav_wait_skip(dvdnav_t *this) { | |
55 this->sync_wait = 0; | |
56 this->sync_wait_skip = 1; | |
0 | 57 |
193 | 58 return DVDNAV_STATUS_OK; |
0 | 59 } |
60 | |
195 | 61 dvdnav_status_t dvdnav_get_number_of_titles(dvdnav_t *this, int32_t *titles) { |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
62 if (!this->vm->vmgi) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
63 printerr("Bad VM state."); |
223
2d79ef3f3956
we should not start the VM on dvdnav_get_number_of_titles,
mroi
parents:
195
diff
changeset
|
64 return DVDNAV_STATUS_ERR; |
94
e29110f67f3a
Get xine dvd:///dev/dvd:1.2 i.e. title play working again.
jcdutton
parents:
90
diff
changeset
|
65 } |
e29110f67f3a
Get xine dvd:///dev/dvd:1.2 i.e. title play working again.
jcdutton
parents:
90
diff
changeset
|
66 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
67 (*titles) = vm_get_vmgi(this->vm)->tt_srpt->nr_of_srpts; |
0 | 68 |
193 | 69 return DVDNAV_STATUS_OK; |
0 | 70 } |
71 | |
195 | 72 dvdnav_status_t dvdnav_get_number_of_parts(dvdnav_t *this, int32_t title, int32_t *parts) { |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
73 if (!this->vm->vmgi) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
74 printerr("Bad VM state."); |
193 | 75 return DVDNAV_STATUS_ERR; |
95 | 76 } |
77 if ((title < 1) || (title > vm_get_vmgi(this->vm)->tt_srpt->nr_of_srpts) ) { | |
114 | 78 printerr("Passed a title number out of range."); |
193 | 79 return DVDNAV_STATUS_ERR; |
95 | 80 } |
114 | 81 |
95 | 82 (*parts) = vm_get_vmgi(this->vm)->tt_srpt->title[title-1].nr_of_ptts; |
114 | 83 |
193 | 84 return DVDNAV_STATUS_OK; |
5
c1b55dc1bfed
Add API call to get number of programmes in current title.
richwareham
parents:
0
diff
changeset
|
85 } |
c1b55dc1bfed
Add API call to get number of programmes in current title.
richwareham
parents:
0
diff
changeset
|
86 |
195 | 87 dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int32_t *title, int32_t *part) { |
88 int32_t retval; | |
388 | 89 |
114 | 90 pthread_mutex_lock(&this->vm_lock); |
91 if (!this->vm->vtsi || !this->vm->vmgi) { | |
92 printerr("Bad VM state."); | |
93 pthread_mutex_unlock(&this->vm_lock); | |
193 | 94 return DVDNAV_STATUS_ERR; |
90 | 95 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
96 if (!this->started) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
97 printerr("Virtual DVD machine not started."); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
98 pthread_mutex_unlock(&this->vm_lock); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
99 return DVDNAV_STATUS_ERR; |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
100 } |
114 | 101 if (!this->vm->state.pgc) { |
102 printerr("No current PGC."); | |
103 pthread_mutex_unlock(&this->vm_lock); | |
193 | 104 return DVDNAV_STATUS_ERR; |
114 | 105 } |
158 | 106 if ( (this->vm->state.domain == VTSM_DOMAIN) |
107 || (this->vm->state.domain == VMGM_DOMAIN) ) { | |
108 /* Get current Menu ID: into *part. */ | |
344
fb2fbd4cfbf6
in get_PGCIT() check the validity of vm->vtsi before risking to dereference NULL;
nicodvb
parents:
332
diff
changeset
|
109 if(! vm_get_current_menu(this->vm, part)) { |
fb2fbd4cfbf6
in get_PGCIT() check the validity of vm->vtsi before risking to dereference NULL;
nicodvb
parents:
332
diff
changeset
|
110 pthread_mutex_unlock(&this->vm_lock); |
fb2fbd4cfbf6
in get_PGCIT() check the validity of vm->vtsi before risking to dereference NULL;
nicodvb
parents:
332
diff
changeset
|
111 return DVDNAV_STATUS_ERR; |
fb2fbd4cfbf6
in get_PGCIT() check the validity of vm->vtsi before risking to dereference NULL;
nicodvb
parents:
332
diff
changeset
|
112 } |
159 | 113 if (*part > -1) { |
114 *title = 0; | |
157
7094c8661c05
Return details about menu number in dvdnav_current_title_info()
jcdutton
parents:
146
diff
changeset
|
115 pthread_mutex_unlock(&this->vm_lock); |
193 | 116 return DVDNAV_STATUS_OK; |
157
7094c8661c05
Return details about menu number in dvdnav_current_title_info()
jcdutton
parents:
146
diff
changeset
|
117 } |
114 | 118 } |
158 | 119 if (this->vm->state.domain == VTS_DOMAIN) { |
120 retval = vm_get_current_title_part(this->vm, title, part); | |
121 pthread_mutex_unlock(&this->vm_lock); | |
193 | 122 return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; |
158 | 123 } |
124 printerr("Not in a title or menu."); | |
114 | 125 pthread_mutex_unlock(&this->vm_lock); |
193 | 126 return DVDNAV_STATUS_ERR; |
90 | 127 } |
128 | |
195 | 129 dvdnav_status_t dvdnav_title_play(dvdnav_t *this, int32_t title) { |
90 | 130 return dvdnav_part_play(this, title, 1); |
0 | 131 } |
132 | |
195 | 133 dvdnav_status_t dvdnav_part_play(dvdnav_t *this, int32_t title, int32_t part) { |
134 int32_t retval; | |
0 | 135 |
114 | 136 pthread_mutex_lock(&this->vm_lock); |
137 | 137 if (!this->vm->vmgi) { |
114 | 138 printerr("Bad VM state."); |
139 pthread_mutex_unlock(&this->vm_lock); | |
193 | 140 return DVDNAV_STATUS_ERR; |
0 | 141 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
142 if (!this->started) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
143 /* don't report an error but be nice */ |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
144 vm_start(this->vm); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
145 this->started = 1; |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
146 } |
114 | 147 if (!this->vm->state.pgc) { |
148 printerr("No current PGC."); | |
149 pthread_mutex_unlock(&this->vm_lock); | |
193 | 150 return DVDNAV_STATUS_ERR; |
114 | 151 } |
152 if((title < 1) || (title > this->vm->vmgi->tt_srpt->nr_of_srpts)) { | |
153 printerr("Title out of range."); | |
154 pthread_mutex_unlock(&this->vm_lock); | |
193 | 155 return DVDNAV_STATUS_ERR; |
114 | 156 } |
140 | 157 if((part < 1) || (part > this->vm->vmgi->tt_srpt->title[title-1].nr_of_ptts)) { |
158 printerr("Part out of range."); | |
159 pthread_mutex_unlock(&this->vm_lock); | |
193 | 160 return DVDNAV_STATUS_ERR; |
140 | 161 } |
162 | |
114 | 163 retval = vm_jump_title_part(this->vm, title, part); |
133
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
116
diff
changeset
|
164 if (retval) |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
116
diff
changeset
|
165 this->vm->hop_channel++; |
114 | 166 pthread_mutex_unlock(&this->vm_lock); |
0 | 167 |
193 | 168 return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; |
0 | 169 } |
170 | |
195 | 171 dvdnav_status_t dvdnav_part_play_auto_stop(dvdnav_t *this, int32_t title, |
172 int32_t part, int32_t parts_to_play) { | |
114 | 173 /* FIXME: Implement auto-stop */ |
193 | 174 if (dvdnav_part_play(this, title, part) == DVDNAV_STATUS_OK) |
114 | 175 printerr("Not implemented yet."); |
193 | 176 return DVDNAV_STATUS_ERR; |
0 | 177 } |
178 | |
195 | 179 dvdnav_status_t dvdnav_time_play(dvdnav_t *this, int32_t title, |
180 uint64_t time) { | |
0 | 181 /* FIXME: Implement */ |
114 | 182 printerr("Not implemented yet."); |
193 | 183 return DVDNAV_STATUS_ERR; |
0 | 184 } |
185 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
186 dvdnav_status_t dvdnav_stop(dvdnav_t *this) { |
114 | 187 pthread_mutex_lock(&this->vm_lock); |
146
7f242ec838fd
do not stop the VM here, get_next_block will do that without races
mroi
parents:
140
diff
changeset
|
188 this->vm->stopped = 1; |
114 | 189 pthread_mutex_unlock(&this->vm_lock); |
193 | 190 return DVDNAV_STATUS_OK; |
0 | 191 } |
192 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
193 dvdnav_status_t dvdnav_go_up(dvdnav_t *this) { |
0 | 194 /* A nice easy function... delegate to the VM */ |
114 | 195 pthread_mutex_lock(&this->vm_lock); |
196 vm_jump_up(this->vm); | |
197 pthread_mutex_unlock(&this->vm_lock); | |
0 | 198 |
193 | 199 return DVDNAV_STATUS_OK; |
0 | 200 } |