]> git.decadent.org.uk Git - videolink.git/blobdiff - videolink.cpp
Removed support for Mozilla 1.7.
[videolink.git] / videolink.cpp
index 59956c744eb673a36ce7234669f9fc51798a543c..74b8a21a067979a5317ba0abc9bd645558e4dc40 100644 (file)
@@ -15,8 +15,6 @@
 
 #include <stdlib.h>
 
-#include <boost/shared_ptr.hpp>
-
 #include <gdkmm/pixbuf.h>
 #include <glibmm/convert.h>
 #include <glibmm/spawn.h>
 #include <nsIURI.h> // required before nsILink.h
 #include <nsILink.h>
 #include <nsIPrefBranch.h>
-#if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
-#   include <nsPresContext.h>
-#else
-#   include <nsIPresContext.h>
-    typedef nsIPresContext nsPresContext; // ugh
-#endif
+#include <nsPresContext.h>
 #include <nsIPrefService.h>
 #include <nsIPresShell.h>
-#if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
-#   include <nsServiceManagerUtils.h>
-#else
-#   include <nsIServiceManagerUtils.h>
-#endif
+#include <nsServiceManagerUtils.h>
 #include <nsIWebBrowser.h>
 #include <nsString.h>
 
 #include "child_iterator.hpp"
 #include "dvd.hpp"
 #include "generate_dvd.hpp"
+#include "geometry.hpp"
 #include "link_iterator.hpp"
 #include "null_prompt_service.hpp"
 #include "pixbufs.hpp"
 #include "style_sheets.hpp"
 #include "temp_file.hpp"
 #include "video.hpp"
+#include "warp_pointer.hpp"
 #include "x_frame_buffer.hpp"
 #include "xml_utils.hpp"
 #include "xpcom_support.hpp"
@@ -77,58 +68,6 @@ using xpcom_support::check;
 
 namespace
 {
-    // We can try using any of these encoders to convert PNG to MPEG.
-    enum mpeg_encoder
-    {
-       mpeg_encoder_ffmpeg,         // ffmpeg
-       mpeg_encoder_mjpegtools_old, // mjpegtools before version 1.8
-       mpeg_encoder_mjpegtools_new  // mjpegtools from version 1.8
-    };
-
-    struct rectangle
-    {
-       int left, top;     // inclusive
-       int right, bottom; // exclusive
-
-       rectangle operator|=(const rectangle & other)
-           {
-               if (other.empty())
-               {
-                   // use current extents unchanged
-               }
-               else if (empty())
-               {
-                   // use other extents
-                   *this = other;
-               }
-               else
-               {
-                   // find rectangle enclosing both extents
-                   left = std::min(left, other.left);
-                   top = std::min(top, other.top);
-                   right = std::max(right, other.right);
-                   bottom = std::max(bottom, other.bottom);
-               }
-
-               return *this;
-           }
-
-       rectangle operator&=(const rectangle & other)
-           {
-               // find rectangle enclosed in both extents
-               left = std::max(left, other.left);
-               top = std::max(top, other.top);
-               right = std::max(left, std::min(right, other.right));
-               bottom = std::max(top, std::min(bottom, other.bottom));
-               return *this;
-           }
-
-       bool empty() const
-           {
-               return left == right || bottom == top;
-           }
-    };
-
     rectangle get_elem_rect(nsIDOMNSDocument * ns_doc,
                            nsIDOMElement * elem)
     {
@@ -163,6 +102,40 @@ namespace
     }
 
 
+    enum video_format
+    {
+       video_format_none,
+       video_format_mpeg2_ps,
+       video_format_vob_list
+    };
+
+    video_format video_format_from_uri(const std::string & uri)
+    {
+       // FIXME: This is a bit of a hack.  Perhaps we could decide
+       // later based on the MIME type determined by Mozilla?
+       static struct {
+           const char * extension;
+           video_format format;
+       } const mapping[] = {
+           {".vob",     video_format_mpeg2_ps},
+           {".mpeg",    video_format_mpeg2_ps},
+           {".mpeg2",   video_format_mpeg2_ps},
+           {".voblist", video_format_vob_list}
+       };
+       for (std::size_t i = 0;
+            i != sizeof(mapping) / sizeof(mapping[0]);
+            ++i)
+       {
+           std::size_t ext_len = std::strlen(mapping[i].extension);
+           if (uri.size() > ext_len
+               && uri.compare(uri.size() - ext_len, ext_len,
+                              mapping[i].extension) == 0)
+               return mapping[i].format;
+       }
+       return video_format_none;
+    }
+
+    
     class videolink_window : public Gtk::Window
     {
     public:
@@ -170,13 +143,16 @@ namespace
            const video::frame_params & frame_params,
            const std::string & main_page_uri,
            const std::string & output_dir,
-           mpeg_encoder encoder);
+           dvd_generator::mpeg_encoder encoder);
 
        bool is_finished() const;
 
     private:
