diff --git a/api/crypto/frame_crypto_transformer.cc b/api/crypto/frame_crypto_transformer.cc index 1604a80e53..a9a2b2d55c 100644 --- a/api/crypto/frame_crypto_transformer.cc +++ b/api/crypto/frame_crypto_transformer.cc @@ -442,17 +442,18 @@ void FrameCryptorTransformer::encryptFrame( auto key_set = key_handler->GetKeySet(key_index_); uint8_t unencrypted_bytes = get_unencrypted_bytes(frame.get(), type_); - Buffer frame_header(unencrypted_bytes); + Buffer frame_header = Buffer::CreateUninitializedWithSize(unencrypted_bytes); for (size_t i = 0; i < unencrypted_bytes; i++) { frame_header[i] = data_in[i]; } - Buffer frame_trailer(2); + Buffer frame_trailer = Buffer::CreateUninitializedWithSize(2); frame_trailer[0] = getIvSize(); frame_trailer[1] = key_index_; Buffer iv = makeIv(frame->GetSsrc(), frame->GetTimestamp()); - Buffer payload(data_in.size() - unencrypted_bytes); + Buffer payload = + Buffer::CreateUninitializedWithSize(data_in.size() - unencrypted_bytes); for (size_t i = unencrypted_bytes; i < data_in.size(); i++) { payload[i - unencrypted_bytes] = data_in[i]; } @@ -462,8 +463,7 @@ void FrameCryptorTransformer::encryptFrame( key_set->encryption_key, iv, frame_header, payload, &buffer) == Success) { Buffer encrypted_payload(buffer.data(), buffer.size()); - Buffer tag(encrypted_payload.data() + encrypted_payload.size() - 16, - 16); + Buffer tag(encrypted_payload.data() + encrypted_payload.size() - 16, 16); Buffer data_without_header; data_without_header.AppendData(encrypted_payload); data_without_header.AppendData(iv); @@ -566,12 +566,12 @@ void FrameCryptorTransformer::decryptFrame( uint8_t unencrypted_bytes = get_unencrypted_bytes(frame.get(), type_); - Buffer frame_header(unencrypted_bytes); + Buffer frame_header = Buffer::CreateUninitializedWithSize(unencrypted_bytes); for (size_t i = 0; i < unencrypted_bytes; i++) { frame_header[i] = data_in[i]; } - Buffer frame_trailer(2); + Buffer frame_trailer = Buffer::CreateUninitializedWithSize(2); frame_trailer[0] = data_in[data_in.size() - 2]; frame_trailer[1] = data_in[data_in.size() - 1]; uint8_t ivLength = frame_trailer[0]; @@ -613,12 +613,13 @@ void FrameCryptorTransformer::decryptFrame( auto key_set = key_handler->GetKeySet(key_index); - Buffer iv = Buffer(ivLength); + Buffer iv = Buffer::CreateUninitializedWithSize(ivLength); for (size_t i = 0; i < ivLength; i++) { iv[i] = data_in[data_in.size() - 2 - ivLength + i]; } - Buffer encrypted_buffer(data_in.size() - unencrypted_bytes); + Buffer encrypted_buffer = + Buffer::CreateUninitializedWithSize(data_in.size() - unencrypted_bytes); for (size_t i = unencrypted_bytes; i < data_in.size(); i++) { encrypted_buffer[i - unencrypted_bytes] = data_in[i]; } @@ -634,7 +635,8 @@ void FrameCryptorTransformer::decryptFrame( H265::ParseRbsp(encrypted_buffer.data(), encrypted_buffer.size())); } - Buffer encrypted_payload(encrypted_buffer.size() - ivLength - 2); + Buffer encrypted_payload = Buffer::CreateUninitializedWithSize( + encrypted_buffer.size() - ivLength - 2); for (size_t i = 0; i < encrypted_payload.size(); i++) { encrypted_payload[i] = encrypted_buffer[i]; } @@ -795,7 +797,8 @@ RTCErrorOr> DataPacketCryptor::Encrypt( std::vector buffer; Buffer payload(data.data(), data.size()); - auto frame_header = Buffer(0); // no frame header for data packets + auto frame_header = Buffer::CreateUninitializedWithSize( + 0); // no frame header for data packets if (AesEncryptDecrypt(EncryptOrDecrypt::kEncrypt, algorithm_, key_set->encryption_key, iv, frame_header, payload, &buffer) == Success) { @@ -826,12 +829,13 @@ RTCErrorOr> DataPacketCryptor::Decrypt( std::to_string(key_index) + "] out of range for participant " + participant_id); } - + std::vector buffer; Buffer encrypted_payload(encryptedPacket->data.data(), - encryptedPacket->data.size()); + encryptedPacket->data.size()); Buffer iv(encryptedPacket->iv.data(), encryptedPacket->iv.size()); - auto frame_header = Buffer(0); // no frame header for data packets + auto frame_header = Buffer::CreateUninitializedWithSize( + 0); // no frame header for data packets auto key_set = key_handler->GetKeySet(key_index); auto initialKeyMaterial = key_set->material; diff --git a/api/test/mock_transformable_video_frame.h b/api/test/mock_transformable_video_frame.h index 03addf1988..2529dcca66 100644 --- a/api/test/mock_transformable_video_frame.h +++ b/api/test/mock_transformable_video_frame.h @@ -45,7 +45,6 @@ class MockTransformableVideoFrame : public TransformableVideoFrameInterface { (const, override)); MOCK_METHOD(std::string, GetMimeType, (), (const, override)); MOCK_METHOD(VideoFrameMetadata, Metadata, (), (const, override)); - MOCK_METHOD(RTPVideoHeader&, header, (), (const, override)); MOCK_METHOD(std::optional, GetPresentationTimestamp, (), diff --git a/modules/audio_device/include/test_audio_device.cc b/modules/audio_device/include/test_audio_device.cc index 851945e004..06c43cca92 100644 --- a/modules/audio_device/include/test_audio_device.cc +++ b/modules/audio_device/include/test_audio_device.cc @@ -51,17 +51,17 @@ constexpr int kFramesPerSecond = kNumMicrosecsPerSec / kFrameLengthUs; class TestAudioDeviceModuleImpl : public AudioDeviceModuleImpl { public: TestAudioDeviceModuleImpl( - TaskQueueFactory* task_queue_factory, + const Environment& env, std::unique_ptr capturer, std::unique_ptr renderer, float speed = 1) : AudioDeviceModuleImpl( AudioLayer::kDummyAudio, - std::make_unique(task_queue_factory, + std::make_unique(env, std::move(capturer), std::move(renderer), speed), - task_queue_factory, + &env.task_queue_factory(), /*create_detached=*/true) {} ~TestAudioDeviceModuleImpl() override = default; @@ -70,16 +70,16 @@ class TestAudioDeviceModuleImpl : public AudioDeviceModuleImpl { class TestAudioDeviceModuleImpl : public AudioDeviceModuleForTest { public: TestAudioDeviceModuleImpl( - TaskQueueFactory* task_queue_factory, + const Environment& env, std::unique_ptr capturer, std::unique_ptr renderer, float speed = 1) : audio_device_(std::make_unique( - task_queue_factory, + env, std::move(capturer), std::move(renderer), speed)), - audio_device_buffer_(task_queue_factory, + audio_device_buffer_(&env.task_queue_factory(), /*create_detached=*/true) { audio_device_->AttachAudioBuffer(&audio_device_buffer_); } @@ -784,12 +784,12 @@ size_t TestAudioDeviceModule::SamplesPerFrame(int sampling_frequency_in_hz) { } scoped_refptr TestAudioDeviceModule::Create( - TaskQueueFactory* task_queue_factory, + const Environment& env, std::unique_ptr capturer, std::unique_ptr renderer, float speed) { auto audio_device = make_ref_counted( - task_queue_factory, std::move(capturer), std::move(renderer), speed); + env, std::move(capturer), std::move(renderer), speed); #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) // Ensure that the current platform is supported. diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 7175aef343..c51bbb64b7 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -95,6 +95,7 @@ if (is_ios || is_mac) { rtc_library("base_objc") { visibility = [ "*" ] sources = [ + "objc/base/RTCAudioRenderer.h", "objc/base/RTCCodecSpecificInfo.h", "objc/base/RTCEncodedImage.h", "objc/base/RTCEncodedImage.m", @@ -253,7 +254,7 @@ if (is_ios || is_mac) { } if (!build_with_chromium) { - if (is_ios) { + if (is_ios || is_mac) { rtc_library("native_api_audio_device_module") { visibility = [ "*" ] @@ -263,7 +264,6 @@ if (is_ios || is_mac) { ] deps = [ - ":audio_device", ":audio_device_module_error_handler", "../api:make_ref_counted", "../api:scoped_refptr", @@ -274,8 +274,14 @@ if (is_ios || is_mac) { "../rtc_base:logging", "../system_wrappers", ] + + if (is_ios) { + deps += [ ":audio_device" ] + } } + } + if (is_ios) { rtc_source_set("audio_session_observer") { visibility = [ ":*" ] @@ -681,7 +687,6 @@ if (is_ios || is_mac) { if (is_mac) { sources += [ "objc/components/renderer/metal/RTCMTLNSVideoView.h", - "objc/components/renderer/metal/RTCMTLNSVideoView.m", ] frameworks += [ "AppKit.framework" ] } @@ -1094,11 +1099,19 @@ if (is_ios || is_mac) { "objc/api/peerconnection/RTCDataChannelConfiguration+Private.h", "objc/api/peerconnection/RTCDataChannelConfiguration.h", "objc/api/peerconnection/RTCDataChannelConfiguration.mm", + "objc/api/peerconnection/RTCDataPacketCryptor.h", + "objc/api/peerconnection/RTCDataPacketCryptor.mm", "objc/api/peerconnection/RTCDtmfSender+Private.h", "objc/api/peerconnection/RTCDtmfSender.h", "objc/api/peerconnection/RTCDtmfSender.mm", "objc/api/peerconnection/RTCFieldTrials.h", "objc/api/peerconnection/RTCFieldTrials.mm", + "objc/api/peerconnection/RTCFrameCryptor+Private.h", + "objc/api/peerconnection/RTCFrameCryptor.h", + "objc/api/peerconnection/RTCFrameCryptor.mm", + "objc/api/peerconnection/RTCFrameCryptorKeyProvider+Private.h", + "objc/api/peerconnection/RTCFrameCryptorKeyProvider.h", + "objc/api/peerconnection/RTCFrameCryptorKeyProvider.mm", "objc/api/peerconnection/RTCIODevice.h", "objc/api/peerconnection/RTCIODevice.mm", "objc/api/peerconnection/RTCIceCandidate+Private.h", @@ -1257,6 +1270,7 @@ if (is_ios || is_mac) { "../api/audio_codecs:audio_codecs_api", "../api/audio_codecs:builtin_audio_decoder_factory", "../api/audio_codecs:builtin_audio_encoder_factory", + "../api/crypto:frame_crypto_transformer", "../api/crypto:frame_decryptor_interface", "../api/crypto:frame_encryptor_interface", "../api/environment", @@ -1290,10 +1304,9 @@ if (is_ios || is_mac) { "../system_wrappers:metrics", ] - if (is_ios) { + if (is_ios || is_mac) { deps += [ ":native_api_audio_device_module", - "../api/transport:network_control", ] } } @@ -1448,6 +1461,11 @@ if (is_ios || is_mac) { } } + bundle_data("darwin_privacy_info") { + sources = [ "objc/PrivacyInfo.xcprivacy" ] + outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] + } + if (is_ios) { apple_framework_bundle_with_umbrella_header("framework_objc") { info_plist = "objc/Info.plist" @@ -1473,6 +1491,7 @@ if (is_ios || is_mac) { "objc/base/RTCVideoFrame.h", "objc/base/RTCVideoFrameBuffer.h", "objc/base/RTCVideoRenderer.h", + "objc/base/RTCAudioRenderer.h", "objc/base/RTCYUVPlanarBuffer.h", "objc/components/audio/RTCAudioDevice.h", "objc/components/audio/RTCAudioSession.h", @@ -1502,6 +1521,9 @@ if (is_ios || is_mac) { "objc/api/peerconnection/RTCConfiguration.h", "objc/api/peerconnection/RTCDataChannel.h", "objc/api/peerconnection/RTCDataChannelConfiguration.h", + "objc/api/peerconnection/RTCDataPacketCryptor.h", + "objc/api/peerconnection/RTCFrameCryptor.h", + "objc/api/peerconnection/RTCFrameCryptorKeyProvider.h", "objc/api/peerconnection/RTCFieldTrials.h", "objc/api/peerconnection/RTCIceCandidate.h", "objc/api/peerconnection/RTCIceCandidateErrorEvent.h", @@ -1601,6 +1623,7 @@ if (is_ios || is_mac) { deps = [ ":audio_objc", ":base_objc", + ":darwin_privacy_info", ":default_codec_factory_objc", ":metal_objc", ":native_api", @@ -1642,6 +1665,39 @@ if (is_ios || is_mac) { } if (is_mac) { + rtc_library("desktopcapture_objc") { + visibility = [ "*" ] + sources = [ + "objc/components/capturer/RTCDesktopCapturer+Private.h", + "objc/components/capturer/RTCDesktopCapturer.h", + "objc/components/capturer/RTCDesktopCapturer.mm", + "objc/components/capturer/RTCDesktopMediaList+Private.h", + "objc/components/capturer/RTCDesktopMediaList.h", + "objc/components/capturer/RTCDesktopMediaList.mm", + "objc/components/capturer/RTCDesktopSource+Private.h", + "objc/components/capturer/RTCDesktopSource.h", + "objc/components/capturer/RTCDesktopSource.mm", + "objc/native/src/objc_desktop_capture.h", + "objc/native/src/objc_desktop_capture.mm", + "objc/native/src/objc_desktop_media_list.h", + "objc/native/src/objc_desktop_media_list.mm", + ] + frameworks = [ "AppKit.framework" ] + + configs += [ "..:common_objc" ] + + public_configs = [ ":common_config_objc" ] + + deps = [ + ":base_objc", + ":helpers_objc", + ":videoframebuffer_objc", + "../modules/desktop_capture", + "../rtc_base/system:gcd_helpers", + "//third_party:jpeg", + ] + } + apple_framework_bundle_with_umbrella_header("mac_framework_objc") { info_plist = "objc/Info.plist" output_name = "WebRTC" @@ -1655,8 +1711,11 @@ if (is_ios || is_mac) { "objc/api/peerconnection/RTCCryptoOptions.h", "objc/api/peerconnection/RTCDataChannel.h", "objc/api/peerconnection/RTCDataChannelConfiguration.h", + "objc/api/peerconnection/RTCDataPacketCryptor.h", "objc/api/peerconnection/RTCDtmfSender.h", "objc/api/peerconnection/RTCFieldTrials.h", + "objc/api/peerconnection/RTCFrameCryptor.h", + "objc/api/peerconnection/RTCFrameCryptorKeyProvider.h", "objc/api/peerconnection/RTCIODevice.h", "objc/api/peerconnection/RTCIceCandidate.h", "objc/api/peerconnection/RTCIceCandidateErrorEvent.h", @@ -1697,6 +1756,7 @@ if (is_ios || is_mac) { "objc/api/video_codec/RTCVideoEncoderVP9.h", "objc/api/video_frame_buffer/RTCNativeI420Buffer.h", "objc/api/video_frame_buffer/RTCNativeMutableI420Buffer.h", + "objc/base/RTCAudioRenderer.h", "objc/base/RTCCodecSpecificInfo.h", "objc/base/RTCEncodedImage.h", "objc/base/RTCI420Buffer.h", @@ -1718,6 +1778,9 @@ if (is_ios || is_mac) { "objc/base/RTCVideoRenderer.h", "objc/base/RTCYUVPlanarBuffer.h", "objc/components/capturer/RTCCameraVideoCapturer.h", + "objc/components/capturer/RTCDesktopCapturer.h", + "objc/components/capturer/RTCDesktopMediaList.h", + "objc/components/capturer/RTCDesktopSource.h", "objc/components/capturer/RTCFileVideoCapturer.h", "objc/components/renderer/metal/RTCMTLNSVideoView.h", "objc/components/renderer/opengl/RTCVideoViewShading.h", @@ -1741,7 +1804,9 @@ if (is_ios || is_mac) { deps = [ ":base_objc", + ":darwin_privacy_info", ":default_codec_factory_objc", + ":desktopcapture_objc", ":metal_objc", ":native_api", ":native_video", diff --git a/sdk/objc/api/peerconnection/RTCFrameCryptor.mm b/sdk/objc/api/peerconnection/RTCFrameCryptor.mm index 4a7b02497a..268585cf9e 100644 --- a/sdk/objc/api/peerconnection/RTCFrameCryptor.mm +++ b/sdk/objc/api/peerconnection/RTCFrameCryptor.mm @@ -32,8 +32,8 @@ namespace webrtc { -RTCFrameCryptorDelegateAdapter::RTCFrameCryptorDelegateAdapter(RTC_OBJC_TYPE(RTCFrameCryptor) * - frameCryptor) +RTCFrameCryptorDelegateAdapter::RTCFrameCryptorDelegateAdapter( + RTC_OBJC_TYPE(RTCFrameCryptor) * frameCryptor) : frame_cryptor_(frameCryptor) {} RTCFrameCryptorDelegateAdapter::~RTCFrameCryptorDelegateAdapter() {} @@ -46,45 +46,64 @@ kMissingKey, kInternalError, */ -void RTCFrameCryptorDelegateAdapter::OnFrameCryptionStateChanged(const std::string participant_id, - FrameCryptionState state) { +void RTCFrameCryptorDelegateAdapter::OnFrameCryptionStateChanged( + const std::string participant_id, FrameCryptionState state) { RTC_OBJC_TYPE(RTCFrameCryptor) *frameCryptor = frame_cryptor_; if (frameCryptor.delegate) { switch (state) { case FrameCryptionState::kNew: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateNew)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState:RTC_OBJC_TYPE( + RTCFrameCryptorStateNew)]; break; case FrameCryptionState::kOk: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateOk)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState:RTC_OBJC_TYPE( + RTCFrameCryptorStateOk)]; break; case FrameCryptionState::kEncryptionFailed: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateEncryptionFailed)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState: + RTC_OBJC_TYPE( + RTCFrameCryptorStateEncryptionFailed)]; break; case FrameCryptionState::kDecryptionFailed: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateDecryptionFailed)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState: + RTC_OBJC_TYPE( + RTCFrameCryptorStateDecryptionFailed)]; break; case FrameCryptionState::kMissingKey: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateMissingKey)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState: + RTC_OBJC_TYPE( + RTCFrameCryptorStateMissingKey)]; break; case FrameCryptionState::kKeyRatcheted: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateKeyRatcheted)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState: + RTC_OBJC_TYPE( + RTCFrameCryptorStateKeyRatcheted)]; break; case FrameCryptionState::kInternalError: [frameCryptor.delegate frameCryptor:frameCryptor - didStateChangeWithParticipantId:[NSString stringForStdString:participant_id] - withState:RTC_OBJC_TYPE(RTCFrameCryptorStateInternalError)]; + didStateChangeWithParticipantId: + [NSString stringForStdString:participant_id] + withState: + RTC_OBJC_TYPE( + RTCFrameCryptorStateInternalError)]; break; } } @@ -94,7 +113,8 @@ @implementation RTC_OBJC_TYPE (RTCFrameCryptor) { const webrtc::RtpSenderInterface *_sender; const webrtc::RtpReceiverInterface *_receiver; - webrtc::scoped_refptr _frame_crypto_transformer; + webrtc::scoped_refptr + _frame_crypto_transformer; webrtc::scoped_refptr _observer; os_unfair_lock _lock; } @@ -102,7 +122,8 @@ @implementation RTC_OBJC_TYPE (RTCFrameCryptor) { @synthesize participantId = _participantId; @synthesize delegate = _delegate; -- (webrtc::FrameCryptorTransformer::Algorithm)algorithmFromEnum:(RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm { +- (webrtc::FrameCryptorTransformer::Algorithm)algorithmFromEnum: + (RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm { switch (algorithm) { case RTC_OBJC_TYPE(RTCCryptorAlgorithmAesGcm): return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm; @@ -111,82 +132,102 @@ case RTC_OBJC_TYPE(RTCCryptorAlgorithmAesGcm): } } -- (nullable instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - rtpSender:(RTC_OBJC_TYPE(RTCRtpSender) *)sender - participantId:(NSString *)participantId - algorithm:(RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm - keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider { +- (nullable instancetype) + initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory + rtpSender:(RTC_OBJC_TYPE(RTCRtpSender) *)sender + participantId:(NSString *)participantId + algorithm:(RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm + keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider { self = [super init]; if (self) { _lock = OS_UNFAIR_LOCK_INIT; - webrtc::scoped_refptr nativeRtpSender = sender.nativeRtpSender; + webrtc::scoped_refptr nativeRtpSender = + sender.nativeRtpSender; if (nativeRtpSender == nullptr) return nil; - webrtc::scoped_refptr nativeTrack = nativeRtpSender->track(); + webrtc::scoped_refptr nativeTrack = + nativeRtpSender->track(); if (nativeTrack == nullptr) return nil; webrtc::FrameCryptorTransformer::MediaType mediaType = - nativeTrack->kind() == "audio" ? webrtc::FrameCryptorTransformer::MediaType::kAudioFrame - : webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; + nativeTrack->kind() == "audio" ? + webrtc::FrameCryptorTransformer::MediaType::kAudioFrame : + webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; os_unfair_lock_lock(&_lock); - _observer = webrtc::make_ref_counted(self); + _observer = + webrtc::make_ref_counted(self); _participantId = participantId; _frame_crypto_transformer = - webrtc::scoped_refptr(new webrtc::FrameCryptorTransformer( - factory.signalingThread, [participantId stdString], mediaType, - [self algorithmFromEnum:algorithm], keyProvider.nativeKeyProvider)); + webrtc::scoped_refptr( + new webrtc::FrameCryptorTransformer( + factory.signalingThread, + [participantId stdString], + mediaType, + [self algorithmFromEnum:algorithm], + keyProvider.nativeKeyProvider)); factory.signalingThread->BlockingCall([self, nativeRtpSender] { // Must be called on signal thread - nativeRtpSender->SetEncoderToPacketizerFrameTransformer(_frame_crypto_transformer); + nativeRtpSender->SetFrameTransformer(_frame_crypto_transformer); }); _frame_crypto_transformer->SetEnabled(false); - _frame_crypto_transformer->RegisterFrameCryptorTransformerObserver(_observer); + _frame_crypto_transformer->RegisterFrameCryptorTransformerObserver( + _observer); os_unfair_lock_unlock(&_lock); } return self; } -- (nullable instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - rtpReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver - participantId:(NSString *)participantId - algorithm:(RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm - keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider { +- (nullable instancetype) + initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory + rtpReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver + participantId:(NSString *)participantId + algorithm:(RTC_OBJC_TYPE(RTCCryptorAlgorithm))algorithm + keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider { self = [super init]; if (self) { _lock = OS_UNFAIR_LOCK_INIT; - webrtc::scoped_refptr nativeRtpReceiver = receiver.nativeRtpReceiver; + webrtc::scoped_refptr nativeRtpReceiver = + receiver.nativeRtpReceiver; if (nativeRtpReceiver == nullptr) return nil; - webrtc::scoped_refptr nativeTrack = nativeRtpReceiver->track(); + webrtc::scoped_refptr nativeTrack = + nativeRtpReceiver->track(); if (nativeTrack == nullptr) return nil; webrtc::FrameCryptorTransformer::MediaType mediaType = - nativeTrack->kind() == "audio" ? webrtc::FrameCryptorTransformer::MediaType::kAudioFrame - : webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; + nativeTrack->kind() == "audio" ? + webrtc::FrameCryptorTransformer::MediaType::kAudioFrame : + webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; os_unfair_lock_lock(&_lock); - _observer = webrtc::make_ref_counted(self); + _observer = + webrtc::make_ref_counted(self); _participantId = participantId; _frame_crypto_transformer = - webrtc::scoped_refptr(new webrtc::FrameCryptorTransformer( - factory.signalingThread, [participantId stdString], mediaType, - [self algorithmFromEnum:algorithm], keyProvider.nativeKeyProvider)); + webrtc::scoped_refptr( + new webrtc::FrameCryptorTransformer( + factory.signalingThread, + [participantId stdString], + mediaType, + [self algorithmFromEnum:algorithm], + keyProvider.nativeKeyProvider)); factory.signalingThread->BlockingCall([self, nativeRtpReceiver] { // Must be called on signal thread - nativeRtpReceiver->SetDepacketizerToDecoderFrameTransformer(_frame_crypto_transformer); + nativeRtpReceiver->SetFrameTransformer(_frame_crypto_transformer); }); _frame_crypto_transformer->SetEnabled(false); - _frame_crypto_transformer->RegisterFrameCryptorTransformerObserver(_observer); + _frame_crypto_transformer->RegisterFrameCryptorTransformerObserver( + _observer); os_unfair_lock_unlock(&_lock); } @@ -205,7 +246,9 @@ - (void)dealloc { - (BOOL)enabled { os_unfair_lock_lock(&_lock); - BOOL result = _frame_crypto_transformer != nullptr ? _frame_crypto_transformer->enabled() : NO; + BOOL result = _frame_crypto_transformer != nullptr ? + _frame_crypto_transformer->enabled() : + NO; os_unfair_lock_unlock(&_lock); return result; } @@ -220,7 +263,9 @@ - (void)setEnabled:(BOOL)enabled { - (int)keyIndex { os_unfair_lock_lock(&_lock); - int result = _frame_crypto_transformer != nullptr ? _frame_crypto_transformer->key_index() : 0; + int result = _frame_crypto_transformer != nullptr ? + _frame_crypto_transformer->key_index() : + 0; os_unfair_lock_unlock(&_lock); return result; } diff --git a/sdk/objc/api/peerconnection/RTCFrameCryptorKeyProvider.mm b/sdk/objc/api/peerconnection/RTCFrameCryptorKeyProvider.mm index c261a3efb7..94e8f2d7e9 100644 --- a/sdk/objc/api/peerconnection/RTCFrameCryptorKeyProvider.mm +++ b/sdk/objc/api/peerconnection/RTCFrameCryptorKeyProvider.mm @@ -26,7 +26,7 @@ @implementation RTC_OBJC_TYPE (RTCFrameCryptorKeyProvider) { webrtc::scoped_refptr _nativeKeyProvider; } -- (rtc::scoped_refptr)nativeKeyProvider { +- (webrtc::scoped_refptr)nativeKeyProvider { return _nativeKeyProvider; } @@ -35,11 +35,11 @@ - (instancetype)initWithRatchetSalt:(NSData *)salt sharedKeyMode:(BOOL)sharedKey uncryptedMagicBytes:(NSData *)uncryptedMagicBytes { return [self initWithRatchetSalt:salt - ratchetWindowSize:windowSize - sharedKeyMode:sharedKey - uncryptedMagicBytes:uncryptedMagicBytes - failureTolerance:-1 - keyRingSize:webrtc::DEFAULT_KEYRING_SIZE]; + ratchetWindowSize:windowSize + sharedKeyMode:sharedKey + uncryptedMagicBytes:uncryptedMagicBytes + failureTolerance:-1 + keyRingSize:webrtc::DEFAULT_KEYRING_SIZE]; } - (instancetype)initWithRatchetSalt:(NSData *)salt @@ -49,12 +49,12 @@ - (instancetype)initWithRatchetSalt:(NSData *)salt failureTolerance:(int)failureTolerance keyRingSize:(int)keyRingSize { return [self initWithRatchetSalt:salt - ratchetWindowSize:windowSize - sharedKeyMode:sharedKey - uncryptedMagicBytes:uncryptedMagicBytes - failureTolerance:-1 - keyRingSize:keyRingSize - discardFrameWhenCryptorNotReady:false]; + ratchetWindowSize:windowSize + sharedKeyMode:sharedKey + uncryptedMagicBytes:uncryptedMagicBytes + failureTolerance:-1 + keyRingSize:keyRingSize + discardFrameWhenCryptorNotReady:false]; } - (instancetype)initWithRatchetSalt:(NSData *)salt @@ -67,33 +67,42 @@ - (instancetype)initWithRatchetSalt:(NSData *)salt self = [super init]; if (self) { webrtc::KeyProviderOptions options; - options.ratchet_salt = std::vector((const uint8_t *)salt.bytes, - ((const uint8_t *)salt.bytes) + salt.length); + options.ratchet_salt = + std::vector((const uint8_t *)salt.bytes, + ((const uint8_t *)salt.bytes) + salt.length); options.ratchet_window_size = windowSize; options.shared_key = sharedKey; options.failure_tolerance = failureTolerance; options.key_ring_size = keyRingSize; - options.discard_frame_when_cryptor_not_ready = discardFrameWhenCryptorNotReady; - if(uncryptedMagicBytes != nil) { - options.uncrypted_magic_bytes = std::vector((const uint8_t *)uncryptedMagicBytes.bytes, - ((const uint8_t *)uncryptedMagicBytes.bytes) + uncryptedMagicBytes.length); + options.discard_frame_when_cryptor_not_ready = + discardFrameWhenCryptorNotReady; + if (uncryptedMagicBytes != nil) { + options.uncrypted_magic_bytes = + std::vector((const uint8_t *)uncryptedMagicBytes.bytes, + ((const uint8_t *)uncryptedMagicBytes.bytes) + + uncryptedMagicBytes.length); } - _nativeKeyProvider = webrtc::make_ref_counted(options); + _nativeKeyProvider = + webrtc::make_ref_counted(options); } return self; } -- (void)setKey:(NSData *)key withIndex:(int)index forParticipant:(NSString *)participantId { +- (void)setKey:(NSData *)key + withIndex:(int)index + forParticipant:(NSString *)participantId { _nativeKeyProvider->SetKey( [participantId stdString], index, - std::vector((const uint8_t *)key.bytes, ((const uint8_t *)key.bytes) + key.length)); + std::vector((const uint8_t *)key.bytes, + ((const uint8_t *)key.bytes) + key.length)); } - (void)setSharedKey:(NSData *)key withIndex:(int)index { _nativeKeyProvider->SetSharedKey( index, - std::vector((const uint8_t *)key.bytes, ((const uint8_t *)key.bytes) + key.length)); + std::vector((const uint8_t *)key.bytes, + ((const uint8_t *)key.bytes) + key.length)); } - (NSData *)ratchetSharedKey:(int)index { @@ -107,12 +116,14 @@ - (NSData *)exportSharedKey:(int)index { } - (NSData *)ratchetKey:(NSString *)participantId withIndex:(int)index { - std::vector nativeKey = _nativeKeyProvider->RatchetKey([participantId stdString], index); + std::vector nativeKey = + _nativeKeyProvider->RatchetKey([participantId stdString], index); return [NSData dataWithBytes:nativeKey.data() length:nativeKey.size()]; } - (NSData *)exportKey:(NSString *)participantId withIndex:(int)index { - std::vector nativeKey = _nativeKeyProvider->ExportKey([participantId stdString], index); + std::vector nativeKey = + _nativeKeyProvider->ExportKey([participantId stdString], index); return [NSData dataWithBytes:nativeKey.data() length:nativeKey.size()]; } diff --git a/sdk/objc/native/api/audio_device_module.mm b/sdk/objc/native/api/audio_device_module.mm index 485a9b6386..154c248746 100644 --- a/sdk/objc/native/api/audio_device_module.mm +++ b/sdk/objc/native/api/audio_device_module.mm @@ -44,6 +44,7 @@ #endif } +#if defined(WEBRTC_IOS) webrtc::scoped_refptr CreateMutedDetectAudioDeviceModule( AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler, bool bypass_voice_processing) { @@ -79,13 +80,8 @@ ADMErrorHandler error_handler, bool bypass_voice_processing) { RTC_DLOG(LS_INFO) << __FUNCTION__; -#if defined(WEBRTC_IOS) return webrtc::make_ref_counted( env, bypass_voice_processing, muted_speech_event_handler, error_handler); -#else - RTC_LOG(LS_ERROR) - << "current platform is not supported => this module will self destruct!"; - return nullptr; -#endif } +#endif } // namespace webrtc diff --git a/sdk/objc/native/src/objc_desktop_capture.h b/sdk/objc/native/src/objc_desktop_capture.h index b9ca6c9759..49c6c8bba7 100644 --- a/sdk/objc/native/src/objc_desktop_capture.h +++ b/sdk/objc/native/src/objc_desktop_capture.h @@ -21,8 +21,8 @@ #include "api/video/i420_buffer.h" #include "api/video/video_frame.h" -#include "modules/desktop_capture/desktop_capture_options.h" #include "modules/desktop_capture/desktop_and_cursor_composer.h" +#include "modules/desktop_capture/desktop_capture_options.h" #include "modules/desktop_capture/desktop_frame.h" #include "rtc_base/thread.h" @@ -35,12 +35,13 @@ enum DesktopType { kScreen, kWindow }; class ObjCDesktopCapturer : public DesktopCapturer::Callback { public: - enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED}; + enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED }; public: - ObjCDesktopCapturer(DesktopType type, - webrtc::DesktopCapturer::SourceId source_id, - id delegate); + ObjCDesktopCapturer( + DesktopType type, + webrtc::DesktopCapturer::SourceId source_id, + id delegate); virtual ~ObjCDesktopCapturer(); virtual CaptureState Start(uint32_t fps); @@ -50,19 +51,22 @@ class ObjCDesktopCapturer : public DesktopCapturer::Callback { virtual bool IsRunning(); protected: - virtual void OnCaptureResult(webrtc::DesktopCapturer::Result result, - std::unique_ptr frame) override; + virtual void OnCaptureResult( + webrtc::DesktopCapturer::Result result, + std::unique_ptr frame) override; + private: void CaptureFrame(); webrtc::DesktopCaptureOptions options_; std::unique_ptr capturer_; - std::unique_ptr thread_; + std::unique_ptr thread_; CaptureState capture_state_ = CS_STOPPED; DesktopType type_; webrtc::DesktopCapturer::SourceId source_id_; id delegate_; - uint32_t capture_delay_ = 1000; // 1s - webrtc::DesktopCapturer::Result result_ = webrtc::DesktopCapturer::Result::SUCCESS; + uint32_t capture_delay_ = 1000; // 1s + webrtc::DesktopCapturer::Result result_ = + webrtc::DesktopCapturer::Result::SUCCESS; }; } // namespace webrtc diff --git a/sdk/objc/native/src/objc_desktop_capture.mm b/sdk/objc/native/src/objc_desktop_capture.mm index ca43f6afd3..7ab8e06bb2 100644 --- a/sdk/objc/native/src/objc_desktop_capture.mm +++ b/sdk/objc/native/src/objc_desktop_capture.mm @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "sdk/objc/native/src/objc_desktop_capture.h" #include "api/sequence_checker.h" #include "rtc_base/checks.h" -#include "sdk/objc/native/src/objc_desktop_capture.h" #include "sdk/objc/native/src/objc_video_frame.h" #include "third_party/libyuv/include/libyuv.h" @@ -27,10 +27,13 @@ enum { kCaptureDelay = 33, kCaptureMessageId = 1000 }; -ObjCDesktopCapturer::ObjCDesktopCapturer(DesktopType type, - webrtc::DesktopCapturer::SourceId source_id, - id delegate) - : thread_(rtc::Thread::Create()), source_id_(source_id), delegate_(delegate) { +ObjCDesktopCapturer::ObjCDesktopCapturer( + DesktopType type, + webrtc::DesktopCapturer::SourceId source_id, + id delegate) + : thread_(webrtc::Thread::Create()), + source_id_(source_id), + delegate_(delegate) { RTC_DCHECK(thread_); type_ = type; thread_->Start(); @@ -49,17 +52,15 @@ } ObjCDesktopCapturer::~ObjCDesktopCapturer() { - thread_->BlockingCall([this] { - capturer_.reset(); - }); + thread_->BlockingCall([this] { capturer_.reset(); }); } ObjCDesktopCapturer::CaptureState ObjCDesktopCapturer::Start(uint32_t fps) { - if(capture_state_ == CS_RUNNING) { + if (capture_state_ == CS_RUNNING) { return capture_state_; } - if(fps == 0) { + if (fps == 0) { capture_state_ = CS_FAILED; return capture_state_; } @@ -83,14 +84,10 @@ } } - thread_->BlockingCall([this] { - capturer_->Start(this); - }); + thread_->BlockingCall([this] { capturer_->Start(this); }); capture_state_ = CS_RUNNING; - thread_->PostTask([this] { - CaptureFrame(); - }); + thread_->PostTask([this] { CaptureFrame(); }); [delegate_ didSourceCaptureStart]; return capture_state_; @@ -105,8 +102,9 @@ return capture_state_ == CS_RUNNING; } -void ObjCDesktopCapturer::OnCaptureResult(webrtc::DesktopCapturer::Result result, - std::unique_ptr frame) { +void ObjCDesktopCapturer::OnCaptureResult( + webrtc::DesktopCapturer::Result result, + std::unique_ptr frame) { if (result != result_) { if (result == webrtc::DesktopCapturer::Result::ERROR_PERMANENT) { [delegate_ didSourceCaptureError]; @@ -150,13 +148,15 @@ CVPixelBufferRef pixelBuffer = NULL; - NSDictionary *pixelAttributes = @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{}}; - CVReturn res = CVPixelBufferCreate(kCFAllocatorDefault, - width, - height, - kCVPixelFormatType_32BGRA, - (__bridge CFDictionaryRef)(pixelAttributes), - &pixelBuffer); + NSDictionary *pixelAttributes = + @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{}}; + CVReturn res = + CVPixelBufferCreate(kCFAllocatorDefault, + width, + height, + kCVPixelFormatType_32BGRA, + (__bridge CFDictionaryRef)(pixelAttributes), + &pixelBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); uint8_t *pxdata = (uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer); libyuv::ConvertToARGB(reinterpret_cast(frame->data()), @@ -182,10 +182,10 @@ [[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:pixelBuffer]; NSTimeInterval timeStampSeconds = CACurrentMediaTime(); int64_t timeStampNs = lroundf(timeStampSeconds * NSEC_PER_SEC); - RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame = - [[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:rtcPixelBuffer - rotation:RTC_OBJC_TYPE(RTCVideoRotation_0) - timeStampNs:timeStampNs]; + RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame = [[RTC_OBJC_TYPE(RTCVideoFrame) + alloc] initWithBuffer:rtcPixelBuffer + rotation:RTC_OBJC_TYPE(RTCVideoRotation_0) + timeStampNs:timeStampNs]; CVPixelBufferRelease(pixelBuffer); [delegate_ didCaptureVideoFrame:videoFrame]; } @@ -194,11 +194,8 @@ RTC_DCHECK_RUN_ON(thread_.get()); if (capture_state_ == CS_RUNNING) { capturer_->CaptureFrame(); - thread_->PostDelayedHighPrecisionTask( - [this]() { - CaptureFrame(); - }, - TimeDelta::Millis(capture_delay_)); + thread_->PostDelayedHighPrecisionTask([this]() { CaptureFrame(); }, + TimeDelta::Millis(capture_delay_)); } } diff --git a/sdk/objc/native/src/objc_desktop_media_list.h b/sdk/objc/native/src/objc_desktop_media_list.h index ecb2d27221..d17e49c872 100644 --- a/sdk/objc/native/src/objc_desktop_media_list.h +++ b/sdk/objc/native/src/objc_desktop_media_list.h @@ -17,24 +17,23 @@ #ifndef SDK_OBJC_NATIVE_SRC_OBJC_DESKTOP_MEDIA_LIST_H_ #define SDK_OBJC_NATIVE_SRC_OBJC_DESKTOP_MEDIA_LIST_H_ -#import "base/RTCMacros.h" - #include "api/video/i420_buffer.h" #include "api/video/video_frame.h" +#import "base/RTCMacros.h" +#import "components/capturer/RTCDesktopMediaList+Private.h" #include "modules/desktop_capture/desktop_capture_options.h" #include "modules/desktop_capture/desktop_capturer.h" #include "modules/desktop_capture/desktop_frame.h" -#include "rtc_base/thread.h" - #include "objc_desktop_capture.h" - -#import "components/capturer/RTCDesktopMediaList+Private.h" +#include "rtc_base/thread.h" namespace webrtc { class MediaSource { public: - MediaSource( ObjCDesktopMediaList *mediaList, DesktopCapturer::Source src, DesktopType type) + MediaSource(ObjCDesktopMediaList* mediaList, + DesktopCapturer::Source src, + DesktopType type) : source(src), mediaList_(mediaList), type_(type) {} virtual ~MediaSource() {} @@ -49,8 +48,6 @@ class MediaSource { // Returns the thumbnail of the source, jpeg format. std::vector thumbnail() const { return thumbnail_; } - - DesktopType type() const { return type_; } bool UpdateThumbnail(); @@ -60,49 +57,58 @@ class MediaSource { private: std::vector thumbnail_; - ObjCDesktopMediaList *mediaList_; + ObjCDesktopMediaList* mediaList_; DesktopType type_; }; class ObjCDesktopMediaList { public: - enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED}; + enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED }; + public: - ObjCDesktopMediaList(DesktopType type, RTC_OBJC_TYPE(RTCDesktopMediaList)* objcMediaList); + ObjCDesktopMediaList(DesktopType type, + RTC_OBJC_TYPE(RTCDesktopMediaList) * objcMediaList); virtual ~ObjCDesktopMediaList(); - virtual int32_t UpdateSourceList(bool force_reload = false, bool get_thumbnail = true); + virtual int32_t UpdateSourceList(bool force_reload = false, + bool get_thumbnail = true); virtual int GetSourceCount() const; - + virtual MediaSource* GetSource(int index); - virtual bool GetThumbnail(MediaSource *source, bool notify); + virtual bool GetThumbnail(MediaSource* source, bool notify); private: - class CallbackProxy : public DesktopCapturer::Callback { - public: - CallbackProxy(){} - void SetCallback(std::function frame)> on_capture_result) { - on_capture_result_ = on_capture_result; - } - private: - void OnCaptureResult(webrtc::DesktopCapturer::Result result, - std::unique_ptr frame) override { - if(on_capture_result_) on_capture_result_(result, std::move(frame)); - } + class CallbackProxy : public DesktopCapturer::Callback { + public: + CallbackProxy() {} + void SetCallback( std::function frame)> on_capture_result_ = nullptr; - }; + std::unique_ptr frame)> + on_capture_result) { + on_capture_result_ = on_capture_result; + } + + private: + void OnCaptureResult(webrtc::DesktopCapturer::Result result, + std::unique_ptr frame) override { + if (on_capture_result_) + on_capture_result_(result, std::move(frame)); + } + std::function frame)> + on_capture_result_ = nullptr; + }; + private: std::unique_ptr callback_; webrtc::DesktopCaptureOptions options_; std::unique_ptr capturer_; - std::unique_ptr thread_; + std::unique_ptr thread_; std::vector> sources_; - RTC_OBJC_TYPE(RTCDesktopMediaList)* objcMediaList_; + RTC_OBJC_TYPE(RTCDesktopMediaList) * objcMediaList_; DesktopType type_; }; diff --git a/sdk/objc/native/src/objc_desktop_media_list.mm b/sdk/objc/native/src/objc_desktop_media_list.mm index cb783737a2..b269159bfa 100644 --- a/sdk/objc/native/src/objc_desktop_media_list.mm +++ b/sdk/objc/native/src/objc_desktop_media_list.mm @@ -36,8 +36,11 @@ namespace webrtc { ObjCDesktopMediaList::ObjCDesktopMediaList(DesktopType type, - RTC_OBJC_TYPE(RTCDesktopMediaList) * objcMediaList) - : thread_(rtc::Thread::Create()), objcMediaList_(objcMediaList), type_(type) { + RTC_OBJC_TYPE(RTCDesktopMediaList) * + objcMediaList) + : thread_(webrtc::Thread::Create()), + objcMediaList_(objcMediaList), + type_(type) { RTC_DCHECK(thread_); thread_->Start(); options_ = webrtc::DesktopCaptureOptions::CreateDefault(); @@ -47,7 +50,7 @@ callback_ = std::make_unique(); thread_->BlockingCall([this, type] { - if (type == kScreen) { + if (type == kScreen) { capturer_ = webrtc::DesktopCapturer::CreateScreenCapturer(options_); } else { capturer_ = webrtc::DesktopCapturer::CreateWindowCapturer(options_); @@ -57,12 +60,11 @@ } ObjCDesktopMediaList::~ObjCDesktopMediaList() { - thread_->BlockingCall([this] { - capturer_.reset(); - }); + thread_->BlockingCall([this] { capturer_.reset(); }); } -int32_t ObjCDesktopMediaList::UpdateSourceList(bool force_reload, bool get_thumbnail) { +int32_t ObjCDesktopMediaList::UpdateSourceList(bool force_reload, + bool get_thumbnail) { if (force_reload) { for (auto source : sources_) { [objcMediaList_ mediaSourceRemoved:source.get()]; @@ -72,9 +74,8 @@ webrtc::DesktopCapturer::SourceList new_sources; - thread_->BlockingCall([this, &new_sources] { - capturer_->GetSourceList(&new_sources); - }); + thread_->BlockingCall( + [this, &new_sources] { capturer_->GetSourceList(&new_sources); }); typedef std::set SourceSet; SourceSet new_source_set; @@ -101,7 +102,8 @@ for (size_t i = 0; i < new_sources.size(); ++i) { if (old_source_set.find(new_sources[i].id) == old_source_set.end()) { MediaSource *source = new MediaSource(this, new_sources[i], type_); - sources_.insert(sources_.begin() + i, std::shared_ptr(source)); + sources_.insert(sources_.begin() + i, + std::shared_ptr(source)); [objcMediaList_ mediaSourceAdded:source]; GetThumbnail(source, true); } @@ -146,17 +148,17 @@ bool ObjCDesktopMediaList::GetThumbnail(MediaSource *source, bool notify) { thread_->PostTask([this, source, notify] { - if(capturer_->SelectSource(source->id())){ - callback_->SetCallback([&](webrtc::DesktopCapturer::Result result, - std::unique_ptr frame) { - auto old_thumbnail = source->thumbnail(); - source->SaveCaptureResult(result, std::move(frame)); - if(old_thumbnail.size() != source->thumbnail().size() && notify) { - [objcMediaList_ mediaSourceThumbnailChanged:source]; - } - }); - capturer_->CaptureFrame(); - } + if (capturer_->SelectSource(source->id())) { + callback_->SetCallback([&](webrtc::DesktopCapturer::Result result, + std::unique_ptr frame) { + auto old_thumbnail = source->thumbnail(); + source->SaveCaptureResult(result, std::move(frame)); + if (old_thumbnail.size() != source->thumbnail().size() && notify) { + [objcMediaList_ mediaSourceThumbnailChanged:source]; + } + }); + capturer_->CaptureFrame(); + } }); return true; @@ -174,8 +176,9 @@ return mediaList_->GetThumbnail(this, true); } -void MediaSource::SaveCaptureResult(webrtc::DesktopCapturer::Result result, - std::unique_ptr frame) { +void MediaSource::SaveCaptureResult( + webrtc::DesktopCapturer::Result result, + std::unique_ptr frame) { if (result != webrtc::DesktopCapturer::Result::SUCCESS) { return; } @@ -199,13 +202,15 @@ CVPixelBufferRef pixelBuffer = NULL; - NSDictionary *pixelAttributes = @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{}}; - CVReturn res = CVPixelBufferCreate(kCFAllocatorDefault, - width, - height, - kCVPixelFormatType_32BGRA, - (__bridge CFDictionaryRef)(pixelAttributes), - &pixelBuffer); + NSDictionary *pixelAttributes = + @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{}}; + CVReturn res = + CVPixelBufferCreate(kCFAllocatorDefault, + width, + height, + kCVPixelFormatType_32BGRA, + (__bridge CFDictionaryRef)(pixelAttributes), + &pixelBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); uint8_t *pxdata = (uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer); libyuv::ConvertToARGB(reinterpret_cast(frame->data()), diff --git a/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm b/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm index a6b1f834e6..79312120ee 100644 --- a/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm +++ b/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm @@ -121,8 +121,10 @@ - (void)setUp { - (void)tearDown { [self.delegateMock stopMocking]; [self.deviceMock stopMocking]; + [self.captureConnectionMock stopMocking]; self.delegateMock = nil; self.deviceMock = nil; + self.captureConnectionMock = nil; self.capturer = nil; } @@ -455,10 +457,11 @@ - (void)setUp { - (void)tearDown { [self.delegateMock stopMocking]; [self.deviceMock stopMocking]; + [self.captureSessionMock stopMocking]; self.delegateMock = nil; self.deviceMock = nil; - self.capturer = nil; self.captureSessionMock = nil; + self.capturer = nil; } #pragma mark - test cases diff --git a/sdk/objc/unittests/RTCPeerConnectionFactoryBuilderTest.mm b/sdk/objc/unittests/RTCPeerConnectionFactoryBuilderTest.mm index 115b5e200e..173e1c69b4 100644 --- a/sdk/objc/unittests/RTCPeerConnectionFactoryBuilderTest.mm +++ b/sdk/objc/unittests/RTCPeerConnectionFactoryBuilderTest.mm @@ -9,14 +9,8 @@ */ #import +#import #import -#ifdef __cplusplus -extern "C" { -#endif -#import -#ifdef __cplusplus -} -#endif #import "api/peerconnection/RTCPeerConnectionFactory+Native.h" #import "api/peerconnection/RTCPeerConnectionFactoryBuilder+DefaultComponents.h" #import "api/peerconnection/RTCPeerConnectionFactoryBuilder.h" @@ -28,8 +22,37 @@ #include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_encoder_factory.h" +#include + #include "rtc_base/gunit.h" -#include "rtc_base/system/unused.h" + +namespace { + +id StubInitWithMediaAndDependencies( + RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory, + SEL selector, + webrtc::PeerConnectionFactoryDependencies dependencies) { + return factory; +} + +RTC_OBJC_TYPE(RTCPeerConnectionFactory) * + CreatePeerConnectionFactoryWithStubbedNativeInitializer( + RTCPeerConnectionFactoryBuilder *builder) { + Method initializer = class_getInstanceMethod( + [RTC_OBJC_TYPE(RTCPeerConnectionFactory) class], + @selector(initWithMediaAndDependencies:)); + IMP original_initializer = + method_setImplementation(initializer, + reinterpret_cast( + &StubInitWithMediaAndDependencies)); + @try { + return [builder createPeerConnectionFactory]; + } @finally { + method_setImplementation(initializer, original_initializer); + } +} + +} // namespace @interface RTCPeerConnectionFactoryBuilderTests : XCTestCase @end @@ -37,27 +60,14 @@ @interface RTCPeerConnectionFactoryBuilderTests : XCTestCase @implementation RTCPeerConnectionFactoryBuilderTests - (void)testBuilder { - id factoryMock = - OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]); - OCMExpect([factoryMock alloc]).andReturn(factoryMock); - webrtc::PeerConnectionFactoryDependencies default_deps; - RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] - ignoringNonObjectArgs] initWithMediaAndDependencies:default_deps]); RTCPeerConnectionFactoryBuilder* builder = [[RTCPeerConnectionFactoryBuilder alloc] init]; RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory = - [builder createPeerConnectionFactory]; + CreatePeerConnectionFactoryWithStubbedNativeInitializer(builder); EXPECT_TRUE(peerConnectionFactory != nil); - OCMVerifyAll(factoryMock); } - (void)testAudioDeviceModuleBuilder { - id factoryMock = - OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]); - OCMExpect([factoryMock alloc]).andReturn(factoryMock); - webrtc::PeerConnectionFactoryDependencies default_deps; - RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] - ignoringNonObjectArgs] initWithMediaAndDependencies:default_deps]); RTCPeerConnectionFactoryBuilder* builder = [RTCPeerConnectionFactoryBuilder builder]; __block int calledAdmBuilder = 0; @@ -66,24 +76,16 @@ - (void)testAudioDeviceModuleBuilder { return webrtc::scoped_refptr(nullptr); }]; RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory = - [builder createPeerConnectionFactory]; + CreatePeerConnectionFactoryWithStubbedNativeInitializer(builder); EXPECT_TRUE(peerConnectionFactory != nil); EXPECT_EQ(calledAdmBuilder, 1); - OCMVerifyAll(factoryMock); } - (void)testDefaultComponentsBuilder { - id factoryMock = - OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]); - OCMExpect([factoryMock alloc]).andReturn(factoryMock); - webrtc::PeerConnectionFactoryDependencies default_deps; - RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] - ignoringNonObjectArgs] initWithMediaAndDependencies:default_deps]); RTCPeerConnectionFactoryBuilder* builder = [RTCPeerConnectionFactoryBuilder defaultBuilder]; RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory = - [builder createPeerConnectionFactory]; + CreatePeerConnectionFactoryWithStubbedNativeInitializer(builder); EXPECT_TRUE(peerConnectionFactory != nil); - OCMVerifyAll(factoryMock); } @end diff --git a/webrtc.gni b/webrtc.gni index 15966b93ce..adf150604f 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -562,6 +562,14 @@ template("rtc_test") { } } + if (!build_with_chromium && rtc_include_tests && + (!defined(invoker.is_xctest) || !invoker.is_xctest)) { + if (!defined(deps)) { + deps = [] + } + deps += [ webrtc_root + "test:test_main" ] + } + assert( !defined(absl_deps), "`absl_deps` has been deprecated, add your Abseil dependencies to the `deps` variable.") @@ -1177,7 +1185,7 @@ if (is_mac || is_ios) { deps = [ ":create_bracket_include_headers_$this_target_name" ] } - if (is_mac || target_environment == "catalyst") { + if (is_mac) { headers_dir = "Versions/A/Headers" copy("copy_umbrella_header_$target_name") { sources = [ umbrella_header_path ]