Move a test from media_session_unittest to codec_vendor_unittest
This test was only testing codec vendor functionality. Bug: webrtc:360058654 Change-Id: I5763e766a44f6bb1542c4281b1d6c177a52c8c74 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/375600 Commit-Queue: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43811}
This commit is contained in:
parent
2bebeaffe5
commit
1a72c0ccb9
@ -2010,6 +2010,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||||||
sources = [
|
sources = [
|
||||||
"audio_rtp_receiver_unittest.cc",
|
"audio_rtp_receiver_unittest.cc",
|
||||||
"channel_unittest.cc",
|
"channel_unittest.cc",
|
||||||
|
"codec_vendor_unittest.cc",
|
||||||
"dtls_srtp_transport_integrationtest.cc",
|
"dtls_srtp_transport_integrationtest.cc",
|
||||||
"dtls_srtp_transport_unittest.cc",
|
"dtls_srtp_transport_unittest.cc",
|
||||||
"dtls_transport_unittest.cc",
|
"dtls_transport_unittest.cc",
|
||||||
@ -2036,6 +2037,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||||||
deps = [
|
deps = [
|
||||||
":audio_rtp_receiver",
|
":audio_rtp_receiver",
|
||||||
":channel",
|
":channel",
|
||||||
|
":codec_vendor",
|
||||||
":dtls_srtp_transport",
|
":dtls_srtp_transport",
|
||||||
":dtls_transport",
|
":dtls_transport",
|
||||||
":ice_transport",
|
":ice_transport",
|
||||||
|
|||||||
105
pc/codec_vendor_unittest.cc
Normal file
105
pc/codec_vendor_unittest.cc
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2004 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 "pc/codec_vendor.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
#include "media/base/codec.h"
|
||||||
|
#include "media/base/codec_list.h"
|
||||||
|
#include "media/base/media_constants.h"
|
||||||
|
#include "media/base/test_utils.h"
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
#include "test/gtest.h"
|
||||||
|
|
||||||
|
namespace cricket {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Codec CreateRedAudioCodec(absl::string_view encoding_id) {
|
||||||
|
Codec red = CreateAudioCodec(63, "red", 48000, 2);
|
||||||
|
red.SetParam(kCodecParamNotInNameValueFormat,
|
||||||
|
std::string(encoding_id) + '/' + std::string(encoding_id));
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Codec kAudioCodecs1[] = {CreateAudioCodec(111, "opus", 48000, 2),
|
||||||
|
CreateRedAudioCodec("111"),
|
||||||
|
CreateAudioCodec(102, "iLBC", 8000, 1),
|
||||||
|
CreateAudioCodec(0, "PCMU", 8000, 1),
|
||||||
|
CreateAudioCodec(8, "PCMA", 8000, 1),
|
||||||
|
CreateAudioCodec(107, "CN", 48000, 1)};
|
||||||
|
|
||||||
|
const Codec kAudioCodecs2[] = {
|
||||||
|
CreateAudioCodec(126, "foo", 16000, 1),
|
||||||
|
CreateAudioCodec(0, "PCMU", 8000, 1),
|
||||||
|
CreateAudioCodec(127, "iLBC", 8000, 1),
|
||||||
|
};
|
||||||
|
|
||||||
|
const Codec kAudioCodecsAnswer[] = {
|
||||||
|
CreateAudioCodec(102, "iLBC", 8000, 1),
|
||||||
|
CreateAudioCodec(0, "PCMU", 8000, 1),
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(CodecVendorTest, TestSetAudioCodecs) {
|
||||||
|
CodecVendor codec_vendor(nullptr, false);
|
||||||
|
std::vector<Codec> send_codecs = MAKE_VECTOR(kAudioCodecs1);
|
||||||
|
std::vector<Codec> recv_codecs = MAKE_VECTOR(kAudioCodecs2);
|
||||||
|
|
||||||
|
// The merged list of codecs should contain any send codecs that are also
|
||||||
|
// nominally in the receive codecs list. Payload types should be picked from
|
||||||
|
// the send codecs and a number-of-channels of 0 and 1 should be equivalent
|
||||||
|
// (set to 1). This equals what happens when the send codecs are used in an
|
||||||
|
// offer and the receive codecs are used in the following answer.
|
||||||
|
const std::vector<Codec> sendrecv_codecs = MAKE_VECTOR(kAudioCodecsAnswer);
|
||||||
|
const std::vector<Codec> no_codecs;
|
||||||
|
|
||||||
|
RTC_CHECK_EQ(send_codecs[2].name, "iLBC")
|
||||||
|
<< "Please don't change shared test data!";
|
||||||
|
RTC_CHECK_EQ(recv_codecs[2].name, "iLBC")
|
||||||
|
<< "Please don't change shared test data!";
|
||||||
|
// Alter iLBC send codec to have zero channels, to test that that is handled
|
||||||
|
// properly.
|
||||||
|
send_codecs[2].channels = 0;
|
||||||
|
|
||||||
|
// Alter iLBC receive codec to be lowercase, to test that case conversions
|
||||||
|
// are handled properly.
|
||||||
|
recv_codecs[2].name = "ilbc";
|
||||||
|
|
||||||
|
// Test proper merge
|
||||||
|
codec_vendor.set_audio_codecs(send_codecs, recv_codecs);
|
||||||
|
EXPECT_EQ(send_codecs, codec_vendor.audio_send_codecs().codecs());
|
||||||
|
EXPECT_EQ(recv_codecs, codec_vendor.audio_recv_codecs().codecs());
|
||||||
|
EXPECT_EQ(sendrecv_codecs, codec_vendor.audio_sendrecv_codecs().codecs());
|
||||||
|
|
||||||
|
// Test empty send codecs list
|
||||||
|
codec_vendor.set_audio_codecs(no_codecs, recv_codecs);
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_send_codecs().codecs());
|
||||||
|
EXPECT_EQ(recv_codecs, codec_vendor.audio_recv_codecs().codecs());
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_sendrecv_codecs().codecs());
|
||||||
|
|
||||||
|
// Test empty recv codecs list
|
||||||
|
codec_vendor.set_audio_codecs(send_codecs, no_codecs);
|
||||||
|
EXPECT_EQ(send_codecs, codec_vendor.audio_send_codecs().codecs());
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_recv_codecs().codecs());
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_sendrecv_codecs().codecs());
|
||||||
|
|
||||||
|
// Test all empty codec lists
|
||||||
|
codec_vendor.set_audio_codecs(no_codecs, no_codecs);
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_send_codecs().codecs());
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_recv_codecs().codecs());
|
||||||
|
EXPECT_EQ(no_codecs, codec_vendor.audio_sendrecv_codecs().codecs());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace cricket
|
||||||
@ -4652,76 +4652,6 @@ INSTANTIATE_TEST_SUITE_P(MediaProtocolDtlsPatternTest,
|
|||||||
MediaProtocolTest,
|
MediaProtocolTest,
|
||||||
ValuesIn(kMediaProtocolsDtls));
|
ValuesIn(kMediaProtocolsDtls));
|
||||||
|
|
||||||
TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) {
|
|
||||||
webrtc::test::ScopedKeyValueConfig field_trials;
|
|
||||||
TransportDescriptionFactory tdf(field_trials);
|
|
||||||
tdf.set_certificate(rtc::RTCCertificate::Create(
|
|
||||||
std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id"))));
|
|
||||||
|
|
||||||
UniqueRandomIdGenerator ssrc_generator;
|
|
||||||
webrtc::FakePayloadTypeSuggester pt_suggester;
|
|
||||||
MediaSessionDescriptionFactory sf(nullptr, false, &ssrc_generator, &tdf,
|
|
||||||
&pt_suggester);
|
|
||||||
std::vector<Codec> send_codecs = MAKE_VECTOR(kAudioCodecs1);
|
|
||||||
std::vector<Codec> recv_codecs = MAKE_VECTOR(kAudioCodecs2);
|
|
||||||
|
|
||||||
// The merged list of codecs should contain any send codecs that are also
|
|
||||||
// nominally in the receive codecs list. Payload types should be picked from
|
|
||||||
// the send codecs and a number-of-channels of 0 and 1 should be equivalent
|
|
||||||
// (set to 1). This equals what happens when the send codecs are used in an
|
|
||||||
// offer and the receive codecs are used in the following answer.
|
|
||||||
const std::vector<Codec> sendrecv_codecs = MAKE_VECTOR(kAudioCodecsAnswer);
|
|
||||||
const std::vector<Codec> no_codecs;
|
|
||||||
|
|
||||||
RTC_CHECK_EQ(send_codecs[2].name, "iLBC")
|
|
||||||
<< "Please don't change shared test data!";
|
|
||||||
RTC_CHECK_EQ(recv_codecs[2].name, "iLBC")
|
|
||||||
<< "Please don't change shared test data!";
|
|
||||||
// Alter iLBC send codec to have zero channels, to test that that is handled
|
|
||||||
// properly.
|
|
||||||
send_codecs[2].channels = 0;
|
|
||||||
|
|
||||||
// Alter iLBC receive codec to be lowercase, to test that case conversions
|
|
||||||
// are handled properly.
|
|
||||||
recv_codecs[2].name = "ilbc";
|
|
||||||
|
|
||||||
// Test proper merge
|
|
||||||
sf.CodecVendorForTesting()->set_audio_codecs(send_codecs, recv_codecs);
|
|
||||||
EXPECT_EQ(send_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_send_codecs().codecs());
|
|
||||||
EXPECT_EQ(recv_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_recv_codecs().codecs());
|
|
||||||
EXPECT_EQ(sendrecv_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_sendrecv_codecs().codecs());
|
|
||||||
|
|
||||||
// Test empty send codecs list
|
|
||||||
sf.CodecVendorForTesting()->set_audio_codecs(no_codecs, recv_codecs);
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_send_codecs().codecs());
|
|
||||||
EXPECT_EQ(recv_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_recv_codecs().codecs());
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_sendrecv_codecs().codecs());
|
|
||||||
|
|
||||||
// Test empty recv codecs list
|
|
||||||
sf.CodecVendorForTesting()->set_audio_codecs(send_codecs, no_codecs);
|
|
||||||
EXPECT_EQ(send_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_send_codecs().codecs());
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_recv_codecs().codecs());
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_sendrecv_codecs().codecs());
|
|
||||||
|
|
||||||
// Test all empty codec lists
|
|
||||||
sf.CodecVendorForTesting()->set_audio_codecs(no_codecs, no_codecs);
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_send_codecs().codecs());
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_recv_codecs().codecs());
|
|
||||||
EXPECT_EQ(no_codecs,
|
|
||||||
sf.CodecVendorForTesting()->audio_sendrecv_codecs().codecs());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare the two vectors of codecs ignoring the payload type.
|
// Compare the two vectors of codecs ignoring the payload type.
|
||||||
bool CodecsMatch(const std::vector<Codec>& codecs1,
|
bool CodecsMatch(const std::vector<Codec>& codecs1,
|
||||||
const std::vector<Codec>& codecs2) {
|
const std::vector<Codec>& codecs2) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user