Update of /cvsroot/freevo/freevo/src/tv/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18310/src/tv/plugins

Modified Files:
        mplayer.py 
Log Message:
add modified version from Henrik aka KaarPo

Index: mplayer.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/tv/plugins/mplayer.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** mplayer.py  26 Jun 2005 10:53:00 -0000      1.46
--- mplayer.py  16 Jul 2005 09:18:28 -0000      1.47
***************
*** 6,26 ****
  #
  # Notes:
! # Todo:        
  #
  # -----------------------------------------------------------------------
  # $Log$
! # Revision 1.46  2005/06/26 10:53:00  dischi
  # use kaa.epg instead of pyepg
  #
! # Revision 1.45  2005/01/08 15:40:54  dischi
  # remove TRUE, FALSE, DEBUG and HELPER
  #
! # Revision 1.44  2004/10/28 19:43:52  dischi
  # remove broken imports
  #
! # Revision 1.43  2004/10/06 19:01:33  dischi
  # use new childapp interface
  #
! # Revision 1.42  2004/08/05 17:27:16  dischi
  # Major (unfinished) tv update:
  # o the epg is now taken from kaa.epg in lib
--- 6,29 ----
  #
  # Notes:
! # Todo:        
  #
  # -----------------------------------------------------------------------
  # $Log$
! # Revision 1.47  2005/07/16 09:18:28  dischi
! # add modified version from Henrik aka KaarPo
! #
! # Revision 1.46  2005/06/26 10:53:00  dischi
  # use kaa.epg instead of pyepg
  #
! # Revision 1.45  2005/01/08 15:40:54  dischi
  # remove TRUE, FALSE, DEBUG and HELPER
  #
! # Revision 1.44  2004/10/28 19:43:52  dischi
  # remove broken imports
  #
! # Revision 1.43  2004/10/06 19:01:33  dischi
  # use new childapp interface
  #
! # Revision 1.42  2004/08/05 17:27:16  dischi
  # Major (unfinished) tv update:
  # o the epg is now taken from kaa.epg in lib
***************
*** 31,45 ****
  # Bugs:
  # o The listing area in the tv guide is blank right now, some code
! #   needs to be moved to gui but it's not done yet.
  # o The only player working right now is xine with dvb
  # o channels.py needs much work to support something else than dvb
  # o recording looks broken, too
  #
! # Revision 1.41  2004/07/26 18:10:19  dischi
  # move global event handling to eventhandler.py
  #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
! # Copyright (C) 2002 Krister Lagerstrom, et al. 
  # Please see the file freevo/Docs/CREDITS for a complete list of authors.
  #
--- 34,48 ----
  # Bugs:
  # o The listing area in the tv guide is blank right now, some code
! #   needs to be moved to gui but it's not done yet.
  # o The only player working right now is xine with dvb
  # o channels.py needs much work to support something else than dvb
  # o recording looks broken, too
  #
! # Revision 1.41  2004/07/26 18:10:19  dischi
  # move global event handling to eventhandler.py
  #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
! # Copyright (C) 2002 Krister Lagerstrom, et al.
  # Please see the file freevo/Docs/CREDITS for a complete list of authors.
  #
***************
*** 61,70 ****
  
  
  # Configuration file. Determines where to look for AVI/MP3 files, etc
  import config
  
  import time, os
  
! import util    # Various utilities
  
  import event as em
--- 64,77 ----
  
  
+ # Modified by Henrik aka KaarPo
+ # Handles ONLY ivtv at the moment...
+ 
  # Configuration file. Determines where to look for AVI/MP3 files, etc
  import config
+ from kaa.notifier import Process
  
  import time, os
  
! import util    # Various utilities
  
  import event as em
***************
*** 73,290 ****
  import plugin
  import eventhandler
  
  from tv.player import TVPlayer
  
  
  class PluginInterface(plugin.Plugin):
!     """
!     Plugin to watch tv with mplayer.
!     """
!     def __init__(self):
!         plugin.Plugin.__init__(self)
  
!         # create the mplayer object and register it
!         plugin.register(MPlayer(), plugin.TV)
  
  
  class MPlayer(TVPlayer):
  
