Author: dmeyer
Date: Mon Nov 6 15:03:03 2006
New Revision: 1983
Removed:
trunk/popcorn/src/backends/gstreamer/gst_types.py
Modified:
trunk/popcorn/src/backends/gstreamer/child.py
trunk/popcorn/src/backends/gstreamer/main.py
trunk/popcorn/src/backends/gstreamer/player.py
Log:
make gstreamer work again
Modified: trunk/popcorn/src/backends/gstreamer/child.py
==============================================================================
--- trunk/popcorn/src/backends/gstreamer/child.py (original)
+++ trunk/popcorn/src/backends/gstreamer/child.py Mon Nov 6 15:03:03 2006
@@ -1,59 +1,84 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# gstreamer/child.py - child process for gstreamer backend
+# -----------------------------------------------------------------------------
+# $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 os
import sys
import fcntl
+# gstreamer imports
import pygst
pygst.require('0.10')
import gst
+# import kaa.notifier and set mainloop to glib
import kaa.notifier
kaa.notifier.init('gtk', x11=False)
+# kaa.popcorn imports
from kaa.popcorn.utils import Player
from kaa.popcorn.ptypes import *
-from gst_types import Status
class GStreamer(Player):
-
- def __init__(self, instance_id):
+ """
+ gstreamer based player
+ """
+ def __init__(self):
Player.__init__(self)
self._gst = None
- self._status_object = Status(self._send_status)
- self._status_last = None
self._streaminfo = {}
-
- def get_status(self):
- return self._status_object.get_status()
-
- def set_status(self, status):
- return self._status_object.set_status(status)
-
- status = property(get_status, set_status, None, '')
-
- def _send_status(self):
+
+ # create gst object
+ self._gst = gst.element_factory_make("playbin", "player")
+ self._gst.get_bus().add_watch(self._gst_message)
+ self._timer = kaa.notifier.WeakTimer(self._get_position)
+
+
+ def set_state(self, state):
"""
- Outputs stream status information.
+ Set state on parent and start/stop position timer.
"""
- if not self._gst:
- return
-
- pos = 0
- if self.status == Status.PLAYING:
- pos = float(self._gst.query_position(gst.FORMAT_TIME)[0] /
1000000) / 1000
- current = self.status, pos
-
- if current != self._status_last:
- self._status_last = current
- self.parent.set_status(*current)
+ self.parent.set_state(state)
+ self._timer.stop()
+ if state == STATE_PLAYING:
+ self._timer.start(0.1)
def _gst_message(self, bus, msg):
+ """
+ Message from gstreamer thread.
+ """
# do something clever here
if msg.type == gst.MESSAGE_STATE_CHANGED:
old, new, pending = msg.parse_state_changed()
if new == gst.STATE_PLAYING:
- self.status = Status.PLAYING
+ self.set_state(STATE_PLAYING)
return True
if msg.type == gst.MESSAGE_ERROR:
@@ -66,10 +91,10 @@
gst.STREAM_ERROR_TYPE_NOT_FOUND,
gst.STREAM_ERROR_WRONG_TYPE):
# unable to play
- self.status = Status.IDLE
+ self.set_state(STATE_IDLE)
return True
if e.domain.startswith('gst-resource-error'):
- self.status = Status.IDLE
+ self.set_state(STATE_IDLE)
return True
# print e, e.code, e.domain
return True
@@ -77,55 +102,95 @@
taglist = msg.parse_tag()
for key in taglist.keys():
self._streaminfo[key] = taglist[key]
+ self.parent.set_streaminfo(self._streaminfo)
return True
-
-
- # calls from parent
-
- def setup(self, wid):
- # create xv sink
- vo = gst.element_factory_make("xvimagesink", "vo")
- vo.set_xwindow_id(long(wid))
- vo.set_property('force-aspect-ratio', True)
- # now create the player and set the output
- self._gst = gst.element_factory_make("playbin", "player")
+
+ def _get_position(self):
+ """
+ Get stream position and send to parent process.
+ """
+ usec = self._gst.query_position(gst.FORMAT_TIME)[0]
+ pos = float(usec / 1000000) / 1000
+ self.parent.set_position(pos)
+
+
+ #
+ # setup from parent
+ #
+
+ def configure_video(self, driver, **kwargs):
+ """
+ Set video driver and parameter.
+ """
+ if driver == 'xv':
+ vo = gst.element_factory_make("xvimagesink", "vo")
+ vo.set_xwindow_id(long(kwargs.get('window')))
+ vo.set_property('force-aspect-ratio', True)
+ elif driver == 'none':
+ vo = gst.element_factory_make("fakesink", "vo")
+ else:
+ raise AttributeError('Unsupported video driver %s', driver)
self._gst.set_property('video-sink', vo)
- self._gst.get_bus().add_watch(self._gst_message)
+ def configure_audio(self, driver):
+ """
+ Set audio driver (oss or alsa).
+ """
+ ao = gst.element_factory_make("%ssink" % driver, "ao")
+ self._gst.set_property('audio-sink', ao)
+
+
+
+ #
+ # commands from parent
+ #
+
def open(self, uri):
+ """
+ Open mrl.
+ """
self._gst.set_property('uri', uri)
- self.status = Status.OPENING
self._streaminfo = {}
-
+ self.set_state(STATE_OPEN)
+
def play(self):
+ """
+ Start or resume playback.
+ """
self._gst.set_state(gst.STATE_PLAYING)
- def pause(self):
- self._gst.set_state(gst.STATE_PAUSED)
-
-
def stop(self):
+ """
+ Stop playback.
+ """
self._gst.set_state(gst.STATE_NULL)
- self.status = Status.IDLE
+ self.set_state(STATE_IDLE)
- def die(self):
- sys.exit(0)
+ def pause(self):
+ """
+ Pause playback.
+ """
+ self._gst.set_state(gst.STATE_PAUSED)
def seek(self, value, type):
+ """
+ SEEK_RELATIVE, SEEK_ABSOLUTE or SEEK_PERCENTAGE.
+ """
pos = 0
if type == SEEK_RELATIVE:
- pos = self._gst.query_position(gst.FORMAT_TIME)[0] + value *
1000000000
+ current = self._gst.query_position(gst.FORMAT_TIME)[0]
+ pos = current + value * 1000000000
if type == SEEK_ABSOLUTE:
pos = value * 1000000000
if type == SEEK_PERCENTAGE and 'duration' in self._streaminfo:
pos = (self._streaminfo['duration'] / 100) * value
+ # seek now
self._gst.seek(1.0, gst.FORMAT_TIME,
gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
gst.SEEK_TYPE_SET, pos, gst.SEEK_TYPE_NONE, 0)
-
Modified: trunk/popcorn/src/backends/gstreamer/main.py
==============================================================================
--- trunk/popcorn/src/backends/gstreamer/main.py (original)
+++ trunk/popcorn/src/backends/gstreamer/main.py Mon Nov 6 15:03:03 2006
@@ -1,7 +1,6 @@
-import sys
import kaa
from child import GStreamer
-player = GStreamer(sys.argv[1])
+player = GStreamer()
kaa.main()
Modified: trunk/popcorn/src/backends/gstreamer/player.py
==============================================================================
--- trunk/popcorn/src/backends/gstreamer/player.py (original)
+++ trunk/popcorn/src/backends/gstreamer/player.py Mon Nov 6 15:03:03 2006
@@ -1,125 +1,123 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# gstreamer/player.py - gstreamer backend
+# -----------------------------------------------------------------------------
+# $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 sys
import os
-import kaa.notifier
+# kaa imports
+from kaa.notifier import WeakCallback
+# kaa.popcorn imports
from kaa.popcorn.backends.base import MediaPlayer
from kaa.popcorn.ptypes import *
from kaa.popcorn.utils import ChildProcess
-from gst_types import Status
class GStreamer(MediaPlayer):
- _instance_count = 0
-
def __init__(self):
super(GStreamer, self).__init__()
- self._instance_id = "kaa.gst-%d-%d" % (os.getpid(),
GStreamer._instance_count)
- GStreamer._instance_count += 1
-
- self._stream_info = {}
- self._position = 0.0
self._state = STATE_NOT_RUNNING
+ self._gst = None
- def _span(self):
- script = os.path.join(os.path.dirname(__file__), 'main.py')
- self._gst = ChildProcess(self, script, str(self._instance_id))
- self._gst.signals["completed"].connect_weak(self._exited)
- self._gst.set_stop_command(kaa.notifier.WeakCallback(self._end_child))
- self._gst.start()
- self._state = STATE_IDLE
-
-
- def _exited(self, exitcode):
+ def _child_exited(self, exitcode):
self._state = STATE_NOT_RUNNING
+ self._gst = None
- def _end_child(self):
- self._state = STATE_SHUTDOWN
- self._gst.die()
-
-
- # child handling
-
- def _child_set_status(self, status, pos):
- if status == Status.PLAYING:
- if not self.get_state() in (STATE_PLAYING, STATE_PAUSED):
- self._state = STATE_PLAYING
- self._position = pos
- return True
- if status == Status.IDLE:
- self._state = STATE_IDLE
- self._position = 0
-
-
# public API
-
+
def open(self, mrl):
+ """
+ Open mrl.
+ """
if mrl.find('://') == -1:
mrl = 'file://' + mrl
self._mrl = mrl
- if self._state == STATE_NOT_RUNNING:
- self._span()
+ if not self._gst:
+ script = os.path.join(os.path.dirname(__file__), 'main.py')
+ self._gst = ChildProcess(self, script)
+ self._gst.signals["completed"].connect_weak(self._child_exited)
+ self._gst.set_stop_command(WeakCallback(self._gst.die))
+ self._gst.start()
self._position = 0.0
+ self._state = STATE_OPENING
+ self._gst.open(self._mrl)
+ if self._window:
+ self._gst.configure_video('xv', window=self._window.get_id())
+ else:
+ self._gst.configure_video('none')
+ self._gst.configure_audio(self._config.audio.driver)
def play(self):
"""
- Start playing. If playback is paused, resume. If not wait
- async until either the playing has started or an error
- occurred.
+ Start playback.
"""
- wid = None
- if self._window:
- wid = self._window.get_id()
- self._gst.setup(wid=wid)
- self._gst.open(self._mrl)
self._gst.play()
- self._state = STATE_OPENING
- return
+
+
+ def stop(self):
+ """
+ Stop playback.
+ """
+ self._gst.stop()
def pause(self):
+ """
+ Pause playback.
+ """
self._gst.pause()
self._state = STATE_PAUSED
def resume(self):
+ """
+ Resume playback.
+ """
self._gst.play()
self._state = STATE_PLAYING
-
- def stop(self):
- self._gst.stop()
-
-
- def die(self):
- self.stop()
- self._gst.die()
- self._state = STATE_SHUTDOWN
-
-
- def get_info(self):
- return self._stream_info
-
- def osd_can_update(self):
- return False
-
-
- def get_position(self):
- return self._position
+ def release(self):
+ """
+ Release audio and video devices.
+ """
+ if self._gst:
+ self._state = STATE_SHUTDOWN
+ self._gst.die()
def seek(self, value, type):
+ """
+ SEEK_RELATIVE, SEEK_ABSOLUTE or SEEK_PERCENTAGE.
+ """
self._gst.seek(value, type)
-
-
- def nav_command(self, input):
- return False
-
-
- def is_in_menu(self):
- return False
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog