Mercurial > libdvdnav.hg
annotate dvdnav.c @ 217:eb503714e1c2 src
these variables are not needed any more
author | mroi |
---|---|
date | Wed, 31 Dec 2003 16:56:12 +0000 |
parents | 373f27da196b |
children | 065a2835ba90 |
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 | |
31 | 28 /* |
29 #define LOG_DEBUG | |
30 */ | |
31 | |
0 | 32 #include <pthread.h> |
33 #include "dvdnav_internal.h" | |
34 #include "read_cache.h" | |
35 | |
169 | 36 #include "nav_read.h" |
0 | 37 |
38 #include <stdlib.h> | |
39 #include <stdio.h> | |
84 | 40 #include <sys/time.h> |
0 | 41 |
97
c1dff1899bda
First patch for personalized dvd viewing. I have not tested it yet.
jcdutton
parents:
92
diff
changeset
|
42 #include "remap.h" |
c1dff1899bda
First patch for personalized dvd viewing. I have not tested it yet.
jcdutton
parents:
92
diff
changeset
|
43 |
114 | 44 static dvdnav_status_t dvdnav_clear(dvdnav_t * this) { |
45 /* clear everything except file, vm, mutex, readahead */ | |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
46 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
47 if (this->file) DVDCloseFile(this->file); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
48 this->file = NULL; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
49 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
50 memset(&this->pci,0,sizeof(this->pci)); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
51 memset(&this->dsi,0,sizeof(this->dsi)); |
197
a20a5976a207
last_cmd_nav_lbn has to be initialized with an invalid value, so that the first
mroi
parents:
195
diff
changeset
|
52 this->last_cmd_nav_lbn = SRI_END_OF_CELL; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
53 |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
54 /* Set initial values of flags */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
55 this->position_current.still = 0; |
23 | 56 this->skip_still = 0; |
116 | 57 this->sync_wait = 0; |
58 this->sync_wait_skip = 0; | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
59 this->spu_clut_changed = 0; |
114 | 60 this->started = 0; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
61 |
34
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
62 dvdnav_read_cache_clear(this->cache); |
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
63 |
193 | 64 return DVDNAV_STATUS_OK; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
65 } |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
66 |
114 | 67 dvdnav_status_t dvdnav_open(dvdnav_t** dest, const char *path) { |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
68 dvdnav_t *this; |
84 | 69 struct timeval time; |
0 | 70 |
71 /* Create a new structure */ | |
100 | 72 fprintf(MSG_OUT, "libdvdnav: Using dvdnav version %s from http://dvd.sf.net\n", VERSION); |
82 | 73 |
0 | 74 (*dest) = NULL; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
75 this = (dvdnav_t*)malloc(sizeof(dvdnav_t)); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
76 if(!this) |
193 | 77 return DVDNAV_STATUS_ERR; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
78 memset(this, 0, (sizeof(dvdnav_t) ) ); /* Make sure this structure is clean */ |
114 | 79 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
80 pthread_mutex_init(&this->vm_lock, NULL); |
0 | 81 /* Initialise the error string */ |
82 printerr(""); | |
83 | |
84 /* Initialise the VM */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
85 this->vm = vm_new_vm(); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
86 if(!this->vm) { |
114 | 87 printerr("Error initialising the DVD VM."); |
92 | 88 pthread_mutex_destroy(&this->vm_lock); |
89 free(this); | |
193 | 90 return DVDNAV_STATUS_ERR; |
0 | 91 } |
114 | 92 if(!vm_reset(this->vm, path)) { |
93 printerr("Error starting the VM / opening the DVD device."); | |
92 | 94 pthread_mutex_destroy(&this->vm_lock); |
95 vm_free_vm(this->vm); | |
96 free(this); | |
193 | 97 return DVDNAV_STATUS_ERR; |
0 | 98 } |
99 | |
100 /* Set the path. FIXME: Is a deep copy 'right' */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
101 strncpy(this->path, path, MAX_PATH_LEN); |
0 | 102 |
103 /* Pre-open and close a file so that the CSS-keys are cached. */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
104 this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), 0, DVD_READ_MENU_VOBS); |
0 | 105 |
34
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
106 /* Start the read-ahead cache. */ |
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
107 this->cache = dvdnav_read_cache_new(this); |
84 | 108 |
114 | 109 /* Seed the random numbers. So that the DVD VM Command rand() |
110 * gives a different start value each time a DVD is played. */ | |
111 gettimeofday(&time, NULL); | |
84 | 112 srand(time.tv_usec); |
113 | |
114 | 114 dvdnav_clear(this); |
115 | |
116 (*dest) = this; | |
193 | 117 return DVDNAV_STATUS_OK; |
0 | 118 } |
119 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
120 dvdnav_status_t dvdnav_close(dvdnav_t *this) { |
114 | 121 |
31 | 122 #ifdef LOG_DEBUG |
76 | 123 fprintf(MSG_OUT, "libdvdnav: close:called\n"); |
31 | 124 #endif |
34
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
125 |
114 | 126 if(!this) { |
127 printerr("Passed a NULL pointer."); | |
193 | 128 return DVDNAV_STATUS_ERR; |
114 | 129 } |
130 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
131 if (this->file) { |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
132 DVDCloseFile(this->file); |
31 | 133 #ifdef LOG_DEBUG |
76 | 134 fprintf(MSG_OUT, "libdvdnav: close:file closing\n"); |
31 | 135 #endif |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
136 this->file = NULL; |
0 | 137 } |
138 | |
139 /* Free the VM */ | |
114 | 140 if(this->vm) |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
141 vm_free_vm(this->vm); |
114 | 142 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
143 pthread_mutex_destroy(&this->vm_lock); |
60 | 144 |
145 /* We leave the final freeing of the entire structure to the cache, | |
146 * because we don't know, if there are still buffers out in the wild, | |
147 * that must return first. */ | |
114 | 148 if(this->cache) |
60 | 149 dvdnav_read_cache_free(this->cache); |
114 | 150 else |
151 free(this); | |
0 | 152 |
193 | 153 return DVDNAV_STATUS_OK; |
0 | 154 } |
155 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
156 dvdnav_status_t dvdnav_reset(dvdnav_t *this) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
157 dvdnav_status_t result; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
158 |
31 | 159 #ifdef LOG_DEBUG |
76 | 160 fprintf(MSG_OUT, "libdvdnav: reset:called\n"); |
31 | 161 #endif |
114 | 162 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
163 if(!this) { |
114 | 164 printerr("Passed a NULL pointer."); |
193 | 165 return DVDNAV_STATUS_ERR; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
166 } |
114 | 167 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
168 pthread_mutex_lock(&this->vm_lock); |
114 | 169 |
31 | 170 #ifdef LOG_DEBUG |
76 | 171 fprintf(MSG_OUT, "libdvdnav: reseting vm\n"); |
31 | 172 #endif |
114 | 173 if(!vm_reset(this->vm, NULL)) { |
174 printerr("Error restarting the VM."); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
175 pthread_mutex_unlock(&this->vm_lock); |
193 | 176 return DVDNAV_STATUS_ERR; |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
177 } |
31 | 178 #ifdef LOG_DEBUG |
76 | 179 fprintf(MSG_OUT, "libdvdnav: clearing dvdnav\n"); |
31 | 180 #endif |
114 | 181 result = dvdnav_clear(this); |
182 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
183 pthread_mutex_unlock(&this->vm_lock); |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
184 return result; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
185 } |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
186 |
114 | 187 dvdnav_status_t dvdnav_path(dvdnav_t *this, const char** path) { |
188 | |
189 if(!this || !path) { | |
190 printerr("Passed a NULL pointer."); | |
193 | 191 return DVDNAV_STATUS_ERR; |
0 | 192 } |
193 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
194 (*path) = this->path; |
0 | 195 |
193 | 196 return DVDNAV_STATUS_OK; |
0 | 197 } |
198 | |
114 | 199 const char* dvdnav_err_to_string(dvdnav_t *this) { |
200 | |
201 if(!this) | |
3
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
202 return "Hey! You gave me a NULL pointer you naughty person!"; |
0 | 203 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
204 return this->err_str; |
0 | 205 } |
206 | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
207 /* converts a dvd_time_t to PTS ticks */ |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
208 static int64_t dvdnav_convert_time(dvd_time_t *time) { |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
209 int64_t result; |
195 | 210 int64_t frames; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
211 |
135 | 212 result = (time->hour >> 4 ) * 10 * 60 * 60 * 90000; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
213 result += (time->hour & 0x0f) * 60 * 60 * 90000; |
135 | 214 result += (time->minute >> 4 ) * 10 * 60 * 90000; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
215 result += (time->minute & 0x0f) * 60 * 90000; |
135 | 216 result += (time->second >> 4 ) * 10 * 90000; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
217 result += (time->second & 0x0f) * 90000; |
135 | 218 |
219 frames = ((time->frame_u & 0x30) >> 4) * 10; | |
220 frames += ((time->frame_u & 0x0f) ) ; | |
221 | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
222 if (time->frame_u & 0x80) |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
223 result += frames * 3000; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
224 else |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
225 result += frames * 3600; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
226 |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
227 return result; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
228 } |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
229 |
114 | 230 /* |
0 | 231 * Returns 1 if block contains NAV packet, 0 otherwise. |
217 | 232 * Processes said NAV packet if present. |
0 | 233 * |
234 * Most of the code in here is copied from xine's MPEG demuxer | |
235 * so any bugs which are found in that should be corrected here also. | |
236 */ | |
195 | 237 static int32_t dvdnav_decode_packet(dvdnav_t *this, uint8_t *p, dsi_t *nav_dsi, pci_t *nav_pci) { |
238 int32_t bMpeg1 = 0; | |
0 | 239 uint32_t nHeaderLen; |
240 uint32_t nPacketLen; | |
241 uint32_t nStreamID; | |
242 | |
243 if (p[3] == 0xBA) { /* program stream pack header */ | |
195 | 244 int32_t nStuffingBytes; |
0 | 245 |
246 bMpeg1 = (p[4] & 0x40) == 0; | |
247 | |
248 if (bMpeg1) { | |
114 | 249 p += 12; |
0 | 250 } else { /* mpeg2 */ |
251 nStuffingBytes = p[0xD] & 0x07; | |
252 p += 14 + nStuffingBytes; | |
253 } | |
254 } | |
255 | |
256 if (p[3] == 0xbb) { /* program stream system header */ | |
257 nHeaderLen = (p[4] << 8) | p[5]; | |
258 p += 6 + nHeaderLen; | |
259 } | |
260 | |
261 /* we should now have a PES packet here */ | |
262 if (p[0] || p[1] || (p[2] != 1)) { | |
76 | 263 fprintf(MSG_OUT, "libdvdnav: demux error! %02x %02x %02x (should be 0x000001) \n",p[0],p[1],p[2]); |
0 | 264 return 0; |
265 } | |
266 | |
267 nPacketLen = p[4] << 8 | p[5]; | |
268 nStreamID = p[3]; | |
269 | |
270 nHeaderLen = 6; | |
271 p += nHeaderLen; | |
272 | |
273 if (nStreamID == 0xbf) { /* Private stream 2 */ | |
114 | 274 #if 0 |
195 | 275 int32_t i; |
114 | 276 fprintf(MSG_OUT, "libdvdnav: nav packet=%u\n",p-p_start-6); |
277 for(i=0;i<80;i++) | |
278 fprintf(MSG_OUT, "%02x ",p[i-6]); | |
279 fprintf(MSG_OUT, "\n"); | |
280 #endif | |
281 | |
0 | 282 if(p[0] == 0x00) { |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
283 navRead_PCI(nav_pci, p+1); |
0 | 284 } |
285 | |
286 p += nPacketLen; | |
287 | |
288 /* We should now have a DSI packet. */ | |
289 if(p[6] == 0x01) { | |
290 nPacketLen = p[4] << 8 | p[5]; | |
291 p += 6; | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
292 navRead_DSI(nav_dsi, p+1); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
293 } |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
294 return 1; |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
295 } |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
296 return 0; |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
297 } |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
298 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
299 /* DSI is used for most angle stuff. |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
300 * PCI is used for only non-seemless angle stuff |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
301 */ |
195 | 302 static int32_t dvdnav_get_vobu(dvdnav_t *this, dsi_t *nav_dsi, pci_t *nav_pci, dvdnav_vobu_t *vobu) { |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
303 uint32_t next; |
195 | 304 int32_t angle, num_angle; |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
305 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
306 vobu->vobu_start = nav_dsi->dsi_gi.nv_pck_lbn; /* Absolute offset from start of disk */ |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
307 vobu->vobu_length = nav_dsi->dsi_gi.vobu_ea; /* Relative offset from vobu_start */ |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
308 |
43
0ba15bf3dc25
Biiiiiiig change to let doxygen generate some docs for the library. Note that I'm in no way sure that the autoconf stuff plays nice.
richwareham
parents:
42
diff
changeset
|
309 /* |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
310 * If we're not at the end of this cell, we can determine the next |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
311 * VOBU to display using the VOBU_SRI information section of the |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
312 * DSI. Using this value correctly follows the current angle, |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
313 * avoiding the doubled scenes in The Matrix, and makes our life |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
314 * really happy. |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
315 * |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
316 * vobu_next is an offset value, 0x3fffffff = SRI_END_OF_CELL |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
317 * DVDs are about 6 Gigs, which is only up to 0x300000 blocks |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
318 * Should really assert if bit 31 != 1 |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
319 */ |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
320 |
114 | 321 #if 0 |
322 /* Old code -- may still be useful one day */ | |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
323 if(nav_dsi->vobu_sri.next_vobu != SRI_END_OF_CELL ) { |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
324 vobu->vobu_next = ( nav_dsi->vobu_sri.next_vobu & 0x3fffffff ); |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
325 } else { |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
326 vobu->vobu_next = vobu->vobu_length; |
114 | 327 } |
328 #else | |
329 /* Relative offset from vobu_start */ | |
330 vobu->vobu_next = ( nav_dsi->vobu_sri.next_vobu & 0x3fffffff ); | |
331 #endif | |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
332 |
114 | 333 vm_get_angle_info(this->vm, &angle, &num_angle); |
334 | |
335 /* FIMXE: The angle reset doesn't work for some reason for the moment */ | |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
336 #if 0 |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
337 if((num_angle < angle) && (angle != 1)) { |
114 | 338 fprintf(MSG_OUT, "libdvdnav: angle ends!\n"); |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
339 |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
340 /* This is to switch back to angle one when we |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
341 * finish with angles. */ |
114 | 342 dvdnav_angle_change(this, 1); |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
343 } |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
344 #endif |
0 | 345 |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
346 if(num_angle != 0) { |
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
347 |
114 | 348 if((next = nav_pci->nsml_agli.nsml_agl_dsta[angle-1]) != 0) { |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
349 if((next & 0x3fffffff) != 0) { |
114 | 350 if(next & 0x80000000) |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
351 vobu->vobu_next = - (int32_t)(next & 0x3fffffff); |
114 | 352 else |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
353 vobu->vobu_next = + (int32_t)(next & 0x3fffffff); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
354 } |
114 | 355 } else if((next = nav_dsi->sml_agli.data[angle-1].address) != 0) { |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
356 vobu->vobu_length = nav_dsi->sml_pbi.ilvu_ea; |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
357 |
114 | 358 if((next & 0x80000000) && (next != 0x7fffffff)) |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
359 vobu->vobu_next = - (int32_t)(next & 0x3fffffff); |
114 | 360 else |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
361 vobu->vobu_next = + (int32_t)(next & 0x3fffffff); |
0 | 362 } |
363 } | |
33
ef2136c4e7b2
Angles now work (still a few wrinkles though -- e.g. angle does not reset to '1' when returning to menus)
richwareham
parents:
31
diff
changeset
|
364 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
365 return 1; |
0 | 366 } |
60 | 367 |
114 | 368 /* |
369 * These are the main get_next_block function which actually get the media stream video and audio etc. | |
370 * | |
371 * There are two versions: The second one is using the zero-copy read ahead cache and therefore | |
372 * hands out pointers targetting directly into the cache. | |
373 * The first one uses a memcopy to fill this cache block into the application provided memory. | |
374 * The benefit of this first one is that no special memory management is needed. The application is | |
375 * the only one responsible of allocating and freeing the memory associated with the pointer. | |
376 * The drawback is the additional memcopy. | |
28 | 377 */ |
60 | 378 |
195 | 379 dvdnav_status_t dvdnav_get_next_block(dvdnav_t *this, uint8_t *buf, |
380 int32_t *event, int32_t *len) { | |
60 | 381 unsigned char *block; |
382 dvdnav_status_t status; | |
383 | |
384 block = buf; | |
385 status = dvdnav_get_next_cache_block(this, &block, event, len); | |
193 | 386 if (status == DVDNAV_STATUS_OK && block != buf) { |
60 | 387 /* we received a block from the cache, copy it, so we can give it back */ |
388 memcpy(buf, block, DVD_VIDEO_LB_LEN); | |
389 dvdnav_free_cache_block(this, block); | |
390 } | |
391 return status; | |
392 } | |
393 | |
195 | 394 dvdnav_status_t dvdnav_get_next_cache_block(dvdnav_t *this, uint8_t **buf, |
395 int32_t *event, int32_t *len) { | |
0 | 396 dvd_state_t *state; |
195 | 397 int32_t result; |
114 | 398 |
60 | 399 if(!this || !event || !len || !buf || !*buf) { |
114 | 400 printerr("Passed a NULL pointer."); |
193 | 401 return DVDNAV_STATUS_ERR; |
0 | 402 } |
114 | 403 |
404 pthread_mutex_lock(&this->vm_lock); | |
0 | 405 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
406 if(!this->started) { |
0 | 407 /* Start the VM */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
408 vm_start(this->vm); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
409 this->started = 1; |
0 | 410 } |
411 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
412 state = &(this->vm->state); |
0 | 413 (*event) = DVDNAV_NOP; |
414 (*len) = 0; | |
415 | |
416 /* Check the STOP flag */ | |
114 | 417 if(this->vm->stopped) { |
121 | 418 vm_stop(this->vm); |
0 | 419 (*event) = DVDNAV_STOP; |
114 | 420 this->started = 0; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
421 pthread_mutex_unlock(&this->vm_lock); |
193 | 422 return DVDNAV_STATUS_OK; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
423 } |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
424 |
114 | 425 vm_position_get(this->vm, &this->position_next); |
0 | 426 |
126 | 427 #ifdef LOG_DEBUG |
114 | 428 fprintf(MSG_OUT, "libdvdnav: POS-NEXT "); |
429 vm_position_print(this->vm, &this->position_next); | |
116 | 430 fprintf(MSG_OUT, "libdvdnav: POS-CUR "); |
114 | 431 vm_position_print(this->vm, &this->position_current); |
31 | 432 #endif |
114 | 433 |
434 /* did we hop? */ | |
435 if(this->position_current.hop_channel != this->position_next.hop_channel) { | |
436 (*event) = DVDNAV_HOP_CHANNEL; | |
58 | 437 #ifdef LOG_DEBUG |
114 | 438 fprintf(MSG_OUT, "libdvdnav: HOP_CHANNEL\n"); |
31 | 439 #endif |
115 | 440 if (this->position_next.hop_channel - this->position_current.hop_channel >= HOP_SEEK) { |
195 | 441 int32_t num_angles = 0, current; |
114 | 442 |
443 /* we seeked -> check for multiple angles */ | |
444 vm_get_angle_info(this->vm, ¤t, &num_angles); | |
445 if (num_angles > 1) { | |
195 | 446 int32_t result, block; |
114 | 447 /* we have to skip the first VOBU when seeking in a multiangle feature, |
448 * because it might belong to the wrong angle */ | |
449 block = this->position_next.cell_start + this->position_next.block; | |
450 result = dvdnav_read_cache_block(this->cache, block, 1, buf); | |
451 if(result <= 0) { | |
452 printerr("Error reading NAV packet."); | |
453 pthread_mutex_unlock(&this->vm_lock); | |
193 | 454 return DVDNAV_STATUS_ERR; |
114 | 455 } |
456 /* Decode nav into pci and dsi. Then get next VOBU info. */ | |
457 if(!dvdnav_decode_packet(this, *buf, &this->dsi, &this->pci)) { | |
458 printerr("Expected NAV packet but none found."); | |
459 pthread_mutex_unlock(&this->vm_lock); | |
193 | 460 return DVDNAV_STATUS_ERR; |
114 | 461 } |
462 dvdnav_get_vobu(this, &this->dsi, &this->pci, &this->vobu); | |
463 /* skip to next, if there is a next */ | |
464 if (this->vobu.vobu_next != SRI_END_OF_CELL) { | |
465 this->vobu.vobu_start += this->vobu.vobu_next; | |
466 this->vobu.vobu_next = 0; | |
467 } | |
468 /* update VM state */ | |
469 this->vm->state.blockN = this->vobu.vobu_start - this->position_next.cell_start; | |
470 } | |
471 } | |
472 this->position_current.hop_channel = this->position_next.hop_channel; | |
141
8f63f4c25f2f
update position on HOP_CHANNEL, do not rely on a following CELL_CHANGE
mroi
parents:
135
diff
changeset
|
473 /* update VOBU info */ |
8f63f4c25f2f
update position on HOP_CHANNEL, do not rely on a following CELL_CHANGE
mroi
parents:
135
diff
changeset
|
474 this->vobu.vobu_start = this->position_next.cell_start + this->position_next.block; |
8f63f4c25f2f
update position on HOP_CHANNEL, do not rely on a following CELL_CHANGE
mroi
parents:
135
diff
changeset
|
475 this->vobu.vobu_next = 0; |
127 | 476 /* Make blockN == vobu_length to do expected_nav */ |
114 | 477 this->vobu.vobu_length = 0; |
127 | 478 this->vobu.blockN = 0; |
116 | 479 this->sync_wait = 0; |
30 | 480 pthread_mutex_unlock(&this->vm_lock); |
193 | 481 return DVDNAV_STATUS_OK; |
0 | 482 } |
483 | |
116 | 484 /* Check the HIGHLIGHT flag */ |
485 if(this->position_current.button != this->position_next.button) { | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
486 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t *)*buf; |
116 | 487 |
488 (*event) = DVDNAV_HIGHLIGHT; | |
489 #ifdef LOG_DEBUG | |
490 fprintf(MSG_OUT, "libdvdnav: HIGHLIGHT\n"); | |
491 #endif | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
492 (*len) = sizeof(dvdnav_highlight_event_t); |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
493 hevent->display = 1; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
494 hevent->buttonN = this->position_next.button; |
116 | 495 this->position_current.button = this->position_next.button; |
496 pthread_mutex_unlock(&this->vm_lock); | |
193 | 497 return DVDNAV_STATUS_OK; |
116 | 498 } |
499 | |
500 /* Check the WAIT flag */ | |
501 if(this->sync_wait) { | |
502 (*event) = DVDNAV_WAIT; | |
503 #ifdef LOG_DEBUG | |
504 fprintf(MSG_OUT, "libdvdnav: WAIT\n"); | |
505 #endif | |
506 (*len) = 0; | |
507 pthread_mutex_unlock(&this->vm_lock); | |
193 | 508 return DVDNAV_STATUS_OK; |
116 | 509 } |
510 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
511 /* Check to see if we need to change the currently opened VOB */ |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
512 if((this->position_current.vts != this->position_next.vts) || |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
513 (this->position_current.domain != this->position_next.domain)) { |
0 | 514 dvd_read_domain_t domain; |
195 | 515 int32_t vtsN; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
516 dvdnav_vts_change_event_t *vts_event = (dvdnav_vts_change_event_t *)*buf; |
0 | 517 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
518 if(this->file) { |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
519 DVDCloseFile(this->file); |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
520 this->file = NULL; |
0 | 521 } |
522 | |
217 | 523 vts_event->old_vtsN = this->position_current.vts; |
524 vts_event->old_domain = this->position_current.domain; | |
0 | 525 |
114 | 526 /* Use the DOMAIN to find whether to open menu or title VOBs */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
527 switch(this->position_next.domain) { |
114 | 528 case FP_DOMAIN: |
529 case VMGM_DOMAIN: | |
0 | 530 domain = DVD_READ_MENU_VOBS; |
531 vtsN = 0; | |
532 break; | |
114 | 533 case VTSM_DOMAIN: |
0 | 534 domain = DVD_READ_MENU_VOBS; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
535 vtsN = this->position_next.vts; |
0 | 536 break; |
114 | 537 case VTS_DOMAIN: |
0 | 538 domain = DVD_READ_TITLE_VOBS; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
539 vtsN = this->position_next.vts; |
0 | 540 break; |
114 | 541 default: |
0 | 542 printerr("Unknown domain when changing VTS."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
543 pthread_mutex_unlock(&this->vm_lock); |
193 | 544 return DVDNAV_STATUS_ERR; |
0 | 545 } |
546 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
547 this->position_current.vts = this->position_next.vts; |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
548 this->position_current.domain = this->position_next.domain; |
34
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
549 dvdnav_read_cache_clear(this->cache); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
550 this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), vtsN, domain); |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
551 vts_event->new_vtsN = this->position_next.vts; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
552 vts_event->new_domain = this->position_next.domain; |
0 | 553 |
554 /* If couldn't open the file for some reason, moan */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
555 if(this->file == NULL) { |
0 | 556 printerrf("Error opening vtsN=%i, domain=%i.", vtsN, domain); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
557 pthread_mutex_unlock(&this->vm_lock); |
193 | 558 return DVDNAV_STATUS_ERR; |
0 | 559 } |
560 | |
561 /* File opened successfully so return a VTS change event */ | |
562 (*event) = DVDNAV_VTS_CHANGE; | |
114 | 563 #ifdef LOG_DEBUG |
564 fprintf(MSG_OUT, "libdvdnav: VTS_CHANGE\n"); | |
565 #endif | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
566 (*len) = sizeof(dvdnav_vts_change_event_t); |
0 | 567 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
568 this->spu_clut_changed = 1; |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
569 this->position_current.cell = -1; /* Force an update */ |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
570 this->position_current.spu_channel = -1; /* Force an update */ |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
571 this->position_current.audio_channel = -1; /* Force an update */; |
0 | 572 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
573 pthread_mutex_unlock(&this->vm_lock); |
193 | 574 return DVDNAV_STATUS_OK; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
575 } |
114 | 576 |
577 /* Check if the cell changed */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
578 if( (this->position_current.cell != this->position_next.cell) || |
50
578ce1d41479
Rename some of the functions in vm.c to help readability.
jcdutton
parents:
45
diff
changeset
|
579 (this->position_current.cell_restart != this->position_next.cell_restart) || |
114 | 580 (this->position_current.cell_start != this->position_next.cell_start) ) { |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
581 dvdnav_cell_change_event_t *cell_event = (dvdnav_cell_change_event_t *)*buf; |
195 | 582 int32_t first_cell_nr, last_cell_nr, i; |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
583 dvd_state_t *state = &this->vm->state; |
114 | 584 |
585 (*event) = DVDNAV_CELL_CHANGE; | |
586 #ifdef LOG_DEBUG | |
587 fprintf(MSG_OUT, "libdvdnav: CELL_CHANGE\n"); | |
588 #endif | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
589 (*len) = sizeof(dvdnav_cell_change_event_t); |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
590 |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
591 cell_event->cellN = state->cellN; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
592 cell_event->pgN = state->pgN; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
593 cell_event->cell_length = |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
594 dvdnav_convert_time(&state->pgc->cell_playback[state->cellN-1].playback_time); |
161 | 595 |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
596 cell_event->pg_length = 0; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
597 /* Find start cell of program. */ |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
598 first_cell_nr = state->pgc->program_map[state->pgN-1]; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
599 /* Find end cell of program */ |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
600 if(state->pgN < state->pgc->nr_of_programs) |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
601 last_cell_nr = state->pgc->program_map[state->pgN] - 1; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
602 else |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
603 last_cell_nr = state->pgc->nr_of_cells; |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
604 for (i = first_cell_nr; i <= last_cell_nr; i++) |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
605 cell_event->pg_length += |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
606 dvdnav_convert_time(&state->pgc->cell_playback[i - 1].playback_time); |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
607 cell_event->pgc_length = dvdnav_convert_time(&state->pgc->playback_time); |
151 | 608 |
609 cell_event->cell_start = 0; | |
610 for (i = 1; i < state->cellN; i++) | |
611 cell_event->cell_start += | |
612 dvdnav_convert_time(&state->pgc->cell_playback[i - 1].playback_time); | |
161 | 613 |
614 cell_event->pg_start = 0; | |
615 for (i = 1; i < state->pgc->program_map[state->pgN-1]; i++) | |
616 cell_event->pg_start += | |
617 dvdnav_convert_time(&state->pgc->cell_playback[i - 1].playback_time); | |
618 | |
114 | 619 this->position_current.cell = this->position_next.cell; |
50
578ce1d41479
Rename some of the functions in vm.c to help readability.
jcdutton
parents:
45
diff
changeset
|
620 this->position_current.cell_restart = this->position_next.cell_restart; |
114 | 621 this->position_current.cell_start = this->position_next.cell_start; |
622 this->position_current.block = this->position_next.block; | |
623 | |
624 /* vobu info is used for mid cell resumes */ | |
625 this->vobu.vobu_start = this->position_next.cell_start + this->position_next.block; | |
626 this->vobu.vobu_next = 0; | |
127 | 627 /* Make blockN == vobu_length to do expected_nav */ |
114 | 628 this->vobu.vobu_length = 0; |
127 | 629 this->vobu.blockN = 0; |
114 | 630 |
631 /* update the spu palette at least on PGC changes */ | |
632 this->spu_clut_changed = 1; | |
633 this->position_current.spu_channel = -1; /* Force an update */ | |
634 this->position_current.audio_channel = -1; /* Force an update */ | |
635 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
636 pthread_mutex_unlock(&this->vm_lock); |
193 | 637 return DVDNAV_STATUS_OK; |
0 | 638 } |
639 | |
114 | 640 /* has the CLUT changed? */ |
641 if(this->spu_clut_changed) { | |
642 (*event) = DVDNAV_SPU_CLUT_CHANGE; | |
643 #ifdef LOG_DEBUG | |
644 fprintf(MSG_OUT, "libdvdnav: SPU_CLUT_CHANGE\n"); | |
645 #endif | |
646 (*len) = 16 * sizeof(uint32_t); | |
647 memcpy(*buf, &(state->pgc->palette), 16 * sizeof(uint32_t)); | |
648 this->spu_clut_changed = 0; | |
649 pthread_mutex_unlock(&this->vm_lock); | |
193 | 650 return DVDNAV_STATUS_OK; |
114 | 651 } |
652 | |
653 /* has the SPU channel changed? */ | |
654 if(this->position_current.spu_channel != this->position_next.spu_channel) { | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
655 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t *)*buf; |
114 | 656 |
657 (*event) = DVDNAV_SPU_STREAM_CHANGE; | |
658 #ifdef LOG_DEBUG | |
659 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE\n"); | |
660 #endif | |
661 (*len) = sizeof(dvdnav_spu_stream_change_event_t); | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
662 stream_change->physical_wide = vm_get_subp_active_stream(this->vm, 0); |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
663 stream_change->physical_letterbox = vm_get_subp_active_stream(this->vm, 1); |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
664 stream_change->physical_pan_scan = vm_get_subp_active_stream(this->vm, 2); |
114 | 665 this->position_current.spu_channel = this->position_next.spu_channel; |
666 #ifdef LOG_DEBUG | |
143
0b302ca31859
merge James fixes from xine-lib cvs back into libdvdnav cvs so they will not be lost
mroi
parents:
142
diff
changeset
|
667 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_wide=%d\n",stream_change->physical_wide); |
0b302ca31859
merge James fixes from xine-lib cvs back into libdvdnav cvs so they will not be lost
mroi
parents:
142
diff
changeset
|
668 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_letterbox=%d\n",stream_change->physical_letterbox); |
0b302ca31859
merge James fixes from xine-lib cvs back into libdvdnav cvs so they will not be lost
mroi
parents:
142
diff
changeset
|
669 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_pan_scan=%d\n",stream_change->physical_pan_scan); |
114 | 670 #endif |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
671 if (stream_change->physical_wide != -1 && |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
672 stream_change->physical_letterbox != -1 && |
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
673 stream_change->physical_pan_scan != -1) { |
114 | 674 #ifdef LOG_DEBUG |
193 | 675 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE returning DVDNAV_STATUS_OK\n"); |
114 | 676 #endif |
677 pthread_mutex_unlock(&this->vm_lock); | |
193 | 678 return DVDNAV_STATUS_OK; |
114 | 679 } |
680 } | |
0 | 681 |
114 | 682 /* has the audio channel changed? */ |
683 if(this->position_current.audio_channel != this->position_next.audio_channel) { | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
684 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t *)*buf; |
114 | 685 |
686 (*event) = DVDNAV_AUDIO_STREAM_CHANGE; | |
687 #ifdef LOG_DEBUG | |
688 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE\n"); | |
689 #endif | |
690 (*len) = sizeof(dvdnav_audio_stream_change_event_t); | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
691 stream_change->physical = vm_get_audio_active_stream( this->vm ); |
114 | 692 this->position_current.audio_channel = this->position_next.audio_channel; |
693 #ifdef LOG_DEBUG | |
193 | 694 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE stream_id=%d returning DVDNAV_STATUS_OK\n",stream_change->physical); |
114 | 695 #endif |
696 pthread_mutex_unlock(&this->vm_lock); | |
193 | 697 return DVDNAV_STATUS_OK; |
114 | 698 } |
699 | |
700 /* Check the STILLFRAME flag */ | |
701 if(this->position_current.still != 0) { | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
702 dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)*buf; |
114 | 703 |
704 (*event) = DVDNAV_STILL_FRAME; | |
705 #ifdef LOG_DEBUG | |
706 fprintf(MSG_OUT, "libdvdnav: STILL_FRAME\n"); | |
707 #endif | |
708 (*len) = sizeof(dvdnav_still_event_t); | |
134
d9d75a22a061
- new event on cell changes to report program and cell number and some time info
mroi
parents:
127
diff
changeset
|
709 still_event->length = this->position_current.still; |
114 | 710 pthread_mutex_unlock(&this->vm_lock); |
194 | 711 return DVDNAV_STATUS_OK; |
114 | 712 } |
713 | |
714 /* Have we reached the end of a VOBU? */ | |
715 if (this->vobu.blockN >= this->vobu.vobu_length) { | |
716 | |
717 /* Have we reached the end of a cell? */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
718 if(this->vobu.vobu_next == SRI_END_OF_CELL) { |
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
719 /* End of Cell from NAV DSI info */ |
31 | 720 #ifdef LOG_DEBUG |
76 | 721 fprintf(MSG_OUT, "libdvdnav: Still set to %x\n", this->position_next.still); |
31 | 722 #endif |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
723 this->position_current.still = this->position_next.still; |
0 | 724 |
116 | 725 /* we are about to leave a cell, so a lot of state changes could occur; |
726 * under certain conditions, the application should get in sync with us before this, | |
727 * otherwise it might show stills or menus too shortly */ | |
728 if ((this->position_current.still || this->pci.hli.hl_gi.hli_ss) && !this->sync_wait_skip) { | |
729 this->sync_wait = 1; | |
730 } else { | |
731 if( this->position_current.still == 0 || this->skip_still ) { | |
732 /* no active cell still -> get us to the next cell */ | |
733 vm_get_next_cell(this->vm); | |
734 this->position_current.still = 0; /* still gets activated at end of cell */ | |
735 this->skip_still = 0; | |
736 this->sync_wait_skip = 0; | |
737 } | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
738 } |
114 | 739 /* handle related state changes in next iteration */ |
740 (*event) = DVDNAV_NOP; | |
741 (*len) = 0; | |
742 pthread_mutex_unlock(&this->vm_lock); | |
193 | 743 return DVDNAV_STATUS_OK; |
114 | 744 } |
0 | 745 |
114 | 746 /* Perform remapping jump if necessary (this is always a |
0 | 747 * VOBU boundary). */ |
114 | 748 if (this->vm->map) { |
749 this->vobu.vobu_next = remap_block( this->vm->map, | |
750 this->vm->state.domain, this->vm->state.TTN_REG, | |
751 this->vm->state.pgN, | |
752 this->vobu.vobu_start, this->vobu.vobu_next); | |
753 } | |
0 | 754 |
114 | 755 /* at the start of the next VOBU -> expecting NAV packet */ |
45 | 756 result = dvdnav_read_cache_block(this->cache, this->vobu.vobu_start + this->vobu.vobu_next, 1, buf); |
0 | 757 |
758 if(result <= 0) { | |
759 printerr("Error reading NAV packet."); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
760 pthread_mutex_unlock(&this->vm_lock); |
193 | 761 return DVDNAV_STATUS_ERR; |
0 | 762 } |
114 | 763 /* Decode nav into pci and dsi. Then get next VOBU info. */ |
764 if(!dvdnav_decode_packet(this, *buf, &this->dsi, &this->pci)) { | |
0 | 765 printerr("Expected NAV packet but none found."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
766 pthread_mutex_unlock(&this->vm_lock); |
193 | 767 return DVDNAV_STATUS_ERR; |
0 | 768 } |
114 | 769 /* We need to update the vm state->blockN with which VOBU we are in. |
770 * This is so RSM resumes to the VOBU level and not just the CELL level. | |
28 | 771 */ |
114 | 772 this->vm->state.blockN = this->vobu.vobu_start - this->position_current.cell_start; |
773 | |
774 dvdnav_get_vobu(this, &this->dsi, &this->pci, &this->vobu); | |
775 this->vobu.blockN = 0; | |
776 /* Give the cache a hint about the size of next VOBU. | |
777 * This improves pre-caching, because the VOBU will almost certainly be read entirely. | |
45 | 778 */ |
779 dvdnav_pre_cache_blocks(this->cache, this->vobu.vobu_start+1, this->vobu.vobu_length+1); | |
0 | 780 |
191
dbea22936623
when a command has been issued to leave a menu, filter all further commands
mroi
parents:
179
diff
changeset
|
781 /* release NAV menu filter, when we reach the same NAV packet again */ |
dbea22936623
when a command has been issued to leave a menu, filter all further commands
mroi
parents:
179
diff
changeset
|
782 if (this->last_cmd_nav_lbn == this->pci.pci_gi.nv_pck_lbn) |
198
373f27da196b
This one should also be reset to an invalid value, but 0 is not invalid.
mroi
parents:
197
diff
changeset
|
783 this->last_cmd_nav_lbn = SRI_END_OF_CELL; |
191
dbea22936623
when a command has been issued to leave a menu, filter all further commands
mroi
parents:
179
diff
changeset
|
784 |
0 | 785 /* Successfully got a NAV packet */ |
786 (*event) = DVDNAV_NAV_PACKET; | |
114 | 787 #ifdef LOG_DEBUG |
788 fprintf(MSG_OUT, "libdvdnav: NAV_PACKET\n"); | |
789 #endif | |
3
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
790 (*len) = 2048; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
791 pthread_mutex_unlock(&this->vm_lock); |
193 | 792 return DVDNAV_STATUS_OK; |
0 | 793 } |
794 | |
795 /* If we've got here, it must just be a normal block. */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
796 if(!this->file) { |
114 | 797 printerr("Attempting to read without opening file."); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
798 pthread_mutex_unlock(&this->vm_lock); |
193 | 799 return DVDNAV_STATUS_ERR; |
0 | 800 } |
801 | |
114 | 802 this->vobu.blockN++; |
34
1f29402ef2ef
'Objectified' the read-ahead cache in preparation to implement a 'proper' threaded cache a-la that recommended in the DVD Demystified book.
richwareham
parents:
33
diff
changeset
|
803 result = dvdnav_read_cache_block(this->cache, this->vobu.vobu_start + this->vobu.blockN, 1, buf); |
0 | 804 if(result <= 0) { |
805 printerr("Error reading from DVD."); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
806 pthread_mutex_unlock(&this->vm_lock); |
193 | 807 return DVDNAV_STATUS_ERR; |
0 | 808 } |
114 | 809 (*event) = DVDNAV_BLOCK_OK; |
0 | 810 (*len) = 2048; |
811 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
812 pthread_mutex_unlock(&this->vm_lock); |
193 | 813 return DVDNAV_STATUS_OK; |
0 | 814 } |
815 | |
114 | 816 dvdnav_status_t dvdnav_get_title_string(dvdnav_t *this, const char **title_str) { |
817 | |
818 if(!this || !title_str) { | |
819 printerr("Passed a NULL pointer."); | |
193 | 820 return DVDNAV_STATUS_ERR; |
114 | 821 } |
822 | |
823 (*title_str) = this->vm->dvd_name; | |
193 | 824 return DVDNAV_STATUS_OK; |
114 | 825 } |
826 | |
827 uint8_t dvdnav_get_video_aspect(dvdnav_t *this) { | |
828 uint8_t retval; | |
829 | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
830 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
831 printerr("Passed a NULL pointer."); |
114 | 832 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
833 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
834 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
835 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
836 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
837 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
838 |
114 | 839 pthread_mutex_lock(&this->vm_lock); |
840 retval = (uint8_t)vm_get_video_aspect(this->vm); | |
841 pthread_mutex_unlock(&this->vm_lock); | |
842 | |
843 return retval; | |
844 } | |
845 | |
846 uint8_t dvdnav_get_video_scale_permission(dvdnav_t *this) { | |
847 uint8_t retval; | |
848 | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
849 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
850 printerr("Passed a NULL pointer."); |
114 | 851 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
852 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
853 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
854 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
855 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
856 } |
114 | 857 |
858 pthread_mutex_lock(&this->vm_lock); | |
859 retval = (uint8_t)vm_get_video_scale_permission(this->vm); | |
860 pthread_mutex_unlock(&this->vm_lock); | |
861 | |
862 return retval; | |
863 } | |
864 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
865 uint16_t dvdnav_audio_stream_to_lang(dvdnav_t *this, uint8_t stream) { |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
866 audio_attr_t attr; |
0 | 867 |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
868 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
869 printerr("Passed a NULL pointer."); |
0 | 870 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
871 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
872 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
873 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
874 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
875 } |
0 | 876 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
877 pthread_mutex_lock(&this->vm_lock); |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
878 attr = vm_get_audio_attr(this->vm, stream); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
879 pthread_mutex_unlock(&this->vm_lock); |
0 | 880 |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
881 if(attr.lang_type != 1) |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
882 return 0xffff; |
0 | 883 |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
884 return attr.lang_code; |
0 | 885 } |
886 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
887 uint16_t dvdnav_spu_stream_to_lang(dvdnav_t *this, uint8_t stream) { |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
888 subp_attr_t attr; |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
889 |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
890 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
891 printerr("Passed a NULL pointer."); |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
892 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
893 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
894 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
895 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
896 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
897 } |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
898 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
899 pthread_mutex_lock(&this->vm_lock); |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
900 attr = vm_get_subp_attr(this->vm, stream); |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
901 pthread_mutex_unlock(&this->vm_lock); |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
902 |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
903 if(attr.type != 1) |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
904 return 0xffff; |
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
905 |
25
df024077cbc1
Why rewrite vm function, use it instead (this remark is for me, of course ;-) ).
f1rmb
parents:
24
diff
changeset
|
906 return attr.lang_code; |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
907 } |
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
908 |
114 | 909 int8_t dvdnav_get_audio_logical_stream(dvdnav_t *this, uint8_t audio_num) { |
910 int8_t retval; | |
911 | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
912 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
913 printerr("Passed a NULL pointer."); |
114 | 914 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
915 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
916 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
917 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
918 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
919 } |
114 | 920 |
921 pthread_mutex_lock(&this->vm_lock); | |
922 if (!this->vm->state.pgc) { | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
923 printerr("No current PGC."); |
114 | 924 pthread_mutex_unlock(&this->vm_lock); |
925 return -1; | |
926 } | |
927 retval = vm_get_audio_stream(this->vm, audio_num); | |
928 pthread_mutex_unlock(&this->vm_lock); | |
929 | |
930 return retval; | |
931 } | |
932 | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
933 int8_t dvdnav_get_spu_logical_stream(dvdnav_t *this, uint8_t subp_num) { |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
934 int8_t retval; |
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
935 |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
936 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
937 printerr("Passed a NULL pointer."); |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
938 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
939 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
940 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
941 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
942 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
943 } |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
944 |
114 | 945 pthread_mutex_lock(&this->vm_lock); |
946 if (!this->vm->state.pgc) { | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
947 printerr("No current PGC."); |
114 | 948 pthread_mutex_unlock(&this->vm_lock); |
949 return -1; | |
950 } | |
951 retval = vm_get_subp_stream(this->vm, subp_num, 0); | |
952 pthread_mutex_unlock(&this->vm_lock); | |
953 | |
954 return retval; | |
955 } | |
956 | |
957 int8_t dvdnav_get_active_audio_stream(dvdnav_t *this) { | |
958 int8_t retval; | |
959 | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
960 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
961 printerr("Passed a NULL pointer."); |
114 | 962 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
963 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
964 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
965 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
966 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
967 } |
114 | 968 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
969 pthread_mutex_lock(&this->vm_lock); |
114 | 970 if (!this->vm->state.pgc) { |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
971 printerr("No current PGC."); |
114 | 972 pthread_mutex_unlock(&this->vm_lock); |
973 return -1; | |
974 } | |
975 retval = vm_get_audio_active_stream(this->vm); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
976 pthread_mutex_unlock(&this->vm_lock); |
114 | 977 |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
978 return retval; |
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
979 } |
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
980 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
981 int8_t dvdnav_get_active_spu_stream(dvdnav_t *this) { |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
982 int8_t retval; |
0 | 983 |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
984 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
985 printerr("Passed a NULL pointer."); |
0 | 986 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
987 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
988 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
989 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
990 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
991 } |
0 | 992 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
993 pthread_mutex_lock(&this->vm_lock); |
114 | 994 if (!this->vm->state.pgc) { |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
995 printerr("No current PGC."); |
114 | 996 pthread_mutex_unlock(&this->vm_lock); |
997 return -1; | |
998 } | |
999 retval = vm_get_subp_active_stream(this->vm, 0); | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1000 pthread_mutex_unlock(&this->vm_lock); |
0 | 1001 |
21
d2d73f2ad8d3
Change/fix SPU active stream id. Same for audio. Few new functions, largely
f1rmb
parents:
17
diff
changeset
|
1002 return retval; |
0 | 1003 } |
1004 | |
114 | 1005 static int8_t dvdnav_is_domain(dvdnav_t *this, domain_t domain) { |
1006 int8_t retval; | |
1007 | |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1008 if(!this) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1009 printerr("Passed a NULL pointer."); |
114 | 1010 return -1; |
142
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1011 } |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1012 if(!this->started) { |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1013 printerr("Virtual DVD machine not started."); |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1014 return -1; |
e375b765ebf5
some more sanity checking will prevent segfaults in these functions
mroi
parents:
141
diff
changeset
|
1015 } |
114 | 1016 |
1017 pthread_mutex_lock(&this->vm_lock); | |
1018 retval = (this->vm->state.domain == domain); | |
1019 pthread_mutex_unlock(&this->vm_lock); | |
1020 | |
1021 return retval; | |
1022 } | |
1023 | |
0 | 1024 /* First Play domain. (Menu) */ |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1025 int8_t dvdnav_is_domain_fp(dvdnav_t *this) { |
114 | 1026 return dvdnav_is_domain(this, FP_DOMAIN); |
0 | 1027 } |
1028 /* Video management Menu domain. (Menu) */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1029 int8_t dvdnav_is_domain_vmgm(dvdnav_t *this) { |
114 | 1030 return dvdnav_is_domain(this, VMGM_DOMAIN); |
0 | 1031 } |
1032 /* Video Title Menu domain (Menu) */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1033 int8_t dvdnav_is_domain_vtsm(dvdnav_t *this) { |
114 | 1034 return dvdnav_is_domain(this, VTSM_DOMAIN); |
0 | 1035 } |
1036 /* Video Title domain (playing movie). */ | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1037 int8_t dvdnav_is_domain_vts(dvdnav_t *this) { |
114 | 1038 return dvdnav_is_domain(this, VTS_DOMAIN); |
0 | 1039 } |
1040 | |
114 | 1041 /* Generally delegate angle information handling to VM */ |
195 | 1042 dvdnav_status_t dvdnav_angle_change(dvdnav_t *this, int32_t angle) { |
1043 int32_t num, current; | |
0 | 1044 |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1045 if(!this) { |
114 | 1046 printerr("Passed a NULL pointer."); |
193 | 1047 return DVDNAV_STATUS_ERR; |
0 | 1048 } |
1049 | |
114 | 1050 pthread_mutex_lock(&this->vm_lock); |
1051 vm_get_angle_info(this->vm, ¤t, &num); | |
0 | 1052 /* Set angle SPRM if valid */ |
1053 if((angle > 0) && (angle <= num)) { | |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1054 this->vm->state.AGL_REG = angle; |
0 | 1055 } else { |
114 | 1056 printerr("Passed an invalid angle number."); |
1057 pthread_mutex_unlock(&this->vm_lock); | |
193 | 1058 return DVDNAV_STATUS_ERR; |
0 | 1059 } |
114 | 1060 pthread_mutex_unlock(&this->vm_lock); |
0 | 1061 |
193 | 1062 return DVDNAV_STATUS_OK; |
0 | 1063 } |
1064 | |
195 | 1065 dvdnav_status_t dvdnav_get_angle_info(dvdnav_t *this, int32_t *current_angle, |
1066 int32_t *number_of_angles) { | |
114 | 1067 if(!this || !current_angle || !number_of_angles) { |
1068 printerr("Passed a NULL pointer."); | |
193 | 1069 return DVDNAV_STATUS_ERR; |
22
3c1df0cb3aee
Start of rewrite of libdvdnav. Still need to re-implement seeking.
jcdutton
parents:
21
diff
changeset
|
1070 } |
114 | 1071 |
1072 pthread_mutex_lock(&this->vm_lock); | |
1073 vm_get_angle_info(this->vm, current_angle, number_of_angles); | |
1074 pthread_mutex_unlock(&this->vm_lock); | |
1075 | |
193 | 1076 return DVDNAV_STATUS_OK; |
114 | 1077 } |
0 | 1078 |
67
61c0ee1bbb7a
Moved get_current_nav_pci into dvdnac.c, changed example to use it instead of 'home-rolled'
richwareham
parents:
66
diff
changeset
|
1079 pci_t* dvdnav_get_current_nav_pci(dvdnav_t *this) { |
114 | 1080 if(!this) return 0; |
67
61c0ee1bbb7a
Moved get_current_nav_pci into dvdnac.c, changed example to use it instead of 'home-rolled'
richwareham
parents:
66
diff
changeset
|
1081 return &this->pci; |
61c0ee1bbb7a
Moved get_current_nav_pci into dvdnac.c, changed example to use it instead of 'home-rolled'
richwareham
parents:
66
diff
changeset
|
1082 } |
61c0ee1bbb7a
Moved get_current_nav_pci into dvdnac.c, changed example to use it instead of 'home-rolled'
richwareham
parents:
66
diff
changeset
|
1083 |
66
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1084 dsi_t* dvdnav_get_current_nav_dsi(dvdnav_t *this) { |
114 | 1085 if(!this) return 0; |
66
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1086 return &this->dsi; |
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1087 } |
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1088 |
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1089 uint32_t dvdnav_get_next_still_flag(dvdnav_t *this) { |
114 | 1090 if(!this) return -1; |
66
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1091 return this->position_next.still; |
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1092 } |
2bd4a78eefce
Patch from aschultz@cs.uni-magdeburg.de to allow for still-frame 'peek-ahead'
richwareham
parents:
60
diff
changeset
|
1093 |