Skip to content

Commit 4033207

Browse files
fix: audio buffer handling in WebRTC service
Added a size check before sleeping and relocking in the audio buffer processing loop to prevent unnecessary delays when the buffer is sufficiently large. Also refactored the update method in page_gathering_widget for conciseness.
1 parent cf91647 commit 4033207

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/client/main.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ struct page_gathering_widget : public ui::widget_flex {
172172
*height / 2);
173173
}
174174

175-
void update(ui::update_context &ctx) override {
176-
ui::widget::update(ctx);
177-
}
175+
void update(ui::update_context &ctx) override { ui::widget::update(ctx); }
178176
};
179177

180178
emplace_child<loading_bar_widget>();
@@ -675,9 +673,11 @@ void ClientContext::init_webrtc_service() {
675673
webrtc_service->audioBuffer_.erase(
676674
webrtc_service->audioBuffer_.begin(),
677675
webrtc_service->audioBuffer_.begin() + 960);
678-
lock.unlock();
679-
std::this_thread::sleep_for(std::chrono::milliseconds(8));
680-
lock.lock();
676+
if (webrtc_service->audioBuffer_.size() < 960) {
677+
lock.unlock();
678+
std::this_thread::sleep_for(std::chrono::milliseconds(8));
679+
lock.lock();
680+
}
681681
} else {
682682
std::this_thread::yield();
683683
}

0 commit comments

Comments
 (0)