Skip to content

Commit a899696

Browse files
committed
Fix logic error when calling _encoder.init()
1 parent 528e015 commit a899696

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/webrtc/include/scy/webrtc/streamrecorder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class StreamRecorder : public rtc::VideoSinkInterface<webrtc::VideoFrame>,
5050
rtc::scoped_refptr<webrtc::AudioTrackInterface> _audioTrack;
5151
bool _awaitingVideo;
5252
bool _awaitingAudio;
53+
bool _shouldInit = true;
5354
};
5455

5556

src/webrtc/src/streamrecorder.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,15 @@ void StreamRecorder::OnFrame(const webrtc::VideoFrame& yuvframe)
8181
ivideo.pixelFmt = "yuv420p";
8282
ivideo.fps = 25;
8383

84-
if (!_awaitingAudio)
85-
_encoder.init();
84+
if (_shouldInit) {
85+
try {
86+
_encoder.init();
87+
_shouldInit = false;
88+
} catch (std::exception& exc) {
89+
LError("Failed to init encoder: ", exc.what())
90+
_encoder.uninit();
91+
}
92+
}
8693
}
8794

8895
if (_encoder.isActive()) {
@@ -132,8 +139,15 @@ void StreamRecorder::OnData(const void* audio_data, int bits_per_sample,
132139
// format. Set an assertion just incase this ever changes or varies.
133140
assert(bits_per_sample == 16);
134141

135-
if (!_awaitingVideo)
136-
_encoder.init();
142+
if (_shouldInit) {
143+
try {
144+
_encoder.init();
145+
_shouldInit = false;
146+
} catch (std::exception& exc) {
147+
LError("Failed to init encoder: ", exc.what())
148+
_encoder.uninit();
149+
}
150+
}
137151
}
138152

139153
if (_encoder.isActive())

0 commit comments

Comments
 (0)