fixed merge conflic

This commit is contained in:
Tim Caldwell
2017-10-12 10:32:26 +13:00
7 changed files with 98 additions and 77 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.pyc
*.log

View File

@@ -30,7 +30,7 @@ def setup_logging():
logger = setup_logging()
######## sets paths and constants ########
PATH_TO_BROWSER = 'C:\TestFolderStucture' #TODO replace this with pi path name when i know what makes sense
PATH_TO_BROWSER = 'C:/TestFolderStucture'#get_the_current_dir_path() #TODO replace this with pi path name when i know what makes sense
PATH_TO_DATA_OBJECTS = get_the_current_dir_path()
EMPTY_BANK = dict(name='',location='',length=-1,start=-1,end=-1)

View File

@@ -1 +1 @@
[{"start": -1, "length": -1, "end": -1, "location": "", "name": "extremely_minimal_video_1.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "C:\\TestFolderStucture\\minimal_videos/minimal_video_1.mp4", "name": "minimal_video_1.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "C:\\TestFolderStucture\\minimal_videos/minimal_video_2.mp4", "name": "minimal_video_2.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}]
[{"start": -1, "length": -1, "end": -1, "location": "", "name": "spooky_video_2.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "C:/TestFolderStucture/random_video_1.mp4", "name": "random_video_1.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "C:/TestFolderStucture/random_video_2.mp4", "name": "random_video_2.mp4"}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}, {"start": -1, "length": -1, "end": -1, "location": "", "name": ""}]

View File

@@ -4,7 +4,9 @@ import sys
import dbus
import subprocess
from time import time,strftime
import data_centre
logger = data_centre.setup_logging()
"""
@@ -103,8 +105,8 @@ class OMXDriver(object):
# self.mon.log(self, 'dbus user ' + self.dbus_user)
# self.mon.log(self, 'dbus name ' + self.dbus_name)
# print self.omxplayer_cmd
print("Send command to omxplayer: "+ self.omxplayer_cmd)
# logger.info self.omxplayer_cmd
logger.info("Send command to omxplayer: "+ self.omxplayer_cmd)
# self._process=subprocess.Popen(self.omxplayer_cmd,shell=True,stdout=file('/home/pi/pipresents/pp_logs/stdout.txt','a'),stderr=file('/home/pi/pipresents/pp_logs/stderr.txt','a'))
self._process=subprocess.Popen(self.omxplayer_cmd,shell=True,stdout=file('/dev/null','a'),stderr=file('/dev/null','a'))
self.pid=self._process.pid
@@ -119,13 +121,13 @@ class OMXDriver(object):
connect_success=self.__dbus_connect()
if connect_success is True:
# print 'SUCCESS'
print('connected to omxplayer dbus after ' + str(self.dbus_tries) + ' centisecs')
logger.info('connected to omxplayer dbus after ' + str(self.dbus_tries) + ' centisecs')
# get duration of the track in microsecs if fails return a very large duration
# posibly faile because omxplayer is running but not omxplayer.bin
duration_success,duration=self.get_duration()
if duration_success is False:
print('get duration failed for n attempts using '+ str(duration/60000000)+ ' minutes')
logger.info('get duration failed for n attempts using '+ str(duration/60000000)+ ' minutes')
# calculate time to pause before last frame
self.duration = duration
self.pause_at_end_time = duration - 350000
@@ -184,7 +186,7 @@ class OMXDriver(object):
self.end_play_reason='pause_at_end'
return
else:
print 'pause at end failed, probably because of delay after detection, just run on'
logger.info( 'pause at end failed, probably because of delay after detection, just run on')
self.widget.after(self.delay,self._status_loop)
else:
# need to do the pausing for preload after first timestamp is received 0 is default value before start
@@ -199,7 +201,7 @@ class OMXDriver(object):
else:
# should never fail, just warn at the moment
# print 'pause after load failed '+ + str(self.video_position)
print( str(self.id)+ ' pause after load fail ' + str(self.video_position))
logger.info( str(self.id)+ ' pause after load fail ' + str(self.video_position))
self.widget.after(self.delay,self._status_loop)
else:
self.widget.after(self.delay,self._status_loop)
@@ -218,30 +220,30 @@ class OMXDriver(object):
# print self.id,' unpause for show success', self.video_position
else:
# should never fail, just warn at the moment
print(str(self.id)+ ' unpause for show fail ' + str(self.video_position))
logger.info(str(self.id)+ ' unpause for show fail ' + str(self.video_position))
def control(self,char):
val = OMXDriver.KEY_MAP[char]
print('>control received and sent to omxplayer ' + str(self.pid))
#logger.info('>control received and sent to omxplayer ' + str(self.pid))
if self.is_running():
try:
self.__iface_player.Action(dbus.Int32(val))
except dbus.exceptions.DBusException as ex:
print('Failed to send control - dbus exception: {}'.format(ex.get_dbus_message()))
#logger.info('Failed to send control - dbus exception: {}'.format(ex.get_dbus_message()))
return
else:
print('Failed to send control - process not running')
logger.info('Failed to send control - process not running')
return
# USE ONLY at end and after load
# return succces of the operation, several tries if pause did not work and no error reported.
def pause(self,reason):
print(self,'pause received '+reason)
#logger.info(self,'pause received {}'.format(reason))
if self.paused is False:
print('not paused so send pause '+reason)
logger.info('not paused so send pause {}'.format(reason))
tries=1
while True:
if self.send_pause() is False:
@@ -256,12 +258,12 @@ class OMXDriver(object):
return False
else:
# failed for no good reason
print(self, '!!!!! repeat pause ' + str(tries))
logger.info(self, '!!!!! repeat pause {}'.format(str(tries)))
# print self.id,' !!!!! repeat pause ',self.video_position, tries
tries +=1
if tries >5:
# print self.id, ' pause failed for n attempts'
print('pause failed for n attempts')
logger.info('pause failed for n attempts')
return False
# repeat
@@ -269,9 +271,9 @@ class OMXDriver(object):
# USE ONLY for show
def unpause(self,reason):
print('MON' + 'Unpause received '+ reason)
logger.info('MON' + 'Unpause received {}'.format(reason))
if self.paused is True:
print('MON' +'Is paused so Track will be unpaused '+ reason)
logger.info('MON' +'Is paused so Track will be unpaused {}'.format(reason))
tries=1
while True:
if self.send_unpause() is False:
@@ -287,12 +289,12 @@ class OMXDriver(object):
# failed for good reason because of exception or process not running caused by end of track
return False
else:
print('warn' + '!!!!! repeat unpause ' + str(tries))
logger.info('warn' + '!!!!! repeat unpause {}'.format(tries))
# print self.id,' !!!! repeat unpause ',self.video_position, tries
tries +=1
if tries >5:
# print self.id, ' unpause failed for n attempts'
print('warn' + 'unpause failed for n attempts')
logger.info('warn' + 'unpause failed for n attempts')
return False
@@ -301,11 +303,11 @@ class OMXDriver(object):
try:
result=self.__iface_props.PlaybackStatus()
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to test paused - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to test paused - dbus exception: {}'.format(ex.get_dbus_message()))
return 'Failed'
return result
else:
print('warn'+'Failed to test paused - process not running')
logger.info('warn'+'Failed to test paused - process not running')
# print self.id,' test paused not successful - process'
return 'Failed'
@@ -315,11 +317,11 @@ class OMXDriver(object):
try:
self.__iface_player.Pause()
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to send pause - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to send pause - dbus exception: {}'.format(ex.get_dbus_message()))
return False
return True
else:
print('warn'+'Failed to send pause - process not running')
logger.info('warn'+'Failed to send pause - process not running')
# print self.id,' send pause not successful - process'
return False
@@ -329,16 +331,16 @@ class OMXDriver(object):
try:
self.__iface_player.Action(16)
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to send unpause - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to send unpause - dbus exception: {}'.format(ex.get_dbus_message()))
return False
return True
else:
print('warn'+'Failed to send unpause - process not running')
logger.info('warn'+'Failed to send unpause - process not running')
# print self.id,' send unpause not successful - process'
return False
def pause_on(self):
print('mon'+'pause on received ')
logger.info('mon'+'pause on received ')
# print 'pause on',self.paused
if self.paused is True:
return
@@ -350,15 +352,15 @@ class OMXDriver(object):
# print 'paused OK'
return
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to do pause on - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to do pause on - dbus exception: {}'.format(ex.get_dbus_message()))
return
else:
print('warn'+'Failed to do pause on - process not running')
logger.info('warn'+'Failed to do pause on - process not running')
return
def pause_off(self):
print('mon'+'pause off received ')
logger.info('mon'+'pause off received ')
# print 'pause off',self.paused
if self.paused is False:
return
@@ -369,14 +371,14 @@ class OMXDriver(object):
# print 'not paused OK'
return
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to do pause off - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to do pause off - dbus exception: {}'.format(ex.get_dbus_message()))
return
else:
print('warn'+'Failed to do pause off - process not running')
logger.info('warn'+'Failed to do pause off - process not running')
return
def go(self):
print('log'+'go received ')
logger.info('log'+'go received ')
self.unpause('for go')
@@ -392,7 +394,7 @@ class OMXDriver(object):
def toggle_pause(self,reason):
print('log'+'toggle pause received '+ reason)
logger.info('log'+'toggle pause received {}'.format(reason))
if not self.paused:
self.paused = True
else:
@@ -401,16 +403,16 @@ class OMXDriver(object):
try:
self.__iface_player.Action(16)
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to toggle pause - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to toggle pause - dbus exception: {}'.format(ex.get_dbus_message()))
return
else:
print('warn'+'Failed to toggle pause - process not running')
logger.info('warn'+'Failed to toggle pause - process not running')
return
def stop(self):
print('log'+'>stop received and quit sent to omxplayer ' + str(self.pid))
logger.info('log'+'>stop received and quit sent to omxplayer {} '.format(self.pid))
# need to send 'nice day'
if self.paused_at_end is True:
self.end_play_signal=True
@@ -420,10 +422,10 @@ class OMXDriver(object):
try:
self.__iface_root.Quit()
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed to quit - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed to quit - dbus exception: {}'.format(ex.get_dbus_message()))
return
else:
print('warn'+'Failed to quit - process not running')
logger.info('warn'+'Failed to quit - process not running')
return
@@ -471,7 +473,7 @@ class OMXDriver(object):
if success is True:
return True,duration
else:
print('warn'+ 'repeat get duration ' + str(tries))
logger.info('warn'+ 'repeat get duration {}'.format(tries))
tries +=1
if tries >5:
return False,sys.maxint*100
@@ -484,7 +486,7 @@ class OMXDriver(object):
micros = self.__iface_props.Duration()
return True,micros
except dbus.exceptions.DBusException as ex:
print('warn'+'Failed get duration - dbus exception: {}'.format(ex.get_dbus_message()))
logger.info('warn'+'Failed get duration - dbus exception: {}'.format(ex.get_dbus_message()))
return False,-1
else:
return False,-1
@@ -502,20 +504,20 @@ class OMXDriver(object):
bus_pid_filename = "/tmp/omxplayerdbus.{}.pid".format(self.dbus_user)
if not os.path.exists(bus_address_filename):
print('log'+'waiting for bus address file ' + bus_address_filename)
logger.info('log'+'waiting for bus address file {}'.format(bus_address_filename))
self.omx_loaded=False
return False
else:
f = open(bus_address_filename, "r")
bus_address = f.read().rstrip()
if bus_address == '':
print('log'+ 'waiting for bus address in file ' + bus_address_filename)
logger.info('log'+ 'waiting for bus address in file {}'.format(bus_address_filename))
self.omx_loaded=False
return False
else:
# self.mon.log(self, 'bus address found ' + bus_address)
if not os.path.exists(bus_pid_filename):
print('warn'+ 'bus pid file does not exist ' + bus_pid_filename)
logger.info('warn'+ 'bus pid file does not exist {}'.format(bus_pid_filename))
self.omx_loaded=False
return False
else:

BIN
omxdriver.pyc Normal file

Binary file not shown.

View File

@@ -1 +1 @@
[{"name": "PLAYBACK_MODE", "value": "RANDOM"}, {"name": "PLAYLIST", "value": "[1,1,1,4,1,2,1,4]"}, {"name": "SYNC_LENGTHS", "value": "OFF"}, {"name": "SYNC_LENGTHS_TO", "value": "00:08"}, {"name": "RAND_START", "value": "OFF"}, {"name": "VIDEO_OUTPUT", "value": "HDMI"}]
[{"name": "PLAYBACK_MODE", "value": "LOOPER"}, {"name": "PLAYLIST", "value": "[1,1,1,4,1,2,1,4]"}, {"name": "SYNC_LENGTHS", "value": "OFF"}, {"name": "SYNC_LENGTHS_TO", "value": "00:08"}, {"name": "RAND_START", "value": "OFF"}, {"name": "VIDEO_OUTPUT", "value": "HDMI"}]

View File

@@ -1,26 +1,36 @@
import time
#from omxdriver import OMXDriver <== for deving only
try:
from omxdriver import OMXDriver #<== for deving only
has_omx = True
except ImportError:
has_omx = False
from Tkinter import Tk, Canvas
import data_centre
logger = data_centre.setup_logging()
#layer = 0
class video_driver(object):
def __init__(self, widget = None):
self.widget = widget
self.delay = 50
self.last_player = video_player(self.widget,'a')
self.current_player = video_player(self.widget,'b')
self.next_player = video_player(self.widget,'c')
logger.info('the has_omx flag is {}'.format(has_omx))
if has_omx:
self.last_player = video_player(self.widget,'a')
self.current_player = video_player(self.widget,'b')
self.next_player = video_player(self.widget,'c')
self.manual_next = False
self.manual_next = False
self.begin_playing()
self.widget.after(self.delay,self.begin_playing)
def begin_playing(self):
#TODO: the first clip will be a demo
first_context = data_centre.get_next_context()
#first_context = '/home/pi/pp_home/media/samplerloop3s.mp4'
self.current_player.load_content(first_context)
#first_context = '/home/pi/pp_home/media/01_trashpalaceintro.mp4'
logger.info(first_context['location'])
self.current_player.load_content(first_context['location'])
self.wait_for_first_load()
@@ -34,21 +44,21 @@ class video_driver(object):
def switch_players(self):
self.temp_player = self.last_player
self.last_player = self.current_player
print('switch: last_player is {}'.format(self.last_player.name))
logger.info('switch: last_player is {}'.format(self.last_player.name))
self.current_player = self.next_player
print('switch: current_player is {}'.format(self.current_player.name))
logger.info('switch: current_player is {}'.format(self.current_player.name))
self.next_player = self.temp_player
print('switch: next_player is {}'.format(self.next_player.name))
logger.info('switch: next_player is {}'.format(self.next_player.name))
self.last_player.exit()
def play_video(self):
print('{} is about to play'.format(self.current_player.name))
logger.info('{} is about to play'.format(self.current_player.name))
self.current_player.play_content()
#self.last_player.exit()
next_context = data_centre.get_next_context()
#next_context = '/home/pi/pp_home/media/samplerloop3s.mp4'
self.next_player.load_content(next_context)
self.next_player.load_content(next_context['location'])
self.wait_for_next_cycle()
@@ -56,14 +66,14 @@ class video_driver(object):
def wait_for_next_cycle(self):
if(self.current_player.is_finished() or self.manual_next):
print('{} is finished'.format(self.current_player.name))
logger.info('{} is finished'.format(self.current_player.name))
self.manual_next = False
if self.next_player.is_loaded():
print('{} is loaded on switchover'.format(self.next_player.name))
logger.info('{} is loaded on switchover'.format(self.next_player.name))
self.switch_players()
self.play_video()
else:
print('{} is not loaded yet!'.format(self.next_player.name))
logger.info('{} is not loaded yet!'.format(self.next_player.name))
self.current_player.pause_content()
self.wait_for_next_load()
else:
@@ -78,8 +88,11 @@ class video_driver(object):
def get_info_for_video_display(self):
return self.current_player.bank_number, self.current_player.status, self.next_player.bank_number,\
if has_omx:
return self.current_player.bank_number, self.current_player.status, self.next_player.bank_number,\
self.next_player.status, self.current_player.duration, self.current_player.video_length
else:
return 0, 'test', 1, 'test' , 0, 10
class video_player(object):
@@ -105,14 +118,18 @@ class video_player(object):
def play_content(self):
self.status = 'PLAYING'
print('{} is playing now'.format(self.name))
logger.info('{} is playing now'.format(self.name))
self.omx.pause_before_play_required = 'no'
self.omx.show(True,0)
def load_content(self, context):
self.status = 'LOADING'
print('{} is loading now {}'.format(self.name,context))
self.omx.load(context,'after-first-frame','','')
logger.info('{} is loading now {}'.format(self.name,context))
self.omx.load(context,'after-first-frame','--win 0,0,400,400 --no-osd','')
#layer = layer + 1
def set_to_default(self):
self.omx.kill()
@@ -120,19 +137,19 @@ class video_player(object):
def exit(self):
if(self.omx.omx_loaded is not None):
print('{} is exiting omx'.format(self.name))
logger.info('{} is exiting omx'.format(self.name))
self.omx.stop()
self.omx = OMXDriver(self.widget,'')
def pause_content(self):
self.status = 'PAUSED'
# tk = Tk()
#
# canvas = Canvas(tk,width=500,height=400, bd=0, highlightthickness=0)
# canvas.pack()
#
# driver = video_driver(canvas)
#
# while True:
# tk.update()
#tk = Tk()
#canvas = Canvas(tk,width=500,height=400, bd=0, highlightthickness=0)
#canvas.pack()
#driver = video_driver(canvas)
#while True:
# tk.update()