-       dvd_contents::pgc_ref add_menu(const std::string & uri);
-       dvd_contents::pgc_ref add_title(const std::string & uri);
+       struct page_state;
+
+       dvd_generator::pgc_ref add_menu(const std::string & uri);
+       dvd_generator::pgc_ref add_title(const std::string & uri,
+                                        video_format format);
        void load_next_page();
        bool on_idle();
        void on_net_state_change(const char * uri, gint flags, guint status);
@@ -184,28 +160,34 @@ namespace
            {
                return pending_window_update_ || pending_req_count_;
            }
-       bool process_page();
-       void save_screenshot();
-       void process_links(nsIPresShell * pres_shell,
-                          nsPresContext * pres_context,
-                          nsIDOMWindow * dom_window);
+       // Do as much processing as possible.  Return a flag indicating
+       // whether to call again once the browser is idle.
+       bool process();
+       // Return a Pixbuf containing a copy of the window contents.
+       Glib::RefPtr<Gdk::Pixbuf> get_screenshot();
+       // Do as much processing as possible on the page links.  Return
+       // a flag indicating whether to call again once the browser is
+       // idle.
+       bool process_links(
+           page_state * state,
+           nsIDOMDocument * basic_doc,
+           nsIPresShell * pres_shell,
+           nsPresContext * pres_context,
+           nsIDOMWindow * dom_window);
 
        video::frame_params frame_params_;
        std::string output_dir_;
-       mpeg_encoder encoder_;
        browser_widget browser_widget_;
-       nsCOMPtr<nsIStyleSheet> stylesheet_;
 
-       dvd_contents contents_;
-       typedef std::map<std::string, dvd_contents::pgc_ref> resource_map_type;
+       dvd_generator generator_;
+       typedef std::map<std::string, dvd_generator::pgc_ref>
+           resource_map_type;
        resource_map_type resource_map_;
 
        std::queue<std::string> page_queue_;
        bool pending_window_update_;
        int pending_req_count_;
        bool have_tweaked_page_;
-       std::auto_ptr<temp_file> background_temp_;
-       struct page_state;
        std::auto_ptr<page_state> page_state_;
 
        bool finished_;
@@ -215,11 +197,10 @@ namespace
        const video::frame_params & frame_params,
        const std::string & main_page_uri,
        const std::string & output_dir,
-       mpeg_encoder encoder)
+       dvd_generator::mpeg_encoder encoder)
            : frame_params_(frame_params),
              output_dir_(output_dir),
-             encoder_(encoder),
-             stylesheet_(load_css("file://" VIDEOLINK_SHARE_DIR "/videolink.css")),
+             generator_(frame_params, encoder),
              pending_window_update_(false),
              pending_req_count_(0),
              have_tweaked_page_(false),
@@ -243,37 +224,23 @@ namespace
        return finished_;
     }
 
