What is Required for a Recorder Source for ArgusTv

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Wed Aug 07, 2013 6:24 am

dot-i wrote:
Kay Diefenthal wrote:
dot-i wrote:Does such a captured file play in MediaPortal, XBMC and vlc?
yes vlc and wmp12(if Lav directshow is installed)
Ok, cool, and what about XBMC? If that plays it too, this could serve directly as a recording file.

i dosent use XBMC or MediaPortal

capture a rtp stream
think if i remove the Rtp Header from Rtp Packet should it be possible to write into a file in theory

User avatar
dot-i
Site Admin
Posts: 5848
Joined: Mon Oct 01, 2012 3:40 pm

Re: What is Required for a Recorder Source for ArgusTv

Post by dot-i » Wed Aug 07, 2013 8:34 pm

Okay, but just install it for testing purposes, because it's rather important the file plays in all these systems, otherwise more work will be required to make it into a valid recording file...
I have the heart of a child. I keep it in a jar on my shelf. -- Robert Bloch
Image

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Sat Aug 10, 2013 10:06 am

dot-i wrote:Okay, but just install it for testing purposes, because it's rather important the file plays in all these systems, otherwise more work will be required to make it into a valid recording file...
if Xbmc or Mediaportal can Play MpegTs i doesnt Need to install them!
Sat>Ip transmit the Transport stream from sat dvbc or dvbt
over the protocols Http/Rtsp for session handling and Rtp for the Data Si Pmt Pat and so

http://www.satip.info/resources

User avatar
dot-i
Site Admin
Posts: 5848
Joined: Mon Oct 01, 2012 3:40 pm

Re: What is Required for a Recorder Source for ArgusTv

Post by dot-i » Sat Aug 10, 2013 6:16 pm

Kay Diefenthal wrote:capture a rtp stream
think if i remove the Rtp Header from Rtp Packet should it be possible to write into a file in theory
That's basically my question and perhaps you answered this but it's not 100% clear to me.

So can you, or did you, write a console program that captures the Sat>IP stream to an actual file? And if so, does this file play in e.g. VLC?
I have the heart of a child. I keep it in a jar on my shelf. -- Robert Bloch
Image

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Sat Aug 10, 2013 6:32 pm

dot-i wrote:
Kay Diefenthal wrote:capture a rtp stream
think if i remove the Rtp Header from Rtp Packet should it be possible to write into a file in theory
That's basically my question and perhaps you answered this but it's not 100% clear to me.

So can you, or did you, write a console program that captures the Sat>IP stream to an actual file? And if so, does this file play in e.g. VLC?
in vlc is this no Problem

if you let vlc Setup the Rtsp session Play vlc the stream
if you control rtsp and give vlc thr rtp URL Plays vlc too

in my sample is the rtsp part finished and i work on the rtp and the hint with remove the rtp Header from rtp packet and add the sequenze to buffer is more theory

User avatar
dot-i
Site Admin
Posts: 5848
Joined: Mon Oct 01, 2012 3:40 pm

Re: What is Required for a Recorder Source for ArgusTv

Post by dot-i » Sun Aug 11, 2013 10:52 pm

OK, thanks, so if I understand correctly this is all purely streaming, there is no functional file recording yet in what you tried?
I have the heart of a child. I keep it in a jar on my shelf. -- Robert Bloch
Image

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Mon Aug 12, 2013 6:05 am

dot-i wrote:OK, thanks, so if I understand correctly this is all purely streaming, there is no functional file recording yet in what you tried?

i work on it

Code: Select all


namespace Sat2Ip.RtspSample
{
    public class DumpToFile
    {
        static int TS_PACKET_SIZE = 188;
        private string _address;
        int _port;
        string _file;
        Socket _sock;
        Thread _th;
        int _timeout = 5000;
        volatile bool _stopCondition = false;

        public void start(string address,int port, string file)
        {
            _stopCondition = false;
            _address = address;
            _port = port;
            _file = file;
            _th = new Thread(receive) {IsBackground = true};
            _th.Start();
        }

        public void stop()
        {
            _stopCondition = true;
            _th.Abort();


        }

