コード例 #1
0
ファイル: DashClient.cs プロジェクト: hjhgitw/JuvoPlayer
        /// <summary>
        /// Swaps updated representation based on Manifest Reload.
        /// Updates segment information and base segment ID for the stream.
        /// </summary>
        /// <returns>bool. True. Representations were swapped. False otherwise</returns>
        private void SwapRepresentation()
        {
            // Exchange updated representation with "null". On subsequent calls, this will be an indication
            // that there is no new representations.
            var newRep = Interlocked.Exchange(ref newRepresentation, null);

            // Update internals with new representation if exists.
            if (newRep == null)
            {
                return;
            }

            initStreamBytes.Clear();

            currentRepresentation = newRep;
            currentStreams        = currentRepresentation.Segments;
            var docParams = currentStreams.GetDocumentParameters();

            if (docParams == null)
            {
                throw new ArgumentNullException("currentStreams.GetDocumentParameters() returns null");
            }

            currentStreamDuration = IsDynamic
                ? docParams.Document.MediaPresentationDuration
                : currentStreams.Duration;

            if (lastDownloadSegmentTimeRange == null)
            {
                currentSegmentId  = currentRepresentation.Segments.StartSegmentId();
                firstSegmentClock = currentStreams.SegmentTimeRange(currentSegmentId).Start;
                LogInfo($"Rep. Swap. Start Seg: [{currentSegmentId}]");
                return;
            }

            var    newSeg = currentStreams.NextSegmentId(lastDownloadSegmentTimeRange.Start);
            string message;

            if (newSeg.HasValue)
            {
                var segmentTimeRange = currentStreams.SegmentTimeRange(newSeg);
                message = $"Updated Seg: [{newSeg}]/({segmentTimeRange?.Start}-{segmentTimeRange?.Duration})";
            }
            else
            {
                message = "Not Found. Setting segment to null";
            }

            LogInfo(
                $"Rep. Swap. Last Seg: {currentSegmentId}/{lastDownloadSegmentTimeRange.Start}-{lastDownloadSegmentTimeRange.Duration} {message}");
            currentSegmentId = newSeg;

            LogInfo("Representations swapped.");
        }