← Back to team overview

sltv team mailing list archive

[Branch ~sltv/sltv/trunk] Rev 4: incluindo suporte a captura de câmera firewire.

 

------------------------------------------------------------
revno: 4
committer: Lucas <lucasa@mini-laptop>
branch nick: SLTV
timestamp: Tue 2009-09-22 10:19:02 -0300
message:
  incluindo suporte a captura de câmera firewire.
modified:
  lib/sltv.jar
  src/br/org/softwarelivre/sltv/Capture.java
  src/br/org/softwarelivre/sltv/SLTVPlayerGst.java
  src/br/org/softwarelivre/sltv/SLTVPlayerMain.java
  src/br/org/softwarelivre/sltv/VideoPipeline.java


--
lp:sltv
https://code.launchpad.net/~sltv/sltv/trunk

Your team sltv is subscribed to branch lp:sltv.
To unsubscribe from this branch go to https://code.launchpad.net/~sltv/sltv/trunk/+edit-subscription.
=== modified file 'lib/sltv.jar'
Binary files lib/sltv.jar	2009-09-11 03:20:29 +0000 and lib/sltv.jar	2009-09-22 13:19:02 +0000 differ
=== modified file 'src/br/org/softwarelivre/sltv/Capture.java'
--- src/br/org/softwarelivre/sltv/Capture.java	2009-09-11 03:20:29 +0000
+++ src/br/org/softwarelivre/sltv/Capture.java	2009-09-22 13:19:02 +0000
@@ -1,42 +1,100 @@
 package br.org.softwarelivre.sltv;
 
+import javax.swing.JOptionPane;
+
+import org.gstreamer.Bin;
 import org.gstreamer.Caps;
 import org.gstreamer.Element;
 import org.gstreamer.ElementFactory;
