public override void StartSegment(ISegmentMetadata segmentMetadata) { this._audioParser = (IAudioParser)this.Parser; IShoutcastSegmentMetadata shoutcastSegmentMetadata = segmentMetadata as IShoutcastSegmentMetadata; if (null != shoutcastSegmentMetadata) { int?icyMetaInt = shoutcastSegmentMetadata.IcyMetaInt; int num; if (icyMetaInt.HasValue) { int?nullable = icyMetaInt; num = (nullable.GetValueOrDefault() <= 0 ? 0 : (nullable.HasValue ? 1 : 0)) == 0 ? 1 : 0; } else { num = 1; } if (num == 0) { this._audioParser = this._shoutcastMetadataFilterFactory.Create(segmentMetadata, (IAudioParser)this.Parser, new Action <ITrackMetadata>(((MediaParserBase <TConfigurator>) this).SetTrackMetadata), icyMetaInt.Value); } } this._metadataSink.ReportSegmentMetadata(this.Parser.Position ?? TimeSpan.Zero, segmentMetadata); }
public virtual void ReportSegmentMetadata(TimeSpan timestamp, ISegmentMetadata segmentMetadata) { Debug.WriteLine(string.Concat(new object[4] { (object)"MetadataSink.ReportSegmentMetadata() ", (object)timestamp, (object)" ", (object)segmentMetadata })); bool lockTaken = false; object obj = null; try { Monitor.Enter(obj = this._lock, ref lockTaken); this._metadataState.SegmentTimestamp = timestamp; this._metadataState.SegmentMetadata = segmentMetadata; } finally { if (lockTaken) { Monitor.Exit(obj); } } }
public virtual TimeSpan?Update(MetadataState state, TimeSpan position) { bool lockTaken = false; object obj = null; try { Monitor.Enter(obj = this._lock, ref lockTaken); this._position = position; TimeSpan? nullable1 = this.ProcessPendingTracks(); IStreamMetadata streamMetadata = this._metadataState.StreamMetadata; ISegmentMetadata segmentMetadata = this._metadataState.SegmentMetadata; state.SegmentMetadata = segmentMetadata; state.SegmentTimestamp = this._metadataState.SegmentTimestamp; state.StreamMetadata = streamMetadata; state.StreamTimestamp = this._metadataState.StreamTimestamp; state.TrackMetadata = this._metadataState.TrackMetadata; state.ConfigurationMetadata = this._metadataState.ConfigurationMetadata; int num1; if (this._metadataState.StreamTimestamp > this._position) { TimeSpan streamTimestamp = this._metadataState.StreamTimestamp; TimeSpan?nullable2 = nullable1; num1 = (nullable2.HasValue ? (streamTimestamp < nullable2.GetValueOrDefault() ? 1 : 0) : 0) == 0 ? 1 : 0; } else { num1 = 1; } if (num1 == 0) { nullable1 = new TimeSpan?(this._metadataState.StreamTimestamp); } int num2; if (this._metadataState.SegmentTimestamp > this._position) { TimeSpan segmentTimestamp = this._metadataState.SegmentTimestamp; TimeSpan?nullable2 = nullable1; num2 = (nullable2.HasValue ? (segmentTimestamp < nullable2.GetValueOrDefault() ? 1 : 0) : 0) == 0 ? 1 : 0; } else { num2 = 1; } if (num2 == 0) { nullable1 = new TimeSpan?(this._metadataState.SegmentTimestamp); } return(nullable1); } finally { if (lockTaken) { Monitor.Exit(obj); } } }
public virtual void ReportSegmentMetadata(TimeSpan timestamp, ISegmentMetadata segmentMetadata) { Debug.WriteLine("MetadataSink.ReportSegmentMetadata() " + timestamp + " " + segmentMetadata); lock (_lock) { _metadataState.SegmentTimestamp = timestamp; _metadataState.SegmentMetadata = segmentMetadata; } }
private async Task ReadResponseAsync(IMediaParser mediaParser, IWebStreamResponse webStreamResponse, WebResponse webResponse, SingleStreamMediaManager.QueueThrottle throttle, CancellationToken cancellationToken) { byte[] buffer = new byte[16384]; Task cancellationTask = CancellationTokenExtensions.AsTask(cancellationToken); try { ISegmentMetadata segmentMetadata = this._webMetadataFactory.CreateSegmentMetadata(webResponse, (ContentType)null); mediaParser.StartSegment(segmentMetadata); using (Stream stream = await webStreamResponse.GetStreamAsync(cancellationToken).ConfigureAwait(false)) { while (true) { Task waitTask = throttle.WaitAsync(); if (!waitTask.IsCompleted) { Task task = await TaskEx.WhenAny(waitTask, cancellationTask).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); } int length = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); if (length > 0) { mediaParser.ProcessData(buffer, 0, length); } else { break; } } } } finally { mediaParser.ProcessEndOfData(); } }
private Task OpenStream(Action <ISegmentMetadata> setMetadata, CancellationToken cancellationToken) { this.ThrowIfDisposed(); WebResponse webResponse = new WebResponse(); IRetry retry = this._retryManager.CreateRetry(2, 200, new Func <Exception, bool>(RetryPolicy.IsWebExceptionRetryable)); return(RetryExtensions.CallAsync(retry, (Func <Task>)(async() => { long?nullable1; long?nullable2; while (true) { if (this._startOffset.HasValue && this._endOffset.HasValue) { nullable1 = this._endOffset; nullable2 = this._startOffset; nullable1 = nullable1.HasValue & nullable2.HasValue ? new long?(nullable1.GetValueOrDefault() - nullable2.GetValueOrDefault()) : new long?(); long?nullable3; if (!nullable1.HasValue) { nullable2 = new long?(); nullable3 = nullable2; } else { nullable3 = new long?(nullable1.GetValueOrDefault() + 1L); } this._expectedBytes = nullable3; } else { this._expectedBytes = new long?(); } this._response = await this._webReader.GetWebStreamAsync(this._actualUrl ?? this._segment.Url, false, cancellationToken, this._segment.ParentUrl, this._startOffset, this._endOffset, webResponse).ConfigureAwait(false); if (!this._response.IsSuccessStatusCode) { HttpStatusCode statusCode = (HttpStatusCode)this._response.HttpStatusCode; if (HttpStatusCode.NotFound != statusCode && !RetryPolicy.IsRetryable(statusCode)) { this._response.EnsureSuccessStatusCode(); } bool canRetry = await retry.CanRetryAfterDelayAsync(cancellationToken).ConfigureAwait(false); if (!canRetry) { if ((Uri)null != this._actualUrl && this._actualUrl != this._segment.Url) { this._actualUrl = (Uri)null; } else { this._response.EnsureSuccessStatusCode(); } } this._response.Dispose(); this._response = (IWebStreamResponse)null; } else { break; } } this._actualUrl = this._response.ActualUrl; long?contentLength = this._response.ContentLength; if (!this._endOffset.HasValue) { nullable1 = contentLength; long?nullable3; if (!nullable1.HasValue) { nullable2 = new long?(); nullable3 = nullable2; } else { nullable3 = new long?(nullable1.GetValueOrDefault() - 1L); } this._endOffset = nullable3; } if (!this._expectedBytes.HasValue) { this._expectedBytes = contentLength; } SegmentReader segmentReader1 = this; ConfiguredTaskAwaitable <Stream> configuredTaskAwaitable = this._response.GetStreamAsync(cancellationToken).ConfigureAwait(false); PositionStream positionStream = new PositionStream(await configuredTaskAwaitable); segmentReader1._responseStream = (Stream)positionStream; Task <Stream> filterStreamTask = this._segment.CreateFilterAsync(this._responseStream, cancellationToken); if (null != filterStreamTask) { SegmentReader segmentReader2 = this; configuredTaskAwaitable = filterStreamTask.ConfigureAwait(false); Stream stream = await configuredTaskAwaitable; segmentReader2._readStream = stream; } else { this._readStream = this._responseStream; } ISegmentMetadata segmentMetadata = this._webMetadataFactory.CreateSegmentMetadata(webResponse, (ContentType)null); setMetadata(segmentMetadata); }), cancellationToken)); }
public IAudioParser Create(ISegmentMetadata segmentMetadata, IAudioParser audioParser, Action<ITrackMetadata> reportMetadata, int interval) { var encoding = _shoutcastEncodingSelector.GetEncoding(segmentMetadata.Url); return new ShoutcastMetadataFilter(audioParser, reportMetadata, interval, encoding); }
public abstract void StartSegment(ISegmentMetadata segmentMetadata);
public override void ReportSegmentMetadata(TimeSpan timestamp, ISegmentMetadata segmentMetadata) { base.ReportSegmentMetadata(timestamp, segmentMetadata); this._updateAction(); }
public IAudioParser Create(ISegmentMetadata segmentMetadata, IAudioParser audioParser, Action <ITrackMetadata> reportMetadata, int interval) { Encoding encoding = this._shoutcastEncodingSelector.GetEncoding(segmentMetadata.Url); return((IAudioParser) new ShoutcastMetadataFilter(audioParser, reportMetadata, interval, encoding)); }
public void StartSegment(ISegmentMetadata segmentMetadata) { }
public override void ReportSegmentMetadata(TimeSpan timestamp, ISegmentMetadata segmentMetadata) { base.ReportSegmentMetadata(timestamp, segmentMetadata); _updateAction(); }