        private void receive()
        {
            int RECV_SIZE = 8192;
            byte[] data = new byte[RECV_SIZE];
            int recv = 0;
            var rtpEndPoint = new IPEndPoint(IPAddress.Parse(_address), _port);
            _sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _sock.Bind(rtpEndPoint);

            var sender = new IPEndPoint(IPAddress.Parse(_address), _port);
            var remotEndPoint = (EndPoint)sender;
            recv = _sock.ReceiveFrom(data, data.Length, SocketFlags.None, ref remotEndPoint);

            // open file stream
            
            FileStream fs = null; ;
            try
            {
                fs = new FileStream(_file, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, true);
            }
            catch
            {
                if (_sock != null)
                {
                    _sock.Close();
                    _sock = null;
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }

            byte[] syncbyte = BitConverter.GetBytes(0x47); //0x47
            byte[] buffer = new byte[RECV_SIZE];

            while (recv > 0)
            {
                //ts packet is 188 bytes long
                //each udp packet should start with with syncbyte 0X47 
                //and is 188 x 7 =1316 bytes long

                WriteObject wo = new WriteObject();
                wo.FStream = fs;

                int j = 0;
                for (int i = 0; i < recv; i = i + 188)
                {
                    if (data[i] == syncbyte[0])
                    {

                        Array.Copy(data, i, buffer, j, 188);
                        j = j + 188;
                    }
                    else
                    {
                        Console.Write("Syncbyte not found");
                    }
                }

                IAsyncResult asyncResult;
                fs.BeginWrite(buffer, 0, j, EndWriteCallBack, wo);

                try
                {
                    recv = _sock.ReceiveFrom(data, data.Length, SocketFlags.None, ref remotEndPoint);
                }
                catch
                {
                    break;
                }

                if (_stopCondition)
                    break;
            }

            // clean
            if (_sock != null)
            {
                _sock.Close();
                _sock = null;
            }
            if (fs != null)
            {
                fs.Close();
            }
        }

        private void EndWriteCallBack(IAsyncResult res)
        {
            var wo = (WriteObject)res.AsyncState;
            var ftemp = wo.FStream;
            ftemp.EndWrite(res);
        }
    }

    internal class WriteObject
    {
        FileStream fStream;

        public FileStream FStream
        {
            get { return fStream; }
            set { fStream = value; }
        }
    }
}

the streams.ts is createt and data Comes in
in this hang i at time "No Sync Byte found"

Code: Select all

for (int i = 0; i < recv; i = i + 188)
{
    if (data[i] == syncbyte[0])
    {

       Array.Copy(data, i, buffer, j, 188);
       j = j + 188;
    }
    else
    {
       Console.Write("Syncbyte not found");
    }
}

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Sun Sep 01, 2013 7:17 pm

Now can i save the stream to disk but the Problem is the record has jitter

Code: Select all


namespace Sat2Ip.Library.Rtp
{
    public class RtpClient
    {

        private static int bufferlenght = 128*1328;
        byte[] data = new byte[bufferlenght];
        
        private EndPoint _endPoint;
        
        private bool writeHeaderToConsole = true;
        private bool listening = false;
        private int _port;
        private string _address;
        private Thread listenerThread;
        private Socket _sock;
        private int _rcvd;
       
        private RtpPacket _packet;
        private FileStream _fspayload;

       
        /// <summary>
        /// Gets whether the client is listening for packets
        /// </summary>
        public bool Listening
        {
            get { return listening; }
        }

        /// <summary>
        /// Gets the port the RTP client is listening on
        /// </summary>
        public int Port
        {
            get { return _port; }
        }

        

        /// <summary>
        /// RTP Client for receiving an RTP stream containing a WAVE audio stream
        /// </summary>
        /// <param name="port">The port to listen on</param>
        public RtpClient(string address,int port)
        {
            Console.WriteLine(" [RTPClient] Loading...");

            _port = port;
            _address = address; 


            Console.WriteLine(" Done");
        }

        /// <summary>
        /// Creates a connection to the RTP stream
        /// </summary>
        public void StartClient(string path,string name)
        {
            var pathname = string.Format(@"{0}:\{1}.ts", path, name);            
            _fspayload = new FileStream(@pathname, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, true);
            var rtpEndPoint = new IPEndPoint(IPAddress.Parse(_address), _port);
            var endPoint =(EndPoint) rtpEndPoint;
            _sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _sock.Bind(endPoint);
            
            var sender = new IPEndPoint(IPAddress.Parse(_address), _port);
            _endPoint = (EndPoint)sender;
            //
            listening = true;
            listenerThread = new Thread(ReceiveCallback);
            listenerThread.Start();

            Console.WriteLine(" [RTPClient] Listening for packets on port " + _port + "...");
        }

