Bug 1343640: dump RT(C)P as raw hex into log files. r=bwc

MozReview-Commit-ID: 5vNitjQJmih

--HG--
extra : rebase_source : ff49349423419cf8a568fd3dcd96f2421a880fad
This commit is contained in:
Nils Ohlmeier [:drno] 2017-03-01 23:22:36 -08:00
parent 62d88014e0
commit e4c43ec7d3
4 changed files with 121 additions and 0 deletions

View File

@ -130,6 +130,8 @@
'./src/mediapipeline/MediaPipeline.cpp',
'./src/mediapipeline/MediaPipelineFilter.h',
'./src/mediapipeline/MediaPipelineFilter.cpp',
'./src/mediapipeline/RtpLogger.h',
'./src/mediapipeline/RtpLogger.cpp',
# SDP
'./src/sdp/sipcc/ccsdp.h',
'./src/sdp/sipcc/cpr_string.c',

View File

@ -34,6 +34,7 @@
#include "AudioSegment.h"
#include "MediaSegment.h"
#include "MediaPipelineFilter.h"
#include "RtpLogger.h"
#include "databuffer.h"
#include "transportflow.h"
#include "transportlayer.h"
@ -1076,6 +1077,9 @@ void MediaPipeline::RtpPacketReceived(TransportLayer *layer,
MOZ_MTLOG(ML_DEBUG, description_ << " received RTP packet.");
increment_rtp_packets_received(out_len);
RtpLogger::LogPacket(inner_data.get(), out_len, true, true, header.headerLength,
description_);
(void)conduit_->ReceivedRTPPacket(inner_data.get(), out_len, header.ssrc); // Ignore error codes
}
@ -1137,6 +1141,8 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
MOZ_MTLOG(ML_DEBUG, description_ << " received RTCP packet.");
increment_rtcp_packets_received();
RtpLogger::LogPacket(inner_data.get(), out_len, true, false, 0, description_);
MOZ_ASSERT(rtcp_.recv_srtp_); // This should never happen
(void)conduit_->ReceivedRTCPPacket(inner_data.get(), out_len); // Ignore error codes
@ -1627,6 +1633,17 @@ nsresult MediaPipeline::PipelineTransport::SendRtpRtcpPacket_s(
// libsrtp enciphers in place, so we need a big enough buffer.
MOZ_ASSERT(data->capacity() >= data->len() + SRTP_MAX_EXPANSION);
if (RtpLogger::IsPacketLoggingOn()) {
int header_len = 12;
webrtc::RTPHeader header;
if (pipeline_->rtp_parser_ &&
pipeline_->rtp_parser_->Parse(data->data(), data->len(), &header)) {
header_len = header.headerLength;
}
RtpLogger::LogPacket(data->data(), data->len(), false, is_rtp, header_len,
pipeline_->description_);
}
int out_len;
nsresult res;
if (is_rtp) {

View File

@ -0,0 +1,74 @@
/* 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 "logging.h"
#include <sstream>
#ifdef _WIN32
#include <time.h>
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
// Logging context
using namespace mozilla;
MOZ_MTLOG_MODULE("rtplogger")
namespace mozilla {
bool RtpLogger::IsPacketLoggingOn() {
return MOZ_LOG_TEST(getLogModule(), ML_DEBUG);
}
void RtpLogger::LogPacket(const unsigned char *data, int len, bool input,
bool isRtp, int headerLength, std::string desc) {
if (MOZ_LOG_TEST(getLogModule(), ML_DEBUG)) {
std::stringstream ss;
/* This creates text2pcap compatible format, e.g.:
* O 10:36:26.864934 000000 80 c8 00 06 6d ... RTCP_PACKET
*/
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');
int offset_ = headerLength;
if (isRtp && (offset_ + 5 < len)) {
// Allow the first 5 bytes of the payload in clear
offset_ += 5;
}
for (int i=0; i < len; ++i) {
if (isRtp && i > offset_) {
ss << " 00";
}
else {
ss << " " << std::setw(2) << (int)data[i];
}
}
MOZ_MTLOG(ML_DEBUG, "\n" << ss.str() <<
(isRtp ? " RTP_PACKET " : " RTCP_PACKET ") <<
desc);
}
}
} // end of namespace

View File

@ -0,0 +1,28 @@
/* 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
#ifndef rtplogger_h__
#define rtplogger_h__
#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
namespace mozilla {
/* This class logs RTP and RTCP packets in hex in a format compatible to
* text2pcap.
* Example to convert the MOZ log file into a PCAP file:
* egrep '(RTP_PACKET|RTCP_PACKET)' moz.log | text2pcap -D -n -l 1 -i 17 -u 1234,1235 -t '%H:%M:%S.' - rtp.pcap
*/
class RtpLogger {
public:
static bool IsPacketLoggingOn();
static void LogPacket(const unsigned char *data, int len, bool input,
bool isRtp, int headerLength, std::string desc);
};
} // End of namespace
#endif