viewgit/index.php:465 Only variables should be passed by reference [2048]
viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]
# # -*- coding: utf-8 -*- # # Implementazione del Widget per gestire il video # # This file is part of RaiTV # # RaiTV is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # RaiTV is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RaiTV; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import pygtk, gtk, gst, cairo, threading, time class GstPlayer(threading.Thread): def __init__(self, xid, video): threading.Thread.__init__(self) self.xid = xid self.video = video self.exit_required = False self.loading = False self.daemon = True def set_sink(self, sink): assert self.xid self.imagesink = sink self.imagesink.set_xwindow_id(self.xid) def on_sync_message(self, bus, message): if message.structure is None: return if message.structure.get_name() == 'prepare-xwindow-id': gtk.gdk.threads_enter() self.set_sink(message.src) message.src.set_property("force-aspect-ratio", True) gtk.gdk.threads_leave() def on_message(self, bus, message): if message.type == gst.MESSAGE_ERROR: err, debug = message.parse_error() print err, debug elif message.type == gst.MESSAGE_LATENCY: print message.parse_latency() elif message.type == gst.MESSAGE_BUFFERING: if message.parse_buffering() is 100: self.play() self.loading = False def is_loading(self): return self.loading def run(self): self.player = gst.element_factory_make("playbin", "player") self.player.set_property bus = self.player.get_bus() bus.enable_sync_message_emission() bus.add_signal_watch() bus.connect("sync-message::element", self.on_sync_message) bus.connect("message", self.on_message) self.loading = True self.player.set_property("uri", self.video) self.pause() while not self.exit_required: pass self.player.set_state(gst.STATE_NULL) def exit(self): self.player.set_state(gst.STATE_NULL) self.exit_required = True def pause(self): if self.player is not None: self.player.set_state(gst.STATE_PAUSED) def play(self): self.player.set_state(gst.STATE_PLAYING) self.loading = False self.playing = True class VideoWidget(gtk.DrawingArea): def __init__(self, loader): self.loader = loader ## Creo la drawing area e la coloro ## di nero gtk.DrawingArea.__init__(self) self.set_size_request(240,240) self.unset_flags(gtk.DOUBLE_BUFFERED) ## Connetto l'expose-event self.connect("expose-event", self.colorize) self.playing = False self.player = None def colorize(self, widget, event): """Quando la finestra viene creata la coloriamo di nero. Poi sarà tutto lavoro per gstreamer""" ## Ci permettiamo di disegnare sopra il filmato ## se e solo se non c'è un filmato che sta andando! :) if not self.playing: cr = self.window.cairo_create() ## Non facciamo lavoro extra e coloriamo solo ciò ## che è stato scoperto cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) cr.clip() width, height = self.window.get_size() cr.set_source_rgb(0,0,0) cr.rectangle(0,0,width,height) cr.fill() pixbuf = gtk.gdk.pixbuf_new_from_file(self.loader.UIPath("rai_logo.png")) x = pixbuf.get_width() y = pixbuf.get_height() cr.set_source_pixbuf(pixbuf,max((width-x)/2,0),max((height-y)/2,0)) cr.rectangle(max((width - x)/2,0),max((height-y)/2,0),x,y) cr.fill() return def load_video(self, uri): """Start video playing with the specified URI""" ## Stoppiamo ogni video if self.playing: self.stop() self.player = GstPlayer(self.window.xid, uri) self.player.start() self.player.pause() self.playing = True ## Aspettiamo 5 secondi def pause(self): if self.player is not None: self.player.pause() def stop(self): self.playing = False if self.player is not None: self.player.exit() self.player.join(2) if self.player.isAlive(): print " => Ops, l'ho ucciso brutalmente" del self.player self.repaint() def repaint(self): if self.window is not None: width, height = self.window.get_size() self.queue_draw_area(0,0,width,height) def play(self): if self.player is not None: if self.playing is True: self.stop() self.playing = True self.player.play() def reset(self): pass