Author: dmeyer
Date: Fri Dec  8 15:12:01 2006
New Revision: 2188

Modified:
   trunk/popcorn/src/backends/base.py
   trunk/popcorn/src/backends/gstreamer/__init__.py
   trunk/popcorn/src/backends/manager.py
   trunk/popcorn/src/backends/mplayer/__init__.py
   trunk/popcorn/src/backends/mplayer/config.cxml
   trunk/popcorn/src/backends/mplayer/player.py
   trunk/popcorn/src/backends/xine/__init__.py
   trunk/popcorn/src/backends/xine/player.py
   trunk/popcorn/src/generic.py
   trunk/popcorn/src/ptypes.py

Log:
update get_player_class to find out the best possible player

Modified: trunk/popcorn/src/backends/base.py
==============================================================================
--- trunk/popcorn/src/backends/base.py  (original)
+++ trunk/popcorn/src/backends/base.py  Fri Dec  8 15:12:01 2006
@@ -80,30 +80,6 @@
         self._frame_shmem = None
         
 
-    def get_capabilities(self):
-        """
-        Return player capabilities.
-        """
-        return self._player_caps        # filled by generic
-
-
-    def get_supported_schemes(self):
-        """
-        Return supported schemes.
-        """
-        return self._player_schemes     # filled by generic
-
-
-    def has_capability(self, cap):
-        """
-        Return if the player has the given capability.
-        """
-        supported_caps = self.get_capabilities()
-        if type(cap) not in (list, tuple):
-            return cap in supported_caps
-        return sets.Set(cap).issubset(sets.Set(supported_caps))
-
-
     # state handling
 
     def get_state(self):

Modified: trunk/popcorn/src/backends/gstreamer/__init__.py
==============================================================================
--- trunk/popcorn/src/backends/gstreamer/__init__.py    (original)
+++ trunk/popcorn/src/backends/gstreamer/__init__.py    Fri Dec  8 15:12:01 2006
@@ -39,7 +39,7 @@
     Return capabilities of the gstreamer backend.
     """
     capabilities = {
-        CAP_CANVAS : False,
+        CAP_OSD : False,
         CAP_CANVAS : False,
         CAP_DYNAMIC_FILTERS : False,
         CAP_VARIABLE_SPEED : False,
@@ -54,10 +54,10 @@
                 "rtp", "smb", "mms", "pnm", "rtsp" ]
 
     # list of extentions when to prefer this player
-    exts = config.preferred.extentions.split(' ')
+    exts = config.preferred.extentions.split(',')
 
     # list of codecs when to prefer this player
-    codecs = config.preferred.codecs.split(' ')
+    codecs = config.preferred.codecs.split(',')
 
     return capabilities, schemes, exts, codecs
 

Modified: trunk/popcorn/src/backends/manager.py
==============================================================================
--- trunk/popcorn/src/backends/manager.py       (original)
+++ trunk/popcorn/src/backends/manager.py       Fri Dec  8 15:12:01 2006
@@ -30,6 +30,10 @@
 
 # python imports
 import os
+import logging
+
+# kaa imports
+import kaa.metadata
 
 # kaa.popcorn imports
 from kaa.popcorn.ptypes import *
@@ -41,6 +45,8 @@
 # internal list of players
 _players = {}
 
+# get logging object
+log = logging.getLogger('popcorn.manager')
 
 def register(player_id, cls, get_caps_callback):
     """
@@ -63,7 +69,7 @@
     }
 
 
