Fix video recorder not working if sound disabled (fixes bug 200)
authorWuzzy <Wuzzy2@mail.ru>
Tue, 17 Jul 2018 12:17:11 +0200
changeset 13492 c7df0d96da81
parent 13491 f725701ca529
child 13493 3bb07c847886
Fix video recorder not working if sound disabled (fixes bug #200)
ChangeLog.txt
QTfrontend/net/recorder.cpp
hedgewars/uVideoRec.pas
--- a/ChangeLog.txt	Mon Jul 16 23:27:15 2018 +0200
+++ b/ChangeLog.txt	Tue Jul 17 12:17:11 2018 +0200
@@ -4,8 +4,10 @@
 Game:
  + Add new key to show mission panel (default: M)
  + Add chat command “/help”, displays help for chat commands
+ * Fix crash when 2 or more controllers were connected
  * Fix extreme amounts of droplets when shooting with minigun into ocean world edge
  * Fix hog being unable to walk after using sniper rifle without firing both shots
+ * Fix video recorder not working when game audio was disabled
  * Fix teleport tooltip claiming it doesn't end turn in hog placing phase with inf. attack
 
 Highlander:
--- a/QTfrontend/net/recorder.cpp	Mon Jul 16 23:27:15 2018 +0200
+++ b/QTfrontend/net/recorder.cpp	Tue Jul 17 12:17:11 2018 +0200
@@ -140,7 +140,10 @@
 // Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both.
 // The library does support using both at once after all.
     arguments << QString::number(config->rec_Bitrate()*1024);
-    arguments << (config->recordAudio() ? config->audioCodec() : "no");
+    if (config->recordAudio() && (config->isSoundEnabled() || config->isMusicEnabled()))
+        arguments << config->audioCodec();
+    else
+        arguments << "no";
 
     return arguments;
 }
--- a/hedgewars/uVideoRec.pas	Mon Jul 16 23:27:15 2018 +0200
+++ b/hedgewars/uVideoRec.pas	Tue Jul 17 12:17:11 2018 +0200
@@ -73,7 +73,8 @@
     numPixels: LongWord;
     startTime, numFrames, curTime, progress, maxProgress: LongWord;
     soundFilePath: shortstring;
-    thumbnailSaved : Boolean;
+    thumbnailSaved: boolean;
+    recordAudio: boolean;
 
 function BeginVideoRecording: Boolean;
 var filename, desc: shortstring;
@@ -113,7 +114,12 @@
     desc:= desc + 'prefix[' + RecPrefix + ']prefix';
 
     filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix;
-    soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
+
+    recordAudio:= (cAudioCodec <> 'no');
+    if recordAudio then
+        soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'
+    else
+        soundFilePath:= '';
 
     if checkFails(AVWrapper_Init(@AddFileLogRaw
         , PChar(ansistring(filename))
@@ -149,7 +155,8 @@
     if AVWrapper_Close() < 0 then
         halt(-1);
     Erase(cameraFile);
-    DeleteFile(soundFilePath);
+    if recordAudio then
+        DeleteFile(soundFilePath);
     SendIPC(_S'v'); // inform frontend that we finished
 end;
 
@@ -268,43 +275,49 @@
         CopyFile(recordFileName, UserPathPrefix + '/VideoTemp/' + RecPrefix + '.hwd');
     end;
 
-    Mix_QuerySpec(@frequency, @format, @channels);
-    AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
-    if format <> $8010 then
-    begin
-        // TODO: support any audio format
-        AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
-        exit;
-    end;
+    if cIsSoundEnabled then
+        begin
+        Mix_QuerySpec(@frequency, @format, @channels);
+        AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
+        if format <> $8010 then
+            begin
+            // TODO: support any audio format
+            AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
+            exit;
+            end;
 
 {$IOCHECKS OFF}
-    // create sound file
-    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
-    Assign(audioFile, filename);
-    Rewrite(audioFile, 1);
-    if IOResult <> 0 then
-    begin
-        AddFileLog('Error: Could not write to ' + filename);
-        exit;
-    end;
+        // create sound file
+        filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
+        Assign(audioFile, filename);
+        Rewrite(audioFile, 1);
+        if IOResult <> 0 then
+            begin
+            AddFileLog('Error: Could not write to ' + filename);
+            exit;
+            end;
+        end;
 
     // create file with camera positions
     filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtout';
     Assign(cameraFile, filename);
     Rewrite(cameraFile);
     if IOResult <> 0 then
-    begin
+        begin
         AddFileLog('Error: Could not write to ' + filename);
         exit;
-    end;
+        end;
 
-    // save audio parameters in sound file
-    BlockWrite(audioFile, frequency, 4);
-    BlockWrite(audioFile, channels, 4);
+    if cIsSoundEnabled then
+        begin
+        // save audio parameters in sound file
+        BlockWrite(audioFile, frequency, 4);
+        BlockWrite(audioFile, channels, 4);
 {$IOCHECKS ON}
 
-    // register callback for actual audio recording
-    Mix_SetPostMix(@RecordPostMix, nil);
+        // register callback for actual audio recording
+        Mix_SetPostMix(@RecordPostMix, nil);
+        end;
 
     startTime:= SDL_GetTicks();
     flagPrerecording:= true;
@@ -315,12 +328,18 @@
     AddFileLog('StopPreRecording');
     flagPrerecording:= false;
 
-    // call SDL_LockAudio because RecordPostMix may be executing right now
-    SDL_LockAudio();
-    Close(audioFile);
+    if cIsSoundEnabled then
+        begin
+        // call SDL_LockAudio because RecordPostMix may be executing right now
+        SDL_LockAudio();
+        Close(audioFile);
+        end
     Close(cameraFile);
-    Mix_SetPostMix(nil, nil);
-    SDL_UnlockAudio();
+    if cIsSoundEnabled then
+        begin
+        Mix_SetPostMix(nil, nil);
+        SDL_UnlockAudio();
+        end;
 
     if not thumbnailSaved then
         SaveThumbnail();