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 nsCOMPtr<nsIBoxObject> box;
114 check(ns_doc->GetBoxObjectFor(elem, getter_AddRefs(box)));
116 check(box->GetScreenX(&result.left));
117 check(box->GetScreenY(&result.top));
118 check(box->GetWidth(&width));
119 check(box->GetHeight(&height));
120 result.right = result.left + width;
121 result.bottom = result.top + height;
123 for (ChildIterator it = ChildIterator(elem), end; it != end; ++it)
125 nsCOMPtr<nsIDOMNode> child_node(*it);
127 if (check(child_node->GetNodeType(&child_type)),
128 child_type == nsIDOMNode::ELEMENT_NODE)
130 nsCOMPtr<nsIDOMElement> child_elem(
131 do_QueryInterface(child_node));
132 result |= get_elem_rect(ns_doc, child_elem);
139 class WebDvdWindow : public Gtk::Window
143 const video::frame_params & frame_params,
144 const std::string & main_page_uri,
145 const std::string & output_dir);
148 void add_page(const std::string & uri);
149 void add_video(const std::string & uri);
150 void load_next_page();
151 void on_net_state_change(const char * uri, gint flags, guint status);
152 void save_screenshot();
153 void process_links(nsIPresShell * pres_shell,
154 nsIPresContext * pres_context,
155 nsIDOMWindow * dom_window);
158 enum ResourceType { page_resource, video_resource };
159 typedef std::pair<ResourceType, int> ResourceEntry;
160 video::frame_params frame_params_;
161 std::string output_dir_;
162 BrowserWidget browser_widget_;
163 nsCOMPtr<nsIStyleSheet> stylesheet_;
164 std::queue<std::string> page_queue_;
165 std::map<std::string, ResourceEntry> resource_map_;
166 std::vector<std::vector<std::string> > page_links_;
167 std::vector<std::string> video_paths_;
169 int pending_req_count_;
170 std::auto_ptr<temp_file> background_temp_;
172 std::auto_ptr<link_state> link_state_;
173 std::vector<boost::shared_ptr<temp_file> > page_temp_files_;
176 WebDvdWindow::WebDvdWindow(
177 const video::frame_params & frame_params,
178 const std::string & main_page_uri,
179 const std::string & output_dir)
180 : frame_params_(frame_params),
181 output_dir_(output_dir),
182 stylesheet_(load_css("file://" WEBDVD_LIB_DIR "/webdvd.css")),
184 pending_req_count_(0)
186 set_default_size(frame_params_.width, frame_params_.height);
187 add(browser_widget_);
188 browser_widget_.show();
189 browser_widget_.signal_net_state().connect(
190 SigC::slot(*this, &WebDvdWindow::on_net_state_change));
192 add_page(main_page_uri);
196 void WebDvdWindow::add_page(const std::string & uri)
198 if (resource_map_.insert(
199 std::make_pair(uri, ResourceEntry(page_resource, 0)))
202 page_queue_.push(uri);
206 void WebDvdWindow::add_video(const std::string & uri)
208 if (resource_map_.insert(
209 std::make_pair(uri, ResourceEntry(video_resource,
210 video_paths_.size() + 1)))
213 // FIXME: Should accept some slightly different URI prefixes
214 // (e.g. file://localhost/) and decode any URI-escaped
215 // characters in the path.
216 assert(uri.compare(0, 8, "file:///") == 0);
217 video_paths_.push_back(uri.substr(7));
221 void WebDvdWindow::load_next_page()
225 assert(!page_queue_.empty());
226 const std::string & uri = page_queue_.front();
227 std::cout << "loading " << uri << std::endl;
229 std::size_t page_count = page_links_.size();
230 resource_map_[uri].second = ++page_count;
231 page_links_.resize(page_count);
232 browser_widget_.load_uri(uri);
235 void WebDvdWindow::on_net_state_change(const char * uri,
236 gint flags, guint status)
242 } action = process_nothing;
244 if (flags & GTK_MOZ_EMBED_FLAG_IS_REQUEST)
246 if (flags & GTK_MOZ_EMBED_FLAG_START)
247 ++pending_req_count_;
248 if (flags & GTK_MOZ_EMBED_FLAG_STOP)
250 assert(pending_req_count_ != 0);
251 --pending_req_count_;
253 if (pending_req_count_ == 0 && link_state_.get())
254 action = process_current_link;
257 if (flags & GTK_MOZ_EMBED_FLAG_STOP
258 && flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW)
259 action = process_new_page;
261 if (action != process_nothing)
263 assert(loading_ && !page_queue_.empty());
264 assert(pending_req_count_ == 0);
268 // Check whether the load was successful, ignoring this
270 if (status != NS_IMAGELIB_ERROR_LOAD_ABORTED)
273 nsCOMPtr<nsIWebBrowser> browser(
274 browser_widget_.get_browser());
275 nsCOMPtr<nsIDocShell> doc_shell(do_GetInterface(browser));
277 nsCOMPtr<nsIPresShell> pres_shell;
278 check(doc_shell->GetPresShell(getter_AddRefs(pres_shell)));
279 nsCOMPtr<nsIPresContext> pres_context;
280 check(doc_shell->GetPresContext(
281 getter_AddRefs(pres_context)));
282 nsCOMPtr<nsIDOMWindow> dom_window;
283 check(browser->GetContentDOMWindow(
284 getter_AddRefs(dom_window)));
286 if (action == process_new_page)
288 apply_style_sheet(stylesheet_, pres_shell);
291 process_links(pres_shell, pres_context, dom_window);
292 if (!link_state_.get())
295 if (page_queue_.empty())
304 catch (std::exception & e)
306 std::cerr << "Fatal error";
307 if (!page_queue_.empty())
308 std::cerr << " while processing <" << page_queue_.front()
310 std::cerr << ": " << e.what() << "\n";
316 void WebDvdWindow::save_screenshot()
318 Glib::RefPtr<Gdk::Window> window(get_window());
320 window->process_updates(true);
322 background_temp_.reset(new temp_file("webdvd-back-"));
323 background_temp_->close();
324 std::cout << "saving " << background_temp_->get_name() << std::endl;
325 Gdk::Pixbuf::create(Glib::RefPtr<Gdk::Drawable>(window),
326 window->get_colormap(),
328 frame_params_.width, frame_params_.height)
329 ->save(background_temp_->get_name(), "png");
332 struct WebDvdWindow::link_state
334 Glib::RefPtr<Gdk::Pixbuf> diff_pixbuf;
336 std::auto_ptr<temp_file> spumux_temp;
337 std::ofstream spumux_file;
339 std::auto_ptr<temp_file> links_temp;
342 LinkIterator links_it, links_end;
346 Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf;
349 void WebDvdWindow::process_links(nsIPresShell * pres_shell,
350 nsIPresContext * pres_context,
351 nsIDOMWindow * dom_window)
353 Glib::RefPtr<Gdk::Window> window(get_window());
356 nsCOMPtr<nsIDOMDocument> basic_doc;
357 check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
358 nsCOMPtr<nsIDOMNSDocument> ns_doc(do_QueryInterface(basic_doc));
360 nsCOMPtr<nsIEventStateManager> event_state_man(
361 pres_context->EventStateManager()); // does not AddRef
362 assert(event_state_man);
363 nsCOMPtr<nsIDOMDocumentEvent> event_factory(
364 do_QueryInterface(basic_doc));
365 assert(event_factory);
366 nsCOMPtr<nsIDOMDocumentView> doc_view(do_QueryInterface(basic_doc));
368 nsCOMPtr<nsIDOMAbstractView> view;
369 check(doc_view->GetDefaultView(getter_AddRefs(view)));
371 // Set up or recover our iteration state.
372 std::auto_ptr<link_state> state(link_state_);
375 state.reset(new link_state);
377 state->diff_pixbuf = Gdk::Pixbuf::create(
379 true, 8, // has_alpha, bits_per_sample
380 frame_params_.width, frame_params_.height);
382 state->spumux_temp.reset(new temp_file("webdvd-spumux-"));
383 state->spumux_temp->close();
385 state->links_temp.reset(new temp_file("webdvd-links-"));
386 state->links_temp->close();
388 state->spumux_file.open(state->spumux_temp->get_name().c_str());
389 state->spumux_file <<
392 " <spu force='yes' start='00:00:00.00'\n"
393 " highlight='" << state->links_temp->get_name()
395 " select='" << state->links_temp->get_name()
399 state->links_it = LinkIterator(basic_doc);
400 state->link_changing = false;
403 rectangle window_rect = {
404 0, 0, frame_params_.width, frame_params_.height
407 for (/* no initialisation */;
408 state->links_it != state->links_end;
411 nsCOMPtr<nsIDOMNode> node(*state->links_it);
413 // Find the link URI.
414 nsCOMPtr<nsILink> link(do_QueryInterface(node));
416 nsCOMPtr<nsIURI> uri;
417 check(link->GetHrefURI(getter_AddRefs(uri)));
418 std::string uri_string;
420 nsCString uri_ns_string;
421 check(uri->GetSpec(uri_ns_string));
422 uri_string.assign(uri_ns_string.BeginReading(),
423 uri_ns_string.EndReading());
425 std::string uri_sans_fragment(uri_string, 0, uri_string.find('#'));
427 // Is this a new link?
428 if (!state->link_changing)
430 // Find a rectangle enclosing the link and clip it to the
432 nsCOMPtr<nsIDOMElement> elem(do_QueryInterface(node));
434 state->link_rect = get_elem_rect(ns_doc, elem);
435 state->link_rect &= window_rect;
437 if (state->link_rect.empty())
439 std::cerr << "Ignoring invisible link to "
440 << uri_string << "\n";
446 if (state->link_num >= dvd::menu_buttons_max)
448 if (state->link_num == dvd::menu_buttons_max)
449 std::cerr << "No more than " << dvd::menu_buttons_max
450 << " buttons can be placed on a page\n";
451 std::cerr << "Ignoring link to " << uri_string << "\n";
455 // Check whether this is a link to a video or a page then
456 // add it to the known resources if not already seen.
458 check(uri->GetPath(path));
459 // FIXME: This is a bit of a hack. Perhaps we could decide
460 // later based on the MIME type determined by Mozilla?
461 if (path.Length() > 4
462 && std::strcmp(path.EndReading() - 4, ".vob") == 0)
465 check(uri->SchemeIs("file", &is_file));
468 std::cerr << "Links to video must use the file:"
472 add_video(uri_sans_fragment);
476 add_page(uri_sans_fragment);
479 nsCOMPtr<nsIContent> content(do_QueryInterface(node));
481 nsCOMPtr<nsIDOMEventTarget> event_target(
482 do_QueryInterface(node));
483 assert(event_target);
485 state->norm_pixbuf = Gdk::Pixbuf::create(
486 Glib::RefPtr<Gdk::Drawable>(window),
487 window->get_colormap(),
488 state->link_rect.left,
489 state->link_rect.top,
492 state->link_rect.right - state->link_rect.left,
493 state->link_rect.bottom - state->link_rect.top);
495 nsCOMPtr<nsIDOMEvent> event;
496 check(event_factory->CreateEvent(
497 NS_ConvertASCIItoUTF16("MouseEvents"),
498 getter_AddRefs(event)));
499 nsCOMPtr<nsIDOMMouseEvent> mouse_event(
500 do_QueryInterface(event));
502 check(mouse_event->InitMouseEvent(
503 NS_ConvertASCIItoUTF16("mouseover"),
507 0, // detail: mouse click count
508 state->link_rect.left, // screenX
509 state->link_rect.top, // screenY
510 state->link_rect.left, // clientX
511 state->link_rect.top, // clientY
512 false, false, false, false, // qualifiers
513 0, // button: left (or primary)
514 0)); // related target
516 check(event_target->DispatchEvent(mouse_event,
518 check(event_state_man->SetContentState(content,
519 NS_EVENT_STATE_HOVER));
521 pres_shell->FlushPendingNotifications(true);
523 // We may have to exit and wait for image loading
524 // to complete, at which point we will be called
526 if (pending_req_count_ > 0)
528 state->link_changing = true;
534 window->process_updates(true);
536 Glib::RefPtr<Gdk::Pixbuf> changed_pixbuf(
538 Glib::RefPtr<Gdk::Drawable>(window),
539 window->get_colormap(),
540 state->link_rect.left,
541 state->link_rect.top,
544 state->link_rect.right - state->link_rect.left,
545 state->link_rect.bottom - state->link_rect.top));
550 state->link_rect.left,
551 state->link_rect.top,
552 state->link_rect.right - state->link_rect.left,
553 state->link_rect.bottom - state->link_rect.top);
555 state->spumux_file <<
556 " <button x0='" << state->link_rect.left << "'"
557 " y0='" << state->link_rect.top << "'"
558 " x1='" << state->link_rect.right - 1 << "'"
559 " y1='" << state->link_rect.bottom - 1 << "'/>\n";
561 // Add to the page's links, ignoring any fragment (for now).
562 page_links_.back().push_back(uri_sans_fragment);
565 quantise_rgba_pixbuf(state->diff_pixbuf, dvd::button_n_colours);
567 std::cout << "saving " << state->links_temp->get_name()
569 state->diff_pixbuf->save(state->links_temp->get_name(), "png");
571 state->spumux_file <<
576 state->spumux_file.close();
578 // TODO: if (!state->spumux_file) throw ...
581 boost::shared_ptr<temp_file> vob_temp(
582 new temp_file("webdvd-vob-"));
583 std::ostringstream command_stream;
584 command_stream << "pngtopnm "
585 << background_temp_->get_name()
586 << " | ppmtoy4m -v0 -n1 -F"
587 << frame_params_.rate_numer
588 << ":" << frame_params_.rate_denom
589 << " -A" << frame_params_.pixel_ratio_width
590 << ":" << frame_params_.pixel_ratio_height
591 << (" -Ip -S420_mpeg2"
592 " | mpeg2enc -v0 -f8 -a2 -o/dev/stdout"
593 " | mplex -v0 -f8 -o/dev/stdout /dev/stdin"
594 " | spumux -v0 -mdvd ")
595 << state->spumux_temp->get_name()
596 << " > " << vob_temp->get_name();
597 std::string command(command_stream.str());
598 const char * argv[] = {
599 "/bin/sh", "-c", command.c_str(), 0
601 std::cout << "running " << argv[2] << std::endl;
603 Glib::spawn_sync(".",
604 Glib::ArrayHandle<std::string>(
605 argv, sizeof(argv)/sizeof(argv[0]),
606 Glib::OWNERSHIP_NONE),
607 Glib::SPAWN_STDOUT_TO_DEV_NULL,
611 if (command_result != 0)
612 throw std::runtime_error("spumux pipeline failed");
614 page_temp_files_.push_back(vob_temp);
618 void generate_page_dispatch(std::ostream &, int indent,
619 int first_page, int last_page);
621 void WebDvdWindow::generate_dvd()
623 temp_file temp("webdvd-dvdauthor-");
625 std::ofstream file(temp.get_name().c_str());
627 // We generate code that uses registers in the following way:
629 // g0: link destination (when jumping to menu 1), then scratch
630 // g1: current location
631 // g2-g11: location history (g2 = most recent)
632 // g12: location that last linked to a video
634 // All locations are divided into two bitfields: the least
635 // significant 10 bits are a page/menu number and the most
636 // significant 6 bits are a link/button number. This is
637 // chosen for compatibility with the encoding of the s8
638 // (button) register.
640 static const int link_mult = dvd::reg_s8_button_mult;
641 static const int page_mask = link_mult - 1;
642 static const int link_mask = (1 << dvd::reg_bits) - link_mult;
649 for (std::size_t page_num = 1;
650 page_num <= page_links_.size();
653 std::vector<std::string> & page_links =
654 page_links_[page_num - 1];
658 // This is the first page (root menu) which needs to
659 // include initialisation and dispatch code.
662 " <pgc entry='title'>\n"
664 // Has the location been set yet?
667 // Initialise the current location to first link on
669 " g1 = " << 1 * link_mult + 1 << ";\n"
673 // Has the user selected a link?
676 // First update the history.
677 // Does link go to the last page in the history?
678 " if (((g0 ^ g2) & " << page_mask
680 // It does; we treat this as going back and pop the old
681 // location off the history stack into the current
682 // location. Clear the free stack slot.
684 " g1 = g2; g2 = g3; g3 = g4; g4 = g5;\n"
685 " g5 = g6; g6 = g7; g7 = g8; g8 = g9;\n"
686 " g9 = g10; g10 = g11; g11 = 0;\n"
689 // Link goes to some other page, so push current
690 // location onto the history stack and set the current
691 // location to be exactly the target location.
693 " g11 = g10; g10 = g9; g9 = g8; g8 = g7;\n"
694 " g7 = g6; g6 = g5; g5 = g4; g4 = g3;\n"
695 " g3 = g2; g2 = g1; g1 = g0;\n"
698 // Find the target page number.
699 " g0 = g1 & " << page_mask << ";\n";
700 // There seems to be no way to perform a computed jump,
701 // so we generate all possible jumps and a binary search
702 // to select the correct one.
703 generate_page_dispatch(file, 12, 1, page_links_.size());
707 else // page_num != 1
715 // Clear link indicator and highlight the
716 // appropriate link/button.
717 " g0 = 0; s8 = g1 & " << link_mask << ";\n"
720 << page_temp_files_[page_num - 1]->get_name() << "'/>\n";
722 for (std::size_t link_num = 1;
723 link_num <= page_links.size();
728 // Update current location.
729 " g1 = " << link_num * link_mult + page_num << ";";
731 // Jump to appropriate resource.
732 const ResourceEntry & resource_loc =
733 resource_map_[page_links[link_num - 1]];
734 if (resource_loc.first == page_resource)
736 " g0 = " << 1 * link_mult + resource_loc.second << ";"
738 else if (resource_loc.first == video_resource)
739 file << " jump title " << resource_loc.second << ";";
741 file << " </button>\n";
751 // Generate a titleset for each video. This appears to make
752 // jumping to titles a whole lot simpler.
753 for (std::size_t video_num = 1;
754 video_num <= video_paths_.size();
759 // Generate a dummy menu so that the menu button on the
760 // remote control will work.
762 " <pgc entry='root'>\n"
763 " <pre> jump vmgm menu; </pre>\n"
768 // Record calling page/menu.
769 " <pre> g12 = g1; </pre>\n"
770 // FIXME: Should XML-escape the path
771 " <vob file='" << video_paths_[video_num - 1]
773 // If page/menu location has not been changed during the
774 // video, change the location to be the following
775 // link/button when returning to it. In any case,
776 // return to a page/menu.
777 " <post> if (g1 eq g12) g1 = g1 + " << link_mult
778 << "; call menu; </post>\n"
790 const char * argv[] = {
792 "-o", output_dir_.c_str(),
793 "-x", temp.get_name().c_str(),
797 Glib::spawn_sync(".",
798 Glib::ArrayHandle<std::string>(
799 argv, sizeof(argv)/sizeof(argv[0]),
800 Glib::OWNERSHIP_NONE),
801 Glib::SPAWN_SEARCH_PATH
802 | Glib::SPAWN_STDOUT_TO_DEV_NULL,
806 if (command_result != 0)
807 throw std::runtime_error("dvdauthor failed");
811 void generate_page_dispatch(std::ostream & file, int indent,
812 int first_page, int last_page)
814 if (first_page == 1 && last_page == 1)
816 // The dispatch code is *on* page 1 so we must not dispatch to
817 // page 1 since that would cause an infinite loop. This case
818 // should be unreachable if there is more than one page due
819 // to the following case.
821 else if (first_page == 1 && last_page == 2)
823 // dvdauthor doesn't allow empty blocks or null statements so
824 // when selecting between pages 1 and 2 we don't use an "else"
825 // part. We must use braces so that a following "else" will
826 // match the right "if".
827 file << std::setw(indent) << "" << "{\n"
828 << std::setw(indent) << "" << "if (g0 eq 2)\n"
829 << std::setw(indent + 2) << "" << "jump menu 2;\n"
830 << std::setw(indent) << "" << "}\n";
832 else if (first_page == last_page)
834 file << std::setw(indent) << ""
835 << "jump menu " << first_page << ";\n";
839 int middle = (first_page + last_page) / 2;
840 file << std::setw(indent) << "" << "if (g0 le " << middle << ")\n";
841 generate_page_dispatch(file, indent + 2, first_page, middle);
842 file << std::setw(indent) << "" << "else\n";
843 generate_page_dispatch(file, indent + 2, middle + 1, last_page);
847 const video::frame_params & lookup_frame_params(const char * str)
850 static const struct { const char * str; bool is_ntsc; }
856 // For DVD purposes, SECAM can be treated identically to PAL.
860 for (std::size_t i = 0;
861 i != sizeof(known_strings)/sizeof(known_strings[0]);
863 if (std::strcmp(str, known_strings[i].str) == 0)
864 return known_strings[i].is_ntsc ?
865 video::ntsc_params : video::pal_params;
866 throw std::runtime_error(
867 std::string("Invalid video standard: ").append(str));
870 void print_usage(std::ostream & stream, const char * command_name)
872 stream << "Usage: " << command_name
873 << (" [gtk-options] [--video-std std-name]"
874 " front-page-url output-dir\n");
879 int main(int argc, char ** argv)
883 // Do initial argument parsing. We have to do this before
884 // letting Gtk parse the arguments since we need to spawn Xvfb
885 // first and that's currently dependent on the frame
886 // parameters (though we could just make it large enough for
887 // any frame) and also an unnecessary expense in some cases.
888 video::frame_params frame_params = video::pal_params;
889 for (int argi = 1; argi != argc; ++argi)
891 if (std::strcmp(argv[argi], "--") == 0)
893 if (std::strcmp(argv[argi], "--help") == 0)
895 print_usage(std::cout, argv[0]);
898 if (std::strcmp(argv[argi], "--video-std") == 0)
900 if (argi + 1 == argc)
902 std::cerr << "Missing argument to --video-std\n";
903 print_usage(std::cerr, argv[0]);
906 frame_params = lookup_frame_params(argv[argi + 1]);
911 // Spawn Xvfb and set env variables so that Xlib will use it
912 // Use 8 bits each for RGB components, which should translate into
913 // "enough" bits for YUV components.
914 FrameBuffer fb(frame_params.width, frame_params.height, 3 * 8);
915 setenv("XAUTHORITY", fb.get_x_authority().c_str(), true);
916 setenv("DISPLAY", fb.get_x_display().c_str(), true);
919 Gtk::Main kit(argc, argv);
921 // Complete argument parsing with Gtk's options out of the way.
925 if (std::strcmp(argv[argi], "--video-std") == 0)
929 else if (std::strcmp(argv[argi], "--") == 0)
934 else if (argv[argi][0] == '-')
936 std::cerr << "Invalid option: " << argv[argi] << "\n";
937 print_usage(std::cerr, argv[0]);
943 if (argi != argc - 2)
945 print_usage(std::cerr, argv[0]);
949 // Initialise Mozilla
950 BrowserWidget::init();
952 WebDvdWindow window(frame_params, argv[argi], argv[argi + 1]);
953 Gtk::Main::run(window);
955 catch (std::exception & e)
957 std::cerr << "Fatal error: " << e.what() << "\n";