-    dvd_contents::pgc_ref videolink_window::add_menu(const std::string & uri)
+    dvd_generator::pgc_ref videolink_window::add_menu(const std::string & uri)
     {
-       dvd_contents::pgc_ref next_menu(dvd_contents::menu_pgc,
-                                       contents_.menus.size());
-       std::pair<resource_map_type::iterator, bool> insert_result(
-           resource_map_.insert(std::make_pair(uri, next_menu)));
-
-       if (!insert_result.second)
-       {
-           return insert_result.first->second;
-       }
-       else
+       dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
+       if (pgc_ref.type == dvd_generator::unknown_pgc)
        {
+           pgc_ref = generator_.add_menu();
            page_queue_.push(uri);
-           contents_.menus.resize(contents_.menus.size() + 1);
-           return next_menu;
        }
+       return pgc_ref;
     }
 
-    dvd_contents::pgc_ref videolink_window::add_title(const std::string & uri)
+    dvd_generator::pgc_ref videolink_window::add_title(const std::string & uri,
+                                                     video_format format)
     {
-       dvd_contents::pgc_ref next_title(dvd_contents::title_pgc,
-                                        contents_.titles.size());
-       std::pair<resource_map_type::iterator, bool> insert_result(
-           resource_map_.insert(std::make_pair(uri, next_title)));
+       dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
 
-       if (!insert_result.second)
-       {
-           return insert_result.first->second;
-       }
-       else
+       if (pgc_ref.type == dvd_generator::unknown_pgc)
        {
            Glib::ustring hostname;
            std::string path(Glib::filename_from_uri(uri, hostname));
@@ -283,7 +250,7 @@ namespace
 
            // Store a reference to a linked VOB file, or the contents
            // of a linked VOB list file.
-           if (path.compare(path.size() - 4, 4, ".vob") == 0)
+           if (format == video_format_mpeg2_ps)
            {
                if (!Glib::file_test(path, Glib::FILE_TEST_IS_REGULAR))
                    throw std::runtime_error(
@@ -292,16 +259,19 @@ namespace
                ref.file = path;
                list.push_back(ref);
            }
-           else
+           else if (format == video_format_vob_list)
            {
-               assert(path.compare(path.size() - 8, 8, ".voblist") == 0);
                read_vob_list(path).swap(list);
            }
+           else
+           {
+               assert(!"unrecognised format in add_title");
+           }
 
-           contents_.titles.resize(contents_.titles.size() + 1);
-           contents_.titles.back().swap(list);
-           return next_title;
+           pgc_ref = generator_.add_title(list);
        }
+
+       return pgc_ref;
     }
 
     void videolink_window::load_next_page()
@@ -315,6 +285,14 @@ namespace
 
     bool videolink_window::on_idle()
     {
+       if (!output_dir_.empty())
+       {
+           // Put pointer in the top-left so that no links appear in
+           // the hover state when we take a screenshot.
+           warp_pointer(get_window(),
+                        -frame_params_.width, -frame_params_.height);
+       }
+       
        load_next_page();
        return false; // don't call again thankyou
     }
@@ -395,7 +373,7 @@ namespace
        {
            try
            {
-               if (!process_page())
+               if (!process())
                {
                    finished_ = true;
                    Gtk::Main::quit();
@@ -422,7 +400,30 @@ namespace
        }
     }
 
-    bool videolink_window::process_page()
+    struct videolink_window::page_state
+    {
+       page_state(Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf,
+                  nsIDOMDocument * doc, int width, int height)
+               : norm_pixbuf(norm_pixbuf),
+                 diff_pixbuf(Gdk::Pixbuf::create(
+                                 Gdk::COLORSPACE_RGB,
+                                 true, 8, // has_alpha, bits_per_sample
+                                 width, height)),
+                 links_it(doc),
+                 link_changing(false)
+           {
+           }
+
+       Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf;
+       Glib::RefPtr<Gdk::Pixbuf> diff_pixbuf;
+
+       link_iterator links_it, links_end;
+
+       rectangle link_rect;
+       bool link_changing;
+    };
+
+    bool videolink_window::process()
     {
        assert(!page_queue_.empty());
 
@@ -436,12 +437,9 @@ namespace
        nsCOMPtr<nsIDOMWindow> dom_window;
        check(browser->GetContentDOMWindow(getter_AddRefs(dom_window)));
 
-       // If we haven't done so already, apply the stylesheet and
-       // disable scrollbars.
+       // If we haven't done so already, disable scrollbars.
        if (!have_tweaked_page_)
        {
-           apply_style_sheet(stylesheet_, pres_shell);
-
            // This actually only needs to be done once.
            nsCOMPtr<nsIDOMBarProp> dom_bar_prop;
            check(dom_window->GetScrollbars(getter_AddRefs(dom_bar_prop)));
@@ -458,27 +456,44 @@ namespace
        // All further work should only be done if we're not in preview mode.
        if (!output_dir_.empty())
        {
-           // If we haven't already started work on this menu, save a
-           // screenshot of its normal appearance.
-           if (!page_state_.get())
-               save_screenshot();
+           nsCOMPtr<nsIDOMDocument> basic_doc;
+           check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
 
            // Start or continue processing links.
-           process_links(pres_shell, pres_context, dom_window);
-
-           // If we've finished work on the links, move on to the
-           // next page, if any, or else generate the DVD filesystem.
-           if (!page_state_.get())
+           std::auto_ptr<page_state> state(page_state_);
+           if (!state.get())
+               state.reset(
+                   new page_state(
+                       get_screenshot(),
+                       basic_doc, frame_params_.width, frame_params_.height));
+           if (process_links(
+                   state.get(),
+                   basic_doc, pres_shell, pres_context, dom_window))
            {
+               // Save iteration state for later.
+               page_state_ = state;
+           }
+           else
+           {
+               // We've finished work on the links so generate the
+               // menu VOB.
+               quantise_rgba_pixbuf(state->diff_pixbuf,
+                                    dvd::button_n_colours);
+               generator_.generate_menu_vob(
+                   resource_map_[page_queue_.front()].index,
+                   state->norm_pixbuf, state->diff_pixbuf);
+
+               // Move on to the next page, if any, or else generate
+               // the DVD filesystem.
                page_queue_.pop();
-               if (page_queue_.empty())
+               if (!page_queue_.empty())
                {
-                   generate_dvd(contents_, output_dir_);
-                   return false;
+                   load_next_page();
                }
                else
                {
-                   load_next_page();
+                   generator_.generate(output_dir_);
+                   return false;
                }
            }
        }
@@ -486,63 +501,28 @@ namespace
        return true;
     }
 
-    void videolink_window::save_screenshot()
+    Glib::RefPtr<Gdk::Pixbuf> videolink_window::get_screenshot()
     {
        Glib::RefPtr<Gdk::Window> window(get_window());
        assert(window);
        window->process_updates(true);
 
-       background_temp_.reset(new temp_file("videolink-back-"));
-       background_temp_->close();
-       std::cout << "saving " << background_temp_->get_name() << std::endl;
-       Gdk::Pixbuf::create(Glib::RefPtr<Gdk::Drawable>(window),
-                           window->get_colormap(),
-                           0, 0, 0, 0,
-                           frame_params_.width, frame_params_.height)
-           ->save(background_temp_->get_name(), "png");
+       return Gdk::Pixbuf::create(Glib::RefPtr<Gdk::Drawable>(window),
+                                  window->get_colormap(),
+                                  0, 0, 0, 0,
+                                  frame_params_.width, frame_params_.height);
     }
 
-    struct videolink_window::page_state
-    {
-       page_state(nsIDOMDocument * doc, int width, int height)
-               : diff_pixbuf(Gdk::Pixbuf::create(
-                                 Gdk::COLORSPACE_RGB,
-                                 true, 8, // has_alpha, bits_per_sample
-                                 width, height)),
-                 spumux_temp("videolink-spumux-"),
-                 links_temp("videolink-links-"),
-                 link_num(0),
-                 links_it(doc),
-                 link_changing(false)
-           {
-               spumux_temp.close();
-               links_temp.close();
-           }
-
-       Glib::RefPtr<Gdk::Pixbuf> diff_pixbuf;
-
-       temp_file spumux_temp;
-       std::ofstream spumux_file;
-
-       temp_file links_temp;
-
-       unsigned link_num;
-       link_iterator links_it, links_end;
-
-       rectangle link_rect;
-       bool link_changing;
-       Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf;
-    };
-
-    void videolink_window::process_links(nsIPresShell * pres_shell,
-                                    nsPresContext * pres_context,
-                                    nsIDOMWindow * dom_window)
+    bool videolink_window::process_links(
+       page_state * state,
+       nsIDOMDocument * basic_doc,
+       nsIPresShell * pres_shell,
+       nsPresContext * pres_context,
+       nsIDOMWindow * dom_window)
     {
        Glib::RefPtr<Gdk::Window> window(get_window());
        assert(window);
 
-       nsCOMPtr<nsIDOMDocument> basic_doc;
-       check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
        nsCOMPtr<nsIDOMNSDocument> ns_doc(do_QueryInterface(basic_doc));
        assert(ns_doc);
        nsCOMPtr<nsIEventStateManager> event_state_man(
@@ -556,28 +536,11 @@ namespace
        nsCOMPtr<nsIDOMAbstractView> view;
        check(doc_view->GetDefaultView(getter_AddRefs(view)));
 
-       // Set up or recover our iteration state.
-       std::auto_ptr<page_state> state(page_state_);
-       if (!state.get())
-       {
-           state.reset(
-               new page_state(
-                   basic_doc, frame_params_.width, frame_params_.height));
-           
-           state->spumux_file.open(state->spumux_temp.get_name().c_str());
-           state->spumux_file <<
-               "<subpictures>\n"
-               "  <stream>\n"
-               "    <spu force='yes' start='00:00:00.00'\n"
-               "        highlight='" << state->links_temp.get_name() << "'\n"
-               "        select='" << state->links_temp.get_name() << "'>\n";
-       }
-
        rectangle window_rect = {
            0, 0, frame_params_.width, frame_params_.height
        };
 
-       unsigned menu_num = resource_map_[page_queue_.front()].index;
+       unsigned menu_index = resource_map_[page_queue_.front()].index;
 
        for (/* no initialisation */;
             state->links_it != state->links_end;
@@ -621,34 +584,12 @@ namespace
                    continue;
                }
 
-               ++state->link_num;
-
-               if (state->link_num >= unsigned(dvd::menu_buttons_max))
-               {
-                   if (state->link_num == unsigned(dvd::menu_buttons_max))
-                       std::cerr << "No more than " << dvd::menu_buttons_max
-                                 << " buttons can be placed on a menu\n";
-                   std::cerr << "Ignoring link to " << uri_and_fragment
-                             << "\n";
-                   continue;
-               }
-
-               state->spumux_file <<
-                   "      <button x0='" << state->link_rect.left << "'"
-                   " y0='" << state->link_rect.top << "'"
-                   " x1='" << state->link_rect.right - 1 << "'"
-                   " y1='" << state->link_rect.bottom - 1 << "'/>\n";
-
                // Check whether this is a link to a video or a page then
                // add it to the known resources if not already seen; then
                // add it to the menu entries.
-               dvd_contents::pgc_ref target;
-               // FIXME: This is a bit of a hack.  Perhaps we could decide
-               // later based on the MIME type determined by Mozilla?
-               if ((uri.size() > 4
-                    && uri.compare(uri.size() - 4, 4, ".vob") == 0)
-                   || (uri.size() > 8
-                       && uri.compare(uri.size() - 8, 8, ".voblist") == 0))
+               dvd_generator::pgc_ref target;
+               video_format format = video_format_from_uri(uri);
+               if (format != video_format_none)
                {
                    PRBool is_file;
                    check(uri_iface->SchemeIs("file", &is_file));
@@ -658,17 +599,19 @@ namespace
                                  << " scheme\n";
                        continue;
                    }
-                   target = add_title(uri);
+                   target = add_title(uri, format);
                    target.sub_index =
                        std::strtoul(fragment.c_str(), NULL, 10);
                }
-               else
+               else // video_format == video_format_none
                {
                    target = add_menu(uri);
                    // TODO: If there's a fragment, work out which button
                    // is closest and set target.sub_index.
                }
-               contents_.menus[menu_num].entries.push_back(target);
+
+               generator_.add_menu_entry(menu_index,
+                                         state->link_rect, target);
 
                nsCOMPtr<nsIContent> content(do_QueryInterface(node));
                assert(content);
@@ -676,16 +619,6 @@ namespace
                    do_QueryInterface(node));
                assert(event_target);
 
-               state->norm_pixbuf = Gdk::Pixbuf::create(
-                   Glib::RefPtr<Gdk::Drawable>(window),
-                   window->get_colormap(),
-                   state->link_rect.left,
-                   state->link_rect.top,
-                   0,
-                   0,
-                   state->link_rect.right - state->link_rect.left,
-                   state->link_rect.bottom - state->link_rect.top);
-
                nsCOMPtr<nsIDOMEvent> event;
                check(event_factory->CreateEvent(
                          NS_ConvertASCIItoUTF16("MouseEvents"),
@@ -712,12 +645,7 @@ namespace
                check(event_state_man->SetContentState(content,
                                                       NS_EVENT_STATE_HOVER));
 
-#              if MOZ_VERSION_MAJOR > 1                                   \
-                    || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
-                   pres_shell->FlushPendingNotifications(Flush_Display);
-#              else
-                   pres_shell->FlushPendingNotifications(true);
-#              endif
+               pres_shell->FlushPendingNotifications(Flush_Display);
 
                // We may have to exit and wait for image loading
                // to complete, at which point we will be called
@@ -725,8 +653,7 @@ namespace
                if (browser_is_busy())
                {
                    state->link_changing = true;
-                   page_state_ = state;
-                   return;
+                   return true;
                }
            }
 
@@ -752,79 +679,7 @@ namespace
                state->link_rect.bottom - state->link_rect.top);
        }
 
-       quantise_rgba_pixbuf(state->diff_pixbuf, dvd::button_n_colours);
-
-       std::cout << "saving " << state->links_temp.get_name()
-                 << std::endl;
-       state->diff_pixbuf->save(state->links_temp.get_name(), "png");
-
-       state->spumux_file <<
-           "    </spu>\n"
-           "  </stream>\n"
-           "</subpictures>\n";
-
-       state->spumux_file.close();
-
-       // TODO: if (!state->spumux_file) throw ...
-
-       {
-           std::ostringstream command_stream;
-           if (encoder_ == mpeg_encoder_ffmpeg)
-           {
-               command_stream
-                   << "ffmpeg"
-                   << " -f image2 -vcodec png -i "
-                   << background_temp_->get_name()
-                   << " -target " << frame_params_.ffmpeg_name <<  "-dvd"
-                   << " -vcodec mpeg2video -an -y /dev/stdout"
-                   << " | spumux -v0 -mdvd " << state->spumux_temp.get_name()
-                   << " > " << contents_.menus[menu_num].vob_temp->get_name();
-           }
-           else
-           {
-               assert(encoder_ == mpeg_encoder_mjpegtools_old
-                      || encoder_ == mpeg_encoder_mjpegtools_new);
-               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 ";
-               // The chroma subsampling keywords changed between
-               // versions 1.6.2 and 1.8 of mjpegtools.  There is no
-               // keyword that works with both.
-               if (encoder_ == mpeg_encoder_mjpegtools_old)
-                   command_stream << "-S420_mpeg2";
-               else
-                   command_stream << "-S420mpeg2";
-               command_stream
-                   << (" | mpeg2enc -v0 -f8 -a2 -o/dev/stdout"
-                       " | mplex -v0 -f8 -o/dev/stdout /dev/stdin"
-                       " | spumux -v0 -mdvd ")
-                   << state->spumux_temp.get_name()
-                   << " > "
-                   << contents_.menus[menu_num].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");
-       }
+       return false;
     }
 
     const video::frame_params & lookup_frame_params(const char * str)
@@ -866,21 +721,12 @@ namespace
        nsCOMPtr<nsIPrefBranch> pref_branch;
        check(pref_service->GetBranch("", getter_AddRefs(pref_branch)));
 
-#      if MOZ_VERSION_MAJOR > 1                                 \
-           || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
-           // Disable IE-compatibility kluge that causes backgrounds to
-           // sometimes/usually be missing from snapshots.  This is only
-           // effective from Mozilla 1.8 onward.
-           check(pref_branch->SetBoolPref(
-                     "layout.fire_onload_after_image_background_loads",
-                     true));
-
-           // Turn off link underlining.  This is also set in the agent
-           // stylesheet, but seems to be overridden by preferences in
-           // Mozilla 1.8.
-           check(pref_branch->SetBoolPref("browser.underline_anchors",
-                                          false));
-#      endif
+       // Disable IE-compatibility kluge that causes backgrounds to
+       // sometimes/usually be missing from snapshots.  This is only
+       // effective from Mozilla 1.8 onward.
+       check(pref_branch->SetBoolPref(
+                 "layout.fire_onload_after_image_background_loads",
+                 true));
 
        // Set display resolution.  With standard-definition video we
        // will be fitting ~600 pixels across a screen typically
@@ -890,8 +736,21 @@ namespace
        // slightly different but unfortunately Mozilla doesn't
        // support non-square pixels (and neither do fontconfig or Xft
        // anyway).
-       check(pref_branch->SetIntPref("browser.display.screen_resolution",
-                                     40));
+
+       // The browser.display.screen_resolution preference sets the
+       // the nominal resolution for dimensions expressed in pixels.
+       // (They may be scaled!)  In Mozilla 1.7 it also sets the
+       // assumed resolution of the display - hence pixel sizes are
+       // respected on-screen - but this is no longer the case in
+       // 1.8.  Therefore it was renamed to layout.css.dpi in 1.8.1.
+       // In 1.8 we need to set the assumed screen resolution
+       // separately, but don't know how yet.  Setting one to 40
+       // but not the other is *bad*, so currently we set neither.
+
+#      if 0
+           check(pref_branch->SetIntPref("browser.display.screen_resolution",
+                                         40));
+#      endif
     }
 
 } // namespace
