Misc: Add make target to generate debian package

This makes it easier to test that the Debian packaging scripts work.
Note: the Ubuntu PPAs and the OpenSUSE Build Service build the source
package directly and won't be using this make target.
Debian packaging: Break up long lines

This makes it easier to read and easier to see changes in a line-by-line
diff.
Port to Gstreamer 1.0

Note: This change will break many user configurations.  See
`docs/backwards-compatibility.md` for migration notes.

Gstreamer 1.0 has been out for more than a year now and is where the
majority of the upstream development is going nowadays.  This change will
make it easier to develop further more advanced features such as sound
analysis, support for testing Smart TVs with webcams and new UIs for stbt.

Using GStreamer 1.0 from Python is incompatible with Gstreamer 0.10 in
that Gstreamer 1.0:

1. Gstreamer 1.0 has a different C API to 0.10
2. Some of the elements and properties have been renamed in Gstreamer 1.0.
3. Gstreamer 1.0 uses GObject introspection for automatically generating
   Python bindings from the C API

Migration was mostly straightforward, but the changes to the
appsink/appsrc were quite tricky.  Because caps information is no longer
attached to buffers appsink now produces `GstSample`s rather than
`GstBuffers` which includes caps information.  Getting this right so the
caps can get through to the appsrc was a little fiddly.

The bigger issue are regressions in upstream GStreamer which affect our
hardware support.  We are fixing issues upstream but this means that you
may have to have a bleeding-edge GStreamer for certain hardware to work.
See `docs/backwards-compatibility.md` for specifics.

Notes:

* For GStreamer 1.0 vp8enc has replaced the property "speed" with
  "cpu-used" where speed=7 is the same as cpu-used=6.  Also the default
  quality settings have changed requiring {min,max}_quantizer to be set.
  See GStreamer BugZilla [#684206] for more information.
* Performance is significantly degraded (by a factor of ~4).  Based on
  profiling this seems to be related to it being slow to create buffers
  from numpy arrays as required for drawing notes on the saved/displayed
  video.  This will be improved in subsequent commits.
* on_new_sample is called as a GObject callback and should never throw.
  This was noticed as with Gstreamer 1.0 it requires a return value.  We
  should probably catch all exceptions thrown in any callback and work out
  how to signal errors some other way.
* pylint 0.25.1 which I have on my Debian testing machine doesn't
  understand gobject introspection imports so I've had to add a pylint
  disable to the import.  Upgrading to pylint 1.0.0 fixes this but in the
  interests of working with multiple pylint versions the disable remains.
* I've had to increase the default threshold in is_screen_black test as it
  seems, possibly with the move from `video/x-raw-yuv` to
  `video/x-raw,format=I420` that blacks aren't as black anymore, possibly
  as a result of GStreamer 1.0 choosing a different type of yuv in 0.10 or
  possibly due to changes introduced during the ffmpegcolorspace ->
  videoconvert change.

[#684206]: https://bugzilla.gnome.org/show_bug.cgi?id=684206
debugging: Dump internal GStreamer pipeline state on error

GStreamer has a debug feature where it can dump how a pipeline is wired
up as a graph.  This is very useful for debugging problems with the
GStreamer pipeline.  This commit adds the necessary hooks such that this
information may be dumped when an error occurs much like gst-launch-1.0
already behaves

The effect is that if `GST_DEBUG_DUMP_DOT_DIR` is defined in the
environment and an error occurs a GraphViz dot file will be written to that
directory.  You can then use `dot -T png -o image.png graph.dot` to convert
it to a PNG.

See [Running GStreamer Applications][1] in the GStreamer documentation for
more information.

[1]: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html
Don't skip test_that_video_index_is_written_on_eos on OS X

GStreamer 1.0's webmmux (from macports gstreamer1-gst-plugins-good 1.2.3
package) does work correctly on OS X.
(FAILING TEST) Don't skip test_save_video on OS X

GStreamer 1.0's webmmux does work correctly on OS X (see the previous
commit). However, test_save_video hangs indefinitely. I need to
investigate, but in the meantime I shouldn't hide the problem from
myself (or anyone else testing on OS X). test_save_video does pass on
Linux.
docs/backwards-compatibility.md: Document current hang with Blackmagic
Merge pull request #71 from wmanley/gst-1.0

Port to Gstreamer 1.0
travis: Tidy up list of packges to be installed

One per line and alphabetical order makes it easier to see changes in a
line-by-line diff.  The actual list of packages has not been changed.
stbt tv: Allow complex source pipelines with shell escaping

Previously if you had a stbt.conf like:

    source_pipeline=mysrc property="prop with spaces"

bash would get confused and would pass `property="prop` as `$2` and
separately pass `with` as `$3` and `spaces"` as `$4`.  Using `eval` fixes
this issue although it does make me slightly worried that if some bash
syntax inadvertently ended up in source_pipeline stbt tv could behave
oddly.

This is required for smart-tv support as, due to the complexities of
image processing `source_pipeline`s can require many complex parameters.
debugging: Add checking to gst_to_opencv

OpenCV requires video frames in BGR format.  Previously if you passed a
`GstSample` in another format (e.g. I420 or RGB) `gst_to_opencv` would
either produce a cryptic error message or silently continue having done
the wrong thing.

This commit fixes that by adding an assertion.  Admittedly you have to try
pretty hard to get your hands on a non BGR format `GstSample` but I've
managed it in the past and this would have saved me some debugging effort.
Self-Tests: Improve sandboxing

