From: Vásáry Dániel Date: Tue, 27 Nov 2018 13:56:05 +0000 (+0000) Subject: Bug #102 DxPlay lejátszás végeztével elveszti a fonalat X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=3732481a83df621f75344ae944f27ae68a285366;p=mediacube.git Bug #102 DxPlay lejátszás végeztével elveszti a fonalat Bug #95 Több szegmens esetén a szegmensek vége és eleje nem lehet ugyan az a képkocka git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C31352 --- diff --git a/client/DxPlay/Configuration/dxplay - Copy.json b/client/DxPlay/Configuration/dxplay.json similarity index 88% rename from client/DxPlay/Configuration/dxplay - Copy.json rename to client/DxPlay/Configuration/dxplay.json index cc6f5e6a..c958879c 100644 --- a/client/DxPlay/Configuration/dxplay - Copy.json +++ b/client/DxPlay/Configuration/dxplay.json @@ -1,7 +1,8 @@ { "targetDirectory": "DONE", "uiFileName": "dxplay.en", - "isMaximized": true, + "isMaximized": false, + "isStandalone": false, "player": { "autoStart": false, "segmentEditor": true diff --git a/client/DxPlay/DxPlay.csproj b/client/DxPlay/DxPlay.csproj index 432eff95..57e4c91f 100644 --- a/client/DxPlay/DxPlay.csproj +++ b/client/DxPlay/DxPlay.csproj @@ -193,7 +193,6 @@ PlayerControls.cs - @@ -210,6 +209,9 @@ + + Form + @@ -243,7 +245,7 @@ - + Always diff --git a/client/DxPlay/DxPlayer.cs b/client/DxPlay/DxPlayer.cs index 8a044d95..294b412a 100644 --- a/client/DxPlay/DxPlayer.cs +++ b/client/DxPlay/DxPlayer.cs @@ -1,19 +1,18 @@ -using System; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Windows.Forms; -using System.Threading; - using DirectShowLib; +using DxPlay.Properties; +using MaestroShared.Metadata; using Microsoft.Win32.SafeHandles; -using System.ComponentModel; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; -using System.Collections.Generic; using Myriadbits.MXF; -using MaestroShared.Metadata; using NLog; -using DxPlay.Properties; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Threading; +using System.Windows.Forms; namespace DxPlay { public delegate void DxPlayEvent(); @@ -74,7 +73,7 @@ namespace DxPlay { // (Control to show video in, Avi file to play public DxPlayer(Control hWin, ref MediaDescription mediaDesc, DxPlaySettings settings) { this.settings = settings; - + SeekTo = -1; stringValues.Add(GraphState.Exiting, settings.Resource("EXITING", Resources.EXITING)); stringValues.Add(GraphState.Paused, settings.Resource("PAUSED", Resources.PAUSED)); stringValues.Add(GraphState.Playing, settings.Resource("PLAYING", Resources.PLAYING)); @@ -159,10 +158,10 @@ namespace DxPlay { UpdateTC(); Thread.Sleep(10); - if (SeekTo != 0) { + if (SeekTo > -1) { RealSeek(SeekTo); Thread.Sleep(100); - SeekTo = 0; + SeekTo = -1; } } @@ -171,8 +170,6 @@ namespace DxPlay { // start playing public void Play() { // If we aren't already playing (or shutting down) - if (State == GraphState.Completed) - Stop(); if (State == GraphState.Stopped || State == GraphState.Paused) { int hr = graph.MediaControl.Run(); DsError.ThrowExceptionForHR(hr); @@ -184,7 +181,7 @@ namespace DxPlay { // Pause the capture graph. public void Pause() { // If we are playing - if (State == GraphState.Playing || State == GraphState.Completed) { + if (State == GraphState.Playing) { int hr = graph.MediaControl.Pause(); DsError.ThrowExceptionForHR(hr); @@ -198,7 +195,7 @@ namespace DxPlay { //// Can only Stop when playing or paused Seek(0); Pause(); - if (State == GraphState.Playing || State == GraphState.Paused || State == GraphState.Completed) { + if (State == GraphState.Playing || State == GraphState.Paused) { int hr = graph.MediaControl.StopWhenReady(); DsError.ThrowExceptionForHR(hr); State = GraphState.Stopped; @@ -225,6 +222,7 @@ namespace DxPlay { public void RealSeek(int value) { if (graph == null || graph.MediaSeeking == null) return; + double frameLength = (double)MEDIATIME_REFERENCE / MediaDescription.FrameRate; long avgTimePerFrame = (long)Math.Ceiling(MEDIATIME_REFERENCE / MediaDescription.FrameRate); long requestedPosition = (long)Math.Ceiling(value * frameLength); @@ -243,6 +241,9 @@ namespace DxPlay { DsError.ThrowExceptionForHR(hr); corrected = true; } + + if (State == GraphState.Completed) + State = GraphState.Stopped; //ForceRepaintFrame(); logger.Debug("Seeking requested frame {0} got frame {1}, media position {2}, frame length {3}, corrected {4}", value, reachedFrames, requestedPosition, avgTimePerFrame, corrected); } @@ -250,8 +251,7 @@ namespace DxPlay { private void UpdateTC() { if (graph == null || graph.MediaSeeking == null) return; - long currentPosition; - int hr = graph.MediaSeeking.GetCurrentPosition(out currentPosition); + int hr = graph.MediaSeeking.GetCurrentPosition(out long currentPosition); DsError.ThrowExceptionForHR(hr); int frames = ReferenceTimeToFrames(currentPosition); if (CurrentTC.ZeroBasedFrames != frames) { @@ -516,7 +516,6 @@ namespace DxPlay { // If the clip is finished playing if (ec == EventCode.Complete) { State = GraphState.Completed; - Pause(); } // Release any resources the message allocated diff --git a/client/DxPlay/DxPlayerx.cs b/client/DxPlay/DxPlayerx.cs deleted file mode 100644 index 0f7c16fe..00000000 --- a/client/DxPlay/DxPlayerx.cs +++ /dev/null @@ -1,691 +0,0 @@ -using System; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Diagnostics; -using System.Windows.Forms; -using System.Threading; - -using DirectShowLib; -using DirectShowLib.Utils; -using Microsoft.Win32.SafeHandles; -using System.ComponentModel; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; -using System.Collections.Generic; -using Myriadbits.MXF; -using MaestroShared.Metadata; -using NLog; -using DxPlay.Properties; - -namespace DxPlay { - - internal class DxPlayerx : ISampleGrabberCB, IDisposable { - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - - [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory")] - private static extern void CopyMemory(IntPtr Destination, IntPtr Source, [MarshalAs(UnmanagedType.U4)] uint Length); - - private const int MEDIATIME_REFERENCE = 10000000; - - public enum GraphState { - Stopped, - Completed, - Paused, - Playing, - Exiting - } - - public Dictionary stateHunStringValues = new Dictionary(); - - public MediaDescription MediaDescription { get; internal set; } - public Timecode CurrentTC { get; internal set; } - public GraphState State { get; internal set; } - - private IFilterGraph2 m_FilterGraph; - private IMediaControl m_mediaCtrl; - private IMediaEvent m_mediaEvent; - - // Event used by Media Event thread - private ManualResetEvent m_mre; - private BackgroundWorker tcWorker; - // Current state of the graph (can change async) - - public event DxPlayEvent PlayEvent; - public delegate void DxPlayEvent(); - - private Thread m_eventThread = null; - private IMediaSeeking m_mediaSeek = null; - - private IVideoWindow m_videoWindow = null; - private IBaseFilter m_videoRenderer = null; - private object tcLock = new object(); - Bitmap m_Bitmap = null; - public bool IsError { get; set; } -#if DEBUG - // Allow you to "Connect to remote graph" from GraphEdit - DsROTEntry m_DsRot; -#endif - private int m_stride; - - // Release everything. - public void Dispose() { - CloseInterfaces(); - } - - ~DxPlayerx() { - CloseInterfaces(); - } - - Control playerWindow; - private object ppUnk; - - // Play an avi file into a window. Allow for snapshots. - // (Control to show video in, Avi file to play - public DxPlayerx(Control hWin, ref MediaDescription mediaDesc) { - FillTheHunStringvalues(); - State = GraphState.Stopped; - try { - int hr; - IntPtr hEvent; - MediaDescription = mediaDesc; - // Set up the graph - playerWindow = hWin; - - SetupGraph(); - - hWin.Hide(); - hWin.Show(); - - // Get the event handle the graph will use to signal - // when events occur - Debug.WriteLine("GetEventHandle"); - hr = m_mediaEvent.GetEventHandle(out hEvent); - DsError.ThrowExceptionForHR(hr); - - // Wrap the graph event with a ManualResetEvent - m_mre = new ManualResetEvent(false); - m_mre.SafeWaitHandle = new SafeWaitHandle(hEvent, true); - - // Create a new thread to wait for events - Debug.WriteLine("m_eventThread.Start()"); - m_eventThread = new Thread(new ThreadStart(EventWait)); - m_eventThread.Name = "Media Event Thread"; - m_eventThread.Start(); - - m_Bitmap = Properties.Resources.lgs; - - tcWorker = new BackgroundWorker(); - tcWorker.DoWork += TcWorker_DoWork; - tcWorker.WorkerSupportsCancellation = true; - tcWorker.RunWorkerAsync(tcLock); - - } - catch { - Dispose(); - throw; - } - } - - private void FillTheHunStringvalues() { - stateHunStringValues.Add(GraphState.Exiting, Resources.EXITING); - stateHunStringValues.Add(GraphState.Paused, Resources.PAUSED); - stateHunStringValues.Add(GraphState.Playing, Resources.PLAYING); - stateHunStringValues.Add(GraphState.Stopped, Resources.STOPPED); - stateHunStringValues.Add(GraphState.Completed, Resources.COMPLETED); - } - - private void TcWorker_DoWork(object sender, DoWorkEventArgs e) { - while (!e.Cancel) { - UpdateTC(); - Thread.Sleep(10); - } - } - - - // start playing - public void Play() { - // If we aren't already playing (or shutting down) - if (State == GraphState.Completed) - Stop(); - if (State == GraphState.Stopped || State == GraphState.Paused) { - int hr = m_mediaCtrl.Run(); - DsError.ThrowExceptionForHR(hr); - - State = GraphState.Playing; - } - } - - // Pause the capture graph. - public void Pause() { - // If we are playing - if (State == GraphState.Playing) { - int hr = m_mediaCtrl.Pause(); - DsError.ThrowExceptionForHR(hr); - - State = GraphState.Paused; - Seek(CurrentTC.ZeroBasedFrames); - } - } - - // Pause the capture graph. - public void Stop() { - // Can only Stop when playing or paused - if (State == GraphState.Playing || State == GraphState.Paused || State == GraphState.Completed) { - int hr = m_mediaCtrl.Stop(); - DsError.ThrowExceptionForHR(hr); - State = GraphState.Stopped; - } - Rewind(); - PlayEvent?.Invoke(); - } - - // Reset the clip back to the beginning - public void Rewind() { - Seek(0); - } - - public void Seek(int value) { - double frameLength = (double)MEDIATIME_REFERENCE / MediaDescription.FrameRate; - long avgTimePerFrame = (long)Math.Ceiling(MEDIATIME_REFERENCE / MediaDescription.FrameRate); - long requestedPosition = (long)Math.Ceiling(value * frameLength); - int hr = m_mediaSeek.SetPositions(requestedPosition, AMSeekingSeekingFlags.AbsolutePositioning, null, AMSeekingSeekingFlags.NoPositioning); - DsError.ThrowExceptionForHR(hr); - - long currentPosition; - hr = m_mediaSeek.GetCurrentPosition(out currentPosition); - DsError.ThrowExceptionForHR(hr); - bool corrected = false; - int reachedFrames = (int)Math.Abs((double)currentPosition / avgTimePerFrame); - if (reachedFrames != value) { - //NTSC-n nem megy a seek a kerekítési hibák miatt, mindíg ua. a frame jön ki - requestedPosition += (int)frameLength / 2; - hr = m_mediaSeek.SetPositions(requestedPosition, AMSeekingSeekingFlags.AbsolutePositioning, null, AMSeekingSeekingFlags.NoPositioning); - DsError.ThrowExceptionForHR(hr); - corrected = true; - } - - Debug.WriteLine("Seeking requested frame {0} got frame {1}, media position {2}, frame length {3}, corrected {4}", value, reachedFrames, requestedPosition, avgTimePerFrame, corrected); - } - - private void UpdateTC() { - if (m_mediaSeek == null) - return; - long currentPosition; - int hr = m_mediaSeek.GetCurrentPosition(out currentPosition); - DsError.ThrowExceptionForHR(hr); - int frames = ReferenceTimeToFrames(currentPosition); - if (CurrentTC.ZeroBasedFrames != frames) { - CurrentTC.Set(frames); - //Debug.WriteLine("Current frame is {0} ({1}), media position is {2}, AVG frame time is {3}", frames, CurrentTC.ToString(), currentPosition, AvgTimePerFrame); - } - PlayEvent?.Invoke(); - - } - - private int ReferenceTimeToFrames(long refTime) { - long AvgTimePerFrame = (long)Math.Ceiling(MEDIATIME_REFERENCE / MediaDescription.FrameRate); - return (int)Math.Abs((double)refTime / AvgTimePerFrame); - } - - private void SetupGraph() { - int hr; - - try { - IsError = false; - m_FilterGraph = new FilterGraph() as IFilterGraph2; - - IGraphBuilder graphBuilder = m_FilterGraph as IGraphBuilder; - m_mediaSeek = m_FilterGraph as IMediaSeeking; - m_mediaEvent = m_FilterGraph as IMediaEvent; - m_mediaCtrl = m_FilterGraph as IMediaControl; - m_videoWindow = m_FilterGraph as IVideoWindow; - - logger.Debug("SetTimeCodes"); - SetTimeCodes(); - -#if DEBUG - m_DsRot = new DsROTEntry(m_FilterGraph); -#endif - logger.Debug("Add SourceFilter to graph"); - IBaseFilter sourceFilter = null; - hr = m_FilterGraph.AddSourceFilter(MediaDescription.FileName, MediaDescription.FileName, out sourceFilter); - DsError.ThrowExceptionForHR(hr); - - //Type typeFromClsid = Type.GetTypeFromCLSID(new Guid("CCE7BD95-3BC4-4cfb-9664-0BF83201BE09")); - //splitter = (IBaseFilter)Activator.CreateInstance(typeFromClsid); - //m_FilterGraph.AddFilter(splitter, "MXF Splitter"); - //splitter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, "Sony MXF Splitter"); - - logger.Debug("Add LAVSplitter to graph"); - IBaseFilter splitter = LoadSplitter(graphBuilder); - if (splitter == null) - throw new Exception("No splitter!"); - - logger.Debug("Connect SourceFilter -> LAVSplitter"); - FilterGraphTools.ConnectFilters(graphBuilder, sourceFilter, "Output", splitter, "Input", true); - - IAMStreamSelect amStreamSelect = (IAMStreamSelect)splitter; - if (amStreamSelect != null) { - int count = 0; - amStreamSelect.Count(out count); - int audioCount = 0; - for (int i = 0; i < count; i++) { - AMMediaType ppmt; - AMStreamSelectInfoFlags pdwFlags; - int plcid; - int pdwGroup; - string ppszName; - object ppObject; - amStreamSelect.Info(i, out ppmt, out pdwFlags, out plcid, out pdwGroup, out ppszName, out ppObject, out ppUnk); - - if (ppmt.majorType == MediaType.Audio) { - Debug.WriteLine("Found audio channel"); - audioCount++; - } - - DsUtils.FreeAMMediaType(ppmt); - //Marshal.FreeCoTaskMem(ppszName); - if (ppObject != null) - DsUtils.ReleaseComObject(ppUnk); - - } - Debug.WriteLine("Audio count: " + audioCount); - } - - logger.Debug("Add LAVVideo to graph"); - IBaseFilter videoDecoder = LoadVideoDecoder(graphBuilder); - - if (videoDecoder == null) - throw new Exception("No video decoder!"); - - logger.Debug("Connect LAVSplitter -> LAVVideo"); - FilterGraphTools.ConnectFilters(graphBuilder, splitter, "Video", videoDecoder, "Input", true); - - logger.Debug("Add SampleGrabber to graph"); - IBaseFilter sampGrabber = (IBaseFilter)new SampleGrabber(); - ISampleGrabber sampleGrabber = (ISampleGrabber)sampGrabber; - ConfigureSampleGrabber(sampleGrabber); - - hr = m_FilterGraph.AddFilter(sampGrabber, "Sample Grabber"); - DsError.ThrowExceptionForHR(hr); - - logger.Debug("Connect LAVVideo -> SampleGrabber"); - FilterGraphTools.ConnectFilters(graphBuilder, videoDecoder, "Output", sampGrabber, "Input", true); - - AMMediaType media = new AMMediaType(); - sampleGrabber.GetConnectedMediaType(media); - logger.Debug("SaveSizeInfo"); - SaveSizeInfo(media); - DsUtils.FreeAMMediaType(media); - - logger.Debug("Add VideoMixingRenderer9 to graph"); - m_videoRenderer = (IBaseFilter)new VideoMixingRenderer9(); - hr = m_FilterGraph.AddFilter(m_videoRenderer, "Video Mixing Renderer 9"); - DsError.ThrowExceptionForHR(hr); - - - try { - //IPin pin = DsFindPin.ByName(sampGrabber, "Output"); - //m_FilterGraph.RenderEx(pin, AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero); - //Marshal.ReleaseComObject(pin); - logger.Debug("Connect SampleGrabber -> VideoMixingRenderer9"); - FilterGraphTools.ConnectFilters(graphBuilder, sampGrabber, "Output", m_videoRenderer, "VMR Input0", true); - } - catch (Exception e) { - logger.Error(e); - } - - try { - if (DsFindPin.ByName(splitter, "Audio") != null) { - logger.Debug("Add LAVAudio to graph"); - IBaseFilter audioDecoder = null; - audioDecoder = LoadAudioDecoder(graphBuilder); - if (audioDecoder == null) - throw new Exception("No audio decoder!"); - - logger.Debug("Connect LAVSplitter -> LAVAudio"); - FilterGraphTools.ConnectFilters(graphBuilder, splitter, "Audio", audioDecoder, "Input", true); - FilterGraphTools.RenderPin(graphBuilder, audioDecoder, "Output"); - } else { - logger.Warn("Audio pin not available"); - } - } - catch (Exception ex) { - logger.Warn("Audio pin not available"); - } - - - //logger.Debug("SaveSizeInfo"); - //SaveSizeInfo(sampGrabber as ISampleGrabber); - logger.Debug("ConfigureVideoWindow"); - ConfigureVideoWindow(); - - logger.Debug("Enable YADIF deinterlace"); - ILAVVideoSettings settings = (ILAVVideoSettings)videoDecoder; - settings.SetSWDeintMode(LAVSWDeintModes.SWDeintMode_YADIF); - settings.SetSWDeintOutput(LAVDeintOutput.DeintOutput_FramePer2Field); - } - catch (Exception e) { - Debug.WriteLine(e.Message); - IsError = true; - } - finally { - } -#if DEBUG - // Double check to make sure we aren't releasing something - // important. - //GC.Collect(); - //GC.WaitForPendingFinalizers(); -#endif - } - - private static IBaseFilter LoadVideoDecoder(IGraphBuilder graphBuilder) { - IBaseFilter videoDecoder = null; - ILAVVideoSettings lavVideoSettings; - videoDecoder = FilterProvider.GetVideoFilter(out lavVideoSettings); - if (videoDecoder == null) - videoDecoder = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, "LAV Video Decoder"); - else - graphBuilder.AddFilter(videoDecoder, "LAV Video Decoder"); - return videoDecoder; - } - - private static IBaseFilter LoadAudioDecoder(IGraphBuilder graphBuilder) { - IBaseFilter audioDecoder = null; - ILAVAudioSettings lavAudioSettings; - ILAVAudioStatus lavAudioStatus; - audioDecoder = FilterProvider.GetAudioFilter(out lavAudioSettings, out lavAudioStatus); - if (audioDecoder == null) - audioDecoder = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, "LAV Audio Decoder"); - else - graphBuilder.AddFilter(audioDecoder, "LAV Audio Decoder"); - return audioDecoder; - } - - private static IBaseFilter LoadSplitter(IGraphBuilder graphBuilder) { - IBaseFilter splitter = null; - ILAVSplitterSettings lavSplitterSettings; - splitter = FilterProvider.GetSplitter(out lavSplitterSettings); - if (splitter == null) - splitter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, "LAV Splitter"); - else - graphBuilder.AddFilter(splitter, "LAV Splitter"); - return splitter; - } - - private void SetTimeCodes() { - int hr; - long duration; - hr = m_mediaSeek.GetDuration(out duration); - DsError.ThrowExceptionForHR(hr); - MediaDescription.duration = new Timecode(); - MediaDescription.Duration.Set(ReferenceTimeToFrames(duration)); - if (MediaDescription.FirstFrame == null) { - try { - MXFFile mxf = new MXFFile(MediaDescription.FileName); - mxf.Inspect(); - //MediaDescription.firstFrame = new Timecode(mxf.FirstSystemItem?.UserDateFullFrameNb, MediaDescription.FrameRate); - MediaDescription.firstFrame = new Timecode((int)mxf.TimecodeComponent.StartTimecode, (float)mxf.TimecodeComponent.RoundedTimecodeBase); - } - catch (Exception ex) { - MediaDescription.firstFrame = new Timecode(); - } - } - //MediaDescription.firstFrame = new Timecode(); - CurrentTC = new Timecode(MediaDescription.FirstFrame); - } - - - // Configure the video window - private void ConfigureVideoWindow() { - int hr; - - // Set the output window - hr = m_videoWindow.put_Owner(playerWindow.Handle); - DsError.ThrowExceptionForHR(hr); - - hr = m_videoWindow.put_MessageDrain(playerWindow.Handle); - DsError.ThrowExceptionForHR(hr); - - // Set the window style - hr = m_videoWindow.put_WindowStyle((WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings)); - DsError.ThrowExceptionForHR(hr); - - // Make the window visible - hr = m_videoWindow.put_Visible(OABool.True); - DsError.ThrowExceptionForHR(hr); - - UpdateVideoWindow(); - } - - public void UpdateVideoWindow() { - Size resolution = MediaDescription.Resolution; - if (resolution.Width == 0 || resolution.Height == 0) - return; - int hr; - // Position the playing location - Rectangle rc = playerWindow.ClientRectangle; - double x = (double)resolution.Width / resolution.Height; - double y = (double)rc.Right / rc.Bottom; - int playerWidth = 0; - int playerHeight = 0; - if (x - y < 0) { - playerWidth = (int)Math.Ceiling(rc.Bottom * x); - playerHeight = rc.Bottom; - } else { - x = (double)resolution.Height / resolution.Width; - playerWidth = rc.Right; - playerHeight = (int)Math.Ceiling(rc.Right * x); ; - } - - hr = m_videoWindow.SetWindowPosition((rc.Right - playerWidth) / 2, (rc.Bottom - playerHeight) / 2, playerWidth, playerHeight); - DsError.ThrowExceptionForHR(hr); - } - - public void ToggleFullscreen() { - m_videoWindow.put_FullScreenMode(IsFullscreen() ? OABool.False : OABool.True); - } - - public bool IsFullscreen() { - OABool isFullscreen; - int hr = m_videoWindow.get_FullScreenMode(out isFullscreen); - DsError.ThrowExceptionForHR(hr); - return isFullscreen == OABool.True ? true : false; - } - - // Set the options on the sample grabber - private void ConfigureSampleGrabber(ISampleGrabber sampGrabber) { - int hr; - //AMMediaType media; - //media = new AMMediaType(); - //media.majorType = MediaType.Video; - //media.subType = MediaSubType.RGB24; - //media.formatType = FormatType.VideoInfo; - //hr = sampGrabber.SetMediaType(media); - //DsError.ThrowExceptionForHR(hr); - //DsUtils.FreeAMMediaType(media); - - hr = sampGrabber.SetCallback(this, 1); - DsError.ThrowExceptionForHR(hr); - - // Configure the samplegrabber - hr = sampGrabber.SetBufferSamples(true); - DsError.ThrowExceptionForHR(hr); - } - - private void SaveSizeInfo(AMMediaType media) { - //int hr; - //AMMediaType media = new AMMediaType(); - //hr = sampGrabber.GetConnectedMediaType(media); - //DsError.ThrowExceptionForHR(hr); - - if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero)) { - throw new NotSupportedException("Unknown Grabber Media Format"); - } - - // Grab the size info - VideoInfoHeader videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); - MediaDescription.resolution = new Size(videoInfoHeader.BmiHeader.Width, videoInfoHeader.BmiHeader.Height); - MediaDescription.frameRate = MEDIATIME_REFERENCE / videoInfoHeader.AvgTimePerFrame; - - m_stride = videoInfoHeader.BmiHeader.Width * (videoInfoHeader.BmiHeader.BitCount / 8); - } - - // Shut down capture - private void CloseInterfaces() { - Debug.WriteLine("CloseInterfaces"); - int hr; - GC.SuppressFinalize(this); - if (tcWorker != null) - tcWorker.CancelAsync(); - lock (this) { - if (State != GraphState.Exiting) { - State = GraphState.Exiting; - - // Release the thread (if the thread was started) - if (m_mre != null) { - m_mre.Set(); - } - } - - if (m_mediaCtrl != null) { - // Stop the graph - hr = m_mediaCtrl.Stop(); - FilterGraphTools.DisconnectAllPins((IGraphBuilder)m_mediaCtrl); - FilterGraphTools.RemoveAllFilters((IGraphBuilder)m_mediaCtrl); - m_mediaCtrl = null; - - } - - if (m_videoWindow != null) { - hr = m_videoWindow.put_Visible(OABool.False); - hr = m_videoWindow.put_MessageDrain(IntPtr.Zero); - hr = m_videoWindow.put_Owner(IntPtr.Zero); - m_videoWindow = null; - } - - m_mediaEvent = null; - m_mediaSeek = null; - -#if DEBUG - if (m_DsRot != null) { - m_DsRot.Dispose(); - m_DsRot = null; - } -#endif - if (m_FilterGraph != null) { - Marshal.ReleaseComObject(m_FilterGraph); - m_FilterGraph = null; - } - } - GC.Collect(); - //if (m_eventThread != null) - // m_eventThread.Join(); - } - - public int SampleCB(double SampleTime, IMediaSample pSample) { - Marshal.ReleaseComObject(pSample); - return 0; - } - - public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { - return 0; - int frames = (int)Math.Abs(SampleTime * MediaDescription.FrameRate); - //Debug.WriteLine("BufferCB frames {0}, sample time {1}", frames, SampleTime); - Font font = new Font("Tahoma", 30); - string display = frames.ToString(); - SizeF size = new SizeF(100, 100); - m_Bitmap = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height)); - GraphicsUnit units = GraphicsUnit.Point; - RectangleF bitmapRectF = m_Bitmap.GetBounds(ref units); - - Graphics g = Graphics.FromImage(m_Bitmap); - - g.SmoothingMode = SmoothingMode.AntiAlias; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.PixelOffsetMode = PixelOffsetMode.HighQuality; - g.FillRectangle(Brushes.Transparent, bitmapRectF); - g.DrawString(display, font, Brushes.White, bitmapRectF); - g.Flush(); - - m_Bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); - Rectangle r = new Rectangle(0, 0, m_Bitmap.Width, m_Bitmap.Height); - lock (this) { - BitmapData bmdLogo = m_Bitmap.LockBits(r, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); - if (bmdLogo != null) { - IntPtr ipSource = bmdLogo.Scan0; - IntPtr ipDest = pBuffer; - - for (int x = 0; x < bmdLogo.Height; x++) { - CopyMemory(ipDest, ipSource, (uint)bmdLogo.Stride); - ipDest = (IntPtr)(ipDest.ToInt64() + m_stride); - ipSource = (IntPtr)(ipSource.ToInt64() + bmdLogo.Stride); - } - } - m_Bitmap.UnlockBits(bmdLogo); - bmdLogo = null; - } - return 0; - } - - // Wait for events to happen. This approach uses waiting on an event handle. - // The nice thing about doing it this way is that you aren't in the windows message - // loop, and don't have to worry about re-entrency or taking too long. Plus, being - // in a class as we are, we don't have access to the message loop. - // Alternately, you can receive your events as windows messages. See - // IMediaEventEx.SetNotifyWindow. - private void EventWait() { - // Returned when GetEvent is called but there are no events - const int E_ABORT = unchecked((int)0x80004004); - - int hr; - IntPtr p1, p2; - EventCode ec; - - do { - // Wait for an event - m_mre.WaitOne(-1, true); - - // Avoid contention for m_State - lock (this) { - // If we are not shutting down - if (State != GraphState.Exiting) { - // Read the event - for ( - hr = m_mediaEvent.GetEvent(out ec, out p1, out p2, 0); - hr >= 0; - hr = m_mediaEvent.GetEvent(out ec, out p1, out p2, 0) - ) { - // Write the event name to the debug window - Debug.WriteLine(ec.ToString()); - - // If the clip is finished playing - if (ec == EventCode.Complete) { - State = GraphState.Completed; - } - - // Release any resources the message allocated - hr = m_mediaEvent.FreeEventParams(ec, p1, p2); - DsError.ThrowExceptionForHR(hr); - - //lock (tcLock) { - // UpdateTC(""); - //} - - } - - // If the error that exited the loop wasn't due to running out of events - if (hr != E_ABORT) { - DsError.ThrowExceptionForHR(hr); - } - } else { - // We are shutting down - Debug.WriteLine("Shutdown"); - break; - } - } - } while (true); - } - - } -} diff --git a/client/DxPlay/PlayerForm.Designer.cs b/client/DxPlay/PlayerForm.Designer.cs index 6e5a8208..f96aea3d 100644 --- a/client/DxPlay/PlayerForm.Designer.cs +++ b/client/DxPlay/PlayerForm.Designer.cs @@ -185,7 +185,7 @@ namespace DxPlay { this.tpSegments.Location = new System.Drawing.Point(4, 4); this.tpSegments.Name = "tpSegments"; this.tpSegments.Padding = new System.Windows.Forms.Padding(3); - this.tpSegments.Size = new System.Drawing.Size(192, 30); + this.tpSegments.Size = new System.Drawing.Size(263, 304); this.tpSegments.TabIndex = 1; this.tpSegments.Text = "Segments"; this.tpSegments.UseVisualStyleBackColor = true; @@ -215,11 +215,12 @@ namespace DxPlay { this.dgSegments.Name = "dgSegments"; this.dgSegments.RowHeadersVisible = false; this.dgSegments.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dgSegments.Size = new System.Drawing.Size(186, 0); + this.dgSegments.Size = new System.Drawing.Size(257, 273); this.dgSegments.TabIndex = 1; this.dgSegments.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgSegments_CellContentClick); this.dgSegments.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgSegments_CellMouseDoubleClick); this.dgSegments.ColumnAdded += new System.Windows.Forms.DataGridViewColumnEventHandler(this.dgSegments_ColumnAdded); + this.dgSegments.MouseClick += new System.Windows.Forms.MouseEventHandler(this.OnSegmentEditorMouseClick); // // segmentActions // @@ -236,7 +237,7 @@ namespace DxPlay { this.segmentActions.Location = new System.Drawing.Point(3, 3); this.segmentActions.Name = "segmentActions"; this.segmentActions.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; - this.segmentActions.Size = new System.Drawing.Size(186, 25); + this.segmentActions.Size = new System.Drawing.Size(257, 25); this.segmentActions.TabIndex = 0; this.segmentActions.Text = "toolStrip1"; // @@ -326,7 +327,6 @@ namespace DxPlay { this.btnToggleSegmentEditor.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnToggleSegmentEditor.UseVisualStyleBackColor = false; this.btnToggleSegmentEditor.Visible = false; - this.btnToggleSegmentEditor.Click += new System.EventHandler(this.OnToggleSegmentEditor); // // pMetadataDisplay // diff --git a/client/DxPlay/PlayerForm.cs b/client/DxPlay/PlayerForm.cs index 68da28e4..21e290e6 100644 --- a/client/DxPlay/PlayerForm.cs +++ b/client/DxPlay/PlayerForm.cs @@ -1,12 +1,10 @@ using DxPlay.Model; using DxPlay.Properties; using MaestroShared.Commons; -using MaestroShared.Metadata; using NLog; using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -249,15 +247,26 @@ namespace DxPlay { Pause(); return; } + if (m_play.State == GraphState.Completed) { + m_play.Seek(0); + } m_play.Play(); - playerControls.Play.Image = Resources.ic_pause_black_24dp_2x; - tooltips.SetToolTip(playerControls.Play, Settings.Resource("PAUSE", Resources.PAUSE)); + UpdatePlayPauseButton(); + } + + private void UpdatePlayPauseButton() { + if (m_play.State == GraphState.Playing) { + playerControls.Play.Image = Resources.ic_pause_black_24dp_2x; + tooltips.SetToolTip(playerControls.Play, Settings.Resource("PAUSE", Resources.PAUSE)); + } else { + playerControls.Play.Image = Resources.ic_play_arrow_black_24dp_2x; + tooltips.SetToolTip(playerControls.Play, Settings.Resource("PLAY", Resources.PLAY)); + } } private void Pause() { m_play.Pause(); - playerControls.Play.Image = Resources.ic_play_arrow_black_24dp_2x; - tooltips.SetToolTip(playerControls.Play, Settings.Resource("PLAY", Resources.PLAY)); + UpdatePlayPauseButton(); } private void OnPlayClick(object sender, EventArgs e) { @@ -455,7 +464,7 @@ namespace DxPlay { if (Disposing || IsDisposed || m_play == null) return; if (m_play.State == GraphState.Completed) - Pause(); + UpdatePlayPauseButton(); if (!trackBarAtUser) playerControls.TrackBar.Value = m_play.CurrentTC.ZeroBasedFrames; playerControls.CurrentTC.Text = m_play.CurrentTC.ToString(); @@ -506,173 +515,6 @@ namespace DxPlay { m_play.Dispose(); } - private void OnDefineOneSegmentClick(object sender, EventArgs e) { - if (m_play == null) - return; - MovieSegment segment = null; - if (model.Segments.Count == 0) { - segment = new MovieSegment() { - TCIn = new Timecode(m_mediaDescription.FirstFrame.Frames), - TCOut = new Timecode(m_mediaDescription.FirstFrame, m_mediaDescription.Duration) - }; - } else { - MovieSegment lastSegment = model.Segments[model.Segments.Count - 1]; - Timecode tcEnd = new Timecode(m_mediaDescription.FirstFrame, m_mediaDescription.Duration); - if (lastSegment.TCOut.Frames == tcEnd.Frames) { - MsgBox.Error(Settings.Resource("ERRORCREATESEGMENT", Resources.ERRORCREATESEGMENT)); - return; - } - segment = new MovieSegment() { - TCIn = new Timecode(lastSegment.TCOut.Frames), - TCOut = tcEnd - }; - } - model.Segments.Add(segment); - } - - private void OnDeleteSegmentClick(object sender, EventArgs e) { - if (bsSegments.Current != null) - model.Segments.Remove(bsSegments.Current as MovieSegment); - } - - private void SetActualPositionAsIn() { - if (m_play == null) - return; - MovieSegment currentSegment = bsSegments.Current as MovieSegment; - if (currentSegment == null || bsSegments.Count == 0) { - MovieSegment newSegment = new MovieSegment() { - TCIn = new Timecode(m_play.CurrentTC.Frames), - TCOut = new Timecode(m_play.MediaDescription.FirstFrame.Frames + m_play.MediaDescription.Duration.Frames) - }; - bsSegments.Position = bsSegments.Add(newSegment); - } else { - if (currentSegment.TCOut.Frames <= m_play.CurrentTC.Frames) { - int pos = bsSegments.IndexOf(currentSegment); - if (pos == bsSegments.Count - 1) { - MovieSegment newSegment = new MovieSegment() { - TCIn = new Timecode(m_play.CurrentTC.Frames), - TCOut = new Timecode(m_play.MediaDescription.FirstFrame.Frames + m_play.MediaDescription.Duration.Frames) - }; - bsSegments.Position = bsSegments.Add(newSegment); - return; - } - MsgBox.Error(Settings.Resource("ERRORINVALIDTCIN", Resources.ERRORINVALIDTCIN)); - return; - } - //if (MessageBox.Show("Biztos felül akarja írni az belépõt?", "Belépõ felülírása", MessageBoxButtons.YesNo) == DialogResult.No) - // return; - MovieSegment collisionSegment = model.Segments.Where(s => s.TCIn.Frames < m_play.CurrentTC.Frames && m_play.CurrentTC.Frames < s.TCOut.Frames).SingleOrDefault(); - - if (collisionSegment != null && !currentSegment.Equals(collisionSegment)) { - MsgBox.Error(Settings.Resource("ERRORSEGMENTCOLLISION", Resources.ERRORSEGMENTCOLLISION)); - return; - } - - currentSegment.TCIn = new Timecode(m_play.CurrentTC.Frames); - } - } - - - private void SetActualPositionAsOut() { - if (m_play == null) - return; - MovieSegment currentSegment = bsSegments.Current as MovieSegment; - if (currentSegment == null || bsSegments.Count == 0) { - MovieSegment newSegment = new MovieSegment() { - TCIn = new Timecode(m_play.MediaDescription.FirstFrame.Frames), - TCOut = new Timecode(m_play.CurrentTC.Frames), - }; - bsSegments.Position = bsSegments.Add(newSegment); - } else { - if (currentSegment.TCIn.Frames >= m_play.CurrentTC.Frames) - MsgBox.Error(Settings.Resource("ERRORINVALIDTCOUT", Resources.ERRORINVALIDTCOUT)); - - MovieSegment collisionSegment = model.Segments.Where(s => s.TCIn.Frames < m_play.CurrentTC.Frames && m_play.CurrentTC.Frames < s.TCOut.Frames).SingleOrDefault(); - - if (collisionSegment != null && !currentSegment.Equals(collisionSegment)) { - MsgBox.Error(Settings.Resource("ERRORSEGMENTCOLLISION", Resources.ERRORSEGMENTCOLLISION)); - return; - } - - //if (MessageBox.Show("Biztos felül akarja írni az kilépõt?", "Kilépõ felülírása", MessageBoxButtons.YesNo) == DialogResult.No) - // return; - currentSegment.TCOut = new Timecode(m_play.CurrentTC.Frames); - } - } - - private void OnActualPositionToTCInToolStripMenuItem1Click(object sender, EventArgs e) { - SetActualPositionAsIn(); - } - - private void OnActualPositionToTCOutToolStripMenuItem1Click(object sender, EventArgs e) { - SetActualPositionAsOut(); - } - - private void OnSplitSegmentAtCurrentPositionClick(object sender, EventArgs e) { - MovieSegment currentSegment = model.Segments.Where(s => s.TCIn.Frames < m_play.CurrentTC.Frames && s.TCOut.Frames > m_play.CurrentTC.Frames).SingleOrDefault(); - if (currentSegment == null) - return; - int position = model.Segments.IndexOf(currentSegment); - MovieSegment newSegment = new MovieSegment() { - TCIn = new Timecode(currentSegment.TCIn.Frames), - TCOut = new Timecode(m_play.CurrentTC.Frames) - }; - currentSegment.TCIn = new Timecode(m_play.CurrentTC.Frames); - model.Segments.Insert(position, newSegment); - } - - private void dgSegments_ColumnAdded(object sender, DataGridViewColumnEventArgs e) { - int index = e.Column.Index; - switch (index) { - case 0: - e.Column.HeaderText = Settings.Resource("TCIN", Resources.TCIN); - e.Column.ReadOnly = true; - break; - case 1: - e.Column.HeaderText = Settings.Resource("TCOUT", Resources.TCOUT); - e.Column.ReadOnly = true; - break; - case 2: - e.Column.HeaderText = Settings.Resource("OPTIONAL", Resources.OPTIONAL); - break; - case 3: - e.Column.HeaderText = Settings.Resource("COMMENT", Resources.COMMENT); - break; - } - } - - - private void dgSegments_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { - MovieSegment actualSegment = bsSegments.Current as MovieSegment; - if (actualSegment == null || m_play == null) - return; - if (e.ColumnIndex == 0) { - m_play.Pause(); - m_play.Seek(actualSegment.TCIn.Frames - m_play.MediaDescription.FirstFrame.Frames); - } - if (e.ColumnIndex == 1) { - m_play.Pause(); - int pos = actualSegment.TCOut.Frames - m_play.MediaDescription.FirstFrame.Frames; - //Az utolsó kocka nem jelenik meg egyébként - try { - if (pos == m_play.MediaDescription.Duration.Frames) { - pos--; - m_play.Seek(pos); - m_play.Play(); - } else - m_play.Seek(pos); - } catch (Exception ex) { - MsgBox.Error(ex.Message); - } - - } - - } - - private void dgSegments_CellContentClick(object sender, DataGridViewCellEventArgs e) { - if (e.ColumnIndex == 2) - dgSegments.EndEdit(); - } private void menuOpenFile_Click(object sender, EventArgs e) { openFileDialogOpened = true; @@ -697,8 +539,6 @@ namespace DxPlay { } - private void OnToggleSegmentEditor(object sender, EventArgs e) { - } } } diff --git a/client/DxPlay/PlayerForm.resx b/client/DxPlay/PlayerForm.resx index 4748e2a2..3a82e29c 100644 --- a/client/DxPlay/PlayerForm.resx +++ b/client/DxPlay/PlayerForm.resx @@ -173,7 +173,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABo - CAAAAk1TRnQBSQFMAgEBAgEAAZABAQGQAQEBGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAgEAAZgBAQGYAQEBGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABYAMAARgDAAEBAQABCAYAAQkYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/client/DxPlay/PlayerFormSegments.cs b/client/DxPlay/PlayerFormSegments.cs new file mode 100644 index 00000000..cd43b033 --- /dev/null +++ b/client/DxPlay/PlayerFormSegments.cs @@ -0,0 +1,188 @@ +using DxPlay.Properties; +using MaestroShared.Commons; +using MaestroShared.Metadata; +using System; +using System.Linq; +using System.Windows.Forms; + +namespace DxPlay { + public partial class PlayerForm : Form { + + private void OnDefineOneSegmentClick(object sender, EventArgs e) { + if (m_play == null) + return; + MovieSegment segment = null; + if (model.Segments.Count == 0) { + segment = new MovieSegment() { + TCIn = new Timecode(m_mediaDescription.FirstFrame.Frames), + TCOut = new Timecode(m_mediaDescription.FirstFrame, m_mediaDescription.Duration) + }; + } else { + MovieSegment lastSegment = model.Segments[model.Segments.Count - 1]; + Timecode tcEnd = new Timecode(m_mediaDescription.FirstFrame, m_mediaDescription.Duration); + if (lastSegment.TCOut.Frames == tcEnd.Frames) { + MsgBox.Error(Settings.Resource("ERRORCREATESEGMENT", Resources.ERRORCREATESEGMENT)); + return; + } + segment = new MovieSegment() { + TCIn = new Timecode(lastSegment.TCOut.Frames), + TCOut = tcEnd + }; + } + model.Segments.Add(segment); + } + + private void OnDeleteSegmentClick(object sender, EventArgs e) { + if (bsSegments.Current != null) + model.Segments.Remove(bsSegments.Current as MovieSegment); + } + + private void SetActualPositionAsIn() { + if (m_play == null) + return; + MovieSegment currentSegment = bsSegments.Current as MovieSegment; + if (currentSegment == null || bsSegments.Count == 0) { + MovieSegment newSegment = new MovieSegment() { + TCIn = new Timecode(m_play.CurrentTC.Frames), + TCOut = new Timecode(m_play.MediaDescription.FirstFrame.Frames + m_play.MediaDescription.Duration.Frames) + }; + bsSegments.Position = bsSegments.Add(newSegment); + } else { + if (currentSegment.TCOut.Frames < m_play.CurrentTC.Frames) { + int pos = bsSegments.IndexOf(currentSegment); + if (pos == bsSegments.Count - 1) { + MovieSegment newSegment = new MovieSegment() { + TCIn = new Timecode(m_play.CurrentTC.Frames), + TCOut = new Timecode(m_play.MediaDescription.FirstFrame.Frames + m_play.MediaDescription.Duration.Frames) + }; + bsSegments.Position = bsSegments.Add(newSegment); + return; + } + MsgBox.Error(Settings.Resource("ERRORINVALIDTCIN", Resources.ERRORINVALIDTCIN)); + return; + } + //if (MessageBox.Show("Biztos felül akarja írni az belépőt?", "Belépő felülírása", MessageBoxButtons.YesNo) == DialogResult.No) + // return; + MovieSegment collisionSegment = model.Segments.Where(s => s.TCIn.Frames < m_play.CurrentTC.Frames && m_play.CurrentTC.Frames <= s.TCOut.Frames).SingleOrDefault(); + + if (collisionSegment != null && !currentSegment.Equals(collisionSegment)) { + MsgBox.Error(Settings.Resource("ERRORSEGMENTCOLLISION", Resources.ERRORSEGMENTCOLLISION)); + return; + } + + currentSegment.TCIn = new Timecode(m_play.CurrentTC.Frames); + } + } + + + private void SetActualPositionAsOut() { + if (m_play == null) + return; + MovieSegment currentSegment = bsSegments.Current as MovieSegment; + if (currentSegment == null || bsSegments.Count == 0) { + MovieSegment newSegment = new MovieSegment() { + TCIn = new Timecode(m_play.MediaDescription.FirstFrame.Frames), + TCOut = new Timecode(m_play.CurrentTC.Frames), + }; + bsSegments.Position = bsSegments.Add(newSegment); + } else { + if (currentSegment.TCIn.Frames >= m_play.CurrentTC.Frames) + MsgBox.Error(Settings.Resource("ERRORINVALIDTCOUT", Resources.ERRORINVALIDTCOUT)); + + MovieSegment collisionSegment = model.Segments.Where(s => s.TCIn.Frames < m_play.CurrentTC.Frames && m_play.CurrentTC.Frames <= s.TCOut.Frames).SingleOrDefault(); + + if (collisionSegment != null && !currentSegment.Equals(collisionSegment)) { + MsgBox.Error(Settings.Resource("ERRORSEGMENTCOLLISION", Resources.ERRORSEGMENTCOLLISION)); + return; + } + + //if (MessageBox.Show("Biztos felül akarja írni az kilépőt?", "Kilépő felülírása", MessageBoxButtons.YesNo) == DialogResult.No) + // return; + currentSegment.TCOut = new Timecode(m_play.CurrentTC.Frames); + } + } + + private void OnActualPositionToTCInToolStripMenuItem1Click(object sender, EventArgs e) { + SetActualPositionAsIn(); + } + + private void OnActualPositionToTCOutToolStripMenuItem1Click(object sender, EventArgs e) { + SetActualPositionAsOut(); + } + + private void OnSplitSegmentAtCurrentPositionClick(object sender, EventArgs e) { + MovieSegment currentSegment = model.Segments.Where(s => s.TCIn.Frames <= m_play.CurrentTC.Frames && s.TCOut.Frames >= m_play.CurrentTC.Frames).SingleOrDefault(); + if (currentSegment == null) + return; + int position = model.Segments.IndexOf(currentSegment); + MovieSegment newSegment = new MovieSegment() { + TCIn = new Timecode(currentSegment.TCIn.Frames), + TCOut = new Timecode(m_play.CurrentTC.Frames - 1) + }; + currentSegment.TCIn = new Timecode(m_play.CurrentTC.Frames); + model.Segments.Insert(position, newSegment); + } + + private void dgSegments_ColumnAdded(object sender, DataGridViewColumnEventArgs e) { + int index = e.Column.Index; + switch (index) { + case 0: + e.Column.HeaderText = Settings.Resource("TCIN", Resources.TCIN); + e.Column.ReadOnly = true; + break; + case 1: + e.Column.HeaderText = Settings.Resource("TCOUT", Resources.TCOUT); + e.Column.ReadOnly = true; + break; + case 2: + e.Column.HeaderText = Settings.Resource("OPTIONAL", Resources.OPTIONAL); + break; + case 3: + e.Column.HeaderText = Settings.Resource("COMMENT", Resources.COMMENT); + break; + } + } + + + private void dgSegments_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { + MovieSegment actualSegment = bsSegments.Current as MovieSegment; + if (actualSegment == null || m_play == null) + return; + if (e.ColumnIndex == 0) { + m_play.Pause(); + m_play.Seek(actualSegment.TCIn.Frames - m_play.MediaDescription.FirstFrame.Frames); + } + if (e.ColumnIndex == 1) { + m_play.Pause(); + int pos = actualSegment.TCOut.Frames - m_play.MediaDescription.FirstFrame.Frames; + //Az utolsó kocka nem jelenik meg egyébként + try { + if (pos == m_play.MediaDescription.Duration.Frames) { + pos--; + m_play.Seek(pos); + m_play.Play(); + } else + m_play.Seek(pos); + } catch (Exception ex) { + MsgBox.Error(ex.Message); + } + + } + + } + + private void dgSegments_CellContentClick(object sender, DataGridViewCellEventArgs e) { + if (e.ColumnIndex == 2) + dgSegments.EndEdit(); + } + + private void OnSegmentEditorMouseClick(object sender, MouseEventArgs e) { + var ht = dgSegments.HitTest(e.X, e.Y); + + if (ht.Type == DataGridViewHitTestType.None) { + dgSegments.ClearSelection(); + } + } + + } +} diff --git a/client/DxPlay/Program.cs b/client/DxPlay/Program.cs index 67c37c12..dc06f22d 100644 --- a/client/DxPlay/Program.cs +++ b/client/DxPlay/Program.cs @@ -32,7 +32,7 @@ namespace Maestro { if (dxPlayConfig.Exists) { Type[] knownTypes = { typeof(TrafficMetadata) }; var settings = ConfigurationSerializer.Load(dxPlayConfig.FullName, knownTypes); - settings.IsStandalone = true; + //settings.IsStandalone = true; playerForm.Settings = settings; if (settings.IsMaximized) playerForm.WindowState = FormWindowState.Maximized; diff --git a/client/Maestro/Program.cs b/client/Maestro/Program.cs index bd05c20b..907f2637 100644 --- a/client/Maestro/Program.cs +++ b/client/Maestro/Program.cs @@ -2,13 +2,10 @@ using LinkDotNet.MessageHandling.Contracts; using Maestro.Properties; using MaestroShared.Configuration; -using MediaCubeClient; -using Newtonsoft.Json.Linq; using NLog; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; using System.DirectoryServices.AccountManagement; using System.IO; using System.Linq; @@ -32,7 +29,7 @@ namespace Maestro { [STAThread] [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)] static void Main() { - + /* IMessageBus mb = new MessageBus(); mb.Subscribe(m => { if (m.Finished) { @@ -49,7 +46,7 @@ namespace Maestro { c.SubmitJob("fake.xml", data); Thread.Sleep(1000000); return; - + */ string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString(); string userName = WindowsIdentity.GetCurrent().Name;