Moved RtcEventLog files from call/ to logging/
The RtcEventLog headers need to be accessible from any place which needs
logging, and the implementation needs access to data structures that are
logged.
After a discussion in the code review, we all agreed to move the RtcEventLog implementation into its own top level directory - which I called "logging/" in expectation that other types of logging may have similar requirements. The directory contains two main build targets - "rtc_event_log_api", which is just rtc_event_log.h, that has no external dependencies and can be used from anywhere, and "rtc_event_log_impl" which contains the rest of the implementation and has many dependencies (more in the future).
The "api" target can be referenced from anywhere, while the "impl" target is only needed at the place of instantiation (currently Call, soon to be moved to PeerConnection by https://codereview.webrtc.org/2353033005/).
This change allows using RtcEventLog in the p2p/ directory, so that we
can log STUN pings and ICE state transitions.
BUG=webrtc:6393
R=kjellander@webrtc.org, kwiberg@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org
Review URL: https://codereview.webrtc.org/2380683005 .
Cr-Original-Commit-Position: refs/heads/master@{#14485}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: cc91d284e43e266f97edb999eb2ebfc8a094beac
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 648bc85..bd2b30e 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -23,11 +23,11 @@
}
deps = [
- ":rtc_event_log",
"..:webrtc_common",
"../api:call_api",
"../audio",
"../base:rtc_task_queue",
+ "../logging:rtc_event_log_impl",
"../modules/congestion_controller",
"../modules/rtp_rtcp",
"../system_wrappers",
@@ -35,32 +35,6 @@
]
}
-rtc_static_library("rtc_event_log") {
- sources = [
- "rtc_event_log.cc",
- "rtc_event_log.h",
- "rtc_event_log_helper_thread.cc",
- "rtc_event_log_helper_thread.h",
- ]
-
- defines = []
-
- deps = [
- "..:webrtc_common",
- "../modules/rtp_rtcp",
- ]
-
- if (rtc_enable_protobuf) {
- defines += [ "ENABLE_RTC_EVENT_LOG" ]
- deps += [ "..:rtc_event_log_proto" ]
- }
- if (is_clang && !is_nacl) {
- # Suppress warnings from Chrome's Clang plugins.
- # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
- suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
- }
-}
-
if (rtc_include_tests) {
rtc_source_set("call_tests") {
testonly = true
@@ -69,7 +43,6 @@
"bitrate_estimator_tests.cc",
"call_unittest.cc",
"packet_injection_tests.cc",
- "ringbuffer_unittest.cc",
]
deps = [
":call",
@@ -82,24 +55,4 @@
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}
- rtc_source_set("rtc_event_log_tests") {
- testonly = true
- sources = [
- "rtc_event_log_unittest.cc",
- "rtc_event_log_unittest_helper.cc",
- ]
- deps = [
- ":rtc_event_log",
- "..:rtc_event_log_parser",
- "../modules/rtp_rtcp",
- "../system_wrappers:metrics_default",
- "//testing/gmock",
- "//testing/gtest",
- ]
- if (is_clang) {
- # Suppress warnings from the Chromium Clang plugin.
- # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
- suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
- }
- }
}
diff --git a/call/DEPS b/call/DEPS
index 0f90308..4256b58 100644
--- a/call/DEPS
+++ b/call/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+webrtc/audio",
"+webrtc/base",
+ "+webrtc/logging/rtc_event_log",
"+webrtc/modules/audio_coding",
"+webrtc/modules/bitrate_controller",
"+webrtc/modules/congestion_controller",
diff --git a/call/call.cc b/call/call.cc
index 16a6f46..dd08d77 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -27,8 +27,8 @@
#include "webrtc/base/trace_event.h"
#include "webrtc/call.h"
#include "webrtc/call/bitrate_allocator.h"
-#include "webrtc/call/rtc_event_log.h"
#include "webrtc/config.h"
+#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
#include "webrtc/modules/pacing/paced_sender.h"
diff --git a/call/mock/mock_rtc_event_log.h b/call/mock/mock_rtc_event_log.h
index bb1337e..2762386 100644
--- a/call/mock/mock_rtc_event_log.h
+++ b/call/mock/mock_rtc_event_log.h
@@ -13,7 +13,7 @@
#include <string>
-#include "webrtc/call/rtc_event_log.h"
+#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
#include "webrtc/test/gmock.h"
namespace webrtc {
diff --git a/call/ringbuffer.h b/call/ringbuffer.h
deleted file mode 100644
index fa5e422..0000000
--- a/call/ringbuffer.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2015 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.
- *
- */
-
-#ifndef WEBRTC_CALL_RINGBUFFER_H_
-#define WEBRTC_CALL_RINGBUFFER_H_
-
-#include <memory>
-#include <utility>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/base/constructormagic.h"
-
-namespace webrtc {
-
-// A RingBuffer works like a fixed size queue which starts discarding
-// the oldest elements when it becomes full.
-template <typename T>
-class RingBuffer {
- public:
- // Creates a RingBuffer with space for |capacity| elements.
- explicit RingBuffer(size_t capacity)
- : // We allocate space for one extra sentinel element.
- data_(new T[capacity + 1]) {
- RTC_DCHECK(capacity > 0);
- end_ = data_.get() + (capacity + 1);
- front_ = data_.get();
- back_ = data_.get();
- }
-
- ~RingBuffer() {
- // The unique_ptr will free the memory.
- }
-
- // Removes an element from the front of the queue.
- void pop_front() {
- RTC_DCHECK(!empty());
- ++front_;
- if (front_ == end_) {
- front_ = data_.get();
- }
- }
-
- // Appends an element to the back of the queue (and removes an
- // element from the front if there is no space at the back of the queue).
- void push_back(const T& elem) {
- *back_ = elem;
- ++back_;
- if (back_ == end_) {
- back_ = data_.get();
- }
- if (back_ == front_) {
- ++front_;
- }
- if (front_ == end_) {
- front_ = data_.get();
- }
- }
-
- // Appends an element to the back of the queue (and removes an
- // element from the front if there is no space at the back of the queue).
- void push_back(T&& elem) {
- *back_ = std::move(elem);
- ++back_;
- if (back_ == end_) {
- back_ = data_.get();
- }
- if (back_ == front_) {
- ++front_;
- }
- if (front_ == end_) {
- front_ = data_.get();
- }
- }
-
- T& front() { return *front_; }
-
- const T& front() const { return *front_; }
-
- bool empty() const { return (front_ == back_); }
-
- private:
- std::unique_ptr<T[]> data_;
- T* end_;
- T* front_;
- T* back_;
-
- RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RingBuffer);
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_CALL_RINGBUFFER_H_
diff --git a/call/ringbuffer_unittest.cc b/call/ringbuffer_unittest.cc
deleted file mode 100644
index 370f262..0000000
--- a/call/ringbuffer_unittest.cc
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2015 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 <list>
-
-#include "webrtc/base/random.h"
-#include "webrtc/call/ringbuffer.h"
-#include "webrtc/test/gtest.h"
-
-namespace {
-template <typename T>
-class MovableType {
- public:
- MovableType() : value_(), moved_from_(false), moved_to_(false) {}
- explicit MovableType(T value)
- : value_(value), moved_from_(false), moved_to_(false) {}
- MovableType(const MovableType<T>& other)
- : value_(other.value_), moved_from_(false), moved_to_(false) {}
- MovableType(MovableType<T>&& other)
- : value_(other.value_), moved_from_(false), moved_to_(true) {
- other.moved_from_ = true;
- }
-
- MovableType& operator=(const MovableType<T>& other) {
- value_ = other.value_;
- moved_from_ = false;
- moved_to_ = false;
- return *this;
- }
-
- MovableType& operator=(MovableType<T>&& other) {
- value_ = other.value_;
- moved_from_ = false;
- moved_to_ = true;
- other.moved_from_ = true;
- return *this;
- }
-
- T Value() { return value_; }
- bool IsMovedFrom() { return moved_from_; }
- bool IsMovedTo() { return moved_to_; }
-
- private:
- T value_;
- bool moved_from_;
- bool moved_to_;
-};
-
-} // namespace
-
-namespace webrtc {
-
-// Verify that the ring buffer works as a simple queue.
-TEST(RingBufferTest, SimpleQueue) {
- size_t capacity = 100;
- RingBuffer<size_t> q(capacity);
- EXPECT_TRUE(q.empty());
- for (size_t i = 0; i < capacity; i++) {
- q.push_back(i);
- EXPECT_FALSE(q.empty());
- }
-
- for (size_t i = 0; i < capacity; i++) {
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(i, q.front());
- q.pop_front();
- }
- EXPECT_TRUE(q.empty());
-}
-
-// Do a "random" sequence of queue operations and verify that the
-// result is consistent with the same operation performed on a std::list.
-TEST(RingBufferTest, ConsistentWithStdList) {
- Random prng(987654321ull);
- size_t capacity = 10;
- RingBuffer<int> q(capacity);
- std::list<int> l;
- EXPECT_TRUE(q.empty());
- for (size_t i = 0; i < 100 * capacity; i++) {
- bool insert = prng.Rand<bool>();
- if ((insert && l.size() < capacity) || l.size() == 0) {
- int x = prng.Rand<int>();
- l.push_back(x);
- q.push_back(x);
- EXPECT_FALSE(q.empty());
- } else {
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(l.front(), q.front());
- l.pop_front();
- q.pop_front();
- }
- }
- while (!l.empty()) {
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(l.front(), q.front());
- l.pop_front();
- q.pop_front();
- }
- EXPECT_TRUE(q.empty());
-}
-
-// Test that the ringbuffer starts reusing elements from the front
-// when the queue becomes full.
-TEST(RingBufferTest, OverwriteOldElements) {
- size_t capacity = 100;
- size_t insertions = 3 * capacity + 25;
- RingBuffer<size_t> q(capacity);
- EXPECT_TRUE(q.empty());
- for (size_t i = 0; i < insertions; i++) {
- q.push_back(i);
- EXPECT_FALSE(q.empty());
- }
-
- for (size_t i = insertions - capacity; i < insertions; i++) {
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(i, q.front());
- q.pop_front();
- }
- EXPECT_TRUE(q.empty());
-}
-
-// Test that the ringbuffer uses std::move when pushing an rvalue reference.
-TEST(RingBufferTest, MoveSemanticsForPushBack) {
- size_t capacity = 100;
- size_t insertions = 3 * capacity + 25;
- RingBuffer<MovableType<size_t>> q(capacity);
- EXPECT_TRUE(q.empty());
- for (size_t i = 0; i < insertions; i++) {
- MovableType<size_t> tmp(i);
- EXPECT_FALSE(tmp.IsMovedFrom());
- EXPECT_FALSE(tmp.IsMovedTo());
- q.push_back(std::move(tmp));
- EXPECT_TRUE(tmp.IsMovedFrom());
- EXPECT_FALSE(tmp.IsMovedTo());
- EXPECT_FALSE(q.empty());
- }
-
- for (size_t i = insertions - capacity; i < insertions; i++) {
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(i, q.front().Value());
- EXPECT_FALSE(q.front().IsMovedFrom());
- EXPECT_TRUE(q.front().IsMovedTo());
- q.pop_front();
- }
- EXPECT_TRUE(q.empty());
-}
-
-TEST(RingBufferTest, SmallCapacity) {
- size_t capacity = 1;
- RingBuffer<int> q(capacity);
- EXPECT_TRUE(q.empty());
- q.push_back(4711);
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(4711, q.front());
- q.push_back(1024);
- EXPECT_FALSE(q.empty());
- EXPECT_EQ(1024, q.front());
- q.pop_front();
- EXPECT_TRUE(q.empty());
-}
-
-} // namespace webrtc
diff --git a/call/rtc_event_log.cc b/call/rtc_event_log.cc
deleted file mode 100644
index c022296..0000000
--- a/call/rtc_event_log.cc
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright (c) 2015 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 "webrtc/call/rtc_event_log.h"
-
-#include <limits>
-#include <vector>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/base/constructormagic.h"
-#include "webrtc/base/event.h"
-#include "webrtc/base/swap_queue.h"
-#include "webrtc/base/thread_checker.h"
-#include "webrtc/call.h"
-#include "webrtc/call/rtc_event_log_helper_thread.h"
-#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
-#include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/file_wrapper.h"
-#include "webrtc/system_wrappers/include/logging.h"
-
-#ifdef ENABLE_RTC_EVENT_LOG
-// Files generated at build-time by the protobuf compiler.
-#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
-#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
-#else
-#include "webrtc/call/rtc_event_log.pb.h"
-#endif
-#endif
-
-namespace webrtc {
-
-#ifdef ENABLE_RTC_EVENT_LOG
-
-class RtcEventLogImpl final : public RtcEventLog {
- public:
- explicit RtcEventLogImpl(const Clock* clock);
- ~RtcEventLogImpl() override;
-
- bool StartLogging(const std::string& file_name,
- int64_t max_size_bytes) override;
- bool StartLogging(rtc::PlatformFile platform_file,
- int64_t max_size_bytes) override;
- void StopLogging() override;
- void LogVideoReceiveStreamConfig(
- const VideoReceiveStream::Config& config) override;
- void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override;
- void LogRtpHeader(PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t packet_length) override;
- void LogRtcpPacket(PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t length) override;
- void LogAudioPlayout(uint32_t ssrc) override;
- void LogBwePacketLossEvent(int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets) override;
-
- private:
- void StoreEvent(std::unique_ptr<rtclog::Event>* event);
-
- // Message queue for passing control messages to the logging thread.
- SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_;
-
- // Message queue for passing events to the logging thread.
- SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_;
-
- const Clock* const clock_;
-
- RtcEventLogHelperThread helper_thread_;
- rtc::ThreadChecker thread_checker_;
-
- RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogImpl);
-};
-
-namespace {
-// The functions in this namespace convert enums from the runtime format
-// that the rest of the WebRtc project can use, to the corresponding
-// serialized enum which is defined by the protobuf.
-
-rtclog::VideoReceiveConfig_RtcpMode ConvertRtcpMode(RtcpMode rtcp_mode) {
- switch (rtcp_mode) {
- case RtcpMode::kCompound:
- return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
- case RtcpMode::kReducedSize:
- return rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE;
- case RtcpMode::kOff:
- RTC_NOTREACHED();
- return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
- }
- RTC_NOTREACHED();
- return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
-}
-
-rtclog::MediaType ConvertMediaType(MediaType media_type) {
- switch (media_type) {
- case MediaType::ANY:
- return rtclog::MediaType::ANY;
- case MediaType::AUDIO:
- return rtclog::MediaType::AUDIO;
- case MediaType::VIDEO:
- return rtclog::MediaType::VIDEO;
- case MediaType::DATA:
- return rtclog::MediaType::DATA;
- }
- RTC_NOTREACHED();
- return rtclog::ANY;
-}
-
-// The RTP and RTCP buffers reserve space for twice the expected number of
-// sent packets because they also contain received packets.
-static const int kEventsPerSecond = 1000;
-static const int kControlMessagesPerSecond = 10;
-} // namespace
-
-// RtcEventLogImpl member functions.
-RtcEventLogImpl::RtcEventLogImpl(const Clock* clock)
- // Allocate buffers for roughly one second of history.
- : message_queue_(kControlMessagesPerSecond),
- event_queue_(kEventsPerSecond),
- clock_(clock),
- helper_thread_(&message_queue_,
- &event_queue_,
- clock),
- thread_checker_() {
- thread_checker_.DetachFromThread();
-}
-
-RtcEventLogImpl::~RtcEventLogImpl() {
- // The RtcEventLogHelperThread destructor closes the file
- // and waits for the thread to terminate.
-}
-
-bool RtcEventLogImpl::StartLogging(const std::string& file_name,
- int64_t max_size_bytes) {
- RTC_DCHECK(thread_checker_.CalledOnValidThread());
- RtcEventLogHelperThread::ControlMessage message;
- message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE;
- message.max_size_bytes = max_size_bytes <= 0
- ? std::numeric_limits<int64_t>::max()
- : max_size_bytes;
- message.start_time = clock_->TimeInMicroseconds();
- message.stop_time = std::numeric_limits<int64_t>::max();
- message.file.reset(FileWrapper::Create());
- if (!message.file->OpenFile(file_name.c_str(), false)) {
- LOG(LS_ERROR) << "Can't open file. WebRTC event log not started.";
- return false;
- }
- if (!message_queue_.Insert(&message)) {
- LOG(LS_ERROR) << "Message queue full. Can't start logging.";
- return false;
- }
- helper_thread_.SignalNewEvent();
- LOG(LS_INFO) << "Starting WebRTC event log.";
- return true;
-}
-
-bool RtcEventLogImpl::StartLogging(rtc::PlatformFile platform_file,
- int64_t max_size_bytes) {
- RTC_DCHECK(thread_checker_.CalledOnValidThread());
- RtcEventLogHelperThread::ControlMessage message;
- message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE;
- message.max_size_bytes = max_size_bytes <= 0
- ? std::numeric_limits<int64_t>::max()
- : max_size_bytes;
- message.start_time = clock_->TimeInMicroseconds();
- message.stop_time = std::numeric_limits<int64_t>::max();
- message.file.reset(FileWrapper::Create());
- FILE* file_handle = rtc::FdopenPlatformFileForWriting(platform_file);
- if (!file_handle) {
- LOG(LS_ERROR) << "Can't open file. WebRTC event log not started.";
- // Even though we failed to open a FILE*, the platform_file is still open
- // and needs to be closed.
- if (!rtc::ClosePlatformFile(platform_file)) {
- LOG(LS_ERROR) << "Can't close file.";
- }
- return false;
- }
- if (!message.file->OpenFromFileHandle(file_handle)) {
- LOG(LS_ERROR) << "Can't open file. WebRTC event log not started.";
- return false;
- }
- if (!message_queue_.Insert(&message)) {
- LOG(LS_ERROR) << "Message queue full. Can't start logging.";
- return false;
- }
- helper_thread_.SignalNewEvent();
- LOG(LS_INFO) << "Starting WebRTC event log.";
- return true;
-}
-
-void RtcEventLogImpl::StopLogging() {
- RTC_DCHECK(thread_checker_.CalledOnValidThread());
- RtcEventLogHelperThread::ControlMessage message;
- message.message_type = RtcEventLogHelperThread::ControlMessage::STOP_FILE;
- message.stop_time = clock_->TimeInMicroseconds();
- while (!message_queue_.Insert(&message)) {
- // TODO(terelius): We would like to have a blocking Insert function in the
- // SwapQueue, but for the time being we will just clear any previous
- // messages.
- // Since StopLogging waits for the thread, it is essential that we don't
- // clear any STOP_FILE messages. To ensure that there is only one call at a
- // time, we require that all calls to StopLogging are made on the same
- // thread.
- LOG(LS_ERROR) << "Message queue full. Clearing queue to stop logging.";
- message_queue_.Clear();
- }
- LOG(LS_INFO) << "Stopping WebRTC event log.";
- helper_thread_.WaitForFileFinished();
-}
-
-void RtcEventLogImpl::LogVideoReceiveStreamConfig(
- const VideoReceiveStream::Config& config) {
- std::unique_ptr<rtclog::Event> event(new rtclog::Event());
- event->set_timestamp_us(clock_->TimeInMicroseconds());
- event->set_type(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT);
-
- rtclog::VideoReceiveConfig* receiver_config =
- event->mutable_video_receiver_config();
- receiver_config->set_remote_ssrc(config.rtp.remote_ssrc);
- receiver_config->set_local_ssrc(config.rtp.local_ssrc);
-
- receiver_config->set_rtcp_mode(ConvertRtcpMode(config.rtp.rtcp_mode));
- receiver_config->set_remb(config.rtp.remb);
-
- for (const auto& kv : config.rtp.rtx) {
- rtclog::RtxMap* rtx = receiver_config->add_rtx_map();
- rtx->set_payload_type(kv.first);
- rtx->mutable_config()->set_rtx_ssrc(kv.second.ssrc);
- rtx->mutable_config()->set_rtx_payload_type(kv.second.payload_type);
- }
-
- for (const auto& e : config.rtp.extensions) {
- rtclog::RtpHeaderExtension* extension =
- receiver_config->add_header_extensions();
- extension->set_name(e.uri);
- extension->set_id(e.id);
- }
-
- for (const auto& d : config.decoders) {
- rtclog::DecoderConfig* decoder = receiver_config->add_decoders();
- decoder->set_name(d.payload_name);
- decoder->set_payload_type(d.payload_type);
- }
- StoreEvent(&event);
-}
-
-void RtcEventLogImpl::LogVideoSendStreamConfig(
- const VideoSendStream::Config& config) {
- std::unique_ptr<rtclog::Event> event(new rtclog::Event());
- event->set_timestamp_us(clock_->TimeInMicroseconds());
- event->set_type(rtclog::Event::VIDEO_SENDER_CONFIG_EVENT);
-
- rtclog::VideoSendConfig* sender_config = event->mutable_video_sender_config();
-
- for (const auto& ssrc : config.rtp.ssrcs) {
- sender_config->add_ssrcs(ssrc);
- }
-
- for (const auto& e : config.rtp.extensions) {
- rtclog::RtpHeaderExtension* extension =
- sender_config->add_header_extensions();
- extension->set_name(e.uri);
- extension->set_id(e.id);
- }
-
- for (const auto& rtx_ssrc : config.rtp.rtx.ssrcs) {
- sender_config->add_rtx_ssrcs(rtx_ssrc);
- }
- sender_config->set_rtx_payload_type(config.rtp.rtx.payload_type);
-
- rtclog::EncoderConfig* encoder = sender_config->mutable_encoder();
- encoder->set_name(config.encoder_settings.payload_name);
- encoder->set_payload_type(config.encoder_settings.payload_type);
- StoreEvent(&event);
-}
-
-void RtcEventLogImpl::LogRtpHeader(PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t packet_length) {
- // Read header length (in bytes) from packet data.
- if (packet_length < 12u) {
- return; // Don't read outside the packet.
- }
- const bool x = (header[0] & 0x10) != 0;
- const uint8_t cc = header[0] & 0x0f;
- size_t header_length = 12u + cc * 4u;
-
- if (x) {
- if (packet_length < 12u + cc * 4u + 4u) {
- return; // Don't read outside the packet.
- }
- size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4);
- header_length += (x_len + 1) * 4;
- }
-
- std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event());
- rtp_event->set_timestamp_us(clock_->TimeInMicroseconds());
- rtp_event->set_type(rtclog::Event::RTP_EVENT);
- rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket);
- rtp_event->mutable_rtp_packet()->set_type(ConvertMediaType(media_type));
- rtp_event->mutable_rtp_packet()->set_packet_length(packet_length);
- rtp_event->mutable_rtp_packet()->set_header(header, header_length);
- StoreEvent(&rtp_event);
-}
-
-void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t length) {
- std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event());
- rtcp_event->set_timestamp_us(clock_->TimeInMicroseconds());
- rtcp_event->set_type(rtclog::Event::RTCP_EVENT);
- rtcp_event->mutable_rtcp_packet()->set_incoming(direction == kIncomingPacket);
- rtcp_event->mutable_rtcp_packet()->set_type(ConvertMediaType(media_type));
-
- RTCPUtility::RtcpCommonHeader header;
- const uint8_t* block_begin = packet;
- const uint8_t* packet_end = packet + length;
- RTC_DCHECK(length <= IP_PACKET_SIZE);
- uint8_t buffer[IP_PACKET_SIZE];
- uint32_t buffer_length = 0;
- while (block_begin < packet_end) {
- if (!RtcpParseCommonHeader(block_begin, packet_end - block_begin,
- &header)) {
- break; // Incorrect message header.
- }
- uint32_t block_size = header.BlockSize();
- switch (header.packet_type) {
- case RTCPUtility::PT_SR:
- FALLTHROUGH();
- case RTCPUtility::PT_RR:
- FALLTHROUGH();
- case RTCPUtility::PT_BYE:
- FALLTHROUGH();
- case RTCPUtility::PT_IJ:
- FALLTHROUGH();
- case RTCPUtility::PT_RTPFB:
- FALLTHROUGH();
- case RTCPUtility::PT_PSFB:
- FALLTHROUGH();
- case RTCPUtility::PT_XR:
- // We log sender reports, receiver reports, bye messages
- // inter-arrival jitter, third-party loss reports, payload-specific
- // feedback and extended reports.
- memcpy(buffer + buffer_length, block_begin, block_size);
- buffer_length += block_size;
- break;
- case RTCPUtility::PT_SDES:
- FALLTHROUGH();
- case RTCPUtility::PT_APP:
- FALLTHROUGH();
- default:
- // We don't log sender descriptions, application defined messages
- // or message blocks of unknown type.
- break;
- }
-
- block_begin += block_size;
- }
- rtcp_event->mutable_rtcp_packet()->set_packet_data(buffer, buffer_length);
- StoreEvent(&rtcp_event);
-}
-
-void RtcEventLogImpl::LogAudioPlayout(uint32_t ssrc) {
- std::unique_ptr<rtclog::Event> event(new rtclog::Event());
- event->set_timestamp_us(clock_->TimeInMicroseconds());
- event->set_type(rtclog::Event::AUDIO_PLAYOUT_EVENT);
- auto playout_event = event->mutable_audio_playout_event();
- playout_event->set_local_ssrc(ssrc);
- StoreEvent(&event);
-}
-
-void RtcEventLogImpl::LogBwePacketLossEvent(int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets) {
- std::unique_ptr<rtclog::Event> event(new rtclog::Event());
- event->set_timestamp_us(clock_->TimeInMicroseconds());
- event->set_type(rtclog::Event::BWE_PACKET_LOSS_EVENT);
- auto bwe_event = event->mutable_bwe_packet_loss_event();
- bwe_event->set_bitrate(bitrate);
- bwe_event->set_fraction_loss(fraction_loss);
- bwe_event->set_total_packets(total_packets);
- StoreEvent(&event);
-}
-
-void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) {
- if (!event_queue_.Insert(event)) {
- LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event.";
- }
- helper_thread_.SignalNewEvent();
-}
-
-bool RtcEventLog::ParseRtcEventLog(const std::string& file_name,
- rtclog::EventStream* result) {
- char tmp_buffer[1024];
- int bytes_read = 0;
- std::unique_ptr<FileWrapper> dump_file(FileWrapper::Create());
- if (!dump_file->OpenFile(file_name.c_str(), true)) {
- return false;
- }
- std::string dump_buffer;
- while ((bytes_read = dump_file->Read(tmp_buffer, sizeof(tmp_buffer))) > 0) {
- dump_buffer.append(tmp_buffer, bytes_read);
- }
- dump_file->CloseFile();
- return result->ParseFromString(dump_buffer);
-}
-
-#endif // ENABLE_RTC_EVENT_LOG
-
-bool RtcEventLogNullImpl::StartLogging(rtc::PlatformFile platform_file,
- int64_t max_size_bytes) {
- // The platform_file is open and needs to be closed.
- if (!rtc::ClosePlatformFile(platform_file)) {
- LOG(LS_ERROR) << "Can't close file.";
- }
- return false;
-}
-
-// RtcEventLog member functions.
-std::unique_ptr<RtcEventLog> RtcEventLog::Create(const Clock* clock) {
-#ifdef ENABLE_RTC_EVENT_LOG
- return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl(clock));
-#else
- return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
-#endif // ENABLE_RTC_EVENT_LOG
-}
-
-std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
- return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
-}
-
-} // namespace webrtc
diff --git a/call/rtc_event_log.h b/call/rtc_event_log.h
deleted file mode 100644
index a335969..0000000
--- a/call/rtc_event_log.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2015 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.
- */
-
-#ifndef WEBRTC_CALL_RTC_EVENT_LOG_H_
-#define WEBRTC_CALL_RTC_EVENT_LOG_H_
-
-#include <memory>
-#include <string>
-
-#include "webrtc/base/platform_file.h"
-#include "webrtc/video_receive_stream.h"
-#include "webrtc/video_send_stream.h"
-
-namespace webrtc {
-
-// Forward declaration of storage class that is automatically generated from
-// the protobuf file.
-namespace rtclog {
-class EventStream;
-} // namespace rtclog
-
-class Clock;
-class RtcEventLogImpl;
-
-enum class MediaType;
-
-enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
-
-class RtcEventLog {
- public:
- virtual ~RtcEventLog() {}
-
- // Factory method to create an RtcEventLog object.
- static std::unique_ptr<RtcEventLog> Create(const Clock* clock);
-
- // Create an RtcEventLog object that does nothing.
- static std::unique_ptr<RtcEventLog> CreateNull();
-
- // Starts logging a maximum of max_size_bytes bytes to the specified file.
- // If the file already exists it will be overwritten.
- // If max_size_bytes <= 0, logging will be active until StopLogging is called.
- // The function has no effect and returns false if we can't start a new log
- // e.g. because we are already logging or the file cannot be opened.
- virtual bool StartLogging(const std::string& file_name,
- int64_t max_size_bytes) = 0;
-
- // Same as above. The RtcEventLog takes ownership of the file if the call
- // is successful, i.e. if it returns true.
- virtual bool StartLogging(rtc::PlatformFile platform_file,
- int64_t max_size_bytes) = 0;
-
- // Deprecated. Pass an explicit file size limit.
- bool StartLogging(const std::string& file_name) {
- return StartLogging(file_name, 10000000);
- }
-
- // Deprecated. Pass an explicit file size limit.
- bool StartLogging(rtc::PlatformFile platform_file) {
- return StartLogging(platform_file, 10000000);
- }
-
- // Stops logging to file and waits until the thread has finished.
- virtual void StopLogging() = 0;
-
- // Logs configuration information for webrtc::VideoReceiveStream.
- virtual void LogVideoReceiveStreamConfig(
- const webrtc::VideoReceiveStream::Config& config) = 0;
-
- // Logs configuration information for webrtc::VideoSendStream.
- virtual void LogVideoSendStreamConfig(
- const webrtc::VideoSendStream::Config& config) = 0;
-
- // Logs the header of an incoming or outgoing RTP packet. packet_length
- // is the total length of the packet, including both header and payload.
- virtual void LogRtpHeader(PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t packet_length) = 0;
-
- // Logs an incoming or outgoing RTCP packet.
- virtual void LogRtcpPacket(PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t length) = 0;
-
- // Logs an audio playout event.
- virtual void LogAudioPlayout(uint32_t ssrc) = 0;
-
- // Logs a bitrate update from the bandwidth estimator based on packet loss.
- virtual void LogBwePacketLossEvent(int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets) = 0;
-
- // Reads an RtcEventLog file and returns true when reading was successful.
- // The result is stored in the given EventStream object.
- // The order of the events in the EventStream is implementation defined.
- // The current implementation writes a LOG_START event, then the old
- // configurations, then the remaining events in timestamp order and finally
- // a LOG_END event. However, this might change without further notice.
- // TODO(terelius): Change result type to a vector?
- static bool ParseRtcEventLog(const std::string& file_name,
- rtclog::EventStream* result);
-};
-
-// No-op implementation is used if flag is not set, or in tests.
-class RtcEventLogNullImpl final : public RtcEventLog {
- public:
- bool StartLogging(const std::string& file_name,
- int64_t max_size_bytes) override {
- return false;
- }
- bool StartLogging(rtc::PlatformFile platform_file,
- int64_t max_size_bytes) override;
- void StopLogging() override {}
- void LogVideoReceiveStreamConfig(
- const VideoReceiveStream::Config& config) override {}
- void LogVideoSendStreamConfig(
- const VideoSendStream::Config& config) override {}
- void LogRtpHeader(PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t packet_length) override {}
- void LogRtcpPacket(PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t length) override {}
- void LogAudioPlayout(uint32_t ssrc) override {}
- void LogBwePacketLossEvent(int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets) override {}
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_CALL_RTC_EVENT_LOG_H_
diff --git a/call/rtc_event_log.proto b/call/rtc_event_log.proto
deleted file mode 100644
index b14306e..0000000
--- a/call/rtc_event_log.proto
+++ /dev/null
@@ -1,242 +0,0 @@
-syntax = "proto2";
-option optimize_for = LITE_RUNTIME;
-package webrtc.rtclog;
-
-
-enum MediaType {
- ANY = 0;
- AUDIO = 1;
- VIDEO = 2;
- DATA = 3;
-}
-
-
-// This is the main message to dump to a file, it can contain multiple event
-// messages, but it is possible to append multiple EventStreams (each with a
-// single event) to a file.
-// This has the benefit that there's no need to keep all data in memory.
-message EventStream {
- repeated Event stream = 1;
-}
-
-
-message Event {
- // required - Elapsed wallclock time in us since the start of the log.
- optional int64 timestamp_us = 1;
-
- // The different types of events that can occur, the UNKNOWN_EVENT entry
- // is added in case future EventTypes are added, in that case old code will
- // receive the new events as UNKNOWN_EVENT.
- enum EventType {
- UNKNOWN_EVENT = 0;
- LOG_START = 1;
- LOG_END = 2;
- RTP_EVENT = 3;
- RTCP_EVENT = 4;
- AUDIO_PLAYOUT_EVENT = 5;
- BWE_PACKET_LOSS_EVENT = 6;
- BWE_PACKET_DELAY_EVENT = 7;
- VIDEO_RECEIVER_CONFIG_EVENT = 8;
- VIDEO_SENDER_CONFIG_EVENT = 9;
- AUDIO_RECEIVER_CONFIG_EVENT = 10;
- AUDIO_SENDER_CONFIG_EVENT = 11;
- }
-
- // required - Indicates the type of this event
- optional EventType type = 2;
-
- // optional - but required if type == RTP_EVENT
- optional RtpPacket rtp_packet = 3;
-
- // optional - but required if type == RTCP_EVENT
- optional RtcpPacket rtcp_packet = 4;
-
- // optional - but required if type == AUDIO_PLAYOUT_EVENT
- optional AudioPlayoutEvent audio_playout_event = 5;
-
- // optional - but required if type == BWE_PACKET_LOSS_EVENT
- optional BwePacketLossEvent bwe_packet_loss_event = 6;
-
- // optional - but required if type == VIDEO_RECEIVER_CONFIG_EVENT
- optional VideoReceiveConfig video_receiver_config = 8;
-
- // optional - but required if type == VIDEO_SENDER_CONFIG_EVENT
- optional VideoSendConfig video_sender_config = 9;
-
- // optional - but required if type == AUDIO_RECEIVER_CONFIG_EVENT
- optional AudioReceiveConfig audio_receiver_config = 10;
-
- // optional - but required if type == AUDIO_SENDER_CONFIG_EVENT
- optional AudioSendConfig audio_sender_config = 11;
-}
-
-
-message RtpPacket {
- // required - True if the packet is incoming w.r.t. the user logging the data
- optional bool incoming = 1;
-
- // required
- optional MediaType type = 2;
-
- // required - The size of the packet including both payload and header.
- optional uint32 packet_length = 3;
-
- // required - The RTP header only.
- optional bytes header = 4;
-
- // Do not add code to log user payload data without a privacy review!
-}
-
-
-message RtcpPacket {
- // required - True if the packet is incoming w.r.t. the user logging the data
- optional bool incoming = 1;
-
- // required
- optional MediaType type = 2;
-
- // required - The whole packet including both payload and header.
- optional bytes packet_data = 3;
-}
-
-message AudioPlayoutEvent {
- // required - The SSRC of the audio stream associated with the playout event.
- optional uint32 local_ssrc = 2;
-}
-
-message BwePacketLossEvent {
- // required - Bandwidth estimate (in bps) after the update.
- optional int32 bitrate = 1;
-
- // required - Fraction of lost packets since last receiver report
- // computed as floor( 256 * (#lost_packets / #total_packets) ).
- // The possible values range from 0 to 255.
- optional uint32 fraction_loss = 2;
-
- // TODO(terelius): Is this really needed? Remove or make optional?
- // required - Total number of packets that the BWE update is based on.
- optional int32 total_packets = 3;
-}
-
-// TODO(terelius): Video and audio streams could in principle share SSRC,
-// so identifying a stream based only on SSRC might not work.
-// It might be better to use a combination of SSRC and media type
-// or SSRC and port number, but for now we will rely on SSRC only.
-message VideoReceiveConfig {
- // required - Synchronization source (stream identifier) to be received.
- optional uint32 remote_ssrc = 1;
- // required - Sender SSRC used for sending RTCP (such as receiver reports).
- optional uint32 local_ssrc = 2;
-
- // Compound mode is described by RFC 4585 and reduced-size
- // RTCP mode is described by RFC 5506.
- enum RtcpMode {
- RTCP_COMPOUND = 1;
- RTCP_REDUCEDSIZE = 2;
- }
- // required - RTCP mode to use.
- optional RtcpMode rtcp_mode = 3;
-
- // required - Receiver estimated maximum bandwidth.
- optional bool remb = 4;
-
- // Map from video RTP payload type -> RTX config.
- repeated RtxMap rtx_map = 5;
-
- // RTP header extensions used for the received stream.
- repeated RtpHeaderExtension header_extensions = 6;
-
- // List of decoders associated with the stream.
- repeated DecoderConfig decoders = 7;
-}
-
-
-// Maps decoder names to payload types.
-message DecoderConfig {
- // required
- optional string name = 1;
-
- // required
- optional int32 payload_type = 2;
-}
-
-
-// Maps RTP header extension names to numerical IDs.
-message RtpHeaderExtension {
- // required
- optional string name = 1;
-
- // required
- optional int32 id = 2;
-}
-
-
-// RTX settings for incoming video payloads that may be received.
-// RTX is disabled if there's no config present.
-message RtxConfig {
- // required - SSRC to use for the RTX stream.
- optional uint32 rtx_ssrc = 1;
-
- // required - Payload type to use for the RTX stream.
- optional int32 rtx_payload_type = 2;
-}
-
-
-message RtxMap {
- // required
- optional int32 payload_type = 1;
-
- // required
- optional RtxConfig config = 2;
-}
-
-
-message VideoSendConfig {
- // Synchronization source (stream identifier) for outgoing stream.
- // One stream can have several ssrcs for e.g. simulcast.
- // At least one ssrc is required.
- repeated uint32 ssrcs = 1;
-
- // RTP header extensions used for the outgoing stream.
- repeated RtpHeaderExtension header_extensions = 2;
-
- // List of SSRCs for retransmitted packets.
- repeated uint32 rtx_ssrcs = 3;
-
- // required if rtx_ssrcs is used - Payload type for retransmitted packets.
- optional int32 rtx_payload_type = 4;
-
- // required - Encoder associated with the stream.
- optional EncoderConfig encoder = 5;
-}
-
-
-// Maps encoder names to payload types.
-message EncoderConfig {
- // required
- optional string name = 1;
-
- // required
- optional int32 payload_type = 2;
-}
-
-
-message AudioReceiveConfig {
- // required - Synchronization source (stream identifier) to be received.
- optional uint32 remote_ssrc = 1;
-
- // required - Sender SSRC used for sending RTCP (such as receiver reports).
- optional uint32 local_ssrc = 2;
-
- // RTP header extensions used for the received audio stream.
- repeated RtpHeaderExtension header_extensions = 3;
-}
-
-
-message AudioSendConfig {
- // required - Synchronization source (stream identifier) for outgoing stream.
- optional uint32 ssrc = 1;
-
- // RTP header extensions used for the outgoing audio stream.
- repeated RtpHeaderExtension header_extensions = 2;
-}
diff --git a/call/rtc_event_log2rtp_dump.cc b/call/rtc_event_log2rtp_dump.cc
deleted file mode 100644
index 5733cfa..0000000
--- a/call/rtc_event_log2rtp_dump.cc
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2015 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 <iostream>
-#include <memory>
-#include <sstream>
-#include <string>
-
-#include "gflags/gflags.h"
-#include "webrtc/base/checks.h"
-#include "webrtc/call.h"
-#include "webrtc/call/rtc_event_log.h"
-#include "webrtc/call/rtc_event_log_parser.h"
-#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
-#include "webrtc/test/rtp_file_writer.h"
-
-namespace {
-
-DEFINE_bool(noaudio,
- false,
- "Excludes audio packets from the converted RTPdump file.");
-DEFINE_bool(novideo,
- false,
- "Excludes video packets from the converted RTPdump file.");
-DEFINE_bool(nodata,
- false,
- "Excludes data packets from the converted RTPdump file.");
-DEFINE_bool(nortp,
- false,
- "Excludes RTP packets from the converted RTPdump file.");
-DEFINE_bool(nortcp,
- false,
- "Excludes RTCP packets from the converted RTPdump file.");
-DEFINE_string(ssrc,
- "",
- "Store only packets with this SSRC (decimal or hex, the latter "
- "starting with 0x).");
-
-// Parses the input string for a valid SSRC. If a valid SSRC is found, it is
-// written to the output variable |ssrc|, and true is returned. Otherwise,
-// false is returned.
-// The empty string must be validated as true, because it is the default value
-// of the command-line flag. In this case, no value is written to the output
-// variable.
-bool ParseSsrc(std::string str, uint32_t* ssrc) {
- // If the input string starts with 0x or 0X it indicates a hexadecimal number.
- auto read_mode = std::dec;
- if (str.size() > 2 &&
- (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) {
- read_mode = std::hex;
- str = str.substr(2);
- }
- std::stringstream ss(str);
- ss >> read_mode >> *ssrc;
- return str.empty() || (!ss.fail() && ss.eof());
-}
-
-} // namespace
-
-// This utility will convert a stored event log to the rtpdump format.
-int main(int argc, char* argv[]) {
- std::string program_name = argv[0];
- std::string usage =
- "Tool for converting an RtcEventLog file to an RTP dump file.\n"
- "Run " +
- program_name +
- " --helpshort for usage.\n"
- "Example usage:\n" +
- program_name + " input.rel output.rtp\n";
- google::SetUsageMessage(usage);
- google::ParseCommandLineFlags(&argc, &argv, true);
-
- if (argc != 3) {
- std::cout << google::ProgramUsage();
- return 0;
- }
- std::string input_file = argv[1];
- std::string output_file = argv[2];
-
- uint32_t ssrc_filter = 0;
- if (!FLAGS_ssrc.empty())
- RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc_filter))
- << "Flag verification has failed.";
-
- webrtc::ParsedRtcEventLog parsed_stream;
- if (!parsed_stream.ParseFile(input_file)) {
- std::cerr << "Error while parsing input file: " << input_file << std::endl;
- return -1;
- }
-
- std::unique_ptr<webrtc::test::RtpFileWriter> rtp_writer(
- webrtc::test::RtpFileWriter::Create(
- webrtc::test::RtpFileWriter::FileFormat::kRtpDump, output_file));
-
- if (!rtp_writer.get()) {
- std::cerr << "Error while opening output file: " << output_file
- << std::endl;
- return -1;
- }
-
- std::cout << "Found " << parsed_stream.GetNumberOfEvents()
- << " events in the input file." << std::endl;
- int rtp_counter = 0, rtcp_counter = 0;
- bool header_only = false;
- for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) {
- // The parsed_stream will assert if the protobuf event is missing
- // some required fields and we attempt to access them. We could consider
- // a softer failure option, but it does not seem useful to generate
- // RTP dumps based on broken event logs.
- if (!FLAGS_nortp &&
- parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) {
- webrtc::test::RtpPacket packet;
- webrtc::PacketDirection direction;
- webrtc::MediaType media_type;
- parsed_stream.GetRtpHeader(i, &direction, &media_type, packet.data,
- &packet.length, &packet.original_length);
- if (packet.original_length > packet.length)
- header_only = true;
- packet.time_ms = parsed_stream.GetTimestamp(i) / 1000;
-
- // TODO(terelius): Maybe add a flag to dump outgoing traffic instead?
- if (direction == webrtc::kOutgoingPacket)
- continue;
- if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO)
- continue;
- if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO)
- continue;
- if (FLAGS_nodata && media_type == webrtc::MediaType::DATA)
- continue;
- if (!FLAGS_ssrc.empty()) {
- const uint32_t packet_ssrc =
- webrtc::ByteReader<uint32_t>::ReadBigEndian(
- reinterpret_cast<const uint8_t*>(packet.data + 8));
- if (packet_ssrc != ssrc_filter)
- continue;
- }
-
- rtp_writer->WritePacket(&packet);
- rtp_counter++;
- }
- if (!FLAGS_nortcp &&
- parsed_stream.GetEventType(i) ==
- webrtc::ParsedRtcEventLog::RTCP_EVENT) {
- webrtc::test::RtpPacket packet;
- webrtc::PacketDirection direction;
- webrtc::MediaType media_type;
- parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet.data,
- &packet.length);
- // For RTCP packets the original_length should be set to 0 in the
- // RTPdump format.
- packet.original_length = 0;
- packet.time_ms = parsed_stream.GetTimestamp(i) / 1000;
-
- // TODO(terelius): Maybe add a flag to dump outgoing traffic instead?
- if (direction == webrtc::kOutgoingPacket)
- continue;
- if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO)
- continue;
- if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO)
- continue;
- if (FLAGS_nodata && media_type == webrtc::MediaType::DATA)
- continue;
- if (!FLAGS_ssrc.empty()) {
- const uint32_t packet_ssrc =
- webrtc::ByteReader<uint32_t>::ReadBigEndian(
- reinterpret_cast<const uint8_t*>(packet.data + 4));
- if (packet_ssrc != ssrc_filter)
- continue;
- }
-
- rtp_writer->WritePacket(&packet);
- rtcp_counter++;
- }
- }
- std::cout << "Wrote " << rtp_counter << (header_only ? " header-only" : "")
- << " RTP packets and " << rtcp_counter << " RTCP packets to the "
- << "output file." << std::endl;
- return 0;
-}
diff --git a/call/rtc_event_log_helper_thread.cc b/call/rtc_event_log_helper_thread.cc
deleted file mode 100644
index c0f8972..0000000
--- a/call/rtc_event_log_helper_thread.cc
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (c) 2016 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 "webrtc/call/rtc_event_log_helper_thread.h"
-
-#include <algorithm>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/system_wrappers/include/logging.h"
-
-#ifdef ENABLE_RTC_EVENT_LOG
-
-namespace webrtc {
-
-namespace {
-const int kEventsInHistory = 10000;
-
-bool IsConfigEvent(const rtclog::Event& event) {
- rtclog::Event_EventType event_type = event.type();
- return event_type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT ||
- event_type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT ||
- event_type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT ||
- event_type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT;
-}
-} // namespace
-
-// RtcEventLogImpl member functions.
-RtcEventLogHelperThread::RtcEventLogHelperThread(
- SwapQueue<ControlMessage>* message_queue,
- SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue,
- const Clock* const clock)
- : message_queue_(message_queue),
- event_queue_(event_queue),
- history_(kEventsInHistory),
- config_history_(),
- file_(FileWrapper::Create()),
- thread_(&ThreadOutputFunction, this, "RtcEventLog thread"),
- max_size_bytes_(std::numeric_limits<int64_t>::max()),
- written_bytes_(0),
- start_time_(0),
- stop_time_(std::numeric_limits<int64_t>::max()),
- has_recent_event_(false),
- most_recent_event_(),
- output_string_(),
- wake_periodically_(false, false),
- wake_from_hibernation_(false, false),
- file_finished_(false, false),
- clock_(clock) {
- RTC_DCHECK(message_queue_);
- RTC_DCHECK(event_queue_);
- RTC_DCHECK(clock_);
- thread_.Start();
-}
-
-RtcEventLogHelperThread::~RtcEventLogHelperThread() {
- ControlMessage message;
- message.message_type = ControlMessage::TERMINATE_THREAD;
- message.stop_time = clock_->TimeInMicroseconds();
- while (!message_queue_->Insert(&message)) {
- // We can't destroy the event log until we have stopped the thread,
- // so clear the message queue and try again. Note that if we clear
- // any STOP_FILE events, then the threads calling StopLogging would likely
- // wait indefinitely. However, there should not be any such calls as we
- // are executing the destructor.
- LOG(LS_WARNING) << "Clearing message queue to terminate thread.";
- message_queue_->Clear();
- }
- wake_from_hibernation_.Set();
- wake_periodically_.Set(); // Wake up the output thread.
- thread_.Stop(); // Wait for the thread to terminate.
-}
-
-void RtcEventLogHelperThread::WaitForFileFinished() {
- wake_from_hibernation_.Set();
- wake_periodically_.Set();
- file_finished_.Wait(rtc::Event::kForever);
-}
-
-void RtcEventLogHelperThread::SignalNewEvent() {
- wake_from_hibernation_.Set();
-}
-
-bool RtcEventLogHelperThread::AppendEventToString(rtclog::Event* event) {
- rtclog::EventStream event_stream;
- event_stream.add_stream();
- event_stream.mutable_stream(0)->Swap(event);
- // We create a new event stream per event but because of the way protobufs
- // are encoded, events can be merged by concatenating them. Therefore,
- // it will look like a single stream when we read it back from file.
- bool stop = true;
- if (written_bytes_ + static_cast<int64_t>(output_string_.size()) +
- event_stream.ByteSize() <=
- max_size_bytes_) {
- event_stream.AppendToString(&output_string_);
- stop = false;
- }
- // Swap the event back so that we don't mix event types in the queues.
- event_stream.mutable_stream(0)->Swap(event);
- return stop;
-}
-
-bool RtcEventLogHelperThread::LogToMemory() {
- RTC_DCHECK(!file_->is_open());
- bool message_received = false;
-
- // Process each event earlier than the current time and append it to the
- // appropriate history_.
- int64_t current_time = clock_->TimeInMicroseconds();
- if (!has_recent_event_) {
- has_recent_event_ = event_queue_->Remove(&most_recent_event_);
- }
- while (has_recent_event_ &&
- most_recent_event_->timestamp_us() <= current_time) {
- if (IsConfigEvent(*most_recent_event_)) {
- config_history_.push_back(std::move(most_recent_event_));
- } else {
- history_.push_back(std::move(most_recent_event_));
- }
- has_recent_event_ = event_queue_->Remove(&most_recent_event_);
- message_received = true;
- }
- return message_received;
-}
-
-void RtcEventLogHelperThread::StartLogFile() {
- RTC_DCHECK(file_->is_open());
- bool stop = false;
- output_string_.clear();
-
- // Create and serialize the LOG_START event.
- rtclog::Event start_event;
- start_event.set_timestamp_us(start_time_);
- start_event.set_type(rtclog::Event::LOG_START);
- AppendEventToString(&start_event);
-
- // Serialize the config information for all old streams.
- for (auto& event : config_history_) {
- AppendEventToString(event.get());
- }
-
- // Serialize the events in the event queue.
- while (!history_.empty() && !stop) {
- stop = AppendEventToString(history_.front().get());
- if (!stop) {
- history_.pop_front();
- }
- }
-
- // Write to file.
- if (!file_->Write(output_string_.data(), output_string_.size())) {
- LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file.";
- // The current FileWrapper implementation closes the file on error.
- RTC_DCHECK(!file_->is_open());
- return;
- }
- written_bytes_ += output_string_.size();
-
- // Free the allocated memory since we probably won't need this amount of
- // space again.
- output_string_.clear();
- output_string_.shrink_to_fit();
-
- if (stop) {
- RTC_DCHECK(file_->is_open());
- StopLogFile();
- }
-}
-
-bool RtcEventLogHelperThread::LogToFile() {
- RTC_DCHECK(file_->is_open());
- output_string_.clear();
- bool message_received = false;
-
- // Append each event older than both the current time and the stop time
- // to the output_string_.
- int64_t current_time = clock_->TimeInMicroseconds();
- int64_t time_limit = std::min(current_time, stop_time_);
- if (!has_recent_event_) {
- has_recent_event_ = event_queue_->Remove(&most_recent_event_);
- }
- bool stop = false;
- while (!stop && has_recent_event_ &&
- most_recent_event_->timestamp_us() <= time_limit) {
- stop = AppendEventToString(most_recent_event_.get());
- if (!stop) {
- if (IsConfigEvent(*most_recent_event_)) {
- config_history_.push_back(std::move(most_recent_event_));
- }
- has_recent_event_ = event_queue_->Remove(&most_recent_event_);
- }
- message_received = true;
- }
-
- // Write string to file.
- if (!file_->Write(output_string_.data(), output_string_.size())) {
- LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file.";
- // The current FileWrapper implementation closes the file on error.
- RTC_DCHECK(!file_->is_open());
- return message_received;
- }
- written_bytes_ += output_string_.size();
-
- // We want to stop logging if we have reached the file size limit. We also
- // want to stop logging if the remaining events are more recent than the
- // time limit, or in other words if we have terminated the loop despite
- // having more events in the queue.
- if ((has_recent_event_ && most_recent_event_->timestamp_us() > stop_time_) ||
- stop) {
- RTC_DCHECK(file_->is_open());
- StopLogFile();
- }
- return message_received;
-}
-
-void RtcEventLogHelperThread::StopLogFile() {
- RTC_DCHECK(file_->is_open());
- output_string_.clear();
-
- rtclog::Event end_event;
- // This function can be called either because we have reached the stop time,
- // or because we have reached the log file size limit. Therefore, use the
- // current time if we have not reached the time limit.
- end_event.set_timestamp_us(
- std::min(stop_time_, clock_->TimeInMicroseconds()));
- end_event.set_type(rtclog::Event::LOG_END);
- AppendEventToString(&end_event);
-
- if (written_bytes_ + static_cast<int64_t>(output_string_.size()) <=
- max_size_bytes_) {
- if (!file_->Write(output_string_.data(), output_string_.size())) {
- LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file.";
- // The current FileWrapper implementation closes the file on error.
- RTC_DCHECK(!file_->is_open());
- }
- written_bytes_ += output_string_.size();
- }
-
- max_size_bytes_ = std::numeric_limits<int64_t>::max();
- written_bytes_ = 0;
- start_time_ = 0;
- stop_time_ = std::numeric_limits<int64_t>::max();
- output_string_.clear();
- file_->CloseFile();
- RTC_DCHECK(!file_->is_open());
-}
-
-void RtcEventLogHelperThread::ProcessEvents() {
- ControlMessage message;
-
- while (true) {
- bool message_received = false;
- // Process control messages.
- while (message_queue_->Remove(&message)) {
- switch (message.message_type) {
- case ControlMessage::START_FILE:
- if (!file_->is_open()) {
- max_size_bytes_ = message.max_size_bytes;
- start_time_ = message.start_time;
- stop_time_ = message.stop_time;
- file_.swap(message.file);
- StartLogFile();
- } else {
- // Already started. Ignore message and close file handle.
- message.file->CloseFile();
- }
- message_received = true;
- break;
- case ControlMessage::STOP_FILE:
- if (file_->is_open()) {
- stop_time_ = message.stop_time;
- LogToFile(); // Log remaining events from message queues.
- }
- // LogToFile might stop on it's own so we need to recheck the state.
- if (file_->is_open()) {
- StopLogFile();
- }
- file_finished_.Set();
- message_received = true;
- break;
- case ControlMessage::TERMINATE_THREAD:
- if (file_->is_open()) {
- StopLogFile();
- }
- return;
- }
- }
-
- // Write events to file or memory.
- if (file_->is_open()) {
- message_received |= LogToFile();
- } else {
- message_received |= LogToMemory();
- }
-
- // Accumulate a new batch of events instead of processing them one at a
- // time.
- if (message_received) {
- wake_periodically_.Wait(100);
- } else {
- wake_from_hibernation_.Wait(rtc::Event::kForever);
- }
- }
-}
-
-bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) {
- RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj);
- helper->ProcessEvents();
- return false;
-}
-
-} // namespace webrtc
-
-#endif // ENABLE_RTC_EVENT_LOG
diff --git a/call/rtc_event_log_helper_thread.h b/call/rtc_event_log_helper_thread.h
deleted file mode 100644
index 1408961..0000000
--- a/call/rtc_event_log_helper_thread.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2016 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.
- */
-
-#ifndef WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_
-#define WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_
-
-#include <limits>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "webrtc/base/constructormagic.h"
-#include "webrtc/base/event.h"
-#include "webrtc/base/ignore_wundef.h"
-#include "webrtc/base/platform_thread.h"
-#include "webrtc/base/swap_queue.h"
-#include "webrtc/call/ringbuffer.h"
-#include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/file_wrapper.h"
-
-#ifdef ENABLE_RTC_EVENT_LOG
-// Files generated at build-time by the protobuf compiler.
-RTC_PUSH_IGNORING_WUNDEF()
-#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
-#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
-#else
-#include "webrtc/call/rtc_event_log.pb.h"
-#endif
-RTC_POP_IGNORING_WUNDEF()
-#endif
-
-#ifdef ENABLE_RTC_EVENT_LOG
-
-namespace webrtc {
-
-class RtcEventLogHelperThread final {
- public:
- struct ControlMessage {
- ControlMessage()
- : message_type(STOP_FILE),
- file(nullptr),
- max_size_bytes(0),
- start_time(0),
- stop_time(0) {}
- enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type;
-
- std::unique_ptr<FileWrapper> file; // Only used with START_FILE.
- int64_t max_size_bytes; // Only used with START_FILE.
- int64_t start_time; // Only used with START_FILE.
- int64_t stop_time; // Used with all 3 message types.
-
- friend void swap(ControlMessage& lhs, ControlMessage& rhs) {
- using std::swap;
- swap(lhs.message_type, rhs.message_type);
- lhs.file.swap(rhs.file);
- swap(lhs.max_size_bytes, rhs.max_size_bytes);
- swap(lhs.start_time, rhs.start_time);
- swap(lhs.stop_time, rhs.stop_time);
- }
- };
-
- RtcEventLogHelperThread(
- SwapQueue<ControlMessage>* message_queue,
- SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue,
- const Clock* const clock);
- ~RtcEventLogHelperThread();
-
- // This function MUST be called once a STOP_FILE message is added to the
- // signalling queue. The function will make sure that the output thread
- // wakes up to read the message, and it blocks until the output thread has
- // finished writing to the file.
- void WaitForFileFinished();
-
- // This fuction MUST be called once an event is added to the event queue.
- void SignalNewEvent();
-
- private:
- static bool ThreadOutputFunction(void* obj);
-
- bool AppendEventToString(rtclog::Event* event);
- bool LogToMemory();
- void StartLogFile();
- bool LogToFile();
- void StopLogFile();
- void ProcessEvents();
-
- // Message queues for passing events to the logging thread.
- SwapQueue<ControlMessage>* message_queue_;
- SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue_;
-
- // History containing the most recent events (~ 10 s).
- RingBuffer<std::unique_ptr<rtclog::Event>> history_;
-
- // History containing all past configuration events.
- std::vector<std::unique_ptr<rtclog::Event>> config_history_;
-
- std::unique_ptr<FileWrapper> file_;
- rtc::PlatformThread thread_;
-
- int64_t max_size_bytes_;
- int64_t written_bytes_;
- int64_t start_time_;
- int64_t stop_time_;
-
- bool has_recent_event_;
- std::unique_ptr<rtclog::Event> most_recent_event_;
-
- // Temporary space for serializing profobuf data.
- std::string output_string_;
-
- rtc::Event wake_periodically_;
- rtc::Event wake_from_hibernation_;
- rtc::Event file_finished_;
-
- const Clock* const clock_;
-
- RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread);
-};
-
-} // namespace webrtc
-
-#endif // ENABLE_RTC_EVENT_LOG
-
-#endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_
diff --git a/call/rtc_event_log_parser.cc b/call/rtc_event_log_parser.cc
deleted file mode 100644
index a2f95d0..0000000
--- a/call/rtc_event_log_parser.cc
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright (c) 2016 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 "webrtc/call/rtc_event_log_parser.h"
-
-#include <string.h>
-
-#include <fstream>
-#include <istream>
-#include <utility>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/base/logging.h"
-#include "webrtc/call.h"
-#include "webrtc/call/rtc_event_log.h"
-#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-#include "webrtc/system_wrappers/include/file_wrapper.h"
-
-namespace webrtc {
-
-namespace {
-MediaType GetRuntimeMediaType(rtclog::MediaType media_type) {
- switch (media_type) {
- case rtclog::MediaType::ANY:
- return MediaType::ANY;
- case rtclog::MediaType::AUDIO:
- return MediaType::AUDIO;
- case rtclog::MediaType::VIDEO:
- return MediaType::VIDEO;
- case rtclog::MediaType::DATA:
- return MediaType::DATA;
- }
- RTC_NOTREACHED();
- return MediaType::ANY;
-}
-
-RtcpMode GetRuntimeRtcpMode(rtclog::VideoReceiveConfig::RtcpMode rtcp_mode) {
- switch (rtcp_mode) {
- case rtclog::VideoReceiveConfig::RTCP_COMPOUND:
- return RtcpMode::kCompound;
- case rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE:
- return RtcpMode::kReducedSize;
- }
- RTC_NOTREACHED();
- return RtcpMode::kOff;
-}
-
-ParsedRtcEventLog::EventType GetRuntimeEventType(
- rtclog::Event::EventType event_type) {
- switch (event_type) {
- case rtclog::Event::UNKNOWN_EVENT:
- return ParsedRtcEventLog::EventType::UNKNOWN_EVENT;
- case rtclog::Event::LOG_START:
- return ParsedRtcEventLog::EventType::LOG_START;
- case rtclog::Event::LOG_END:
- return ParsedRtcEventLog::EventType::LOG_END;
- case rtclog::Event::RTP_EVENT:
- return ParsedRtcEventLog::EventType::RTP_EVENT;
- case rtclog::Event::RTCP_EVENT:
- return ParsedRtcEventLog::EventType::RTCP_EVENT;
- case rtclog::Event::AUDIO_PLAYOUT_EVENT:
- return ParsedRtcEventLog::EventType::AUDIO_PLAYOUT_EVENT;
- case rtclog::Event::BWE_PACKET_LOSS_EVENT:
- return ParsedRtcEventLog::EventType::BWE_PACKET_LOSS_EVENT;
- case rtclog::Event::BWE_PACKET_DELAY_EVENT:
- return ParsedRtcEventLog::EventType::BWE_PACKET_DELAY_EVENT;
- case rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT:
- return ParsedRtcEventLog::EventType::VIDEO_RECEIVER_CONFIG_EVENT;
- case rtclog::Event::VIDEO_SENDER_CONFIG_EVENT:
- return ParsedRtcEventLog::EventType::VIDEO_SENDER_CONFIG_EVENT;
- case rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT:
- return ParsedRtcEventLog::EventType::AUDIO_RECEIVER_CONFIG_EVENT;
- case rtclog::Event::AUDIO_SENDER_CONFIG_EVENT:
- return ParsedRtcEventLog::EventType::AUDIO_SENDER_CONFIG_EVENT;
- }
- RTC_NOTREACHED();
- return ParsedRtcEventLog::EventType::UNKNOWN_EVENT;
-}
-
-std::pair<uint64_t, bool> ParseVarInt(std::istream& stream) {
- uint64_t varint = 0;
- for (size_t bytes_read = 0; bytes_read < 10; ++bytes_read) {
- // The most significant bit of each byte is 0 if it is the last byte in
- // the varint and 1 otherwise. Thus, we take the 7 least significant bits
- // of each byte and shift them 7 bits for each byte read previously to get
- // the (unsigned) integer.
- int byte = stream.get();
- if (stream.eof()) {
- return std::make_pair(varint, false);
- }
- RTC_DCHECK(0 <= byte && byte <= 255);
- varint |= static_cast<uint64_t>(byte & 0x7F) << (7 * bytes_read);
- if ((byte & 0x80) == 0) {
- return std::make_pair(varint, true);
- }
- }
- return std::make_pair(varint, false);
-}
-
-} // namespace
-
-bool ParsedRtcEventLog::ParseFile(const std::string& filename) {
- std::ifstream file(filename, std::ios_base::in | std::ios_base::binary);
- if (!file.good() || !file.is_open()) {
- LOG(LS_WARNING) << "Could not open file for reading.";
- return false;
- }
-
- return ParseStream(file);
-}
-
-bool ParsedRtcEventLog::ParseString(const std::string& s) {
- std::istringstream stream(s, std::ios_base::in | std::ios_base::binary);
- return ParseStream(stream);
-}
-
-bool ParsedRtcEventLog::ParseStream(std::istream& stream) {
- events_.clear();
- const size_t kMaxEventSize = (1u << 16) - 1;
- std::vector<char> tmp_buffer(kMaxEventSize);
- uint64_t tag;
- uint64_t message_length;
- bool success;
-
- RTC_DCHECK(stream.good());
-
- while (1) {
- // Check whether we have reached end of file.
- stream.peek();
- if (stream.eof()) {
- return true;
- }
-
- // Read the next message tag. The tag number is defined as
- // (fieldnumber << 3) | wire_type. In our case, the field number is
- // supposed to be 1 and the wire type for an length-delimited field is 2.
- const uint64_t kExpectedTag = (1 << 3) | 2;
- std::tie(tag, success) = ParseVarInt(stream);
- if (!success) {
- LOG(LS_WARNING) << "Missing field tag from beginning of protobuf event.";
- return false;
- } else if (tag != kExpectedTag) {
- LOG(LS_WARNING) << "Unexpected field tag at beginning of protobuf event.";
- return false;
- }
-
- // Read the length field.
- std::tie(message_length, success) = ParseVarInt(stream);
- if (!success) {
- LOG(LS_WARNING) << "Missing message length after protobuf field tag.";
- return false;
- } else if (message_length > kMaxEventSize) {
- LOG(LS_WARNING) << "Protobuf message length is too large.";
- return false;
- }
-
- // Read the next protobuf event to a temporary char buffer.
- stream.read(tmp_buffer.data(), message_length);
- if (stream.gcount() != static_cast<int>(message_length)) {
- LOG(LS_WARNING) << "Failed to read protobuf message from file.";
- return false;
- }
-
- // Parse the protobuf event from the buffer.
- rtclog::Event event;
- if (!event.ParseFromArray(tmp_buffer.data(), message_length)) {
- LOG(LS_WARNING) << "Failed to parse protobuf message.";
- return false;
- }
- events_.push_back(event);
- }
-}
-
-size_t ParsedRtcEventLog::GetNumberOfEvents() const {
- return events_.size();
-}
-
-int64_t ParsedRtcEventLog::GetTimestamp(size_t index) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_timestamp_us());
- return event.timestamp_us();
-}
-
-ParsedRtcEventLog::EventType ParsedRtcEventLog::GetEventType(
- size_t index) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_type());
- return GetRuntimeEventType(event.type());
-}
-
-// The header must have space for at least IP_PACKET_SIZE bytes.
-void ParsedRtcEventLog::GetRtpHeader(size_t index,
- PacketDirection* incoming,
- MediaType* media_type,
- uint8_t* header,
- size_t* header_length,
- size_t* total_length) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::RTP_EVENT);
- RTC_CHECK(event.has_rtp_packet());
- const rtclog::RtpPacket& rtp_packet = event.rtp_packet();
- // Get direction of packet.
- RTC_CHECK(rtp_packet.has_incoming());
- if (incoming != nullptr) {
- *incoming = rtp_packet.incoming() ? kIncomingPacket : kOutgoingPacket;
- }
- // Get media type.
- RTC_CHECK(rtp_packet.has_type());
- if (media_type != nullptr) {
- *media_type = GetRuntimeMediaType(rtp_packet.type());
- }
- // Get packet length.
- RTC_CHECK(rtp_packet.has_packet_length());
- if (total_length != nullptr) {
- *total_length = rtp_packet.packet_length();
- }
- // Get header length.
- RTC_CHECK(rtp_packet.has_header());
- if (header_length != nullptr) {
- *header_length = rtp_packet.header().size();
- }
- // Get header contents.
- if (header != nullptr) {
- const size_t kMinRtpHeaderSize = 12;
- RTC_CHECK_GE(rtp_packet.header().size(), kMinRtpHeaderSize);
- RTC_CHECK_LE(rtp_packet.header().size(),
- static_cast<size_t>(IP_PACKET_SIZE));
- memcpy(header, rtp_packet.header().data(), rtp_packet.header().size());
- }
-}
-
-// The packet must have space for at least IP_PACKET_SIZE bytes.
-void ParsedRtcEventLog::GetRtcpPacket(size_t index,
- PacketDirection* incoming,
- MediaType* media_type,
- uint8_t* packet,
- size_t* length) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::RTCP_EVENT);
- RTC_CHECK(event.has_rtcp_packet());
- const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet();
- // Get direction of packet.
- RTC_CHECK(rtcp_packet.has_incoming());
- if (incoming != nullptr) {
- *incoming = rtcp_packet.incoming() ? kIncomingPacket : kOutgoingPacket;
- }
- // Get media type.
- RTC_CHECK(rtcp_packet.has_type());
- if (media_type != nullptr) {
- *media_type = GetRuntimeMediaType(rtcp_packet.type());
- }
- // Get packet length.
- RTC_CHECK(rtcp_packet.has_packet_data());
- if (length != nullptr) {
- *length = rtcp_packet.packet_data().size();
- }
- // Get packet contents.
- if (packet != nullptr) {
- RTC_CHECK_LE(rtcp_packet.packet_data().size(),
- static_cast<unsigned>(IP_PACKET_SIZE));
- memcpy(packet, rtcp_packet.packet_data().data(),
- rtcp_packet.packet_data().size());
- }
-}
-
-void ParsedRtcEventLog::GetVideoReceiveConfig(
- size_t index,
- VideoReceiveStream::Config* config) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(config != nullptr);
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT);
- RTC_CHECK(event.has_video_receiver_config());
- const rtclog::VideoReceiveConfig& receiver_config =
- event.video_receiver_config();
- // Get SSRCs.
- RTC_CHECK(receiver_config.has_remote_ssrc());
- config->rtp.remote_ssrc = receiver_config.remote_ssrc();
- RTC_CHECK(receiver_config.has_local_ssrc());
- config->rtp.local_ssrc = receiver_config.local_ssrc();
- // Get RTCP settings.
- RTC_CHECK(receiver_config.has_rtcp_mode());
- config->rtp.rtcp_mode = GetRuntimeRtcpMode(receiver_config.rtcp_mode());
- RTC_CHECK(receiver_config.has_remb());
- config->rtp.remb = receiver_config.remb();
- // Get RTX map.
- config->rtp.rtx.clear();
- for (int i = 0; i < receiver_config.rtx_map_size(); i++) {
- const rtclog::RtxMap& map = receiver_config.rtx_map(i);
- RTC_CHECK(map.has_payload_type());
- RTC_CHECK(map.has_config());
- RTC_CHECK(map.config().has_rtx_ssrc());
- RTC_CHECK(map.config().has_rtx_payload_type());
- webrtc::VideoReceiveStream::Config::Rtp::Rtx rtx_pair;
- rtx_pair.ssrc = map.config().rtx_ssrc();
- rtx_pair.payload_type = map.config().rtx_payload_type();
- config->rtp.rtx.insert(std::make_pair(map.payload_type(), rtx_pair));
- }
- // Get header extensions.
- config->rtp.extensions.clear();
- for (int i = 0; i < receiver_config.header_extensions_size(); i++) {
- RTC_CHECK(receiver_config.header_extensions(i).has_name());
- RTC_CHECK(receiver_config.header_extensions(i).has_id());
- const std::string& name = receiver_config.header_extensions(i).name();
- int id = receiver_config.header_extensions(i).id();
- config->rtp.extensions.push_back(RtpExtension(name, id));
- }
- // Get decoders.
- config->decoders.clear();
- for (int i = 0; i < receiver_config.decoders_size(); i++) {
- RTC_CHECK(receiver_config.decoders(i).has_name());
- RTC_CHECK(receiver_config.decoders(i).has_payload_type());
- VideoReceiveStream::Decoder decoder;
- decoder.payload_name = receiver_config.decoders(i).name();
- decoder.payload_type = receiver_config.decoders(i).payload_type();
- config->decoders.push_back(decoder);
- }
-}
-
-void ParsedRtcEventLog::GetVideoSendConfig(
- size_t index,
- VideoSendStream::Config* config) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(config != nullptr);
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::VIDEO_SENDER_CONFIG_EVENT);
- RTC_CHECK(event.has_video_sender_config());
- const rtclog::VideoSendConfig& sender_config = event.video_sender_config();
- // Get SSRCs.
- config->rtp.ssrcs.clear();
- for (int i = 0; i < sender_config.ssrcs_size(); i++) {
- config->rtp.ssrcs.push_back(sender_config.ssrcs(i));
- }
- // Get header extensions.
- config->rtp.extensions.clear();
- for (int i = 0; i < sender_config.header_extensions_size(); i++) {
- RTC_CHECK(sender_config.header_extensions(i).has_name());
- RTC_CHECK(sender_config.header_extensions(i).has_id());
- const std::string& name = sender_config.header_extensions(i).name();
- int id = sender_config.header_extensions(i).id();
- config->rtp.extensions.push_back(RtpExtension(name, id));
- }
- // Get RTX settings.
- config->rtp.rtx.ssrcs.clear();
- for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) {
- config->rtp.rtx.ssrcs.push_back(sender_config.rtx_ssrcs(i));
- }
- if (sender_config.rtx_ssrcs_size() > 0) {
- RTC_CHECK(sender_config.has_rtx_payload_type());
- config->rtp.rtx.payload_type = sender_config.rtx_payload_type();
- } else {
- // Reset RTX payload type default value if no RTX SSRCs are used.
- config->rtp.rtx.payload_type = -1;
- }
- // Get encoder.
- RTC_CHECK(sender_config.has_encoder());
- RTC_CHECK(sender_config.encoder().has_name());
- RTC_CHECK(sender_config.encoder().has_payload_type());
- config->encoder_settings.payload_name = sender_config.encoder().name();
- config->encoder_settings.payload_type =
- sender_config.encoder().payload_type();
-}
-
-void ParsedRtcEventLog::GetAudioPlayout(size_t index, uint32_t* ssrc) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::AUDIO_PLAYOUT_EVENT);
- RTC_CHECK(event.has_audio_playout_event());
- const rtclog::AudioPlayoutEvent& loss_event = event.audio_playout_event();
- RTC_CHECK(loss_event.has_local_ssrc());
- if (ssrc != nullptr) {
- *ssrc = loss_event.local_ssrc();
- }
-}
-
-void ParsedRtcEventLog::GetBwePacketLossEvent(size_t index,
- int32_t* bitrate,
- uint8_t* fraction_loss,
- int32_t* total_packets) const {
- RTC_CHECK_LT(index, GetNumberOfEvents());
- const rtclog::Event& event = events_[index];
- RTC_CHECK(event.has_type());
- RTC_CHECK_EQ(event.type(), rtclog::Event::BWE_PACKET_LOSS_EVENT);
- RTC_CHECK(event.has_bwe_packet_loss_event());
- const rtclog::BwePacketLossEvent& loss_event = event.bwe_packet_loss_event();
- RTC_CHECK(loss_event.has_bitrate());
- if (bitrate != nullptr) {
- *bitrate = loss_event.bitrate();
- }
- RTC_CHECK(loss_event.has_fraction_loss());
- if (fraction_loss != nullptr) {
- *fraction_loss = loss_event.fraction_loss();
- }
- RTC_CHECK(loss_event.has_total_packets());
- if (total_packets != nullptr) {
- *total_packets = loss_event.total_packets();
- }
-}
-
-} // namespace webrtc
diff --git a/call/rtc_event_log_parser.h b/call/rtc_event_log_parser.h
deleted file mode 100644
index a50ec20..0000000
--- a/call/rtc_event_log_parser.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2016 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.
- */
-#ifndef WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_
-#define WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_
-
-#include <string>
-#include <vector>
-
-#include "webrtc/base/ignore_wundef.h"
-#include "webrtc/call/rtc_event_log.h"
-#include "webrtc/video_receive_stream.h"
-#include "webrtc/video_send_stream.h"
-
-// Files generated at build-time by the protobuf compiler.
-RTC_PUSH_IGNORING_WUNDEF()
-#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
-#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
-#else
-#include "webrtc/call/rtc_event_log.pb.h"
-#endif
-RTC_POP_IGNORING_WUNDEF()
-
-namespace webrtc {
-
-enum class MediaType;
-
-class ParsedRtcEventLog {
- friend class RtcEventLogTestHelper;
-
- public:
- enum EventType {
- UNKNOWN_EVENT = 0,
- LOG_START = 1,
- LOG_END = 2,
- RTP_EVENT = 3,
- RTCP_EVENT = 4,
- AUDIO_PLAYOUT_EVENT = 5,
- BWE_PACKET_LOSS_EVENT = 6,
- BWE_PACKET_DELAY_EVENT = 7,
- VIDEO_RECEIVER_CONFIG_EVENT = 8,
- VIDEO_SENDER_CONFIG_EVENT = 9,
- AUDIO_RECEIVER_CONFIG_EVENT = 10,
- AUDIO_SENDER_CONFIG_EVENT = 11
- };
-
- // Reads an RtcEventLog file and returns true if parsing was successful.
- bool ParseFile(const std::string& file_name);
-
- // Reads an RtcEventLog from a string and returns true if successful.
- bool ParseString(const std::string& s);
-
- // Reads an RtcEventLog from an istream and returns true if successful.
- bool ParseStream(std::istream& stream);
-
- // Returns the number of events in an EventStream.
- size_t GetNumberOfEvents() const;
-
- // Reads the arrival timestamp (in microseconds) from a rtclog::Event.
- int64_t GetTimestamp(size_t index) const;
-
- // Reads the event type of the rtclog::Event at |index|.
- EventType GetEventType(size_t index) const;
-
- // Reads the header, direction, media type, header length and packet length
- // from the RTP event at |index|, and stores the values in the corresponding
- // output parameters. The output parameters can be set to nullptr if those
- // values aren't needed.
- // NB: The header must have space for at least IP_PACKET_SIZE bytes.
- void GetRtpHeader(size_t index,
- PacketDirection* incoming,
- MediaType* media_type,
- uint8_t* header,
- size_t* header_length,
- size_t* total_length) const;
-
- // Reads packet, direction, media type and packet length from the RTCP event
- // at |index|, and stores the values in the corresponding output parameters.
- // The output parameters can be set to nullptr if those values aren't needed.
- // NB: The packet must have space for at least IP_PACKET_SIZE bytes.
- void GetRtcpPacket(size_t index,
- PacketDirection* incoming,
- MediaType* media_type,
- uint8_t* packet,
- size_t* length) const;
-
- // Reads a config event to a (non-NULL) VideoReceiveStream::Config struct.
- // Only the fields that are stored in the protobuf will be written.
- void GetVideoReceiveConfig(size_t index,
- VideoReceiveStream::Config* config) const;
-
- // Reads a config event to a (non-NULL) VideoSendStream::Config struct.
- // Only the fields that are stored in the protobuf will be written.
- void GetVideoSendConfig(size_t index, VideoSendStream::Config* config) const;
-
- // Reads the SSRC from the audio playout event at |index|. The SSRC is stored
- // in the output parameter ssrc. The output parameter can be set to nullptr
- // and in that case the function only asserts that the event is well formed.
- void GetAudioPlayout(size_t index, uint32_t* ssrc) const;
-
- // Reads bitrate, fraction loss (as defined in RFC 1889) and total number of
- // expected packets from the BWE event at |index| and stores the values in
- // the corresponding output parameters. The output parameters can be set to
- // nullptr if those values aren't needed.
- // NB: The packet must have space for at least IP_PACKET_SIZE bytes.
- void GetBwePacketLossEvent(size_t index,
- int32_t* bitrate,
- uint8_t* fraction_loss,
- int32_t* total_packets) const;
-
- private:
- std::vector<rtclog::Event> events_;
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_
diff --git a/call/rtc_event_log_unittest.cc b/call/rtc_event_log_unittest.cc
deleted file mode 100644
index 6c4ec63..0000000
--- a/call/rtc_event_log_unittest.cc
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * Copyright (c) 2015 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 <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "webrtc/base/buffer.h"
-#include "webrtc/base/checks.h"
-#include "webrtc/base/random.h"
-#include "webrtc/call.h"
-#include "webrtc/call/rtc_event_log.h"
-#include "webrtc/call/rtc_event_log_parser.h"
-#include "webrtc/call/rtc_event_log_unittest_helper.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
-#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
-#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
-#include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
-#include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/test/gtest.h"
-#include "webrtc/test/test_suite.h"
-#include "webrtc/test/testsupport/fileutils.h"
-
-// Files generated at build-time by the protobuf compiler.
-#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
-#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
-#else
-#include "webrtc/call/rtc_event_log.pb.h"
-#endif
-
-namespace webrtc {
-
-namespace {
-
-const RTPExtensionType kExtensionTypes[] = {
- RTPExtensionType::kRtpExtensionTransmissionTimeOffset,
- RTPExtensionType::kRtpExtensionAudioLevel,
- RTPExtensionType::kRtpExtensionAbsoluteSendTime,
- RTPExtensionType::kRtpExtensionVideoRotation,
- RTPExtensionType::kRtpExtensionTransportSequenceNumber};
-const char* kExtensionNames[] = {
- RtpExtension::kTimestampOffsetUri, RtpExtension::kAudioLevelUri,
- RtpExtension::kAbsSendTimeUri, RtpExtension::kVideoRotationUri,
- RtpExtension::kTransportSequenceNumberUri};
-const size_t kNumExtensions = 5;
-
-void PrintActualEvents(const ParsedRtcEventLog& parsed_log) {
- std::map<int, size_t> actual_event_counts;
- for (size_t i = 0; i < parsed_log.GetNumberOfEvents(); i++) {
- actual_event_counts[parsed_log.GetEventType(i)]++;
- }
- printf("Actual events: ");
- for (auto kv : actual_event_counts) {
- printf("%d_count = %zu, ", kv.first, kv.second);
- }
- printf("\n");
- for (size_t i = 0; i < parsed_log.GetNumberOfEvents(); i++) {
- printf("%4d ", parsed_log.GetEventType(i));
- }
- printf("\n");
-}
-
-void PrintExpectedEvents(size_t rtp_count,
- size_t rtcp_count,
- size_t playout_count,
- size_t bwe_loss_count) {
- printf(
- "Expected events: rtp_count = %zu, rtcp_count = %zu,"
- "playout_count = %zu, bwe_loss_count = %zu\n",
- rtp_count, rtcp_count, playout_count, bwe_loss_count);
- size_t rtcp_index = 1, playout_index = 1, bwe_loss_index = 1;
- printf("strt cfg cfg ");
- for (size_t i = 1; i <= rtp_count; i++) {
- printf(" rtp ");
- if (i * rtcp_count >= rtcp_index * rtp_count) {
- printf("rtcp ");
- rtcp_index++;
- }
- if (i * playout_count >= playout_index * rtp_count) {
- printf("play ");
- playout_index++;
- }
- if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
- printf("loss ");
- bwe_loss_index++;
- }
- }
- printf("end \n");
-}
-} // namespace
-
-/*
- * Bit number i of extension_bitvector is set to indicate the
- * presence of extension number i from kExtensionTypes / kExtensionNames.
- * The least significant bit extension_bitvector has number 0.
- */
-RtpPacketToSend GenerateRtpPacket(const RtpHeaderExtensionMap* extensions,
- uint32_t csrcs_count,
- size_t packet_size,
- Random* prng) {
- RTC_CHECK_GE(packet_size, 16 + 4 * csrcs_count + 4 * kNumExtensions);
-
- std::vector<uint32_t> csrcs;
- for (unsigned i = 0; i < csrcs_count; i++) {
- csrcs.push_back(prng->Rand<uint32_t>());
- }
-
- RtpPacketToSend rtp_packet(extensions, packet_size);
- rtp_packet.SetPayloadType(prng->Rand(127));
- rtp_packet.SetMarker(prng->Rand<bool>());
- rtp_packet.SetSequenceNumber(prng->Rand<uint16_t>());
- rtp_packet.SetSsrc(prng->Rand<uint32_t>());
- rtp_packet.SetTimestamp(prng->Rand<uint32_t>());
- rtp_packet.SetCsrcs(csrcs);
-
- rtp_packet.SetExtension<TransmissionOffset>(prng->Rand(0x00ffffff));
- rtp_packet.SetExtension<AudioLevel>(prng->Rand<bool>(), prng->Rand(127));
- rtp_packet.SetExtension<AbsoluteSendTime>(prng->Rand<int32_t>());
- rtp_packet.SetExtension<VideoOrientation>(prng->Rand(2));
- rtp_packet.SetExtension<TransportSequenceNumber>(prng->Rand<uint16_t>());
-
- size_t payload_size = packet_size - rtp_packet.headers_size();
- uint8_t* payload = rtp_packet.AllocatePayload(payload_size);
- for (size_t i = 0; i < payload_size; i++) {
- payload[i] = prng->Rand<uint8_t>();
- }
- return rtp_packet;
-}
-
-rtc::Buffer GenerateRtcpPacket(Random* prng) {
- rtcp::ReportBlock report_block;
- report_block.SetMediaSsrc(prng->Rand<uint32_t>()); // Remote SSRC.
- report_block.SetFractionLost(prng->Rand(50));
-
- rtcp::SenderReport sender_report;
- sender_report.SetSenderSsrc(prng->Rand<uint32_t>());
- sender_report.SetNtp(NtpTime(prng->Rand<uint32_t>(), prng->Rand<uint32_t>()));
- sender_report.SetPacketCount(prng->Rand<uint32_t>());
- sender_report.AddReportBlock(report_block);
-
- return sender_report.Build();
-}
-
-void GenerateVideoReceiveConfig(uint32_t extensions_bitvector,
- VideoReceiveStream::Config* config,
- Random* prng) {
- // Create a map from a payload type to an encoder name.
- VideoReceiveStream::Decoder decoder;
- decoder.payload_type = prng->Rand(0, 127);
- decoder.payload_name = (prng->Rand<bool>() ? "VP8" : "H264");
- config->decoders.push_back(decoder);
- // Add SSRCs for the stream.
- config->rtp.remote_ssrc = prng->Rand<uint32_t>();
- config->rtp.local_ssrc = prng->Rand<uint32_t>();
- // Add extensions and settings for RTCP.
- config->rtp.rtcp_mode =
- prng->Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize;
- config->rtp.remb = prng->Rand<bool>();
- // Add a map from a payload type to a new ssrc and a new payload type for RTX.
- VideoReceiveStream::Config::Rtp::Rtx rtx_pair;
- rtx_pair.ssrc = prng->Rand<uint32_t>();
- rtx_pair.payload_type = prng->Rand(0, 127);
- config->rtp.rtx.insert(std::make_pair(prng->Rand(0, 127), rtx_pair));
- // Add header extensions.
- for (unsigned i = 0; i < kNumExtensions; i++) {
- if (extensions_bitvector & (1u << i)) {
- config->rtp.extensions.push_back(
- RtpExtension(kExtensionNames[i], prng->Rand<int>()));
- }
- }
-}
-
-void GenerateVideoSendConfig(uint32_t extensions_bitvector,
- VideoSendStream::Config* config,
- Random* prng) {
- // Create a map from a payload type to an encoder name.
- config->encoder_settings.payload_type = prng->Rand(0, 127);
- config->encoder_settings.payload_name = (prng->Rand<bool>() ? "VP8" : "H264");
- // Add SSRCs for the stream.
- config->rtp.ssrcs.push_back(prng->Rand<uint32_t>());
- // Add a map from a payload type to new ssrcs and a new payload type for RTX.
- config->rtp.rtx.ssrcs.push_back(prng->Rand<uint32_t>());
- config->rtp.rtx.payload_type = prng->Rand(0, 127);
- // Add header extensions.
- for (unsigned i = 0; i < kNumExtensions; i++) {
- if (extensions_bitvector & (1u << i)) {
- config->rtp.extensions.push_back(
- RtpExtension(kExtensionNames[i], prng->Rand<int>()));
- }
- }
-}
-
-// Test for the RtcEventLog class. Dumps some RTP packets and other events
-// to disk, then reads them back to see if they match.
-void LogSessionAndReadBack(size_t rtp_count,
- size_t rtcp_count,
- size_t playout_count,
- size_t bwe_loss_count,
- uint32_t extensions_bitvector,
- uint32_t csrcs_count,
- unsigned int random_seed) {
- ASSERT_LE(rtcp_count, rtp_count);
- ASSERT_LE(playout_count, rtp_count);
- ASSERT_LE(bwe_loss_count, rtp_count);
- std::vector<RtpPacketToSend> rtp_packets;
- std::vector<rtc::Buffer> rtcp_packets;
- std::vector<uint32_t> playout_ssrcs;
- std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates;
-
- VideoReceiveStream::Config receiver_config(nullptr);
- VideoSendStream::Config sender_config(nullptr);
-
- Random prng(random_seed);
-
- // Initialize rtp header extensions to be used in generated rtp packets.
- RtpHeaderExtensionMap extensions;
- for (unsigned i = 0; i < kNumExtensions; i++) {
- if (extensions_bitvector & (1u << i)) {
- extensions.Register(kExtensionTypes[i], i + 1);
- }
- }
- // Create rtp_count RTP packets containing random data.
- for (size_t i = 0; i < rtp_count; i++) {
- size_t packet_size = prng.Rand(1000, 1100);
- rtp_packets.push_back(
- GenerateRtpPacket(&extensions, csrcs_count, packet_size, &prng));
- }
- // Create rtcp_count RTCP packets containing random data.
- for (size_t i = 0; i < rtcp_count; i++) {
- rtcp_packets.push_back(GenerateRtcpPacket(&prng));
- }
- // Create playout_count random SSRCs to use when logging AudioPlayout events.
- for (size_t i = 0; i < playout_count; i++) {
- playout_ssrcs.push_back(prng.Rand<uint32_t>());
- }
- // Create bwe_loss_count random bitrate updates for BwePacketLoss.
- for (size_t i = 0; i < bwe_loss_count; i++) {
- bwe_loss_updates.push_back(
- std::make_pair(prng.Rand<int32_t>(), prng.Rand<uint8_t>()));
- }
- // Create configurations for the video streams.
- GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng);
- GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng);
- const int config_count = 2;
-
- // Find the name of the current test, in order to use it as a temporary
- // filename.
- auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
- const std::string temp_filename =
- test::OutputPath() + test_info->test_case_name() + test_info->name();
-
- // When log_dumper goes out of scope, it causes the log file to be flushed
- // to disk.
- {
- SimulatedClock fake_clock(prng.Rand<uint32_t>());
- std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock));
- log_dumper->LogVideoReceiveStreamConfig(receiver_config);
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- log_dumper->LogVideoSendStreamConfig(sender_config);
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- size_t rtcp_index = 1;
- size_t playout_index = 1;
- size_t bwe_loss_index = 1;
- for (size_t i = 1; i <= rtp_count; i++) {
- log_dumper->LogRtpHeader(
- (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket,
- (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
- rtp_packets[i - 1].data(), rtp_packets[i - 1].size());
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- if (i * rtcp_count >= rtcp_index * rtp_count) {
- log_dumper->LogRtcpPacket(
- (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket,
- rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
- rtcp_packets[rtcp_index - 1].data(),
- rtcp_packets[rtcp_index - 1].size());
- rtcp_index++;
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- }
- if (i * playout_count >= playout_index * rtp_count) {
- log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]);
- playout_index++;
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- }
- if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
- log_dumper->LogBwePacketLossEvent(
- bwe_loss_updates[bwe_loss_index - 1].first,
- bwe_loss_updates[bwe_loss_index - 1].second, i);
- bwe_loss_index++;
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- }
- if (i == rtp_count / 2) {
- log_dumper->StartLogging(temp_filename, 10000000);
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
- }
- }
- log_dumper->StopLogging();
- }
-
- // Read the generated file from disk.
- ParsedRtcEventLog parsed_log;
-
- ASSERT_TRUE(parsed_log.ParseFile(temp_filename));
-
- // Verify that what we read back from the event log is the same as
- // what we wrote down. For RTCP we log the full packets, but for
- // RTP we should only log the header.
- const size_t event_count = config_count + playout_count + bwe_loss_count +
- rtcp_count + rtp_count + 2;
- EXPECT_GE(1000u, event_count); // The events must fit in the message queue.
- EXPECT_EQ(event_count, parsed_log.GetNumberOfEvents());
- if (event_count != parsed_log.GetNumberOfEvents()) {
- // Print the expected and actual event types for easier debugging.
- PrintActualEvents(parsed_log);
- PrintExpectedEvents(rtp_count, rtcp_count, playout_count, bwe_loss_count);
- }
- RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0);
- RtcEventLogTestHelper::VerifyReceiveStreamConfig(parsed_log, 1,
- receiver_config);
- RtcEventLogTestHelper::VerifySendStreamConfig(parsed_log, 2, sender_config);
- size_t event_index = config_count + 1;
- size_t rtcp_index = 1;
- size_t playout_index = 1;
- size_t bwe_loss_index = 1;
- for (size_t i = 1; i <= rtp_count; i++) {
- RtcEventLogTestHelper::VerifyRtpEvent(
- parsed_log, event_index,
- (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket,
- (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
- rtp_packets[i - 1].data(), rtp_packets[i - 1].headers_size(),
- rtp_packets[i - 1].size());
- event_index++;
- if (i * rtcp_count >= rtcp_index * rtp_count) {
- RtcEventLogTestHelper::VerifyRtcpEvent(
- parsed_log, event_index,
- rtcp_index % 2 == 0 ? kIncomingPacket : kOutgoingPacket,
- rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
- rtcp_packets[rtcp_index - 1].data(),
- rtcp_packets[rtcp_index - 1].size());
- event_index++;
- rtcp_index++;
- }
- if (i * playout_count >= playout_index * rtp_count) {
- RtcEventLogTestHelper::VerifyPlayoutEvent(
- parsed_log, event_index, playout_ssrcs[playout_index - 1]);
- event_index++;
- playout_index++;
- }
- if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
- RtcEventLogTestHelper::VerifyBweLossEvent(
- parsed_log, event_index, bwe_loss_updates[bwe_loss_index - 1].first,
- bwe_loss_updates[bwe_loss_index - 1].second, i);
- event_index++;
- bwe_loss_index++;
- }
- }
-
- // Clean up temporary file - can be pretty slow.
- remove(temp_filename.c_str());
-}
-
-TEST(RtcEventLogTest, LogSessionAndReadBack) {
- // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events
- // with no header extensions or CSRCS.
- LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321);
-
- // Enable AbsSendTime and TransportSequenceNumbers.
- uint32_t extensions = 0;
- for (uint32_t i = 0; i < kNumExtensions; i++) {
- if (kExtensionTypes[i] == RTPExtensionType::kRtpExtensionAbsoluteSendTime ||
- kExtensionTypes[i] ==
- RTPExtensionType::kRtpExtensionTransportSequenceNumber) {
- extensions |= 1u << i;
- }
- }
- LogSessionAndReadBack(8, 2, 0, 0, extensions, 0, 3141592653u);
-
- extensions = (1u << kNumExtensions) - 1; // Enable all header extensions.
- LogSessionAndReadBack(9, 2, 3, 2, extensions, 2, 2718281828u);
-
- // Try all combinations of header extensions and up to 2 CSRCS.
- for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) {
- for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) {
- LogSessionAndReadBack(5 + extensions, // Number of RTP packets.
- 2 + csrcs_count, // Number of RTCP packets.
- 3 + csrcs_count, // Number of playout events.
- 1 + csrcs_count, // Number of BWE loss events.
- extensions, // Bit vector choosing extensions.
- csrcs_count, // Number of contributing sources.
- extensions * 3 + csrcs_count + 1); // Random seed.
- }
- }
-}
-
-TEST(RtcEventLogTest, LogEventAndReadBack) {
- Random prng(987654321);
-
- // Create one RTP and one RTCP packet containing random data.
- size_t packet_size = prng.Rand(1000, 1100);
- RtpPacketToSend rtp_packet =
- GenerateRtpPacket(nullptr, 0, packet_size, &prng);
- rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng);
-
- // Find the name of the current test, in order to use it as a temporary
- // filename.
- auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
- const std::string temp_filename =
- test::OutputPath() + test_info->test_case_name() + test_info->name();
-
- // Add RTP, start logging, add RTCP and then stop logging
- SimulatedClock fake_clock(prng.Rand<uint32_t>());
- std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock));
-
- log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(),
- rtp_packet.size());
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
-
- log_dumper->StartLogging(temp_filename, 10000000);
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
-
- log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO,
- rtcp_packet.data(), rtcp_packet.size());
- fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
-
- log_dumper->StopLogging();
-
- // Read the generated file from disk.
- ParsedRtcEventLog parsed_log;
- ASSERT_TRUE(parsed_log.ParseFile(temp_filename));
-
- // Verify that what we read back from the event log is the same as
- // what we wrote down.
- EXPECT_EQ(4u, parsed_log.GetNumberOfEvents());
-
- RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0);
-
- RtcEventLogTestHelper::VerifyRtpEvent(
- parsed_log, 1, kIncomingPacket, MediaType::VIDEO, rtp_packet.data(),
- rtp_packet.headers_size(), rtp_packet.size());
-
- RtcEventLogTestHelper::VerifyRtcpEvent(parsed_log, 2, kOutgoingPacket,
- MediaType::VIDEO, rtcp_packet.data(),
- rtcp_packet.size());
-
- RtcEventLogTestHelper::VerifyLogEndEvent(parsed_log, 3);
-
- // Clean up temporary file - can be pretty slow.
- remove(temp_filename.c_str());
-}
-
-} // namespace webrtc
diff --git a/call/rtc_event_log_unittest_helper.cc b/call/rtc_event_log_unittest_helper.cc
deleted file mode 100644
index 566e92b..0000000
--- a/call/rtc_event_log_unittest_helper.cc
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * Copyright (c) 2016 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 "webrtc/call/rtc_event_log_unittest_helper.h"
-
-#include <string.h>
-
-#include <string>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/test/gtest.h"
-#include "webrtc/test/test_suite.h"
-#include "webrtc/test/testsupport/fileutils.h"
-
-// Files generated at build-time by the protobuf compiler.
-#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
-#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
-#else
-#include "webrtc/call/rtc_event_log.pb.h"
-#endif
-
-namespace webrtc {
-
-namespace {
-MediaType GetRuntimeMediaType(rtclog::MediaType media_type) {
- switch (media_type) {
- case rtclog::MediaType::ANY:
- return MediaType::ANY;
- case rtclog::MediaType::AUDIO:
- return MediaType::AUDIO;
- case rtclog::MediaType::VIDEO:
- return MediaType::VIDEO;
- case rtclog::MediaType::DATA:
- return MediaType::DATA;
- }
- RTC_NOTREACHED();
- return MediaType::ANY;
-}
-} // namespace
-
-// Checks that the event has a timestamp, a type and exactly the data field
-// corresponding to the type.
-::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) {
- if (!event.has_timestamp_us()) {
- return ::testing::AssertionFailure() << "Event has no timestamp";
- }
- if (!event.has_type()) {
- return ::testing::AssertionFailure() << "Event has no event type";
- }
- rtclog::Event_EventType type = event.type();
- if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_rtp_packet() ? "" : "no ") << "RTP packet";
- }
- if ((type == rtclog::Event::RTCP_EVENT) != event.has_rtcp_packet()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_rtcp_packet() ? "" : "no ") << "RTCP packet";
- }
- if ((type == rtclog::Event::AUDIO_PLAYOUT_EVENT) !=
- event.has_audio_playout_event()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_audio_playout_event() ? "" : "no ")
- << "audio_playout event";
- }
- if ((type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT) !=
- event.has_video_receiver_config()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_video_receiver_config() ? "" : "no ")
- << "receiver config";
- }
- if ((type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT) !=
- event.has_video_sender_config()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_video_sender_config() ? "" : "no ") << "sender config";
- }
- if ((type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT) !=
- event.has_audio_receiver_config()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_audio_receiver_config() ? "" : "no ")
- << "audio receiver config";
- }
- if ((type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT) !=
- event.has_audio_sender_config()) {
- return ::testing::AssertionFailure()
- << "Event of type " << type << " has "
- << (event.has_audio_sender_config() ? "" : "no ")
- << "audio sender config";
- }
- return ::testing::AssertionSuccess();
-}
-
-void RtcEventLogTestHelper::VerifyReceiveStreamConfig(
- const ParsedRtcEventLog& parsed_log,
- size_t index,
- const VideoReceiveStream::Config& config) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT, event.type());
- const rtclog::VideoReceiveConfig& receiver_config =
- event.video_receiver_config();
- // Check SSRCs.
- ASSERT_TRUE(receiver_config.has_remote_ssrc());
- EXPECT_EQ(config.rtp.remote_ssrc, receiver_config.remote_ssrc());
- ASSERT_TRUE(receiver_config.has_local_ssrc());
- EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc());
- // Check RTCP settings.
- ASSERT_TRUE(receiver_config.has_rtcp_mode());
- if (config.rtp.rtcp_mode == RtcpMode::kCompound) {
- EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_COMPOUND,
- receiver_config.rtcp_mode());
- } else {
- EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE,
- receiver_config.rtcp_mode());
- }
- ASSERT_TRUE(receiver_config.has_remb());
- EXPECT_EQ(config.rtp.remb, receiver_config.remb());
- // Check RTX map.
- ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()),
- receiver_config.rtx_map_size());
- for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) {
- ASSERT_TRUE(rtx_map.has_payload_type());
- ASSERT_TRUE(rtx_map.has_config());
- EXPECT_EQ(1u, config.rtp.rtx.count(rtx_map.payload_type()));
- const rtclog::RtxConfig& rtx_config = rtx_map.config();
- const VideoReceiveStream::Config::Rtp::Rtx& rtx =
- config.rtp.rtx.at(rtx_map.payload_type());
- ASSERT_TRUE(rtx_config.has_rtx_ssrc());
- ASSERT_TRUE(rtx_config.has_rtx_payload_type());
- EXPECT_EQ(rtx.ssrc, rtx_config.rtx_ssrc());
- EXPECT_EQ(rtx.payload_type, rtx_config.rtx_payload_type());
- }
- // Check header extensions.
- ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()),
- receiver_config.header_extensions_size());
- for (int i = 0; i < receiver_config.header_extensions_size(); i++) {
- ASSERT_TRUE(receiver_config.header_extensions(i).has_name());
- ASSERT_TRUE(receiver_config.header_extensions(i).has_id());
- const std::string& name = receiver_config.header_extensions(i).name();
- int id = receiver_config.header_extensions(i).id();
- EXPECT_EQ(config.rtp.extensions[i].id, id);
- EXPECT_EQ(config.rtp.extensions[i].uri, name);
- }
- // Check decoders.
- ASSERT_EQ(static_cast<int>(config.decoders.size()),
- receiver_config.decoders_size());
- for (int i = 0; i < receiver_config.decoders_size(); i++) {
- ASSERT_TRUE(receiver_config.decoders(i).has_name());
- ASSERT_TRUE(receiver_config.decoders(i).has_payload_type());
- const std::string& decoder_name = receiver_config.decoders(i).name();
- int decoder_type = receiver_config.decoders(i).payload_type();
- EXPECT_EQ(config.decoders[i].payload_name, decoder_name);
- EXPECT_EQ(config.decoders[i].payload_type, decoder_type);
- }
-
- // Check consistency of the parser.
- VideoReceiveStream::Config parsed_config(nullptr);
- parsed_log.GetVideoReceiveConfig(index, &parsed_config);
- EXPECT_EQ(config.rtp.remote_ssrc, parsed_config.rtp.remote_ssrc);
- EXPECT_EQ(config.rtp.local_ssrc, parsed_config.rtp.local_ssrc);
- // Check RTCP settings.
- EXPECT_EQ(config.rtp.rtcp_mode, parsed_config.rtp.rtcp_mode);
- EXPECT_EQ(config.rtp.remb, parsed_config.rtp.remb);
- // Check RTX map.
- EXPECT_EQ(config.rtp.rtx.size(), parsed_config.rtp.rtx.size());
- for (const auto& kv : config.rtp.rtx) {
- auto parsed_kv = parsed_config.rtp.rtx.find(kv.first);
- EXPECT_EQ(kv.first, parsed_kv->first);
- EXPECT_EQ(kv.second.ssrc, parsed_kv->second.ssrc);
- EXPECT_EQ(kv.second.payload_type, parsed_kv->second.payload_type);
- }
- // Check header extensions.
- EXPECT_EQ(config.rtp.extensions.size(), parsed_config.rtp.extensions.size());
- for (size_t i = 0; i < parsed_config.rtp.extensions.size(); i++) {
- EXPECT_EQ(config.rtp.extensions[i].uri,
- parsed_config.rtp.extensions[i].uri);
- EXPECT_EQ(config.rtp.extensions[i].id, parsed_config.rtp.extensions[i].id);
- }
- // Check decoders.
- EXPECT_EQ(config.decoders.size(), parsed_config.decoders.size());
- for (size_t i = 0; i < parsed_config.decoders.size(); i++) {
- EXPECT_EQ(config.decoders[i].payload_name,
- parsed_config.decoders[i].payload_name);
- EXPECT_EQ(config.decoders[i].payload_type,
- parsed_config.decoders[i].payload_type);
- }
-}
-
-void RtcEventLogTestHelper::VerifySendStreamConfig(
- const ParsedRtcEventLog& parsed_log,
- size_t index,
- const VideoSendStream::Config& config) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::VIDEO_SENDER_CONFIG_EVENT, event.type());
- const rtclog::VideoSendConfig& sender_config = event.video_sender_config();
- // Check SSRCs.
- ASSERT_EQ(static_cast<int>(config.rtp.ssrcs.size()),
- sender_config.ssrcs_size());
- for (int i = 0; i < sender_config.ssrcs_size(); i++) {
- EXPECT_EQ(config.rtp.ssrcs[i], sender_config.ssrcs(i));
- }
- // Check header extensions.
- ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()),
- sender_config.header_extensions_size());
- for (int i = 0; i < sender_config.header_extensions_size(); i++) {
- ASSERT_TRUE(sender_config.header_extensions(i).has_name());
- ASSERT_TRUE(sender_config.header_extensions(i).has_id());
- const std::string& name = sender_config.header_extensions(i).name();
- int id = sender_config.header_extensions(i).id();
- EXPECT_EQ(config.rtp.extensions[i].id, id);
- EXPECT_EQ(config.rtp.extensions[i].uri, name);
- }
- // Check RTX settings.
- ASSERT_EQ(static_cast<int>(config.rtp.rtx.ssrcs.size()),
- sender_config.rtx_ssrcs_size());
- for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) {
- EXPECT_EQ(config.rtp.rtx.ssrcs[i], sender_config.rtx_ssrcs(i));
- }
- if (sender_config.rtx_ssrcs_size() > 0) {
- ASSERT_TRUE(sender_config.has_rtx_payload_type());
- EXPECT_EQ(config.rtp.rtx.payload_type, sender_config.rtx_payload_type());
- }
- // Check encoder.
- ASSERT_TRUE(sender_config.has_encoder());
- ASSERT_TRUE(sender_config.encoder().has_name());
- ASSERT_TRUE(sender_config.encoder().has_payload_type());
- EXPECT_EQ(config.encoder_settings.payload_name,
- sender_config.encoder().name());
- EXPECT_EQ(config.encoder_settings.payload_type,
- sender_config.encoder().payload_type());
-
- // Check consistency of the parser.
- VideoSendStream::Config parsed_config(nullptr);
- parsed_log.GetVideoSendConfig(index, &parsed_config);
- // Check SSRCs
- EXPECT_EQ(config.rtp.ssrcs.size(), parsed_config.rtp.ssrcs.size());
- for (size_t i = 0; i < config.rtp.ssrcs.size(); i++) {
- EXPECT_EQ(config.rtp.ssrcs[i], parsed_config.rtp.ssrcs[i]);
- }
- // Check header extensions.
- EXPECT_EQ(config.rtp.extensions.size(), parsed_config.rtp.extensions.size());
- for (size_t i = 0; i < parsed_config.rtp.extensions.size(); i++) {
- EXPECT_EQ(config.rtp.extensions[i].uri,
- parsed_config.rtp.extensions[i].uri);
- EXPECT_EQ(config.rtp.extensions[i].id, parsed_config.rtp.extensions[i].id);
- }
- // Check RTX settings.
- EXPECT_EQ(config.rtp.rtx.ssrcs.size(), parsed_config.rtp.rtx.ssrcs.size());
- for (size_t i = 0; i < config.rtp.rtx.ssrcs.size(); i++) {
- EXPECT_EQ(config.rtp.rtx.ssrcs[i], parsed_config.rtp.rtx.ssrcs[i]);
- }
- EXPECT_EQ(config.rtp.rtx.payload_type, parsed_config.rtp.rtx.payload_type);
- // Check encoder.
- EXPECT_EQ(config.encoder_settings.payload_name,
- parsed_config.encoder_settings.payload_name);
- EXPECT_EQ(config.encoder_settings.payload_type,
- parsed_config.encoder_settings.payload_type);
-}
-
-void RtcEventLogTestHelper::VerifyRtpEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t header_size,
- size_t total_size) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type());
- const rtclog::RtpPacket& rtp_packet = event.rtp_packet();
- ASSERT_TRUE(rtp_packet.has_incoming());
- EXPECT_EQ(direction == kIncomingPacket, rtp_packet.incoming());
- ASSERT_TRUE(rtp_packet.has_type());
- EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type()));
- ASSERT_TRUE(rtp_packet.has_packet_length());
- EXPECT_EQ(total_size, rtp_packet.packet_length());
- ASSERT_TRUE(rtp_packet.has_header());
- ASSERT_EQ(header_size, rtp_packet.header().size());
- for (size_t i = 0; i < header_size; i++) {
- EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i]));
- }
-
- // Check consistency of the parser.
- PacketDirection parsed_direction;
- MediaType parsed_media_type;
- uint8_t parsed_header[1500];
- size_t parsed_header_size, parsed_total_size;
- parsed_log.GetRtpHeader(index, &parsed_direction, &parsed_media_type,
- parsed_header, &parsed_header_size,
- &parsed_total_size);
- EXPECT_EQ(direction, parsed_direction);
- EXPECT_EQ(media_type, parsed_media_type);
- ASSERT_EQ(header_size, parsed_header_size);
- EXPECT_EQ(0, std::memcmp(header, parsed_header, header_size));
- EXPECT_EQ(total_size, parsed_total_size);
-}
-
-void RtcEventLogTestHelper::VerifyRtcpEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t total_size) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type());
- const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet();
- ASSERT_TRUE(rtcp_packet.has_incoming());
- EXPECT_EQ(direction == kIncomingPacket, rtcp_packet.incoming());
- ASSERT_TRUE(rtcp_packet.has_type());
- EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type()));
- ASSERT_TRUE(rtcp_packet.has_packet_data());
- ASSERT_EQ(total_size, rtcp_packet.packet_data().size());
- for (size_t i = 0; i < total_size; i++) {
- EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i]));
- }
-
- // Check consistency of the parser.
- PacketDirection parsed_direction;
- MediaType parsed_media_type;
- uint8_t parsed_packet[1500];
- size_t parsed_total_size;
- parsed_log.GetRtcpPacket(index, &parsed_direction, &parsed_media_type,
- parsed_packet, &parsed_total_size);
- EXPECT_EQ(direction, parsed_direction);
- EXPECT_EQ(media_type, parsed_media_type);
- ASSERT_EQ(total_size, parsed_total_size);
- EXPECT_EQ(0, std::memcmp(packet, parsed_packet, total_size));
-}
-
-void RtcEventLogTestHelper::VerifyPlayoutEvent(
- const ParsedRtcEventLog& parsed_log,
- size_t index,
- uint32_t ssrc) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::AUDIO_PLAYOUT_EVENT, event.type());
- const rtclog::AudioPlayoutEvent& playout_event = event.audio_playout_event();
- ASSERT_TRUE(playout_event.has_local_ssrc());
- EXPECT_EQ(ssrc, playout_event.local_ssrc());
-
- // Check consistency of the parser.
- uint32_t parsed_ssrc;
- parsed_log.GetAudioPlayout(index, &parsed_ssrc);
- EXPECT_EQ(ssrc, parsed_ssrc);
-}
-
-void RtcEventLogTestHelper::VerifyBweLossEvent(
- const ParsedRtcEventLog& parsed_log,
- size_t index,
- int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- ASSERT_EQ(rtclog::Event::BWE_PACKET_LOSS_EVENT, event.type());
- const rtclog::BwePacketLossEvent& bwe_event = event.bwe_packet_loss_event();
- ASSERT_TRUE(bwe_event.has_bitrate());
- EXPECT_EQ(bitrate, bwe_event.bitrate());
- ASSERT_TRUE(bwe_event.has_fraction_loss());
- EXPECT_EQ(fraction_loss, bwe_event.fraction_loss());
- ASSERT_TRUE(bwe_event.has_total_packets());
- EXPECT_EQ(total_packets, bwe_event.total_packets());
-
- // Check consistency of the parser.
- int32_t parsed_bitrate;
- uint8_t parsed_fraction_loss;
- int32_t parsed_total_packets;
- parsed_log.GetBwePacketLossEvent(
- index, &parsed_bitrate, &parsed_fraction_loss, &parsed_total_packets);
- EXPECT_EQ(bitrate, parsed_bitrate);
- EXPECT_EQ(fraction_loss, parsed_fraction_loss);
- EXPECT_EQ(total_packets, parsed_total_packets);
-}
-
-void RtcEventLogTestHelper::VerifyLogStartEvent(
- const ParsedRtcEventLog& parsed_log,
- size_t index) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- EXPECT_EQ(rtclog::Event::LOG_START, event.type());
-}
-
-void RtcEventLogTestHelper::VerifyLogEndEvent(
- const ParsedRtcEventLog& parsed_log,
- size_t index) {
- const rtclog::Event& event = parsed_log.events_[index];
- ASSERT_TRUE(IsValidBasicEvent(event));
- EXPECT_EQ(rtclog::Event::LOG_END, event.type());
-}
-
-} // namespace webrtc
diff --git a/call/rtc_event_log_unittest_helper.h b/call/rtc_event_log_unittest_helper.h
deleted file mode 100644
index b662c3c..0000000
--- a/call/rtc_event_log_unittest_helper.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2016 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.
- */
-
-#ifndef WEBRTC_CALL_RTC_EVENT_LOG_UNITTEST_HELPER_H_
-#define WEBRTC_CALL_RTC_EVENT_LOG_UNITTEST_HELPER_H_
-
-#include "webrtc/call.h"
-#include "webrtc/call/rtc_event_log_parser.h"
-
-namespace webrtc {
-
-class RtcEventLogTestHelper {
- public:
- static void VerifyReceiveStreamConfig(
- const ParsedRtcEventLog& parsed_log,
- size_t index,
- const VideoReceiveStream::Config& config);
- static void VerifySendStreamConfig(const ParsedRtcEventLog& parsed_log,
- size_t index,
- const VideoSendStream::Config& config);
- static void VerifyRtpEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- PacketDirection direction,
- MediaType media_type,
- const uint8_t* header,
- size_t header_size,
- size_t total_size);
- static void VerifyRtcpEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- PacketDirection direction,
- MediaType media_type,
- const uint8_t* packet,
- size_t total_size);
- static void VerifyPlayoutEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- uint32_t ssrc);
- static void VerifyBweLossEvent(const ParsedRtcEventLog& parsed_log,
- size_t index,
- int32_t bitrate,
- uint8_t fraction_loss,
- int32_t total_packets);
-
- static void VerifyLogStartEvent(const ParsedRtcEventLog& parsed_log,
- size_t index);
- static void VerifyLogEndEvent(const ParsedRtcEventLog& parsed_log,
- size_t index);
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_CALL_RTC_EVENT_LOG_UNITTEST_HELPER_H_
diff --git a/call/webrtc_call.gypi b/call/webrtc_call.gypi
index 455a11a..59dcef6 100644
--- a/call/webrtc_call.gypi
+++ b/call/webrtc_call.gypi
@@ -12,7 +12,7 @@
'<(webrtc_root)/modules/modules.gyp:congestion_controller',
'<(webrtc_root)/modules/modules.gyp:rtp_rtcp',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
- '<(webrtc_root)/webrtc.gyp:rtc_event_log',
+ '<(webrtc_root)/webrtc.gyp:rtc_event_log_impl',
],
'webrtc_call_sources': [
'call/bitrate_allocator.cc',