-def get_player_class(mrl = None, caps = None, exclude = None, force = None,
+def get_player_class((mrl, metadata), caps = None, exclude = None, force = 
None,
                      preferred = None):
     """
     Searches the registered players for the most capable player given the mrl
@@ -81,10 +87,6 @@
 
         player_caps, schemes, exts, codecs = _players[player_id]["callback"]()
 
-        # FIXME: fix the usage of player_caps everywhere to acceped a
-        # dict with capabilities and the rating
-        player_caps = [ x for x in player_caps.keys() if x ]
-        
         _players[player_id].update({
             "caps": player_caps,
             "schemes": schemes,
@@ -94,62 +96,84 @@
             "codecs": codecs,
             "loaded": True,
         })
-        cls = _players[player_id]['class']
-        cls._player_caps = player_caps
-        cls._player_schemes = schemes
-
 
-    if force == mrl == caps == None:
-        if preferred != None and preferred in _players:
-            return _players[preferred]["class"]
-            
-        # FIXME: return the best possible player. This requires a new
-        # register function with more information about how good a player
-        # is for playing a specific mrl.
-        return _players.values()[0]["class"]
 
     if force != None and force in _players:
-        return _players[force]["class"]
-
-    if mrl != None:
-        scheme, path = parse_mrl(mrl)
-        ext = os.path.splitext(path)[1]
-        if ext:
-            ext = ext[1:]  # Eat leading '.'
+        player = _players[force]
+        if scheme not in player["schemes"]:
+            return None
+        # return forced player, no matter if the other
+        # capabilities match or not
+        return player["class"]
+
+    scheme, path = parse_mrl(mrl)
+    ext = os.path.splitext(path)[1]
+    if ext:
+        ext = ext[1:]  # Eat leading '.'
 
     if caps != None and type(caps) not in (tuple, list):
         caps = (caps,)
     if exclude != None and type(exclude) not in (tuple, list):
         exclude  = (exclude,)
 
+    codecs = []
+    if metadata:
+        if metadata.media == kaa.metadata.MEDIA_AV:
+            codecs.extend( [ x.fourcc for x in metadata.video if x.fourcc ] )
+            codecs.extend( [ x.fourcc for x in metadata.audio if x.fourcc ] )
+        if 'fourcc' in metadata and metadata.fourcc:
+            codecs.append(metadata.fourcc)
+
     choice = None
+
     for player_id, player in _players.items():
-        if mrl != None and scheme not in player["schemes"]:
+        if scheme not in player["schemes"]:
             # MRL scheme is not supported by this player.
+            log.debug('skip %s, does not support %s', player_id, scheme)
             continue
+        
         if exclude and player_id in exclude:
             # Player is in exclude list.
+            log.debug('skip %s, in exclude list', player_id)
             continue
-        if caps != None and not 
sets.Set(caps).issubset(sets.Set(player["caps"])):
-            # Requested capabilities not present.
-            continue
-        if mrl and choice and ext in choice["extensions"] and ext not in 
player["extensions"]:
-            # Our current choice lists the mrl's extension while this choice 
-            # doesn't.
-            continue
 
-        if scheme == 'dvd' and choice and CAP_DVD_MENUS in player["caps"] and \
-           CAP_DVD_MENUS not in choice["caps"]:
-            # If the mrl is dvd, make sure we prefer the player that supports
-            # CAP_DVD_MENUS
-            choice = player
-        elif player_id == preferred or not choice:
-            choice = player
+        rating = 0
+        if caps:
+            # Rate player on the given capabilities. If one or more needed
+            # capabilities are False or 0, skip this player
+            for c in caps:
+                r = player['caps'].get(c, None)
+                if not r:
+                    log.debug("%s has no capability %s", player_id, c)
+                    rating = -1
+                    break
+                if not r == True:
+                    rating += r
+
+            if rating == -1:
+                # bad player
+                continue
+
+        if ext and ext in player["extensions"]:
+            # player is good at this extension
+            rating += 3
+
+        for c in codecs:
+            if c in player["codecs"]:
+                # player is good at this extension
+                rating += 3
+            
+        if preferred == player_id:
+            rating += 2
+
+        log.debug('%s rating: %s', player_id, rating)
+        if not choice or choice[1] < rating:
+            choice = player, rating
 
-    if not choice:
-        return None
+        if not choice:
+            return None
 
-    return choice["class"]
+    return choice[0]["class"]
 
 
 def get_all_players():

Modified: trunk/popcorn/src/backends/mplayer/__init__.py
==============================================================================
--- trunk/popcorn/src/backends/mplayer/__init__.py      (original)
+++ trunk/popcorn/src/backends/mplayer/__init__.py      Fri Dec  8 15:12:01 2006
@@ -71,10 +71,10 @@
                 "rtp", "rtsp", "ftp", "udp", "sdp", "dvd", "fifo" ]
 
     # list of extentions when to prefer this player
-    exts = config.preferred.extentions.split(' ')
+    exts = config.preferred.extentions.split(',')
 
     # list of codecs when to prefer this player
-    codecs = config.preferred.codecs.split(' ')
+    codecs = config.preferred.codecs.split(',')
 
     return capabilities, schemes, exts, codecs
 

Modified: trunk/popcorn/src/backends/mplayer/config.cxml
==============================================================================
--- trunk/popcorn/src/backends/mplayer/config.cxml      (original)
+++ trunk/popcorn/src/backends/mplayer/config.cxml      Fri Dec  8 15:12:01 2006
@@ -30,7 +30,7 @@
         </var>
 
         <!-- TODO: find a good default value -->
-        <var name="codecs" default="AVC1">
+        <var name="codecs" default="AVC1,FLV1">
             <desc>
                 Comma seperated list of video or audio codecs fourcc codes for
                 which this player should be the preferred player. Use mminfo

Modified: trunk/popcorn/src/backends/mplayer/player.py
==============================================================================
--- trunk/popcorn/src/backends/mplayer/player.py        (original)
+++ trunk/popcorn/src/backends/mplayer/player.py        Fri Dec  8 15:12:01 2006
@@ -344,12 +344,8 @@
             print 'Error: not idle'
             return False
 
-        schemes = self.get_supported_schemes()
         scheme, path = parse_mrl(mrl)
 
-        if scheme not in schemes:
-            raise ValueError, "Unsupported mrl scheme '%s'" % scheme
-
         self._file_args = []
         if scheme in ("file", "fifo"):
             self._file = path

Modified: trunk/popcorn/src/backends/xine/__init__.py
==============================================================================
--- trunk/popcorn/src/backends/xine/__init__.py (original)
+++ trunk/popcorn/src/backends/xine/__init__.py Fri Dec  8 15:12:01 2006
@@ -39,7 +39,7 @@
     Return capabilities of the xine backend.
     """
     capabilities = {
-        CAP_CANVAS : True,
+        CAP_OSD : True,
         CAP_CANVAS : True,
         CAP_DYNAMIC_FILTERS : False,
         CAP_VARIABLE_SPEED : True,
@@ -60,10 +60,10 @@
     codecs = []
 
     # list of extentions when to prefer this player
-    exts = config.preferred.extentions.split(' ')
+    exts = config.preferred.extentions.split(',')
 
     # list of codecs when to prefer this player
-    codecs = config.preferred.codecs.split(' ')
+    codecs = config.preferred.codecs.split(',')
 
     return capabilities, schemes, exts, codecs
 

Modified: trunk/popcorn/src/backends/xine/player.py
==============================================================================
--- trunk/popcorn/src/backends/xine/player.py   (original)
+++ trunk/popcorn/src/backends/xine/player.py   Fri Dec  8 15:12:01 2006
@@ -248,8 +248,7 @@
         Open mrl.
         """
         scheme, path = parse_mrl(mrl)
-        if scheme not in self.get_supported_schemes():
-            raise ValueError, "Unsupported mrl scheme '%s'" % scheme
+
         self._mrl = "%s:%s" % (scheme, path)
         if not self._xine:
             self._child_spawn()

Modified: trunk/popcorn/src/generic.py
==============================================================================
--- trunk/popcorn/src/generic.py        (original)
+++ trunk/popcorn/src/generic.py        Fri Dec  8 15:12:01 2006
@@ -37,6 +37,7 @@
 
 # kaa imports
 import kaa.notifier
+import kaa.metadata
 
 # kaa.popcorn imports
 import backends.manager
@@ -79,6 +80,7 @@
     def __init__(self, window=None, config=default_config):
 
         self._player = None
+        self._media = ( None, None )
         self._size = (0,0)
         self._aspect = None
         self.set_window(window)
@@ -129,7 +131,7 @@
     def _get_player_class(self, player=None):
         """
         Return player class object to play the current mrl. This function
-        uses self._open_mrl, self._open_caps as mrl and caps and respects
+        uses self._media, self._open_caps as mrl and caps and respects
         the failed player and the player deactived in the config. If player
         is given as argument, this player will be used.
         """
@@ -138,7 +140,7 @@
             if not getattr(self._config, p).activate and not p in exclude:
                 exclude.append(p)
         return backends.manager.get_player_class(\
-            self._open_mrl, self._open_caps, exclude, player,
+            self._media, self._open_caps, exclude, player,
             self._config.preferred)
 
 
@@ -167,7 +169,7 @@
             if cls:
                 # a new possible player is found, try it
                 self._create_player(cls)
-                self._open(self._open_mrl)
+                self._open()
                 self.play()
                 return True
             # everything failed
@@ -235,13 +237,14 @@
             
     
     @required_states(STATE_NOT_RUNNING, STATE_IDLE)
-    def _open(self, mrl):
+    def _open(self):
         """
         The real open function called from 'open'.
         """
         self._player.set_window(self._window)
         self._player.set_size(self._size, self._aspect)
-        self._player.open(mrl)
+        # FIXME: maybe give the whole media object to the child
+        self._player.open(self._media[0])
         self.signals['open'].emit()
 
 
@@ -258,7 +261,8 @@
 
         if mrl.find('://') == -1:
             mrl = 'file://' + os.path.abspath(mrl)
-        self._open_mrl = mrl
+
+        self._media = mrl, kaa.metadata.parse(mrl)
         self._open_caps = caps
         self._failed_player = []
         cls = self._get_player_class(player)
@@ -276,7 +280,7 @@
             if not isinstance(self._player, cls):
                 self._player.release()
                 self._create_player(cls)
-        self._open(mrl)
+        self._open()
 
 
     @required_states(STATE_OPEN, STATE_PLAYING, STATE_PAUSED)
@@ -463,15 +467,6 @@
             return self._player.set_aspect(aspect)
 
 
-    def has_capability(self, cap):
-        """
-        Return if the player has the given capability.
-        """
-        if self._player:
-            return self._player.has_capability(cap)
-        return False
-
-
     # For CAP_OSD
 
     def osd_can_update(self):

Modified: trunk/popcorn/src/ptypes.py
==============================================================================
--- trunk/popcorn/src/ptypes.py (original)
+++ trunk/popcorn/src/ptypes.py Fri Dec  8 15:12:01 2006
@@ -26,15 +26,14 @@
 #
 # -----------------------------------------------------------------------------
 
-CAP_NONE  = 0
-CAP_OSD   = 3
-CAP_DVD = 4
-CAP_DVD_MENUS = 5
-CAP_DYNAMIC_FILTERS = 6
-CAP_VARIABLE_SPEED = 7
-CAP_VISUALIZATION = 8
-CAP_DEINTERLACE = 9
-CAP_CANVAS = 10
+CAP_OSD = 'CAP_OSD'
+CAP_CANVAS = 'CAP_CANVAS'
+CAP_DYNAMIC_FILTERS = 'CAP_DYNAMIC_FILTERS'
+CAP_VARIABLE_SPEED = 'CAP_VARIABLE_SPEED'
+CAP_VISUALIZATION = 'CAP_VISUALIZATION'
+CAP_DVD = 'CAP_DVD'
+CAP_DVD_MENUS = 'CAP_DVD_MENUS'
+CAP_DEINTERLACE = 'CAP_DEINTERLACE'
 
 STATE_NOT_RUNNING = 'STATE_NOT_RUNNING'
 STATE_IDLE = 'STATE_IDLE'

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to