-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathCreateVideoCodecFactory.cpp
More file actions
109 lines (97 loc) · 3.01 KB
/
CreateVideoCodecFactory.cpp
File metadata and controls
109 lines (97 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "pch.h"
#include <media/engine/internal_decoder_factory.h>
#include <media/engine/internal_encoder_factory.h>
#include "CreateVideoCodecFactory.h"
#include "GraphicsDevice/IGraphicsDevice.h"
#include "ProfilerMarkerFactory.h"
#if CUDA_PLATFORM
#include "Codec/NvCodec/NvCodec.h"
#include "SimulcastEncoderFactory.h"
#endif
#if UNITY_OSX || UNITY_IOS
#import <sdk/objc/components/video_codec/RTCVideoDecoderFactoryH264.h>
#import <sdk/objc/components/video_codec/RTCVideoEncoderFactoryH264.h>
#import <sdk/objc/native/api/video_decoder_factory.h>
#import <sdk/objc/native/api/video_encoder_factory.h>
#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 && gfxDevice->IsCudaSupport())
{
CUcontext context = gfxDevice->GetCUcontext();
if (NvEncoder::IsSupported(context))
{
NV_ENC_BUFFER_FORMAT format = gfxDevice->GetEncodeBufferFormat();
std::unique_ptr<VideoEncoderFactory> factory =
std::make_unique<NvEncoderFactory>(context, format, profiler);
return CreateSimulcastEncoderFactory(std::move(factory));
}
}
#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 && gfxDevice->IsCudaSupport())
{
CUcontext context = gfxDevice->GetCUcontext();
return new NvDecoderFactory(context, profiler);
}
#endif
}
return nullptr;
}
}
}