Create and use RtcEventLogOutput for output

We need to support two modes of writing to the output:
1. Current way - the application lets lets WebRTC know which file to write to, and WebRTC is then in charge of the writing.
2. New way - the application would receive indications from WebRTC about (encoded) RTC events, and would itself be in charge of processing them (be it writing it to a file, uploading it somewhere, etc.).

We achieve this by creating an interface for output - RtcEventLogOutput. By providing an instance of the subclass, RtcEventLogOutputFile, the old behavior is achieved. The subclass of the new behavior is to be added by a later CL.

TBR=stefan@webrtc.org

Bug: webrtc:8111
Change-Id: I9c50521a7f7144d86d8353a65995795862e19c44
Reviewed-on: https://webrtc-review.googlesource.com/2686
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Reviewed-by: Elad Alon <eladalon@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20135}
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 77e8e02..bc95895 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -20,6 +20,7 @@
 #include "api/mediastreamproxy.h"
 #include "api/mediastreamtrackproxy.h"
 #include "call/call.h"
+#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
 #include "logging/rtc_event_log/rtc_event_log.h"
 #include "media/sctp/sctptransport.h"
 #include "pc/audiotrack.h"
@@ -36,6 +37,8 @@
 #include "rtc_base/bind.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
+#include "rtc_base/ptr_util.h"
+#include "rtc_base/safe_conversions.h"
 #include "rtc_base/stringencode.h"
 #include "rtc_base/stringutils.h"
 #include "rtc_base/trace_event.h"
@@ -2533,7 +2536,14 @@
   if (!event_log_) {
     return false;
   }
-  return event_log_->StartLogging(file, max_size_bytes);
+
+  // TODO(eladalon): It would be better to not allow negative values into PC.
+  const size_t max_size = (max_size_bytes < 0)
+                              ? RtcEventLog::kUnlimitedOutput
+                              : rtc::saturated_cast<size_t>(max_size_bytes);
+
+  return event_log_->StartLogging(
+      rtc::MakeUnique<RtcEventLogOutputFile>(file, max_size));
 }
 
 void PeerConnection::StopRtcEventLog_w() {