!     def __init__(self):
!         TVPlayer.__init__(self, 'mplayer')
!         
! 
!     def rate(self):
!         pass
!     
!     def Play(self, mode, tuner_channel=None):
! 
!         if not tuner_channel:
!             tuner_channel = self.fc.getChannel()
!             
!         vg = self.current_vg = self.fc.getVideoGroup(tuner_channel)
! 
!         # Convert to MPlayer TV setting strings
!         norm = 'norm=%s' % vg.tuner_norm
!         input = 'input=%s' % vg.input_num
!         device= 'device=%s' % vg.vdev
!             
!         w, h = config.TV_VIEW_SIZE
!         outfmt = 'outfmt=%s' % config.TV_VIEW_OUTFMT
! 
!         # Build the MPlayer command
!         args = ( config.MPLAYER_CMD, config.MPLAYER_VO_DEV,
!                  config.MPLAYER_VO_DEV_OPTS, config.MPLAYER_ARGS_DEF )
! 
!         if mode == 'tv':
!             if vg.group_type == 'ivtv':
!                 ivtv_dev = ivtv.IVTV(vg.vdev)
!                 ivtv_dev.init_settings()
!                 ivtv_dev.setinput(vg.input_num)
!                 #ivtv_dev.print_settings()
!                 self.fc.chanSet(tuner_channel)
!             
!                 tvcmd = vg.vdev
! 
!                 if config.MPLAYER_ARGS.has_key('ivtv'):
!                     args += (config.MPLAYER_ARGS['ivtv'],)
! 
!             elif vg.group_type == 'webcam':
!                 self.fc.chanSet(tuner_channel, app='mplayer')
!                 tvcmd = ''
  
!                 if config.MPLAYER_ARGS.has_key('webcam'):
!                     args += (config.MPLAYER_ARGS['webcam'],)
  
!             elif vg.group_type == 'dvb':
!                 self.fc.chanSet(tuner_channel, app='mplayer')
!                 tvcmd = ''
!                 args += ( '"dvb://%s" %s' % ( tuner_channel,
!                                               config.MPLAYER_ARGS[ 'dvb' ] ) 
, )
  
-             else:
-                 freq_khz = self.fc.chanSet(tuner_channel, app='mplayer')
-                 tuner_freq = '%1.3f' % (freq_khz / 1000.0)
  
!                 tvcmd = ('tv:// -tv driver=%s:freq=%s:%s:%s:'
!                          '%s:width=%s:height=%s:%s %s' %
!                          (config.TV_DRIVER, tuner_freq, device, input, norm, 
!                           w, h, outfmt, config.TV_OPTS))
  
!                 if config.MPLAYER_ARGS.has_key('tv'):
!                     args += (config.MPLAYER_ARGS['tv'],)
  
  
!         elif mode == 'vcr':
!             tvcmd = ('tv:// -tv driver=%s:%s:%s:'
!                      '%s:width=%s:height=%s:%s %s' %
!                      (config.TV_DRIVER, device, input, norm, 
!                       w, h, outfmt, config.TV_OPTS))
  
!             if config.MPLAYER_ARGS.has_key('tv'):
!                 args += (config.MPLAYER_ARGS['tv'],)
  
!         else:
!             print 'Mode "%s" is not implemented' % mode  # XXX ui.message()
!             return
  
!         args += (tvcmd,)
  
!         mpl = '%s -vo %s%s -fs %s -slave %s %s' % args
  
!         command = mpl
!         self.mode = mode
  
  
!         # XXX Mixer manipulation code.
!         # TV is on line in
!         # VCR is mic in
!         # btaudio (different dsp device) will be added later
!         mixer = plugin.getbyname('MIXER')
!         
!         if mixer and config.MAJOR_AUDIO_CTRL == 'VOL':
!             mixer_vol = mixer.getMainVolume()
!             mixer.setMainVolume(0)
!         elif mixer and config.MAJOR_AUDIO_CTRL == 'PCM':
!             mixer_vol = mixer.getPcmVolume()
!             mixer.setPcmVolume(0)
! 
!         # Start up the TV task
!         self.app = childapp.Instance( command, prio = config.MPLAYER_NICE )
!         
!         eventhandler.append(self)
  
!         # Suppress annoying audio clicks
!         time.sleep(0.4)
!         # XXX Hm.. This is hardcoded and very unflexible.
!         if mixer and mode == 'vcr':
!             mixer.setMicVolume(config.VCR_IN_VOLUME)
!         elif mixer:
!             mixer.setLineinVolume(config.TV_IN_VOLUME)
!             mixer.setIgainVolume(config.TV_IN_VOLUME)
!             
!         if mixer and config.MAJOR_AUDIO_CTRL == 'VOL':
!             mixer.setMainVolume(mixer_vol)
!         elif mixer and config.MAJOR_AUDIO_CTRL == 'PCM':
!             mixer.setPcmVolume(mixer_vol)
  
  
  
!     def Stop(self, channel_change=0):
!         mixer = plugin.getbyname('MIXER')
!         if mixer and not channel_change:
!             mixer.setLineinVolume(0)
!             mixer.setMicVolume(0)
!             mixer.setIgainVolume(0) # Input on emu10k cards.
  
!         self.app.stop('quit\n')
  
!         eventhandler.remove(self)
  
! #         if rc.focused_app() and not channel_change:
! #             rc.focused_app().show()
  
