1 /*
2 * Copyright (c) 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 #include "modules/video_coding/decoder_database.h"
12
13 #include <memory>
14 #include <utility>
15
16 #include "api/test/mock_video_decoder.h"
17 #include "test/gmock.h"
18 #include "test/gtest.h"
19
20 namespace webrtc {
21 namespace {
22
23 using ::testing::NiceMock;
24
25 // Test registering and unregistering an external decoder instance.
TEST(VCMDecoderDatabaseTest,RegisterExternalDecoder)26 TEST(VCMDecoderDatabaseTest, RegisterExternalDecoder) {
27 VCMDecoderDatabase db;
28 constexpr int kPayloadType = 1;
29 ASSERT_FALSE(db.IsExternalDecoderRegistered(kPayloadType));
30
31 auto decoder = std::make_unique<NiceMock<MockVideoDecoder>>();
32 bool decoder_deleted = false;
33 EXPECT_CALL(*decoder, Destruct).WillOnce([&decoder_deleted] {
34 decoder_deleted = true;
35 });
36
37 db.RegisterExternalDecoder(kPayloadType, std::move(decoder));
38 EXPECT_TRUE(db.IsExternalDecoderRegistered(kPayloadType));
39 db.DeregisterExternalDecoder(kPayloadType);
40 EXPECT_TRUE(decoder_deleted);
41 EXPECT_FALSE(db.IsExternalDecoderRegistered(kPayloadType));
42 }
43
TEST(VCMDecoderDatabaseTest,RegisterReceiveCodec)44 TEST(VCMDecoderDatabaseTest, RegisterReceiveCodec) {
45 VCMDecoderDatabase db;
46 constexpr int kPayloadType = 1;
47 ASSERT_FALSE(db.DeregisterReceiveCodec(kPayloadType));
48
49 VideoDecoder::Settings settings;
50 settings.set_codec_type(kVideoCodecVP8);
51 settings.set_max_render_resolution({10, 10});
52 settings.set_number_of_cores(4);
53 db.RegisterReceiveCodec(kPayloadType, settings);
54
55 EXPECT_TRUE(db.DeregisterReceiveCodec(kPayloadType));
56 }
57
TEST(VCMDecoderDatabaseTest,DeregisterReceiveCodecs)58 TEST(VCMDecoderDatabaseTest, DeregisterReceiveCodecs) {
59 VCMDecoderDatabase db;
60 constexpr int kPayloadType1 = 1;
61 constexpr int kPayloadType2 = 2;
62 ASSERT_FALSE(db.DeregisterReceiveCodec(kPayloadType1));
63 ASSERT_FALSE(db.DeregisterReceiveCodec(kPayloadType2));
64
65 VideoDecoder::Settings settings1;
66 settings1.set_codec_type(kVideoCodecVP8);
67 settings1.set_max_render_resolution({10, 10});
68 settings1.set_number_of_cores(4);
69
70 VideoDecoder::Settings settings2 = settings1;
71 settings2.set_codec_type(kVideoCodecVP9);
72
73 db.RegisterReceiveCodec(kPayloadType1, settings1);
74 db.RegisterReceiveCodec(kPayloadType2, settings2);
75
76 db.DeregisterReceiveCodecs();
77
78 // All receive codecs must have been removed.
79 EXPECT_FALSE(db.DeregisterReceiveCodec(kPayloadType1));
80 EXPECT_FALSE(db.DeregisterReceiveCodec(kPayloadType2));
81 }
82
83 } // namespace
84 } // namespace webrtc
85