1
+ package org .webrtc ;
2
+
3
+ import androidx .annotation .Nullable ;
4
+
5
+ import java .util .Arrays ;
6
+ import java .util .LinkedHashSet ;
7
+
8
+ public class AMSDefaultVideoDecoderFactory implements VideoDecoderFactory {
9
+ private final VideoDecoderFactory hardwareVideoDecoderFactory ;
10
+ private final VideoDecoderFactory softwareVideoDecoderFactory = new SoftwareVideoDecoderFactory ();
11
+ private final @ Nullable VideoDecoderFactory platformSoftwareVideoDecoderFactory ;
12
+
13
+ /**
14
+ * Create decoder factory using default hardware decoder factory.
15
+ */
16
+ public AMSDefaultVideoDecoderFactory (@ Nullable EglBase .Context eglContext ) {
17
+ this .hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory (eglContext );
18
+ this .platformSoftwareVideoDecoderFactory = new PlatformSoftwareVideoDecoderFactory (eglContext );
19
+ }
20
+
21
+ /**
22
+ * Create decoder factory using explicit hardware decoder factory.
23
+ */
24
+ AMSDefaultVideoDecoderFactory (VideoDecoderFactory hardwareVideoDecoderFactory ) {
25
+ this .hardwareVideoDecoderFactory = hardwareVideoDecoderFactory ;
26
+ this .platformSoftwareVideoDecoderFactory = null ;
27
+ }
28
+
29
+ @ Override
30
+ public @ Nullable VideoDecoder createDecoder (VideoCodecInfo codecType ) {
31
+ VideoDecoder softwareDecoder = softwareVideoDecoderFactory .createDecoder (codecType );
32
+ final VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory .createDecoder (codecType );
33
+ if (softwareDecoder == null && platformSoftwareVideoDecoderFactory != null ) {
34
+ softwareDecoder = platformSoftwareVideoDecoderFactory .createDecoder (codecType );
35
+ }
36
+ if (hardwareDecoder != null && softwareDecoder != null ) {
37
+ // Both hardware and software supported, wrap it in a software fallback
38
+ return new VideoDecoderFallback (
39
+ /* fallback= */ softwareDecoder , /* primary= */ hardwareDecoder );
40
+ }
41
+ return hardwareDecoder != null ? hardwareDecoder : softwareDecoder ;
42
+ }
43
+
44
+ @ Override
45
+ public VideoCodecInfo [] getSupportedCodecs () {
46
+ LinkedHashSet <VideoCodecInfo > supportedCodecInfos = new LinkedHashSet <VideoCodecInfo >();
47
+
48
+ supportedCodecInfos .addAll (Arrays .asList (softwareVideoDecoderFactory .getSupportedCodecs ()));
49
+ supportedCodecInfos .addAll (Arrays .asList (hardwareVideoDecoderFactory .getSupportedCodecs ()));
50
+ if (platformSoftwareVideoDecoderFactory != null ) {
51
+ supportedCodecInfos .addAll (
52
+ Arrays .asList (platformSoftwareVideoDecoderFactory .getSupportedCodecs ()));
53
+ }
54
+
55
+ return supportedCodecInfos .toArray (new VideoCodecInfo [supportedCodecInfos .size ()]);
56
+ }
57
+ }
0 commit comments