@@ -784,7 +784,7 @@ void DMD::ZeDMDThread()
784784 if (m_pUpdateBufferQueue[bufferPositionMod]->width != width ||
785785 m_pUpdateBufferQueue[bufferPositionMod]->height != height)
786786 {
787- Log (DMDUtil_LogLevel_INFO, " Change frame size from %dx%d to %dx%d" , width, height,
787+ Log (DMDUtil_LogLevel_INFO, " ZeDMD: Change frame size from %dx%d to %dx%d" , width, height,
788788 m_pUpdateBufferQueue[bufferPositionMod]->width , m_pUpdateBufferQueue[bufferPositionMod]->height );
789789 width = m_pUpdateBufferQueue[bufferPositionMod]->width ;
790790 height = m_pUpdateBufferQueue[bufferPositionMod]->height ;
@@ -793,6 +793,8 @@ void DMD::ZeDMDThread()
793793 m_pZeDMD->SetFrameSize (width, height);
794794 }
795795
796+ Log (DMDUtil_LogLevel_DEBUG, " ZeDMD: Render frame buffer position %d at real buffer postion %d" , bufferPosition, bufferPositionMod);
797+
796798 bool update = false ;
797799 if (m_pUpdateBufferQueue[bufferPositionMod]->depth != 24 )
798800 {
@@ -903,15 +905,17 @@ void DMD::SerumThread()
903905
904906 while (true )
905907 {
906- if (nextRotation == 0 && sceneCurrentFrame >= sceneFrameCount )
908+ if (m_stopFlag. load (std::memory_order_acquire) )
907909 {
908- std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
909- m_dmdCV.wait (
910- sl, [&]()
911- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
912- sl.unlock ();
910+ if (m_pSerum)
911+ {
912+ Serum_Dispose ();
913+ }
914+
915+ return ;
913916 }
914- else
917+
918+ if (m_pSerum && nextRotation == 0 && sceneCurrentFrame >= sceneFrameCount)
915919 {
916920 uint16_t sceneId = m_pupSceneId.load (std::memory_order_relaxed);
917921 if (sceneId > 0 )
@@ -930,27 +934,22 @@ void DMD::SerumThread()
930934 // Reset the trigger after processing
931935 m_pupSceneId.store (0 , std::memory_order_release);
932936 }
933- else
934- {
935- std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
936- }
937937 }
938938
939- if (m_stopFlag. load (std::memory_order_acquire) )
939+ if (nextRotation == 0 && sceneCurrentFrame >= sceneFrameCount )
940940 {
941- if (m_pSerum)
942- {
943- Serum_Dispose ();
944- }
945-
946- return ;
941+ std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
942+ m_dmdCV.wait (
943+ sl, [&]()
944+ { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
945+ sl.unlock ();
947946 }
948947
949948 uint32_t now =
950949 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now ().time_since_epoch ())
951950 .count ();
952951
953- if (!m_stopFlag. load (std::memory_order_relaxed) && sceneCurrentFrame < sceneFrameCount && nextSceneFrame <= now)
952+ if (m_pSerum && sceneCurrentFrame < sceneFrameCount && nextSceneFrame <= now)
954953 {
955954 Update* sceneUpdate = new Update ();
956955 if (m_pGenerator->generateFrame (prevTriggerId, sceneCurrentFrame++, sceneUpdate->data ))
@@ -959,7 +958,7 @@ void DMD::SerumThread()
959958
960959 if (result != IDENTIFY_NO_FRAME)
961960 {
962- Log (DMDUtil_LogLevel_DEBUG, " Got PUP scene %d, frame %d colorized" , prevTriggerId, sceneCurrentFrame - 1 );
961+ Log (DMDUtil_LogLevel_DEBUG, " Serum: Got PUP scene %d, frame %d colorized" , prevTriggerId, sceneCurrentFrame - 1 );
963962 sceneUpdate->depth = m_pGenerator->getDepth ();
964963 sceneUpdate->hasData = true ;
965964 QueueSerumFrames (sceneUpdate, flags & FLAG_REQUEST_32P_FRAMES, flags & FLAG_REQUEST_64P_FRAMES);
@@ -1010,7 +1009,7 @@ void DMD::SerumThread()
10101009 }
10111010
10121011 const uint16_t updateBufferQueuePosition = m_updateBufferQueuePosition.load (std::memory_order_acquire);
1013- while (!m_stopFlag. load (std::memory_order_relaxed) && bufferPosition != updateBufferQueuePosition)
1012+ while (bufferPosition != updateBufferQueuePosition)
10141013 {
10151014 // Don't use GetNextBufferPosition() here, we need all frames for PUP triggers!
10161015 ++bufferPosition; // 65635 + 1 = 0
@@ -1028,7 +1027,7 @@ void DMD::SerumThread()
10281027 continue ;
10291028 }
10301029
1031- if (sceneCurrentFrame < sceneFrameCount && !sceneInterruptable) continue ;
1030+ if (m_pSerum && sceneCurrentFrame < sceneFrameCount && !sceneInterruptable) continue ;
10321031
10331032 if (m_pUpdateBufferQueue[bufferPositionMod]->mode == Mode::Data)
10341033 {
@@ -1047,8 +1046,8 @@ void DMD::SerumThread()
10471046
10481047 if (m_altColorPath[0 ] == ' \0 ' ) strcpy (m_altColorPath, Config::GetInstance ()->GetAltColorPath ());
10491048 flags = 0 ;
1050- // At the moment, ZeDMD HD and RGB24DMD are the only devices supporting 64P frames. Not requesting 64P saves
1051- // memory.
1049+ // At the moment, ZeDMD HD and RGB24DMD are the only devices supporting 64P frames. Not requesting 64P
1050+ // saves memory.
10521051 if (m_pZeDMD)
10531052 {
10541053 if (m_pZeDMD->GetWidth () == 256 )
@@ -1077,7 +1076,7 @@ void DMD::SerumThread()
10771076 m_pSerum = (name[0 ] != ' \0 ' ) ? Serum_Load (m_altColorPath, m_romName, flags) : nullptr ;
10781077 if (m_pSerum)
10791078 {
1080- Log (DMDUtil_LogLevel_INFO, " Loaded Serum v%d colorization for %s" , m_pSerum->SerumVersion , m_romName);
1079+ Log (DMDUtil_LogLevel_INFO, " Serum: Loaded v%d colorization for %s" , m_pSerum->SerumVersion , m_romName);
10811080
10821081 Serum_SetIgnoreUnknownFramesTimeout (Config::GetInstance ()->GetIgnoreUnknownFramesTimeout ());
10831082 Serum_SetMaximumUnknownFramesToSkip (Config::GetInstance ()->GetMaximumUnknownFramesToSkip ());
@@ -1090,12 +1089,12 @@ void DMD::SerumThread()
10901089 {
10911090 snprintf (csvPath, sizeof (csvPath), " %s/%s/%s.pup.csv" , m_altColorPath, m_romName, m_romName);
10921091 }
1093- Log (DMDUtil_LogLevel_INFO, " Check for PUP scenes for %s at %s" , m_romName, csvPath);
1092+ Log (DMDUtil_LogLevel_INFO, " Serum: Check for PUP scenes for %s at %s" , m_romName, csvPath);
10941093
10951094 if (m_pGenerator->parseCSV (csvPath))
10961095 {
10971096 m_pGenerator->setDepth (m_pUpdateBufferQueue[bufferPositionMod]->depth );
1098- Log (DMDUtil_LogLevel_INFO, " Loaded PUP scenes for %s, bit depth %d" , m_romName,
1097+ Log (DMDUtil_LogLevel_INFO, " Serum: Loaded PUP scenes for %s, bit depth %d" , m_romName,
10991098 m_pUpdateBufferQueue[bufferPositionMod]->depth );
11001099 }
11011100 }
@@ -1172,27 +1171,29 @@ void DMD::SerumThread()
11721171 }
11731172 }
11741173
1175- if (sceneCurrentFrame < sceneFrameCount )
1174+ if (m_pSerum )
11761175 {
1177- nextRotation = 0 ;
1178- continue ;
1179- }
1176+ if (sceneCurrentFrame < sceneFrameCount)
1177+ {
1178+ nextRotation = 0 ;
1179+ continue ;
1180+ }
11801181
1181- if (!m_stopFlag.load (std::memory_order_acquire) && m_pSerum && nextRotation > 0 && m_pSerum->rotationtimer > 0 &&
1182- lastDmdUpdate && now > nextRotation)
1183- {
1184- uint32_t result = Serum_Rotate ();
1182+ if (nextRotation > 0 && m_pSerum->rotationtimer > 0 && lastDmdUpdate && now > nextRotation)
1183+ {
1184+ uint32_t result = Serum_Rotate ();
11851185
1186- // Log(DMDUtil_LogLevel_DEBUG, "Serum: rotation=%lu, flags=%lu", m_pSerum->rotationtimer, result >> 16);
1186+ // Log(DMDUtil_LogLevel_DEBUG, "Serum: rotation=%lu, flags=%lu", m_pSerum->rotationtimer, result >> 16);
11871187
1188- QueueSerumFrames (lastDmdUpdate, result & 0x10000 , result & 0x20000 );
1188+ QueueSerumFrames (lastDmdUpdate, result & 0x10000 , result & 0x20000 );
11891189
1190- if (result > 0 && ((result & 0xffff ) < 2048 ))
1191- {
1192- nextRotation = now + m_pSerum->rotationtimer ;
1190+ if (result > 0 && ((result & 0xffff ) < 2048 ))
1191+ {
1192+ nextRotation = now + m_pSerum->rotationtimer ;
1193+ }
1194+ else
1195+ nextRotation = 0 ;
11931196 }
1194- else
1195- nextRotation = 0 ;
11961197 }
11971198 }
11981199 }
0 commit comments