pitivi r1231 - in branches/SOC_2008_SLAKSHMAN: . pitivi pitivi/ui



Author: slynux
Date: Mon Aug 11 15:39:38 2008
New Revision: 1231
URL: http://svn.gnome.org/viewvc/pitivi?rev=1231&view=rev

Log:
Network stream capture rewrote with smartbin

Modified:
   branches/SOC_2008_SLAKSHMAN/ChangeLog
   branches/SOC_2008_SLAKSHMAN/pitivi/bin.py
   branches/SOC_2008_SLAKSHMAN/pitivi/ui/mainwindow.py
   branches/SOC_2008_SLAKSHMAN/pitivi/ui/netstream_managerdialog.py
   branches/SOC_2008_SLAKSHMAN/pitivi/ui/screencast_managerdialog.py
   branches/SOC_2008_SLAKSHMAN/pitivi/ui/webcam_managerdialog.py

Modified: branches/SOC_2008_SLAKSHMAN/pitivi/bin.py
==============================================================================
--- branches/SOC_2008_SLAKSHMAN/pitivi/bin.py	(original)
+++ branches/SOC_2008_SLAKSHMAN/pitivi/bin.py	Mon Aug 11 15:39:38 2008
@@ -26,6 +26,8 @@
 import gobject
 import gst
 from elements.smartscale import SmartVideoScale
