static int fill_buffer(stream_t *s, char *but, int len) { int event; dvdnav_priv_t* priv=s->priv; if (priv->state & NAV_FLAG_WAIT_READ) /* read is suspended */ return -1; len=0; if(!s->end_pos) update_title_len(s); while(!len) /* grab all event until DVDNAV_BLOCK_OK (len=2048), DVDNAV_STOP or DVDNAV_STILL_FRAME */ { event=dvdnav_stream_read(priv, s->buffer, &len); if(event==-1 || len==-1) { mp_msg(MSGT_CPLAYER,MSGL_ERR, "DVDNAV stream read error!\n"); return 0; } if (event != DVDNAV_BLOCK_OK) dvdnav_get_highlight (priv, 1); switch (event) { case DVDNAV_STOP: { priv->state |= NAV_FLAG_EOF; return len; } case DVDNAV_BLOCK_OK: case DVDNAV_NAV_PACKET: case DVDNAV_STILL_FRAME: return len; case DVDNAV_WAIT: { if (priv->state & NAV_FLAG_WAIT) return len; break; } case DVDNAV_VTS_CHANGE: { int tit = 0, part = 0; dvdnav_vts_change_event_t *vts_event = (dvdnav_vts_change_event_t *)s->buffer; mp_msg(MSGT_CPLAYER,MSGL_INFO, "DVDNAV, switched to title: %d\r\n", vts_event->new_vtsN); priv->state |= NAV_FLAG_CELL_CHANGE; priv->state |= NAV_FLAG_AUDIO_CHANGE; priv->state |= NAV_FLAG_SPU_CHANGE; priv->state &= ~NAV_FLAG_WAIT_SKIP; priv->state &= ~NAV_FLAG_WAIT; s->end_pos = 0; update_title_len(s); show_audio_subs_languages(priv->dvdnav); if (priv->state & NAV_FLAG_WAIT_READ_AUTO) priv->state |= NAV_FLAG_WAIT_READ; if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK) { mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nDVDNAV, NEW TITLE %d\r\n", tit); dvdnav_get_highlight (priv, 0); if(priv->title > 0 && tit != priv->title) { priv->state |= NAV_FLAG_EOF; return 0; } } break; } case DVDNAV_CELL_CHANGE: { priv->state |= NAV_FLAG_CELL_CHANGE; priv->state |= NAV_FLAG_AUDIO_CHANGE; priv->state |= NAV_FLAG_SPU_CHANGE; priv->state &= ~NAV_FLAG_WAIT_SKIP; priv->state &= ~NAV_FLAG_WAIT; if (priv->state & NAV_FLAG_WAIT_READ_AUTO) priv->state |= NAV_FLAG_WAIT_READ; if(priv->title > 0 && dvd_last_chapter > 0) { int tit=0, part=0; if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK && part > dvd_last_chapter) { priv->state |= NAV_FLAG_EOF; return 0; } } dvdnav_get_highlight (priv, 1); } break; case DVDNAV_AUDIO_STREAM_CHANGE: priv->state |= NAV_FLAG_AUDIO_CHANGE; break; case DVDNAV_SPU_STREAM_CHANGE: priv->state |= NAV_FLAG_SPU_CHANGE; break; } } mp_msg(MSGT_STREAM,MSGL_DBG2,"DVDNAV fill_buffer len: %d\n",len); return len; }
int mp_dvdnav_handle_input(stream_t *stream, int cmd, int *button) { dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv; dvdnav_t *nav = priv->dvdnav; dvdnav_status_t status=DVDNAV_STATUS_ERR; pci_t *pci = dvdnav_get_current_nav_pci(nav); int reset = 0; if(cmd != MP_CMD_DVDNAV_SELECT && !pci) return 0; switch(cmd) { case MP_CMD_DVDNAV_UP: status = dvdnav_upper_button_select(nav, pci); break; case MP_CMD_DVDNAV_DOWN: status = dvdnav_lower_button_select(nav, pci); break; case MP_CMD_DVDNAV_LEFT: status = dvdnav_left_button_select(nav, pci); break; case MP_CMD_DVDNAV_RIGHT: status = dvdnav_right_button_select(nav, pci); break; case MP_CMD_DVDNAV_MENU: status = dvdnav_menu_call(nav,DVD_MENU_Root); reset = 1; break; case MP_CMD_DVDNAV_PREVMENU: { int title=0, part=0; dvdnav_current_title_info(nav, &title, &part); if(title) { if(dvdnav_menu_call(nav, DVD_MENU_Part) == DVDNAV_STATUS_OK || dvdnav_menu_call(nav, DVD_MENU_Title) == DVDNAV_STATUS_OK) { reset = 1; break; } } if(dvdnav_menu_call(nav, DVD_MENU_Root) == DVDNAV_STATUS_OK) reset = 1; } break; case MP_CMD_DVDNAV_SELECT: status = dvdnav_button_activate(nav, pci); if(status == DVDNAV_STATUS_OK) reset = 1; break; case MP_CMD_DVDNAV_MOUSECLICK: /* this is a workaround: in theory the simple dvdnav_lower_button_select()+dvdnav_button_activate() should be enough (and generally it is), but there are cases when the calls to dvdnav_lower_button_select() and friends fail! Hence we have to call dvdnav_mouse_activate(priv->mousex, priv->mousey) with the coodinates saved by mp_dvdnav_update_mouse_pos(). This last call always works well */ status = dvdnav_mouse_activate(nav, pci, priv->mousex, priv->mousey); if(status == DVDNAV_STATUS_OK) reset = 1; break; default: mp_msg(MSGT_CPLAYER, MSGL_V, "Unknown DVDNAV cmd %d\n", cmd); break; } if(status == DVDNAV_STATUS_OK) dvdnav_get_current_highlight(nav, button); return reset; }
int main(int argc, char **argv) { dvdnav_t *dvdnav; uint8_t mem[DVD_VIDEO_LB_LEN]; int finished = 0; int output_fd = 0; int dump = 0, tt_dump = 0; /* open dvdnav handle */ printf("Opening DVD...\n"); if (dvdnav_open(&dvdnav, "/dev/dvd") != DVDNAV_STATUS_OK) { printf("Error on dvdnav_open\n"); return 1; } /* set read ahead cache usage */ if (dvdnav_set_readahead_flag(dvdnav, DVD_READ_CACHE) != DVDNAV_STATUS_OK) { printf("Error on dvdnav_set_readahead_flag: %s\n", dvdnav_err_to_string(dvdnav)); return 2; } /* set the language */ if (dvdnav_menu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || dvdnav_audio_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || dvdnav_spu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK) { printf("Error on setting languages: %s\n", dvdnav_err_to_string(dvdnav)); return 2; } /* set the PGC positioning flag to have position information relatively to the * whole feature instead of just relatively to the current chapter */ if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) { printf("Error on dvdnav_set_PGC_positioning_flag: %s\n", dvdnav_err_to_string(dvdnav)); return 2; } /* the read loop which regularly calls dvdnav_get_next_block * and handles the returned events */ printf("Reading...\n"); while (!finished) { int result, event, len; uint8_t *buf = mem; /* the main reading function */ #if DVD_READ_CACHE result = dvdnav_get_next_cache_block(dvdnav, &buf, &event, &len); #else result = dvdnav_get_next_block(dvdnav, buf, &event, &len); #endif if (result == DVDNAV_STATUS_ERR) { printf("Error getting next block: %s\n", dvdnav_err_to_string(dvdnav)); return 3; } switch (event) { case DVDNAV_BLOCK_OK: /* We have received a regular block of the currently playing MPEG stream. * A real player application would now pass this block through demuxing * and decoding. We simply write it to disc here. */ if (!output_fd) { printf("Opening output...\n"); output_fd = open("libdvdnav.mpg", O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG); if (output_fd == -1) { printf("Error opening output\n"); return 4; } } if (dump || tt_dump) write(output_fd, buf, len); break; case DVDNAV_NOP: /* Nothing to do here. */ break; case DVDNAV_STILL_FRAME: /* We have reached a still frame. A real player application would wait * the amount of time specified by the still's length while still handling * user input to make menus and other interactive stills work. * A length of 0xff means an indefinite still which has to be skipped * indirectly by some user interaction. */ { dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)buf; if (still_event->length < 0xff) printf("Skipping %d seconds of still frame\n", still_event->length); else printf("Skipping indefinite length still frame\n"); dvdnav_still_skip(dvdnav); } break; case DVDNAV_WAIT: /* We have reached a point in DVD playback, where timing is critical. * Player application with internal fifos can introduce state * inconsistencies, because libdvdnav is always the fifo's length * ahead in the stream compared to what the application sees. * Such applications should wait until their fifos are empty * when they receive this type of event. */ printf("Skipping wait condition\n"); dvdnav_wait_skip(dvdnav); break; case DVDNAV_SPU_CLUT_CHANGE: /* Player applications should pass the new colour lookup table to their * SPU decoder */ break; case DVDNAV_SPU_STREAM_CHANGE: /* Player applications should inform their SPU decoder to switch channels */ break; case DVDNAV_AUDIO_STREAM_CHANGE: /* Player applications should inform their audio decoder to switch channels */ break; case DVDNAV_HIGHLIGHT: /* Player applications should inform their overlay engine to highlight the * given button */ { dvdnav_highlight_event_t *highlight_event = (dvdnav_highlight_event_t *)buf; printf("Selected button %d\n", highlight_event->buttonN); } break; case DVDNAV_VTS_CHANGE: /* Some status information like video aspect and video scale permissions do * not change inside a VTS. Therefore this event can be used to query such * information only when necessary and update the decoding/displaying * accordingly. */ break; case DVDNAV_CELL_CHANGE: /* Some status information like the current Title and Part numbers do not * change inside a cell. Therefore this event can be used to query such * information only when necessary and update the decoding/displaying * accordingly. */ { int tt = 0, ptt = 0, pos, len; char input = '\0'; dvdnav_current_title_info(dvdnav, &tt, &ptt); dvdnav_get_position(dvdnav, &pos, &len); printf("Cell change: Title %d, Chapter %d\n", tt, ptt); printf("At position %.0f%% inside the feature\n", 100 * (double)pos / (double)len); dump = 0; if (tt_dump && tt != tt_dump) tt_dump = 0; if (!dump && !tt_dump) { fflush(stdin); while ((input != 'a') && (input != 's') && (input != 'q') && (input != 't')) { printf("(a)ppend cell to output\n(s)kip cell\nappend until end of (t)itle\n(q)uit\n"); scanf("%c", &input); } switch (input) { case 'a': dump = 1; break; case 't': tt_dump = tt; break; case 'q': finished = 1; } } } break; case DVDNAV_NAV_PACKET: /* A NAV packet provides PTS discontinuity information, angle linking information and * button definitions for DVD menus. Angles are handled completely inside libdvdnav. * For the menus to work, the NAV packet information has to be passed to the overlay * engine of the player so that it knows the dimensions of the button areas. */ { pci_t *pci; dsi_t *dsi; /* Applications with fifos should not use these functions to retrieve NAV packets, * they should implement their own NAV handling, because the packet you get from these * functions will already be ahead in the stream which can cause state inconsistencies. * Applications with fifos should therefore pass the NAV packet through the fifo * and decoding pipeline just like any other data. */ pci = dvdnav_get_current_nav_pci(dvdnav); dsi = dvdnav_get_current_nav_dsi(dvdnav); if(pci->hli.hl_gi.btn_ns > 0) { int button; printf("Found %i DVD menu buttons...\n", pci->hli.hl_gi.btn_ns); for (button = 0; button < pci->hli.hl_gi.btn_ns; button++) { btni_t *btni = &(pci->hli.btnit[button]); printf("Button %i top-left @ (%i,%i), bottom-right @ (%i,%i)\n", button + 1, btni->x_start, btni->y_start, btni->x_end, btni->y_end); } button = 0; while ((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { printf("Which button (1 to %i): ", pci->hli.hl_gi.btn_ns); scanf("%i", &button); } printf("Selecting button %i...\n", button); /* This is the point where applications with fifos have to hand in a NAV packet * which has traveled through the fifos. See the notes above. */ dvdnav_button_select_and_activate(dvdnav, pci, button); } } break; case DVDNAV_HOP_CHANNEL: /* This event is issued whenever a non-seamless operation has been executed. * Applications with fifos should drop the fifos content to speed up responsiveness. */ break; case DVDNAV_STOP: /* Playback should end here. */ { finished = 1; } break; default: printf("Unknown event (%i)\n", event); finished = 1; break; } #if DVD_READ_CACHE dvdnav_free_cache_block(dvdnav, buf); #endif } /* destroy dvdnav handle */ if (dvdnav_close(dvdnav) != DVDNAV_STATUS_OK) { printf("Error on dvdnav_close: %s\n", dvdnav_err_to_string(dvdnav)); return 5; } close(output_fd); return 0; }
static int control(stream_t *stream, int cmd, void* arg) { dvdnav_priv_t* priv=stream->priv; int tit, part; switch(cmd) { case STREAM_CTRL_SEEK_TO_CHAPTER: { int chap = *((unsigned int *)arg)+1; if(chap < 1 || dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK) break; if(dvdnav_part_play(priv->dvdnav, tit, chap) != DVDNAV_STATUS_OK) break; return 1; } case STREAM_CTRL_GET_NUM_CHAPTERS: { if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK) break; if(dvdnav_get_number_of_parts(priv->dvdnav, tit, &part) != DVDNAV_STATUS_OK) break; if(!part) break; *((unsigned int *)arg) = part; return 1; } case STREAM_CTRL_GET_CURRENT_CHAPTER: { if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) != DVDNAV_STATUS_OK) break; *((unsigned int *)arg) = part - 1; return 1; } case STREAM_CTRL_GET_TIME_LENGTH: { if(priv->duration) { *((double *)arg) = (double)priv->duration / 1000.0; return 1; } break; } case STREAM_CTRL_GET_ASPECT_RATIO: { uint8_t ar = dvdnav_get_video_aspect(priv->dvdnav); *((double *)arg) = !ar ? 4.0/3.0 : 16.0/9.0; return 1; } case STREAM_CTRL_GET_CURRENT_TIME: { double tm; tm = dvdnav_get_current_time(priv->dvdnav)/90000.0f; if(tm != -1) { *((double *)arg) = tm; return 1; } break; } case STREAM_CTRL_SEEK_TO_TIME: { uint64_t tm = (uint64_t) (*((double*)arg) * 90000); if(dvdnav_time_search(priv->dvdnav, tm) == DVDNAV_STATUS_OK) return 1; break; } } return STREAM_UNSUPPORTED; }
void k9PlayMPEG2::playTitle() { dvdnav_t *dvdnav; uint8_t mem[DVD_VIDEO_LB_LEN]; int finished = 0; int32_t tt = 0,ptt=0; uint32_t pos, lgr; int title=m_title->getnumTitle(); /* open dvdnav handle */ if (dvdnav_open(&dvdnav, m_device,m_dvd) != DVDNAV_STATUS_OK) { setError("ERR:Error on dvdnav_open\n"); return ; } /* set read ahead cache usage */ if (dvdnav_set_readahead_flag(dvdnav, DVD_READ_CACHE) != DVDNAV_STATUS_OK) { setError(QString("ERR:Error on dvdnav_set_readahead_flag: %1\n").arg(dvdnav_err_to_string(dvdnav))); return; } /* set the language */ if (dvdnav_menu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || dvdnav_audio_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK || dvdnav_spu_language_select(dvdnav, DVD_LANGUAGE) != DVDNAV_STATUS_OK) { setError(QString("ERR:Error on setting languages: %1\n").arg(dvdnav_err_to_string(dvdnav))); return ; } /* set the PGC positioning flag to have position information relatively to the * whole feature instead of just relatively to the current chapter */ if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) { setError(QString("ERR:Error on dvdnav_set_PGC_positioning_flag: %1\n").arg(dvdnav_err_to_string(dvdnav))); return ; } int32_t parts; dvdnav_get_number_of_parts(dvdnav , title, &parts); if (m_chapter==0) dvdnav_title_play(dvdnav , title); else dvdnav_part_play(dvdnav , title,m_chapter); /* the read loop which regularly calls dvdnav_get_next_block * and handles the returned events */ while (!finished && !m_stopped && qApp!=NULL) { int result, event, len; uint8_t *buf = mem; if (m_idxLect !=0xFFFFFFFF) { dvdnav_sector_search(dvdnav, m_idxLect,SEEK_SET); m_idxLect=0xFFFFFFFF; } /* the main reading function */ #ifdef DVD_READ_CACHE result = dvdnav_get_next_cache_block(dvdnav, &buf, &event, &len); #else result = dvdnav_get_next_block(dvdnav, buf, &event, &len); #endif if (result == DVDNAV_STATUS_ERR) { setError(QString("ERR:Error getting next block: %1\n").arg(dvdnav_err_to_string(dvdnav))); return; } switch (event) { case DVDNAV_NAV_PACKET: { dvdnav_current_title_info(dvdnav, &tt, &ptt); dvdnav_get_position(dvdnav, &pos, &lgr); if (tt != title) finished=1; if (finished==0 && buf[17]==0xE0) { m_decoder.addData( buf,len); } if (qApp->tryLock()) { emit setPosition( pos); qApp->unlock(); } } break; //removed break --> save case DVDNAV_BLOCK_OK: /* We have received a regular block of the currently playing MPEG stream.*/ m_decoder.addData( buf,len); break; case DVDNAV_NOP: /* Nothing to do here. */ break; case DVDNAV_STILL_FRAME: /* We have reached a still frame. A real player application would wait * the amount of time specified by the still's length while still handling * user input to make menus and other interactive stills work. * A length of 0xff means an indefinite still which has to be skipped * indirectly by some user interaction. */ { dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)buf; dvdnav_still_skip(dvdnav); } break; case DVDNAV_WAIT: /* We have reached a point in DVD playback, where timing is critical. * Player application with internal fifos can introduce state * inconsistencies, because libdvdnav is always the fifo's length * ahead in the stream compared to what the application sees. * Such applications should wait until their fifos are empty * when they receive this type of event. */ dvdnav_wait_skip(dvdnav); break; case DVDNAV_SPU_CLUT_CHANGE: /* Player applications should pass the new colour lookup table to their * SPU decoder */ break; case DVDNAV_SPU_STREAM_CHANGE: /* Player applications should inform their SPU decoder to switch channels */ break; case DVDNAV_AUDIO_STREAM_CHANGE: /* Player applications should inform their audio decoder to switch channels */ break; case DVDNAV_HIGHLIGHT: /* Player applications should inform their overlay engine to highlight the * given button */ { dvdnav_highlight_event_t *highlight_event = (dvdnav_highlight_event_t *)buf; } break; case DVDNAV_VTS_CHANGE: /* Some status information like video aspect and video scale permissions do * not change inside a VTS. Therefore this event can be used to query such * information only when necessary and update the decoding/displaying * accordingly. */ break; case DVDNAV_CELL_CHANGE: // dvdnav_get_position(dvdnav, &pos, &lgr); break; case DVDNAV_HOP_CHANNEL: /* This event is issued whenever a non-seamless operation has been executed. * Applications with fifos should drop the fifos content to speed up responsiveness. */ break; case DVDNAV_STOP: /* Playback should end here. */ { finished = 1; } break; default: finished = 1; break; } #ifdef DVD_READ_CACHE dvdnav_free_cache_block(dvdnav, buf); #endif } m_decoder.setNoData(); /* destroy dvdnav handle */ dvdnav_close(dvdnav); }