@@ -910,7 +769,8 @@ int main(int argc, char ** argv)
        bool preview_mode = false;
        std::string menu_url;
        std::string output_dir;
-       mpeg_encoder encoder = mpeg_encoder_ffmpeg;
+       dvd_generator::mpeg_encoder encoder =
+           dvd_generator::mpeg_encoder_ffmpeg;
 
        // Do initial option parsing.  We have to do this before
        // letting Gtk parse the arguments since we may need to spawn
@@ -997,16 +857,16 @@ int main(int argc, char ** argv)
                }
                if (std::strcmp(argv[argi + 1], "ffmpeg") == 0)
                {
-                   encoder = mpeg_encoder_ffmpeg;
+                   encoder = dvd_generator::mpeg_encoder_ffmpeg;
                }
                else if (std::strcmp(argv[argi + 1], "mjpegtools-old") == 0)
                {
-                   encoder = mpeg_encoder_mjpegtools_old;
+                   encoder = dvd_generator::mpeg_encoder_mjpegtools_old;
                }
                else if (std::strcmp(argv[argi + 1], "mjpegtools") == 0
                         || std::strcmp(argv[argi + 1], "mjpegtools-new") == 0)
                {
-                   encoder = mpeg_encoder_mjpegtools_new;
+                   encoder = dvd_generator::mpeg_encoder_mjpegtools_new;
                }
                else
                {
@@ -1054,6 +914,10 @@ int main(int argc, char ** argv)
        // Initialise Mozilla
        browser_widget::initialiser browser_init;
        set_browser_preferences();
+       init_agent_style_sheet("file://" VIDEOLINK_SHARE_DIR "/videolink.css");
+       init_agent_style_sheet(std::string("file://" VIDEOLINK_SHARE_DIR "/")
+                              .append(frame_params.common_name).append(".css")
+                              .c_str());
        if (!preview_mode)
            null_prompt_service::install();