1 /* 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.webrtc; 12 13 import androidx.annotation.Nullable; 14 import java.util.Arrays; 15 import java.util.List; 16 17 public class SoftwareVideoEncoderFactory implements VideoEncoderFactory { 18 private static final String TAG = "SoftwareVideoEncoderFactory"; 19 20 private final long nativeFactory; 21 SoftwareVideoEncoderFactory()22 public SoftwareVideoEncoderFactory() { 23 this.nativeFactory = nativeCreateFactory(); 24 } 25 26 @Nullable 27 @Override createEncoder(VideoCodecInfo info)28 public VideoEncoder createEncoder(VideoCodecInfo info) { 29 long nativeEncoder = nativeCreateEncoder(nativeFactory, info); 30 if (nativeEncoder == 0) { 31 Logging.w(TAG, "Trying to create encoder for unsupported format. " + info); 32 return null; 33 } 34 35 return new WrappedNativeVideoEncoder() { 36 @Override 37 public long createNativeVideoEncoder() { 38 return nativeEncoder; 39 } 40 41 @Override 42 public boolean isHardwareEncoder() { 43 return false; 44 } 45 }; 46 } 47 48 @Override 49 public VideoCodecInfo[] getSupportedCodecs() { 50 return nativeGetSupportedCodecs(nativeFactory).toArray(new VideoCodecInfo[0]); 51 } 52 53 private static native long nativeCreateFactory(); 54 55 private static native long nativeCreateEncoder(long factory, VideoCodecInfo videoCodecInfo); 56 57 private static native List<VideoCodecInfo> nativeGetSupportedCodecs(long factory); 58 } 59