#include "pch.h" #include #include #include "CreateVideoCodecFactory.h" #include "GraphicsDevice/IGraphicsDevice.h" #include "ProfilerMarkerFactory.h" #if CUDA_PLATFORM #include "Codec/NvCodec/NvCodec.h" #endif #if UNITY_OSX || UNITY_IOS #import #import #import #import #elif UNITY_ANDROID #include "Android/AndroidCodecFactoryHelper.h" #include "Android/Jni.h" #endif namespace unity { namespace webrtc { VideoEncoderFactory* CreateVideoEncoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler) { if (impl == kInternalImpl) { return new webrtc::InternalEncoderFactory(); } if (impl == kVideoToolboxImpl) { #if UNITY_OSX || UNITY_IOS return webrtc::ObjCToNativeVideoEncoderFactory([[RTCVideoEncoderFactoryH264 alloc] init]).release(); #endif } if (impl == kAndroidMediaCodecImpl) { #if UNITY_ANDROID if (IsVMInitialized()) { return CreateAndroidEncoderFactory().release(); } #endif } if (impl == kNvCodecImpl) { #if CUDA_PLATFORM if (gfxDevice->IsCudaSupport() && NvEncoder::IsSupported()) { CUcontext context = gfxDevice->GetCUcontext(); NV_ENC_BUFFER_FORMAT format = gfxDevice->GetEncodeBufferFormat(); return new NvEncoderFactory(context, format, profiler); } #endif } return nullptr; } VideoDecoderFactory* CreateVideoDecoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler) { if (impl == kInternalImpl) { return new webrtc::InternalDecoderFactory(); } if (impl == kVideoToolboxImpl) { #if UNITY_OSX || UNITY_IOS return webrtc::ObjCToNativeVideoDecoderFactory([[RTCVideoDecoderFactoryH264 alloc] init]).release(); #endif } if (impl == kAndroidMediaCodecImpl) { #if UNITY_ANDROID if (IsVMInitialized()) return CreateAndroidDecoderFactory().release(); #endif } if (impl == kNvCodecImpl) { #if CUDA_PLATFORM if (gfxDevice->IsCudaSupport()) { CUcontext context = gfxDevice->GetCUcontext(); return new NvDecoderFactory(context, profiler); } #endif } return nullptr; } } }