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. self.player.set_state(gst.STATE_PAUSED)
  95.  
  96. def play(self):
  97. self.player.set_state(gst.STATE_PLAYING)
  98. self.loading = False
  99.  
  100.  
  101. class VideoWidget(gtk.DrawingArea):
  102.  
  103. def __init__(self, loader):
  104.  
  105. self.loader = loader
  106.  
  107. ## Creo la drawing area e la coloro
  108. ## di nero
  109. gtk.DrawingArea.__init__(self)
  110.  
  111. self.set_size_request(240,240)
  112. self.unset_flags(gtk.DOUBLE_BUFFERED)
  113.  
  114. ## Connetto l'expose-event
  115. self.connect("expose-event", self.colorize)
  116.  
  117. self.playing = False
  118. self.player = None
  119.  
  120.  
  121. def colorize(self, widget, event):
  122. """Quando la finestra viene creata la coloriamo di
  123. nero. Poi sarà tutto lavoro per gstreamer"""
  124.  
  125. ## Ci permettiamo di disegnare sopra il filmato
  126. ## se e solo se non c'è un filmato che sta andando! :)
  127.  
  128. if not self.playing:
  129. cr = self.window.cairo_create()
  130. ## Non facciamo lavoro extra e coloriamo solo ciò
  131. ## che è stato scoperto
  132. cr.rectangle(event.area.x, event.area.y,
  133. event.area.width, event.area.height)
  134.  
  135. cr.clip()
  136.  
  137. width, height = self.window.get_size()
  138.  
  139. cr.set_source_rgb(0,0,0)
  140. cr.rectangle(0,0,width,height)
  141. cr.fill()
  142.  
  143. pixbuf = gtk.gdk.pixbuf_new_from_file(self.loader.UIPath("rai_logo.png"))
  144. x = pixbuf.get_width()
  145. y = pixbuf.get_height()
  146. cr.set_source_pixbuf(pixbuf,max((width-x)/2,0),max((height-y)/2,0))
  147.  
  148.  
  149. cr.rectangle(max((width - x)/2,0),max((height-y)/2,0),x,y)
  150. cr.fill()
  151.  
  152. return
  153.  
  154.  
  155. def load_video(self, uri):
  156. """Start video playing with the specified URI"""
  157. ## Stoppiamo ogni video
  158. if self.playing:
  159. self.stop()
  160.  
  161. self.player = GstPlayer(self.window.xid, uri)
  162.  
  163. self.player.start()
  164. self.player.pause()
  165.  
  166. self.playing = True
  167.  
  168.  
  169. ## Aspettiamo 5 secondi
  170.  
  171.  
  172.  
  173. def pause(self):
  174. self.player.pause()
  175.  
  176. def stop(self):
  177. self.playing = False
  178. if self.player is not None:
  179. self.player.exit()
  180. self.player.join(2)
  181. if self.player.isAlive():
  182. print " => Ops, l'ho ucciso brutalmente"
  183. del self.player
  184.  
  185. self.repaint()
  186.  
  187. def repaint(self):
  188.  
  189. if self.window is not None:
  190. width, height = self.window.get_size()
  191. self.queue_draw_area(0,0,width,height)
  192.  
  193.  
  194.  
  195. def play(self):
  196. if self.player is not None:
  197. self.playing = True
  198. self.player.play()
  199.  
  200.  
  201.  
  202.  
  203. def reset(self):
  204. pass