@@ -709,8 +709,25 @@ MLDX12App::ImGuiCommands(void)
709709{
710710 ImGui::Begin (" Settings" );
711711
712- ImGui::Text (" Average redraw frames per second : %.1f" , ImGui::GetIO ().Framerate );
712+ if (ImGui::BeginPopupModal (" ErrorPopup" , NULL , ImGuiWindowFlags_AlwaysAutoResize)) {
713+ ImGui::Text (m_msg);
714+ if (ImGui::Button (" OK" , ImVec2 (120 , 0 ))) {
715+ ImGui::CloseCurrentPopup ();
716+ m_msg[0 ] = 0 ;
717+ }
718+ ImGui::EndPopup ();
719+ }
713720
721+ if (ImGui::BeginPopupModal (" WriteFlushPopup" , NULL , ImGuiWindowFlags_AlwaysAutoResize)) {
722+ ImGui::Text (m_msg);
723+
724+ if (m_state != S_WaitRecordEnd) {
725+ ImGui::CloseCurrentPopup ();
726+ }
727+ ImGui::EndPopup ();
728+ }
729+
730+ ImGui::Text (" Average redraw frames per second : %.1f" , ImGui::GetIO ().Framerate );
714731 ImGui::Text (" ALT+Enter to toggle fullscreen." );
715732
716733 static int selectedDeviceIdx = 0 ;
@@ -733,78 +750,95 @@ MLDX12App::ImGuiCommands(void)
733750 m_videoCapture.SetCallback (this );
734751 bool brv = m_videoCapture.StartCapture (0 );
735752 if (brv) {
736- m_state = S_Capturing;
753+ m_state = S_Previewing;
754+ }
755+ }
756+ break ;
757+ case S_WaitRecordEnd:
758+ {
759+ sprintf_s (m_msg, " Now Writing AVI...\n Remaining %d frames." , m_aviWriter.RecQueueSize ());
760+ m_mutex.lock ();
761+ bool bEnd = m_aviWriter.PollThreadEnd ();
762+ m_mutex.unlock ();
763+ if (bEnd) {
764+ m_state = S_Previewing;
737765 }
738766 }
739767 break ;
740768 case S_Recording:
741- case S_Capturing :
769+ case S_Previewing :
742770 {
743771 int queueSize = 0 ;
772+ m_mutex.lock ();
773+ if (!m_capturedImages.empty ()) {
774+ queueSize = (int )m_capturedImages.size ();
775+ auto & front = m_capturedImages.front ();
776+ ImGui::Text (front.imgFormat .c_str ());
777+ } else {
778+ ImGui::Text (" " );
779+ }
780+ m_mutex.unlock ();
744781
745- if (m_state == S_Capturing) {
746- ImGui::Text (" Now Capturing..." );
747- BMDTimeScale ts = m_videoCapture.FrameRateTS ();
748- BMDTimeValue tv = m_videoCapture.FrameRateTV ();
749- ImGui::Text (" Frame rate : %llu %llu" , (uint64_t )ts, (uint64_t )tv);
782+ BMDTimeScale ts = m_videoCapture.FrameRateTS ();
783+ BMDTimeValue tv = m_videoCapture.FrameRateTV ();
784+ ImGui::Text (" Frame rate : %.1f" , (double )ts / tv);
750785
786+ ImGui::Separator ();
787+
788+ if (m_state == S_Previewing) {
789+ ImGui::Text (" Now Previewing..." );
751790 BMDPixelFormat pixFmt = m_videoCapture.PixelFormat ();
752791 if (bmdFormat10BitYUV == pixFmt) {
753792 ImGui::InputText (" Record filename" , m_writePath, sizeof m_writePath - 1 );
754- ImGui::Text (m_msg);
755- if (ImGui::Button (" Record" )) {
793+ if (ImGui::Button (" Record" , ImVec2 (256 , 64 ))) {
756794 wchar_t path[512 ];
757795 memset (path, 0 , sizeof path);
758796 MultiByteToWideChar (CP_UTF8, 0 , m_writePath, sizeof m_writePath, path, 511 );
759797
760- bool bRv = m_aviWriter.Init (path, m_videoCapture.Width (),
798+ bool bRv = m_aviWriter.Start (path, m_videoCapture.Width (),
761799 m_videoCapture.Height (), (int )(ts / 1000 ),
762800 MLAviWriter::IF_YUV422v210);
763801 if (bRv) {
764802 m_state = S_Recording;
765803 m_msg[0 ] = 0 ;
766804 } else {
767- sprintf_s (m_msg, " File open error : %s" , m_writePath);
805+ sprintf_s (m_msg, " Record Failed.\n File open error : %s" , m_writePath);
806+ ImGui::OpenPopup (" ErrorPopup" );
768807 }
769808 }
770809 }
771- }
772810
773- m_mutex.lock ();
774- if (!m_capturedImages.empty ()) {
775- queueSize = (int )m_capturedImages.size ();
776- auto & front = m_capturedImages.front ();
777- ImGui::Text (front.imgFormat .c_str ());
778- } else {
779- ImGui::Text (" " );
780- }
781- m_mutex.unlock ();
782-
783- ImGui::Text (" Draw Queue size : %d" , queueSize);
784- ImGui::Text (" Frame skip count : %lld" , m_frameSkipCount);
785-
786- if (m_state == S_Recording) {
787- ImGui::Text (" Now Recording..." );
788- ImGui::Text (" Rec Queue size : %d" , m_aviWriter.RecQueueSize ());
789- if (ImGui::Button (" Stop Recording" )) {
790- m_state = S_Capturing;
791-
792- m_mutex.lock ();
793- m_aviWriter.Term ();
794- m_mutex.unlock ();
795- }
796- } else {
797811 if (ImGui::Button (" Stop Capture" )) {
798-
812+
799813 m_videoCapture.StopCapture ();
800814 m_videoCapture.Term ();
801-
815+
802816 m_videoCaptureDeviceList.Term ();
803817 m_videoCaptureDeviceList.Init ();
804818
805819 m_state = S_Init;
806820 }
821+ } else if (m_state == S_Recording) {
822+ ImGui::Text (" Now Recording..." );
823+ ImGui::Text (" Record filename : %s" , m_writePath);
824+ if (ImGui::Button (" Stop Recording" , ImVec2 (256 , 64 ))) {
825+ m_state = S_WaitRecordEnd;
826+
827+ m_mutex.lock ();
828+ m_aviWriter.StopAsync ();
829+ m_mutex.unlock ();
830+
831+ ImGui::OpenPopup (" WriteFlushPopup" );
832+ }
833+
834+ ImGui::Text (" Rec Queue size : %d" , m_aviWriter.RecQueueSize ());
835+ }
836+
837+ ImGui::Text (" Draw Queue size : %d" , queueSize);
838+ if (ImGui::Button (" Clear Draw Queue" )) {
839+ ClearDrawQueue ();
807840 }
841+ ImGui::Text (" Frame Draw skip count : %lld" , m_frameSkipCount);
808842
809843 ImGui::BeginGroup ();
810844 if (ImGui::RadioButton (" Center Crosshair" , m_crosshairType == CH_CenterCrosshair)) {
@@ -815,7 +849,7 @@ MLDX12App::ImGuiCommands(void)
815849 m_crosshairType = CH_4Crosshairs;
816850 }
817851 ImGui::SameLine ();
818- if (ImGui::RadioButton (" None " , m_crosshairType == CH_None)) {
852+ if (ImGui::RadioButton (" CHNone " , m_crosshairType == CH_None)) {
819853 m_crosshairType = CH_None;
820854 }
821855 ImGui::EndGroup ();
@@ -831,7 +865,7 @@ MLDX12App::ImGuiCommands(void)
831865 m_gridType = GR_6x6;
832866 }
833867 ImGui::SameLine ();
834- if (ImGui::RadioButton (" None " , m_gridType == GR_None)) {
868+ if (ImGui::RadioButton (" GRNone " , m_gridType == GR_None)) {
835869 m_gridType = GR_None;
836870 }
837871 ImGui::EndGroup ();
@@ -982,6 +1016,18 @@ MLDX12App::MLVideoCaptureCallback_VideoInputFrameArrived(IDeckLinkVideoInputFram
9821016 m_mutex.unlock ();
9831017}
9841018
1019+ void MLDX12App::ClearDrawQueue (void )
1020+ {
1021+ m_mutex.lock ();
1022+ for (auto ite = m_capturedImages.begin (); ite != m_capturedImages.end (); ++ite) {
1023+ CapturedImage &ci = *ite;
1024+ delete [] ci.data ;
1025+ ci.data = nullptr ;
1026+ }
1027+ m_capturedImages.clear ();
1028+ m_mutex.unlock ();
1029+ }
1030+
9851031void
9861032MLDX12App::UpdateVideoTexture (void ) {
9871033 m_mutex.lock ();
0 commit comments