Mercurial > libdvdnav.hg
annotate navigation.c @ 248:5124cfd4725d src
fix some error conditions (fixes dvdnav_title_part_play())
author | mroi |
---|---|
date | Sun, 20 Jun 2004 16:49:08 +0000 |
parents | 2d79ef3f3956 |
children | bd734ab914d0 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> | |
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 | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
19 * | |
20 * $Id$ | |
21 * | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
28 #include "dvdnav_internal.h" | |
29 | |
30 /* Navigation API calls */ | |
31 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
32 dvdnav_status_t dvdnav_still_skip(dvdnav_t *this) { |
114 | 33 if(!this) { |
34 printerr("Passed a NULL pointer."); | |
193 | 35 return DVDNAV_STATUS_ERR; |
114 | 36 } |
0 | 37 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
38 this->position_current.still = 0; |
23 | 39 this->skip_still = 1; |
116 | 40 this->sync_wait = 0; |
41 this->sync_wait_skip = 1; | |
42 | |
193 | 43 return DVDNAV_STATUS_OK; |
116 | 44 } |
45 | |
46 dvdnav_status_t dvdnav_wait_skip(dvdnav_t *this) { | |
47 if(!this) { | |
48 printerr("Passed a NULL pointer."); | |
193 | 49 return DVDNAV_STATUS_ERR; |
116 | 50 } |
51 | |
52 this->sync_wait = 0; | |
53 this->sync_wait_skip = 1; | |
0 | 54 |
193 | 55 return DVDNAV_STATUS_OK; |
0 | 56 } |
57 | |
195 | 58 dvdnav_status_t dvdnav_get_number_of_titles(dvdnav_t *this, int32_t *titles) { |
114 | 59 if(!this || !titles) { |
60 printerr("Passed a NULL pointer."); | |
193 | 61 return DVDNAV_STATUS_ERR; |
0 | 62 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
63 if (!this->vm->vmgi) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
64 printerr("Bad VM state."); |
223
2d79ef3f3956
we should not start the VM on dvdnav_get_number_of_titles,
mroi
parents:
195
diff
changeset
|
65 return DVDNAV_STATUS_ERR; |
94
e29110f67f3a
Get xine dvd:///dev/dvd:1.2 i.e. title play working again.
jcdutton
parents:
90
diff
changeset
|
66 } |
e29110f67f3a
Get xine dvd:///dev/dvd:1.2 i.e. title play working again.
jcdutton
parents:
90
diff
changeset
|
67 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
68 (*titles) = vm_get_vmgi(this->vm)->tt_srpt->nr_of_srpts; |
0 | 69 |
193 | 70 return DVDNAV_STATUS_OK; |
0 | 71 } |
72 | |
195 | 73 dvdnav_status_t dvdnav_get_number_of_parts(dvdnav_t *this, int32_t title, int32_t *parts) { |
114 | 74 if(!this || !parts) { |
75 printerr("Passed a NULL pointer."); | |
193 | 76 return DVDNAV_STATUS_ERR; |
5
c1b55dc1bfed
Add API call to get number of programmes in current title.
richwareham
parents:
0
diff
changeset
|
77 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
78 if (!this->vm->vmgi) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
79 printerr("Bad VM state."); |
193 | 80 return DVDNAV_STATUS_ERR; |
95 | 81 } |
82 if ((title < 1) || (title > vm_get_vmgi(this->vm)->tt_srpt->nr_of_srpts) ) { | |
114 | 83 printerr("Passed a title number out of range."); |
193 | 84 return DVDNAV_STATUS_ERR; |
95 | 85 } |
114 | 86 |
95 | 87 (*parts) = vm_get_vmgi(this->vm)->tt_srpt->title[title-1].nr_of_ptts; |
114 | 88 |
193 | 89 return DVDNAV_STATUS_OK; |
5
c1b55dc1bfed
Add API call to get number of programmes in current title.
richwareham
parents:
0
diff
changeset
|
90 } |
c1b55dc1bfed
Add API call to get number of programmes in current title.
richwareham
parents:
0
diff
changeset
|
91 |
195 | 92 dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int32_t *title, int32_t *part) { |
93 int32_t retval; | |
114 | 94 |
95 if(!this || !title || !part) { | |
96 printerr("Passed a NULL pointer."); | |
193 | 97 return DVDNAV_STATUS_ERR; |
114 | 98 } |
99 | |
100 pthread_mutex_lock(&this->vm_lock); | |
101 if (!this->vm->vtsi || !this->vm->vmgi) { | |
102 printerr("Bad VM state."); | |
103 pthread_mutex_unlock(&this->vm_lock); | |
193 | 104 return DVDNAV_STATUS_ERR; |
90 | 105 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
106 if (!this->started) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
107 printerr("Virtual DVD machine not started."); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
108 pthread_mutex_unlock(&this->vm_lock); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
109 return DVDNAV_STATUS_ERR; |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
110 } |
114 | 111 if (!this->vm->state.pgc) { |
112 printerr("No current PGC."); | |
113 pthread_mutex_unlock(&this->vm_lock); | |
193 | 114 return DVDNAV_STATUS_ERR; |
114 | 115 } |
158 | 116 if ( (this->vm->state.domain == VTSM_DOMAIN) |
117 || (this->vm->state.domain == VMGM_DOMAIN) ) { | |
118 /* Get current Menu ID: into *part. */ | |
119 vm_get_current_menu(this->vm, part); | |
159 | 120 if (*part > -1) { |
121 *title = 0; | |
157
7094c8661c05
Return details about menu number in dvdnav_current_title_info()
jcdutton
parents:
146
diff
changeset
|
122 pthread_mutex_unlock(&this->vm_lock); |
193 | 123 return DVDNAV_STATUS_OK; |
157
7094c8661c05
Return details about menu number in dvdnav_current_title_info()
jcdutton
parents:
146
diff
changeset
|
124 } |
114 | 125 } |
158 | 126 if (this->vm->state.domain == VTS_DOMAIN) { |
127 retval = vm_get_current_title_part(this->vm, title, part); | |
128 pthread_mutex_unlock(&this->vm_lock); | |
193 | 129 return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; |
158 | 130 } |
131 printerr("Not in a title or menu."); | |
114 | 132 pthread_mutex_unlock(&this->vm_lock); |
193 | 133 return DVDNAV_STATUS_ERR; |
90 | 134 } |
135 | |
195 | 136 dvdnav_status_t dvdnav_title_play(dvdnav_t *this, int32_t title) { |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
137 if(!this) { |
114 | 138 printerr("Passed a NULL pointer."); |
193 | 139 return DVDNAV_STATUS_ERR; |
0 | 140 } |
90 | 141 return dvdnav_part_play(this, title, 1); |
0 | 142 } |
143 | |
195 | 144 dvdnav_status_t dvdnav_part_play(dvdnav_t *this, int32_t title, int32_t part) { |
145 int32_t retval; | |
0 | 146 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
147 if(!this) { |
114 | 148 printerr("Passed a NULL pointer."); |
193 | 149 return DVDNAV_STATUS_ERR; |
114 | 150 } |
151 | |
152 pthread_mutex_lock(&this->vm_lock); | |
137 | 153 if (!this->vm->vmgi) { |
114 | 154 printerr("Bad VM state."); |
155 pthread_mutex_unlock(&this->vm_lock); | |
193 | 156 return DVDNAV_STATUS_ERR; |
0 | 157 } |
248
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
158 if (!this->started) { |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
159 /* don't report an error but be nice */ |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
160 vm_start(this->vm); |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
161 this->started = 1; |
5124cfd4725d
fix some error conditions (fixes dvdnav_title_part_play())
mroi
parents:
223
diff
changeset
|
162 } |
114 | 163 if (!this->vm->state.pgc) { |
164 printerr("No current PGC."); | |
165 pthread_mutex_unlock(&this->vm_lock); | |
193 | 166 return DVDNAV_STATUS_ERR; |
114 | 167 } |
168 if((title < 1) || (title > this->vm->vmgi->tt_srpt->nr_of_srpts)) { | |
169 printerr("Title out of range."); | |
170 pthread_mutex_unlock(&this->vm_lock); | |
193 | 171 return DVDNAV_STATUS_ERR; |
114 | 172 } |
140 | 173 if((part < 1) || (part > this->vm->vmgi->tt_srpt->title[title-1].nr_of_ptts)) { |
174 printerr("Part out of range."); | |
175 pthread_mutex_unlock(&this->vm_lock); | |
193 | 176 return DVDNAV_STATUS_ERR; |
140 | 177 } |
178 | |
114 | 179 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
|
180 if (retval) |
d09a81cf65ce
determine correct PG and PTT numbers when seeking across PG boundaries
mroi
parents:
116
diff
changeset
|
181 this->vm->hop_channel++; |
114 | 182 pthread_mutex_unlock(&this->vm_lock); |
0 | 183 |
193 | 184 return retval ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; |
0 | 185 } |
186 | |
195 | 187 dvdnav_status_t dvdnav_part_play_auto_stop(dvdnav_t *this, int32_t title, |
188 int32_t part, int32_t parts_to_play) { | |
114 | 189 /* FIXME: Implement auto-stop */ |
193 | 190 if (dvdnav_part_play(this, title, part) == DVDNAV_STATUS_OK) |
114 | 191 printerr("Not implemented yet."); |
193 | 192 return DVDNAV_STATUS_ERR; |
0 | 193 } |
194 | |
195 | 195 dvdnav_status_t dvdnav_time_play(dvdnav_t *this, int32_t title, |
196 uint64_t time) { | |
114 | 197 if(!this) { |
198 printerr("Passed a NULL pointer."); | |
193 | 199 return DVDNAV_STATUS_ERR; |
114 | 200 } |
201 | |
0 | 202 /* FIXME: Implement */ |
114 | 203 printerr("Not implemented yet."); |
193 | 204 return DVDNAV_STATUS_ERR; |
0 | 205 } |
206 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
207 dvdnav_status_t dvdnav_stop(dvdnav_t *this) { |
114 | 208 if(!this) { |
209 printerr("Passed a NULL pointer."); | |
193 | 210 return DVDNAV_STATUS_ERR; |
114 | 211 } |
0 | 212 |
114 | 213 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
|
214 this->vm->stopped = 1; |
114 | 215 pthread_mutex_unlock(&this->vm_lock); |
193 | 216 return DVDNAV_STATUS_OK; |
0 | 217 } |
218 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
5
diff
changeset
|
219 dvdnav_status_t dvdnav_go_up(dvdnav_t *this) { |
114 | 220 if(!this) { |
221 printerr("Passed a NULL pointer."); | |
193 | 222 return DVDNAV_STATUS_ERR; |
114 | 223 } |
0 | 224 |
225 /* A nice easy function... delegate to the VM */ | |
114 | 226 pthread_mutex_lock(&this->vm_lock); |
227 vm_jump_up(this->vm); | |
228 pthread_mutex_unlock(&this->vm_lock); | |
0 | 229 |
193 | 230 return DVDNAV_STATUS_OK; |
0 | 231 } |