video_codec_unittest.cc (3757B)
1 /* 2 * Copyright (c) 2025 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_codecs/video_codec.h" 12 13 #include <cstddef> 14 #include <optional> 15 #include <vector> 16 17 #include "api/video/video_codec_type.h" 18 #include "api/video_codecs/sdp_video_format.h" 19 #include "rtc_base/checks.h" 20 #include "test/gtest.h" 21 22 namespace webrtc { 23 24 namespace { 25 26 VideoCodec CreateVideoCodecForMixedCodec( 27 std::optional<VideoCodecType> codec_type, 28 std::vector<bool> active_streams, 29 std::vector<std::optional<SdpVideoFormat>> formats) { 30 RTC_DCHECK(active_streams.size() == formats.size()); 31 32 VideoCodec codec; 33 if (codec_type) { 34 codec.codecType = *codec_type; 35 } 36 codec.numberOfSimulcastStreams = static_cast<unsigned char>(formats.size()); 37 for (size_t i = 0; i < formats.size(); ++i) { 38 codec.simulcastStream[i].active = active_streams[i]; 39 codec.simulcastStream[i].format = formats[i]; 40 } 41 return codec; 42 } 43 44 } // namespace 45 46 TEST(VideoCodecTest, TestIsMixedCodec) { 47 VideoCodec codec; 48 49 // Non mixed-codec cases 50 codec = CreateVideoCodecForMixedCodec(std::nullopt, {}, {}); 51 EXPECT_FALSE(codec.IsMixedCodec()); 52 53 codec = CreateVideoCodecForMixedCodec(std::nullopt, {true}, 54 {SdpVideoFormat::VP8()}); 55 EXPECT_FALSE(codec.IsMixedCodec()); 56 57 codec = CreateVideoCodecForMixedCodec( 58 std::nullopt, {true, true}, 59 {SdpVideoFormat::VP8(), SdpVideoFormat::VP8()}); 60 EXPECT_FALSE(codec.IsMixedCodec()); 61 62 codec = CreateVideoCodecForMixedCodec( 63 std::nullopt, {true, true, true}, 64 {SdpVideoFormat::VP8(), SdpVideoFormat::VP8(), SdpVideoFormat::VP8()}); 65 EXPECT_FALSE(codec.IsMixedCodec()); 66 67 // Mixed-codec cases 68 codec = CreateVideoCodecForMixedCodec( 69 std::nullopt, {true, true}, 70 {SdpVideoFormat::VP8(), SdpVideoFormat::VP9Profile0()}); 71 EXPECT_TRUE(codec.IsMixedCodec()); 72 73 codec = CreateVideoCodecForMixedCodec( 74 std::nullopt, {true, true}, 75 {SdpVideoFormat::VP9Profile0(), SdpVideoFormat::VP9Profile1()}); 76 EXPECT_TRUE(codec.IsMixedCodec()); 77 78 codec = CreateVideoCodecForMixedCodec( 79 std::nullopt, {true, true, true}, 80 {SdpVideoFormat::VP9Profile0(), SdpVideoFormat::VP9Profile1(), 81 SdpVideoFormat::VP9Profile0()}); 82 EXPECT_TRUE(codec.IsMixedCodec()); 83 84 // If formats are only partially set, it will never be a mixed-codec 85 codec = CreateVideoCodecForMixedCodec(kVideoCodecVP8, {true, true}, 86 {std::nullopt, std::nullopt}); 87 EXPECT_FALSE(codec.IsMixedCodec()); 88 89 codec = CreateVideoCodecForMixedCodec( 90 kVideoCodecVP8, {true, true, true}, 91 {SdpVideoFormat::VP8(), std::nullopt, SdpVideoFormat::VP9Profile0()}); 92 EXPECT_FALSE(codec.IsMixedCodec()); 93 94 // The format of non-active streams are ignored 95 codec = CreateVideoCodecForMixedCodec( 96 kVideoCodecVP8, {false, true, true}, 97 {std::nullopt, SdpVideoFormat::VP8(), SdpVideoFormat::VP9Profile0()}); 98 EXPECT_TRUE(codec.IsMixedCodec()); 99 100 codec = CreateVideoCodecForMixedCodec( 101 kVideoCodecVP9, {true, false, true}, 102 {SdpVideoFormat::VP8(), std::nullopt, SdpVideoFormat::VP9Profile0()}); 103 EXPECT_TRUE(codec.IsMixedCodec()); 104 105 codec = CreateVideoCodecForMixedCodec( 106 kVideoCodecVP8, {true, true, false}, 107 {SdpVideoFormat::VP8(), SdpVideoFormat::VP8(), 108 SdpVideoFormat::VP9Profile0()}); 109 EXPECT_FALSE(codec.IsMixedCodec()); 110 } 111 112 } // namespace webrtc