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

Side by Side Diff: webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.cc

Issue 2356763002: Adding debug dump to audio network adaptor. (Closed)
Patch Set: some fixes Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_coding/audio_network_adaptor/debug_dump_writer.h"
12
13 #include "webrtc/base/checks.h"
14
15 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
16 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
17 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/debu g_dump.pb.h"
18 #else
19 #include "webrtc/modules/audio_coding/audio_network_adaptor/debug_dump.pb.h"
20 #endif
21 #endif
22
23 namespace webrtc {
24
25 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
26 namespace {
27
28 using audio_network_adaptor::debug_dump::Event;
29 using audio_network_adaptor::debug_dump::NetworkMetrics;
30 using audio_network_adaptor::debug_dump::EncoderRuntimeConfig;
31
32 void DumpEventToFile(const Event& event, FileWrapper* dump_file) {
33 RTC_CHECK(dump_file->is_open());
34 std::string dump_data;
35 event.SerializeToString(&dump_data);
36 int32_t size = event.ByteSize();
37 dump_file->Write(&size, sizeof(size));
38 dump_file->Write(dump_data.data(), dump_data.length());
39 }
40
41 } // namespace
42 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
43
44 class DebugDumpWriterImpl final : public DebugDumpWriter {
45 public:
46 explicit DebugDumpWriterImpl(FILE* file_handle);
47 ~DebugDumpWriterImpl() override;
48
49 void DumpEncoderRuntimeConfig(
50 const AudioNetworkAdaptor::EncoderRuntimeConfig& config,
51 int64_t timestamp) override;
52
53 void DumpNetworkMetrics(const Controller::NetworkMetrics& metrics,
54 int64_t timestamp) override;
55
56 private:
57 std::unique_ptr<FileWrapper> dump_file_;
58
59 RTC_DISALLOW_COPY_AND_ASSIGN(DebugDumpWriterImpl);
kwiberg-webrtc 2016/09/22 15:54:16 You can skip this line. Everyone will be handling
minyue-webrtc 2016/09/22 20:40:31 Done.
60 };
61
62 DebugDumpWriterImpl::DebugDumpWriterImpl(FILE* file_handle)
63 : dump_file_(FileWrapper::Create()) {
64 #ifndef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
65 RTC_DCHECK(false);
66 #endif
67 dump_file_->OpenFromFileHandle(file_handle);
68 RTC_CHECK(dump_file_->is_open());
69 }
70
71 DebugDumpWriterImpl::~DebugDumpWriterImpl() = default;
kwiberg-webrtc 2016/09/22 15:54:15 Now that this entire class is in the .cc file, the
minyue-webrtc 2016/09/22 20:40:31 Done.
72
73 void DebugDumpWriterImpl::DumpNetworkMetrics(
74 const Controller::NetworkMetrics& metrics,
75 int64_t timestamp) {
76 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
77 Event event;
78 event.set_timestamp(timestamp);
79 event.set_type(Event::NETWORK_METRICS);
80 auto dump_metrics = event.mutable_network_metrics();
81
82 if (metrics.uplink_bandwidth_bps)
83 dump_metrics->set_uplink_bandwidth_bps(*metrics.uplink_bandwidth_bps);
84
85 if (metrics.uplink_packet_loss_fraction) {
86 dump_metrics->set_uplink_packet_loss_fraction(
87 *metrics.uplink_packet_loss_fraction);
88 }
89
90 if (metrics.target_audio_bitrate_bps) {
91 dump_metrics->set_target_audio_bitrate_bps(
92 *metrics.target_audio_bitrate_bps);
93 }
94
95 if (metrics.rtt_ms)
96 dump_metrics->set_rtt_ms(*metrics.rtt_ms);
97
98 DumpEventToFile(event, dump_file_.get());
99 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
100 }
101
102 void DebugDumpWriterImpl::DumpEncoderRuntimeConfig(
103 const AudioNetworkAdaptor::EncoderRuntimeConfig& config,
104 int64_t timestamp) {
105 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
106 Event event;
107 event.set_timestamp(timestamp);
108 event.set_type(Event::ENCODER_RUNTIME_CONFIG);
109 auto dump_config = event.mutable_encoder_runtime_config();
110
111 if (config.bitrate_bps)
112 dump_config->set_bitrate_bps(*config.bitrate_bps);
113
114 if (config.frame_length_ms)
115 dump_config->set_frame_length_ms(*config.frame_length_ms);
116
117 if (config.uplink_packet_loss_fraction) {
118 dump_config->set_uplink_packet_loss_fraction(
119 *config.uplink_packet_loss_fraction);
120 }
121
122 if (config.enable_fec)
123 dump_config->set_enable_fec(*config.enable_fec);
124
125 if (config.enable_dtx)
126 dump_config->set_enable_dtx(*config.enable_dtx);
127
128 if (config.num_channels)
129 dump_config->set_num_channels(*config.num_channels);
130
131 DumpEventToFile(event, dump_file_.get());
132 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
133 }
134
135 std::unique_ptr<DebugDumpWriter> DebugDumpWriter::Create(FILE* file_handle) {
136 std::unique_ptr<DebugDumpWriter> writer(new DebugDumpWriterImpl(file_handle));
137 return writer;
kwiberg-webrtc 2016/09/22 15:54:15 return std::unique_ptr<DebugDumpWriter>(new DebugD
minyue-webrtc 2016/09/22 20:40:31 Done.
138 }
139
140 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698