Exemple #1
0
        private bool ResynchSubs(long syncTimestamp)
        {
            lock (sFrames)
            {
                Log("[SUBS] Resynch Request to -> " + syncTimestamp / 10000);

                sFrames = new Queue <MediaFrame>();
                decoder.SeekAccurate((int)((syncTimestamp / 10000) - 50), FFmpeg.AutoGen.AVMediaType.AVMEDIA_TYPE_SUBTITLE);
                decoder.RunSubs();

                // Fill Sub Frames
                int escapeInfinity = 0;
                while (sFrames.Count < SUBS_MIN_QUEUE_SIZE && isPlaying && decoder.isRunning)
                {
                    escapeInfinity++;
                    Thread.Sleep(10);
                    if (escapeInfinity > 50)
                    {
                        Log("[ERROR EI2] Sub Frames Queue will not be filled by decoder"); return(false);
                    }
                }
                if (!isPlaying || !decoder.isRunning)
                {
                    return(false);
                }

                MediaFrame sFrame     = sFrames.Peek();
                MediaFrame sFrameNext = sFrame;

                // Find Closest Subs Timestamp
                while (isPlaying)
                {
                    if (sFrameNext.timestamp > syncTimestamp)
                    {
                        break;
                    }
                    sFrame = sFrames.Dequeue();
                    if (sFrames.Count < 1)
                    {
                        return(false);
                    }
                    sFrameNext = sFrames.Peek();
                }
                if (!isPlaying)
                {
                    return(false);
                }

                Log("[SUBS] Resynch Successfully to -> " + sFrame.timestamp / 10000 + " ++");

                SendSubFrame();

                return(true);
            }
        }
Exemple #2
0
        private void RestartSubs()
        {
            if (sScreamer != null)
            {
                sScreamer.Abort();
            }

            if (decoder.hasSubs)
            {
                Log("[SUBS  SCREAMER] Restarting ...");

                sScreamer = new Thread(() => {
                    decoder.PauseSubs();
                    if (!isPlaying || videoStartTicks == -1)
                    {
                        return;
                    }

                    Thread.Sleep(20);

                    lock (sFrames) sFrames = new ConcurrentQueue <MediaFrame>();

                    decoder.SeekAccurate((int)((CurTime - subsExternalDelay) / 10000) - 100, FFmpeg.AutoGen.AVMediaType.AVMEDIA_TYPE_SUBTITLE);
                    decoder.RunSubs();

                    while (isPlaying && decoder.hasSubs && sFrames.Count < SUBS_MIN_QUEUE_SIZE && !decoder.isSubsFinish)
                    {
                        Thread.Sleep(20);
                    }

                    try
                    {
                        SubsScreamer();
                    } catch (Exception) { }
                });
                sScreamer.SetApartmentState(ApartmentState.STA);
                sScreamer.Start();
            }
        }