+import org.gstreamer.Pad;
+import org.gstreamer.Element.PAD_ADDED;
+import org.gstreamer.elements.DecodeBin;
+import org.gstreamer.elements.DecodeBin.NEW_DECODED_PAD;
 
 public class Capture extends VideoPipeline {
 
 	private String hostIP = "localhost";
 	private String hostPort = "8001";
+	
+	private Element queueBeginVideo = ElementFactory.make("queue", "queueVideo");
+	
+	private Element queueBeginAudio = ElementFactory.make("queue", "queueAudio");
 
 	public static void main(String[] args) {
 		Capture capture = new Capture();
 	}
 	
-	
 	public Capture() {
 		super();
 		
-		Element v4l2src = ElementFactory.make("v4l2src", "v4l2src");
-		v4l2src.set("device", "/dev/video0");
-//		Element videoscale = ElementFactory.make("videoscale", "videoscale");
-//		Element videorate = ElementFactory.make("videorate", "videorate");
-//		
-//		Element videoFilterSize = ElementFactory.make("capsfilter", null);
-//		videoFilterSize.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=200"+ ", bpp=32, depth=16"));		
-//		Element videoFilterRate = ElementFactory.make("capsfilter", null);
-//		videoFilterRate.setCaps(Caps.fromString("video/x-raw-yuv, framerate=15/1"));
-//		
+		getPipeline().add(queueBeginVideo);
+		
+		createVideoSrc(getPipeline());
+		
+		Element videoscale = ElementFactory.make("videoscale", "videoscale");
+		Element videorate = ElementFactory.make("videorate", "videorate");
+		
+		Element videoFilterSize = ElementFactory.make("capsfilter", null);
+		videoFilterSize.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=200"+ ", bpp=32, depth=16"));		
+		Element videoFilterRate = ElementFactory.make("capsfilter", null);
+		videoFilterRate.setCaps(Caps.fromString("video/x-raw-yuv, framerate=15/1"));
+		
+		String ip = JOptionPane.showInputDialog(null,
+				"What is the server IP?", "Enter the IP",
+				JOptionPane.QUESTION_MESSAGE);
+		if(ip != null && !ip.equals(""))
+			hostIP = ip;
+		
 		Element tcpclientsink = ElementFactory.make("tcpclientsink", "tcpclientsink");
 		tcpclientsink.set("host", hostIP);
 		tcpclientsink.set("port", hostPort);
 		tcpclientsink.set("protocol", 1);
 		
-		getPipeline().addMany(v4l2src, tcpclientsink);
-		//getPipeline().addMany(v4l2src, videorate, videoscale, videoFilterRate, videoFilterSize, tcpclientsink);
-		//boolean linked = getPipeline().linkMany(v4l2src, videorate, videoscale, videoFilterRate, videoFilterSize, tcpclientsink);
-		boolean linked = getPipeline().linkMany(v4l2src,  tcpclientsink);
+		//getPipeline().addMany(v4l2src, tcpclientsink);
+		getPipeline().addMany(videorate, videoscale, videoFilterRate, videoFilterSize, tcpclientsink);
+		boolean linked = getPipeline().linkMany(queueBeginVideo, videorate, videoscale, videoFilterRate, videoFilterSize, tcpclientsink);
+		//boolean linked = getPipeline().linkMany(v4l2src,  tcpclientsink);
 		if (DEBUG) System.out.println("Pipeline capture linked: " + linked);		
 	}
-
+	
+	
+	protected void createVideoSrc(Bin bin) {		
+		createV4LSrc(bin);
+	}
+
+	protected void createV4LSrc(Bin bin) {
+		Element v4l2src = ElementFactory.make("v4l2src", "v4l2src");
+		v4l2src.set("device", "/dev/video0");
+		bin.add(v4l2src);
+		
+		boolean linked = bin.linkMany(v4l2src, this.queueBeginVideo);
+		if (DEBUG) System.out.println("Pipeline V4L linked: " + linked);
+	}
+
+	protected void createFirewireDVSrc(Bin bin) {
+		Element dv1394src = ElementFactory.make("dv1394src", "dv1394src");
+		Element dvdemux = ElementFactory.make("dvdemux", "dvdemux");
+		final Element dvdec = ElementFactory.make("dvdec", "dvdec");
+		bin.addMany(dv1394src, dvdemux, dvdec);
+		boolean linked = bin.linkMany(dv1394src, dvdemux);
+		if (DEBUG) System.out.println("Pipeline 1 1394 linked: " + linked);
+		dvdemux.connect(new PAD_ADDED() {
+			@Override
+			public void padAdded(Element e, Pad pad) {
+				if(pad.getName().equals("video"))
+				{
+					Pad sinkPad = dvdec.getPad("sink");
+					pad.link(sinkPad);
+					if (DEBUG)
+						System.out.println("New Pad [" + pad.getName()
+								+ "] from " + pad.getParentElement().getName()
+								+ " was linked to pad " + sinkPad.getName()
+									+ " from " + sinkPad.getParentElement().getName());
+				}
+			}
+		});
+		
+		linked = bin.linkMany(dvdec, this.queueBeginVideo);
+		if (DEBUG) System.out.println("Pipeline 1 DV1394 linked: " + linked);
+	}
 }

=== modified file 'src/br/org/softwarelivre/sltv/SLTVPlayerGst.java'
--- src/br/org/softwarelivre/sltv/SLTVPlayerGst.java	2009-09-09 01:57:27 +0000
+++ src/br/org/softwarelivre/sltv/SLTVPlayerGst.java	2009-09-22 13:19:02 +0000
@@ -187,14 +187,14 @@
 //		playbin.play();
 		
 		videoPipeline = new VideoPipeline(path, videoComponent.getElement());
