OLD | NEW |
---|---|
(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 DebugDumpWriterImpl::DebugDumpWriterImpl(std::string ana_dump_file_name) | |
45 : dump_file_(FileWrapper::Create()) { | |
46 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.
| |
47 RTC_CHECK(dump_file_->is_open()); | |
48 } | |
49 | |
50 DebugDumpWriterImpl::DebugDumpWriterImpl(FILE* file_handle) | |
51 : dump_file_(FileWrapper::Create()) { | |
52 dump_file_->OpenFromFileHandle(file_handle); | |
53 RTC_CHECK(dump_file_->is_open()); | |
54 } | |
55 | |
56 DebugDumpWriterImpl::~DebugDumpWriterImpl() = default; | |
57 | |
58 void DebugDumpWriterImpl::DumpNetworkMetrics( | |
59 const Controller::NetworkMetrics& metrics, | |
60 int64_t timestamp) { | |
61 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | |
62 Event event; | |
63 event.set_timestamp(timestamp); | |
64 event.set_type(Event::NETWORK_METRICS); | |
65 auto dump_metrics = event.mutable_network_metrics(); | |
66 | |
67 if (metrics.uplink_bandwidth_bps) | |
68 dump_metrics->set_uplink_bandwidth_bps(*metrics.uplink_bandwidth_bps); | |
69 | |
70 if (metrics.uplink_packet_loss_fraction) { | |
71 dump_metrics->set_uplink_packet_loss_fraction( | |
72 *metrics.uplink_packet_loss_fraction); | |
73 } | |
74 | |
75 if (metrics.target_audio_bitrate_bps) { | |
76 dump_metrics->set_target_audio_bitrate_bps( | |
77 *metrics.target_audio_bitrate_bps); | |
78 } | |
79 | |
80 if (metrics.rtt_ms) | |
81 dump_metrics->set_rtt_ms(*metrics.rtt_ms); | |
82 | |
83 DumpEventToFile(event, dump_file_.get()); | |
84 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | |
85 } | |
86 | |
87 void DebugDumpWriterImpl::DumpEncoderRuntimeConfig( | |
88 const AudioNetworkAdaptor::EncoderRuntimeConfig& config, | |
89 int64_t timestamp) { | |
90 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | |
91 Event event; | |
92 event.set_timestamp(timestamp); | |
93 event.set_type(Event::ENCODER_RUNTIME_CONFIG); | |
94 auto dump_config = event.mutable_encoder_runtime_config(); | |
95 | |
96 if (config.bitrate_bps) | |
97 dump_config->set_bitrate_bps(*config.bitrate_bps); | |
98 | |
99 if (config.frame_length_ms) | |
100 dump_config->set_frame_length_ms(*config.frame_length_ms); | |
101 | |
102 if (config.uplink_packet_loss_fraction) { | |
103 dump_config->set_uplink_packet_loss_fraction( | |
104 *config.uplink_packet_loss_fraction); | |
105 } | |
106 | |
107 if (config.enable_fec) | |
108 dump_config->set_enable_fec(*config.enable_fec); | |
109 | |
110 if (config.enable_dtx) | |
111 dump_config->set_enable_dtx(*config.enable_dtx); | |
112 | |
113 if (config.num_channels) | |
114 dump_config->set_num_channels(*config.num_channels); | |
115 | |
116 DumpEventToFile(event, dump_file_.get()); | |
117 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | |
118 } | |
119 | |
120 } // namespace webrtc | |
OLD | NEW |