mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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:
parent
9030994e91
commit
06d034fe40
9 changed files with 38 additions and 33 deletions
|
@ -58,6 +58,7 @@ rtc_library("common_video") {
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:rtc_task_queue",
|
"../rtc_base:rtc_task_queue",
|
||||||
"../rtc_base:safe_minmax",
|
"../rtc_base:safe_minmax",
|
||||||
|
"../rtc_base/synchronization:mutex",
|
||||||
"../rtc_base/system:rtc_export",
|
"../rtc_base/system:rtc_export",
|
||||||
"../system_wrappers:metrics",
|
"../system_wrappers:metrics",
|
||||||
"//third_party/libyuv",
|
"//third_party/libyuv",
|
||||||
|
|
|
@ -39,7 +39,7 @@ BitrateAdjuster::BitrateAdjuster(float min_adjusted_bitrate_pct,
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitrateAdjuster::SetTargetBitrateBps(uint32_t bitrate_bps) {
|
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
|
// 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
|
// immediately since it's likely we have gained or lost a sizeable amount of
|
||||||
// bandwidth and we'll want to respond quickly.
|
// bandwidth and we'll want to respond quickly.
|
||||||
|
@ -58,22 +58,22 @@ void BitrateAdjuster::SetTargetBitrateBps(uint32_t bitrate_bps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BitrateAdjuster::GetTargetBitrateBps() const {
|
uint32_t BitrateAdjuster::GetTargetBitrateBps() const {
|
||||||
rtc::CritScope cs(&crit_);
|
MutexLock lock(&mutex_);
|
||||||
return target_bitrate_bps_;
|
return target_bitrate_bps_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const {
|
uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const {
|
||||||
rtc::CritScope cs(&crit_);
|
MutexLock lock(&mutex_);
|
||||||
return adjusted_bitrate_bps_;
|
return adjusted_bitrate_bps_;
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<uint32_t> BitrateAdjuster::GetEstimatedBitrateBps() {
|
absl::optional<uint32_t> BitrateAdjuster::GetEstimatedBitrateBps() {
|
||||||
rtc::CritScope cs(&crit_);
|
MutexLock lock(&mutex_);
|
||||||
return bitrate_tracker_.Rate(rtc::TimeMillis());
|
return bitrate_tracker_.Rate(rtc::TimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitrateAdjuster::Update(size_t frame_size) {
|
void BitrateAdjuster::Update(size_t frame_size) {
|
||||||
rtc::CritScope cs(&crit_);
|
MutexLock lock(&mutex_);
|
||||||
uint32_t current_time_ms = rtc::TimeMillis();
|
uint32_t current_time_ms = rtc::TimeMillis();
|
||||||
bitrate_tracker_.Update(frame_size, current_time_ms);
|
bitrate_tracker_.Update(frame_size, current_time_ms);
|
||||||
UpdateBitrate(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
|
// Only safe to call this after Update calls have stopped
|
||||||
void BitrateAdjuster::Reset() {
|
void BitrateAdjuster::Reset() {
|
||||||
rtc::CritScope cs(&crit_);
|
MutexLock lock(&mutex_);
|
||||||
target_bitrate_bps_ = 0;
|
target_bitrate_bps_ = 0;
|
||||||
adjusted_bitrate_bps_ = 0;
|
adjusted_bitrate_bps_ = 0;
|
||||||
last_adjusted_target_bitrate_bps_ = 0;
|
last_adjusted_target_bitrate_bps_ = 0;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/critical_section.h"
|
|
||||||
#include "rtc_base/rate_statistics.h"
|
#include "rtc_base/rate_statistics.h"
|
||||||
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
#include "rtc_base/thread_annotations.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);
|
bool IsWithinTolerance(uint32_t bitrate_bps, uint32_t target_bitrate_bps);
|
||||||
|
|
||||||
// Returns smallest possible adjusted value.
|
// 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.
|
// 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 Reset();
|
||||||
void UpdateBitrate(uint32_t current_time_ms)
|
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 min_adjusted_bitrate_pct_;
|
||||||
const float max_adjusted_bitrate_pct_;
|
const float max_adjusted_bitrate_pct_;
|
||||||
// The bitrate we want.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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
|
} // namespace webrtc
|
||||||
|
|
|
@ -491,6 +491,7 @@ if (is_ios || (is_mac && target_cpu != "x86")) {
|
||||||
"../modules/audio_processing:api",
|
"../modules/audio_processing:api",
|
||||||
"../pc:libjingle_peerconnection",
|
"../pc:libjingle_peerconnection",
|
||||||
"../rtc_base",
|
"../rtc_base",
|
||||||
|
"../rtc_base/synchronization:mutex",
|
||||||
"../sdk:base_objc",
|
"../sdk:base_objc",
|
||||||
"../sdk:default_codec_factory_objc",
|
"../sdk:default_codec_factory_objc",
|
||||||
"../sdk:helpers_objc",
|
"../sdk:helpers_objc",
|
||||||
|
|
|
@ -48,6 +48,7 @@ if (is_android) {
|
||||||
deps = [
|
deps = [
|
||||||
":generated_jni",
|
":generated_jni",
|
||||||
"../../api:scoped_refptr",
|
"../../api:scoped_refptr",
|
||||||
|
"../../rtc_base/synchronization:mutex",
|
||||||
"//api:libjingle_peerconnection_api",
|
"//api:libjingle_peerconnection_api",
|
||||||
"//api/rtc_event_log:rtc_event_log_factory",
|
"//api/rtc_event_log:rtc_event_log_factory",
|
||||||
"//api/task_queue:default_task_queue_factory",
|
"//api/task_queue:default_task_queue_factory",
|
||||||
|
|
|
@ -43,7 +43,7 @@ class AndroidCallClient::PCObserver : public webrtc::PeerConnectionObserver {
|
||||||
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
|
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const AndroidCallClient* client_;
|
AndroidCallClient* const client_;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -88,7 +88,7 @@ void AndroidCallClient::Call(JNIEnv* env,
|
||||||
const webrtc::JavaRef<jobject>& remote_sink) {
|
const webrtc::JavaRef<jobject>& remote_sink) {
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
|
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
if (call_started_) {
|
if (call_started_) {
|
||||||
RTC_LOG(LS_WARNING) << "Call already started.";
|
RTC_LOG(LS_WARNING) << "Call already started.";
|
||||||
return;
|
return;
|
||||||
|
@ -112,7 +112,7 @@ void AndroidCallClient::Hangup(JNIEnv* env) {
|
||||||
call_started_ = false;
|
call_started_ = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
if (pc_ != nullptr) {
|
if (pc_ != nullptr) {
|
||||||
pc_->Close();
|
pc_->Close();
|
||||||
pc_ = nullptr;
|
pc_ = nullptr;
|
||||||
|
@ -174,7 +174,7 @@ void AndroidCallClient::CreatePeerConnectionFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidCallClient::CreatePeerConnection() {
|
void AndroidCallClient::CreatePeerConnection() {
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||||
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
|
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
|
||||||
// DTLS SRTP has to be disabled for loopback to work.
|
// DTLS SRTP has to be disabled for loopback to work.
|
||||||
|
@ -205,7 +205,7 @@ void AndroidCallClient::CreatePeerConnection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidCallClient::Connect() {
|
void AndroidCallClient::Connect() {
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
|
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
|
||||||
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ void AndroidCallClient::PCObserver::OnIceGatheringChange(
|
||||||
void AndroidCallClient::PCObserver::OnIceCandidate(
|
void AndroidCallClient::PCObserver::OnIceCandidate(
|
||||||
const webrtc::IceCandidateInterface* candidate) {
|
const webrtc::IceCandidateInterface* candidate) {
|
||||||
RTC_LOG(LS_INFO) << "OnIceCandidate: " << candidate->server_url();
|
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);
|
RTC_DCHECK(client_->pc_ != nullptr);
|
||||||
client_->pc_->AddIceCandidate(candidate);
|
client_->pc_->AddIceCandidate(candidate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "api/peer_connection_interface.h"
|
#include "api/peer_connection_interface.h"
|
||||||
#include "api/scoped_refptr.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 "rtc_base/thread_checker.h"
|
||||||
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
#include "sdk/android/native_api/video/video_source.h"
|
#include "sdk/android/native_api/video/video_source.h"
|
||||||
|
@ -66,7 +66,7 @@ class AndroidCallClient {
|
||||||
rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
|
rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
|
||||||
RTC_GUARDED_BY(thread_checker_);
|
RTC_GUARDED_BY(thread_checker_);
|
||||||
|
|
||||||
rtc::CriticalSection pc_mutex_;
|
webrtc::Mutex pc_mutex_;
|
||||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
|
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
|
||||||
RTC_GUARDED_BY(pc_mutex_);
|
RTC_GUARDED_BY(pc_mutex_);
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "api/peer_connection_interface.h"
|
#include "api/peer_connection_interface.h"
|
||||||
#include "api/scoped_refptr.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 "rtc_base/thread_checker.h"
|
||||||
|
|
||||||
@class RTC_OBJC_TYPE(RTCVideoCapturer);
|
@class RTC_OBJC_TYPE(RTCVideoCapturer);
|
||||||
|
@ -50,7 +50,7 @@ class ObjCCallClient {
|
||||||
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
|
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ObjCCallClient* client_;
|
ObjCCallClient* const client_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
|
void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
|
||||||
|
@ -73,7 +73,7 @@ class ObjCCallClient {
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
|
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
|
||||||
RTC_GUARDED_BY(thread_checker_);
|
RTC_GUARDED_BY(thread_checker_);
|
||||||
|
|
||||||
rtc::CriticalSection pc_mutex_;
|
webrtc::Mutex pc_mutex_;
|
||||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_);
|
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ void ObjCCallClient::Call(RTC_OBJC_TYPE(RTCVideoCapturer) * capturer,
|
||||||
id<RTC_OBJC_TYPE(RTCVideoRenderer)> remote_renderer) {
|
id<RTC_OBJC_TYPE(RTCVideoRenderer)> remote_renderer) {
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
|
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
if (call_started_) {
|
if (call_started_) {
|
||||||
RTC_LOG(LS_WARNING) << "Call already started.";
|
RTC_LOG(LS_WARNING) << "Call already started.";
|
||||||
return;
|
return;
|
||||||
|
@ -90,7 +90,7 @@ void ObjCCallClient::Hangup() {
|
||||||
call_started_ = false;
|
call_started_ = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
if (pc_ != nullptr) {
|
if (pc_ != nullptr) {
|
||||||
pc_->Close();
|
pc_->Close();
|
||||||
pc_ = nullptr;
|
pc_ = nullptr;
|
||||||
|
@ -138,7 +138,7 @@ void ObjCCallClient::CreatePeerConnectionFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjCCallClient::CreatePeerConnection() {
|
void ObjCCallClient::CreatePeerConnection() {
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||||
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
|
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
|
||||||
// DTLS SRTP has to be disabled for loopback to work.
|
// DTLS SRTP has to be disabled for loopback to work.
|
||||||
|
@ -165,7 +165,7 @@ void ObjCCallClient::CreatePeerConnection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjCCallClient::Connect() {
|
void ObjCCallClient::Connect() {
|
||||||
rtc::CritScope lock(&pc_mutex_);
|
webrtc::MutexLock lock(&pc_mutex_);
|
||||||
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
|
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
|
||||||
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ void ObjCCallClient::PCObserver::OnIceGatheringChange(
|
||||||
|
|
||||||
void ObjCCallClient::PCObserver::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
|
void ObjCCallClient::PCObserver::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
|
||||||
RTC_LOG(LS_INFO) << "OnIceCandidate: " << candidate->server_url();
|
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);
|
RTC_DCHECK(client_->pc_ != nullptr);
|
||||||
client_->pc_->AddIceCandidate(candidate);
|
client_->pc_->AddIceCandidate(candidate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue