webrtc_m130/media/base/codec_comparators_unittest.cc
Harald Alvestrand ae40039522 Add comparators unittest, and abandon MatchesForSdp
Use the same code in PayloadTypePicker as in Codec.Matches()

Bug: webrtc:360058654
Change-Id: I549ed24860648cfdb6a173a19773daf01db827b0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365102
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43217}
2024-10-10 14:33:13 +00:00

76 lines
2.9 KiB
C++

/*
* Copyright (c) 2024 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "media/base/codec_comparators.h"
#include "api/audio_codecs/audio_format.h"
#include "media/base/codec.h"
#include "media/base/media_constants.h"
#include "test/gtest.h"
namespace webrtc {
using cricket::Codec;
using cricket::CreateAudioCodec;
using cricket::CreateVideoCodec;
using cricket::kH264CodecName;
using cricket::kH264FmtpPacketizationMode;
TEST(CodecComparatorsTest, CodecMatchesItself) {
Codec codec = cricket::CreateVideoCodec("custom");
EXPECT_TRUE(MatchesWithCodecRules(codec, codec));
}
TEST(CodecComparatorsTest, MismatchedBasicParameters) {
Codec codec = CreateAudioCodec(SdpAudioFormat("opus", 48000, 2));
Codec nonmatch_codec = codec;
nonmatch_codec.name = "g711";
EXPECT_FALSE(MatchesWithCodecRules(nonmatch_codec, codec));
nonmatch_codec = codec;
nonmatch_codec.clockrate = 8000;
EXPECT_FALSE(MatchesWithCodecRules(nonmatch_codec, codec));
nonmatch_codec = codec;
nonmatch_codec.channels = 1;
EXPECT_FALSE(MatchesWithCodecRules(nonmatch_codec, codec));
}
TEST(CodecComparatorsTest, H264PacketizationModeMismatch) {
Codec pt_mode_1 = CreateVideoCodec(kH264CodecName);
Codec pt_mode_0 = pt_mode_1;
pt_mode_0.SetParam(kH264FmtpPacketizationMode, "0");
EXPECT_FALSE(MatchesWithCodecRules(pt_mode_1, pt_mode_0));
EXPECT_FALSE(MatchesWithCodecRules(pt_mode_0, pt_mode_1));
Codec no_pt_mode = pt_mode_1;
no_pt_mode.RemoveParam(kH264FmtpPacketizationMode);
EXPECT_TRUE(MatchesWithCodecRules(pt_mode_0, no_pt_mode));
EXPECT_TRUE(MatchesWithCodecRules(no_pt_mode, pt_mode_0));
EXPECT_FALSE(MatchesWithCodecRules(no_pt_mode, pt_mode_1));
}
TEST(CodecComparatorsTest, AudioParametersIgnored) {
// Currently, all parameters on audio codecs are ignored for matching.
Codec basic_opus = CreateAudioCodec(SdpAudioFormat("opus", 48000, 2));
Codec opus_with_parameters = basic_opus;
opus_with_parameters.SetParam("stereo", "0");
EXPECT_TRUE(MatchesWithCodecRules(basic_opus, opus_with_parameters));
EXPECT_TRUE(MatchesWithCodecRules(opus_with_parameters, basic_opus));
opus_with_parameters.SetParam("nonsense", "stuff");
EXPECT_TRUE(MatchesWithCodecRules(basic_opus, opus_with_parameters));
EXPECT_TRUE(MatchesWithCodecRules(opus_with_parameters, basic_opus));
}
TEST(CodecComparatorsTest, StaticPayloadTypesIgnoreName) {
// This is the IANA registered format for PT 8
Codec codec_1 = CreateAudioCodec(8, "pcma", 8000, 1);
Codec codec_2 = CreateAudioCodec(8, "nonsense", 8000, 1);
EXPECT_TRUE(MatchesWithCodecRules(codec_1, codec_2));
}
} // namespace webrtc