Add AbslStringify for cricket::Codec

This makes debug output easier to read.

Bug: webrtc:360058654
Change-Id: I887be638489cde26868db0db2950262255213160
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365144
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43216}
This commit is contained in:
Harald Alvestrand 2024-10-10 12:31:47 +00:00 committed by WebRTC LUCI CQ
parent 366f205d9b
commit 3203b626f4
4 changed files with 32 additions and 0 deletions

View File

@ -374,6 +374,7 @@ rtc_library("codec") {
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/container:inlined_vector", "//third_party/abseil-cpp/absl/container:inlined_vector",
"//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/strings:str_format",
"//third_party/abseil-cpp/absl/strings:string_view", "//third_party/abseil-cpp/absl/strings:string_view",
] ]
} }

View File

@ -37,4 +37,7 @@ specific_include_rules = {
".*fake_webrtc_call\.h": [ ".*fake_webrtc_call\.h": [
"+video/config", "+video/config",
], ],
".*codec\.h": [
"+absl/strings/str_format.h",
]
} }

View File

@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include "absl/container/inlined_vector.h" #include "absl/container/inlined_vector.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "api/audio_codecs/audio_format.h" #include "api/audio_codecs/audio_format.h"
#include "api/rtp_parameters.h" #include "api/rtp_parameters.h"
@ -174,6 +175,26 @@ struct RTC_EXPORT Codec {
bool operator!=(const Codec& c) const { return !(*this == c); } bool operator!=(const Codec& c) const { return !(*this == c); }
template <typename Sink>
friend void AbslStringify(Sink& sink, const Codec& c) {
absl::Format(&sink, "[%d:", c.id);
switch (c.type) {
case Codec::Type::kAudio:
sink.Append("audio/");
break;
case Codec::Type::kVideo:
sink.Append("video/");
}
absl::Format(&sink, "%s/%d/%d", c.name, c.clockrate, c.channels);
for (auto param : c.params) {
sink.Append(";");
sink.Append(param.first);
sink.Append("=");
sink.Append(param.second);
}
sink.Append("]");
}
protected: protected:
// Creates an empty codec. // Creates an empty codec.
explicit Codec(Type type); explicit Codec(Type type);

View File

@ -640,3 +640,10 @@ TEST(CodecTest, H264CostrainedBaselineNotAddedIfAlreadySpecified) {
EXPECT_EQ(supported_formats[3], kExplicitlySupportedFormats[3]); EXPECT_EQ(supported_formats[3], kExplicitlySupportedFormats[3]);
EXPECT_EQ(supported_formats.size(), kExplicitlySupportedFormats.size()); EXPECT_EQ(supported_formats.size(), kExplicitlySupportedFormats.size());
} }
TEST(CodecTest, AbslStringify) {
Codec codec = cricket::CreateAudioCodec(47, "custom-audio", 48000, 2);
EXPECT_EQ(absl::StrCat(codec), "[47:audio/custom-audio/48000/2]");
codec.params["key"] = "value";
EXPECT_EQ(absl::StrCat(codec), "[47:audio/custom-audio/48000/2;key=value]");
}