MERGING MediaPortal Url Source Splitter & IPTV Filter (2 Viewers)

mm1352000

Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Merged filter before sending SETUP request reserves pair of UDP ports (create sockets without SO_REUSEADDR option). If any of ports are used by someone else, it simply choose next pair of ports (by default, filter starts on port 50000 and goes up to 65535, but min and max ports can be configured in RTSP url). UDP ports are reserved without SO_REUSEADDR option on socket, so it's not able to access them.
    I'm sorry, I don't understand. I'm not very good with network/socket code stuff. :(
    SAT>IP servers deliver a stream via RTSP + RTP. What I'm saying is that I want to implement the RTSP part in C# and use your filter to receive the RTP/UDP stream. Do you think this is possible?
     

    georgius

    Retired Team Member
  • Premium Supporter
  • October 31, 2010
    1,376
    654
    Bratislava
    Home Country
    Slovakia Slovakia
    Merged filter before sending SETUP request reserves pair of UDP ports (create sockets without SO_REUSEADDR option). If any of ports are used by someone else, it simply choose next pair of ports (by default, filter starts on port 50000 and goes up to 65535, but min and max ports can be configured in RTSP url). UDP ports are reserved without SO_REUSEADDR option on socket, so it's not able to access them.
    I'm sorry, I don't understand. I'm not very good with network/socket code stuff. :(
    SAT>IP servers deliver a stream via RTSP + RTP. What I'm saying is that I want to implement the RTSP part in C# and use your filter to receive the RTP/UDP stream. Do you think this is possible?
    Yep, it's possible. But your RTSP implementation must create UDP sockets with SO_REUSEADDR option (if not, then filter cannot use your UDP ports). Then you just create UDP url for filter and it should work - in case that stream is in MPEG2 TS format.

    Edit: I'm not sure, why you're trying to make such complicated solution as C# implementation of RTSP, but receiving data through UDP protocol from filter. Isn't be better to develop new protocol based on RTSP, exactly for your needs of SAT->IP?
     
    Last edited:

    Syrel

    MP Donator
  • Premium Supporter
  • January 2, 2014
    16
    6
    48
    Home Country
    Hungary Hungary
    It will be great if you have logs, I'm curious what is in DESCRIBE response. Probably there is not MPEG2 Transport Stream, but something else.

    Here you are, hopefully I'm using the correct files and formats. In case there's anything else or a different format is needed, pls. educate me. :)

    Thanks a lot for your support!!
     

    Attachments

    • MPIPTVSource.zip
      20.3 KB
    • TVService.zip
      5.8 KB
    • Wireshark.zip
      7.5 KB

    georgius

    Retired Team Member
  • Premium Supporter
  • October 31, 2010
    1,376
    654
    Bratislava
    Home Country
    Slovakia Slovakia
    It will be great if you have logs, I'm curious what is in DESCRIBE response. Probably there is not MPEG2 Transport Stream, but something else.

    Here you are, hopefully I'm using the correct files and formats. In case there's anything else or a different format is needed, pls. educate me. :)

    Thanks a lot for your support!!
    It is as I thought. The stream is not in MPEG2 TS container (one stream with multiplexed audio and video), but you have two streams - one audio (AAC) and one video (H264). I'm working on possibility to support your case, but in current filter state this case is not supported.
     

    KayDiefenthal

    MP Donator
  • Premium Supporter
  • July 18, 2006
    1,176
    92
    46
    Germany - Bonn
    Home Country
    Germany Germany
    Merged filter before sending SETUP request reserves pair of UDP ports (create sockets without SO_REUSEADDR option). If any of ports are used by someone else, it simply choose next pair of ports (by default, filter starts on port 50000 and goes up to 65535, but min and max ports can be configured in RTSP url). UDP ports are reserved without SO_REUSEADDR option on socket, so it's not able to access them.
    I'm sorry, I don't understand. I'm not very good with network/socket code stuff. :(
    SAT>IP servers deliver a stream via RTSP + RTP. What I'm saying is that I want to implement the RTSP part in C# and use your filter to receive the RTP/UDP stream. Do you think this is possible?

    mm1352000 i use this for receiving of RtpData
    Initialize the RtpSession(localaddress, localPort) in RtspSetup Response
    and Invoke Connect in RtspPlay

    Code:
    public class RtpSession
        {
       
       
            private Thread _listenerThread;
       
            private EndPoint _endPoint;
            private MemoryStream _stream;
    
            public MemoryStream Stream
            {
                get { return _stream; }
                set { _stream = value; }
            }
    
            private bool _listening;
            private Socket _socket;
            private int _rcvd;
    
            /// <summary>
            /// Initialize a new Instance of<see cref="RtpSession"/> Class.
            /// </summary>
            public RtpSession(string address,int port )
            {
                _stream = new MemoryStream();
                Connect(address, port);
            }
    
            private void Connect(string address,int port )
            {
                var rtpEndPoint = new IPEndPoint(IPAddress.Parse(address), port);
                var endPoint = (EndPoint)rtpEndPoint;
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress, 1);
                _socket.Bind(endPoint);
    
                var sender = new IPEndPoint(IPAddress.Parse(address), port);
                _endPoint = (EndPoint)sender;
    
    
                _listenerThread = new Thread(ReceiveCallback);
                _listenerThread.Start();
    
            }
    
            private void ReceiveCallback()
            {
                _listening = true;
    
                while (_listening)
                {
                    // Receive RTP packet
                    byte[] packet = new byte[1370];
    
    
                       _rcvd = _socket.ReceiveFrom( packet ,ref _endPoint);
    
                    // Decode the header of the packet.
                    // Each piece of information has a start bit and an end bit.
                    // The GetRTPHeaderValue takes the packet, the start bit index and the
                    // end bit index and determines what the header value is. The header values
                    // are all in Big Endian, which makes things more complicated.
                       int version = GetRTPHeaderValue(packet, 0, 1);
                    int padding = GetRTPHeaderValue(packet, 2, 2);
                    int extension = GetRTPHeaderValue(packet, 3, 3);
                    int csrcCount = GetRTPHeaderValue(packet, 4, 7);
                    int marker = GetRTPHeaderValue(packet, 8, 8);
                    int payloadType = GetRTPHeaderValue(packet, 9, 15);
                    int sequenceNum = GetRTPHeaderValue(packet, 16, 31);
                    int timestamp = GetRTPHeaderValue(packet, 32, 63);
                    int ssrcId = GetRTPHeaderValue(packet, 64, 95);
                    int csrcid = GetRTPHeaderValue(packet, 96,96);
                    StringBuilder sb = new StringBuilder();
                    sb.Append(string.Format(" RtpPacket V:{0}, P:{1}, EX:{2}, CSRC:{3}, M:{4}, PT:{5}, SQ:{6}, TS:{7}, SSRC:{8}, CSRC:{9} \r\n", version, padding, extension, csrcCount, marker, payloadType, sequenceNum, timestamp, ssrcId,csrcid));
                    Debug.Write(sb.ToString());
    
    //the packet payload starts at Offset 12 and the Payload lenght is packet.lenght without headersize
                    _stream.Write(packet, 12, packet.Length - 12);
              
                }
            }
            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;
            }
    
            public void StopClient()
            {
                // Tell listener thread that we are done listening.
                _listening = false;
            }
    
        }
     
    Last edited:

    pilehave

    Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    Will it be/is it possible to use this filter in other plugins than OLV?

    I'm currently using an old librtmp in my HeadWeb-plugin and would love to be able to use a filter that is maintained along with MediaPortal.

    HeadWeb content is rtmpe.
     

    georgius

    Retired Team Member
  • Premium Supporter
  • October 31, 2010
    1,376
    654
    Bratislava
    Home Country
    Slovakia Slovakia
    hello georgius, only for say you, thank you on all the work you made ...
    I'm still working on it, but still in testing phase. I hope that on end of week will be available public testing version for RTSP, HTTP, UDP and RTP protocols.

    Will it be/is it possible to use this filter in other plugins than OLV?

    I'm currently using an old librtmp in my HeadWeb-plugin and would love to be able to use a filter that is maintained along with MediaPortal.

    HeadWeb content is rtmpe.
    It's planned to be IPTV filter (used by MP TV Service) and OnlineVideos filter. But it can be used by any application using COM (e.g. I'm using GraphStudioNext for testing). Only thing which you MUST follow is URL formatting.
     

    georgius

    Retired Team Member
  • Premium Supporter
  • October 31, 2010
    1,376
    654
    Bratislava
    Home Country
    Slovakia Slovakia
    Maybe noticed, maybe not, but reworked filter is ready for bigger testing :) So, read carefully first post for reworked filter. Possibly you will not need to change anything, except deleting previous filter files and copying new filter files. Waiting for your test results :)
     

    georgius

    Retired Team Member
  • Premium Supporter
  • October 31, 2010
    1,376
    654
    Bratislava
    Home Country
    Slovakia Slovakia
    It is possible in IPTV, when first opening stream, that TvService crash. It is caused by incorrect handling of error returned from filter - TvService doesn't check error code returned from filter. I know that @Sebastiii made some changes, but I'm not sure if they are pushed into master branch and if they are in current MP (in 1.7.1 it sure, that this problem is not fixed).
     

    Users who are viewing this thread

    Top Bottom