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 class DebugDumpWriterImpl final : public DebugDumpWriter { |
| 45 public: |
| 46 explicit DebugDumpWriterImpl(FILE* file_handle); |
| 47 ~DebugDumpWriterImpl() override = default; |
| 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 |
| 60 DebugDumpWriterImpl::DebugDumpWriterImpl(FILE* file_handle) |
| 61 : dump_file_(FileWrapper::Create()) { |
| 62 #ifndef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 63 RTC_DCHECK(false); |
| 64 #endif |
| 65 dump_file_->OpenFromFileHandle(file_handle); |
| 66 RTC_CHECK(dump_file_->is_open()); |
| 67 } |
| 68 |
| 69 void DebugDumpWriterImpl::DumpNetworkMetrics( |
| 70 const Controller::NetworkMetrics& metrics, |
| 71 int64_t timestamp) { |
| 72 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 73 Event event; |
| 74 event.set_timestamp(timestamp); |
| 75 event.set_type(Event::NETWORK_METRICS); |
| 76 auto dump_metrics = event.mutable_network_metrics(); |
| 77 |
| 78 if (metrics.uplink_bandwidth_bps) |
| 79 dump_metrics->set_uplink_bandwidth_bps(*metrics.uplink_bandwidth_bps); |
| 80 |
| 81 if (metrics.uplink_packet_loss_fraction) { |
| 82 dump_metrics->set_uplink_packet_loss_fraction( |
| 83 *metrics.uplink_packet_loss_fraction); |
| 84 } |
| 85 |
| 86 if (metrics.target_audio_bitrate_bps) { |
| 87 dump_metrics->set_target_audio_bitrate_bps( |
| 88 *metrics.target_audio_bitrate_bps); |
| 89 } |
| 90 |
| 91 if (metrics.rtt_ms) |
| 92 dump_metrics->set_rtt_ms(*metrics.rtt_ms); |
| 93 |
| 94 DumpEventToFile(event, dump_file_.get()); |
| 95 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 96 } |
| 97 |
| 98 void DebugDumpWriterImpl::DumpEncoderRuntimeConfig( |
| 99 const AudioNetworkAdaptor::EncoderRuntimeConfig& config, |
| 100 int64_t timestamp) { |
| 101 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 102 Event event; |
| 103 event.set_timestamp(timestamp); |
| 104 event.set_type(Event::ENCODER_RUNTIME_CONFIG); |
| 105 auto dump_config = event.mutable_encoder_runtime_config(); |
| 106 |
| 107 if (config.bitrate_bps) |
| 108 dump_config->set_bitrate_bps(*config.bitrate_bps); |
| 109 |
| 110 if (config.frame_length_ms) |
| 111 dump_config->set_frame_length_ms(*config.frame_length_ms); |
| 112 |
| 113 if (config.uplink_packet_loss_fraction) { |
| 114 dump_config->set_uplink_packet_loss_fraction( |
| 115 *config.uplink_packet_loss_fraction); |
| 116 } |
| 117 |
| 118 if (config.enable_fec) |
| 119 dump_config->set_enable_fec(*config.enable_fec); |
| 120 |
| 121 if (config.enable_dtx) |
| 122 dump_config->set_enable_dtx(*config.enable_dtx); |
| 123 |
| 124 if (config.num_channels) |
| 125 dump_config->set_num_channels(*config.num_channels); |
| 126 |
| 127 DumpEventToFile(event, dump_file_.get()); |
| 128 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 129 } |
| 130 |
| 131 std::unique_ptr<DebugDumpWriter> DebugDumpWriter::Create(FILE* file_handle) { |
| 132 return std::unique_ptr<DebugDumpWriter>(new DebugDumpWriterImpl(file_handle)); |
| 133 } |
| 134 |
| 135 } // namespace webrtc |
OLD | NEW |