rev |
line source |
paulo@0
|
1 /*
|
paulo@0
|
2 * Copyright (C) 2003 by the libdvdnav project
|
paulo@0
|
3 *
|
paulo@0
|
4 * This file is part of libdvdnav, a DVD navigation library.
|
paulo@0
|
5 *
|
paulo@0
|
6 * libdvdnav is free software; you can redistribute it and/or modify
|
paulo@0
|
7 * it under the terms of the GNU General Public License as published by
|
paulo@0
|
8 * the Free Software Foundation; either version 2 of the License, or
|
paulo@0
|
9 * (at your option) any later version.
|
paulo@0
|
10 *
|
paulo@0
|
11 * libdvdnav is distributed in the hope that it will be useful,
|
paulo@0
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
paulo@0
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
paulo@0
|
14 * GNU General Public License for more details.
|
paulo@0
|
15 *
|
paulo@0
|
16 * You should have received a copy of the GNU General Public License
|
paulo@0
|
17 * along with this program; if not, write to the Free Software
|
paulo@0
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
paulo@0
|
19 *
|
paulo@0
|
20 * $Id: menus.c 1135 2008-09-06 21:55:51Z rathann $
|
paulo@0
|
21 *
|
paulo@0
|
22 */
|
paulo@0
|
23
|
paulo@0
|
24 #include <stdio.h>
|
paulo@0
|
25 #include <unistd.h>
|
paulo@0
|
26 #include <inttypes.h>
|
paulo@0
|
27 #include <sys/types.h>
|
paulo@0
|
28 #include <sys/stat.h>
|
paulo@0
|
29 #include <fcntl.h>
|
paulo@0
|
30 #include "dvd_types.h"
|
paulo@0
|
31 #include <dvdread/dvd_reader.h>
|
paulo@0
|
32 #include <dvdread/nav_types.h>
|
paulo@0
|
33 #include <dvdread/ifo_types.h> /* For vm_cmd_t */
|
paulo@0
|
34 #include "dvdnav.h"
|
paulo@0
|
35 #include "dvdnav_events.h"
|
paulo@0
|
36
|
paulo@0
|
37 /* shall we use libdvdnav's read ahead cache? */
|
paulo@0
|
38 #define DVD_READ_CACHE 1
|
paulo@0
|
39
|
paulo@0
|
40 /* which is the default language for menus/audio/subpictures? */
|
paulo@0
|
41 #define DVD_LANGUAGE "en"
|
paulo@0
|
42
|
paulo@0
|
43 #ifdef WIN32
|
paulo@0
|
44 #define S_IRWXG 0
|
paulo@0
|
45 #endif
|
paulo@0
|
46
|
paulo@0
|
47 int main(int argc, char **argv) {
|
paulo@0
|
48 dvdnav_t *dvdnav;
|
paulo@0
|
49 uint8_t mem[DVD_VIDEO_LB_LEN];
|
paulo@0
|
50 int finished = 0;
|
paulo@0
|
51 int output_fd = 0;
|
paulo@1
|
52 int dump = 0, tt_dump = 0, tt_skip = 0;
|
paulo@0
|
53
|
paulo@0
|
54 /* open dvdnav handle */
|
paulo@0
|
55 printf("Opening DVD...\n");
|
paulo@0
|
56 if (dvdnav_open(&dvdnav, "/dev/dvd") != DVDNAV_STATUS_OK) {
|
paulo@0
|
57 printf("Error on dvdnav_open\n");
|
paulo@0
|
58 return 1;
|
paulo@0
|
59 }
|
paulo@0
|
60
|
paulo@0
|
61 /* set read ahead cache usage */
|
paulo@0
|
62 if (dvdnav_set_readahead_flag(dvdnav, DVD_READ_CACHE) != DVDNAV_STATUS_OK) {
|
paulo@0
|
63 printf("Error on dvdnav_set_readahead_flag: %s\n", dvdnav_err_to_string(dvdnav));
|
paulo@0
|
64 return 2;
|
paulo@0
|
65 }
|
paulo@0
|
66
|
paulo@0
|
67 /* set the language */
|
paulo@0
|
68 if (dvdnav_menu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK ||
|
paulo@0
|
69 dvdnav_audio_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK ||
|
paulo@0
|
70 dvdnav_spu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK) {
|
paulo@0
|
71 printf("Error on setting languages: %s\n", dvdnav_err_to_string(dvdnav));
|
paulo@0
|
72 return 2;
|
paulo@0
|
73 }
|
paulo@0
|
74
|
paulo@0
|
75 /* set the PGC positioning flag to have position information relatively to the
|
paulo@0
|
76 * whole feature instead of just relatively to the current chapter */
|
paulo@0
|
77 if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) {
|
paulo@0
|
78 printf("Error on dvdnav_set_PGC_positioning_flag: %s\n", dvdnav_err_to_string(dvdnav));
|
paulo@0
|
79 return 2;
|
paulo@0
|
80 }
|
paulo@0
|
81
|
paulo@0
|
82
|
paulo@0
|
83 /* the read loop which regularly calls dvdnav_get_next_block
|
paulo@0
|
84 * and handles the returned events */
|
paulo@0
|
85 printf("Reading...\n");
|
paulo@0
|
86 while (!finished) {
|
paulo@0
|
87 int result, event, len;
|
paulo@0
|
88 uint8_t *buf = mem;
|
paulo@0
|
89
|
paulo@0
|
90 /* the main reading function */
|
paulo@0
|
91 #if DVD_READ_CACHE
|
paulo@0
|
92 result = dvdnav_get_next_cache_block(dvdnav, &buf, &event, &len);
|
paulo@0
|
93 #else
|
paulo@0
|
94 result = dvdnav_get_next_block(dvdnav, buf, &event, &len);
|
paulo@0
|
95 #endif
|
paulo@0
|
96
|
paulo@0
|
97 if (result == DVDNAV_STATUS_ERR) {
|
paulo@0
|
98 printf("Error getting next block: %s\n", dvdnav_err_to_string(dvdnav));
|
paulo@0
|
99 return 3;
|
paulo@0
|
100 }
|
paulo@0
|
101
|
paulo@0
|
102 switch (event) {
|
paulo@0
|
103 case DVDNAV_BLOCK_OK:
|
paulo@0
|
104 /* We have received a regular block of the currently playing MPEG stream.
|
paulo@0
|
105 * A real player application would now pass this block through demuxing
|
paulo@0
|
106 * and decoding. We simply write it to disc here. */
|
paulo@0
|
107
|
paulo@1
|
108 if (!output_fd && (dump || tt_dump)) {
|
paulo@0
|
109 printf("Opening output...\n");
|
paulo@1
|
110 output_fd = open("libdvdnav.mpg", O_CREAT | O_WRONLY | O_APPEND, S_IRWXU | S_IRWXG);
|
paulo@0
|
111 if (output_fd == -1) {
|
paulo@0
|
112 printf("Error opening output\n");
|
paulo@0
|
113 return 4;
|
paulo@0
|
114 }
|
paulo@0
|
115 }
|
paulo@0
|
116
|
paulo@0
|
117 if (dump || tt_dump)
|
paulo@0
|
118 write(output_fd, buf, len);
|
paulo@0
|
119
|
paulo@0
|
120 break;
|
paulo@0
|
121 case DVDNAV_NOP:
|
paulo@0
|
122 /* Nothing to do here. */
|
paulo@0
|
123 break;
|
paulo@0
|
124 case DVDNAV_STILL_FRAME:
|
paulo@0
|
125 /* We have reached a still frame. A real player application would wait
|
paulo@0
|
126 * the amount of time specified by the still's length while still handling
|
paulo@0
|
127 * user input to make menus and other interactive stills work.
|
paulo@0
|
128 * A length of 0xff means an indefinite still which has to be skipped
|
paulo@0
|
129 * indirectly by some user interaction. */
|
paulo@0
|
130 {
|
paulo@0
|
131 dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)buf;
|
paulo@0
|
132 if (still_event->length < 0xff)
|
paulo@0
|
133 printf("Skipping %d seconds of still frame\n", still_event->length);
|
paulo@0
|
134 else
|
paulo@0
|
135 printf("Skipping indefinite length still frame\n");
|
paulo@0
|
136 dvdnav_still_skip(dvdnav);
|
paulo@0
|
137 }
|
paulo@0
|
138 break;
|
paulo@0
|
139 case DVDNAV_WAIT:
|
paulo@0
|
140 /* We have reached a point in DVD playback, where timing is critical.
|
paulo@0
|
141 * Player application with internal fifos can introduce state
|
paulo@0
|
142 * inconsistencies, because libdvdnav is always the fifo's length
|
paulo@0
|
143 * ahead in the stream compared to what the application sees.
|
paulo@0
|
144 * Such applications should wait until their fifos are empty
|
paulo@0
|
145 * when they receive this type of event. */
|
paulo@0
|
146 printf("Skipping wait condition\n");
|
paulo@0
|
147 dvdnav_wait_skip(dvdnav);
|
paulo@0
|
148 break;
|
paulo@0
|
149 case DVDNAV_SPU_CLUT_CHANGE:
|
paulo@0
|
150 /* Player applications should pass the new colour lookup table to their
|
paulo@0
|
151 * SPU decoder */
|
paulo@0
|
152 break;
|
paulo@0
|
153 case DVDNAV_SPU_STREAM_CHANGE:
|
paulo@0
|
154 /* Player applications should inform their SPU decoder to switch channels */
|
paulo@0
|
155 break;
|
paulo@0
|
156 case DVDNAV_AUDIO_STREAM_CHANGE:
|
paulo@0
|
157 /* Player applications should inform their audio decoder to switch channels */
|
paulo@0
|
158 break;
|
paulo@0
|
159 case DVDNAV_HIGHLIGHT:
|
paulo@0
|
160 /* Player applications should inform their overlay engine to highlight the
|
paulo@0
|
161 * given button */
|
paulo@0
|
162 {
|
paulo@0
|
163 dvdnav_highlight_event_t *highlight_event = (dvdnav_highlight_event_t *)buf;
|
paulo@0
|
164 printf("Selected button %d\n", highlight_event->buttonN);
|
paulo@0
|
165 }
|
paulo@0
|
166 break;
|
paulo@0
|
167 case DVDNAV_VTS_CHANGE:
|
paulo@0
|
168 /* Some status information like video aspect and video scale permissions do
|
paulo@0
|
169 * not change inside a VTS. Therefore this event can be used to query such
|
paulo@0
|
170 * information only when necessary and update the decoding/displaying
|
paulo@0
|
171 * accordingly. */
|
paulo@0
|
172 break;
|
paulo@0
|
173 case DVDNAV_CELL_CHANGE:
|
paulo@0
|
174 /* Some status information like the current Title and Part numbers do not
|
paulo@0
|
175 * change inside a cell. Therefore this event can be used to query such
|
paulo@0
|
176 * information only when necessary and update the decoding/displaying
|
paulo@0
|
177 * accordingly. */
|
paulo@0
|
178 {
|
paulo@0
|
179 int32_t tt = 0, ptt = 0;
|
paulo@0
|
180 uint32_t pos, len;
|
paulo@0
|
181 char input = '\0';
|
paulo@0
|
182
|
paulo@0
|
183 dvdnav_current_title_info(dvdnav, &tt, &ptt);
|
paulo@0
|
184 dvdnav_get_position(dvdnav, &pos, &len);
|
paulo@0
|
185 printf("Cell change: Title %d, Chapter %d\n", tt, ptt);
|
paulo@0
|
186 printf("At position %.0f%% inside the feature\n", 100 * (double)pos / (double)len);
|
paulo@0
|
187
|
paulo@0
|
188 dump = 0;
|
paulo@0
|
189 if (tt_dump && tt != tt_dump)
|
paulo@0
|
190 tt_dump = 0;
|
paulo@0
|
191
|
paulo@1
|
192 if (tt_skip && tt != tt_skip)
|
paulo@1
|
193 tt_skip = 0;
|
paulo@1
|
194
|
paulo@1
|
195 if (output_fd && !tt_dump) {
|
paulo@1
|
196 printf("Closing output...\n");
|
paulo@1
|
197 output_fd = close(output_fd);
|
paulo@1
|
198 }
|
paulo@1
|
199
|
paulo@1
|
200 if (!dump && !tt_dump && !tt_skip) {
|
paulo@0
|
201 fflush(stdin);
|
paulo@1
|
202 while ((input != 'a') && (input != 's') && (input != 'q') && (input != 't') && (input != 'l')) {
|
paulo@1
|
203 printf("(a)ppend cell to output\n(s)kip cell\nappend until end of (t)itle\nskip tit(l)e\n(q)uit\n");
|
paulo@0
|
204 scanf("%c", &input);
|
paulo@0
|
205 }
|
paulo@0
|
206
|
paulo@0
|
207 switch (input) {
|
paulo@0
|
208 case 'a':
|
paulo@0
|
209 dump = 1;
|
paulo@0
|
210 break;
|
paulo@0
|
211 case 't':
|
paulo@0
|
212 tt_dump = tt;
|
paulo@0
|
213 break;
|
paulo@1
|
214 case 'l':
|
paulo@1
|
215 tt_skip = tt;
|
paulo@1
|
216 break;
|
paulo@0
|
217 case 'q':
|
paulo@0
|
218 finished = 1;
|
paulo@0
|
219 }
|
paulo@0
|
220 }
|
paulo@0
|
221 }
|
paulo@0
|
222 break;
|
paulo@0
|
223 case DVDNAV_NAV_PACKET:
|
paulo@0
|
224 /* A NAV packet provides PTS discontinuity information, angle linking information and
|
paulo@0
|
225 * button definitions for DVD menus. Angles are handled completely inside libdvdnav.
|
paulo@0
|
226 * For the menus to work, the NAV packet information has to be passed to the overlay
|
paulo@0
|
227 * engine of the player so that it knows the dimensions of the button areas. */
|
paulo@0
|
228 {
|
paulo@0
|
229 pci_t *pci;
|
paulo@0
|
230
|
paulo@0
|
231 /* Applications with fifos should not use these functions to retrieve NAV packets,
|
paulo@0
|
232 * they should implement their own NAV handling, because the packet you get from these
|
paulo@0
|
233 * functions will already be ahead in the stream which can cause state inconsistencies.
|
paulo@0
|
234 * Applications with fifos should therefore pass the NAV packet through the fifo
|
paulo@0
|
235 * and decoding pipeline just like any other data. */
|
paulo@0
|
236 pci = dvdnav_get_current_nav_pci(dvdnav);
|
paulo@0
|
237 dvdnav_get_current_nav_dsi(dvdnav);
|
paulo@0
|
238
|
paulo@0
|
239 if(pci->hli.hl_gi.btn_ns > 0) {
|
paulo@0
|
240 int button;
|
paulo@0
|
241
|
paulo@0
|
242 printf("Found %i DVD menu buttons...\n", pci->hli.hl_gi.btn_ns);
|
paulo@0
|
243
|
paulo@0
|
244 for (button = 0; button < pci->hli.hl_gi.btn_ns; button++) {
|
paulo@0
|
245 btni_t *btni = &(pci->hli.btnit[button]);
|
paulo@0
|
246 printf("Button %i top-left @ (%i,%i), bottom-right @ (%i,%i)\n",
|
paulo@0
|
247 button + 1, btni->x_start, btni->y_start,
|
paulo@0
|
248 btni->x_end, btni->y_end);
|
paulo@0
|
249 }
|
paulo@0
|
250
|
paulo@0
|
251 button = 0;
|
paulo@0
|
252 while ((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) {
|
paulo@0
|
253 printf("Which button (1 to %i): ", pci->hli.hl_gi.btn_ns);
|
paulo@0
|
254 scanf("%i", &button);
|
paulo@0
|
255 }
|
paulo@0
|
256
|
paulo@0
|
257 printf("Selecting button %i...\n", button);
|
paulo@0
|
258 /* This is the point where applications with fifos have to hand in a NAV packet
|
paulo@0
|
259 * which has traveled through the fifos. See the notes above. */
|
paulo@0
|
260 dvdnav_button_select_and_activate(dvdnav, pci, button);
|
paulo@0
|
261 }
|
paulo@0
|
262 }
|
paulo@0
|
263 break;
|
paulo@0
|
264 case DVDNAV_HOP_CHANNEL:
|
paulo@0
|
265 /* This event is issued whenever a non-seamless operation has been executed.
|
paulo@0
|
266 * Applications with fifos should drop the fifos content to speed up responsiveness. */
|
paulo@0
|
267 break;
|
paulo@0
|
268 case DVDNAV_STOP:
|
paulo@0
|
269 /* Playback should end here. */
|
paulo@0
|
270 {
|
paulo@0
|
271 finished = 1;
|
paulo@0
|
272 }
|
paulo@0
|
273 break;
|
paulo@0
|
274 default:
|
paulo@0
|
275 printf("Unknown event (%i)\n", event);
|
paulo@0
|
276 finished = 1;
|
paulo@0
|
277 break;
|
paulo@0
|
278 }
|
paulo@0
|
279 #if DVD_READ_CACHE
|
paulo@0
|
280 dvdnav_free_cache_block(dvdnav, buf);
|
paulo@0
|
281 #endif
|
paulo@0
|
282 }
|
paulo@0
|
283
|
paulo@0
|
284 /* destroy dvdnav handle */
|
paulo@0
|
285 if (dvdnav_close(dvdnav) != DVDNAV_STATUS_OK) {
|
paulo@0
|
286 printf("Error on dvdnav_close: %s\n", dvdnav_err_to_string(dvdnav));
|
paulo@0
|
287 return 5;
|
paulo@0
|
288 }
|
paulo@0
|
289 close(output_fd);
|
paulo@0
|
290
|
paulo@0
|
291 return 0;
|
paulo@0
|
292 }
|