1 /*
2  *  Copyright (c) 2018 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 "api/video/video_bitrate_allocation.h"
12 
13 #include <vector>
14 
15 #include "absl/types/optional.h"
16 #include "test/gtest.h"
17 
18 namespace webrtc {
TEST(VideoBitrateAllocation,SimulcastTargetBitrate)19 TEST(VideoBitrateAllocation, SimulcastTargetBitrate) {
20   VideoBitrateAllocation bitrate;
21   bitrate.SetBitrate(0, 0, 10000);
22   bitrate.SetBitrate(0, 1, 20000);
23   bitrate.SetBitrate(1, 0, 40000);
24   bitrate.SetBitrate(1, 1, 80000);
25 
26   VideoBitrateAllocation layer0_bitrate;
27   layer0_bitrate.SetBitrate(0, 0, 10000);
28   layer0_bitrate.SetBitrate(0, 1, 20000);
29 
30   VideoBitrateAllocation layer1_bitrate;
31   layer1_bitrate.SetBitrate(0, 0, 40000);
32   layer1_bitrate.SetBitrate(0, 1, 80000);
33 
34   std::vector<absl::optional<VideoBitrateAllocation>> layer_allocations =
35       bitrate.GetSimulcastAllocations();
36 
37   EXPECT_EQ(layer0_bitrate, layer_allocations[0]);
38   EXPECT_EQ(layer1_bitrate, layer_allocations[1]);
39 }
40 
TEST(VideoBitrateAllocation,SimulcastTargetBitrateWithInactiveStream)41 TEST(VideoBitrateAllocation, SimulcastTargetBitrateWithInactiveStream) {
42   // Create bitrate allocation with bitrate only for the first and third stream.
43   VideoBitrateAllocation bitrate;
44   bitrate.SetBitrate(0, 0, 10000);
45   bitrate.SetBitrate(0, 1, 20000);
46   bitrate.SetBitrate(2, 0, 40000);
47   bitrate.SetBitrate(2, 1, 80000);
48 
49   VideoBitrateAllocation layer0_bitrate;
50   layer0_bitrate.SetBitrate(0, 0, 10000);
51   layer0_bitrate.SetBitrate(0, 1, 20000);
52 
53   VideoBitrateAllocation layer2_bitrate;
54   layer2_bitrate.SetBitrate(0, 0, 40000);
55   layer2_bitrate.SetBitrate(0, 1, 80000);
56 
57   std::vector<absl::optional<VideoBitrateAllocation>> layer_allocations =
58       bitrate.GetSimulcastAllocations();
59 
60   EXPECT_EQ(layer0_bitrate, layer_allocations[0]);
61   EXPECT_FALSE(layer_allocations[1]);
62   EXPECT_EQ(layer2_bitrate, layer_allocations[2]);
63 }
64 }  // namespace webrtc
65