public async Task ConnectAsync(DateTime initialTimeStamp, CancellationToken token) { IRtspTransportClient rtspTransportClient = _transportClientProvider(); Volatile.Write(ref _rtspTransportClient, rtspTransportClient); await _rtspTransportClient.ConnectAsync(token); RtspRequestMessage optionsRequest = _requestMessageFactory.CreateOptionsRequest(); RtspResponseMessage optionsResponse = await _rtspTransportClient.ExecuteRequest(optionsRequest, token); if (optionsResponse.StatusCode == RtspStatusCode.Ok) { ParsePublicHeader(optionsResponse.Headers[WellKnownHeaders.Public]); } RtspRequestMessage describeRequest = _requestMessageFactory.CreateDescribeRequest(); RtspResponseMessage describeResponse = await _rtspTransportClient.EnsureExecuteRequest(describeRequest, token); string contentBaseHeader = describeResponse.Headers[WellKnownHeaders.ContentBase]; if (!string.IsNullOrEmpty(contentBaseHeader)) { _requestMessageFactory.ContentBase = new Uri(contentBaseHeader); } var parser = new SdpParser(); IEnumerable <RtspTrackInfo> tracks = parser.Parse(describeResponse.ResponseBody); bool anyTrackRequested = false; foreach (RtspMediaTrackInfo track in GetTracksToSetup(tracks)) { await SetupTrackAsync(initialTimeStamp, track, token); anyTrackRequested = true; } if (!anyTrackRequested) { throw new RtspClientException("Any suitable track is not found"); } RtspRequestMessage playRequest = (initialTimeStamp != default(DateTime) ? _requestMessageFactory.CreatePlayRequest(initialTimeStamp) : _requestMessageFactory.CreatePlayRequest()); RtspResponseMessage playResponse = await _rtspTransportClient.EnsureExecuteRequest(playRequest, token, 1); // TODO : Create a specific parse to convert the clock values Regex clockRegex = new Regex(@"clock=(?<startTime>\d{8}T\d{6}Z)\-(?<endTime>\d{8}T\d{6}Z)", RegexOptions.Singleline); foreach (string playResponseHeader in playResponse.Headers.GetValues("Range")) { Match clockMatches = clockRegex.Match(playResponseHeader); if (clockMatches.Success) { _mediaPayloadParser.BaseTime = DateTime.ParseExact(clockMatches.Groups["startTime"].Value, "yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture, DateTimeStyles.None); } } }
public async Task ConnectAsync(CancellationToken token) { IRtspTransportClient rtspTransportClient = _transportClientProvider(); Volatile.Write(ref _rtspTransportClient, rtspTransportClient); await _rtspTransportClient.ConnectAsync(token); RtspRequestMessage optionsRequest = _requestMessageFactory.CreateOptionsRequest(); RtspResponseMessage optionsResponse = await _rtspTransportClient.ExecuteRequest(optionsRequest, token); if (optionsResponse.StatusCode == RtspStatusCode.Ok) { ParsePublicHeader(optionsResponse.Headers[WellKnownHeaders.Public]); } RtspRequestMessage describeRequest = _requestMessageFactory.CreateDescribeRequest(); RtspResponseMessage describeResponse = await _rtspTransportClient.EnsureExecuteRequest(describeRequest, token); string contentBaseHeader = describeResponse.Headers[WellKnownHeaders.ContentBase]; if (!string.IsNullOrEmpty(contentBaseHeader)) { _requestMessageFactory.ContentBase = new Uri(contentBaseHeader); } var parser = new SdpParser(); IEnumerable <RtspTrackInfo> tracks = parser.Parse(describeResponse.ResponseBody); bool anyTrackRequested = false; foreach (RtspMediaTrackInfo track in GetTracksToSetup(tracks)) { await SetupTrackAsync(track, token); Codec = track.Codec; anyTrackRequested = true; } if (!anyTrackRequested) { throw new RtspClientException("Any suitable track is not found"); } RtspRequestMessage playRequest = _requestMessageFactory.CreatePlayRequest(); await _rtspTransportClient.EnsureExecuteRequest(playRequest, token, 1); }