!         if os.path.exists('/tmp/freevo.wid'): os.unlink('/tmp/freevo.wid')
  
  
!     def eventhandler(self, event, menuw=None):
!         s_event = '%s' % event
  
!         if event == em.STOP or event == em.PLAY_END:
!             self.Stop()
!             eventhandler.post(em.PLAY_END)
!             return True
  
!         elif event in [ em.TV_CHANNEL_UP, em.TV_CHANNEL_DOWN] or 
s_event.startswith('INPUT_'):
!             if event == em.TV_CHANNEL_UP:
!                 nextchan = self.fc.getNextChannel()
!             elif event == em.TV_CHANNEL_DOWN:
!                 nextchan = self.fc.getPrevChannel()
!             else:
!                 chan = int( s_event[6] )
!                 nextchan = self.fc.getManChannel(chan)
  
!             nextvg = self.fc.getVideoGroup(nextchan)
  
!             if self.current_vg != nextvg:
!                 self.Stop(channel_change=1)
!                 self.Play('tv', nextchan)
!                 return True
  
!             if self.mode == 'vcr':
!                 return True
!             
!             elif self.current_vg.group_type == 'dvb':
!                 self.Stop(channel_change=1)
!                 self.Play('tv', nextchan)
!                 return True
  
!             elif self.current_vg.group_type == 'ivtv':
!                 self.fc.chanSet(nextchan)
!                 self.app.write('seek 999999 0\n')
  
!             else:
!                 freq_khz = self.fc.chanSet(nextchan, app=self.app)
!                 new_freq = '%1.3f' % (freq_khz / 1000.0)
!                 self.app.write('tv_set_freq %s\n' % new_freq)
  
!             self.current_vg = self.fc.getVideoGroup(self.fc.getChannel())
  
!             # Display a channel changed message
!             tuner_id, chan_name, prog_info = self.fc.getChannelInfo()
!             now = time.strftime('%H:%M')
!             msg = '%s %s (%s): %s' % (now, chan_name, tuner_id, prog_info)
!             cmd = 'osd_show_text "%s"\n' % msg
!             self.app.write(cmd)
!             return True
  
-         elif event == em.TOGGLE_OSD:
-             # Display the channel info message
-             tuner_id, chan_name, prog_info = self.fc.getChannelInfo()
-             now = time.strftime('%H:%M')
-             msg = '%s %s (%s): %s' % (now, chan_name, tuner_id, prog_info)
-             cmd = 'osd_show_text "%s"\n' % msg
-             self.app.write(cmd)
-             return True
-             
-         return False
-     
--- 80,277 ----
  import plugin
  import eventhandler
+ import notifier
+ 
+ from config.tvcards import IVTVCard
+ from tv.freq import get_frequency
+ import kaa.epg
  
  from tv.player import TVPlayer
  
+ import logging
+ log = logging.getLogger('tv')
  
  class PluginInterface(plugin.Plugin):
!     """
!     Plugin to watch tv with mplayer.
!     """
!     def __init__(self):
!         plugin.Plugin.__init__(self)
  
!         # create the mplayer object and register it
!         plugin.register(MPlayer(), plugin.TV, True)
  
  
  class MPlayer(TVPlayer):
  
!     def __init__(self):
!         TVPlayer.__init__(self, 'mplayer')
!         
!     def rate(self, channel, device, uri):
!         """
!         for now, just handle ivtv
!         """
!         log.info('MPlayer.rate(): channel=[%s] device=[%s] uri=[%s]' %
!         (channel, device, uri))
!         if device.startswith('ivtv'):
!             log.info('MPlayer.rate(): Returning 2: MPlayer handles this!')
!             return 2
  
!         return 0
  
!     def tune(self, uri):
!         log.info('MPlayer.play(): Tuning [%s] to chan [%s]' %
!         (self.device.vdev, uri))
!         import tv.v4l2
!         v = tv.v4l2.Videodev(device=self.device.vdev)
!     v.setchannel(uri)
!     del v
  
  
!     def play(self, channel, device, uri):
  
!         log.info('MPlayer.play(): channel=[%s] device=[%s] uri=[%s]' %
!         (channel, device, uri))
  
+     self.channel = channel
+         self.device = config.TV_CARDS[device]
+         if not isinstance(self.device, IVTVCard):
+             self.reason = 'Device %s is not of class IVTVCard' % device
+         log.error('MPlayer.play(): ' + self.reason)
+             return
  
!         log.debug('MPlayer.play(): driver=[%s] vdev=[%s] chanlist=[%s]' %
!         (self.device.driver, self.device.vdev, self.device.chanlist))
  
!         self.tune(uri)
  