        /// <summary>
        /// Tells the UDP client to stop listening for packets.
        /// </summary>
        public void StopClient()
        {
            // Set the boolean to false to stop the asynchronous packet receiving
            listening = false;
            Console.WriteLine(" [RTPClient] Stopped listening on port " + _port);
        }

        /// <summary>
        /// Handles the receiving of UDP packets from the RTP stream
        /// </summary>
        /// <param name="ar">Contains packet data</param>
        private void ReceiveCallback()
        {
            // Begin looking for the next packet

            while (listening)
            {
                _rcvd = _sock.ReceiveFrom(data, ref _endPoint);
                _packet = new RtpPacket(data, _rcvd);
                

                WriteObject wo = new WriteObject();
                wo.FStream = _fspayload;
                IAsyncResult asyncResult;
                _fspayload.BeginWrite(_packet.Payload, 0, _packet.GetPayloadLength(), EndWriteCallBack, wo);
                
            }

        }
        private void EndWriteCallBack(IAsyncResult res)
        {
            var wo = (WriteObject)res.AsyncState;
            var ftemp = wo.FStream;
            ftemp.EndWrite(res);
        }

        /// <summary>
        /// Grabs a value from the RTP header in Big-Endian format
        /// </summary>
        /// <param name="packet">The RTP packet</param>
        /// <param name="startBit">Start bit of the data value</param>
        /// <param name="endBit">End bit of the data value</param>
        /// <returns>The value</returns>
        private int GetRtpHeaderValue(byte[] packet, int startBit, int endBit)
        {
            int result = 0;

            // Number of bits in value
            int length = endBit - startBit + 1;

            // Values in RTP header are big endian, so need to do these conversions
            for (int i = startBit; i <= endBit; i++)
            {
                int byteIndex = i/8;
                int bitShift = 7 - (i%8);
                result += ((packet[byteIndex] >> bitShift) & 1)*(int) Math.Pow(2, length - i + startBit - 1);
            }
            return result;
        }
    }
    internal class WriteObject
    {
        FileStream fStream;

        public FileStream FStream
        {
            get { return fStream; }
            set { fStream = value; }
        }
    }
}

Attachments
Al_Jazeera_English.zip
(3.37 MiB) Downloaded 147 times

User avatar
JMS
Posts: 50
Joined: Fri May 30, 2008 12:23 am
Location: Königswinter, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by JMS » Mon Sep 02, 2013 10:58 am

Although I don't known if this matters (should not !!!) some experiences of my own:

* 4k is quite a small buffer for the FileStream buffer, I go for at least 100k, normally 1M
* I experienced some heavy problems using FileStream constructor with async=true which internally uses Windows async file I/O (as I remember) - in my opinion you can BeginWrite even if async=false
* Never hat the courage to send multiple BeginWrite requests at a time: I have a DoubleBuffering implementation on my own (you can find it in the TS assembly of DVB.NET I think) which makes sure that only one BeginWrite is active at each time and in addition decouples receiving from writing

Just some guess

Jochen

User avatar
Kay Diefenthal
Posts: 226
Joined: Fri Nov 16, 2012 10:40 am
Location: Wachtberg, NRW, Germany
Contact:

Re: What is Required for a Recorder Source for ArgusTv

Post by Kay Diefenthal » Mon Sep 02, 2013 5:20 pm

JMS wrote:Although I don't known if this matters (should not !!!) some experiences of my own:

* 4k is quite a small buffer for the FileStream buffer, I go for at least 100k, normally 1M
* I experienced some heavy problems using FileStream constructor with async=true which internally uses Windows async file I/O (as I remember) - in my opinion you can BeginWrite even if async=false
* Never hat the courage to send multiple BeginWrite requests at a time: I have a DoubleBuffering implementation on my own (you can find it in the TS assembly of DVB.NET I think) which makes sure that only one BeginWrite is active at each time and in addition decouples receiving from writing

Just some guess

Jochen

Hi Jochen

danke das mit der Byte Array größe hat geklappt 4096000 <- damit habe ich keine jitter mehr

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest