~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/elements/thumbnailsink.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# PiTiVi , Non-linear video editor
2
 
#
3
 
#       pitivi/elements/thumbnailsink.py
4
 
#
5
 
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
6
 
#
7
 
# This program is free software; you can redistribute it and/or
8
 
# modify it under the terms of the GNU Lesser General Public
9
 
# License as published by the Free Software Foundation; either
10
 
# version 2.1 of the License, or (at your option) any later version.
11
 
#
12
 
# This program is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
# Lesser General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU Lesser General Public
18
 
# License along with this program; if not, write to the
19
 
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
 
# Boston, MA 02110-1301, USA.
21
 
"""
22
 
GdkPixbuf thumbnail sink
23
 
"""
24
 
 
25
 
import gobject
26
 
import gst
27
 
import cairo
28
 
import array
29
 
from pitivi.utils import big_to_cairo_alpha_mask, big_to_cairo_red_mask, big_to_cairo_green_mask, big_to_cairo_blue_mask
30
 
 
31
 
 
32
 
class CairoSurfaceThumbnailSink(gst.BaseSink):
33
 
    """
34
 
    GStreamer thumbnailing sink element.
35
 
 
36
 
    Can be used in pipelines to generates gtk.gdk.Pixbuf automatically.
37
 
    """
38
 
 
39
 
    __gsignals__ = {
40
 
        "thumbnail": (gobject.SIGNAL_RUN_LAST,
41
 
                      gobject.TYPE_NONE,
42
 
                      (gobject.TYPE_PYOBJECT, gobject.TYPE_UINT64))
43
 
        }
44
 
 
45
 
    __gsttemplates__ = (
46
 
        gst.PadTemplate("sink",
47
 
                         gst.PAD_SINK,
48
 
                         gst.PAD_ALWAYS,
49
 
                         gst.Caps("video/x-raw-rgb,"
50
 
                                  "bpp = (int) 32, depth = (int) 32,"
51
 
                                  "endianness = (int) BIG_ENDIAN,"
52
 
                                  "alpha_mask = (int) %i, "
53
 
                                  "red_mask = (int)   %i, "
54
 
                                  "green_mask = (int) %i, "
55
 
                                  "blue_mask = (int)  %i, "
56
 
                                  "width = (int) [ 1, max ], "
57
 
                                  "height = (int) [ 1, max ], "
58
 
                                  "framerate = (fraction) [ 0, max ]"
59
 
                                  % (big_to_cairo_alpha_mask,
60
 
                                     big_to_cairo_red_mask,
61
 
                                     big_to_cairo_green_mask,
62
 
                                     big_to_cairo_blue_mask)))
63
 
        )
64
 
 
65
 
    def __init__(self):
66
 
        gst.BaseSink.__init__(self)
67
 
        self._width = 1
68
 
        self._height = 1
69
 
        self.set_sync(False)
70
 
 
71
 
    def do_set_caps(self, caps):
72
 
        self.log("caps %s" % caps.to_string())
73
 
        self.log("padcaps %s" % self.get_pad("sink").get_caps().to_string())
74
 
        self.width = caps[0]["width"]
75
 
        self.height = caps[0]["height"]
76
 
        if not caps[0].get_name() == "video/x-raw-rgb":
77
 
            return False
78
 
        return True
79
 
 
80
 
    def do_render(self, buf):
81
 
        self.log("buffer %s %d" % (gst.TIME_ARGS(buf.timestamp),
82
 
                                   len(buf.data)))
83
 
        b = array.array("b")
84
 
        b.fromstring(buf)
85
 
        pixb = cairo.ImageSurface.create_for_data(b,
86
 
            # We don't use FORMAT_ARGB32 because Cairo uses premultiplied
87
 
            # alpha, and gstreamer does not.  Discarding the alpha channel
88
 
            # is not ideal, but the alternative would be to compute the
89
 
            # conversion in python (slow!).
90
 
            cairo.FORMAT_RGB24,
91
 
            self.width,
92
 
            self.height,
93
 
            self.width * 4)
94
 
 
95
 
        self.emit('thumbnail', pixb, buf.timestamp)
96
 
        return gst.FLOW_OK
97
 
 
98
 
    def do_preroll(self, buf):
99
 
        return self.do_render(buf)
100
 
 
101
 
gobject.type_register(CairoSurfaceThumbnailSink)