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

« back to all changes in this revision

Viewing changes to pitivi/elements/extractionsink.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/extractionsink.py
4
 
#
5
 
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
6
 
# Copyright (c) 2011, Benjamin M. Schwartz <bens@alum.mit.edu>
7
 
#
8
 
# This program is free software; you can redistribute it and/or
9
 
# modify it under the terms of the GNU Lesser General Public
10
 
# License as published by the Free Software Foundation; either
11
 
# version 2.1 of the License, or (at your option) any later version.
12
 
#
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
# Lesser General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU Lesser General Public
19
 
# License along with this program; if not, write to the
20
 
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21
 
# Boston, MA 02110-1301, USA.
22
 
 
23
 
"""
24
 
Extract audio samples without storing the whole waveform in memory
25
 
"""
26
 
 
27
 
import array
28
 
import gobject
29
 
gobject.threads_init()
30
 
import gst
31
 
from pitivi.utils import native_endianness, call_false
32
 
 
33
 
 
34
 
class ExtractionSink(gst.BaseSink):
35
 
 
36
 
    """
37
 
    Passes audio data directly to a provided L{Extractee}
38
 
    """
39
 
 
40
 
    caps = gst.Caps(
41
 
        "audio/x-raw-float, width=(int) 32, "
42
 
        "endianness = (int) %s, "
43
 
        "channels = (int) 1,"
44
 
        "rate = (int) [1, 96000]"
45
 
        % native_endianness)
46
 
 
47
 
    __gsttemplates__ = (
48
 
        gst.PadTemplate(
49
 
            "sink",
50
 
            gst.PAD_SINK,
51
 
            gst.PAD_ALWAYS,
52
 
            caps),)
53
 
 
54
 
    def __init__(self):
55
 
        gst.BaseSink.__init__(self)
56
 
        self.props.sync = False
57
 
        self.rate = 0
58
 
        self.channels = 0
59
 
        self.reset()
60
 
        self._cb = None
61
 
 
62
 
    def set_extractee(self, extractee):
63
 
        self.extractee = extractee
64
 
 
65
 
    def set_stopped_cb(self, cb):
66
 
        self._cb = cb
67
 
 
68
 
    def reset(self):
69
 
        self.samples = array.array('f')
70
 
        self.extractee = None
71
 
 
72
 
    def do_set_caps(self, caps):
73
 
        if not caps[0].get_name() == "audio/x-raw-float":
74
 
            return False
75
 
        self.rate = caps[0]["rate"]
76
 
        self.channels = caps[0]["channels"]
77
 
        return True
78
 
 
79
 
    def do_render(self, buf):
80
 
        if self.extractee is not None:
81
 
            self.extractee.receive(array.array('f', buf.data))
82
 
        return gst.FLOW_OK
83
 
 
84
 
    def do_preroll(self, buf):
85
 
        return gst.FLOW_OK
86
 
 
87
 
    def do_event(self, ev):
88
 
        self.info("Got event of type %s" % ev.type)
89
 
        if ev.type == gst.EVENT_EOS:
90
 
            if self._cb:
91
 
                gobject.idle_add(call_false, self._cb)
92
 
        return gst.FLOW_OK
93
 
 
94
 
gobject.type_register(ExtractionSink)