!     command = 'mplayer -nolirc -slave '
!     command += config.MPLAYER_ARGS_DEF + ' '
!         if config.MPLAYER_ARGS.has_key('ivtv'):
!             command += config.MPLAYER_ARGS['ivtv'] + ' '
!         command += '-ao ' + config.MPLAYER_AO_DEV + ' '
!         command += '-vo ' + config.MPLAYER_VO_DEV + \
!              config.MPLAYER_VO_DEV_OPTS + ' '
!     command += self.device.vdev
  
!         log.info('mplayer.play(): Starting cmd=%s' % command)
  
!         self.show()
!         self.app = Process( command )
  
!     return
  
  
!     def stop(self, channel_change=0):
!         """
!         Stop mplayer
!         """
!         log.info('MPlayer.stop(): Stopping mplayer')
!         TVPlayer.stop(self)
!         if self.app:
!             self.app.stop('quit\n')
  
!     def osd_channel(self):
!         # Display the channel info message
!         #tuner_id, chan_name, prog_info = self.fc.getChannelInfo()
!         now = time.strftime('%H:%M')
!     program = self.channel[time.time()]
!         #msg = '%s %s (%s): %s' % (now, chan_name, tuner_id, prog_info)
!     msg = '%s [%s]: %s' % ( self.channel.title, now, program.title)
!         cmd = 'osd_show_text "%s"\n' % msg
!         self.app.write(cmd)
!         return False # this removes the timer...
  
+     def osd_updown(self):
+         cmd = 'osd_show_text "Changing to [%s]"\n' % self.channel.title
+         self.app.write(cmd)
+     # wait three seconds for the tuner to tune in...
+         cb = notifier.Callback( self.osd_channel )
+         notifier.addTimer( 3000, cb )
+     return False
  
+     def eventhandler(self, event, menuw=None):
+     """
+     MPlayer event handler.
+     If an event is not bound in this
+         function it will be passed over to the items eventhandler.
+     """
  
!         s_event = '%s' % event
!         log.debug('MPlayer.eventhandler(): Got event [%s]' % s_event)
  
!         if event == em.STOP or event == em.PLAY_END:
!             self.stop()
!             eventhandler.post(em.PLAY_END)
!             return True
  
!         if event == em.TV_CHANNEL_UP:
!             self.channel = kaa.epg.get_channel(self.channel, 1)
!             uri = self.channel.get_uri(self.channel, self.device)
!             self.tune(String(uri))
!             self.osd_updown()
!             return True
  
!         if event == em.TV_CHANNEL_DOWN:
!             self.channel = kaa.epg.get_channel(self.channel, -1)
!             uri = self.channel.get_uri(self.channel, self.device)
!             self.tune(String(uri))
!             self.osd_updown()
!             return True
  
!     elif event == em.OSD_MESSAGE:
!             cmd = 'osd_show_text "%s"\n' % event.arg
!             self.app.write(cmd)
!             return True
  
  
!     # not changed by HKP yet...
!         elif False and s_event.startswith('INPUT_'):
!             if event == em.TV_CHANNEL_UP:
!                 nextchan = self.fc.getNextChannel()
!             elif event == em.TV_CHANNEL_DOWN:
!                 nextchan = self.fc.getPrevChannel()
!             else:
!                 chan = int( s_event[6] )
!                 nextchan = self.fc.getManChannel(chan)
  
!             nextvg = self.fc.getVideoGroup(nextchan)
  
!             if self.current_vg != nextvg:
!                 self.Stop(channel_change=1)
!                 self.Play('tv', nextchan)
!                 return True
  
!             if self.mode == 'vcr':
!                 return True
!             
!             elif self.current_vg.group_type == 'dvb':
!                 self.Stop(channel_change=1)
!                 self.Play('tv', nextchan)
!                 return True
  
!             elif self.current_vg.group_type == 'ivtv':
!                 self.fc.chanSet(nextchan)
!                 self.app.write('seek 999999 0\n')
  
!             else:
!                 freq_khz = self.fc.chanSet(nextchan, app=self.app)
!                 new_freq = '%1.3f' % (freq_khz / 1000.0)
!                 self.app.write('tv_set_freq %s\n' % new_freq)
  
!             self.current_vg = self.fc.getVideoGroup(self.fc.getChannel())
  
!             # Display a channel changed message
!             tuner_id, chan_name, prog_info = self.fc.getChannelInfo()
!             now = time.strftime('%H:%M')
!             msg = '%s %s (%s): %s' % (now, chan_name, tuner_id, prog_info)
!             cmd = 'osd_show_text "%s"\n' % msg
!             self.app.write(cmd)
!             return True
  
!         elif event == em.TOGGLE_OSD:
!         self.osd_channel()
!         return True
  
!         log.debug('MPlayer.eventhandler(): No handler for event [%s]' % 
s_event)
!         return False
  



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to