Author: dmeyer
Date: Fri Feb 23 16:33:21 2007
New Revision: 2513

Added:
   trunk/WIP/record/src/device.py
   trunk/WIP/record/src/recording.py
      - copied, changed from r2512, /trunk/record/src/recording.py
   trunk/WIP/record/src/sink.py
Modified:
   trunk/WIP/record/src/__init__.py
   trunk/WIP/record/src/channel.py
   trunk/WIP/record/test/tuner.py

Log:
add recording interface similar to kaa.record1

Modified: trunk/WIP/record/src/__init__.py
==============================================================================
--- trunk/WIP/record/src/__init__.py    (original)
+++ trunk/WIP/record/src/__init__.py    Fri Feb 23 16:33:21 2007
@@ -6,4 +6,9 @@
 gst.plugin_load_file(dirname + '/_gstrecord.so')
 
 from channel import *
+from device import Device
+from sink import *
+from recording import Recording
+
+# FIXME: remove this
 from gstdvbsrc import DVBsrc

Modified: trunk/WIP/record/src/channel.py
==============================================================================
--- trunk/WIP/record/src/channel.py     (original)
+++ trunk/WIP/record/src/channel.py     Fri Feb 23 16:33:21 2007
@@ -37,7 +37,7 @@
 import logging
 
 # get logging object
-log = logging.getLogger('record')
+log = logging.getLogger('record.channel')
 
 class Channel(object):
     # TODO / FIXME add missing compare function

Added: trunk/WIP/record/src/device.py
==============================================================================
--- (empty file)
+++ trunk/WIP/record/src/device.py      Fri Feb 23 16:33:21 2007
@@ -0,0 +1,95 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# device.py - General Device Wrapper
+# -----------------------------------------------------------------------------
+# $Id: recording.py 915 2005-11-23 19:26:28Z dmeyer $
+#
+# -----------------------------------------------------------------------------
+# kaa-record - A recording module
+# Copyright (C) 2007 S�nke Schwardt, Dirk Meyer
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+
+__all__ = [ 'Device' ]
+
+# python imports
+import logging
+
+# gstreamer imports
+import pygst
+pygst.require('0.10')
+import gst
+
+# kaa.record imports
+import gstdvbsrc
+
+# get logging object
+log = logging.getLogger('record.gstreamer')
+
+class Device(object):
+
+    def __init__(self, device):
+
+        # create gstreamer pipline
+        self.pipeline = gst.Pipeline()
+        self.pipeline.get_bus().add_watch(self._gst_event)
+
+        if device.startswith('dvb'):
+            self.device = gstdvbsrc.DVBsrc()
+            self.device.set_property('adapter', int(device[3:]))
+
+        self.pipeline.add(self.device)
+        # FIXME: set to playing when needed
+        self.pipeline.set_state(gst.STATE_PLAYING)
+
+
+    def _gst_event(self, bus, message):
+        t = message.type
+        if t == gst.MESSAGE_EOS:
+            log.info('EOS')
+        elif t == gst.MESSAGE_ERROR:
+            err, debug = message.parse_error()
+            log.error('%s: %s', err, debug)
+        else:
+            log.info(str(message))
+        return True
+
+
+    def start_recording(self, channel, output):
+        element = output.element
+        self.pipeline.add(element)
+        element.set_state(gst.STATE_PLAYING)
+        sink = element.get_pad('sink')
+        # FIXME: clean up needed
+        pids = int(channel.config['vpid']), int(channel.config['apids'][0][0])
+        self.device.set_property('channel', channel)
+        self.device.get_request_pad(*pids).link(sink)
+
+
+    def stop_recording(self, output):
+        element = output.element
+        pad = element.get_pad('sink')
+        peer = pad.get_peer()
+        peer.unlink(pad)
+        self.device.remove_pad(peer)
+        element.unparent()
+        element.set_state(gst.STATE_NULL)

Copied: trunk/WIP/record/src/recording.py (from r2512, 
/trunk/record/src/recording.py)
==============================================================================
--- /trunk/record/src/recording.py      (original)
+++ trunk/WIP/record/src/recording.py   Fri Feb 23 16:33:21 2007
@@ -6,12 +6,12 @@
 #
 # -----------------------------------------------------------------------------
 # kaa-record - A recording module
-# Copyright (C) 2005 S�nke Schwardt, Dirk Meyer
+# Copyright (C) 2005-2007 S�nke Schwardt, Dirk Meyer
 #
 # First Edition: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
 #
-# Please see the file doc/CREDITS for a complete list of authors.
+# 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
@@ -60,14 +60,13 @@
         self.signals = { 'start': Signal(), 'stop': Signal() }
 
         # internal timer
-        self.timer = { 'start': OneShotTimer(self.__start),
-                       'stop': OneShotTimer(self.__stop) }
-        # id from device.start_recording
-        self.__rec_id = None
+        self.timer = { 'start': OneShotTimer(self._start),
+                       'stop': OneShotTimer(self._stop) }
+        self.is_running = False
         # start timer
