X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=blobdiff_plain;f=generate_dvd.cpp;h=371894d41edc23abd7ac34abee8337fd52b64711;hp=eb8fc0498fe0895cde21234810bfa5cc671773b6;hb=HEAD;hpb=2bc553f13070e61f28fb28ec333d9abd710d2b51 diff --git a/generate_dvd.cpp b/generate_dvd.cpp index eb8fc04..371894d 100644 --- a/generate_dvd.cpp +++ b/generate_dvd.cpp @@ -1,6 +1,7 @@ -// Copyright 2005-6 Ben Hutchings . +// Copyright 2005-8 Ben Hutchings . // See the file "COPYING" for licence details. +#include #include #include #include @@ -10,6 +11,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -88,8 +93,8 @@ namespace double menu_duration_seconds(const video::frame_params & params) { return double(menu_duration_frames(params)) - * double(params.rate_numer) - / double(params.rate_denom); + / double(params.rate_numer) + * double(params.rate_denom); } void throw_length_error(const char * limit_type, std::size_t limit) @@ -105,6 +110,17 @@ namespace // domain. This seems to be an oddity of the parser that could be // fixed, but for now we'll have to work with it. const unsigned dvdauthor_anonymous_menus_max = dvd::domain_pgcs_max - 8; + + // The current navigation code packs menu and button number into a + // single register, so the number of menus is limited to + // dvd::reg_s8_button_mult - 1 == 1023. However temp_file_name() + // is limited to 999 numbered files and it seems pointless to + // change it to get another 24. + // If people really need more we could use separate menu and + // button number registers, possibly allowing up to 11900 menus + // (the size of the indirect jump tables might become a problem + // though). + const unsigned menus_max = 999; } dvd_generator::dvd_generator(const video::frame_params & frame_params, @@ -118,8 +134,8 @@ dvd_generator::pgc_ref dvd_generator::add_menu() { pgc_ref next_menu(menu_pgc, menus_.size()); - if (next_menu.index == dvdauthor_anonymous_menus_max) - throw_length_error("number of menus", dvdauthor_anonymous_menus_max); + if (next_menu.index == menus_max) + throw_length_error("number of menus", menus_max); menus_.resize(next_menu.index + 1); return next_menu; @@ -150,12 +166,12 @@ void dvd_generator::generate_menu_vob(unsigned index, std::string background_name( temp_file_name(temp_dir_, "menu-%3d-back.png", 1 + index)); - std::cout << "saving " << background_name << std::endl; + std::cout << "INFO: Saving " << background_name << std::endl; background->save(background_name, "png"); std::string highlights_name( temp_file_name(temp_dir_, "menu-%3d-links.png", 1 + index)); - std::cout << "saving " << highlights_name << std::endl; + std::cout << "INFO: Saving " << highlights_name << std::endl; highlights->save(highlights_name, "png"); std::string spumux_name( @@ -200,11 +216,15 @@ void dvd_generator::generate_menu_vob(unsigned index, } } } + // Pad vertically to even y coordinates since dvdauthor claims + // odd values may result in incorrect display. + // XXX This may cause overlappping where it wasn't previously + // a problem. spumux_file << " " << temp_file_name(temp_dir_, "menu-%3d.mpeg", 1 + index); + << " | spumux -v0 -mdvd " << spumux_name << " > " << output_name; std::string command(command_stream.str()); const char * argv[] = { "/bin/sh", "-c", command.c_str(), 0 }; - std::cout << "running " << command << std::endl; + std::cout << "INFO: Running " << command << std::endl; int command_result; Glib::spawn_sync(".", Glib::ArrayHandle( argv, sizeof(argv)/sizeof(argv[0]), Glib::OWNERSHIP_NONE), Glib::SPAWN_STDOUT_TO_DEV_NULL, - SigC::Slot0(), + sigc::slot(), 0, 0, &command_result); - if (command_result != 0) + struct stat stat_buf; + if (command_result != 0 || stat(output_name.c_str(), &stat_buf) != 0 + || stat_buf.st_size == 0) throw std::runtime_error("spumux pipeline failed"); } @@ -299,257 +304,390 @@ dvd_generator::pgc_ref dvd_generator::add_title(vob_list & content) void dvd_generator::generate(const std::string & output_dir) const { + // This function uses a mixture of 0-based and 1-based numbering, + // due to the differing conventions of the language and the DVD + // format. Variable names ending in "_index" indicate 0-based + // indices and variable names ending in "_num" indicate 1-based + // numbers. + std::string name(temp_file_name(temp_dir_, "videolink.dvdauthor")); std::ofstream file(name.c_str()); + file << "\n"; // We generate code that uses registers in the following way: // - // g0: scratch - // g1: target menu location - // g2: source/return menu location for title - // g3: target chapter number - // - // All locations are divided into two bitfields: the least - // significant 10 bits are a page/menu number and the most - // significant 6 bits are a link/button number, and numbering - // starts at 1, not 0. This is done for compatibility with - // the encoding of the s8 (button) register. - // - static const int button_mult = dvd::reg_s8_button_mult; - static const int menu_mask = button_mult - 1; - static const int button_mask = (1 << dvd::reg_bits) - button_mult; - - file << - "\n" - " \n" - " \n"; - - for (unsigned menu_index = 0; menu_index != menus_.size(); ++menu_index) + // g0: Scratch. + // g1: Target location when jumping between menus. Top 6 bits are + // the button number (like s8) and bottom 10 bits are the menu + // number. This is used for selecting the appropriate button + // when entering a menu, for completing indirect jumps between + // domains, and for jumping to the correct menu after exiting a + // title. This is set to 0 in the pre-routine of the target + // menu. + // g2: Current location in menus. This is used for jumping to the + // correct menu when the player exits a title. + // g3: Target chapter number plus 1 when jumping to a title. + // This is used to jump to the correct chapter and to + // distinguish between indirect jumps to menus and titles. + // This is set to 0 in the pre-routine of the target title. + // g4: Source menu location used to jump to a title. This is + // compared with g2 to determine whether to increment the + // button number if the title is played to the end. + + static const unsigned button_mult = dvd::reg_s8_button_mult; + static const unsigned menu_mask = button_mult - 1; + static const unsigned button_mask = (1U << dvd::reg_bits) - button_mult; + + // Iterate over VMGM and titlesets. For these purposes, we + // consider the VMGM to be titleset 0. + + // We need a titleset for each title, and we may also need titlesets to + // hold extra menus if we have too many for the VMGM. + // Also, we need at least one titleset. + const unsigned titleset_end = std::max( + 1U + std::max(1U, titles_.size()), + (menus_.size() + dvdauthor_anonymous_menus_max - 1) + / dvdauthor_anonymous_menus_max); + + for (unsigned titleset_num = 0; + titleset_num != titleset_end; + ++titleset_num) { - const menu & this_menu = menus_[menu_index]; - - if (menu_index == 0) + const char * const outer_element_name = + titleset_num == 0 ? "vmgm" : "titleset"; + const bool have_real_title = + titleset_num != 0 && titleset_num <= titles_.size(); + const bool have_real_menus = + titleset_num * dvdauthor_anonymous_menus_max < menus_.size(); + + file << " <" << outer_element_name << ">\n" << + " \n" + "