From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/transportbridge/RtpLogger.cpp | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dom/media/webrtc/transportbridge/RtpLogger.cpp (limited to 'dom/media/webrtc/transportbridge/RtpLogger.cpp') diff --git a/dom/media/webrtc/transportbridge/RtpLogger.cpp b/dom/media/webrtc/transportbridge/RtpLogger.cpp new file mode 100644 index 0000000000..aac1fad197 --- /dev/null +++ b/dom/media/webrtc/transportbridge/RtpLogger.cpp @@ -0,0 +1,67 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Original author: nohlmeier@mozilla.com + +#include "RtpLogger.h" +#include "mozilla/Logging.h" + +#include +#include +#include +#ifdef _WIN32 +# include +# include +#else +# include +#endif + +// Logging context +using namespace mozilla; + +mozilla::LazyLogModule gRtpLoggerLog("RtpLogger"); + +namespace mozilla { + +bool RtpLogger::IsPacketLoggingOn() { + return MOZ_LOG_TEST(gRtpLoggerLog, LogLevel::Debug); +} + +void RtpLogger::LogPacket(const MediaPacket& packet, bool input, + std::string desc) { + if (MOZ_LOG_TEST(gRtpLoggerLog, LogLevel::Debug)) { + bool isRtp = (packet.type() == MediaPacket::RTP); + std::stringstream ss; + /* This creates text2pcap compatible format, e.g.: + * RTCP_PACKET O 10:36:26.864934 000000 80 c8 00 06 6d ... + */ + ss << (input ? "I " : "O "); + std::time_t t = std::time(nullptr); + std::tm tm = *std::localtime(&t); + char buf[9]; + if (0 < strftime(buf, sizeof(buf), "%H:%M:%S", &tm)) { + ss << buf; + } + ss << std::setfill('0'); +#ifdef _WIN32 + struct timeb tb; + ftime(&tb); + ss << "." << (tb.millitm) << " "; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + ss << "." << (tv.tv_usec) << " "; +#endif + ss << " 000000"; + ss << std::hex << std::setfill('0'); + for (size_t i = 0; i < packet.len(); ++i) { + ss << " " << std::setw(2) << (int)packet.data()[i]; + } + MOZ_LOG(gRtpLoggerLog, LogLevel::Debug, + ("%s%s%s", desc.c_str(), (isRtp ? " RTP_PACKET " : " RTCP_PACKET "), + ss.str().c_str())); + } +} + +} // namespace mozilla -- cgit v1.2.3