-        self.__schedule()
-        
-        
+        self._schedule()
+
+
     def modify(self, start, stop):
         """
         Modify start or stop time of the recording. When the
@@ -76,38 +75,31 @@
         self.start = start
         self.stop = stop
         # restart timer
-        self.__schedule()
+        self._schedule()
 
 
     def remove(self):
         """
         Remove the recording.
         """
-        if self.recording():
-            self.__stop()
+        if self.is_running:
+            self._stop()
         self.timer['start'].stop()
         self.timer['stop'].stop()
 
-        
-    def recording(self):
-        """
-        Return True if the recording is in progress.
-        """
-        return self.__rec_id != None
-
 
     def active(self):
         """
         Return True if the recording is scheduled or in progress.
         """
-        return self.timer['start'].active() or self.recording()
+        return self.timer['start'].active() or self.is_running
 
 
-    def __schedule(self):
+    def _schedule(self):
         """
         Schedule timer for recording.
         """
-        if not self.recording():
+        if not self.is_running:
             # rec not started yet
             wait = int(max(0, self.start - time.time()))
             log.info('start recording %s in %s seconds' % (self.id, wait))
@@ -115,26 +107,27 @@
         wait = int(max(0, self.stop - time.time()))
         log.info('stop recording %s in %s seconds' % (self.id, wait))
         self.timer['stop'].start(wait)
-            
 
-    def __start(self):
+
+    def _start(self):
         """
         Callback to start the recording.
         """
         log.info('start recording %s' % self.id)
-        self.__rec_id = self.device.start_recording(self.channel, self.output)
+        self.device.start_recording(self.channel, self.output)
+        self.is_running = True
         self.signals['start'].emit()
 
-        
-    def __stop(self):
+
+    def _stop(self):
         """
         Callback to stop the recording.
         """
-        if not self.recording():
+        if not self.is_running:
             # ignore, already dead
             log.info('recording %s already dead' % self.id)
             return
         log.info('stop recording %s' % self.id)
-        self.device.stop_recording(self.__rec_id)
-        self.__rec_id = None
+        self.device.stop_recording(self.output)
+        self.is_running = False
         self.signals['stop'].emit()

Added: trunk/WIP/record/src/sink.py
==============================================================================
--- (empty file)
+++ trunk/WIP/record/src/sink.py        Fri Feb 23 16:33:21 2007
@@ -0,0 +1,10 @@
+__all__ = [ 'Filewriter' ]
+
+import pygst
+pygst.require('0.10')
+import gst
+
+class Filewriter(object):
+    def __init__(self, filename):
+        self.element = gst.element_factory_make('filesink')
+        self.element.set_property('location', filename)

Modified: trunk/WIP/record/test/tuner.py
==============================================================================
--- trunk/WIP/record/test/tuner.py      (original)
+++ trunk/WIP/record/test/tuner.py      Fri Feb 23 16:33:21 2007
@@ -4,14 +4,18 @@
 import gst
 import sys
 import time
+import gc
+import logging
 
 # import kaa.notifier and set mainloop to glib
 import kaa.notifier
 kaa.notifier.init('gtk', x11=False)
 
-# import kaa.record2 for the dvbtuner module
 import kaa.record2
 
+logging.getLogger('record').setLevel(logging.INFO)
+logging.getLogger('record.channel').setLevel(logging.ERROR)
+
 # test app logic
 
 def bus_event(bus, message):
@@ -26,6 +30,14 @@
     print message
     return True
 
+def tuner_debug(dvb):
+    print dvb._tuner.get_property('status')
+
+def gc_check():
+    gc.collect()
+    for g in gc.garbage:
+        print 'oops', g
+
 if len(sys.argv) < 3:
     print 'syntax: %s <channels.conf> <channelname>' % sys.argv[0]
     sys.exit()
@@ -40,44 +52,17 @@
 print 'using channel config of %s' % sys.argv[1]
 print 'and searching channel %s' % sys.argv[2]
 
-# create gstreamer pipline
-pipeline = gst.Pipeline()
-pipeline.get_bus().add_watch(bus_event)
-
-# create DVBCard object and add it
-dvb = kaa.record2.DVBsrc()
-# FIXME: it would be nice to do
-# gst.element_factory_make("dvbsrc")
-
-dvb.set_property('adapter', 0)
-dvb.set_property('channel', chan)
-
-pipeline.add(dvb)
-pipeline.set_state(gst.STATE_PLAYING)
-
-def create_recording(filename, *pids):
-    sink = gst.element_factory_make('filesink')
-    sink.set_property('location', filename)
-    pipeline.add(sink)
-    sink.set_state(gst.STATE_PLAYING)
-    dvb.get_request_pad(*pids).link(sink.get_pad('sink'))
-    return sink
-
-def stop_recording(sink):
-    pad = sink.get_pad('sink')
-    peer = pad.get_peer()
-    peer.unlink(pad)
-    dvb.remove_pad(peer)
-    sink.unparent()
-    sink.set_state(gst.STATE_NULL)
-
-
-zdf = create_recording('zdf.ts', 545, 546)
-
-# start 3sat in 3 seconds
-kaa.notifier.OneShotTimer(create_recording, '3sat.ts', 561, 562).start(3)
-# start second ZDF recording in 5 seconds
-kaa.notifier.OneShotTimer(create_recording, 'zdf2.ts', 545, 546).start(5)
-# stop first ZDF recording 5 seconds later
-kaa.notifier.OneShotTimer(stop_recording, zdf).start(10)
+device = kaa.record2.Device('dvb0')
+
+kaa.record2.Recording(time.time() + 3, time.time() + 8, device,
+                      chan, kaa.record2.Filewriter('zdf.ts'))
+kaa.notifier.Timer(tuner_debug, device.device).start(1)
+
+# # start 3sat in 3 seconds
+# kaa.notifier.OneShotTimer(create_recording, '3sat.ts', 561, 562).start(3)
+# # start second ZDF recording in 5 seconds
+# kaa.notifier.OneShotTimer(create_recording, 'zdf2.ts', 545, 546).start(5)
+# # stop first ZDF recording 5 seconds later
+
+kaa.notifier.Timer(gc_check).start(1)
 kaa.notifier.loop()

-------------------------------------------------------------------------
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