Ejemplo n.º 1
0
        public async Task <RtspStream> PlayStreamAsync(string uri, NetworkCredential credentials = null)
        {
            var rtspStream = new RtspStream(uri, credentials);

            if (rtspStream.Credentials != null)
            {
                _rtspClient.AddCredential(rtspStream.Uri, rtspStream.Credentials);
            }

            var options = await _rtspClient.OptionsAsync(rtspStream.Uri);

            var describeResponse = await _rtspClient.DescribeAsync(rtspStream.Uri);

            var sdpParser = new SdpParser();

            rtspStream.Sdp = sdpParser.Parse(describeResponse.Sdp);

            var contentBaseHeaderValue =
                describeResponse.ResponseMessage.Headers
                .Get("Content-Base") ??
                describeResponse.ResponseMessage.Headers
                .Get("Content-Location");

            var contentBaseUrl = contentBaseHeaderValue != null ? new Uri(contentBaseHeaderValue) : rtspStream.Uri;

            string session = null;

            foreach (var md in rtspStream.Sdp.MediaDescriptions)
            {
                var rtspControlUrl = md.RtspControlUrl.IsAbsoluteUri
                    ? md.RtspControlUrl
                    : new Uri(contentBaseUrl, md.RtspControlUrl);

                var setupResponse = await _rtspClient.SetupAsync(rtspControlUrl, _rtpClient.Port, _rtcpClient.Port);

                md.MediaSourceAttributes.Ssrc = setupResponse.Ssrc;

                session ??= setupResponse.Session;
            }

            rtspStream.Session = session;

            var playResponse = await _rtspClient.PlayAsync(rtspStream.Uri, session, "0.000-");

            return(rtspStream);
        }
Ejemplo n.º 2
0
 public async Task CloseStreamAsync(RtspStream rtspStream)
 {
     await _rtspClient.TeardownAsync(rtspStream.Uri, rtspStream.Session);
 }