Exemplo n.º 1
0
        private void ExitSyncBuffering(MediaType main, MediaType[] all, CancellationToken ct)
        {
            // Don't exit syc-buffering if we are not in syncbuffering
            if (!MediaCore.IsSyncBuffering)
            {
                return;
            }

            // Detect if an exit from Sync Buffering is required
            var canExitSyncBuffering  = MediaCore.Blocks[main].Count > 0;
            var mustExitSyncBuffering =
                ct.IsCancellationRequested ||
                MediaCore.HasDecodingEnded ||
                Container.IsAtEndOfStream ||
                State.HasMediaEnded ||
                Commands.HasPendingCommands ||
                HasDisconnectedClocks;

            try
            {
                if (mustExitSyncBuffering)
                {
                    this.LogDebug(Aspects.ReadingWorker, $"SYNC-BUFFER: 'must exit' condition met.");
                    return;
                }

                if (!canExitSyncBuffering)
                {
                    return;
                }

                foreach (var t in all)
                {
                    if (t == MediaType.Subtitle || t == main)
                    {
                        continue;
                    }

                    // We don't want to consider sync-buffer on attached pictures
                    if (Container.Components[t].IsStillPictures)
                    {
                        continue;
                    }

                    // If we don't have data on the t component beyond the mid time of the main
                    // we can't exit sync-buffering.
                    if (MediaCore.Blocks[t].RangeEndTime < MediaCore.Blocks[main].RangeMidTime)
                    {
                        canExitSyncBuffering = false;
                        break;
                    }
                }
            }
            finally
            {
                // Exit sync-buffering state if we can or we must
                if (mustExitSyncBuffering || canExitSyncBuffering)
                {
                    AlignClocksToPlayback(main, all);
                    MediaCore.SignalSyncBufferingExited();
                }
            }
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 protected override void OnDisposing()
 {
     // Reset the state to non-sync-buffering
     MediaCore.SignalSyncBufferingExited();
 }