public VideoFrame GetCurrentFrame() { //Profiler.Profile.BeginBlock("GetFrame"); // GC.Collect(); long ctick = Environment.TickCount; if (LastTick == 0) { LastTick = ctick; } if (Paused) { LastTick = ctick; // Profiler.Profile.EndBlock("GetFrame"); return(CurrentFrame); } double ts = (double)(ctick - LastTick) / 1000.0; LastTick = ctick; CLOCK += ts; double dt = CLOCK - TimeDelta; // - timeDelay * 30; // Console.WriteLine("Clock:" + dt); if (Frames.Count == 0) { return(null); } if (CurrentFrame == null) { if (Frames.Count == 0) { return(null); } FrameMutex.WaitOne(); CurrentFrame = Frames.Dequeue(); FrameMutex.ReleaseMutex(); } if (CurrentFrame.DPTS <= dt) { } else { //Profiler.Profile.EndBlock("GetFrame"); return(CurrentFrame); } if (CurrentFrame != null) { if (Frames.Count > 0) { // CurrentFrame.Img.Delete(); CurrentFrame = Frames.Dequeue(); // CLOCK = CurrentFrame.DPTS; double dd = (double)CurrentFrame.DDELAY; dd += ((double)CurrentFrame.Pict * (CurrentFrame.DDELAY * 0.5)); timeDelay = dd; //dd = dd * 1000; dd = dd * 50; //LastTick += (long)dd; //CLOCK = CLOCK += dd; //CLOCK = CLOCK -= dd; } //Profiler.Profile.EndBlock("GetFrame"); return(CurrentFrame); } if (Frames.Count == 0) { // Profiler.Profile.EndBlock("GetFrame"); return(null); } if (CurrentFrame == null) { FrameMutex.WaitOne(); CurrentFrame = Frames.Dequeue(); FrameMutex.ReleaseMutex(); } //Profiler.Profile.EndBlock("GetFrame"); return(CurrentFrame); }
public void Thr_Decode() { while (true) { if (!Paused) { if (gotAudioTime == false) { if (VideoIn.audioHasBegun() == 1) { gotAudioTime = true; audioStartTime = Environment.TickCount; } } else { long curTime = Environment.TickCount; long timed = curTime - audioStartTime; AUDIOCLOCK = ((double)(timed) / 1000.0); } while (true) { // FrameMutex.WaitOne(); if (Frames.Count == 0) { // FrameMutex.ReleaseMutex(); break; } FrameMutex.WaitOne(); VideoFrame frm = null; while (true) { frm = Frames.Peek(); if (frm != null) { break; } } FrameMutex.ReleaseMutex(); if (frm.DPTS < AUDIOCLOCK) { FrameMutex.WaitOne(); Frames.Dequeue(); FrameMutex.ReleaseMutex(); } else { // FrameMutex.ReleaseMutex(); break; } // FrameMutex.ReleaseMutex(); } if (Frames.Count > 0) { FrameMutex.WaitOne(); VideoFrame frm = null; while (true) { frm = Frames.Peek(); if (frm != null) { break; } } double ft = frm.DPTS; FrameMutex.ReleaseMutex(); TimeDelta = ft - AUDIOCLOCK; } //FrameMutex.ReleaseMutex(); // FrameMutex.WaitOne(); FrameMutex.WaitOne(); if (Frames.Count < 8) { DecodeNextFrame(); } FrameMutex.ReleaseMutex(); // FrameMutex.ReleaseMutex(); } // GC.Collect(); // T//hread.Sleep(2); } }