Created
March 15, 2011 19:03
-
-
Save joshdoe/871243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GstPlayer(object): | |
sub_area = 0 | |
middle_area = 0 | |
nAccumFrames = 0 | |
def __init__(self, videowidget): | |
self.playing = False | |
self.vw = videowidget | |
self.vw.player = self | |
# create our pipeline, and connect our bus_handler | |
self.pipeline = gst.Pipeline() | |
self.bus = self.pipeline.get_bus() | |
self.bus.enable_sync_message_emission() | |
self.bus.add_signal_watch() | |
self.bus.connect('message', self.on_message) | |
self.bus.connect('sync-message::element', self.on_sync_msg) | |
self.src = gst.element_factory_make('filesrc') | |
arfparse = gst.element_factory_make('arfparse') | |
self.crop = gst.element_factory_make('videocrop') | |
self.blur = gst.element_factory_make('cvsmooth') | |
self.identity = gst.element_factory_make('identity') | |
csp = gst.element_factory_make('ffmpegcolorspace') | |
vsink = gst.element_factory_make('dshowvideosink') | |
# configure elements | |
self.identity.connect('handoff', self.handoff) | |
# populate combobox with blur types | |
# for prop in self.blur.props: | |
# type_name = gobject.type_name(prop.value_type.fundamental) | |
# if type_name == 'GEnum': | |
# if prop.name == 'type': | |
# for key, val in prop.enum_class.__enum_values__.iteritems(): | |
# self.liststore.append([val.value_name, int(val)]) | |
# self.blur.props.type = 1 | |
# self.combobox.set_active(0) # FIXME: don't hardcode, but translate model index | |
# Assemble pipeline | |
self.pipeline.add(self.src, arfparse, self.crop, self.blur, self.identity, csp, vsink) | |
gst.element_link_many(self.src, arfparse, self.crop, self.blur, self.identity, csp, vsink) | |
def on_message(self, bus, message): | |
print 'Got msg!' | |
t = message.type | |
if t == gst.MESSAGE_ERROR: | |
err, debug = message.parse_error() | |
print "Error: %s" % err, debug | |
if self.on_eos: | |
self.on_eos() | |
self.playing = False | |
elif t == gst.MESSAGE_EOS: | |
if self.on_eos: | |
self.on_eos() | |
self.playing = False | |
def on_sync_msg(self, bus, msg): | |
print 'Got sync msg!' | |
if msg.structure is None: | |
return | |
# if msg.structure.get_name() == 'prepare-xwindow-id': | |
# msg.src.set_xwindow_id(self.vw.winId()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment