Update of /cvsroot/freevo/freevo/src/audio/plugins In directory sc8-pr-cvs1:/tmp/cvs-serv29654/audio/plugins
Modified Files: mplayer.py xine.py Log Message: use new childapp thread function Index: mplayer.py =================================================================== RCS file: /cvsroot/freevo/freevo/src/audio/plugins/mplayer.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** mplayer.py 15 Sep 2003 20:06:42 -0000 1.17 --- mplayer.py 19 Sep 2003 22:09:16 -0000 1.18 *************** *** 10,13 **** --- 10,16 ---- # ----------------------------------------------------------------------- # $Log$ + # Revision 1.18 2003/09/19 22:09:16 dischi + # use new childapp thread function + # # Revision 1.17 2003/09/15 20:06:42 dischi # cdda url handling repaired and only stop on playing player *************** *** 63,75 **** - DEBUG = config.DEBUG - - TRUE = 1 - FALSE = 0 - - # contains an initialized MPlayer() object - mplayer = None - - class PluginInterface(plugin.Plugin): """ --- 66,69 ---- *************** *** 78,82 **** """ def __init__(self): - global mplayer # create the mplayer object plugin.Plugin.__init__(self) --- 72,75 ---- *************** *** 93,99 **** def __init__(self): ! self.thread = MPlayer_Thread() ! self.thread.setDaemon(1) ! self.thread.start() self.mode = None self.app_mode = 'audio' --- 86,90 ---- def __init__(self): ! self.thread = childapp.ChildThread() self.mode = None self.app_mode = 'audio' *************** *** 156,172 **** self.item = item - self.thread.item = item ! if not self.thread.item.valid: # Invalid file, show an error and survive. return _('Invalid audio file') - self.thread.play_mode = self.mode - _debug_('MPlayer.play(): Starting thread, cmd=%s' % command) ! self.thread.mode = 'play' ! self.thread.command = command ! self.thread.mode_flag.set() return None --- 147,158 ---- self.item = item ! if not self.item.valid: # Invalid file, show an error and survive. return _('Invalid audio file') _debug_('MPlayer.play(): Starting thread, cmd=%s' % command) ! self.thread.start(MPlayerApp, (command, item)) return None *************** *** 176,186 **** Stop mplayer and set thread to idle """ ! if self.mode == 'play': ! self.thread.app.write('quit\n') ! self.thread.mode = 'stop' ! self.thread.mode_flag.set() ! self.thread.item = None ! while self.thread.mode == 'stop': ! time.sleep(0.3) --- 162,166 ---- Stop mplayer and set thread to idle """ ! self.thread.stop('quit\n') *************** *** 188,194 **** --- 168,176 ---- return self.thread.mode != 'idle' + def refresh(self): self.playerGUI.refresh() + def eventhandler(self, event, menuw=None): """ *************** *** 202,206 **** if event == AUDIO_SEND_MPLAYER_CMD: self.thread.app.write('%s\n' % event.arg) ! return TRUE if event in ( STOP, PLAY_END, USER_END ): --- 184,188 ---- if event == AUDIO_SEND_MPLAYER_CMD: self.thread.app.write('%s\n' % event.arg) ! return True if event in ( STOP, PLAY_END, USER_END ): *************** *** 210,218 **** elif event == PAUSE or event == PLAY: self.thread.app.write('pause\n') ! return TRUE elif event == SEEK: self.thread.app.write('seek %s\n' % event.arg) ! return TRUE else: --- 192,200 ---- elif event == PAUSE or event == PLAY: self.thread.app.write('pause\n') ! return True elif event == SEEK: self.thread.app.write('seek %s\n' % event.arg) ! return True else: *************** *** 228,232 **** """ ! def __init__(self, app, item): if config.MPLAYER_DEBUG: fname_out = os.path.join(config.LOGDIR, 'mplayer_stdout.log') --- 210,214 ---- """ ! def __init__(self, (app, item)): if config.MPLAYER_DEBUG: fname_out = os.path.join(config.LOGDIR, 'mplayer_stdout.log') *************** *** 251,254 **** --- 233,237 ---- self.RE_TIME_NEW = re.compile("^A: *([0-9]+):([0-9]+)").match + def kill(self): # Use SIGINT instead of SIGKILL to make sure MPlayer shuts *************** *** 260,263 **** --- 243,251 ---- self.log_stderr.close() + + def stopped(self): + rc.post_event(AUDIO_PLAY_END) + + def stdout_cb(self, line): if config.MPLAYER_DEBUG: *************** *** 305,351 **** except ValueError: pass # File closed - - - # ====================================================================== - - class MPlayer_Thread(threading.Thread): - """ - Thread to wait for a mplayer command to play - """ - - def __init__(self): - threading.Thread.__init__(self) - - self.play_mode = '' - self.mode = 'idle' - self.mode_flag = threading.Event() - self.command = '' - self.app = None - self.item = None - - - def run(self): - while 1: - if self.mode == 'idle': - self.mode_flag.wait() - self.mode_flag.clear() - - elif self.mode == 'play': - - if DEBUG: - print 'MPlayer_Thread.run(): Started, cmd=%s' % self.command - - self.app = MPlayerApp(self.command, self.item) - - while self.mode == 'play' and self.app.isAlive(): - time.sleep(0.1) - - self.app.kill() - - if self.mode == 'play': - rc.post_event(AUDIO_PLAY_END) - - self.mode = 'idle' - - else: - self.mode = 'idle' --- 293,294 ---- Index: xine.py =================================================================== RCS file: /cvsroot/freevo/freevo/src/audio/plugins/xine.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xine.py 1 Sep 2003 19:46:02 -0000 1.4 --- xine.py 19 Sep 2003 22:09:16 -0000 1.5 *************** *** 13,16 **** --- 13,19 ---- # ----------------------------------------------------------------------- # $Log$ + # Revision 1.5 2003/09/19 22:09:16 dischi + # use new childapp thread function + # # Revision 1.4 2003/09/01 19:46:02 dischi # add menuw to eventhandler, it may be needed *************** *** 47,51 **** import time, os ! import threading, signal import popen2, re --- 50,54 ---- import time, os ! import signal import popen2, re *************** *** 58,71 **** import plugin - # RegExp - import re - - DEBUG = config.DEBUG - - TRUE = 1 - FALSE = 0 - - # contains an initialized Xine() object - xine = None class PluginInterface(plugin.Plugin): --- 61,64 ---- *************** *** 74,84 **** """ def __init__(self): - global xine - plugin.Plugin.__init__(self) - if xine: - return - try: config.CONF.fbxine --- 67,72 ---- *************** *** 119,122 **** --- 107,112 ---- + # ====================================================================== + class Xine: """ *************** *** 125,131 **** def __init__(self, version): ! self.thread = Xine_Thread() ! self.thread.setDaemon(1) ! self.thread.start() self.mode = None self.xine_version = version --- 115,119 ---- def __init__(self, version): ! self.thread = childapp.ChildThread() self.mode = None self.xine_version = version *************** *** 142,145 **** --- 130,136 ---- """ + self.item = item + self.playerGUI = playerGUI + if item.url: filename = item.url *************** *** 147,167 **** filename = item.filename - self.playerGUI = playerGUI - if plugin.getbyname('MIXER'): plugin.getbyname('MIXER').reset() - self.item = item - self.thread.item = item ! command = self.command ! ! if DEBUG: ! print 'Xine.play(): Starting thread, cmd=%s' % command ! self.thread.mode = 'play' ! self.thread.command = '%s "%s"' % (command, filename) ! self.thread.mode_flag.set() ! return None --- 138,149 ---- filename = item.filename if plugin.getbyname('MIXER'): plugin.getbyname('MIXER').reset() ! command = '%s "%s"' % (self.command, filename) ! _debug_('Xine.play(): Starting thread, cmd=%s' % command) ! self.thread.start(XineApp, (command, item, self.refresh)) *************** *** 178,186 **** Stop xine and set thread to idle """ ! self.thread.mode = 'stop' ! self.thread.mode_flag.set() ! self.thread.item = None ! while self.thread.mode == 'stop': ! time.sleep(0.3) --- 160,164 ---- Stop xine and set thread to idle """ ! self.thread.stop('quit\n') *************** *** 190,210 **** function it will be passed over to the items eventhandler """ if event in ( PLAY_END, USER_END ): ! self.stop() return self.item.eventhandler(event) if event == PAUSE or event == PLAY: self.thread.app.write('pause\n') ! return TRUE if event == STOP: - self.thread.app.write('quit\n') - for i in range(10): - if self.thread.mode == 'idle': - break - time.sleep(0.3) - else: - # sometimes xine refuses to die - self.stop() self.playerGUI.stop() return self.item.eventhandler(event) --- 168,183 ---- function it will be passed over to the items eventhandler """ + if event == AUDIO_PLAY_END: + event = PLAY_END + if event in ( PLAY_END, USER_END ): ! self.playerGUI.stop() return self.item.eventhandler(event) if event == PAUSE or event == PLAY: self.thread.app.write('pause\n') ! return True if event == STOP: self.playerGUI.stop() return self.item.eventhandler(event) *************** *** 224,228 **** pos = 30 self.thread.app.write('%s%s\n' % (action, pos)) ! return TRUE # nothing found? Try the eventhandler of the object who called us --- 197,201 ---- pos = 30 self.thread.app.write('%s%s\n' % (action, pos)) ! return True # nothing found? Try the eventhandler of the object who called us *************** *** 238,253 **** """ ! def __init__(self, app, item): self.item = item childapp.ChildApp.__init__(self, app) - self.exit_type = None self.elapsed = 0 ! ! def kill(self): ! # Use SIGINT instead of SIGKILL to make sure Xine shuts ! # down properly and releases all resources before it gets ! # reaped by childapp.kill().wait() ! childapp.ChildApp.kill(self, signal.SIGINT) --- 211,222 ---- """ ! def __init__(self, (app, item, refresh)): self.item = item childapp.ChildApp.__init__(self, app) self.elapsed = 0 + self.refresh = refresh ! def stopped(self): ! rc.post_event(AUDIO_PLAY_END) *************** *** 257,311 **** if self.item.elapsed != self.elapsed: ! xine.refresh() self.elapsed = self.item.elapsed - - - # ====================================================================== - - class Xine_Thread(threading.Thread): - """ - Thread to wait for a xine command to play - """ - - def __init__(self): - threading.Thread.__init__(self) - - self.mode = 'idle' - self.mode_flag = threading.Event() - self.command = '' - self.app = None - self.item = None - - - def run(self): - while 1: - if self.mode == 'idle': - self.mode_flag.wait() - self.mode_flag.clear() - - elif self.mode == 'play': - if DEBUG: - print 'Xine_Thread.run(): Started, cmd=%s' % self.command - - self.app = XineApp(self.command, self.item) - - while self.mode == 'play' and self.app.isAlive(): - time.sleep(0.1) - - self.app.kill() - - if self.mode == 'play': - if self.app.exit_type == "End of file": - rc.post_event(PLAY_END) - elif self.app.exit_type == "Quit": - rc.post_event(USER_END) - else: - rc.post_event(PLAY_END) - - if DEBUG: - print 'Xine_Thread.run(): Stopped' - - self.mode = 'idle' - - else: - self.mode = 'idle' --- 226,229 ---- if self.item.elapsed != self.elapsed: ! self.refresh() self.elapsed = self.item.elapsed ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Freevo-cvslog mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/freevo-cvslog