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]

  1. #
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Implementazione del Widget per gestire il video
  5. #
  6. # This file is part of RaiTV
  7. #
  8. # RaiTV is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # RaiTV 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
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with RaiTV; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21.  
  22.  
  23. import pygtk, gtk, gst, cairo, threading, time
  24.  
  25. class GstPlayer(threading.Thread):
  26.  
  27. def __init__(self, xid, video):
  28. threading.Thread.__init__(self)
  29. self.xid = xid
  30. self.video = video
  31.  
  32. self.exit_required = False
  33. self.loading = False
  34.  
  35. self.daemon = True
  36.  
  37. def set_sink(self, sink):
  38. assert self.xid
  39. self.imagesink = sink
  40. self.imagesink.set_xwindow_id(self.xid)
  41.  
  42. def on_sync_message(self, bus, message):
  43.  
  44. if message.structure is None:
  45. return
  46. if message.structure.get_name() == 'prepare-xwindow-id':
  47. gtk.gdk.threads_enter()
  48.  
  49. self.set_sink(message.src)
  50. message.src.set_property("force-aspect-ratio", True)
  51. gtk.gdk.threads_leave()
  52.  
  53. def on_message(self, bus, message):
  54. if message.type == gst.MESSAGE_ERROR:
  55. err, debug = message.parse_error()
  56. print err, debug
  57. elif message.type == gst.MESSAGE_LATENCY:
  58. print message.parse_latency()
  59. elif message.type == gst.MESSAGE_BUFFERING:
  60. if message.parse_buffering() is 100:
  61. self.play()
  62. self.loading = False
  63.  
  64.  
  65. def is_loading(self):
  66. return self.loading
  67.  
  68. def run(self):
  69. self.player = gst.element_factory_make("playbin", "player")
  70.  
  71. self.player.set_property
  72. bus = self.player.get_bus()
  73. bus.enable_sync_message_emission()
  74. bus.add_signal_watch()
  75. bus.connect("sync-message::element", self.on_sync_message)
  76. bus.connect("message", self.on_message)
  77.  
  78. self.loading = True
  79.  
  80. self.player.set_property("uri", self.video)
  81.  
  82. self.pause()
  83.  
  84. while not self.exit_required:
  85. pass
  86.  
  87. self.player.set_state(gst.STATE_NULL)
  88.  
  89. def exit(self):
  90. self.player.set_state(gst.STATE_NULL)
  91. self.exit_required = True
  92.  
  93. def pause(self):
  94. if self.player is not None:
  95. self.player.set_state(gst.STATE_PAUSED)
  96.  
  97.  
  98. def play(self):
  99. self.player.set_state(gst.STATE_PLAYING)
  100. self.loading = False
  101.  
  102. self.playing = True
  103.  
  104.  
  105. class VideoWidget(gtk.DrawingArea):
  106.  
  107. def __init__(self, loader):
  108.  
  109. self.loader = loader
  110.  
  111. ## Creo la drawing area e la coloro
  112. ## di nero
  113. gtk.DrawingArea.__init__(self)
  114.  
  115. self.set_size_request(240,240)
  116. self.unset_flags(gtk.DOUBLE_BUFFERED)
  117.  
  118. ## Connetto l'expose-event
  119. self.connect("expose-event", self.colorize)
  120.  
  121. self.playing = False
  122. self.player = None
  123.  
  124.  
  125. def colorize(self, widget, event):
  126. """Quando la finestra viene creata la coloriamo di
  127. nero. Poi sarà tutto lavoro per gstreamer"""
  128.  
  129. ## Ci permettiamo di disegnare sopra il filmato
  130. ## se e solo se non c'è un filmato che sta andando! :)
  131.  
  132. if not self.playing:
  133. cr = self.window.cairo_create()
  134. ## Non facciamo lavoro extra e coloriamo solo ciò
  135. ## che è stato scoperto
  136. cr.rectangle(event.area.x, event.area.y,
  137. event.area.width, event.area.height)
  138.  
  139. cr.clip()
  140.  
  141. width, height = self.window.get_size()
  142.  
  143. cr.set_source_rgb(0,0,0)
  144. cr.rectangle(0,0,width,height)
  145. cr.fill()
  146.  
  147. pixbuf = gtk.gdk.pixbuf_new_from_file(self.loader.UIPath("rai_logo.png"))
  148. x = pixbuf.get_width()
  149. y = pixbuf.get_height()
  150. cr.set_source_pixbuf(pixbuf,max((width-x)/2,0),max((height-y)/2,0))
  151.  
  152. cr.rectangle(max((width - x)/2,0),max((height-y)/2,0),x,y)
  153. cr.fill()
  154.  
  155. return
  156.  
  157.  
  158. def load_video(self, uri):
  159. """Start video playing with the specified URI"""
  160. ## Stoppiamo ogni video
  161. if self.playing:
  162. self.stop()
  163.  
  164. self.player = GstPlayer(self.window.xid, uri)
  165.  
  166. self.player.start()
  167. self.player.pause()
  168.  
  169. self.playing = True
  170.  
  171.  
  172. ## Aspettiamo 5 secondi
  173.  
  174.  
  175.  
  176. def pause(self):
  177. if self.player is not None:
  178. self.player.pause()
  179.  
  180. def stop(self):
  181. self.playing = False
  182. if self.player is not None:
  183. self.player.exit()
  184. self.player.join(2)
  185. if self.player.isAlive():
  186. print " => Ops, l'ho ucciso brutalmente"
  187. del self.player
  188.  
  189. self.repaint()
  190.  
  191. def repaint(self):
  192.  
  193. if self.window is not None:
  194. width, height = self.window.get_size()
  195. self.queue_draw_area(0,0,width,height)
  196.  
  197.  
  198.  
  199. def play(self):
  200. if self.player is not None:
  201. if self.playing is True:
  202. self.stop()
  203. self.playing = True
  204. self.player.play()
  205.  
  206.  
  207.  
  208.  
  209. def reset(self):
  210. pass