Skip to content

Commit ea0a391

Browse files
committed
Added debug logging
1 parent a7361ec commit ea0a391

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

Source/AudioCapture.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Celeste.Mod.TASRecorder.Util;
12
using FMOD;
23
using System;
34
using System.Runtime.InteropServices;
@@ -83,6 +84,7 @@ private static unsafe RESULT CaptureCallback(ref DSP_STATE dspState, IntPtr inBu
8384
}
8485
}
8586
}
87+
Log.Debug($"Capturing {samples} samples");
8688

8789
// Block until the management thread allows capturing more (also blocks the main FMOD thread which is good, since it avoid artifacts)
8890
while (TASRecorderModule.Recording && !allowCapture) { }
@@ -106,6 +108,7 @@ private static unsafe RESULT CaptureCallback(ref DSP_STATE dspState, IntPtr inBu
106108
}
107109

108110
private static void CaptureThread() {
111+
Log.Debug("Starting audio capture thread");
109112
totalRecodedSamplesError = 0;
110113
batchesToIgnore = 5;
111114

@@ -117,18 +120,22 @@ private static void CaptureThread() {
117120

118121
// Skip a frame to let the video catch up again
119122
if (totalRecodedSamplesError >= targetRecordedSamples) {
123+
Log.Debug("Skipping audio frame to allow video to catch up");
120124
totalRecodedSamplesError -= targetRecordedSamples;
121125
continue;
122126
}
123127

124128
// Capture at least a frame of data on the FMOD/DSP thread
129+
Log.Debug("Starting audio capture");
125130
allowCapture = true;
126131
while (runThread && recordedSamples < targetRecordedSamples) { }
127132
allowCapture = false;
133+
Log.Debug("Stopping audio capture");
128134

129135
// Accumulate the data overhead
130136
totalRecodedSamplesError += recordedSamples - targetRecordedSamples;
131137
recordedSamples = 0;
132138
}
139+
Log.Debug("Stopped audio capture thread");
133140
}
134141
}

Source/Encoder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public void RefreshSettings() {
131131
}
132132

133133
public void PrepareVideo(int width, int height) {
134+
Log.Debug($"Preparing video at {width}x{height}...");
134135
ref var outStream = ref VideoStream;
135136
var ctx = outStream.CodecCtx;
136137

@@ -151,8 +152,10 @@ public void PrepareVideo(int width, int height) {
151152
}
152153

153154
VideoData = outStream.InFrame->data[0];
155+
Log.Debug("Prepared video");
154156
}
155157
public void PrepareAudio(uint channelCount, uint sampleCount) {
158+
Log.Debug($"Preparing audio at {channelCount} channels and {sampleCount} samples...");
156159
AudioDataSize = Math.Max(channelCount, AUDIO_CHANNEL_COUNT) * sampleCount * (uint) Marshal.SizeOf<float>();
157160
AudioDataSamples = sampleCount;
158161
AudioDataChannels = channelCount;
@@ -161,9 +164,11 @@ public void PrepareAudio(uint channelCount, uint sampleCount) {
161164
AudioDataBufferSize = AudioDataSize * 2; // Avoid having to reallocate soon
162165
AudioData = (byte*) NativeMemory.Realloc(AudioData, AudioDataBufferSize);
163166
}
167+
Log.Debug("Prepared audio");
164168
}
165169

166170
public void FinishVideo() {
171+
Log.Debug("Finishing video...");
167172
ref var outStream = ref VideoStream;
168173
var ctx = outStream.CodecCtx;
169174

@@ -177,6 +182,7 @@ public void FinishVideo() {
177182
outStream.OutFrame->pts = outStream.VideoPTS;
178183

179184
WriteFrame(ref outStream, outStream.OutFrame);
185+
Log.Debug("Finished video");
180186
}
181187
public void FinishAudio() {
182188
ref var outStream = ref AudioStream;
@@ -211,6 +217,7 @@ public void FinishAudio() {
211217
WriteFrame(ref outStream, outStream.OutFrame);
212218
}
213219
}
220+
Log.Debug("Finished audio");
214221
}
215222

