<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le coin à Guij</title>
	<atom:link href="http://guij.emont.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://guij.emont.org/blog</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 12:50:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Video decoding in a sandbox</title>
		<link>http://guij.emont.org/blog/2012/05/08/video-decoding-in-a-sandbox/</link>
		<comments>http://guij.emont.org/blog/2012/05/08/video-decoding-in-a-sandbox/#comments</comments>
		<pubDate>Tue, 08 May 2012 09:01:45 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=272</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
<p>I would like to explain a bit the stuff I've been working on recently at
<a  href="http://www.igalia.com/">Igalia</a>. It is about playing with GStreamer and a sandboxing system to try
and make the playback of untrusted media more secure. Hopefully writing this
will be an occasion for me to get more distance and understand things better,
and for others to give me feedback and ideas. Particularly, even though that is
for me a field of interest, I do not claim to have any real expertise in
security, therefore comments by people who know better would be gladly welcome.</p>
<p>This story started when I decided to have a look at <a  href="http://www.chromium.org/Home">chromium</a> and its
internals. It turns out that one very specific aspect of this application is
its sandboxing system. In a nutshell, a <a  href="http://en.wikipedia.org/wiki/Sandbox_(computer_security)">sandbox</a> is a virtual container in
which untrusted programs can be safely run. In the real world, sandboxes are
rarely perfect, but they are a significant security improvement over not using
one. Chromium uses a sandbox to run its rendering engine (<a  href="http://www.webkit.org/">WebKit</a>), which
is basically the part that transforms the code of a web page into the graphical
representation of it that you see on your screen. The rationale for running
WebKit in a sandbox is not that it is untrusted code in itself, but rather that
it is a big and complex project that is bound to have bugs, like all big and
complex projects. On top of that, the input given to it is quite often data
from untrusted sources, which could potentially be forged so that it exploits
security bugs to do bad things to your computer and your beloved files. Now,
with WebKit running in a sandbox, if a web page has been forged by an attacker
to exploit a vulnerability in WebKit, the attacker will only have access to the
sandbox environment, which means that it won't be able to do things like access
the data on your computer, install software or connect to remote hosts.</p>
<p>As you might know, I like to play with multimedia things, and have hacked quite
a bit on or around <a  href="http://gstreamer.freedesktop.org/">GStreamer</a>. Therefore, I quite automatically thought of
something else that might be worth running in a sandbox: demuxers and decoders.
They are relatively big and complex pieces of software to which we regularly
pass a whole bunch of untrusted data, would it be in a web context or a more
traditional desktop or mobile context.</p>
<p>Fortunately, <a  href="https://www.cr0.org/">Julien Tinnes</a>, a developer of the chromium sandbox for
GNU/Linux made a stand alone version of it called <a  href="http://code.google.com/p/setuid-sandbox/">setuid-sandbox</a>, which
can be used by other projects to easily sandbox any process.</p>
<div  id="architecture">
<h3>Architecture</h3>
<p>The way setuid-sandbox works is rather straightforward: there is a
<tt >sandboxme</tt> command that needs to be installed setuid root. You run
<tt >sandboxme my_command</tt> and then from inside <tt >my_command</tt>, you first set up
the file descriptors that you will need (being careful not to put there
anything that could allow to escape the sandbox, more on that later), and then
you call the provided <tt >chrootme()</tt> function, which will tell the
<tt >sandboxme</tt> process to restrict the privileges that <tt >my_command</tt> has (e.g.
it can still read and write on the fds that it has open, but it cannot open new
ones).</p>
<p>Here is how I organised my integration of setuid-sandbox into GStreamer. What
I want to do for now is to put what I think are the &quot;most dangerous&quot; parts
(demuxing and decoding) in the sandbox, while letting the other components
(mainly source and sinks) outside of the sandbox (for now at least). I decided
to create a small program (called <tt ><span >gst-decoder</span></tt>) that receives the original
muxed and encoded video stream and outputs the decoded video and audio buffers.
<tt ><span >gst-decoder</span></tt> needs 3 channels of communication with the &quot;controlling&quot;
process outside the sandbox (which is called the <em>broker</em>):</p>
<blockquote>
<ol >
<li>one to pass the original stream from the source element in the broker to
<tt ><span >gst-decoder</span></tt></li>
<li>one to pass the video buffers from <tt ><span >gst-decoder</span></tt> to the video sink element
in the broker</li>
<li>one to pass the audio buffers from <tt ><span >gst-decoder</span></tt> to the audio sink element
in the broker</li>
</ol>
</blockquote>
<p>In the future, more channels for subtitle support or other features could be
desirable.</p>
<p>Since I am lazy, I wanted to use off the shelf GStreamer elements to handle
these communication channels. For the cases explained above, that would be:</p>
<blockquote>
<ol >
<li>the <tt >fdsink</tt> element on the broker side, and the <tt >fdsrc</tt> element in the
sandbox</li>
<li><tt >shmsink</tt> (in <tt ><span >gst-decoder</span></tt>) and <tt >shmsrc</tt> (in the broker)</li>
<li>same elements as above</li>
</ol>
</blockquote>
<p>Since I expect other people to be equally lazy^W^W^Wwant their life to be made
easier, my goal is to try and have this reasonably integrated in GStreamer, and
easy to integrate in applications. For that, my best idea so far was to make a
<tt >sandboxedecodebin</tt> element that, from the outside, works like <tt >decodebin</tt>
or <tt >decodebin2</tt>, at least for simple cases: it has a sink pad that can take
any format you would throw at <tt >decodebin</tt>, and it has an audio and a video
source pads that output the decoded result. In the future, it might or might
not be a good idea to try to integrate the &quot;sandboxed&quot; functionality in
<tt >decodebin</tt> directly.</p>
<p>I implemented <tt >sandboxeddecodebin</tt> as a subclass of <a  href="http://gstreamer.freedesktop.org/data/doc/gstreamer/0.10.36/gstreamer/html/GstBin.html">GstBin</a>, and it has
the following flow inside it:</p>
<pre >
fdsink -&gt; [gst-decoder] | -&gt; shmsrc (video) -&gt; gdpdepay
                        | -&gt; shmsrc (audio) -&gt; gdpdepay
