diff --git a/dom/media/systemservices/android_video_capture/video_capture_android.cc b/dom/media/systemservices/android_video_capture/video_capture_android.cc index 4d9205cfe138..f82c21e86385 100644 --- a/dom/media/systemservices/android_video_capture/video_capture_android.cc +++ b/dom/media/systemservices/android_video_capture/video_capture_android.cc @@ -12,9 +12,9 @@ #include "device_info_android.h" #include "modules/utility/include/helpers_android.h" -#include "rtc_base/criticalsection.h" #include "rtc_base/logging.h" -#include "rtc_base/refcountedobject.h" +#include "rtc_base/ref_counted_object.h" +#include "rtc_base/time_utils.h" #include "AndroidBridge.h" @@ -143,7 +143,7 @@ rtc::scoped_refptr VideoCaptureImpl::Create( void VideoCaptureAndroid::OnIncomingFrame(rtc::scoped_refptr buffer, int32_t degrees, int64_t captureTime) { - rtc::CritScope cs(&_apiCs); + MutexLock lock(&api_lock_); VideoRotation rotation = (degrees <= 45 || degrees > 315) ? kVideoRotation_0 @@ -167,7 +167,7 @@ VideoCaptureAndroid::VideoCaptureAndroid() int32_t VideoCaptureAndroid::Init(const char* deviceUniqueIdUTF8) { const int nameLength = strlen(deviceUniqueIdUTF8); - if (nameLength >= kVideoCaptureUniqueNameSize) return -1; + if (nameLength >= kVideoCaptureUniqueNameLength) return -1; // Store the device name RTC_LOG(LS_INFO) << "VideoCaptureAndroid::Init: " << deviceUniqueIdUTF8; @@ -196,29 +196,31 @@ VideoCaptureAndroid::~VideoCaptureAndroid() { int32_t VideoCaptureAndroid::StartCapture( const VideoCaptureCapability& capability) { - _apiCs.Enter(); - AttachThreadScoped ats(g_jvm_capture); - JNIEnv* env = ats.env(); - - if (_deviceInfo.GetBestMatchedCapability(_deviceUniqueId, capability, - _captureCapability) < 0) { - RTC_LOG(LS_ERROR) << __FUNCTION__ << "s: GetBestMatchedCapability failed: " - << capability.width << "x" << capability.height; - // Manual exit of critical section - _apiCs.Leave(); - return -1; - } - - int width = _captureCapability.width; - int height = _captureCapability.height; + JNIEnv* env = nullptr; + int width = 0; + int height = 0; int min_mfps = 0; int max_mfps = 0; - _deviceInfo.GetMFpsRange(_deviceUniqueId, _captureCapability.maxFPS, - &min_mfps, &max_mfps); + { + MutexLock lock(&api_lock_); + AttachThreadScoped ats(g_jvm_capture); + env = ats.env(); - // Exit critical section to avoid blocking camera thread inside - // onIncomingFrame() call. - _apiCs.Leave(); + if (_deviceInfo.GetBestMatchedCapability(_deviceUniqueId, capability, + _captureCapability) < 0) { + RTC_LOG(LS_ERROR) << __FUNCTION__ << "s: GetBestMatchedCapability failed: " + << capability.width << "x" << capability.height; + return -1; + } + + width = _captureCapability.width; + height = _captureCapability.height; + _deviceInfo.GetMFpsRange(_deviceUniqueId, _captureCapability.maxFPS, + &min_mfps, &max_mfps); + + // Exit critical section to avoid blocking camera thread inside + // onIncomingFrame() call. + } jmethodID j_start = env->GetMethodID(g_java_capturer_class, "startCapture", "(IIIIJ)Z"); @@ -227,7 +229,7 @@ int32_t VideoCaptureAndroid::StartCapture( bool started = env->CallBooleanMethod(_jCapturer, j_start, width, height, min_mfps, max_mfps, j_this); if (started) { - rtc::CritScope cs(&_apiCs); + MutexLock lock(&api_lock_); _requestedCapability = capability; _captureStarted = true; } @@ -235,16 +237,18 @@ int32_t VideoCaptureAndroid::StartCapture( } int32_t VideoCaptureAndroid::StopCapture() { - _apiCs.Enter(); - AttachThreadScoped ats(g_jvm_capture); - JNIEnv* env = ats.env(); + JNIEnv* env = nullptr; + { + MutexLock lock(&api_lock_); + AttachThreadScoped ats(g_jvm_capture); + env = ats.env(); - memset(&_requestedCapability, 0, sizeof(_requestedCapability)); - memset(&_captureCapability, 0, sizeof(_captureCapability)); - _captureStarted = false; - // Exit critical section to avoid blocking camera thread inside - // onIncomingFrame() call. - _apiCs.Leave(); + memset(&_requestedCapability, 0, sizeof(_requestedCapability)); + memset(&_captureCapability, 0, sizeof(_captureCapability)); + _captureStarted = false; + // Exit critical section to avoid blocking camera thread inside + // onIncomingFrame() call. + } // try to stop the capturer. jmethodID j_stop = @@ -253,12 +257,12 @@ int32_t VideoCaptureAndroid::StopCapture() { } bool VideoCaptureAndroid::CaptureStarted() { - rtc::CritScope cs(&_apiCs); + MutexLock lock(&api_lock_); return _captureStarted; } int32_t VideoCaptureAndroid::CaptureSettings(VideoCaptureCapability& settings) { - rtc::CritScope cs(&_apiCs); + MutexLock lock(&api_lock_); settings = _requestedCapability; return 0; } diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index d9ad96d9c918..cdd1c540083f 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -186,7 +186,7 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings( mode = AudioProcessing::Config::GainController1::kAdaptiveDigital; } #if defined(WEBRTC_IOS) || defined(ATA) || defined(WEBRTC_ANDROID) - if (mode == GainControl::Mode::kAdaptiveAnalog) { + if (mode == AudioProcessing::Config::GainController1::kAdaptiveAnalog) { LOG_ERROR( "AudioInputProcessing %p Invalid AGC mode kAdaptiveAnalog on " "mobile", diff --git a/third_party/libwebrtc/modules/utility/source/jvm_android.cc b/third_party/libwebrtc/modules/utility/source/jvm_android.cc index 6274992f116e..1a6556145f44 100644 --- a/third_party/libwebrtc/modules/utility/source/jvm_android.cc +++ b/third_party/libwebrtc/modules/utility/source/jvm_android.cc @@ -223,7 +223,6 @@ std::string JNIEnvironment::JavaToStdString(const jstring& j_string) { // static void JVM::Initialize(JavaVM* jvm) { - ALOGD("JVM::Initialize%s", GetThreadInfo().c_str()); if (g_jvm) { return; } diff --git a/third_party/libwebrtc/modules/video_capture/video_capture_impl.h b/third_party/libwebrtc/modules/video_capture/video_capture_impl.h index ccdd04952204..89870d9835f7 100644 --- a/third_party/libwebrtc/modules/video_capture/video_capture_impl.h +++ b/third_party/libwebrtc/modules/video_capture/video_capture_impl.h @@ -79,6 +79,9 @@ class VideoCaptureImpl : public VideoCaptureModule { VideoCaptureImpl(); ~VideoCaptureImpl() override; + // moved DeliverCapturedFrame to protected for VideoCaptureAndroid (mjf) + int32_t DeliverCapturedFrame(VideoFrame& captureFrame); + char* _deviceUniqueId; // current Device unique name; Mutex api_lock_; VideoCaptureCapability _requestedCapability; // Should be set by platform @@ -87,7 +90,6 @@ class VideoCaptureImpl : public VideoCaptureModule { private: void UpdateFrameCount(); uint32_t CalculateFrameRate(int64_t now_ns); - int32_t DeliverCapturedFrame(VideoFrame& captureFrame); // last time the module process function was called. int64_t _lastProcessTimeNanos; diff --git a/third_party/libwebrtc/rtc_base/system/warn_current_thread_is_deadlocked.h b/third_party/libwebrtc/rtc_base/system/warn_current_thread_is_deadlocked.h index 4a0ba9dc0906..eac12022edec 100644 --- a/third_party/libwebrtc/rtc_base/system/warn_current_thread_is_deadlocked.h +++ b/third_party/libwebrtc/rtc_base/system/warn_current_thread_is_deadlocked.h @@ -13,7 +13,7 @@ namespace webrtc { -#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) +#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) && !defined(MOZ_WIDGET_ANDROID) void WarnThatTheCurrentThreadIsProbablyDeadlocked(); #else inline void WarnThatTheCurrentThreadIsProbablyDeadlocked() {} diff --git a/third_party/libwebrtc/sdk/android/api/org/webrtc/VideoCodecInfo.java b/third_party/libwebrtc/sdk/android/api/org/webrtc/VideoCodecInfo.java index 710218add67a..86d25801704d 100644 --- a/third_party/libwebrtc/sdk/android/api/org/webrtc/VideoCodecInfo.java +++ b/third_party/libwebrtc/sdk/android/api/org/webrtc/VideoCodecInfo.java @@ -75,7 +75,7 @@ public class VideoCodecInfo { } @CalledByNative - Map getParams() { + Map getParams() { return params; } }