Migrate common_video/ and examples/ to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: I8e01c8adf1e5a0326e7956bdc635cfd3679a0d1a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176743
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31647}
This commit is contained in:
Markus Handell 2020-07-07 09:17:56 +02:00 committed by Commit Bot
parent 9030994e91
commit 06d034fe40
9 changed files with 38 additions and 33 deletions

View file

@ -58,6 +58,7 @@ rtc_library("common_video") {
"../rtc_base:checks",
"../rtc_base:rtc_task_queue",
"../rtc_base:safe_minmax",
"../rtc_base/synchronization:mutex",
"../rtc_base/system:rtc_export",
"../system_wrappers:metrics",
"//third_party/libyuv",

View file

@ -39,7 +39,7 @@ BitrateAdjuster::BitrateAdjuster(float min_adjusted_bitrate_pct,
}
void BitrateAdjuster::SetTargetBitrateBps(uint32_t bitrate_bps) {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
// If the change in target bitrate is large, update the adjusted bitrate
// immediately since it's likely we have gained or lost a sizeable amount of
// bandwidth and we'll want to respond quickly.
@ -58,22 +58,22 @@ void BitrateAdjuster::SetTargetBitrateBps(uint32_t bitrate_bps) {
}
uint32_t BitrateAdjuster::GetTargetBitrateBps() const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
return target_bitrate_bps_;
}
uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
return adjusted_bitrate_bps_;
}
absl::optional<uint32_t> BitrateAdjuster::GetEstimatedBitrateBps() {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
return bitrate_tracker_.Rate(rtc::TimeMillis());
}
void BitrateAdjuster::Update(size_t frame_size) {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
uint32_t current_time_ms = rtc::TimeMillis();
bitrate_tracker_.Update(frame_size, current_time_ms);
UpdateBitrate(current_time_ms);
@ -100,7 +100,7 @@ uint32_t BitrateAdjuster::GetMaxAdjustedBitrateBps() const {
// Only safe to call this after Update calls have stopped
void BitrateAdjuster::Reset() {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
target_bitrate_bps_ = 0;
adjusted_bitrate_bps_ = 0;
last_adjusted_target_bitrate_bps_ = 0;

View file

@ -15,8 +15,8 @@
#include <stdint.h>
#include "absl/types/optional.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/rate_statistics.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h"
@ -60,29 +60,31 @@ class RTC_EXPORT BitrateAdjuster {
bool IsWithinTolerance(uint32_t bitrate_bps, uint32_t target_bitrate_bps);
// Returns smallest possible adjusted value.
uint32_t GetMinAdjustedBitrateBps() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
uint32_t GetMinAdjustedBitrateBps() const
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns largest possible adjusted value.
uint32_t GetMaxAdjustedBitrateBps() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
uint32_t GetMaxAdjustedBitrateBps() const
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void Reset();
void UpdateBitrate(uint32_t current_time_ms)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
rtc::CriticalSection crit_;
mutable Mutex mutex_;
const float min_adjusted_bitrate_pct_;
const float max_adjusted_bitrate_pct_;
// The bitrate we want.
volatile uint32_t target_bitrate_bps_ RTC_GUARDED_BY(crit_);
volatile uint32_t target_bitrate_bps_ RTC_GUARDED_BY(mutex_);
// The bitrate we use to get what we want.
volatile uint32_t adjusted_bitrate_bps_ RTC_GUARDED_BY(crit_);
volatile uint32_t adjusted_bitrate_bps_ RTC_GUARDED_BY(mutex_);
// The target bitrate that the adjusted bitrate was computed from.
volatile uint32_t last_adjusted_target_bitrate_bps_ RTC_GUARDED_BY(crit_);
volatile uint32_t last_adjusted_target_bitrate_bps_ RTC_GUARDED_BY(mutex_);
// Used to estimate bitrate.
RateStatistics bitrate_tracker_ RTC_GUARDED_BY(crit_);
RateStatistics bitrate_tracker_ RTC_GUARDED_BY(mutex_);
// The last time we tried to adjust the bitrate.
uint32_t last_bitrate_update_time_ms_ RTC_GUARDED_BY(crit_);
uint32_t last_bitrate_update_time_ms_ RTC_GUARDED_BY(mutex_);
// The number of frames since the last time we tried to adjust the bitrate.
uint32_t frames_since_last_update_ RTC_GUARDED_BY(crit_);
uint32_t frames_since_last_update_ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc

View file

@ -491,6 +491,7 @@ if (is_ios || (is_mac && target_cpu != "x86")) {
"../modules/audio_processing:api",
"../pc:libjingle_peerconnection",
"../rtc_base",
"../rtc_base/synchronization:mutex",
"../sdk:base_objc",
"../sdk:default_codec_factory_objc",
"../sdk:helpers_objc",

View file

@ -48,6 +48,7 @@ if (is_android) {
deps = [
":generated_jni",
"../../api:scoped_refptr",
"../../rtc_base/synchronization:mutex",
"//api:libjingle_peerconnection_api",
"//api/rtc_event_log:rtc_event_log_factory",
"//api/task_queue:default_task_queue_factory",

View file

@ -43,7 +43,7 @@ class AndroidCallClient::PCObserver : public webrtc::PeerConnectionObserver {
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
private:
const AndroidCallClient* client_;
AndroidCallClient* const client_;
};
namespace {
@ -88,7 +88,7 @@ void AndroidCallClient::Call(JNIEnv* env,
const webrtc::JavaRef<jobject>& remote_sink) {
RTC_DCHECK_RUN_ON(&thread_checker_);
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
if (call_started_) {
RTC_LOG(LS_WARNING) << "Call already started.";
return;
@ -112,7 +112,7 @@ void AndroidCallClient::Hangup(JNIEnv* env) {
call_started_ = false;
{
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
if (pc_ != nullptr) {
pc_->Close();
pc_ = nullptr;
@ -174,7 +174,7 @@ void AndroidCallClient::CreatePeerConnectionFactory() {
}
void AndroidCallClient::CreatePeerConnection() {
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
webrtc::PeerConnectionInterface::RTCConfiguration config;
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
// DTLS SRTP has to be disabled for loopback to work.
@ -205,7 +205,7 @@ void AndroidCallClient::CreatePeerConnection() {
}
void AndroidCallClient::Connect() {
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
}
@ -240,7 +240,7 @@ void AndroidCallClient::PCObserver::OnIceGatheringChange(
void AndroidCallClient::PCObserver::OnIceCandidate(
const webrtc::IceCandidateInterface* candidate) {
RTC_LOG(LS_INFO) << "OnIceCandidate: " << candidate->server_url();
rtc::CritScope lock(&client_->pc_mutex_);
webrtc::MutexLock lock(&client_->pc_mutex_);
RTC_DCHECK(client_->pc_ != nullptr);
client_->pc_->AddIceCandidate(candidate);
}

View file

@ -18,7 +18,7 @@
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
#include "sdk/android/native_api/jni/scoped_java_ref.h"
#include "sdk/android/native_api/video/video_source.h"
@ -66,7 +66,7 @@ class AndroidCallClient {
rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
RTC_GUARDED_BY(thread_checker_);
rtc::CriticalSection pc_mutex_;
webrtc::Mutex pc_mutex_;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
RTC_GUARDED_BY(pc_mutex_);
};

View file

@ -18,7 +18,7 @@
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
@class RTC_OBJC_TYPE(RTCVideoCapturer);
@ -50,7 +50,7 @@ class ObjCCallClient {
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
private:
const ObjCCallClient* client_;
ObjCCallClient* const client_;
};
void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
@ -73,7 +73,7 @@ class ObjCCallClient {
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
RTC_GUARDED_BY(thread_checker_);
rtc::CriticalSection pc_mutex_;
webrtc::Mutex pc_mutex_;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_);
};

View file

@ -68,7 +68,7 @@ void ObjCCallClient::Call(RTC_OBJC_TYPE(RTCVideoCapturer) * capturer,
id<RTC_OBJC_TYPE(RTCVideoRenderer)> remote_renderer) {
RTC_DCHECK_RUN_ON(&thread_checker_);
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
if (call_started_) {
RTC_LOG(LS_WARNING) << "Call already started.";
return;
@ -90,7 +90,7 @@ void ObjCCallClient::Hangup() {
call_started_ = false;
{
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
if (pc_ != nullptr) {
pc_->Close();
pc_ = nullptr;
@ -138,7 +138,7 @@ void ObjCCallClient::CreatePeerConnectionFactory() {
}
void ObjCCallClient::CreatePeerConnection() {
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
webrtc::PeerConnectionInterface::RTCConfiguration config;
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
// DTLS SRTP has to be disabled for loopback to work.
@ -165,7 +165,7 @@ void ObjCCallClient::CreatePeerConnection() {
}
void ObjCCallClient::Connect() {
rtc::CritScope lock(&pc_mutex_);
webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
}
@ -198,7 +198,7 @@ void ObjCCallClient::PCObserver::OnIceGatheringChange(
void ObjCCallClient::PCObserver::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
RTC_LOG(LS_INFO) << "OnIceCandidate: " << candidate->server_url();
rtc::CritScope lock(&client_->pc_mutex_);
webrtc::MutexLock lock(&client_->pc_mutex_);
RTC_DCHECK(client_->pc_ != nullptr);
client_->pc_->AddIceCandidate(candidate);
}