CreateVideoCodecFactory.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "pch.h"
  2. #include <media/engine/internal_decoder_factory.h>
  3. #include <media/engine/internal_encoder_factory.h>
  4. #include "CreateVideoCodecFactory.h"
  5. #include "GraphicsDevice/IGraphicsDevice.h"
  6. #include "ProfilerMarkerFactory.h"
  7. #if CUDA_PLATFORM
  8. #include "Codec/NvCodec/NvCodec.h"
  9. #endif
  10. #if UNITY_OSX || UNITY_IOS
  11. #import <sdk/objc/components/video_codec/RTCVideoEncoderFactoryH264.h>
  12. #import <sdk/objc/components/video_codec/RTCVideoDecoderFactoryH264.h>
  13. #import <sdk/objc/native/api/video_decoder_factory.h>
  14. #import <sdk/objc/native/api/video_encoder_factory.h>
  15. #elif UNITY_ANDROID
  16. #include "Android/AndroidCodecFactoryHelper.h"
  17. #include "Android/Jni.h"
  18. #endif
  19. namespace unity
  20. {
  21. namespace webrtc
  22. {
  23. VideoEncoderFactory*
  24. CreateVideoEncoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler)
  25. {
  26. if (impl == kInternalImpl)
  27. {
  28. return new webrtc::InternalEncoderFactory();
  29. }
  30. if (impl == kVideoToolboxImpl)
  31. {
  32. #if UNITY_OSX || UNITY_IOS
  33. return webrtc::ObjCToNativeVideoEncoderFactory([[RTCVideoEncoderFactoryH264 alloc] init]).release();
  34. #endif
  35. }
  36. if (impl == kAndroidMediaCodecImpl)
  37. {
  38. #if UNITY_ANDROID
  39. if (IsVMInitialized())
  40. {
  41. return CreateAndroidEncoderFactory().release();
  42. }
  43. #endif
  44. }
  45. if (impl == kNvCodecImpl)
  46. {
  47. #if CUDA_PLATFORM
  48. if (gfxDevice->IsCudaSupport() && NvEncoder::IsSupported())
  49. {
  50. CUcontext context = gfxDevice->GetCUcontext();
  51. NV_ENC_BUFFER_FORMAT format = gfxDevice->GetEncodeBufferFormat();
  52. return new NvEncoderFactory(context, format, profiler);
  53. }
  54. #endif
  55. }
  56. return nullptr;
  57. }
  58. VideoDecoderFactory*
  59. CreateVideoDecoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler)
  60. {
  61. if (impl == kInternalImpl)
  62. {
  63. return new webrtc::InternalDecoderFactory();
  64. }
  65. if (impl == kVideoToolboxImpl)
  66. {
  67. #if UNITY_OSX || UNITY_IOS
  68. return webrtc::ObjCToNativeVideoDecoderFactory([[RTCVideoDecoderFactoryH264 alloc] init]).release();
  69. #endif
  70. }
  71. if (impl == kAndroidMediaCodecImpl)
  72. {
  73. #if UNITY_ANDROID
  74. if (IsVMInitialized())
  75. return CreateAndroidDecoderFactory().release();
  76. #endif
  77. }
  78. if (impl == kNvCodecImpl)
  79. {
  80. #if CUDA_PLATFORM
  81. if (gfxDevice->IsCudaSupport())
  82. {
  83. CUcontext context = gfxDevice->GetCUcontext();
  84. return new NvDecoderFactory(context, profiler);
  85. }
  86. #endif
  87. }
  88. return nullptr;
  89. }
  90. }
  91. }