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 SoftwareVideoDecoderFactory}. */ 22 public class SoftwareVideoDecoderFactoryTest { 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 VideoDecoderFactory factory = new SoftwareVideoDecoderFactory(); 32 VideoCodecInfo[] codecs = factory.getSupportedCodecs(); 33 assertThat(codecs.length).isEqualTo(6); 34 assertThat(codecs[0].name).isEqualTo("VP8"); 35 assertThat(codecs[1].name).isEqualTo("VP9"); 36 assertThat(codecs[2].name).isEqualTo("VP9"); 37 assertThat(codecs[3].name).isEqualTo("VP9"); 38 assertThat(codecs[4].name).isEqualTo("AV1"); 39 assertThat(codecs[5].name).isEqualTo("AV1"); 40 } 41 42 @SmallTest 43 @Test createDecoder_supportedCodec_returnsNotNull()44 public void createDecoder_supportedCodec_returnsNotNull() { 45 VideoDecoderFactory factory = new SoftwareVideoDecoderFactory(); 46 VideoCodecInfo[] codecs = factory.getSupportedCodecs(); 47 assertThat(codecs.length).isGreaterThan(0); 48 for (VideoCodecInfo codec : codecs) { 49 VideoDecoder decoder = factory.createDecoder(codec); 50 assertThat(decoder).isNotNull(); 51 } 52 } 53 54 @SmallTest 55 @Test createDecoder_unsupportedCodec_returnsNull()56 public void createDecoder_unsupportedCodec_returnsNull() { 57 VideoDecoderFactory factory = new SoftwareVideoDecoderFactory(); 58 VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>()); 59 VideoDecoder decoder = factory.createDecoder(codec); 60 assertThat(decoder).isNull(); 61 } 62 } 63