Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Unified Diff: webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc

Issue 2356763002: Adding debug dump to audio network adaptor. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc b/webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8df2b85e21f70a5cb21332a8b7c4fffdfccbae4
--- /dev/null
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc
@@ -0,0 +1,120 @@
+/*
+ * 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/modules/audio_coding/audio_network_adaptor/debug_dump_writer.h"
+
+#include "webrtc/base/checks.h"
+
+#ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
+#include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/debug_dump.pb.h"
+#else
+#include "webrtc/modules/audio_coding/audio_network_adaptor/debug_dump.pb.h"
+#endif
+#endif
+
+namespace webrtc {
+
+#ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+namespace {
+
+using audio_network_adaptor::debug_dump::Event;
+using audio_network_adaptor::debug_dump::NetworkMetrics;
+using audio_network_adaptor::debug_dump::EncoderRuntimeConfig;
+
+void DumpEventToFile(const Event& event, FileWrapper* dump_file) {
+ RTC_CHECK(dump_file->is_open());
+ std::string dump_data;
+ event.SerializeToString(&dump_data);
+ int32_t size = event.ByteSize();
+ dump_file->Write(&size, sizeof(size));
+ dump_file->Write(dump_data.data(), dump_data.length());
+}
+
+} // namespace
+#endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+
+DebugDumpWriterImpl::DebugDumpWriterImpl(std::string ana_dump_file_name)
+ : dump_file_(FileWrapper::Create()) {
+ dump_file_->OpenFile(ana_dump_file_name.c_str(), false);
minyue-webrtc 2016/09/21 09:16:30 Per offline discussion, Michael suggested adding
kwiberg-webrtc 2016/09/21 10:54:09 Not sure I understand how that code would give the
minyue-webrtc 2016/09/22 15:11:49 Done.
+ RTC_CHECK(dump_file_->is_open());
+}
+
+DebugDumpWriterImpl::DebugDumpWriterImpl(FILE* file_handle)
+ : dump_file_(FileWrapper::Create()) {
+ dump_file_->OpenFromFileHandle(file_handle);
+ RTC_CHECK(dump_file_->is_open());
+}
+
+DebugDumpWriterImpl::~DebugDumpWriterImpl() = default;
+
+void DebugDumpWriterImpl::DumpNetworkMetrics(
+ const Controller::NetworkMetrics& metrics,
+ int64_t timestamp) {
+#ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+ Event event;
+ event.set_timestamp(timestamp);
+ event.set_type(Event::NETWORK_METRICS);
+ auto dump_metrics = event.mutable_network_metrics();
+
+ if (metrics.uplink_bandwidth_bps)
+ dump_metrics->set_uplink_bandwidth_bps(*metrics.uplink_bandwidth_bps);
+
+ if (metrics.uplink_packet_loss_fraction) {
+ dump_metrics->set_uplink_packet_loss_fraction(
+ *metrics.uplink_packet_loss_fraction);
+ }
+
+ if (metrics.target_audio_bitrate_bps) {
+ dump_metrics->set_target_audio_bitrate_bps(
+ *metrics.target_audio_bitrate_bps);
+ }
+
+ if (metrics.rtt_ms)
+ dump_metrics->set_rtt_ms(*metrics.rtt_ms);
+
+ DumpEventToFile(event, dump_file_.get());
+#endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+}
+
+void DebugDumpWriterImpl::DumpEncoderRuntimeConfig(
+ const AudioNetworkAdaptor::EncoderRuntimeConfig& config,
+ int64_t timestamp) {
+#ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+ Event event;
+ event.set_timestamp(timestamp);
+ event.set_type(Event::ENCODER_RUNTIME_CONFIG);
+ auto dump_config = event.mutable_encoder_runtime_config();
+
+ if (config.bitrate_bps)
+ dump_config->set_bitrate_bps(*config.bitrate_bps);
+
+ if (config.frame_length_ms)
+ dump_config->set_frame_length_ms(*config.frame_length_ms);
+
+ if (config.uplink_packet_loss_fraction) {
+ dump_config->set_uplink_packet_loss_fraction(
+ *config.uplink_packet_loss_fraction);
+ }
+
+ if (config.enable_fec)
+ dump_config->set_enable_fec(*config.enable_fec);
+
+ if (config.enable_dtx)
+ dump_config->set_enable_dtx(*config.enable_dtx);
+
+ if (config.num_channels)
+ dump_config->set_num_channels(*config.num_channels);
+
+ DumpEventToFile(event, dump_file_.get());
+#endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698