Mercurial > hg > index.fcgi > dvdnav-rip > dvdnav-rip-1pba
changeset 2:399518436fcf
fix tabbing
author | paulo@thepaulopc |
---|---|
date | Fri, 13 Nov 2009 00:02:37 -0800 |
parents | cfe5048cc182 |
children | ffbf478b80c2 |
files | menus.c |
diffstat | 1 files changed, 230 insertions(+), 236 deletions(-) [+] |
line diff
1.1 --- a/menus.c Thu Nov 12 23:43:47 2009 -0800 1.2 +++ b/menus.c Fri Nov 13 00:02:37 2009 -0800 1.3 @@ -45,248 +45,242 @@ 1.4 #endif 1.5 1.6 int main(int argc, char **argv) { 1.7 - dvdnav_t *dvdnav; 1.8 - uint8_t mem[DVD_VIDEO_LB_LEN]; 1.9 - int finished = 0; 1.10 - int output_fd = 0; 1.11 - int dump = 0, tt_dump = 0, tt_skip = 0; 1.12 - 1.13 - /* open dvdnav handle */ 1.14 - printf("Opening DVD...\n"); 1.15 - if (dvdnav_open(&dvdnav, "/dev/dvd") != DVDNAV_STATUS_OK) { 1.16 - printf("Error on dvdnav_open\n"); 1.17 - return 1; 1.18 - } 1.19 - 1.20 - /* set read ahead cache usage */ 1.21 - if (dvdnav_set_readahead_flag(dvdnav, DVD_READ_CACHE) != DVDNAV_STATUS_OK) { 1.22 - printf("Error on dvdnav_set_readahead_flag: %s\n", dvdnav_err_to_string(dvdnav)); 1.23 - return 2; 1.24 - } 1.25 - 1.26 - /* set the language */ 1.27 - if (dvdnav_menu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || 1.28 - dvdnav_audio_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || 1.29 - dvdnav_spu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK) { 1.30 - printf("Error on setting languages: %s\n", dvdnav_err_to_string(dvdnav)); 1.31 - return 2; 1.32 - } 1.33 - 1.34 - /* set the PGC positioning flag to have position information relatively to the 1.35 - * whole feature instead of just relatively to the current chapter */ 1.36 - if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) { 1.37 - printf("Error on dvdnav_set_PGC_positioning_flag: %s\n", dvdnav_err_to_string(dvdnav)); 1.38 - return 2; 1.39 - } 1.40 - 1.41 - 1.42 - /* the read loop which regularly calls dvdnav_get_next_block 1.43 - * and handles the returned events */ 1.44 - printf("Reading...\n"); 1.45 - while (!finished) { 1.46 - int result, event, len; 1.47 - uint8_t *buf = mem; 1.48 - 1.49 - /* the main reading function */ 1.50 + dvdnav_t *dvdnav; 1.51 + uint8_t mem[DVD_VIDEO_LB_LEN]; 1.52 + int finished = 0; 1.53 + int output_fd = 0; 1.54 + int dump = 0, tt_dump = 0, tt_skip = 0; 1.55 + 1.56 + /* open dvdnav handle */ 1.57 + printf("Opening DVD...\n"); 1.58 + if (dvdnav_open(&dvdnav, "/dev/dvd") != DVDNAV_STATUS_OK) { 1.59 + printf("Error on dvdnav_open\n"); 1.60 + return 1; 1.61 + } 1.62 + 1.63 + /* set read ahead cache usage */ 1.64 + if (dvdnav_set_readahead_flag(dvdnav, DVD_READ_CACHE) != DVDNAV_STATUS_OK) { 1.65 + printf("Error on dvdnav_set_readahead_flag: %s\n", dvdnav_err_to_string(dvdnav)); 1.66 + return 2; 1.67 + } 1.68 + 1.69 + /* set the language */ 1.70 + if (dvdnav_menu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || 1.71 + dvdnav_audio_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || 1.72 + dvdnav_spu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK) { 1.73 + printf("Error on setting languages: %s\n", dvdnav_err_to_string(dvdnav)); 1.74 + return 2; 1.75 + } 1.76 + 1.77 + /* set the PGC positioning flag to have position information relatively to the 1.78 + * whole feature instead of just relatively to the current chapter */ 1.79 + if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) { 1.80 + printf("Error on dvdnav_set_PGC_positioning_flag: %s\n", dvdnav_err_to_string(dvdnav)); 1.81 + return 2; 1.82 + } 1.83 + 1.84 + 1.85 + /* the read loop which regularly calls dvdnav_get_next_block 1.86 + * and handles the returned events */ 1.87 + printf("Reading...\n"); 1.88 + while (!finished) { 1.89 + int result, event, len; 1.90 + uint8_t *buf = mem; 1.91 + 1.92 + /* the main reading function */ 1.93 #if DVD_READ_CACHE 1.94 - result = dvdnav_get_next_cache_block(dvdnav, &buf, &event, &len); 1.95 + result = dvdnav_get_next_cache_block(dvdnav, &buf, &event, &len); 1.96 #else 1.97 - result = dvdnav_get_next_block(dvdnav, buf, &event, &len); 1.98 + result = dvdnav_get_next_block(dvdnav, buf, &event, &len); 1.99 #endif 1.100 1.101 - if (result == DVDNAV_STATUS_ERR) { 1.102 - printf("Error getting next block: %s\n", dvdnav_err_to_string(dvdnav)); 1.103 - return 3; 1.104 - } 1.105 + if (result == DVDNAV_STATUS_ERR) { 1.106 + printf("Error getting next block: %s\n", dvdnav_err_to_string(dvdnav)); 1.107 + return 3; 1.108 + } 1.109 + 1.110 + switch (event) { 1.111 + case DVDNAV_BLOCK_OK: 1.112 + /* We have received a regular block of the currently playing MPEG stream. 1.113 + * A real player application would now pass this block through demuxing 1.114 + * and decoding. We simply write it to disc here. */ 1.115 + 1.116 + if (!output_fd && (dump || tt_dump)) { 1.117 + printf("Opening output...\n"); 1.118 + output_fd = open("libdvdnav.mpg", O_CREAT | O_WRONLY | O_APPEND, S_IRWXU | S_IRWXG); 1.119 + if (output_fd == -1) { 1.120 + printf("Error opening output\n"); 1.121 + return 4; 1.122 + } 1.123 + } 1.124 1.125 - switch (event) { 1.126 - case DVDNAV_BLOCK_OK: 1.127 - /* We have received a regular block of the currently playing MPEG stream. 1.128 - * A real player application would now pass this block through demuxing 1.129 - * and decoding. We simply write it to disc here. */ 1.130 + if (dump || tt_dump) 1.131 + write(output_fd, buf, len); 1.132 1.133 - if (!output_fd && (dump || tt_dump)) { 1.134 - printf("Opening output...\n"); 1.135 - output_fd = open("libdvdnav.mpg", O_CREAT | O_WRONLY | O_APPEND, S_IRWXU | S_IRWXG); 1.136 - if (output_fd == -1) { 1.137 - printf("Error opening output\n"); 1.138 - return 4; 1.139 + break; 1.140 + case DVDNAV_NOP: 1.141 + /* Nothing to do here. */ 1.142 + break; 1.143 + case DVDNAV_STILL_FRAME: 1.144 + /* We have reached a still frame. A real player application would wait 1.145 + * the amount of time specified by the still's length while still handling 1.146 + * user input to make menus and other interactive stills work. 1.147 + * A length of 0xff means an indefinite still which has to be skipped 1.148 + * indirectly by some user interaction. */ 1.149 + dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)buf; 1.150 + if (still_event->length < 0xff) 1.151 + printf("Skipping %d seconds of still frame\n", still_event->length); 1.152 + else 1.153 + printf("Skipping indefinite length still frame\n"); 1.154 + dvdnav_still_skip(dvdnav); 1.155 + break; 1.156 + case DVDNAV_WAIT: 1.157 + /* We have reached a point in DVD playback, where timing is critical. 1.158 + * Player application with internal fifos can introduce state 1.159 + * inconsistencies, because libdvdnav is always the fifo's length 1.160 + * ahead in the stream compared to what the application sees. 1.161 + * Such applications should wait until their fifos are empty 1.162 + * when they receive this type of event. */ 1.163 + printf("Skipping wait condition\n"); 1.164 + dvdnav_wait_skip(dvdnav); 1.165 + break; 1.166 + case DVDNAV_SPU_CLUT_CHANGE: 1.167 + /* Player applications should pass the new colour lookup table to their 1.168 + * SPU decoder */ 1.169 + break; 1.170 + case DVDNAV_SPU_STREAM_CHANGE: 1.171 + /* Player applications should inform their SPU decoder to switch channels */ 1.172 + break; 1.173 + case DVDNAV_AUDIO_STREAM_CHANGE: 1.174 + /* Player applications should inform their audio decoder to switch channels */ 1.175 + break; 1.176 + case DVDNAV_HIGHLIGHT: 1.177 + /* Player applications should inform their overlay engine to highlight the 1.178 + * given button */ 1.179 + dvdnav_highlight_event_t *highlight_event = (dvdnav_highlight_event_t *)buf; 1.180 + printf("Selected button %d\n", highlight_event->buttonN); 1.181 + break; 1.182 + case DVDNAV_VTS_CHANGE: 1.183 + /* Some status information like video aspect and video scale permissions do 1.184 + * not change inside a VTS. Therefore this event can be used to query such 1.185 + * information only when necessary and update the decoding/displaying 1.186 + * accordingly. */ 1.187 + break; 1.188 + case DVDNAV_CELL_CHANGE: 1.189 + /* Some status information like the current Title and Part numbers do not 1.190 + * change inside a cell. Therefore this event can be used to query such 1.191 + * information only when necessary and update the decoding/displaying 1.192 + * accordingly. */ 1.193 + { 1.194 + int32_t tt = 0, ptt = 0; 1.195 + uint32_t pos, len; 1.196 + char input = '\0'; 1.197 + 1.198 + dvdnav_current_title_info(dvdnav, &tt, &ptt); 1.199 + dvdnav_get_position(dvdnav, &pos, &len); 1.200 + printf("Cell change: Title %d, Chapter %d\n", tt, ptt); 1.201 + printf("At position %.0f%% inside the feature\n", 100 * (double)pos / (double)len); 1.202 + 1.203 + dump = 0; 1.204 + if (tt_dump && tt != tt_dump) 1.205 + tt_dump = 0; 1.206 + 1.207 + if (tt_skip && tt != tt_skip) 1.208 + tt_skip = 0; 1.209 + 1.210 + if (output_fd && !tt_dump) { 1.211 + printf("Closing output...\n"); 1.212 + output_fd = close(output_fd); 1.213 + } 1.214 + 1.215 + if (!dump && !tt_dump && !tt_skip) { 1.216 + fflush(stdin); 1.217 + while ((input != 'a') && (input != 's') && (input != 'q') && (input != 't') && (input != 'l')) { 1.218 + printf("(a)ppend cell to output\n(s)kip cell\nappend until end of (t)itle\nskip tit(l)e\n(q)uit\n"); 1.219 + scanf("%c", &input); 1.220 + } 1.221 + 1.222 + switch (input) { 1.223 + case 'a': 1.224 + dump = 1; 1.225 + break; 1.226 + case 't': 1.227 + tt_dump = tt; 1.228 + break; 1.229 + case 'l': 1.230 + tt_skip = tt; 1.231 + break; 1.232 + case 'q': 1.233 + finished = 1; 1.234 + } 1.235 + } 1.236 + } 1.237 + break; 1.238 + case DVDNAV_NAV_PACKET: 1.239 + /* A NAV packet provides PTS discontinuity information, angle linking information and 1.240 + * button definitions for DVD menus. Angles are handled completely inside libdvdnav. 1.241 + * For the menus to work, the NAV packet information has to be passed to the overlay 1.242 + * engine of the player so that it knows the dimensions of the button areas. */ 1.243 + { 1.244 + pci_t *pci; 1.245 + 1.246 + /* Applications with fifos should not use these functions to retrieve NAV packets, 1.247 + * they should implement their own NAV handling, because the packet you get from these 1.248 + * functions will already be ahead in the stream which can cause state inconsistencies. 1.249 + * Applications with fifos should therefore pass the NAV packet through the fifo 1.250 + * and decoding pipeline just like any other data. */ 1.251 + pci = dvdnav_get_current_nav_pci(dvdnav); 1.252 + dvdnav_get_current_nav_dsi(dvdnav); 1.253 + 1.254 + if(pci->hli.hl_gi.btn_ns > 0) { 1.255 + int button; 1.256 + 1.257 + printf("Found %i DVD menu buttons...\n", pci->hli.hl_gi.btn_ns); 1.258 + 1.259 + for (button = 0; button < pci->hli.hl_gi.btn_ns; button++) { 1.260 + btni_t *btni = &(pci->hli.btnit[button]); 1.261 + printf("Button %i top-left @ (%i,%i), bottom-right @ (%i,%i)\n", 1.262 + button + 1, btni->x_start, btni->y_start, 1.263 + btni->x_end, btni->y_end); 1.264 + } 1.265 + 1.266 + button = 0; 1.267 + while ((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { 1.268 + printf("Which button (1 to %i): ", pci->hli.hl_gi.btn_ns); 1.269 + scanf("%i", &button); 1.270 + } 1.271 + 1.272 + printf("Selecting button %i...\n", button); 1.273 + /* This is the point where applications with fifos have to hand in a NAV packet 1.274 + * which has traveled through the fifos. See the notes above. */ 1.275 + dvdnav_button_select_and_activate(dvdnav, pci, button); 1.276 + } 1.277 + } 1.278 + break; 1.279 + case DVDNAV_HOP_CHANNEL: 1.280 + /* This event is issued whenever a non-seamless operation has been executed. 1.281 + * Applications with fifos should drop the fifos content to speed up responsiveness. */ 1.282 + break; 1.283 + case DVDNAV_STOP: 1.284 + /* Playback should end here. */ 1.285 + finished = 1; 1.286 + break; 1.287 + default: 1.288 + printf("Unknown event (%i)\n", event); 1.289 + finished = 1; 1.290 + break; 1.291 + } 1.292 +#if DVD_READ_CACHE 1.293 + dvdnav_free_cache_block(dvdnav, buf); 1.294 +#endif 1.295 } 1.296 - } 1.297 - 1.298 - if (dump || tt_dump) 1.299 - write(output_fd, buf, len); 1.300 - 1.301 - break; 1.302 - case DVDNAV_NOP: 1.303 - /* Nothing to do here. */ 1.304 - break; 1.305 - case DVDNAV_STILL_FRAME: 1.306 - /* We have reached a still frame. A real player application would wait 1.307 - * the amount of time specified by the still's length while still handling 1.308 - * user input to make menus and other interactive stills work. 1.309 - * A length of 0xff means an indefinite still which has to be skipped 1.310 - * indirectly by some user interaction. */ 1.311 - { 1.312 - dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)buf; 1.313 - if (still_event->length < 0xff) 1.314 - printf("Skipping %d seconds of still frame\n", still_event->length); 1.315 - else 1.316 - printf("Skipping indefinite length still frame\n"); 1.317 - dvdnav_still_skip(dvdnav); 1.318 - } 1.319 - break; 1.320 - case DVDNAV_WAIT: 1.321 - /* We have reached a point in DVD playback, where timing is critical. 1.322 - * Player application with internal fifos can introduce state 1.323 - * inconsistencies, because libdvdnav is always the fifo's length 1.324 - * ahead in the stream compared to what the application sees. 1.325 - * Such applications should wait until their fifos are empty 1.326 - * when they receive this type of event. */ 1.327 - printf("Skipping wait condition\n"); 1.328 - dvdnav_wait_skip(dvdnav); 1.329 - break; 1.330 - case DVDNAV_SPU_CLUT_CHANGE: 1.331 - /* Player applications should pass the new colour lookup table to their 1.332 - * SPU decoder */ 1.333 - break; 1.334 - case DVDNAV_SPU_STREAM_CHANGE: 1.335 - /* Player applications should inform their SPU decoder to switch channels */ 1.336 - break; 1.337 - case DVDNAV_AUDIO_STREAM_CHANGE: 1.338 - /* Player applications should inform their audio decoder to switch channels */ 1.339 - break; 1.340 - case DVDNAV_HIGHLIGHT: 1.341 - /* Player applications should inform their overlay engine to highlight the 1.342 - * given button */ 1.343 - { 1.344 - dvdnav_highlight_event_t *highlight_event = (dvdnav_highlight_event_t *)buf; 1.345 - printf("Selected button %d\n", highlight_event->buttonN); 1.346 - } 1.347 - break; 1.348 - case DVDNAV_VTS_CHANGE: 1.349 - /* Some status information like video aspect and video scale permissions do 1.350 - * not change inside a VTS. Therefore this event can be used to query such 1.351 - * information only when necessary and update the decoding/displaying 1.352 - * accordingly. */ 1.353 - break; 1.354 - case DVDNAV_CELL_CHANGE: 1.355 - /* Some status information like the current Title and Part numbers do not 1.356 - * change inside a cell. Therefore this event can be used to query such 1.357 - * information only when necessary and update the decoding/displaying 1.358 - * accordingly. */ 1.359 - { 1.360 - int32_t tt = 0, ptt = 0; 1.361 - uint32_t pos, len; 1.362 - char input = '\0'; 1.363 - 1.364 - dvdnav_current_title_info(dvdnav, &tt, &ptt); 1.365 - dvdnav_get_position(dvdnav, &pos, &len); 1.366 - printf("Cell change: Title %d, Chapter %d\n", tt, ptt); 1.367 - printf("At position %.0f%% inside the feature\n", 100 * (double)pos / (double)len); 1.368 - 1.369 - dump = 0; 1.370 - if (tt_dump && tt != tt_dump) 1.371 - tt_dump = 0; 1.372 - 1.373 - if (tt_skip && tt != tt_skip) 1.374 - tt_skip = 0; 1.375 - 1.376 - if (output_fd && !tt_dump) { 1.377 - printf("Closing output...\n"); 1.378 - output_fd = close(output_fd); 1.379 + 1.380 + /* destroy dvdnav handle */ 1.381 + if (dvdnav_close(dvdnav) != DVDNAV_STATUS_OK) { 1.382 + printf("Error on dvdnav_close: %s\n", dvdnav_err_to_string(dvdnav)); 1.383 + return 5; 1.384 } 1.385 - 1.386 - if (!dump && !tt_dump && !tt_skip) { 1.387 - fflush(stdin); 1.388 - while ((input != 'a') && (input != 's') && (input != 'q') && (input != 't') && (input != 'l')) { 1.389 - printf("(a)ppend cell to output\n(s)kip cell\nappend until end of (t)itle\nskip tit(l)e\n(q)uit\n"); 1.390 - scanf("%c", &input); 1.391 - } 1.392 - 1.393 - switch (input) { 1.394 - case 'a': 1.395 - dump = 1; 1.396 - break; 1.397 - case 't': 1.398 - tt_dump = tt; 1.399 - break; 1.400 - case 'l': 1.401 - tt_skip = tt; 1.402 - break; 1.403 - case 'q': 1.404 - finished = 1; 1.405 - } 1.406 - } 1.407 - } 1.408 - break; 1.409 - case DVDNAV_NAV_PACKET: 1.410 - /* A NAV packet provides PTS discontinuity information, angle linking information and 1.411 - * button definitions for DVD menus. Angles are handled completely inside libdvdnav. 1.412 - * For the menus to work, the NAV packet information has to be passed to the overlay 1.413 - * engine of the player so that it knows the dimensions of the button areas. */ 1.414 - { 1.415 - pci_t *pci; 1.416 - 1.417 - /* Applications with fifos should not use these functions to retrieve NAV packets, 1.418 - * they should implement their own NAV handling, because the packet you get from these 1.419 - * functions will already be ahead in the stream which can cause state inconsistencies. 1.420 - * Applications with fifos should therefore pass the NAV packet through the fifo 1.421 - * and decoding pipeline just like any other data. */ 1.422 - pci = dvdnav_get_current_nav_pci(dvdnav); 1.423 - dvdnav_get_current_nav_dsi(dvdnav); 1.424 - 1.425 - if(pci->hli.hl_gi.btn_ns > 0) { 1.426 - int button; 1.427 - 1.428 - printf("Found %i DVD menu buttons...\n", pci->hli.hl_gi.btn_ns); 1.429 - 1.430 - for (button = 0; button < pci->hli.hl_gi.btn_ns; button++) { 1.431 - btni_t *btni = &(pci->hli.btnit[button]); 1.432 - printf("Button %i top-left @ (%i,%i), bottom-right @ (%i,%i)\n", 1.433 - button + 1, btni->x_start, btni->y_start, 1.434 - btni->x_end, btni->y_end); 1.435 - } 1.436 - 1.437 - button = 0; 1.438 - while ((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { 1.439 - printf("Which button (1 to %i): ", pci->hli.hl_gi.btn_ns); 1.440 - scanf("%i", &button); 1.441 - } 1.442 - 1.443 - printf("Selecting button %i...\n", button); 1.444 - /* This is the point where applications with fifos have to hand in a NAV packet 1.445 - * which has traveled through the fifos. See the notes above. */ 1.446 - dvdnav_button_select_and_activate(dvdnav, pci, button); 1.447 - } 1.448 - } 1.449 - break; 1.450 - case DVDNAV_HOP_CHANNEL: 1.451 - /* This event is issued whenever a non-seamless operation has been executed. 1.452 - * Applications with fifos should drop the fifos content to speed up responsiveness. */ 1.453 - break; 1.454 - case DVDNAV_STOP: 1.455 - /* Playback should end here. */ 1.456 - { 1.457 - finished = 1; 1.458 - } 1.459 - break; 1.460 - default: 1.461 - printf("Unknown event (%i)\n", event); 1.462 - finished = 1; 1.463 - break; 1.464 - } 1.465 -#if DVD_READ_CACHE 1.466 - dvdnav_free_cache_block(dvdnav, buf); 1.467 -#endif 1.468 - } 1.469 - 1.470 - /* destroy dvdnav handle */ 1.471 - if (dvdnav_close(dvdnav) != DVDNAV_STATUS_OK) { 1.472 - printf("Error on dvdnav_close: %s\n", dvdnav_err_to_string(dvdnav)); 1.473 - return 5; 1.474 - } 1.475 - close(output_fd); 1.476 - 1.477 - return 0; 1.478 + close(output_fd); 1.479 + 1.480 + return 0; 1.481 }