View Single Post
Posts: 395 | Thanked: 509 times | Joined on Jan 2011 @ Brisbane, Australia
#24
This is the original non-gui version,
basically, it listens on udp 127.0.0.1:5000, starts up gstreamer which streams jpegs to udp 127.0.0.1:5000, every jpeg it gets, it adds on the needed info for smartcam to use, then it tcpsends the frames to smartcam.

danielz000 was thinking we look at modifying tcpsink for gstreamer to add on the needed parts, that would take off the 8% of so usage the GUI has when its streaming:

Code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;

public class UDPListener{
	private const int listenPort = 5000;
	
	public static int Main(){
        Console.Write("Smartcam IP [XXX.XXX.XXX.XXX] : ");
        string ip = Console.ReadLine();
        Console.Write("/dev/video[0] or /dev/video[1]: ");
        string source = Console.ReadLine();

		bool done = false;
		UdpClient listener = new UdpClient(listenPort);
		IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
		byte[] receive_byte_array;
        Queue<byte> _buffer = new Queue<byte>();
        byte[] message = new byte[2];
        
        TcpClient _tc = new TcpClient(ip, 9361);
        NetworkStream _ns = _tc.GetStream();

        Process.Start(String.Format("gst-launch-0.10 v4l2camsrc device=/dev/video{0} driver-name=omap3cam ! ffmpegcolorspace ! video/x-raw-yuv,width=320,height=240 ! jpegenc ! udpsink host=127.0.0.1 port=5000", source));

		try{
			while(!done){
				receive_byte_array = listener.Receive(ref groupEP);
                if (receive_byte_array.Length != 0){
                    byte[] _fileData = receive_byte_array;
                    byte[] _tmpSize = new byte[4];
                    _tmpSize = BitConverter.GetBytes(_fileData.Length);

                    _buffer.Enqueue(1);
                    _buffer.Enqueue(_tmpSize[2]);
                    _buffer.Enqueue(_tmpSize[1]);
                    _buffer.Enqueue(_tmpSize[0]);

                    foreach(byte _b in _fileData){
                        _buffer.Enqueue(_b);
                    }

                    byte[] _packet = _buffer.ToArray();
                    _ns.Write(_packet, 0, _packet.Length);

                    _buffer = new Queue<byte>();
                }
			}
		}catch(Exception e){
			Console.WriteLine(e.ToString());
		}
		
		listener.Close();
		return 0;
	}
}
Ill have to look at hooking the close event, to have it kill gststreamer, if I can.

I couldve probably coded this in python, save installing all the libs and such, but Ive been trying to force myself to use c# more lately and mono being available on n900 made me want to use it.

Ill try streaming it over the internet, the quality slider should help, maybe later an optional framerate limiter.

EDIT::
I portforwarded then connected through my public iport over wifi, a little delay but worked fine (was using front cam, around half quality on the slider). Then I tried over 3g, I dont get good 3g reception here, but I dont think itll work too well anyway, maybe with a frame limiter (and if youve got lots of bandwidth to waste), it was really delayed, hitting Stop didnt close gstreamer, I think it just piles up the frames and nothing really ends up getting through after a little while, had to turn off 3g/kill smartcam-m5

If anyone wants to test some "global" streaming, from one n900 to anothers computer, let me know.

If it crashes over /dev/video1 and gstreamer is not running- but theres still the red light, the only fix ive found is to run:
Code:
gst-launch v4l2camsrc device=/dev/video1 num-buffers=1 ! fakesink
to let it reactivate/deactivate, wish I knew why it does it.

Last edited by azkay; 2011-03-25 at 02:37.
 

The Following User Says Thank You to azkay For This Useful Post: