<s> '''<STR_LIT>''' <EOL> from kivy . lib . gstplayer import GstPlayer , get_gst_version <EOL> from kivy . graphics . texture import Texture <EOL> from kivy . core . video import VideoBase <EOL> from kivy . logger import Logger <EOL> from kivy . clock import Clock <EOL> from kivy . compat import PY2 <EOL> from threading import Lock <EOL> from functools import partial <EOL> from os . path import realpath <EOL> from weakref import ref <EOL> if PY2 : <EOL> from urllib import pathname2url <EOL> else : <EOL> from urllib . request import pathname2url <EOL> Logger . info ( '<STR_LIT>' . format ( <EOL> '<STR_LIT:.>' . join ( map ( str , get_gst_version ( ) ) ) ) ) <EOL> def _on_gstplayer_buffer ( video , width , height , data ) : <EOL> video = video ( ) <EOL> if not video : <EOL> return <EOL> with video . _buffer_lock : <EOL> video . _buffer = ( width , height , data ) <EOL> def _on_gstplayer_message ( mtype , message ) : <EOL> if mtype == '<STR_LIT:error>' : <EOL> Logger . error ( '<STR_LIT>' . format ( message ) ) <EOL> elif mtype == '<STR_LIT>' : <EOL> Logger . warning ( '<STR_LIT>' . format ( message ) ) <EOL> elif mtype == '<STR_LIT:info>' : <EOL> Logger . info ( '<STR_LIT>' . format ( message ) ) <EOL> class VideoGstplayer ( VideoBase ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . player = None <EOL> self . _buffer = None <EOL> self . _buffer_lock = Lock ( ) <EOL> super ( VideoGstplayer , self ) . __init__ ( ** kwargs ) <EOL> def _on_gst_eos_sync ( self ) : <EOL> Clock . schedule_once ( self . _do_eos , <NUM_LIT:0> ) <EOL> def load ( self ) : <EOL> Logger . debug ( '<STR_LIT>' . format ( self . _filename ) ) <EOL> uri = self . _get_uri ( ) <EOL> wk_self = ref ( self ) <EOL> self . player_callback = partial ( _on_gstplayer_buffer , wk_self ) <EOL> self . player = GstPlayer ( uri , self . player_callback , <EOL> self . _on_gst_eos_sync , _on_gstplayer_message ) <EOL> self . player . load ( ) <EOL> def unload ( self ) : <EOL> if self . player : <EOL> self . player . unload ( ) <EOL> self . player = None <EOL> with self . _buffer_lock : <EOL> self . _buffer = None <EOL> self . _texture = None <EOL> def stop ( self ) : <EOL> super ( VideoGstplayer , self ) . stop ( ) <EOL> self . player . stop ( ) <EOL> def pause ( self ) : <EOL> super ( VideoGstplayer , self ) . pause ( ) <EOL> self . player . pause ( ) <EOL> def play ( self ) : <EOL> super ( VideoGstplayer , self ) . play ( ) <EOL> self . player . set_volume ( self . volume ) <EOL> self . player . play ( ) <EOL> def seek ( self , percent ) : <EOL> self . player . seek ( percent ) <EOL> def _get_position ( self ) : <EOL> return self . player . get_position ( ) <EOL> def _get_duration ( self ) : <EOL> return self . player . get_duration ( ) <EOL> def _set_volume ( self , value ) : <EOL> self . _volume = value <EOL> if self . player : <EOL> self . player . set_volume ( self . _volume ) <EOL> def _update ( self , dt ) : <EOL> buf = None <EOL> with self . _buffer_lock : <EOL> buf = self . _buffer <EOL> self . _buffer = None <EOL> if buf is not None : <EOL> self . _update_texture ( buf ) <EOL> self . dispatch ( '<STR_LIT>' ) <EOL> def _update_texture ( self , buf ) : <EOL> width , height , data = buf <EOL> if not self . _texture : <EOL> self . _texture = Texture . create ( size = ( width , height ) , <EOL> colorfmt = '<STR_LIT>' ) <EOL> self . _texture . flip_vertical ( ) <EOL> self . dispatch ( '<STR_LIT>' ) <EOL> if self . _texture : <EOL> self . _texture . blit_buffer ( <EOL> data , size = ( width , height ) , colorfmt = '<STR_LIT>' ) <EOL> def _get_uri ( self ) : <EOL> uri = self . filename <EOL> if not uri : <EOL> return <EOL> if not '<STR_LIT>' in uri : <EOL> uri = '<STR_LIT>' + pathname2url ( realpath ( uri ) ) <EOL> return uri </s>
