• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static org.junit.Assert.assertEquals;
14 
15 import androidx.annotation.Nullable;
16 import androidx.test.filters.SmallTest;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import org.junit.Before;
20 import org.junit.Test;
21 
22 /** Unit tests for {@link DefaultVideoEncoderFactory}. */
23 public class DefaultVideoEncoderFactoryTest {
24   static class CustomHardwareVideoEncoderFactory implements VideoEncoderFactory {
25     private VideoCodecInfo supportedCodec;
26 
CustomHardwareVideoEncoderFactory(VideoCodecInfo supportedCodec)27     public CustomHardwareVideoEncoderFactory(VideoCodecInfo supportedCodec) {
28       this.supportedCodec = supportedCodec;
29     }
30 
31     @Override
createEncoder(VideoCodecInfo info)32     public @Nullable VideoEncoder createEncoder(VideoCodecInfo info) {
33       return null;
34     }
35 
36     @Override
getSupportedCodecs()37     public VideoCodecInfo[] getSupportedCodecs() {
38       return new VideoCodecInfo[] {supportedCodec};
39     }
40   }
41 
42   @Before
setUp()43   public void setUp() {
44     NativeLibrary.initialize(new NativeLibrary.DefaultLoader(), TestConstants.NATIVE_LIBRARY);
45   }
46 
47   @SmallTest
48   @Test
getSupportedCodecs_hwVp8SameParamsAsSwVp8_oneVp8()49   public void getSupportedCodecs_hwVp8SameParamsAsSwVp8_oneVp8() {
50     VideoCodecInfo hwVp8Encoder = new VideoCodecInfo("VP8", new HashMap<>());
51     VideoEncoderFactory hwFactory = new CustomHardwareVideoEncoderFactory(hwVp8Encoder);
52     DefaultVideoEncoderFactory defFactory = new DefaultVideoEncoderFactory(hwFactory);
53     VideoCodecInfo[] supportedCodecs = defFactory.getSupportedCodecs();
54     assertEquals(3, supportedCodecs.length);
55     assertEquals("VP8", supportedCodecs[0].name);
56     assertEquals("AV1", supportedCodecs[1].name);
57     assertEquals("VP9", supportedCodecs[2].name);
58   }
59 
60   @SmallTest
61   @Test
getSupportedCodecs_hwVp8WithDifferentParams_twoVp8()62   public void getSupportedCodecs_hwVp8WithDifferentParams_twoVp8() {
63     VideoCodecInfo hwVp8Encoder = new VideoCodecInfo("VP8", new HashMap<String, String>() {
64       { put("param", "value"); }
65     });
66     VideoEncoderFactory hwFactory = new CustomHardwareVideoEncoderFactory(hwVp8Encoder);
67     DefaultVideoEncoderFactory defFactory = new DefaultVideoEncoderFactory(hwFactory);
68     VideoCodecInfo[] supportedCodecs = defFactory.getSupportedCodecs();
69     assertEquals(4, supportedCodecs.length);
70     assertEquals("VP8", supportedCodecs[0].name);
71     assertEquals("AV1", supportedCodecs[1].name);
72     assertEquals("VP9", supportedCodecs[2].name);
73     assertEquals("VP8", supportedCodecs[3].name);
74     assertEquals(1, supportedCodecs[3].params.size());
75     assertEquals("value", supportedCodecs[3].params.get("param"));
76   }
77 }
78