Friday, March 14, 2008

Building the Firefox video element backends

The git repository has multiple branches which means a little more git usage is needed to get at the Ogg (and soon, GStreamer) backends.

When you clone or pull from the repository you'll automatically pick up the commits for the new branches. You can see these branches with 'git branch -r':
$ git clone git://double.co.nz/git/video.git
$ cd video
$ git branch -r
origin/HEAD
origin/master
origin/ogg
By default the 'master' branch has a checked out working tree. Building this produces <video> element support without any decoder. One approach to building the Ogg backend is to create a local branch with the commits from the remote branch origin/ogg and build that:
$ git checkout -b ogg origin/ogg
Switched to a new branch "ogg"
$ cd mozilla
$ cat >.mozconfig << "EOF"
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-video
ac_add_options --enable-ogg
EOF
$ autoconf2.13
$ make -f client.mk build
When the gstreamer branch is added you can do similar:
$ git checkout -b gstreamer origin/gstreamer
Switched to a new branch "gstreamer"
$ cd mozilla
$ cat >.mozconfig << "EOF"
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-video
ac_add_options --enable-gstreamer
EOF
$ autoconf2.13
$ make -f client.mk
You can do a build which contains both backends by merging. You'll need to fix any merge conflicts and change the ordering of the codec instantiation so that one is preferred over the other when they can both handle the same codec. A merge looks like this:
$ git checkout -b gst_and_ogg origin/master
$ git merge origin/ogg
$ git merge origin/gstreamer
$ cd mozilla
$ cat >.mozconfig << "EOF"
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-video
ac_add_options --enable-ogg
ac_add_options --enable-gstreamer
EOF
$ autoconf2.13
$ make -f client.mk
To update your branches with the latest code from the repository, fetch and merge:
$ git fetch origin
$ git checkout ogg
$ git merge origin/ogg
$ git checkout gstreamer
$ git merge origin/gstreamer
$ git checkout gst_and_ogg
$ git merge origin/ogg
$ git merge origin/gstreamer
Once you've done a successful build you can run it from the obj-dir, or make an installer:
$ cd mozilla
$ make -f client.mk build
$ export NSPR_LOG_MODULE=nsVideoDecoder:5
$ export MOZ_NO_REMOTE=1
$ ./obj-i686-pc-linux-gnu/dist/bin/firefox -ProfileManager
$ make -C browser/installer
When the installer is built there will be a file in the 'dist' subdirectory of the object directory that contains the build. It will be a .tar.gz, .zip or .dmg, depending on the platform. The environment variables set in the above example enable logging of the video debug output and running Firefox even if an existing copy is already running.

Categories: , ,

Labels:

Thursday, March 13, 2008

Refactoring of Firefox HTML video element patch

I've making some changes to the patch implementing the HTML <video> element for Firefox.

Previously the patch attached to the bug contained the implementation of the video element and a Theora backend implemented using liboggplay.

This required pulling in a large amount of third party library code making it more difficult to get reviews for the patch and to get feedback on the changes required for the video element itself. To hopefully fix this I'm changing bug 382267 to only include the video element implementation with no video decoders.

Applying the patch from that bug to the Firefox trunk source and building with the --enable-video option will provide support for <video> but all videos will fail to load due to not having a supported decoder. This is obviously not very useful but will hopefully make the patch easier to get reviewed and landed.

I've added bug 422538 which will contain support for decoding Theora videos. This is the code taken out of the original bug. Applying the patch from this bug on top of the video element patch and building with --enable-ogg will give <video> element support that can play Theora videos.

As part of the refactoring I've made it easier for different video decoder backends to be implemented. There is an abstract class with pure virtual methods that can be inherited from. I have a 'work in progress' implementation of a GStreamer backend that I'll write about later and attach a patch to bug 422540. This backend allows playing any video format supported by GStreamer. I've tested it with the Fluendo H.264 decoder and it plays fine. Keep an eye on the bug if you're interested in this.

An advantage of this refactoring is that embedders of Gecko can choose a video backend that suits their purposes (for legal or other reasons they may choose not to have support for a particular format), or implement their own.

Currently the interface for implementing video decoder backends is a C++ abstract class. I'm considering using XPCOM so that implementations can be built and dynamically loaded. This could allow extensions to be written containing video backends that will work with the <video> element. One of the questions asked of me at the W3C video on the web workshop was whether third party providers of DRM enabled codecs could leverage the <video> element. This could provide a pathway to doing that.

The git repository will be restructured so that the 'master' branch contains the <video> element support only. The 'ogg' and 'gstreamer' branches will contain the implementations of the backends.

Categories: , ,

Labels: