1 // Copyright 2005 Ben Hutchings <ben@decadentplace.org.uk>.
2 // See the file "COPYING" for licence details.
18 #include <boost/shared_ptr.hpp>
20 #include <gdkmm/pixbuf.h>
21 #include <glibmm/convert.h>
22 #include <glibmm/spawn.h>
23 #include <gtkmm/main.h>
24 #include <gtkmm/window.h>
26 #include <imglib2/ImageErrors.h>
27 #include <nsGUIEvent.h>
28 #include <nsIBoxObject.h>
29 #include <nsIContent.h>
30 #include <nsIDocShell.h>
31 #include <nsIDOMAbstractView.h>
32 #include <nsIDOMDocumentEvent.h>
33 #include <nsIDOMDocumentView.h>
34 #include <nsIDOMElement.h>
35 #include <nsIDOMEventTarget.h>
36 #include <nsIDOMHTMLDocument.h>
37 #include <nsIDOMMouseEvent.h>
38 #include <nsIDOMNSDocument.h>
39 #include <nsIDOMWindow.h>
40 #include <nsIEventStateManager.h>
41 #include <nsIInterfaceRequestorUtils.h>
42 #include <nsIURI.h> // required before nsILink.h
44 #include <nsIPresContext.h>
45 #include <nsIPresShell.h>
46 #include <nsIWebBrowser.h>
49 #include "browserwidget.hpp"
50 #include "childiterator.hpp"
52 #include "framebuffer.hpp"
53 #include "linkiterator.hpp"
54 #include "pixbufs.hpp"
55 #include "stylesheets.hpp"
56 #include "temp_file.hpp"
58 #include "xpcom_support.hpp"
60 using xpcom_support::check;
66 int left, top; // inclusive
67 int right, bottom; // exclusive
69 rectangle operator|=(const rectangle & other)
73 // use current extents unchanged
82 // find rectangle enclosing both extents
83 left = std::min(left, other.left);
84 top = std::min(top, other.top);
85 right = std::max(right, other.right);
86 bottom = std::max(bottom, other.bottom);
92 rectangle operator&=(const rectangle & other)
94 // find rectangle enclosed in both extents
95 left = std::max(left, other.left);
96 top = std::max(top, other.top);
97 right = std::max(left, std::min(right, other.right));
98 bottom = std::max(top, std::min(bottom, other.bottom));
104 return left == right || bottom == top;
108 rectangle get_elem_rect(nsIDOMNSDocument * ns_doc,
109 nsIDOMElement * elem)
113 // Start with this element's bounding box
114 nsCOMPtr<nsIBoxObject> box;
115 check(ns_doc->GetBoxObjectFor(elem, getter_AddRefs(box)));
117 check(box->GetScreenX(&result.left));
118 check(box->GetScreenY(&result.top));
119 check(box->GetWidth(&width));
120 check(box->GetHeight(&height));
121 result.right = result.left + width;
122 result.bottom = result.top + height;
124 // Merge bounding boxes of all child elements
125 for (ChildIterator it = ChildIterator(elem), end; it != end; ++it)
127 nsCOMPtr<nsIDOMNode> child_node(*it);
129 if (check(child_node->GetNodeType(&child_type)),
130 child_type == nsIDOMNode::ELEMENT_NODE)
132 nsCOMPtr<nsIDOMElement> child_elem(
133 do_QueryInterface(child_node));
134 result |= get_elem_rect(ns_doc, child_elem);
141 class WebDvdWindow : public Gtk::Window
145 const video::frame_params & frame_params,
146 const std::string & main_page_uri,
147 const std::string & output_dir);
150 void add_page(const std::string & uri);
151 void add_video(const std::string & uri);
152 void load_next_page();
153 void on_net_state_change(const char * uri, gint flags, guint status);
155 void save_screenshot();
156 void process_links(nsIPresShell * pres_shell,
157 nsIPresContext * pres_context,
158 nsIDOMWindow * dom_window);
161 enum ResourceType { page_resource, video_resource };
162 typedef std::pair<ResourceType, int> ResourceEntry;
163 video::frame_params frame_params_;
164 std::string output_dir_;
165 BrowserWidget browser_widget_;
166 nsCOMPtr<nsIStyleSheet> stylesheet_;
167 std::queue<std::string> page_queue_;
168 std::map<std::string, ResourceEntry> resource_map_;
169 std::vector<std::vector<std::string> > page_links_;
170 std::vector<std::string> video_paths_;
171 bool pending_window_update_;
172 int pending_req_count_;
173 std::auto_ptr<temp_file> background_temp_;
175 std::auto_ptr<page_state> page_state_;
176 std::vector<boost::shared_ptr<temp_file> > page_temp_files_;
179 WebDvdWindow::WebDvdWindow(
180 const video::frame_params & frame_params,
181 const std::string & main_page_uri,
182 const std::string & output_dir)
183 : frame_params_(frame_params),
184 output_dir_(output_dir),
185 stylesheet_(load_css("file://" WEBDVD_LIB_DIR "/webdvd.css")),
186 pending_window_update_(false),
187 pending_req_count_(0)
189 set_size_request(frame_params_.width, frame_params_.height);
190 set_resizable(false);
192 add(browser_widget_);
193 browser_widget_.show();
194 browser_widget_.signal_net_state().connect(
195 SigC::slot(*this, &WebDvdWindow::on_net_state_change));
197 add_page(main_page_uri);
201 void WebDvdWindow::add_page(const std::string & uri)
203 if (resource_map_.insert(
204 std::make_pair(uri, ResourceEntry(page_resource, 0)))
207 page_queue_.push(uri);
211 void WebDvdWindow::add_video(const std::string & uri)
213 if (resource_map_.insert(
214 std::make_pair(uri, ResourceEntry(video_resource,
215 video_paths_.size() + 1)))
218 // FIXME: Should accept some slightly different URI prefixes
219 // (e.g. file://localhost/) and decode any URI-escaped
220 // characters in the path.
221 assert(uri.compare(0, 8, "file:///") == 0);
222 video_paths_.push_back(uri.substr(7));
226 void WebDvdWindow::load_next_page()
228 assert(!page_queue_.empty());
229 const std::string & uri = page_queue_.front();
230 std::cout << "loading " << uri << std::endl;
232 std::size_t page_count = page_links_.size();
233 resource_map_[uri].second = ++page_count;
234 page_links_.resize(page_count);
236 pending_window_update_ = true;
237 browser_widget_.load_uri(uri);
240 void WebDvdWindow::on_net_state_change(const char * uri,
241 gint flags, guint status)
243 if (flags & GTK_MOZ_EMBED_FLAG_IS_REQUEST)
245 if (flags & GTK_MOZ_EMBED_FLAG_START)
246 ++pending_req_count_;
248 if (flags & GTK_MOZ_EMBED_FLAG_STOP)
250 assert(pending_req_count_ != 0);
251 --pending_req_count_;
255 if (flags & GTK_MOZ_EMBED_FLAG_STOP
256 && flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW)
258 // Check whether the load was successful, ignoring this
260 if (status != NS_IMAGELIB_ERROR_LOAD_ABORTED)
263 pending_window_update_ = false;
266 if (pending_req_count_ == 0 && !pending_window_update_)
273 catch (std::exception & e)
275 std::cerr << "Fatal error";
276 if (!page_queue_.empty())
277 std::cerr << " while processing <" << page_queue_.front()
279 std::cerr << ": " << e.what() << "\n";
285 bool WebDvdWindow::process_page()
287 assert(!page_queue_.empty());
289 nsCOMPtr<nsIWebBrowser> browser(browser_widget_.get_browser());
290 nsCOMPtr<nsIDocShell> doc_shell(do_GetInterface(browser));
292 nsCOMPtr<nsIPresShell> pres_shell;
293 check(doc_shell->GetPresShell(getter_AddRefs(pres_shell)));
294 nsCOMPtr<nsIPresContext> pres_context;
295 check(doc_shell->GetPresContext(getter_AddRefs(pres_context)));
296 nsCOMPtr<nsIDOMWindow> dom_window;
297 check(browser->GetContentDOMWindow(getter_AddRefs(dom_window)));
299 if (output_dir_.empty())
301 // In preview mode, just apply the stylesheet and let the
302 // user select links.
303 apply_style_sheet(stylesheet_, pres_shell);
307 // If we haven't already started work on this page, apply
308 // the stylesheet and save a screenshot of its normal
310 if (!page_state_.get())
312 apply_style_sheet(stylesheet_, pres_shell);
316 // Start or continue processing links.
317 process_links(pres_shell, pres_context, dom_window);
319 // If we've finished work on the links, move on to the
320 // next page, if any, or else generate the DVD filesystem.
321 if (!page_state_.get())
324 if (page_queue_.empty())
339 void WebDvdWindow::save_screenshot()
341 Glib::RefPtr<Gdk::Window> window(get_window());
343 window->process_updates(true);
345 background_temp_.reset(new temp_file("webdvd-back-"));
346 background_temp_->close();
347 std::cout << "saving " << background_temp_->get_name() << std::endl;
348 Gdk::Pixbuf::create(Glib::RefPtr<Gdk::Drawable>(window),
349 window->get_colormap(),
351 frame_params_.width, frame_params_.height)
352 ->save(background_temp_->get_name(), "png");
355 struct WebDvdWindow::page_state
357 page_state(nsIDOMDocument * doc, int width, int height)
358 : diff_pixbuf(Gdk::Pixbuf::create(
360 true, 8, // has_alpha, bits_per_sample
362 spumux_temp("webdvd-spumux-"),
363 links_temp("webdvd-links-"),
372 Glib::RefPtr<Gdk::Pixbuf> diff_pixbuf;
374 temp_file spumux_temp;
375 std::ofstream spumux_file;
377 temp_file links_temp;
380 LinkIterator links_it, links_end;
384 Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf;
387 void WebDvdWindow::process_links(nsIPresShell * pres_shell,
388 nsIPresContext * pres_context,
389 nsIDOMWindow * dom_window)
391 Glib::RefPtr<Gdk::Window> window(get_window());
394 nsCOMPtr<nsIDOMDocument> basic_doc;
395 check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
396 nsCOMPtr<nsIDOMNSDocument> ns_doc(do_QueryInterface(basic_doc));
398 nsCOMPtr<nsIEventStateManager> event_state_man(
399 pres_context->EventStateManager()); // does not AddRef
400 assert(event_state_man);
401 nsCOMPtr<nsIDOMDocumentEvent> event_factory(
402 do_QueryInterface(basic_doc));
403 assert(event_factory);
404 nsCOMPtr<nsIDOMDocumentView> doc_view(do_QueryInterface(basic_doc));
406 nsCOMPtr<nsIDOMAbstractView> view;
407 check(doc_view->GetDefaultView(getter_AddRefs(view)));
409 // Set up or recover our iteration state.
410 std::auto_ptr<page_state> state(page_state_);
415 basic_doc, frame_params_.width, frame_params_.height));
417 state->spumux_file.open(state->spumux_temp.get_name().c_str());
418 state->spumux_file <<
421 " <spu force='yes' start='00:00:00.00'\n"
422 " highlight='" << state->links_temp.get_name() << "'\n"
423 " select='" << state->links_temp.get_name() << "'>\n";
426 rectangle window_rect = {
427 0, 0, frame_params_.width, frame_params_.height
430 for (/* no initialisation */;
431 state->links_it != state->links_end;
434 nsCOMPtr<nsIDOMNode> node(*state->links_it);
436 // Find the link URI.
437 nsCOMPtr<nsILink> link(do_QueryInterface(node));
439 nsCOMPtr<nsIURI> uri;
440 check(link->GetHrefURI(getter_AddRefs(uri)));
441 std::string uri_string;
443 nsCString uri_ns_string;
444 check(uri->GetSpec(uri_ns_string));
445 uri_string.assign(uri_ns_string.BeginReading(),
446 uri_ns_string.EndReading());
448 std::string uri_sans_fragment(uri_string, 0, uri_string.find('#'));
450 // Is this a new link?
451 if (!state->link_changing)
453 // Find a rectangle enclosing the link and clip it to the
455 nsCOMPtr<nsIDOMElement> elem(do_QueryInterface(node));
457 state->link_rect = get_elem_rect(ns_doc, elem);
458 state->link_rect &= window_rect;
460 if (state->link_rect.empty())
462 std::cerr << "Ignoring invisible link to "
463 << uri_string << "\n";
469 if (state->link_num >= dvd::menu_buttons_max)
471 if (state->link_num == dvd::menu_buttons_max)
472 std::cerr << "No more than " << dvd::menu_buttons_max
473 << " buttons can be placed on a page\n";
474 std::cerr << "Ignoring link to " << uri_string << "\n";
478 // Check whether this is a link to a video or a page then
479 // add it to the known resources if not already seen.
481 check(uri->GetPath(path));
482 // FIXME: This is a bit of a hack. Perhaps we could decide
483 // later based on the MIME type determined by Mozilla?
484 if (path.Length() > 4
485 && std::strcmp(path.EndReading() - 4, ".vob") == 0)
488 check(uri->SchemeIs("file", &is_file));
491 std::cerr << "Links to video must use the file:"
495 add_video(uri_sans_fragment);
499 add_page(uri_sans_fragment);
502 nsCOMPtr<nsIContent> content(do_QueryInterface(node));
504 nsCOMPtr<nsIDOMEventTarget> event_target(
505 do_QueryInterface(node));
506 assert(event_target);
508 state->norm_pixbuf = Gdk::Pixbuf::create(
509 Glib::RefPtr<Gdk::Drawable>(window),
510 window->get_colormap(),
511 state->link_rect.left,
512 state->link_rect.top,
515 state->link_rect.right - state->link_rect.left,
516 state->link_rect.bottom - state->link_rect.top);
518 nsCOMPtr<nsIDOMEvent> event;
519 check(event_factory->CreateEvent(
520 NS_ConvertASCIItoUTF16("MouseEvents"),
521 getter_AddRefs(event)));
522 nsCOMPtr<nsIDOMMouseEvent> mouse_event(
523 do_QueryInterface(event));
525 check(mouse_event->InitMouseEvent(
526 NS_ConvertASCIItoUTF16("mouseover"),
530 0, // detail: mouse click count
531 state->link_rect.left, // screenX
532 state->link_rect.top, // screenY
533 state->link_rect.left, // clientX
534 state->link_rect.top, // clientY
535 false, false, false, false, // qualifiers
536 0, // button: left (or primary)
537 0)); // related target
539 check(event_target->DispatchEvent(mouse_event,
541 check(event_state_man->SetContentState(content,
542 NS_EVENT_STATE_HOVER));
544 pres_shell->FlushPendingNotifications(true);
546 // We may have to exit and wait for image loading
547 // to complete, at which point we will be called
549 if (pending_req_count_ > 0)
551 state->link_changing = true;
557 window->process_updates(true);
559 Glib::RefPtr<Gdk::Pixbuf> changed_pixbuf(
561 Glib::RefPtr<Gdk::Drawable>(window),
562 window->get_colormap(),
563 state->link_rect.left,
564 state->link_rect.top,
567 state->link_rect.right - state->link_rect.left,
568 state->link_rect.bottom - state->link_rect.top));
573 state->link_rect.left,
574 state->link_rect.top,
575 state->link_rect.right - state->link_rect.left,
576 state->link_rect.bottom - state->link_rect.top);
578 state->spumux_file <<
579 " <button x0='" << state->link_rect.left << "'"
580 " y0='" << state->link_rect.top << "'"
581 " x1='" << state->link_rect.right - 1 << "'"
582 " y1='" << state->link_rect.bottom - 1 << "'/>\n";
584 // Add to the page's links, ignoring any fragment (for now).
585 page_links_.back().push_back(uri_sans_fragment);
588 quantise_rgba_pixbuf(state->diff_pixbuf, dvd::button_n_colours);
590 std::cout << "saving " << state->links_temp.get_name()
592 state->diff_pixbuf->save(state->links_temp.get_name(), "png");
594 state->spumux_file <<
599 state->spumux_file.close();
601 // TODO: if (!state->spumux_file) throw ...
604 boost::shared_ptr<temp_file> vob_temp(
605 new temp_file("webdvd-vob-"));
606 std::ostringstream command_stream;
607 command_stream << "pngtopnm "
608 << background_temp_->get_name()
609 << " | ppmtoy4m -v0 -n1 -F"
610 << frame_params_.rate_numer
611 << ":" << frame_params_.rate_denom
612 << " -A" << frame_params_.pixel_ratio_width
613 << ":" << frame_params_.pixel_ratio_height
614 << (" -Ip -S420_mpeg2"
615 " | mpeg2enc -v0 -f8 -a2 -o/dev/stdout"
616 " | mplex -v0 -f8 -o/dev/stdout /dev/stdin"
617 " | spumux -v0 -mdvd ")
618 << state->spumux_temp.get_name()
619 << " > " << vob_temp->get_name();
620 std::string command(command_stream.str());
621 const char * argv[] = {
622 "/bin/sh", "-c", command.c_str(), 0
624 std::cout << "running " << argv[2] << std::endl;
626 Glib::spawn_sync(".",
627 Glib::ArrayHandle<std::string>(
628 argv, sizeof(argv)/sizeof(argv[0]),
629 Glib::OWNERSHIP_NONE),
630 Glib::SPAWN_STDOUT_TO_DEV_NULL,
634 if (command_result != 0)
635 throw std::runtime_error("spumux pipeline failed");
637 page_temp_files_.push_back(vob_temp);
641 void generate_page_dispatch(std::ostream &, int indent,
642 int first_page, int last_page);
644 void WebDvdWindow::generate_dvd()
646 temp_file temp("webdvd-dvdauthor-");
648 std::ofstream file(temp.get_name().c_str());
650 // We generate code that uses registers in the following way:
652 // g0: link destination (when jumping to menu 1), then scratch
653 // g1: current location
654 // g2-g11: location history (g2 = most recent)
655 // g12: location that last linked to a video
657 // All locations are divided into two bitfields: the least
658 // significant 10 bits are a page/menu number and the most
659 // significant 6 bits are a link/button number. This is
660 // chosen for compatibility with the encoding of the s8
661 // (button) register.
663 static const int link_mult = dvd::reg_s8_button_mult;
664 static const int page_mask = link_mult - 1;
665 static const int link_mask = (1 << dvd::reg_bits) - link_mult;
672 for (std::size_t page_num = 1;
673 page_num <= page_links_.size();
676 std::vector<std::string> & page_links =
677 page_links_[page_num - 1];
681 // This is the first page (root menu) which needs to
682 // include initialisation and dispatch code.
685 " <pgc entry='title'>\n"
687 // Has the location been set yet?
690 // Initialise the current location to first link on
692 " g1 = " << 1 * link_mult + 1 << ";\n"
696 // Has the user selected a link?
699 // First update the history.
700 // Does link go to the last page in the history?
701 " if (((g0 ^ g2) & " << page_mask
703 // It does; we treat this as going back and pop the old
704 // location off the history stack into the current
705 // location. Clear the free stack slot.
707 " g1 = g2; g2 = g3; g3 = g4; g4 = g5;\n"
708 " g5 = g6; g6 = g7; g7 = g8; g8 = g9;\n"
709 " g9 = g10; g10 = g11; g11 = 0;\n"
712 // Link goes to some other page, so push current
713 // location onto the history stack and set the current
714 // location to be exactly the target location.
716 " g11 = g10; g10 = g9; g9 = g8; g8 = g7;\n"
717 " g7 = g6; g6 = g5; g5 = g4; g4 = g3;\n"
718 " g3 = g2; g2 = g1; g1 = g0;\n"
721 // Find the target page number.
722 " g0 = g1 & " << page_mask << ";\n";
723 // There seems to be no way to perform a computed jump,
724 // so we generate all possible jumps and a binary search
725 // to select the correct one.
726 generate_page_dispatch(file, 12, 1, page_links_.size());
730 else // page_num != 1
738 // Clear link indicator and highlight the
739 // appropriate link/button.
740 " g0 = 0; s8 = g1 & " << link_mask << ";\n"
743 << page_temp_files_[page_num - 1]->get_name() << "'/>\n";
745 for (std::size_t link_num = 1;
746 link_num <= page_links.size();
751 // Update current location.
752 " g1 = " << link_num * link_mult + page_num << ";";
754 // Jump to appropriate resource.
755 const ResourceEntry & resource_loc =
756 resource_map_[page_links[link_num - 1]];
757 if (resource_loc.first == page_resource)
759 " g0 = " << 1 * link_mult + resource_loc.second << ";"
761 else if (resource_loc.first == video_resource)
762 file << " jump title " << resource_loc.second << ";";
764 file << " </button>\n";
774 // Generate a titleset for each video. This appears to make
775 // jumping to titles a whole lot simpler.
776 for (std::size_t video_num = 1;
777 video_num <= video_paths_.size();
782 // Generate a dummy menu so that the menu button on the
783 // remote control will work.
785 " <pgc entry='root'>\n"
786 " <pre> jump vmgm menu; </pre>\n"
791 // Record calling page/menu.
792 " <pre> g12 = g1; </pre>\n"
793 // FIXME: Should XML-escape the path
794 " <vob file='" << video_paths_[video_num - 1]
796 // If page/menu location has not been changed during the
797 // video, change the location to be the following
798 // link/button when returning to it. In any case,
799 // return to a page/menu.
800 " <post> if (g1 eq g12) g1 = g1 + " << link_mult
801 << "; call menu; </post>\n"
813 const char * argv[] = {
815 "-o", output_dir_.c_str(),
816 "-x", temp.get_name().c_str(),
820 Glib::spawn_sync(".",
821 Glib::ArrayHandle<std::string>(
822 argv, sizeof(argv)/sizeof(argv[0]),
823 Glib::OWNERSHIP_NONE),
824 Glib::SPAWN_SEARCH_PATH
825 | Glib::SPAWN_STDOUT_TO_DEV_NULL,
829 if (command_result != 0)
830 throw std::runtime_error("dvdauthor failed");
834 void generate_page_dispatch(std::ostream & file, int indent,
835 int first_page, int last_page)
837 if (first_page == 1 && last_page == 1)
839 // The dispatch code is *on* page 1 so we must not dispatch to
840 // page 1 since that would cause an infinite loop. This case
841 // should be unreachable if there is more than one page due
842 // to the following case.
844 else if (first_page == 1 && last_page == 2)
846 // dvdauthor doesn't allow empty blocks or null statements so
847 // when selecting between pages 1 and 2 we don't use an "else"
848 // part. We must use braces so that a following "else" will
849 // match the right "if".
850 file << std::setw(indent) << "" << "{\n"
851 << std::setw(indent) << "" << "if (g0 eq 2)\n"
852 << std::setw(indent + 2) << "" << "jump menu 2;\n"
853 << std::setw(indent) << "" << "}\n";
855 else if (first_page == last_page)
857 file << std::setw(indent) << ""
858 << "jump menu " << first_page << ";\n";
862 int middle = (first_page + last_page) / 2;
863 file << std::setw(indent) << "" << "if (g0 le " << middle << ")\n";
864 generate_page_dispatch(file, indent + 2, first_page, middle);
865 file << std::setw(indent) << "" << "else\n";
866 generate_page_dispatch(file, indent + 2, middle + 1, last_page);
870 const video::frame_params & lookup_frame_params(const char * str)
873 static const struct { const char * str; bool is_ntsc; }
879 // For DVD purposes, SECAM can be treated identically to PAL.
883 for (std::size_t i = 0;
884 i != sizeof(known_strings)/sizeof(known_strings[0]);
886 if (std::strcmp(str, known_strings[i].str) == 0)
887 return known_strings[i].is_ntsc ?
888 video::ntsc_params : video::pal_params;
889 throw std::runtime_error(
890 std::string("Invalid video standard: ").append(str));
893 void print_usage(std::ostream & stream, const char * command_name)
895 stream << "Usage: " << command_name
896 << (" [gtk-options] [--video-std std-name]"
897 " [--preview] menu-url [output-dir]\n");
902 int main(int argc, char ** argv)
906 video::frame_params frame_params = video::pal_params;
907 bool preview_mode = false;
909 // Do initial argument parsing. We have to do this before
910 // letting Gtk parse the arguments since we may need to spawn
915 if (std::strcmp(argv[argi], "--") == 0)
919 else if (std::strcmp(argv[argi], "--help") == 0)
921 print_usage(std::cout, argv[0]);
924 else if (std::strcmp(argv[argi], "--preview") == 0)
929 else if (std::strcmp(argv[argi], "--video-std") == 0)
931 if (argi + 1 == argc)
933 std::cerr << "Missing argument to --video-std\n";
934 print_usage(std::cerr, argv[0]);
937 frame_params = lookup_frame_params(argv[argi + 1]);
946 std::auto_ptr<FrameBuffer> fb;
949 // Spawn Xvfb and set env variables so that Xlib will use it
950 // Use 8 bits each for RGB components, which should translate into
951 // "enough" bits for YUV components.
952 fb.reset(new FrameBuffer(frame_params.width, frame_params.height,
954 setenv("XAUTHORITY", fb->get_x_authority().c_str(), true);
955 setenv("DISPLAY", fb->get_x_display().c_str(), true);
959 Gtk::Main kit(argc, argv);
961 // Complete argument parsing with Gtk's options out of the way.
965 if (std::strcmp(argv[argi], "--") == 0)
970 else if (std::strcmp(argv[argi], "--preview") == 0)
974 else if (std::strcmp(argv[argi], "--video-std") == 0)
978 else if (argv[argi][0] == '-')
980 std::cerr << "Invalid option: " << argv[argi] << "\n";
981 print_usage(std::cerr, argv[0]);
989 if (argc - argi != (preview_mode ? 1 : 2))
991 print_usage(std::cerr, argv[0]);
995 // Initialise Mozilla
996 BrowserWidget::init();
998 WebDvdWindow window(frame_params,
1000 preview_mode ? "" : argv[argi + 1]);
1001 Gtk::Main::run(window);
1003 catch (std::exception & e)
1005 std::cerr << "Fatal error: " << e.what() << "\n";
1006 return EXIT_FAILURE;
1009 return EXIT_SUCCESS;