#include "DarwinInterface.h" #include "VideoCapturerInterfaceImpl.h" #include "sdk/objc/native/src/objc_video_track_source.h" #include "media/base/media_constants.h" #include "TGRTCDefaultVideoEncoderFactory.h" #include "TGRTCDefaultVideoDecoderFactory.h" #include "sdk/objc/native/api/video_encoder_factory.h" #include "sdk/objc/native/api/video_decoder_factory.h" #include "api/video_track_source_proxy.h" #ifdef WEBRTC_IOS #include "sdk/objc/components/audio/RTCAudioSession.h" #endif // WEBRTC_IOS #import namespace tgcalls { static webrtc::ObjCVideoTrackSource *getObjCVideoSource(const rtc::scoped_refptr nativeSource) { webrtc::VideoTrackSourceProxy *proxy_source = static_cast(nativeSource.get()); return static_cast(proxy_source->internal()); } void DarwinInterface::configurePlatformAudio() { #ifdef WEBRTC_IOS [RTCAudioSession sharedInstance].useManualAudio = true; [[RTCAudioSession sharedInstance] audioSessionDidActivate:[AVAudioSession sharedInstance]]; [RTCAudioSession sharedInstance].isAudioEnabled = true; #endif } float DarwinInterface::getDisplayAspectRatio() { return 0.0f; } std::unique_ptr DarwinInterface::makeVideoEncoderFactory() { return webrtc::ObjCToNativeVideoEncoderFactory([[TGRTCDefaultVideoEncoderFactory alloc] init]); } std::unique_ptr DarwinInterface::makeVideoDecoderFactory() { return webrtc::ObjCToNativeVideoDecoderFactory([[TGRTCDefaultVideoDecoderFactory alloc] init]); } bool DarwinInterface::supportsEncoding(const std::string &codecName) { if (codecName == cricket::kH265CodecName) { #ifdef WEBRTC_IOS if (@available(iOS 11.0, *)) { return [[AVAssetExportSession allExportPresets] containsObject:AVAssetExportPresetHEVCHighestQuality]; } #elif defined WEBRTC_MAC // WEBRTC_IOS if (@available(macOS 10.14, *)) { return [[AVAssetExportSession allExportPresets] containsObject:AVAssetExportPresetHEVCHighestQuality]; } #endif // WEBRTC_IOS || WEBRTC_MAC } else if (codecName == cricket::kH264CodecName) { return true; } else if (codecName == cricket::kVp8CodecName) { return true; } else if (codecName == cricket::kVp9CodecName) { return true; } return false; } rtc::scoped_refptr DarwinInterface::makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread) { rtc::scoped_refptr objCVideoTrackSource(new rtc::RefCountedObject()); return webrtc::VideoTrackSourceProxy::Create(signalingThread, workerThread, objCVideoTrackSource); } void DarwinInterface::adaptVideoSource(rtc::scoped_refptr videoSource, int width, int height, int fps) { getObjCVideoSource(videoSource)->OnOutputFormatRequest(width, height, fps); } std::unique_ptr DarwinInterface::makeVideoCapturer(rtc::scoped_refptr source, bool useFrontCamera, std::function stateUpdated, std::shared_ptr platformContext, std::pair &outResolution) { return std::make_unique(source, useFrontCamera, stateUpdated, outResolution); } std::unique_ptr CreatePlatformInterface() { return std::make_unique(); } } // namespace tgcalls