xref: /aosp_15_r20/external/webrtc/sdk/media_constraints_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2016 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 "sdk/media_constraints.h"
12 
13 #include "test/gtest.h"
14 
15 namespace webrtc {
16 
17 namespace {
18 
19 // Checks all settings touched by CopyConstraintsIntoRtcConfiguration,
20 // plus audio_jitter_buffer_max_packets.
Matches(const PeerConnectionInterface::RTCConfiguration & a,const PeerConnectionInterface::RTCConfiguration & b)21 bool Matches(const PeerConnectionInterface::RTCConfiguration& a,
22              const PeerConnectionInterface::RTCConfiguration& b) {
23   return a.audio_jitter_buffer_max_packets ==
24              b.audio_jitter_buffer_max_packets &&
25          a.screencast_min_bitrate == b.screencast_min_bitrate &&
26          a.combined_audio_video_bwe == b.combined_audio_video_bwe &&
27          a.media_config == b.media_config;
28 }
29 
TEST(MediaConstraints,CopyConstraintsIntoRtcConfiguration)30 TEST(MediaConstraints, CopyConstraintsIntoRtcConfiguration) {
31   const MediaConstraints constraints_empty;
32   PeerConnectionInterface::RTCConfiguration old_configuration;
33   PeerConnectionInterface::RTCConfiguration configuration;
34 
35   CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration);
36   EXPECT_TRUE(Matches(old_configuration, configuration));
37 
38   const MediaConstraints constraints_screencast(
39       {MediaConstraints::Constraint(MediaConstraints::kScreencastMinBitrate,
40                                     "27")},
41       {});
42   CopyConstraintsIntoRtcConfiguration(&constraints_screencast, &configuration);
43   EXPECT_TRUE(configuration.screencast_min_bitrate);
44   EXPECT_EQ(27, *(configuration.screencast_min_bitrate));
45 
46   // An empty set of constraints will not overwrite
47   // values that are already present.
48   configuration = old_configuration;
49   configuration.audio_jitter_buffer_max_packets = 34;
50   CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration);
51   EXPECT_EQ(34, configuration.audio_jitter_buffer_max_packets);
52 }
53 
54 }  // namespace
55 
56 }  // namespace webrtc
57