Skip to content

Commit 4dcd29a

Browse files
authored
Merge pull request #100 from PALConverteo/fix/wgc-capture-thread-safety
Fix corrupted MP4 recordings on Windows
2 parents 6e69da0 + 906c476 commit 4dcd29a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

electron/native/wgc-capture/src/mf_encoder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ bool MFEncoder::initialize(const std::wstring& outputPath, int width, int height
124124
}
125125

126126
bool MFEncoder::writeFrame(ID3D11Texture2D* texture, int64_t timestampHns) {
127+
std::lock_guard<std::mutex> lock(writeMutex_);
127128
if (!initialized_ || !sinkWriter_) return false;
128129

129130
context_->CopyResource(stagingTexture_.Get(), texture);
@@ -190,6 +191,7 @@ bool MFEncoder::writeFrame(ID3D11Texture2D* texture, int64_t timestampHns) {
190191
}
191192

192193
bool MFEncoder::finalize() {
194+
std::lock_guard<std::mutex> lock(writeMutex_);
193195
if (!initialized_) return false;
194196
initialized_ = false;
195197

electron/native/wgc-capture/src/mf_encoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <wrl/client.h>
99
#include <string>
1010
#include <vector>
11+
#include <mutex>
1112

1213
using Microsoft::WRL::ComPtr;
1314

@@ -32,4 +33,5 @@ class MFEncoder {
3233
int height_ = 0;
3334
int fps_ = 60;
3435
bool initialized_ = false;
36+
std::mutex writeMutex_;
3537
};

0 commit comments

Comments
 (0)