Author: dmeyer
Date: Thu Jan 4 18:32:13 2007
New Revision: 2348
Modified:
trunk/popcorn/src/backends/mplayer/child.py
trunk/popcorn/src/backends/mplayer/player.py
Log:
cleanup in the new code
Modified: trunk/popcorn/src/backends/mplayer/child.py
==============================================================================
--- trunk/popcorn/src/backends/mplayer/child.py (original)
+++ trunk/popcorn/src/backends/mplayer/child.py Thu Jan 4 18:32:13 2007
@@ -1,8 +1,62 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# mplayer/child.py - mplayer child wrapper
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# kaa.popcorn - Generic Player API
+# Copyright (C) 2006 Jason Tackaberry, Dirk Meyer
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import logging
+
+# kaa imports
import kaa.notifier
# start mplayer in gdb for debugging
USE_GDB = False
+# get logging object
+log = logging.getLogger('popcorn.mplayer')
+
+class Arguments(list):
+ """
+ Argument list.
+ """
+ def __init__(self, args=()):
+ if args:
+ args = args.split(' ')
+ list.__init__(self, args)
+
+
+ def add(self, **kwargs):
+ """
+ Add -key=value arguments.
+ """
+ for key, value in kwargs.items():
+ if value is None:
+ continue
+ self.extend(('-' + key.replace('_', '-'), str(value)))
+
class ChildCommand(object):
"""
@@ -20,13 +74,19 @@
if not self._app.is_alive():
return
cmd = '%s %s' % (self._cmd, ' '.join([ str(x) for x in args]))
- # print self._func, cmd
+ log.debug('send %s', cmd)
self._app._child.write(cmd.strip() + '\n')
-class MplayerApp(object):
-
+class MPlayerApp(object):
+ """
+ Mplayer child wrapper,
+ """
def __init__(self, command=None):
+ # create argument list
+ self.args = Arguments("-v -slave -osdlevel 0 -nolirc -nojoystick " +
+ "-nodouble -fixed-vo -identify -framedrop")
+ self.filters = []
if not command:
return
if USE_GDB:
@@ -37,8 +97,18 @@
self.signals = self._child.signals
stop = kaa.notifier.WeakCallback(self._child_stop)
self._child.set_stop_command(stop)
-
- def start(self, args):
+
+
+ def start(self, media):
+ args = self.args[:]
+ if self.filters:
+ args.extend(('-vf', ",".join(self.filters)))
+
+ # add extra file arguments
+ args.extend(media.mplayer_args)
+
+ log.info("spawn: %s %s", self._mp_cmd, ' '.join(args))
+
if USE_GDB:
self._child.start(self._command)
self._child.write("run %s\n" % ' '.join(args))
@@ -58,7 +128,7 @@
if line.startswith("Program received signal SIGSEGV"):
# Mplayer crashed, issue backtrace.
self._child.write("thread apply all bt\n")
-
+
def stop(self):
self._child.stop()
@@ -66,7 +136,7 @@
def is_alive(self):
return self._child and self._child.is_alive()
-
+
def __getattr__(self, attr):
"""
Modified: trunk/popcorn/src/backends/mplayer/player.py
==============================================================================
--- trunk/popcorn/src/backends/mplayer/player.py (original)
+++ trunk/popcorn/src/backends/mplayer/player.py Thu Jan 4 18:32:13 2007
@@ -47,7 +47,7 @@
from kaa.popcorn.backends.base import MediaPlayer
from kaa.popcorn.ptypes import *
-from child import MplayerApp
+from child import MPlayerApp
BUFFER_UNLOCKED = 0x10
BUFFER_LOCKED = 0x20
@@ -61,18 +61,6 @@
# keyed on the full path of the MPlayer binary.
_cache = {}
-class Arguments(list):
- def __init__(self, args=()):
- if args:
- args = args.split(' ')
- list.__init__(self, args)
-
- def add(self, **kwargs):
- for key, value in kwargs.items():
- if value is None:
- continue
- self.extend(('-' + key.replace('_', '-'), str(value)))
-
def _get_mplayer_info(path, callback = None, mtime = None):
"""
Fetches info about the given MPlayer executable. If the values are
@@ -176,7 +164,7 @@
if not self._mp_cmd:
raise PlayerError, "No MPlayer executable found in PATH"
- self._mplayer = MplayerApp()
+ self._mplayer = MPlayerApp()
self._filters_pre = []
self._filters_add = []
@@ -334,13 +322,13 @@
if self.get_state() != STATE_NOT_RUNNING:
raise RuntimeError('mplayer not in STATE_NOT_RUNNING')
- args = Arguments()
+ args = []
if media.scheme == "dvd":
file, title = re.search("(.*?)(\/\d+)?$", media.url[4:]).groups()
if file.replace('/', ''):
if not os.path.isfile(file):
raise ValueError, "Invalid ISO file: %s" % file
- args.add(dvd_device=file)
+ args.extend(('-dvd-device', file))
args.append("dvd://")
if title:
args[-1] += title[1:]
@@ -380,14 +368,17 @@
# not be selected by the generic one. FIXME: verify that!
assert(self._mp_info)
- # create argument list
- args = Arguments("-v -slave -osdlevel 0 -nolirc -nojoystick " +
- "-nodouble -fixed-vo -identify -framedrop")
+ # create mplayer object
+ self._mplayer = MPlayerApp(self._mp_cmd)
+
+ # get argument and filter list
+ args, filters = self._mplayer.args, self._mplayer.filters
+
if 'x11' in self._mp_info['video_drivers']:
args.append('-nomouseinput')
# create filter list
- filters = self._filters_pre[:]
+ filters.extend(self._filters_pre[:])
if 'outbuf' in self._mp_info['video_filters']:
filters += ["outbuf=%s:yv12" % self._frame_shmkey]
@@ -443,9 +434,6 @@
if 'overlay' in self._mp_info['video_filters']:
filters.append("overlay=%s" % self._osd_shmkey)
- if filters:
- args.add(vf=",".join(filters))
-
if isinstance(self._window, kaa.display.X11Window):
args.add(vo='xv', wid=hex(self._window.get_id()),
display=self._window.get_display().get_string())
@@ -509,17 +497,13 @@
elif self._properties.get('subtitle-track') != None:
args.add(sid=self._properties.get('subtitle-track'))
- # add extra file arguments
- args.extend(self._media.mplayer_args)
-
- log.info("spawn: %s %s", self._mp_cmd, ' '.join(args))
-
- self._mplayer = MplayerApp(self._mp_cmd)
+ # connect to signals
self._mplayer.signals["stdout"].connect_weak(self._child_handle_line)
self._mplayer.signals["stderr"].connect_weak(self._child_handle_line)
self._mplayer.signals["completed"].connect_weak(self._child_exited)
- self._mplayer.start(args)
- return
+
+ # start playback
+ self._mplayer.start(self._media)
def stop(self):
-------------------------------------------------------------------------
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