Take a copy of `stbt.conf` so tests are free to make modifications to it.
Also move `$XDG_CACHE_HOME` into test sandbox dir.  This will be useful
for smart TV support as the calibration and test programs will need to
generate videos for display on the TVs.
tests: refactoring: Use set_config consistently

Standardise on a way of setting configuration values in tests using the
recent work on improved test sandboxing and the introduction of
`_set_config()`.

The tests are now shorter, more declarative and easier to read.  This
helper function replaces a surprising diversity in the ways in which sed
was used.
Allow passing a numpy array as a template to match functions

This allows templates to be generated on-the-fly without having to create
intermediate image files.  This will be used for Smart TV support some of
our test patterns are generated from textual descriptions and we want to
match sub-images within them.  e.g. the "letters" test pattern looks like:

    ABCDEFG
    HIJKLMN
    OPQRSTU

and we want to check the locations of each of the letters to confirm that
they're in the right places.

Nonetheless it seems that this could be generally very useful.

Possible example uses:

* You are navigating a carousel of DVD box covers and want to check that
  it correctly wraps back to the beginning.  The code could look like:

        # Grab the currently shown DVD cover given that we know its
        # location and size:
        initial_dvd_cover = stbt.get_frame()[300:700,500:700]

        stbt.press("KEY_RIGHT")
        stbt.press_until_match("KEY_RIGHT", initial_dvd_cover)

* You have an image and you want to find out which way up it is being
  displayed:

        def get_orientation():
            arrow = cv2.imread("arrow.png")
            if matches(arrow):
                return 1
            elif matches(cv2.flip(arrow)):
                return -1
            else:
                raise RuntimeError("Can't find arrow")

Future work: This feature (and stb-tester in general) would really benefit
with some tutorial style documentation to help introduce concepts and
explain when the various features of stb-tester should be applied.
stbt.{Match,Motion}Timeout debug output shows values < 1

If you used `wait_for_match(..., timeout_secs=0.5)` the MatchTimeout
exception's message was "Didn't find match for ... within 0 seconds".

Note that stbt doesn't currently guarantee to process every frame
of video, so very small values for timeout_secs aren't as useful as you
might think. stbt does guarantee to process at least one frame (even if
`timeout_secs=0`).
stbt.MatchTimeout: Avoid verbose numpy representation

...of the template image (in the MatchTimeout exception message) when
the image was given as a numpy array (not a filename).

Commit 2c276e36 added the ability to pass a numpy array as a template
image to `wait_for_match` and other matching functions. But if no match
was found, the output was unnecessarily verbose:

    MatchTimeout: Didn't find match for '[[[255 255 255]
      [255 255 255]
      <snip>
      [176 176 176]]]' within 10 seconds.
Gstreamer 1.0: Improve performance back to pre-1.0 days

When migrating to GStreamer 1.0 we introduced a performance regression
slowing down stb-tester by a factor of 4 or so.  Based on profiling this
was due to it being slow to create buffers (`Gst.Buffer.new_wrapped`) from
the numpy arrays as required for drawing notes on the saved/displayed
video.  My best guess is that instead of doing a straight `memcpy` it was
iterating through each element copying a byte at a time.

This commit fixes these performance issues increases performance back to
stb-tester 0.18 levels.

Unfortunately some of the code is a little hairy.  The proper way to do
this with GStreamer 1.0 is to use `gst_buffer_map()` and access the data
through the returned `GstMapInfo` struct.  Unfortunately the `GstMapInfo`
isn't properly exposed in Python (see [bz #678663]) so instead I use
ctypes to call it more manually.  Note: this issue should be fixed in the
(as yet) unreleased python-gobject 3.12 (see [bz #710561]).

Every `gst_buffer_map()` must be accompanied with a `gst_buffer_unmap()`
and the data must only be accessed between these two calls.  To enforce
this in Python we use a `contextmanager` although this isn't perfect.
This means that the numpy array should not be used outside of the `with:`
statement and the data should be copied instead using `numpy.ndarray.copy`.

[bz #678663]: https://bugzilla.gnome.org/show_bug.cgi?id=678663
[bz #710561]: https://bugzilla.gnome.org/show_bug.cgi?id=710561
Display: Use GstSample in place of (numpy.ndarray, timestamp)

This commit increases performance by ~10% vs. stb-tester 0.18.  We do this
by avoiding copys.  Internally the numpy arrays are backed by the data
directly in the `Gst.Buffer`s.  Instead of 3 copies made during
`detect_match` only one is made now.

Internally we are now passing GstSample around instead of the (data,
timestamp) tuple.  This will be useful in the future the future for
synchronising readings against wall clock time as the `GstSegment`
associated with the buffer is required to correctly interpret the
timestamp.
gst_hacks.py compatibility with OS X

Dynamic libraries are ".dylib" not ".so" on OS X.

If I only do `ctypes.CDLL("libgstreamer-1.0.dylib")`, `dlopen` won't
find the library in `/opt/local/lib` (where GStreamer is installed by
the "macports" package manager), even though I'm using
`/opt/local/bin/python`. Adding `/opt/local/lib` to `DYLD_LIBRARY_PATH`
doesn't work either, I get all sorts of "Symbol not found" errors. So
I'm calculating the path from where GStreamer's GObject-Introspection
typelib data is installed. I've only tested this with macports.
Merge pull request #119 from wmanley/gst-1.0-performance-nocopy

Gstreamer 1.0: Improve performance back to pre-1.0 days