-		videoPipeline.getPipe().play();
+		videoPipeline.getPipeline().play();
 		
 		Thread thread = new Thread(new Runnable() {
 			@Override
 			public void run() {
 				while (true) {
 					try {
-						Thread.sleep(5000);
+						Thread.sleep(25000);
 						SLTVEffects[] effects = SLTVEffects.values();
 						int i = (int) (Math.random() * effects.length);
 						SLTVEffects effect = effects[i];

=== modified file 'src/br/org/softwarelivre/sltv/SLTVPlayerMain.java'
--- src/br/org/softwarelivre/sltv/SLTVPlayerMain.java	2009-09-11 03:20:29 +0000
+++ src/br/org/softwarelivre/sltv/SLTVPlayerMain.java	2009-09-22 13:19:02 +0000
@@ -3,11 +3,8 @@
 import java.awt.BorderLayout;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
-import java.io.File;
-import java.io.IOException;
 
 import javax.swing.JDesktopPane;
-import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
@@ -130,13 +127,14 @@
 	private JMenuItem getJMenuItemPlay() {
 		if (jMenuItemPlay == null) {
 			jMenuItemPlay = new JMenuItem();
-			jMenuItemPlay.setText("Play Video");
+			jMenuItemPlay.setText("Create server player");
 			jMenuItemPlay.addActionListener(new java.awt.event.ActionListener() {
 				public void actionPerformed(java.awt.event.ActionEvent e) {
 
-//					playVideo("/home/lucasa/temp/SpiritOfUbuntu.ogv");
+					//playVideo("");
+					playVideo("/home/lucasa/SpiritOfUbuntu.ogv");
 					// Show the Open File dialog box to the user.
-					JFileChooser fd = new JFileChooser();
+					/*JFileChooser fd = new JFileChooser();
 					int result = fd.showOpenDialog(SLTVPlayerMain.this);
 	                if(result==JFileChooser.APPROVE_OPTION)
 	                {
@@ -152,7 +150,7 @@
 	    					if (fileName != null) {
 	    						playVideo(path.toString());
 	    					}
-	                }
+	                }*/
 				}
 			});
 		}
@@ -167,7 +165,7 @@
 	private JMenuItem getJMenuItemCapture() {
 		if (jMenuItemCapture == null) {
 			jMenuItemCapture = new JMenuItem();
-			jMenuItemCapture.setText("Capture Webcam Video");
+			jMenuItemCapture.setText("Create client webcam video");
 			jMenuItemCapture.addActionListener(new java.awt.event.ActionListener() {
 				public void actionPerformed(java.awt.event.ActionEvent e) {
 					Thread thread = new Thread(new Runnable() {

=== modified file 'src/br/org/softwarelivre/sltv/VideoPipeline.java'
--- src/br/org/softwarelivre/sltv/VideoPipeline.java	2009-09-11 03:20:29 +0000
+++ src/br/org/softwarelivre/sltv/VideoPipeline.java	2009-09-22 13:19:02 +0000
@@ -28,13 +28,17 @@
 	private Bus bus;
 	private Bin filterBin;
 
-	String lastEffect = "";
+	private String lastEffect = "";
 	private Element streamBin;
-	final Element queueBegin = ElementFactory.make("queue", "queue1");
+	private Element queueBegin = ElementFactory.make("queue", "queue1");
 	private int AUTO_INDEX = 0;
 	protected boolean DEBUG = true;
 	private String hostPort = "8001";
 	private String hostIP = "localhost";
+	private Element tee;
+	private Element videoOutput;
+	private Element textoverlay;
+	private Element gnlcomposition;
 
 	public enum SLTVEffects {
 		noeffect("identity"), quarktv, revtv, vertigotv, shagadelictv, warptv, dicetv, agingtv, edgetv;
@@ -65,11 +69,13 @@
 		});
 	}
 	
-	public VideoPipeline(String filepath, Element videoOutput) {
+	public VideoPipeline(final String filepath, Element output) {
 
 		this();
 		
-		Element gnlcomposition = ElementFactory.make("gnlcomposition",
+		this.videoOutput = output;
+		
+		gnlcomposition = ElementFactory.make("gnlcomposition",
 				"gnlcomposition");
 
 		Element videosrc = null;
@@ -81,9 +87,10 @@
 				Pad sinkPad = queueBegin.getPad("sink");
 				pad.link(sinkPad);
 				if (DEBUG)
-					System.out.println("New Pad [" + sinkPad.getName()
-							+ "] from " + sinkPad.getParentElement().getName()
-							+ " was linked");
+					System.out.println("New Pad [" + pad.getName()
+							+ "] from " + pad.getParentElement().getName()
+							+ " was linked to pad " + sinkPad.getName()
+								+ " from " + sinkPad.getParentElement().getName());
 			}
 		});
 
@@ -91,26 +98,29 @@
 		identity.set("single-segment", true);
 		//identity.set("sync", true);
 
-		Element tee = ElementFactory.make("tee", "tee");
+		tee = ElementFactory.make("tee", "tee");
 		Element queue2 = ElementFactory.make("queue", "queue2");
-		Element queue3 = ElementFactory.make("queue", "queue3");
-		Element queue4 = ElementFactory.make("queue", "queue4");
 
 		Element videoFilterSize = ElementFactory.make("capsfilter", null);
-		videoFilterSize.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=200"+ ", bpp=32, depth=16"));		
+		//videoFilterSize.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=200"+ ", bpp=32, depth=16"));
+		videoFilterSize.setCaps(Caps.fromString("video/x-raw-yuv, width=160, height=100"));
 		Element videoFilterRate = ElementFactory.make("capsfilter", null);
-		videoFilterRate.setCaps(Caps.fromString("video/x-raw-yuv, framerate=15/1"));
+		videoFilterRate.setCaps(Caps.fromString("video/x-raw-yuv, framerate=10/1"));
 		
 		Element videofilesrc = createFileSrc(filepath, 0);
 		((Bin) gnlcomposition).add(videofilesrc);
 
 		Element videoscale = ElementFactory.make("videoscale", null);
 		Element videorate = ElementFactory.make("videorate", null);
-
 		
 		Element timeoverlay = ElementFactory.make("timeoverlay", null);
-		//pipe.addMany(gnlcomposition, queue1, queue2, tee, queue3, videoOutput);
-		pipe.addMany(queueBegin, queue2, timeoverlay, videoscale, videoFilterSize, videorate, videoFilterRate, tee, queue3, videoOutput);
+		timeoverlay.set("font-desc", "mono 30");
+		
+		textoverlay = ElementFactory.make("textoverlay", null);
+		textoverlay.set("font-desc", "mono 50");
+		
+		//pipe.addMany(gnlcomposition, queueBegin, queue2, timeoverlay, textoverlay, videoscale, videoFilterSize, videorate, videoFilterRate, tee);
+		pipe.addMany(queueBegin, queue2, timeoverlay, textoverlay, videoscale, videoFilterSize, videorate, videoFilterRate, tee);
 
 		//pipe.addMany(videosrc);
 		//pipe.linkMany(videosrc, queue1);
@@ -123,14 +133,13 @@
 
 		
 		boolean linkedLocal = pipe.linkMany(queueBegin, filterBin,
-				queue2, timeoverlay, videoscale, videoFilterSize, videorate,
-				videoFilterRate, tee, queue3, videoOutput);
+				queue2, timeoverlay, textoverlay, videoscale, videoFilterSize, videorate,
+				videoFilterRate, tee);
 		if (DEBUG) System.out.println("Pipeline local linked: " + linkedLocal);
 
-		//streamBin = createStreamBin();
-		//pipe.addMany(queue4, streamBin);
-		//boolean linkedStream = pipe.linkMany(tee, queue4, streamBin);
-		//if (DEBUG)System.out.println("Pipeline stream linked: " + linkedStream);
+		linkVideoOutput();
+		
+		//streamOggTheora();
 
 		bus = pipe.getBus();
 		bus.connect(new Bus.ERROR() {
@@ -159,6 +168,7 @@
 				case PAUSED:
 					break;
 				case NULL:
+					
 				case READY:
 					break;
 				}
@@ -168,7 +178,13 @@
 		bus.connect(new Bus.MESSAGE() {
 			@Override
 			public void busMessage(Bus bus, Message message) {
-				// if(message.getType() == org.gstreamer.MessageType.ERROR)
+				if(message.getType() == org.gstreamer.MessageType.EOS)
+				{
+					Element videofilesrc = createFileSrc(filepath, 0);
+					((Bin) gnlcomposition).add(videofilesrc);
+					getPipeline().play();
+				}
+					
 				if (DEBUG)
 					System.out.println("Bus MESSAGE - "
 							+ message.getStructure());
@@ -186,7 +202,22 @@
 		pipe.play();
 	}
 
-	private Bin createStreamBin() {
+	public void linkVideoOutput() {
+		Element queue3 = ElementFactory.make("queue", "queue3");
+		pipe.addMany(queue3, this.videoOutput);
+		boolean linkedOutput = pipe.linkMany(tee, queue3, videoOutput);
+		if (DEBUG) System.out.println("Pipeline output linked: " + linkedOutput);
+	}
+
+	public void streamOggTheora() {
+		streamBin = createStreamBin();
+		Element queue4 = ElementFactory.make("queue", "queue4");
+		pipe.addMany(queue4, streamBin);
+		boolean linkedStream = pipe.linkMany(tee, queue4, streamBin);
+		if (DEBUG)System.out.println("Pipeline stream linked: " + linkedStream);
+	}
+
+	protected Bin createStreamBin() {
 		Bin streamBin = new Bin("streambin");
 		/* listen for newly created pads */
 		streamBin.connect(new Element.PAD_ADDED() {
@@ -212,7 +243,7 @@
 		//queue1.set("max-size-buffers", 1000);
 		//queue1.set("max-size-bytes", 100000000);
 		Element theoraenc = ElementFactory.make("theoraenc", "theoraenc");
-		theoraenc.set("quality", 6);
+		theoraenc.set("quality", 20);
 		//theoraenc.set("keyframe-force", 5);
 		Element oggmux = ElementFactory.make("oggmux", "oggmux");
 		Element queue2 = ElementFactory.make("queue", "queue2s");
@@ -232,7 +263,7 @@
 		return streamBin;
 	}
 	
-	private Bin createReadNetworkBin(Bin bin) {
+	protected Bin createReadNetworkBin(Bin bin) {
 		//Bin bin = new Bin("fowardbin");
 		/* listen for newly created pads */
 /*		bin.connect(new Element.PAD_ADDED() {
@@ -282,7 +313,7 @@
 		return bin;
 	}
 
-	protected Pipeline getPipeline() {
+	public Pipeline getPipeline() {
 		return pipe;
 	}
 
@@ -358,10 +389,6 @@
 		return bin;
 	}
 
-	public Pipeline getPipe() {
-		return pipe;
-	}
-
 	public void changeFilter(SLTVEffects effect) {
 		String nameBeforeOld = "queue1";
 		String nameAfterOld = "queue2";
@@ -372,11 +399,13 @@
 		swapElements(getPipeline(), nameBeforeOld, nameAfterOld, nameOldE,
 				newFilter);
 		lastEffect = newFilterName;
+		getTextoverlay().set("text", lastEffect);
 		AUTO_INDEX++;
 	}
 
 	private void swapElements(Bin bin, String nameBeforeOld,
-			String nameAfterOld, String nameOldE, Element newElement) {
+			String nameAfterOld, String nameOldE, Element newElement)
+	{
 		Element beforeOld = bin.getElementByName(nameBeforeOld);
 		Element afterOld = bin.getElementByName(nameAfterOld);
 		Element oldE = bin.getElementByName(nameOldE);
@@ -414,6 +443,42 @@
 		beforeOld.getPad("src").setBlocked(false);
 	}
 
+	public Bus getBus() {
+		return bus;
+	}
+
+	public Bin getFilterBin() {
+		return filterBin;
+	}
+
+	public String getLastEffect() {
+		return lastEffect;
+	}
+
+	public Element getStreamBin() {
+		return streamBin;
+	}
+
+	public Element getQueueBegin() {
+		return queueBegin;
+	}
+
+	public String getHostPort() {
+		return hostPort;
+	}
+
+	public String getHostIP() {
+		return hostIP;
+	}
+
+	public Element getTee() {
+		return tee;
+	}
+
+	public Element getTextoverlay() {
+		return textoverlay;
+	}
+
 	/*
 	 * def swap_elements(self, before_old, after_old, old, new):
 	 * before_old.get_pad('src').set_blocked(True) before_old.unlink(old) #