Ejemplo n.º 1
0
        /// <summary>
        /// Creates the RTP source.
        /// </summary>
        /// <param name="fileSink">The file sink.</param>
        /// <param name="serverAddress">The server address.</param>
        /// <param name="serverRtpPort">The server RTP port.</param>
        /// <param name="serverRtcpPort">The server RTCP port.</param>
        /// <param name="clientRtpPort">The client RTP port.</param>
        /// <param name="clientRtcpPort">The client RTCP port.</param>
        /// <returns>Succeeded or failed.</returns>
        public bool CreateRtpSource(FileSink fileSink, string serverAddress,
                                    int serverRtpPort, int serverRtcpPort,
                                    int clientRtpPort, int clientRtcpPort)
        {
            // Creates rtp socket and rtcp socket:
            ClientSocketBase clientRtpSocket  = null;
            ClientSocketBase clientRtcpSocket = null;
            Socket           socket           = null;

            socket = Utils.CreateUdpSocket(clientRtpPort);
            if (socket == null)
            {
                return(false);
            }

            IPEndPoint iep = new IPEndPoint(IPAddress.Parse(serverAddress), serverRtpPort);

            clientRtpSocket = new ClientSocketUdp(socket, (EndPoint)iep);

            socket = Utils.CreateUdpSocket(clientRtcpPort);
            if (socket != null)
            {
                iep = new IPEndPoint(IPAddress.Parse(serverAddress), serverRtcpPort);
                clientRtcpSocket = new ClientSocketUdp(socket, (EndPoint)iep);
            }

            Source = new RtpSource(fileSink, clientRtpSocket);
            if (Source == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RtpSink"/> class.
        /// </summary>
        /// <param name="payloadType">Type of the payload.</param>
        /// <param name="inputSource">The input source.</param>
        /// <param name="clientRtpSocket">The client RTP socket.</param>
        public RtpSink(int payloadType, MediaSource inputSource, ClientSocketBase clientRtpSocket)
        {
            this.clientRtpSocket = clientRtpSocket;
            this.mediaSource     = inputSource;

            this.mediaSource.MaxFrameSize       = 1360;
            this.mediaSource.PreferredFrameSize = 1024;

            InitBackgroundWorker();
            InitRtpPacket(payloadType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RtpSource"/> class.
        /// </summary>
        /// <param name="fileSink">The file sink.</param>
        /// <param name="clientRtpSocket">The client RTP socket.</param>
        public RtpSource(FileSink fileSink, ClientSocketBase clientRtpSocket)
        {
            this.fileSink        = fileSink;
            this.clientRtpSocket = clientRtpSocket;

            this.clientRtpSocket.DatagramReceived += new EventHandler <TSocketEventArgs>(this.OnDatagramReceived);

            rtpPacket = new RtpPacket();

            preferredFrameSize = 1024;
            internalPacketSize = preferredFrameSize + 16;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begins to receive the client request data with asynchronous mode.
        /// </summary>
        /// <param name="socket">The socket of the TCP.</param>
        public void ReceiveClientRequest(Socket socket)
        {
            ClientSocketTcp clientSocketTcp = new ClientSocketTcp(socket);

            clientSocket = clientSocketTcp;

            clientSocket.ClientTeardown    += new EventHandler(this.OnClientTeardown);
            clientSocket.DatagramReceived  += new EventHandler <TSocketEventArgs>(this.OnDatagramReceived);
            clientSocket.ExceptionOccurred += new EventHandler <TExceptionEventArgs>(this.OnExceptionOccurred);

            clientSocket.ReceiveDatagram();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the stream parameters.
        /// </summary>
        /// <param name="clientSessionId">The client session id(unused at present).</param>
        /// <param name="clientAddr">The client address.</param>
        /// <param name="clientRtpPort">The client RTP port.</param>
        /// <param name="clientRtcpPort">The client RTCP port.</param>
        /// <param name="serverRtpPort">The server RTP port.</param>
        /// <param name="serverRtcpPort">The server RTCP port.</param>
        /// <param name="streamToken">The stream token.</param>
        /// <returns>Succeeded or failed.</returns>
        public bool GetStreamParameters(int clientSessionId, string clientAddr,
                                        int clientRtpPort, int clientRtcpPort, int serverRtpPort, int serverRtcpPort,
                                        ref StreamState streamToken)
        {
            // Creates a new media source:
            MediaSource inputSource = CreateStreamSource();

            if (inputSource == null)
            {
                return(false);
            }

            // Creates rtp socket and rtcp socket for the client:
            ClientSocketBase clientRtpSocket  = null;
            ClientSocketBase clientRtcpSocket = null;
            Socket           socket           = null;

            socket = Utils.CreateUdpSocket(serverRtpPort);
            if (socket == null)
            {
                return(false);
            }

            IPEndPoint iep = new IPEndPoint(IPAddress.Parse(clientAddr), clientRtpPort);

            clientRtpSocket = new ClientSocketUdp(socket, (EndPoint)iep);

            socket = Utils.CreateUdpSocket(serverRtcpPort);
            if (socket != null)
            {
                iep = new IPEndPoint(IPAddress.Parse(clientAddr), clientRtcpPort);
                clientRtcpSocket = new ClientSocketUdp(socket, (EndPoint)iep);
            }

            // Creates a sink for this stream:
            RtpSink rtpSink = CreateRtpSink(inputSource, clientRtpSocket);

            if (rtpSink == null)
            {
                return(false);
            }

            // Setups the state of the stream. The stream will get started later:
            streamToken = new StreamState(rtpSink, inputSource, clientRtcpSocket);
            if (streamToken == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the RTP sink.
        /// </summary>
        /// <param name="inputSource">The input source.</param>
        /// <param name="clientRtpSocket">The client RTP socket.</param>
        /// <returns>The RtpSink object.</returns>
        public override RtpSink CreateRtpSink(MediaSource inputSource, ClientSocketBase clientRtpSocket)
        {
            int payloadType = 33; // MP2T video codec, defined in RFC 2250.

            RtpSink rtpSink = new RtpSink(payloadType, inputSource, clientRtpSocket);

            if (rtpSink == null)
            {
                // Error
                Utils.OutputMessage(false, MsgLevel.Error,
                                    "MPEG2TransportFileServerMediaSession -- CreateRtpSink",
                                    "Could not create an instance of RtpSink!");
            }

            return(rtpSink);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamState"/> class.
 /// </summary>
 /// <param name="rtpSink">The RTP sink.</param>
 /// <param name="inputSource">The input source.</param>
 /// <param name="clientRtcpSocket">The client RTCP socket.</param>
 public StreamState(RtpSink rtpSink, MediaSource inputSource, ClientSocketBase clientRtcpSocket)
 {
     this.rtpSink          = rtpSink;
     this.mediaSource      = inputSource;
     this.clientRtcpSocket = clientRtcpSocket;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates the RTP sink.
 /// </summary>
 /// <param name="inputSource">The input source.</param>
 /// <param name="clientRtpSocket">The client RTP socket.</param>
 /// <returns>The RtpSink object.</returns>
 public virtual RtpSink CreateRtpSink(MediaSource inputSource, ClientSocketBase clientRtpSocket)
 {
     return(null);
 }