+from objectfactory import FileSourceFactory
+
 
 class SmartBin(gst.Pipeline):
     """
@@ -610,3 +612,97 @@
 
         self.recording = False
         return True
+
+
+
+
+class SmartStreamBin(SmartFileBin):
+    """
+    SmartStreamBin with network stream from URI can be used as source.
+    """
+
+    def __init__(self, url):
+        gst.log("Creating new smartstreambin")
+
+	
+	self.factory = FileSourceFactory(url)
+        self.source = self.factory.makeBin()
+
+
+        SmartBin.__init__(self, "smartdefaultbin", has_video=True, has_audio=True)
+
+
+    def record(self, uri, settings=None):
+        """
+        Render the SmartBin to the given uri.
+        Returns : True if the encoding process could be started properly, False otherwise."""
+        self.debug("setting to READY")
+        if self.set_state(gst.STATE_READY) == gst.STATE_CHANGE_FAILURE:
+            self.warning("Couldn't switch to READY !")
+            return False
+
+        if self.recording:
+            self.error("This bin is already in in recording mode !")
+            return
+
+        # temporarily remove the audiosinkthread
+        #self.debug("disconnecting audio sink thread")
+        #self.tmpasink = self.asinkthread
+        # if not self.removeAudioSinkThread():
+        #     return False
+
+        self.debug("creating and adding encoding thread")
+        self.encthread = self._makeEncThread(uri, settings)
+        if not self.encthread:
+            gst.warning("Couldn't create encoding thread")
+            return False
+        self.add(self.encthread)
+        self.debug("encoding thread added")
+
+        # set sync=false on the videosink
+        #self.getRealVideoSink().set_property("sync", False)
+
+        self.debug("linking vtee to ecnthread:vsink")
+        try:
+            self.vtee.get_request_pad("src%d").link(self.encthread.get_pad("vsink"))
+        except:
+            return False
+
+        self.debug("linking atee to encthread:asink")
+        try:
+            self.atee.get_request_pad("src%d").link(self.encthread.get_pad("asink"))
+        except:
+            return False
+
+        self.debug("going back to PLAYING")
+        changeret = self.set_state(gst.STATE_PLAYING)
+        self.debug("now in PLAYING, set_state() returned %r" % changeret)
+        if changeret == gst.STATE_CHANGE_FAILURE:
+            return False
+
+        self.recording = True
+        return True
+
+    def stopRecording(self):
+        """ stop the recording, removing the encoding thread """
+        if self.recording == False:
+            self.warning("This bin is not in recording mode !")
+            return False
+
+        self.set_state(gst.STATE_PAUSED)
+
+        if self.encthread:
+            apad = self.encthread.get_pad("vsink")
+            apad.get_peer().unlink(apad)
+            apad = self.encthread.get_pad("asink")
+            apad.get_peer().unlink(apad)
+            self.remove(self.encthread)
+            self.encthread.set_state(gst.STATE_NULL)
+            del self.encthread
+            self.encthread = None
+            
+        self.getRealVideoSink().set_property("sync", True)
+
+        self.recording = False
+        return True
+

Modified: branches/SOC_2008_SLAKSHMAN/pitivi/ui/mainwindow.py
==============================================================================
--- branches/SOC_2008_SLAKSHMAN/pitivi/ui/mainwindow.py	(original)
+++ branches/SOC_2008_SLAKSHMAN/pitivi/ui/mainwindow.py	Mon Aug 11 15:39:38 2008
@@ -321,6 +321,17 @@
     ## UI Callbacks
 
     def _destroyCb(self, unused_widget, data=None):
+
+	# Quit connection to istanbul/switch off savemode
+	try:
+		bus = dbus.SessionBus()
+            	remote_object = bus.get_object("org.gnome.istanbul", "/state")
+            	self.iface = dbus.Interface(remote_object, "org.gnome.istanbul")
+		self.iface.savemode(False)
+	except:
+		pass
+
+
         instance.PiTiVi.shutdown()
 
 

Modified: branches/SOC_2008_SLAKSHMAN/pitivi/ui/netstream_managerdialog.py
==============================================================================
--- branches/SOC_2008_SLAKSHMAN/pitivi/ui/netstream_managerdialog.py	(original)
+++ branches/SOC_2008_SLAKSHMAN/pitivi/ui/netstream_managerdialog.py	Mon Aug 11 15:39:38 2008
@@ -29,10 +29,12 @@
 pygst.require("0.10")
 import gst
 import tempfile
+import plumber
 from gettext import gettext as _
-
+from pitivi import instance
 from sourcefactories import SourceFactoriesWidget
-
+from pitivi.bin import SmartStreamBin
+from pitivi.settings import ExportSettings
 
 class NetstreamManagerDialog(object):
 
@@ -42,6 +44,14 @@
 		self.capture_pipe = None
 		self.player = None
 
+		
+		'''
+		h=SmartStreamBin("http://127.0.0.1:8080";)
+		instance.PiTiVi.playground._playTemporaryBin(h)
+		
+		h.record("file:///tmp/test.ogg",ExportSettings())
+		'''
+
 		glade_dir = os.path.dirname(os.path.abspath(__file__))
 		self.objectpool_ui = gtk.glade.XML(os.path.join(glade_dir, "net_capture.glade"))
 		self.stream_window = self.objectpool_ui.get_widget("network_capture")
@@ -69,7 +79,7 @@
 		self.stream_window.connect("destroy",self.close)
 
 	
-		dic = { "on_close_clicked" : self.close, "on_preview_btn_clicked":self.live_pipeline,"on_capture_btn_clicked":self.capture}
+		dic = { "on_close_clicked" : self.close, "on_preview_btn_clicked":self.live_pipeline,"on_capture_btn_clicked":self.capture_pipeline}
 
 		self.objectpool_ui.signal_autoconnect(dic)
 
@@ -80,64 +90,79 @@
 		self.capture_btn.set_label("Capture")
 	
 		
+
+
+	# For Setting up audio,video sinks
+	def setSinks(self,uri=None):
+
+		gst.debug("SmartStreamBin player created")
+		self.player = SmartStreamBin(uri)	
+		self.videosink = plumber.get_video_sink()
+
+		vsinkthread = gst.Bin('vsinkthread')
+		vqueue = gst.element_factory_make('queue')
+		cspace = gst.element_factory_make('ffmpegcolorspace')
+		vscale = gst.element_factory_make('videoscale')
+		vscale.props.method = 1
+		vsinkthread.add(self.videosink, vqueue, vscale, cspace)
+		vqueue.link(self.videosink)
+		cspace.link(vscale)
+		vscale.link(vqueue)
+		vsinkthread.videosink = self.videosink
+		vsinkthread.add_pad(gst.GhostPad("sink", cspace.get_pad('sink')))
+		self.player.setVideoSinkThread(vsinkthread)
+
+        	gst.debug("Creating audio sink")
+        	self.audiosink = plumber.get_audio_sink()
+        	asinkthread = gst.Bin('asinkthread')
+        	aqueue = gst.element_factory_make('queue')
+        	aconv = gst.element_factory_make('audioconvert')
+        	asinkthread.add(self.audiosink, aqueue, aconv)
+        	aconv.link(aqueue)
+        	aqueue.link(self.audiosink)
+        	asinkthread.audiosink = self.audiosink
+        	asinkthread.add_pad(gst.GhostPad("sink", aconv.get_pad('sink')))
+		self.player.setAudioSinkThread(asinkthread)
+	
+		bus = self.player.get_bus()
+		bus.add_signal_watch()
+		bus.enable_sync_message_emission()
+		bus.connect('sync-message::element', self.on_sync_message)
+
+	
+		
 	# Create live display pipeline
 	def live_pipeline(self,w=None):
 
 		if self.player:
 			self.player.set_state(gst.STATE_NULL)
+		
 
 		if self.uri.get_text() != None :
-			self.player =  gst.parse_launch( self.uri.get_text() + " ! decodebin name=dbin dbin. ! queue ! ffmpegcolorspace ! autovideosink  dbin. ! queue ! audioconvert ! alsasink ")
-		
-			bus = self.player.get_bus()
-			bus.add_signal_watch()
-			bus.enable_sync_message_emission()
-			bus.connect('message',self.on_message)
-			bus.connect('sync-message::element',self.on_sync_message)
+			self.setSinks(self.uri.get_text())
 			self.player.set_state(gst.STATE_PLAYING)
 
 
 
 	# Stream capture pipeline
-	def capture_pipeline(self):
-
-		self.filepath = tempfile.mktemp()
-		self.file_uri = 'file://' + self.filepath + '.ogg'
-
-
-		if self.uri.get_text() != None and len(self.uri.get_text().split('://')[1]) > 0 :
-			if self.player:
-				self.player.set_state(gst.STATE_NULL)
-			self.capture_pipe = gst.parse_launch(self.uri.get_text() + " ! tee name=tee ! decodebin name=dbin ! queue !  ffmpegcolorspace ! autovideosink dbin. ! queue ! audioconvert ! queue ! alsasink tee. ! queue ! filesink location="+self.filepath+".ogg")		
-
-			bus = self.capture_pipe.get_bus()
-			bus.add_signal_watch()
-			bus.enable_sync_message_emission()
-			bus.connect('message',self.on_message)
-			bus.connect('sync-message::element',self.on_sync_message)
-			self.capture_pipe.set_state(gst.STATE_PLAYING)
-
-			return True
-		else:
-			return False
+	def capture_pipeline(self,w=None):
 
+		if self.capture_btn.get_label() == "Capture":
+			self.player.set_state(gst.STATE_NULL)
+			self.setSinks(self.uri.get_text())
+			gst.debug("recording started")
+			self.filepath = 'file://'+tempfile.mktemp()+'.ogg'
+			self.player.record(self.filepath,ExportSettings())
+			self.capture_btn.set_label("Stop")
+			self.player.set_state(gst.STATE_PLAYING)
 
-	def capture(self,w):
-			
-		
 
-		self.uri_stream = self.uri.get_text()
 
-		if self.capture_btn.get_label() == "Capture" :
-			
-			if self.capture_pipeline():
-				self.capture_btn.set_label("Stop")
 		else:
+			gst.debug("recording stopped")
+			self.player.stopRecording()
+			self.sourcefactories.sourcelist.addFiles([self.filepath])
 			self.capture_btn.set_label("Capture")
-			self.capture_pipe.set_state(gst.STATE_NULL)
-			self.live_pipeline()
-			self.sourcefactories.sourcelist.addFiles([self.file_uri])
-
 
 	def on_message(self,bus,message):
 		t = message.type

Modified: branches/SOC_2008_SLAKSHMAN/pitivi/ui/screencast_managerdialog.py
==============================================================================
--- branches/SOC_2008_SLAKSHMAN/pitivi/ui/screencast_managerdialog.py	(original)
+++ branches/SOC_2008_SLAKSHMAN/pitivi/ui/screencast_managerdialog.py	Mon Aug 11 15:39:38 2008
@@ -93,7 +93,7 @@
 	# Start istanbul using thread module
 	def start_istanbul(self,w):
 		thread.start_new_thread(self.start_thread_istanbul,())
-		time.sleep(1)
+		time.sleep(2)
 		self.dbus_connect()
 		
 		

Modified: branches/SOC_2008_SLAKSHMAN/pitivi/ui/webcam_managerdialog.py
==============================================================================
--- branches/SOC_2008_SLAKSHMAN/pitivi/ui/webcam_managerdialog.py	(original)
+++ branches/SOC_2008_SLAKSHMAN/pitivi/ui/webcam_managerdialog.py	Mon Aug 11 15:39:38 2008
@@ -35,7 +35,6 @@
 from pitivi.playground import PlayGround
 
 
-
 class WebcamManagerDialog(object):
 
 	def __init__(self):
@@ -63,6 +62,8 @@
 		self.player = SmartCaptureBin()		
 		self.setSinks()
 	
+
+
 		self.player.set_state(gst.STATE_PLAYING)
 
 
@@ -71,7 +72,7 @@
 	
 		if self.record_btn.get_label() == "Start Recording":
 			gst.debug("recording started")
-			self.filepath = 'file://'+tempfile.mktemp()+'ogg'
+			self.filepath = 'file://'+tempfile.mktemp()+'.ogg'
 			self.player.record(self.filepath,ExportSettings())
 			self.record_btn.set_label("Stop Recording")
 			self.player.set_state(gst.STATE_PLAYING)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]