Skip to content

Commit 9c4ad30

Browse files
committed
fix: 连续收到多帧音频数据时发生崩溃
1 parent 0061a3b commit 9c4ad30

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/AsyncCallback.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class AsyncCallback
3838
{
3939
if (!callback)
4040
return;
41+
if (signal.test()) // Avoid race condition with loop()
42+
return;
4143
next = std::bind(callback, std::forward<T>(args)...);
4244
signal.test_and_set();
4345
signal.notify_all();

src/AudioDecoder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ bool AudioDecoder::processPacket(AVPacket* packet)
122122
swrCtx = swr_alloc();
123123
}
124124
#if HAVE_CH_LAYOUT
125-
126125
AVChannelLayout out_ch_layout;
127126
av_channel_layout_default(&out_ch_layout, outFrame.channels);
128127

src/StreamPuller.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ StreamPuller::StreamPuller() : exit(1), authenticator(NULL)
111111
callback.invokeSync(CRP_EV_AUDIO_EXTRADATA, &eventData, userData);
112112
}
113113
}
114-
callback(CRP_EV_NEW_AUDIO, audioDecoder->getFrame(), userData);
114+
// Synchronized calls are required to ensure proper processing
115+
// because multiple frames of audio data may be received simultaneously.
116+
callback.invokeSync(CRP_EV_NEW_AUDIO, audioDecoder->getFrame(), userData);
115117
}
116118
};
117119
}

0 commit comments

Comments
 (0)