216223
private void AddStream(AVCodec* codec, ref OutputStream outStream, AVCodecID codecID) {

Source/FFmpegLoader.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,24 @@ private static Task Validate() => Task.Run(() => {
132132
// First, check for system libraries.
133133
Log.Debug("Attempting to load system FFmpeg libraries...");
134134
try {
135+
Log.Debug($"Loading {GetOSLibraryName("avutil")}");
135136
AvutilLibrary = NativeLibrary.Load(GetOSLibraryName("avutil"));
137+
Log.Debug($"Loading {GetOSLibraryName("avformat")}");
136138
AvformatLibrary = NativeLibrary.Load(GetOSLibraryName("avformat"));
139+
Log.Debug($"Loading {GetOSLibraryName("avcodec")}");
137140
AvcodecLibrary = NativeLibrary.Load(GetOSLibraryName("avcodec"));
141+
Log.Debug($"Loading {GetOSLibraryName("swresample")}");
138142
SwresampleLibrary = NativeLibrary.Load(GetOSLibraryName("swresample"));
143+
Log.Debug($"Loading {GetOSLibraryName("swscale")}");
139144
SwscaleLibrary = NativeLibrary.Load(GetOSLibraryName("swscale"));
140145

141-
Log.Debug("Successfully loaded system FFmpeg libraries.");
146+
Log.Debug($"avutil: {GetVersionString(avutil_version())}");
147+
Log.Debug($"avformat: {GetVersionString(avformat_version())}");
148+
Log.Debug($"avcodec: {GetVersionString(avcodec_version())}");
149+
Log.Debug($"swresample: {GetVersionString(swresample_version())}");
150+
Log.Debug($"swscale: {GetVersionString(swscale_version())}");
151+
152+
Log.Info("Successfully loaded system FFmpeg libraries.");
142153

143154
// Libraries are installed on the system, delete the Cache if it exists.
144155
if (File.Exists(ChecksumPath))
@@ -188,11 +199,11 @@ private static Task Validate() => Task.Run(() => {
188199
_validated = true;
189200
_installed = true;
190201
try {
191-
Log.Info($"avutil: {GetVersionString(avutil_version())}");
192-
Log.Info($"avformat: {GetVersionString(avformat_version())}");
193-
Log.Info($"avcodec: {GetVersionString(avcodec_version())}");
194-
Log.Info($"swresample: {GetVersionString(swresample_version())}");
195-
Log.Info($"swscale: {GetVersionString(swscale_version())}");
202+
Log.Debug($"avutil: {GetVersionString(avutil_version())}");
203+
Log.Debug($"avformat: {GetVersionString(avformat_version())}");
204+
Log.Debug($"avcodec: {GetVersionString(avcodec_version())}");
205+
Log.Debug($"swresample: {GetVersionString(swresample_version())}");
206+
Log.Debug($"swscale: {GetVersionString(swscale_version())}");
196207
} catch (Exception ex) {
197208
Log.Error("Failed linking against FFmpeg libraries! Starting without FFmpeg libraries.");
198209
Log.Exception(ex);
@@ -312,15 +323,15 @@ private static bool LoadLibrariesFromCache() {
312323
// However if we are loading from Cache, there is no system library.
313324
Log.Debug("Trying to load libraries from cache...");
314325
try {
315-
Log.Verbose($"Loading {Path.Combine(InstallPath, AvutilName)}");
326+
Log.Debug($"Loading {Path.Combine(InstallPath, AvutilName)}");
316327
AvutilLibrary = NativeLibrary.Load(Path.Combine(InstallPath, AvutilName));
317-
Log.Verbose($"Loading {Path.Combine(InstallPath, SwresampleName)}");
328+
Log.Debug($"Loading {Path.Combine(InstallPath, SwresampleName)}");
318329
SwresampleLibrary = NativeLibrary.Load(Path.Combine(InstallPath, SwresampleName)); // Depends on: avutil
319-
Log.Verbose($"Loading {Path.Combine(InstallPath, SwscaleName)}");
330+
Log.Debug($"Loading {Path.Combine(InstallPath, SwscaleName)}");
320331
SwscaleLibrary = NativeLibrary.Load(Path.Combine(InstallPath, SwscaleName)); // Depends on: avutil
321-
Log.Verbose($"Loading {Path.Combine(InstallPath, AvcodecName)}");
332+
Log.Debug($"Loading {Path.Combine(InstallPath, AvcodecName)}");
322333
AvcodecLibrary = NativeLibrary.Load(Path.Combine(InstallPath, AvcodecName)); // Depends on: avutil, swresample
323-
Log.Verbose($"Loading {Path.Combine(InstallPath, AvformatName)}");
334+
Log.Debug($"Loading {Path.Combine(InstallPath, AvformatName)}");
324335
AvformatLibrary = NativeLibrary.Load(Path.Combine(InstallPath, AvformatName)); // Depends on: avutil, avcodec, swresample
325336

326337
return true;

Source/VideoCapture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Celeste.Mod.TASRecorder.Util;
12
using Microsoft.Xna.Framework;
23
using Microsoft.Xna.Framework.Graphics;
34
using Monocle;
@@ -58,6 +59,7 @@ internal static void Unload() {
5859
private static bool updateHappened;
5960

6061
private static unsafe void CaptureFrame() {
62+
Log.Debug("Starting frame capture");
6163
int width = captureTarget.Width;
6264
int height = captureTarget.Height;
6365

@@ -80,6 +82,7 @@ private static unsafe void CaptureFrame() {
8082
}
8183
}
8284
TASRecorderModule.Encoder.FinishVideo();
85+
Log.Debug("Successfully captured frame");
8386
}
8487

8588
// Taken from Engine.UpdateView(), but without depending on presentation parameters

0 commit comments

Comments
 (0)