- command_stream << "pngtopnm "
- << background_temp_->get_name()
- << " | ppmtoy4m -v0 -n1 -F"
- << frame_params_.rate_numer
- << ":" << frame_params_.rate_denom
- << " -A" << frame_params_.pixel_ratio_width
- << ":" << frame_params_.pixel_ratio_height
- << (" -Ip -S420_mpeg2"
- " | mpeg2enc -v0 -f8 -a2 -o/dev/stdout"
- " | mplex -v0 -f8 -o/dev/stdout /dev/stdin"
- " | spumux -v0 -mdvd ")
- << state->spumux_temp.get_name()
- << " > " << vob_temp->get_name();
- std::string command(command_stream.str());
- const char * argv[] = {
- "/bin/sh", "-c", command.c_str(), 0
- };
- std::cout << "running " << argv[2] << std::endl;
- int command_result;
- Glib::spawn_sync(".",
- Glib::ArrayHandle<std::string>(
- argv, sizeof(argv)/sizeof(argv[0]),
- Glib::OWNERSHIP_NONE),
- Glib::SPAWN_STDOUT_TO_DEV_NULL,
- SigC::Slot0<void>(),
- 0, 0,
- &command_result);
- if (command_result != 0)
- throw std::runtime_error("spumux pipeline failed");
-
- page_temp_files_.push_back(vob_temp);
- }
- }
-
- void generate_page_dispatch(std::ostream &, int indent,
- int first_page, int last_page);
-
- void WebDvdWindow::generate_dvd()
- {
- temp_file temp("webdvd-dvdauthor-");
- temp.close();
- std::ofstream file(temp.get_name().c_str());
-
- // We generate code that uses registers in the following way:
- //
- // g0: link destination (when jumping to menu 1), then scratch
- // g1: current location
- // g2-g11: location history (g2 = most recent)
- // g12: location that last linked to a video
- //
- // 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. This is
- // chosen for compatibility with the encoding of the s8
- // (button) register.
- //
- static const int link_mult = dvd::reg_s8_button_mult;
- static const int page_mask = link_mult - 1;
- static const int link_mask = (1 << dvd::reg_bits) - link_mult;
-
- file <<
- "<dvdauthor>\n"
- " <vmgm>\n"
- " <menus>\n";
-
- for (std::size_t page_num = 1;
- page_num <= page_links_.size();
- ++page_num)
- {
- std::vector<std::string> & page_links =
- page_links_[page_num - 1];
-
- if (page_num == 1)
- {
- // This is the first page (root menu) which needs to
- // include initialisation and dispatch code.
-
- file <<
- " <pgc entry='title'>\n"
- " <pre>\n"
- // Has the location been set yet?
- " if (g1 eq 0)\n"
- " {\n"
- // Initialise the current location to first link on
- // this page.
- " g1 = " << 1 * link_mult + 1 << ";\n"
- " }\n"
- " else\n"
- " {\n"
- // Has the user selected a link?
- " if (g0 ne 0)\n"
- " {\n"
- // First update the history.
- // Does link go to the last page in the history?
- " if (((g0 ^ g2) & " << page_mask
- << ") == 0)\n"
- // It does; we treat this as going back and pop the old
- // location off the history stack into the current
- // location. Clear the free stack slot.
- " {\n"
- " g1 = g2; g2 = g3; g3 = g4; g4 = g5;\n"
- " g5 = g6; g6 = g7; g7 = g8; g8 = g9;\n"
- " g9 = g10; g10 = g11; g11 = 0;\n"
- " }\n"
- " else\n"
- // Link goes to some other page, so push current
- // location onto the history stack and set the current
- // location to be exactly the target location.
- " {\n"
- " g11 = g10; g10 = g9; g9 = g8; g8 = g7;\n"
- " g7 = g6; g6 = g5; g5 = g4; g4 = g3;\n"
- " g3 = g2; g2 = g1; g1 = g0;\n"
- " }\n"
- " }\n"
- // Find the target page number.
- " g0 = g1 & " << page_mask << ";\n";
- // There seems to be no way to perform a computed jump,
- // so we generate all possible jumps and a binary search
- // to select the correct one.
- generate_page_dispatch(file, 12, 1, page_links_.size());
- file <<
- " }\n";
- }
- else // page_num != 1
- {
- file <<
- " <pgc>\n"
- " <pre>\n";
- }
-
- file <<
- // Clear link indicator and highlight the
- // appropriate link/button.
- " g0 = 0; s8 = g1 & " << link_mask << ";\n"
- " </pre>\n"
- " <vob file='"
- << page_temp_files_[page_num - 1]->get_name() << "'/>\n";
-
- for (std::size_t link_num = 1;
- link_num <= page_links.size();
- ++link_num)
- {
- file <<
- " <button>"
- // Update current location.
- " g1 = " << link_num * link_mult + page_num << ";";
-
- // Jump to appropriate resource.
- const ResourceEntry & resource_loc =
- resource_map_[page_links[link_num - 1]];
- if (resource_loc.first == page_resource)
- file <<
- " g0 = " << 1 * link_mult + resource_loc.second << ";"
- " jump menu 1;";
- else if (resource_loc.first == video_resource)
- file << " jump title " << resource_loc.second << ";";
-
- file << " </button>\n";
- }
-
- file << " </pgc>\n";
- }
-
- file <<
- " </menus>\n"
- " </vmgm>\n";
-
- // Generate a titleset for each video. This appears to make
- // jumping to titles a whole lot simpler.
- for (std::size_t video_num = 1;
- video_num <= video_paths_.size();
- ++video_num)
- {
- file <<
- " <titleset>\n"
- // Generate a dummy menu so that the menu button on the
- // remote control will work.
- " <menus>\n"
- " <pgc entry='root'>\n"
- " <pre> jump vmgm menu; </pre>\n"
- " </pgc>\n"
- " </menus>\n"
- " <titles>\n"
- " <pgc>\n"
- // Record calling page/menu.
- " <pre> g12 = g1; </pre>\n";
-
- // Write a reference to a linked VOB file, or the contents
- // of a linked VOB list file.
- const std::string & video_path = video_paths_[video_num - 1];
- if (video_path.compare(video_path.size() - 4, 4, ".vob") == 0)