Skip to content

Commit d9216f0

Browse files
authored
ZoomIt - Fix race condition in audio init (#48685)
It was a race condition.
1 parent 8c9bd8b commit d9216f0

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/modules/ZoomIt/ZoomIt/VideoRecordingSession.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,13 +1149,10 @@ VideoRecordingSession::VideoRecordingSession(
11491149
// Store frame interval for timeout-based frame production when webcam is active.
11501150
m_frameIntervalTicks = ( frameRate > 0 ) ? ( 10'000'000LL / frameRate ) : 333'333LL;
11511151

1152-
if (m_audioGenerator)
1153-
{
1154-
// Always set up audio profile for loopback capture (stereo AAC)
1155-
auto audioProps = m_audioGenerator->GetEncodingProperties();
1156-
m_encodingProfile.Audio(winrt::AudioEncodingProperties::CreateAac(
1157-
audioProps.SampleRate(), audioProps.ChannelCount(), 192000));
1158-
}
1152+
// NOTE: Audio encoding profile (m_encodingProfile.Audio) is set in
1153+
// StartAsync() after the audio graph is fully initialized, not here.
1154+
// Calling GetEncodingProperties() before InitializeAsync completes
1155+
// would crash because m_audioOutputNode is still null.
11591156

11601157
// Describe our input: uncompressed BGRA8 buffers
11611158
auto properties = winrt::VideoEncodingProperties::CreateUncompressed(
@@ -1233,7 +1230,16 @@ winrt::IAsyncAction VideoRecordingSession::StartAsync()
12331230
co_await m_audioGenerator->InitializeAsync();
12341231
}
12351232
RecDiag( L"StartAsync: audio initialized\n" );
1236-
m_streamSource = winrt::MediaStreamSource(m_videoDescriptor, winrt::AudioStreamDescriptor(m_audioGenerator->GetEncodingProperties()));
1233+
1234+
// Set up the audio encoding profile now that the audio graph is
1235+
// fully initialized. GetEncodingProperties() requires
1236+
// m_audioOutputNode to be valid, which is only guaranteed after
1237+
// InitializeAsync completes.
1238+
auto audioProps = m_audioGenerator->GetEncodingProperties();
1239+
m_encodingProfile.Audio(winrt::AudioEncodingProperties::CreateAac(
1240+
audioProps.SampleRate(), audioProps.ChannelCount(), 192000));
1241+
1242+
m_streamSource = winrt::MediaStreamSource(m_videoDescriptor, winrt::AudioStreamDescriptor(audioProps));
12371243
}
12381244
else {
12391245

0 commit comments

Comments
 (0)