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 SoftwareVideoDecoderFactory implements VideoDecoderFactory { 18 private static final String TAG = "SoftwareVideoDecoderFactory"; 19 20 private final long nativeFactory; 21 SoftwareVideoDecoderFactory()22 public SoftwareVideoDecoderFactory() { 23 this.nativeFactory = nativeCreateFactory(); 24 } 25 26 @Nullable 27 @Override createDecoder(VideoCodecInfo info)28 public VideoDecoder createDecoder(VideoCodecInfo info) { 29 long nativeDecoder = nativeCreateDecoder(nativeFactory, info); 30 if (nativeDecoder == 0) { 31 Logging.w(TAG, "Trying to create decoder for unsupported format. " + info); 32 return null; 33 } 34 35 return new WrappedNativeVideoDecoder() { 36 @Override 37 public long createNativeVideoDecoder() { 38 return nativeDecoder; 39 } 40 }; 41 } 42 43 @Override 44 public VideoCodecInfo[] getSupportedCodecs() { 45 return nativeGetSupportedCodecs(nativeFactory).toArray(new VideoCodecInfo[0]); 46 } 47 48 private static native long nativeCreateFactory(); 49 50 private static native long nativeCreateDecoder(long factory, VideoCodecInfo videoCodecInfo); 51 52 private static native List<VideoCodecInfo> nativeGetSupportedCodecs(long factory); 53 } 54