1 /* 2 * Copyright 2022 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 static com.google.common.truth.Truth.assertThat; 14 15 import androidx.annotation.Nullable; 16 import androidx.test.filters.SmallTest; 17 import java.util.HashMap; 18 import org.junit.Before; 19 import org.junit.Test; 20 21 /** Unit tests for {@link SoftwareVideoEncoderFactory}. */ 22 public class SoftwareVideoEncoderFactoryTest { 23 @Before setUp()24 public void setUp() { 25 NativeLibrary.initialize(new NativeLibrary.DefaultLoader(), TestConstants.NATIVE_LIBRARY); 26 } 27 28 @SmallTest 29 @Test getSupportedCodecs_returnsDefaultCodecs()30 public void getSupportedCodecs_returnsDefaultCodecs() { 31 VideoEncoderFactory factory = new SoftwareVideoEncoderFactory(); 32 VideoCodecInfo[] codecs = factory.getSupportedCodecs(); 33 assertThat(codecs.length).isEqualTo(3); 34 assertThat(codecs[0].name).isEqualTo("VP8"); 35 assertThat(codecs[1].name).isEqualTo("AV1"); 36 assertThat(codecs[2].name).isEqualTo("VP9"); 37 } 38 39 @SmallTest 40 @Test createEncoder_supportedCodec_returnsNotNull()41 public void createEncoder_supportedCodec_returnsNotNull() { 42 VideoEncoderFactory factory = new SoftwareVideoEncoderFactory(); 43 VideoCodecInfo[] codecs = factory.getSupportedCodecs(); 44 assertThat(codecs.length).isGreaterThan(0); 45 for (VideoCodecInfo codec : codecs) { 46 VideoEncoder encoder = factory.createEncoder(codec); 47 assertThat(encoder).isNotNull(); 48 } 49 } 50 51 @SmallTest 52 @Test createEncoder_unsupportedCodec_returnsNull()53 public void createEncoder_unsupportedCodec_returnsNull() { 54 VideoEncoderFactory factory = new SoftwareVideoEncoderFactory(); 55 VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>()); 56 VideoEncoder encoder = factory.createEncoder(codec); 57 assertThat(encoder).isNull(); 58 } 59 } 60