</pre>
<p>Note that <tt ><span >gst-decoder</span></tt> is an external (sandboxed) process, and not a GStreamer
element like the other entities of this data flow graph.
The sink pad of <tt >fdsink</tt> and the source pads of the two <tt >gdpdepay</tt> elements
are exported by <tt >sandboxeddecodebin</tt> through ghost pads, which provides a
<tt >decodebin</tt>-like interface.</p>
<p>The <tt ><span >gst-decoder</span></tt> program basically runs a pipeline that looks like that:</p>
<pre >
fdsrc ! decodebin2 name=decoder
decoder. ! video/x-raw-yuv;video/x-raw-rgb ! gdppay ! shmsink (video)
decoder. ! audio/x-raw-int;audio/x-raw-float ! gdppay ! shmsink (audio)
</pre>
<p>and it also makes sure to get the privilege dropped at the right time, which is
discussed below.</p>
</div>
<div  id="when-to-drop-privileges">
<h3>When to drop privileges?</h3>
<p>The ordering of operations needs to be thought carefully to combine GStreamer,
and these elements in particular, with setuid-sandbox. Each of them brings its
own set of conditions.</p>
<p>For setuid-sandbox, inside the sandbox (in <tt ><span >gst-decoder</span></tt>):</p>
<blockquote>
<ul >
<li>before we call <tt >chrootme()</tt>: we can open new fds and do a lot of nice
initialisation, and we don't want to parse any untrusted data</li>
<li>after we call <tt >chrootme()</tt>: we can't open new fds any more, or do similar
initialisation tasks, but we can work on the data we received.</li>
</ul>
</blockquote>
<p>GStreamer has several states in which an element can be, with some rules on
what should be done in which state. From the <a  href="http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-states.txt">design documentation</a>, the
states are defined as follow:</p>
<blockquote>
<ul >
<li>NULL: This is the initial state of an element.</li>
<li>READY: The element should be prepared to go to PAUSED.</li>
<li>PAUSED: The element should be ready to accept and process data. Sink
elements however only accept one buffer and then block.</li>
<li>PLAYING: The same as PAUSED except for live sources and sinks. Sinks accept
and rendering data. Live sources produce data.</li>
</ul>
</blockquote>
<p>In particular, the elements that interest us here behave in the following way:</p>
<blockquote>
<ul >
<li><tt >shmsink</tt> is responsible for the creation and destruction of the shared memory
object and the associated control socket and creates them when going from
NULL to READY and destroys them when going from READY to NULL. Since
<tt >shmsink</tt> is used from inside the sandbox, this means that the state
change NULL to READY needs to happen before <tt >chrootme()</tt>. This also means
that it won't be able to clean up properly the shared memory object and the
control socket.</li>
<li><tt >fdsrc</tt> doesn't create nor destroy the fd it uses, so that can be done
separately. Moreover, in the case of stdin, we leave that responsibility to
the system.</li>
</ul>
</blockquote>
<p>And quite obviously, we want <tt ><span >gst-decoder</span></tt> to handle buffers only after it
has called <tt >chrootme()</tt>, so that it is ready to run potentially unsafe
operations.</p>
<p>This is relatively easy: all we have to do is, in <tt ><span >gst-decoder</span></tt>, to call
<tt >chrootme()</tt> once we are in the READY state and before going to PAUSED.</p>
<p>Another issue with the privilege drop is that we use <tt >decodebin2</tt> (things
would be the same with <tt >decodebin</tt>), and it only loads the plugins it needs
once it knows what kind of data it will have to decode. That is, it needs to
load plugins after it has started to analyse potentially unsafe data. My
solution to that is to preload <em>all</em> the installed plugins when <tt ><span >gst-decoder</span></tt>
starts, so that <tt >decodebin2</tt> doesn't need any privilege to have access to the
plugins it wants (they are already in memory).</p>
<p>This is obviously suboptimal in memory consumption. I can think of two ways to
improve that:</p>
<blockquote>
<ul >
<li>use a white/black list of plugins to avoid loading plugins we are not likely
to need (there are many things we're pretty sure not to need in <tt ><span >gst-decoder</span></tt>,
such as all sources and sinks or gnonlin)</li>
<li>use a separate typefinding sandboxed process that will determine what
plugins are needed, then have <tt ><span >gst-decoder</span></tt> take as argument the plugins that
it needs to load before dropping privileges</li>
</ul>
</blockquote>
</div>
<div  id="synchronising-broker-and-sandbox">
<h3>Synchronising broker and sandbox</h3>
<p>Another synchronisation issue is that the broker has to wait for the sandboxed
process to be ready before interacting with it. As seen before, we have 3
channels through which they interact, and they are of two different types:</p>
<blockquote>
<ul >
<li>the pipe to which the broker writes, which points to stdin in the sandboxed
process</li>
<li>the shared memory areas, and their associated control sockets created by the
two shmsink</li>
</ul>
</blockquote>
<p>The first one is easy to synchronise: as long as the sandboxed process is not
ready, it won't read on the pipe, and <tt >fdsink</tt> on the broker will just wait
until it can write.</p>
<p>The second one is more complex: the shared memory areas are announced over the
control socket when they are ready, so this part gets done correctly for free
by <tt >shmsrc</tt>. But the control sockets need to exist when <tt >shmsrc</tt> tries to
connect to them (this happens when going from READY to PAUSED). For now, my
workaround is to <tt >sleep()</tt> for 2 seconds when <tt >sandboxeddecodebin</tt> goes
from NULL to READY, after launching the subprocess. With this, the control
sockets are very likely to be created when <tt >shmsrc</tt> goes from READY to
PAUSED.</p>
<p>This is obviously very hackish , and I think I would prefer to use
<a  href="http://developer.gnome.org/gio/2.32/GFileMonitor.html">GFileMonitors</a> to check when the sockets are created. Also, I don't know if
it's better to do that in <tt >sandboxeddecodebin</tt> (blocking the switch to READY,
but using that file monitoring instead of a <tt >sleep()</tt>, or going to READY
asynchronously if that's possible?) or in <tt >shmsrc</tt> (in which case I think it
should be optional and probably make <tt >shmsrc</tt> go to PAUSED asynchronously).</p>
</div>
<div  id="making-preroll-work">
<h3>Making Preroll work</h3>
<p>On the broker side, we have another tricky situation. We typically run a
pipeline that contains all of this (the parts between angle brackets are
outside of <tt >sandboxeddecodebin</tt> and given as examples):</p>
<pre >
&lt;filesrc&gt; ! fdsink (passes data to gst-decoder)
shmsrc (gets data from gst-decoder) ! gdpdepay ! &lt;autoaudiosink&gt;
shmsrc (gets data from gst-decoder) ! gdpdepay ! &lt;autovideosink&gt;
</pre>
<p>This pipeline is atypical in that it has a sink that is not really at the
downstream end of it (<tt >fdsink</tt>, which <tt >sandboxeddecodebin</tt> uses to pass
data to <tt ><span >gst-decoder</span></tt>). Data would go through it, then through
<tt ><span >gst-decoder</span></tt> and its own pipeline, and then emerge back in the broker's
pipeline in the <tt >shmsrc</tt> elements.</p>
<p>This is a problem at the <a  href="http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-preroll.txt">preroll</a> phase. Preroll is what usually happens
when going to PAUSED: the sinks wait until they have a buffer to render before
committing the state to PAUSED. The issue with our pipeline, is that the &quot;real&quot;
sinks will only get the data they need to commit to the PAUSED state if <tt >fdsink</tt>
lets the data through, but <tt >fdsink</tt> only passes data once it is in PLAYING state
(apart maybe from one initial buffer). On top of that <tt >sandboxeddecodebin</tt>
is a subclass of <tt >GstBin</tt>. By default, <tt >GstBin</tt> only changes to the next
state (e.g.  PLAYING) once all its elements have reached the previous one (e.g.
PAUSED). This gives us a nice deadlock: the final (downstream) sinks are
waiting for data to come to them to commit their change to PAUSED, <tt >GstBin</tt>
is waiting for all its elements (including final sinks) to finish their
transition to PAUSED before asking them to go to PLAYING, and <tt >fdsink</tt> is
waiting to be asked to switch to PLAYING before it lets the data through (that
the final sinks are waiting on). My workaround to solve this deadlock is to
manually request <tt >fdsink</tt> to go to PLAYING when <tt >sandboxeddecodebin</tt> is
switching to PAUSED. That way, <tt >fdsink</tt> is &quot;one state ahead&quot; of the rest, and
lets the data go through. I haven't decided yet if it's a very ugly way of
solving that issue or if it's an awesome clever hack. If you have an idea of a
cleaner solution, feel free to suggest it in the comments!</p>
</div>
<div  id="analysis-of-open-file-descriptors">
<h3>Analysis of open file descriptors</h3>
<p>Once the privileges have been dropped, the sandboxed process is very limited in
what it can do, but it still can use all the fds that it has open, which might
be a way for it to escape the limitations we want to put on it. For instance,
imagine that the sandboxed process has an open fd on the device that contains
your home directory (say, <tt >/dev/sda</tt>). By reading it, it can access all your
data, even though the sandbox is designed not to let it open more files.</p>
<p>This precise example is very unlikely to happen in our case, but some less
obvious fds could lead to ways to escape the sandbox. That is why I think it is
necessary to analyse the file descriptors that are open in the sandboxed
process and to try to understand the risks they bring.</p>
<p>I took a &quot;snapshot&quot; of the open fds of <tt ><span >gst-decoder</span></tt> while it was decoding a video,
and here is what it looks like:</p>
<pre >
guijemont&#64;thirtytwo:~$ ls -lv /proc/5860/fd
total 0
lr-x------ 1 guijemont guijemont 64 2012-04-18 18:17 0 -&gt; pipe:[8348338]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 1 -&gt; /dev/pts/5
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 2 -&gt; /dev/pts/5
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 3 -&gt; anon_inode:[eventfd]
lr-x------ 1 guijemont guijemont 64 2012-04-18 18:17 4 -&gt; pipe:[8348342]
l-wx------ 1 guijemont guijemont 64 2012-04-18 18:17 5 -&gt; pipe:[8348342]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 6 -&gt; socket:[8358884]
lr-x------ 1 guijemont guijemont 64 2012-04-18 18:17 7 -&gt; pipe:[8359036]
l-wx------ 1 guijemont guijemont 64 2012-04-18 18:17 8 -&gt; pipe:[8359036]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 9 -&gt; anon_inode:[timerfd]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 10 -&gt; /run/shm/shmpipe. 5860.    0
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 11 -&gt; socket:[8358886]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 12 -&gt; socket:[8358887]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 13 -&gt; socket:[8358888]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 14 -&gt; /run/shm/shmpipe. 5860.    1
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 15 -&gt; socket:[8358890]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 16 -&gt; socket:[8358891]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 17 -&gt; socket:[8358892]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 18 -&gt; socket:[8358893]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 19 -&gt; socket:[8358894]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 20 -&gt; socket:[8358895]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 21 -&gt; socket:[8348346]
lrwx------ 1 guijemont guijemont 64 2012-04-18 18:17 22 -&gt; socket:[8348347]
</pre>
<p>I used the &quot;usual suspects&quot; (strace and gdb) to look further into this and
understand where each fd comes from, and try to get an idea of how necessary it
is and of how much of a risk it brings.</p>
<ul >
<li>O: that is <tt >stdin</tt>, and it is the pipe I create when starting <tt >sandboxme
<span >gst-decoder</span></tt>. Also, it is read only. I don't think an attacker could do much
with this, and we need it anyway.</li>
<li>1 and 2: <tt >stdout</tt> and <tt >stderr</tt>, plugged to the pseudo tty where my test
<tt ><span >gst-launch</span></tt> command was running. This is clearly not necessary, and could
be exploited for privilege escalation if there's a bad bug somewhere in
devpts.  I modified the code to make <tt >stdout</tt> and <tt >stderr</tt> point to
<tt >/dev/null</tt> instead when <tt ><span >gst-decoder</span></tt> is launched. There is an
environment variable that can prevent that from happening when one wants to
see the debug messages that are output by <tt ><span >gst-decoder</span></tt>.</li>
<li>3: This is an event fd used by the <a  href="http://developer.gnome.org/glib/2.32/glib-The-Main-Event-Loop.html#GMainContext">GMainContext</a>. I suspect that at least a
few of the components we run to decode our stuff needs a <a  href="http://developer.gnome.org/glib/2.32/glib-The-Main-Event-Loop.html#GMainLoop">GMainLoop</a>, and
therefore a <tt >GMainContext</tt>. And I don't think this is very dangerous,
though I don't know much about the complexity and safety of the event system.</li>
<li>4 and 5: this is a pipe used by the GLib unix signal code. Both ends of the
pipe are inside the sandbox, so I don't think this would be much of a
problem.</li>
<li>6 and 21: shm area control socket for audio. There is one fd created by
<tt >socket()</tt> that is bound to the right temporary file, then another fd is
created by <tt >accept()</tt> when the broker connects. We definitely need that if
we want to use shm, which I think we do for performance reasons (I did not
run benchmarks though).</li>
<li>7 and 8: pipe open by some code in <tt ><span >/usr/lib/frei0r-1/facedetect.so</span></tt> when
it is <tt >g_module_open()</tt>'ed. I don't think we need that at all, and it might
be a good motivation to try and not load all plugins. A limited risk though,
since both ends of the pipe are inside the sandbox.</li>
<li>9: a timer fd opened in the same conditions as the pipe of fds 7 and 8 (by
frei0r's facedetect). This one definitely looks like an unnecessary risk,
though I don't know how much of a risk it actually is.</li>
<li>10 and 14: these are the shared memory areas (one for audio, one for video),
so I think we definitely want them. The alternative would be to use regular
sockets instead to pass the buffers, but I fear it might cost us much in
performances for little added security, though this issue could deserve more
investigation.</li>
<li>11, 12, 15, 16, 17, 18, 19 and 20: these 8 fds are actually 4 socket pairs,
with each time both ends inside the sandbox. They are all created by
<tt >gst_poll_new()</tt>, by the following pieces of code:<ul>
<li><tt >shmsink</tt> in <tt >gst_shm_sink_start()</tt>. It does that twice: once for
audio, once for video.</li>
<li><tt >fdsrc</tt> in <tt >gst_fd_src_start()</tt>.</li>
<li>the system clock (in <tt >gst_system_clock_init()</tt>, via
<tt >gst_poll_new_timer()</tt>).</li>
</ul>
</li>
<li>13 and 22: shm area control socket for video. There is one fd created by
<tt >socket()</tt> that is bound to the right temporary file, then another fd is
created by <tt >accept()</tt> when the broker connects. We definitely need that if
we want to use shm, which I think we do for performance reasons (I did not
run benchmarks though).</li>
</ul>
</div>
<div  id="play-with-it">
<h3>Play with it!</h3>
<p>You can check out the code from its <a  href="https://github.com/guijemont/Sandboxed-Player">github repository</a>, instructions are
available <a  href="https://github.com/guijemont/Sandboxed-Player/blob/master/README.rst">here</a>.</p>
</div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2012/05/08/video-decoding-in-a-sandbox/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FOSDEM 2012 &#8211; can beer freeze?</title>
		<link>http://guij.emont.org/blog/2012/02/02/fosdem-2012-can-beer-freeze/</link>
		<comments>http://guij.emont.org/blog/2012/02/02/fosdem-2012-can-beer-freeze/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 16:38:08 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=265</guid>
		<description><![CDATA[Thanks to my awesome employer Igalia, I am flying tomorrow to the cold city of Brussels to attend FOSDEM 2012. I will give a lightning talk, Saturday at 13:40, about my balloon adventures at Nowhere, with an emphasis on how Free Software made it possible. Hopefully, this will motivate other Free Software hackers to get [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to my awesome employer <a href="http://www.igalia.com/">Igalia</a>, I am flying tomorrow to the cold city of Brussels to attend <a href="http://www.fosdem.org/">FOSDEM</a> 2012.</p>
<p><a href="http://www.fosdem.org"><img src="http://www.fosdem.org/promo/going-to" alt="I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting" /></a></p>
<p>I will give a <a href="http://fosdem.org/2012/schedule/event/balloonfreaks">lightning talk</a>, Saturday at 13:40, about my <a href="http://balloonfreaks.mooo.com/blog/">balloon adventures</a> at <a href="http://www.goingnowhere.org/">Nowhere</a>, with an emphasis on how Free Software made it possible. Hopefully, this will motivate other Free Software hackers to get out of their basement and hack in the &#8220;real&#8221; world :).<br />
The talk should be streamed live at this <a href="http://fosdem.org/2012/news/video-streaming-urls">url</a> (in the Ferrer room).</p>
<p>Many other Igalians will come (I think there will be 14 of us), <a href="http://fosdem.org/2012/schedule/event/gnome3a11y">and</a> <a href="http://fosdem.org/2012/schedule/event/libreplan">will</a> <a href="http://fosdem.org/2012/schedule/event/webappsgnome">give</a> <a href="http://fosdem.org/2012/schedule/event/webkit2">talks</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2012/02/02/fosdem-2012-can-beer-freeze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gstreamer and OpenCV for image stabilisation</title>
		<link>http://guij.emont.org/blog/2011/11/10/gstreamer-and-opencv-for-image-stabilisation/</link>
		<comments>http://guij.emont.org/blog/2011/11/10/gstreamer-and-opencv-for-image-stabilisation/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 10:37:34 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=183</guid>
		<description><![CDATA[I am now back from Prague where I gave a talk on image stabilisation (and my holiday pictures). Hopefully a video of the talk will soon be online. In the meantime, I would like to explain a bit my efforts in written form, with some details slightly updated from the talk (the code progressed a [...]]]></description>
			<content:encoded><![CDATA[<div class="document" id="gstreamer-and-opencv-for-image-stabilisation">
<p>I am now back from <a class="reference external" href="http://guij.emont.org/blog/2011/10/23/prague-we-meet-again/">Prague</a> where I gave a <a class="reference external" href="http://gstreamer.freedesktop.org/conference/speakers.html#emont">talk</a> on image stabilisation (and my holiday pictures). Hopefully a video of the talk will soon be online. In the meantime, I would like to explain a bit my efforts in written form, with some details slightly updated from the talk (the code progressed a bit since then).</p>
<p><b>UPDATE:</b> The talk is now <a href="http://gstconf.ubicast.tv/videos/time-lapse-and-stabilizing-a-sequence-of-images/">online</a>.</p>
<p>I got interested in the issues of image stabilisation through a helium balloon photography <a class="reference external" href="http://balloonfreaks.mooo.com/blog/">project</a> in which I participated. I want to make a nice time lapse video from the pictures I have taken, but they were taken from a camera that was moving, which would make the result <em>very</em> shaky without some kind of postprocessing.</p>
<p>Thankfully, I work at <a class="reference external" href="http://www.igalia.com/">Igalia</a>, which means that on top of my personal time, I could spend on this project some company time (what we call internally our <em>hackfest</em> time, of up to 5 hours per week).</p>
<div id="original-problem-statement">
<h3>Original problem statement</h3>
<p>I have around 4h30 of pictures taken from a balloon 100 metres high. The pictures were taken at a rate of one per minute, which makes around 270 pictures. I want to make a nice <a class="reference external" href="http://en.wikipedia.org/wiki/Time_lapse">time lapse</a> out of it. Simply using the frames as is to build a video does not work well. Partly because I would probably be legally required to include a warning to epileptic people at the beginning of the video, but mostly because people actually watching it would wish they were epileptic to have a good excuse not to watch it.</p>
<p>This is due to the huge differences occurring between two consecutive frames.</p>
<p>Here is an example of two consecutive frames in that series:</p>
<p><a class="reference external image-reference" href="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7539.jpg"><img alt="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7539-300x225.jpg" src="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7539-300x225.jpg"></a><br />
<a class="reference external image-reference" href="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7540.jpg"><img alt="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7540-300x225.jpg" src="http://guij.emont.org/blog/wp-content/uploads/2011/11/IMG_7540-300x225.jpg"></a></p>
<p>As you can see, from one frame to the next, a lot of pixels would change. And that does not look pretty. It is also pretty obvious that they are both pictures of the same thing, and could be made to be pretty similar, mainly by rotating one of them, and maybe reprojecting it a bit so that things align properly even though the point of view changed a bit from one frame to the next.</p>
</div>
<div id="standing-on-the-shoulders-of-giants">
<h3>Standing on the shoulders of giants</h3>
<p>There was no question in my mind that I wanted to use <a class="reference external" href="http://gstreamer.freedesktop.org/">GStreamer</a> for the task, by writing an element or set of elements to do the stabilisation. The two big advantages of this approach are:</p>
<ul class="simple">
<li>I can benefit from all the other elements of GStreamer, and I can easily do things like decode my pictures, turn them in a video, stabilise it and encode it in a format of my choice, all in one command.</li>
<li>Others could easily reuse my work, potentially in ways I could not think of.  One idea would be to integrate that in <a class="reference external" href="http://www.pitivi.org/">PiTiVi</a> in the future.</li>
</ul>
<p>Then, after some research, I realised that <a class="reference external" href="http://opencv.willowgarage.com/wiki/">OpenCV</a> provides a lot of the tools needed for the task as well.</p>
<p>Since I am still in a prototyping/research stage, and I hate to write loads of boilerplate, I am using python for that project, though a later rewrite in <tt class="docutils literal">C</tt> or <tt class="docutils literal">C++</tt> is not impossible.</p>
</div>
<div id="first-things-first">
<h3>First things first</h3>
<p>I will not present things exactly in the order I researched them, but rather in the order I should have researched them: starting with a simpler problem, then getting into the complications of my balloon problem.</p>
<p>The simpler problem at hand is presented to you by Joe the Hippo:</p>
<p><video controls=""><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/shaky-hippo.webm" type="video/webm"><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/shaky-hippo.ogg" type="video/ogg"><br />
</video><br />
<br /><a href="http://guij.emont.org/blog/wp-content/uploads/videos/shaky-hippo.webm">Joe the shaky hippo (video)</a>
<p>As you can see, Joe almost looks like he&#8217;s on a boat. He isn&#8217;t, but the cameraman is, and the video was taken with a lot of zoom. The movement in that video stream has a particularity that can make things simpler: the position of a feature on the screen does not change much from one frame to the next, because a very short amount of time happens between them. We will see that some potentially very useful algorithms take advantage of that particularity.</p>
</div>
<div id="the-steps-of-image-stabilisation">
<h3>The steps of image stabilisation</h3>
<p>As I see it for the moment, there are two basic steps in image stabilisation:</p>
<ol class="arabic simple">
<li>Find the <a class="reference external" href="http://en.wikipedia.org/wiki/Optical_flow">optical flow</a> (i.e. the movement) between two frames</li>
<li>Apply a transformation that reverts that movement, on a global (frame) scale</li>
</ol>
<p>Step 2. is made rather easy by <a class="reference external" href="http://opencv.willowgarage.com/wiki/">OpenCV</a> with the <a class="reference external" href="http://opencv.itseez.com/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography">findHomography()</a> and <a class="reference external" href="http://opencv.itseez.com/modules/imgproc/doc/geometric_transformations.html#warpperspective">warpPerspective()</a> functions, so we won&#8217;t talk much about it here.</p>
</div>
<div id="id1">
<h3>Optical flow</h3>
<p>For all that matters in this study, we can say that for each frame the optical flow is represented by two lists of point coordinates <em>origins</em> and <em>destinations</em>, such that the feature at the coordinate <em>origins[i]</em> in the previous frame is at the coordinate <em>destinations[i]</em> in the current frame.</p>
<p>Optical flow algorithms can be separated in two classes, depending on whether they provide the flow for all pixels (<a class="reference internal" href="#dense-optical-flow">Dense optical flow</a> algorithms) or only for selected pixels (<a class="reference internal" href="#sparse-optical-flow">Sparse optical flow</a> algorithms). Both classes can theoretically provide us with the right data (<em>origins</em> and <em>destinations</em> point lists) to successfully compute the opposite transformation we want to apply using <a class="reference external" href="http://opencv.itseez.com/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography">findHomography()</a>.</p>
<p>I tried one algorithm of each class, choosing the ones that seemed popular to me after reading a bit of <a class="citation-reference" href="#bradski2008" id="id2">[Bradski2008]</a>. Here is what I managed to do with them.</p>
<div id="dense-optical-flow">
<h4>Dense optical flow</h4>
<p>I tried to use OpenCV&#8217;s implementation of the <em>Horn-Schunck</em> algorithm <a class="citation-reference" href="#horn81" id="id3">[Horn81]</a>. I don&#8217;t know if I used it incorrectly, or if the algorithm simply cannot be applied to that situation, but this is all I could do to Joe with that:</p>
<p><video controls=""><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/hippo-hs.webm" type="video/webm"><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/hippo-hs.ogg" type="video/ogg"><br />
</video><br />
<a href="http://guij.emont.org/blog/wp-content/uploads/videos/hippo-hs.webm">Now Joe is shaky and flickery</a>
<p>As you can see, this basically <em>added</em> flickering.  Since that, I did not find time to improve this case before I realised that this algorithm is considered as <a class="reference external" href="http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html#calcopticalflowhs">obsolete</a> in OpenCV, and the new python bindings do not include it.</p>
<p>Note that this does not mean that dense optical flow sucks: David Jordan, a Google Summer of Code student, does <a class="reference external" href="https://gitorious.org/~dmj726/gstreamer/dmj726s-gst-plugins-bad/commits/optical-flow">awesome</a> <a class="reference external" href="http://vimeo.com/30639307">things</a> with a dense algorithm by Proesmans et al. <a class="citation-reference" href="#proesmans94" id="id4">[Proesmans94]</a>.</p>
</div>
<div id="sparse-optical-flow">
<h4>Sparse optical flow</h4>
<p>I played with the <em>Lucas-Kanade</em> algorithm <a class="citation-reference" href="#lucas81" id="id5">[Lucas81]</a>, with the implementation provided by OpenCV. Once I managed to find a good set of parameters (which are now the default in the <tt class="docutils literal">opticalflowfinder</tt> element), I got pretty good results:</p>
<p><video controls=""><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/stabler-hippo.webm" type="video/webm"><br />
  <source src="http://guij.emont.org/blog/wp-content/uploads/videos/stabler-hippo.ogg" type="video/ogg"><br />
</video><br />
Joe enjoys the stability of the river bank, undisturbed by the movements of the water (<a href="http://guij.emont.org/blog/wp-content/uploads/videos/stabler-hippo.webm">video</a>)
<p>And it is quite fast too. On my laptop (with an i5 processor), I can stabilise <em>Joe the hippo</em> in real time <a class="footnote-reference" href="#id7" id="id6">[1]</a> (it is only a 640&#215;480 video, though).</p>
<table class="docutils footnote" frame="void" id="id7" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id6">[1]</a></td>
<td>For those who attended my talk at the Gstreamer Conference 2011: yes, now it is proper real time, I optimised the code a bit.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="the-balloon-problem">
<h3>The balloon problem</h3>
<p>As we seen in the previous section, for a shaky hippo video, [Horn81] isn&#8217;t any help, but [Lucas81] is pretty efficient. But can they be of any use for my balloon problem?</p>
<div id="unsuccessful-results">
<h4>Unsuccessful results</h4>
<p>I won&#8217;t show any video here, because there is nothing much to see. Instead, an explanation in pictures that show how the algorithms rate for the balloon time lapse.</p>
<p>This is what <em>Horn-Schunck</em> can do:</p>
<p><a class="reference external image-reference" href="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-hs.png"><img alt="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-hs-300x112.png" src="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-hs-300x112.png"></a></p>
<p>The picture shows two consecutive frames in the time lapse (the older is on the left). Each of the coloured lines goes from a point on the first image to the corresponding point on the second one, according to the algorithm (click on the image to see a larger version where the lines are more visible). Since <em>Horn-Schunck</em> is a dense algorithm, the coloured lines are only displayed for a random subset of points to avoid clutter.</p>
<p>Obviously, these lines show that the algorithm is completely wrong, and could not follow the big rotation happening between the two frames.</p>
<p>Does <em>Lucas-Kanade</em> rate better? Let&#8217;s see:</p>
<p><a class="reference external image-reference" href="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-lk.png"><img alt="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-lk-300x112.png" src="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-lk-300x112.png"></a></p>
<p>This is the same kind of visualisation, except that there is no need to chose a subset, since the algorithm already does that.</p>
<p>As for the result, it might be slightly less wrong than <em>Horn-Schunck</em>, but <em>Lucas-Kanade</em> does not seem to be of any help to us either.</p>
<p>The issue here, as said earlier, is that these two algorithms, like most optical flow algorithms, are making the assumption that a given feature will not move more than a few pixels from one frame to the next (for some value of &#8220;a few pixels&#8221;). This assumption is very clever for typical video streams taken at 25 or 30 frames per second. Unfortunately, it is obviously wrong in the case of our stream, where the camera has the time to move a lot between two frames (which are captured one minute apart).</p>
<p>Is all hope lost? Of course not!</p>
</div>
<div id="feature-recognition">
<h4>Feature recognition</h4>
<p>I found salvation in feature recognition. OpenCV provides a lot of feature recognition algorithms. I have tried only one of them so far, but I hope to find the time to compare it with others in the future.</p>
<p>The one I tried is SURF (for &#8220;Speeded Up Robust Features&#8221;, <a class="citation-reference" href="#bay06" id="id8">[Bay06]</a>). It finds &#8220;interesting&#8221; features in an image and descriptors associated with them. The descriptors it provides are invariant to rotation and scaling, which means that it is in theory possible to find the same descriptors from frame to frame.</p>
<p>To be able to efficiently compare the sets of frame descriptors I get for two consecutive frames, I use <a class="reference external" href="http://www.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN">FLANN</a>, which is well <a class="reference external" href="http://opencv.itseez.com/modules/flann/doc/flann_fast_approximate_nearest_neighbor_search.html">integrated</a> in OpenCV.</p>
<p>Here is a visualisation of how this method performs:</p>
<p><a class="reference external image-reference" href="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-surf.png"><img alt="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-surf-300x112.png" src="http://guij.emont.org/blog/wp-content/uploads/2011/11/balloon-surf-300x112.png"></a></p>
<p>As you can see, this is obviously much better! There might be a few outliers, but OpenCV&#8217;s <a class="reference external" href="http://opencv.itseez.com/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography">findHomography()</a> can handle them perfectly, and here&#8217;s a <a class="reference external" href="http://guij.emont.org/blog/wp-content/uploads/videos/balloon-201111052333.webm">proof video</a> (I am not including it in the article since it is quite high resolution).</p>
<p>Obviously, the result is not perfect yet (especially in the end), but it is quite promising, and I hope to be able to fix the remaining glitches sooner than later.</p>
</div>
</div>
<div id="show-me-the-code">
<h3>Show me the code!</h3>
<p>The code as well as a quick introduction on how to use it is available <a class="reference external" href="https://github.com/guijemont/GstStabilizer">on github</a>. Bugs and patches should be posted <a class="reference external" href="https://github.com/guijemont/GstStabilizer/issues">here</a>.</p>
<hr class="docutils">
<table class="docutils citation" frame="void" id="bradski2008" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id2">[Bradski2008]</a></td>
<td>G. Bradski and A. Kaehler , &#8220;Learning OpenCV&#8221;, ISBN 978-0-596-51613-0, 2008.
</td>
</tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="horn81" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id3">[Horn81]</a></td>
<td>B. K. P. Horn and B. G. Schunck, “Determining optical flow,” <em>Artificial Intelligence</em> 17 (1981): 185–203, 1981.  <a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.93.3092&amp;rep=rep1&amp;type=pdf">PDF</a>
</td>
</tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="proesmans94" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id4">[Proesmans94]</a></td>
<td>M. Proesmans, L. Van Gool, E. Pauwels, A. Oosterlinck, &#8220;Determination of optical flow and its discontinuities using non-linear diffusion&#8221;, J.-O. Eklundh (Ed.), <em>Computer vision</em> &#8212;  ECCV &#8217;94, <em>Lecture Notes in Comp.  Science</em>, Vol.  801, Springer, Berlin, 295–2304, 1994.  <a class="reference external" href="http://www.cse.iitk.ac.in/users/vision/dipen/references/proesmans-eccv94_1.pdf">PDF</a>
</td>
</tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="lucas81" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id5">[Lucas81]</a></td>
<td>B. Lucas and T. Kanade, &#8220;An Iterative Image Registration Technique with an Application to Stereo Vision&#8221;, Proc. of <em>7th International Joint Conference on Artificial Intelligence (IJCAI)</em>, 674–279 <a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.49.2019&amp;rep=rep1&amp;type=pdf">PDF</a>
</td>
</tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="bay06" rules="none">
<colgroup>
<col class="label">
<col></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id8">[Bay06]</a></td>
<td>H. Bay, T. Tuytelaars and L. Van Gool, “SURF: Speeded Up Robust Features”, <em>9th European Conference on Computer Vision</em>, 2006. <a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.2512&amp;rep=rep1&amp;type=pdf">PDF</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/11/10/gstreamer-and-opencv-for-image-stabilisation/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
<enclosure url="http://guij.emont.org/blog/wp-content/uploads/videos/shaky-hippo.ogg" length="22309965" type="audio/ogg" />
<enclosure url="http://guij.emont.org/blog/wp-content/uploads/videos/hippo-hs.ogg" length="31834330" type="audio/ogg" />
<enclosure url="http://guij.emont.org/blog/wp-content/uploads/videos/stabler-hippo.ogg" length="10029058" type="audio/ogg" />
		</item>
		<item>
		<title>Prague, we meet again!</title>
		<link>http://guij.emont.org/blog/2011/10/23/prague-we-meet-again/</link>
		<comments>http://guij.emont.org/blog/2011/10/23/prague-we-meet-again/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 22:45:29 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Tourisme]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=167</guid>
		<description><![CDATA[&#160; Tomorrow I will fly to Prague, going to the GStreamer Conference, then to LinuxCon Europe and ELCE. I&#8217;m excited to go back there, after having first visited this beautiful city in my last Eurotrip. I will give a talk at the GStreamer Conference about my work on image stabilisation, related to that balloon project [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_172" class="wp-caption aligncenter" style="width: 460px"><a href="http://guij.emont.org/blog/wp-content/uploads/2011/10/img_1040b_small.jpg"><img class="size-large wp-image-172 " title="Charles Bridge in Prague" src="http://guij.emont.org/blog/wp-content/uploads/2011/10/img_1040b_small-1024x684.jpg" alt="The bridge, seen from the Petřín lookout tower" width="450" height="300" /></a><p class="wp-caption-text">Karlův most (Charles bridge)</p></div>
<p>&nbsp;</p>
<p>Tomorrow I will fly to Prague, going to the <a href="http://gstreamer.freedesktop.org/conference/">GStreamer Conference</a>, then to <a href="https://events.linuxfoundation.org/events/linuxcon-europe">LinuxCon Europe</a> and <a href="https://events.linuxfoundation.org/events/embedded-linux-conference-europe/">ELCE</a>.<br />
I&#8217;m excited to go back there, after having first visited this beautiful city in my last <a href="http://guij.emont.org/blog/2011/08/03/eurotrip-starting-soon-desktop-summit-berlin/">Eurotrip</a>.<br />
I will give a <a href="http://gstreamer.freedesktop.org/conference/speakers.html#emont">talk</a> at the GStreamer Conference about my <a href="http://www.gitorious.org/gststabilizer">work</a> on image stabilisation, related to that <a href="http://balloonfreaks.mooo.com/blog/">balloon project</a> we did with <a href="http://nerochiaro.net/">Ugo</a>.<br />
I will go there sponsored by <a href="http://www.igalia.com/">Igalia</a>, with my friends and colleagues <a href="http://blogs.igalia.com/vjaquez/">Víctor</a>, <a href="http://base-art.net/">Philippe</a> and <a href="http://javiermunhoz.com/blog/">Javi</a>. Víctor will give a <a href="http://gstreamer.freedesktop.org/conference/speakers.html#jaquez">talk</a> as well, about the integration of syslink and GStreamer.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/10/23/prague-we-meet-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eurotrip starting soon: Desktop Summit, Berlin</title>
		<link>http://guij.emont.org/blog/2011/08/03/eurotrip-starting-soon-desktop-summit-berlin/</link>
		<comments>http://guij.emont.org/blog/2011/08/03/eurotrip-starting-soon-desktop-summit-berlin/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:03:02 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Tourisme]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=155</guid>
		<description><![CDATA[On Friday, I am going on a little Eurotrip that will lead me through Germany, France, Ireland and Czech Republic. The whole trip will last a month. If I manage better than some american guys, I will get to Berlin on Friday afternoon for the desktop summit: I am going there sponsored by the awesome [...]]]></description>
			<content:encoded><![CDATA[<p>On Friday, I am going on a little <a href="http://www.imdb.com/title/tt0356150/">Eurotrip</a> that will lead me through Germany, France, Ireland and Czech Republic. The whole trip will last a month.</p>
<p>If I manage better than <a href="http://www.youtube.com/watch?v=O5mIm4bPBWE">some american guys</a>, I will get to Berlin on Friday afternoon for the desktop summit:</p>
<p><img class="alignnone" title="I'm going to the Desktop Summit 2011 in Berlin" src="https://www.desktopsummit.org/sites/www.desktopsummit.org/files/DS2011banner.png" alt="" width="333" height="110" /></p>
<p>I am going there sponsored by the awesome company I work for, <a href="http://www.igalia.com/">Igalia</a>. Many other igalians will be there too.</p>
<p>Grilo will be well <a href="http://blogs.igalia.com/jasuarez/2011/07/29/grilo-ds2011-2/">represented</a>, with a short <a href="https://desktopsummit.org/program/sessions/integration-web-media-lookup-gnome-shell-grilo">talk</a> by Philippe on his integration work of Grilo with the Gnome Shell, and a <a href="http://wiki.desktopsummit.org/Workshops_&amp;_BoFs/2011/Developing_applications_with_Grilo">hacking session</a> with Juan and myself.</p>
<p>I will stay in Berlin until the 15th of August, to attend the <a href="https://live.gnome.org/Hackfests/Introspection2011">GObject Introspection hackfest</a>, where I will also be sponsored by Igalia. I should admit I don&#8217;t know much about the internals of GI yet, but I am excited to &#8220;learn by hacking&#8221; in the company of great hackers!</p>
<p>Then I will continue my Eurotrip, but that is another story.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/08/03/eurotrip-starting-soon-desktop-summit-berlin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with balloons</title>
		<link>http://guij.emont.org/blog/2011/05/09/playing-with-balloons/</link>
		<comments>http://guij.emont.org/blog/2011/05/09/playing-with-balloons/#comments</comments>
		<pubDate>Mon, 09 May 2011 08:00:56 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=142</guid>
		<description><![CDATA[These days, I&#8217;m spending a big part of my free time on a nice project with a few friends. That&#8217;s a project involving a balloon. We have recently started a blog called Balloon Freaks to talk about this, you might want to check it out.]]></description>
			<content:encoded><![CDATA[<p>These days, I&#8217;m spending a big part of my free time on a nice project with a few friends. That&#8217;s a project involving a balloon. We have recently started a blog called <a href="http://balloonfreaks.mooo.com/blog/">Balloon Freaks</a> to talk about this, you might want to check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/05/09/playing-with-balloons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blog back online</title>
		<link>http://guij.emont.org/blog/2011/04/27/blog-back-online/</link>
		<comments>http://guij.emont.org/blog/2011/04/27/blog-back-online/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 22:02:13 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://guij.emont.org/blog/?p=124</guid>
		<description><![CDATA[I finally found the time to migrate my blog to the new server I have (the old server died a few weeks ago). I hope I managed to do the transition correctly, and that people following me through a feed reader and/or a planet won&#8217;t be flooded with a truckload of old articles. If that [...]]]></description>
			<content:encoded><![CDATA[<p>I finally found the time to migrate my blog to the new server I have (the old server died a few weeks ago).</p>
<p>I hope I managed to do the transition correctly, and that people following me through a feed reader and/or a planet won&#8217;t be flooded with a truckload of old articles. If that still happens, I apologise. Also, I know the alert readership that you are noticed that I went back to the default wordpress theme: this is by design (and a bit by laziness). I got tired of the old design, which was ugly anyway (it was hacked together from various bits by a very amateurish designer: me). So, here&#8217;s something sober, just like I want it to be.</p>
<p>As for more generic news, I am still happy, enjoying life in Barcelona, loving my job at <a href="http://www.igalia.com/">Igalia</a>, hacking on cool <a href="https://live.gnome.org/Grilo">Grilo</a> stuff (and sometime <a href="http://gstreamer.freedesktop.org/">GStreamer</a> stuff as well). Hopefully I will post some things regarding that in the not so distant future.</p>
<p>This might be difficult because most of my spare time these days is taken by what I call the &#8220;balloon project&#8221;, recently started with a few gifted friends of mine. More on that soon, I promise, as I have plenty of things to tell about this project that involves developments in a lot of domains in which I&#8217;d love to know more but am always discovering things, such as physics, electronics or computer science.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/04/27/blog-back-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fosdem</title>
		<link>http://guij.emont.org/blog/2011/01/22/fosdem-2/</link>
		<comments>http://guij.emont.org/blog/2011/01/22/fosdem-2/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 14:42:24 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">https://guij.emont.org/blog/?p=121</guid>
		<description><![CDATA[Like a few friends have stated, I am now saying it loud and clear: And for that I should thank the awesome company for which I work. I am sure great time will be had, as well as great conversations about free software, multimedia, technology, life, the universe and everything. See you all at FOSDEM!]]></description>
			<content:encoded><![CDATA[<div>
<p>Like <a href="http://blogs.igalia.com/mario/2011/01/22/some-updates-on-frogr-0-4-and-myself/">a</a> <a href="http://people.gnome.org/~csaavedra/news-2011-01.html#D19">few</a> <a href="http://tilloy.net/olivier/blog/post/2011/01/22/Going-to-FOSDEM">friends</a> have stated, I am now saying it loud and clear:<br />
<a href="http://www.fosdem.org"><img src="http://www.fosdem.org/promo/going-to" alt="I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting" /></a></p>
<p>And for that I should thank the awesome <a href="http://www.igalia.com/">company</a> for which I work. I am sure great time will be had, as well as great conversations about free software, multimedia, technology, life, the universe and everything.</p>
<p>See you all at FOSDEM!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2011/01/22/fosdem-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recent hacks: python with gdb to follow gstreamer</title>
		<link>http://guij.emont.org/blog/2010/11/09/recent-hacks-python-with-gdb-to-follow-gstreamer/</link>
		<comments>http://guij.emont.org/blog/2010/11/09/recent-hacks-python-with-gdb-to-follow-gstreamer/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 15:58:39 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>

		<guid isPermaLink="false">https://guij.emont.org/blog/?p=120</guid>
		<description><![CDATA[I&#8217;ve recently discovered one too little-known feature of gdb: you can script it with python. It&#8217;s even in the documentation, and there are nice tutorials available which I invite you to read. The two main cool things you can do in python, is define new commands, and new convenience functions. Unfortunately, as you can read [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently discovered one too little-known feature of gdb: you can script it with python. It&#8217;s even in the <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Python.html">documentation</a>, and there are <a href="http://sourceware.org/gdb/wiki/PythonGdbTutorial">nice tutorials available</a> which I invite you to read.</p>
<p>The two main cool things you can do in python, is define new commands, and new convenience functions. Unfortunately, as you can read in <a href="http://tromey.com/blog/?p=501">this article</a>, defining a new command requires a lot of boilerplate (and it&#8217;s the same for convenience functions).</p>
<p>Since I wanted to write a few commands, I couldn&#8217;t be bothered to copy-paste that boilerplate, so I ended up writing a nice magical class that makes registering a function easier. You can find that <a href="http://gitorious.org/junk/python_gdb_gst_adapter/blobs/master/gdb_auto_command.py#line19">here</a>.</p>
<p>With this new weapon in hand, I wrote new commands to be able to follow what happens in a <a href="http://www.gstreamer.net/data/doc/gstreamer/head/gstreamer-libs/html/GstAdapter.html">GstAdapter</a>. Basically, I wanted to be able to track the position in the original file of each byte that was going out of a given adapter. So I wrote some code to be called by gdb commands when some operations on a GstAdapter are done, doing the necessary calculations and storing, and voilà: I can print, with gdb, the file position of the data obtained with each call to gst_adapter_peek().</p>
<p>All the code and the gdb script can be found over <a href="http://gitorious.org/junk/python_gdb_gst_adapter">there</a>.</p>
<p>As you can see, a gdb script is still needed. I haven&#8217;t yet really tried to play with breakpoints in python, but I have a feeling this is not totally trivial, if at all possible. The other great limitation is speed. It feels like the calls to python stuff from gdb are very costly, and, in the case of GStreamer, don&#8217;t expect smooth playing if you use some gdb command implemented in python for every buffer transmitted.</p>
<p>Conclusion: it&#8217;s got limits, but overall, this ability to enhance gdb with python allows you to do things you couldn&#8217;t do easily otherwise, like store data in complex structures for your debugging, and prototype easily some debugging actions you want to do, where the only alternative is to write it in C and include it in the application/library you are debugging.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2010/11/09/recent-hacks-python-with-gdb-to-follow-gstreamer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New job, new flat: new life!</title>
		<link>http://guij.emont.org/blog/2010/10/05/new-job-new-flat-new-life/</link>
		<comments>http://guij.emont.org/blog/2010/10/05/new-job-new-flat-new-life/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 14:46:13 +0000</pubDate>
		<dc:creator>guijemont</dc:creator>
				<category><![CDATA[Boulot]]></category>
		<category><![CDATA[Geekeries]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">https://guij.emont.org/blog/?p=119</guid>
		<description><![CDATA[You might have noticed one way or another, that I have just started a new job at Igalia. I&#8217;m very excited about joining a company that seems to try and do everything the right way™, and with really great people. At least for starters, and to flex my hacking muscles a bit, I&#8217;m going to hack on [...]]]></description>
			<content:encoded><![CDATA[<p>You might have noticed <a href="http://identi.ca/notice/53375548">one way</a> or <a href="http://www.igalia.com/nc/igalia-247/igalian/item/gemont/">another</a>, that I have just started a new job at <a href="http://www.igalia.com/">Igalia</a>. I&#8217;m very excited about joining a company that seems to try and do everything the right way™, and with really great people.</p>
<p>At least for starters, and to flex my hacking muscles a bit, I&#8217;m going to hack on various <a href="http://www.gstreamer.net/">gstreamer</a> stuff, which is always fun. Also, I think this will be my first post to appear on <a href="http://planet.igalia.com/">planet Igalia</a>, so: HI PLANET READERS!</p>
<p>Oh yeah, as the title says, I&#8217;ve just changed flat, am now living in a great flat in a brand new building with cool flatmates, so that&#8217;s good news as well! And yes, I&#8217;m still in Barcelona, now in Poble Sec, which proves a cool area so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://guij.emont.org/blog/2010/10/05/new-job-new-flat-new-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

