|
| 1 | +package io.antmedia.webrtcandroidframework.core; |
| 2 | + |
| 3 | +import androidx.annotation.Nullable; |
| 4 | + |
| 5 | +import org.webrtc.EglBase; |
| 6 | +import org.webrtc.HardwareVideoEncoderFactory; |
| 7 | +import org.webrtc.SoftwareVideoEncoderFactory; |
| 8 | +import org.webrtc.VideoCodecInfo; |
| 9 | +import org.webrtc.VideoEncoder; |
| 10 | +import org.webrtc.VideoEncoderFactory; |
| 11 | +import org.webrtc.VideoEncoderFallback; |
| 12 | + |
| 13 | +import java.util.Arrays; |
| 14 | +import java.util.LinkedHashSet; |
| 15 | + |
| 16 | +public class AMSDefaultVideoEncoderFactory implements VideoEncoderFactory { |
| 17 | + private final VideoEncoderFactory hardwareVideoEncoderFactory; |
| 18 | + private final VideoEncoderFactory softwareVideoEncoderFactory = new SoftwareVideoEncoderFactory(); |
| 19 | + |
| 20 | + public AMSDefaultVideoEncoderFactory(EglBase.Context eglContext, boolean enableIntelVp8Encoder, boolean enableH264HighProfile) { |
| 21 | + this.hardwareVideoEncoderFactory = new AMSHardwareVideoEncoderFactory(eglContext, enableIntelVp8Encoder, enableH264HighProfile); |
| 22 | + } |
| 23 | + |
| 24 | + AMSDefaultVideoEncoderFactory(VideoEncoderFactory hardwareVideoEncoderFactory) { |
| 25 | + this.hardwareVideoEncoderFactory = hardwareVideoEncoderFactory; |
| 26 | + } |
| 27 | + |
| 28 | + @Nullable |
| 29 | + public VideoEncoder createEncoder(VideoCodecInfo info) { |
| 30 | + VideoEncoder softwareEncoder = this.softwareVideoEncoderFactory.createEncoder(info); |
| 31 | + VideoEncoder hardwareEncoder = this.hardwareVideoEncoderFactory.createEncoder(info); |
| 32 | + if (hardwareEncoder != null && softwareEncoder != null) { |
| 33 | + return new VideoEncoderFallback(softwareEncoder, hardwareEncoder); |
| 34 | + } else { |
| 35 | + return hardwareEncoder != null ? hardwareEncoder : softwareEncoder; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public VideoCodecInfo[] getSupportedCodecs() { |
| 40 | + LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet(); |
| 41 | + supportedCodecInfos.addAll(Arrays.asList(this.softwareVideoEncoderFactory.getSupportedCodecs())); |
| 42 | + supportedCodecInfos.addAll(Arrays.asList(this.hardwareVideoEncoderFactory.getSupportedCodecs())); |
| 43 | + return (VideoCodecInfo[])supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]); |
| 44 | + } |
| 45 | +} |
0 commit comments