From 1a5201e65fabbb58f4bd622401e684e0f7ffc08e Mon Sep 17 00:00:00 2001 From: Sweidan Omar Date: Mon, 17 Jan 2022 12:48:31 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32753 --- client/DxPlay/DxPlayer.cs | 89 ++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/client/DxPlay/DxPlayer.cs b/client/DxPlay/DxPlayer.cs index 5e25cde6..142f47a6 100644 --- a/client/DxPlay/DxPlayer.cs +++ b/client/DxPlay/DxPlayer.cs @@ -74,7 +74,7 @@ namespace DxPlay { Control playerWindow; private PlayerGraph graph; - public PlayerGraph Graph { get; set; } + public PlayerGraph Graph { get => graph; set => graph = value; } private readonly DxPlaySettings settings; // Play an avi file into a window. Allow for snapshots. @@ -100,7 +100,7 @@ namespace DxPlay { // Get the event handle the graph will use to signal // when events occur - logger.Debug("GetEventHandle"); + //logger.Debug("GetEventHandle"); hr = graph.MediaEvent.GetEventHandle(out IntPtr hEvent); DsError.ThrowExceptionForHR(hr); @@ -121,7 +121,7 @@ namespace DxPlay { tcWorker.RunWorkerAsync(tcLock); } catch (Exception e) { - logger.Error(e); + logger.Error(e.StackTrace); Dispose(); throw; } @@ -157,7 +157,7 @@ namespace DxPlay { private void TcWorker_DoWork(object sender, DoWorkEventArgs e) { while (!e.Cancel) { - UpdateTC(); + UpdateTimeCode(); Thread.Sleep(10); if (SeekTo > -1) { @@ -263,17 +263,36 @@ namespace DxPlay { logger.Debug("Seeking requested frame {0} got frame {1}, media position {2}, frame length {3}, corrected {4}", value, reachedFrames, requestedPosition, avgTimePerFrame, corrected); } - private void UpdateTC() { - if (graph == null || graph.MediaSeeking == null) + private void UpdateTimeCode() { + if (graph == null) + { return; - int hr = graph.MediaSeeking.GetCurrentPosition(out long currentPosition); - DsError.ThrowExceptionForHR(hr); - int frames = ReferenceTimeToFrames(currentPosition); - if (CurrentTC.ZeroBasedFrames != frames) { - CurrentTC.Set(frames); - //logger.Debug("Current frame is {0} ({1}), media position is {2}, AVG frame time is {3}", frames, CurrentTC.ToString(), currentPosition, AvgTimePerFrame); } - PlayEvent?.Invoke(); + else + { + if (graph.MediaSeeking == null) + { + return; + } + else + { + try + { + int hr = graph.MediaSeeking.GetCurrentPosition(out long currentPosition); + DsError.ThrowExceptionForHR(hr); + int frames = ReferenceTimeToFrames(currentPosition); + if (CurrentTC.ZeroBasedFrames != frames) + { + CurrentTC.Set(frames); + //logger.Debug("Current frame is {0} ({1}), media position is {2}, AVG frame time is {3}", frames, CurrentTC.ToString(), currentPosition, AvgTimePerFrame); + } + PlayEvent?.Invoke(); + } catch(Exception e) + { + logger.Debug("e.StackTrace: "+e.StackTrace); + } + } + } } private int ReferenceTimeToFrames(long refTime) { @@ -427,26 +446,33 @@ namespace DxPlay { // Shut down capture public void Dispose() { - lock (this) { + lock (this) + { if (isDisposed) + { return; - logger.Debug("Dispose"); - if (tcWorker != null) { - tcWorker.CancelAsync(); } + else + { + logger.Debug("Dispose"); + if (tcWorker != null) { + tcWorker.CancelAsync(); + } - GC.SuppressFinalize(this); - if (State != GraphState.Exiting) { - SetState(State = GraphState.Exiting); - // Release the thread (if the thread was started) - if (m_mre != null) { - m_mre.Set(); + GC.SuppressFinalize(this); + if (State != GraphState.Exiting) { + SetState(State = GraphState.Exiting); + // Release the thread (if the thread was started) + if (m_mre != null) { + m_mre.Set(); + } } - } - if (graph != null) { - graph.Dispose(); - graph = null; + if (graph != null) + { + graph.Dispose(); + graph = null; + } } } GC.Collect(); @@ -526,7 +552,7 @@ namespace DxPlay { hr = graph.MediaEvent.GetEvent(out ec, out p1, out p2, 0) ) { // Write the event name to the debug window - logger.Debug("EVENT:" + ec.ToString()); + //logger.Debug("EVENT:" + ec.ToString()); // If the clip is finished playing if (ec == EventCode.Complete) { @@ -538,7 +564,7 @@ namespace DxPlay { DsError.ThrowExceptionForHR(hr); //lock (tcLock) { - // UpdateTC(""); + // UpdateTimeCode(""); //} } @@ -558,7 +584,10 @@ namespace DxPlay { public void SetPlaySpeed(float value) { - Graph.MediaSeeking.SetRate(value); + if (Graph != null && Graph.MediaSeeking != null) + { + Graph.MediaSeeking.SetRate(value); + } } } } -- 2.54.0