LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/audio_coding/audio_network_adaptor - debug_dump_writer.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 13 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "webrtc/base/ignore_wundef.h"
      15             : 
      16             : #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      17             : RTC_PUSH_IGNORING_WUNDEF()
      18             : #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
      19             : #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/debug_dump.pb.h"
      20             : #else
      21             : #include "webrtc/modules/audio_coding/audio_network_adaptor/debug_dump.pb.h"
      22             : #endif
      23             : RTC_POP_IGNORING_WUNDEF()
      24             : #endif
      25             : 
      26             : namespace webrtc {
      27             : 
      28             : #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      29             : namespace {
      30             : 
      31             : using audio_network_adaptor::debug_dump::Event;
      32             : using audio_network_adaptor::debug_dump::NetworkMetrics;
      33             : using audio_network_adaptor::debug_dump::EncoderRuntimeConfig;
      34             : 
      35             : void DumpEventToFile(const Event& event, FileWrapper* dump_file) {
      36             :   RTC_CHECK(dump_file->is_open());
      37             :   std::string dump_data;
      38             :   event.SerializeToString(&dump_data);
      39             :   int32_t size = event.ByteSize();
      40             :   dump_file->Write(&size, sizeof(size));
      41             :   dump_file->Write(dump_data.data(), dump_data.length());
      42             : }
      43             : 
      44             : }  // namespace
      45             : #endif  // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      46             : 
      47             : class DebugDumpWriterImpl final : public DebugDumpWriter {
      48             :  public:
      49             :   explicit DebugDumpWriterImpl(FILE* file_handle);
      50           0 :   ~DebugDumpWriterImpl() override = default;
      51             : 
      52             :   void DumpEncoderRuntimeConfig(
      53             :       const AudioNetworkAdaptor::EncoderRuntimeConfig& config,
      54             :       int64_t timestamp) override;
      55             : 
      56             :   void DumpNetworkMetrics(const Controller::NetworkMetrics& metrics,
      57             :                           int64_t timestamp) override;
      58             : 
      59             :  private:
      60             :   std::unique_ptr<FileWrapper> dump_file_;
      61             : };
      62             : 
      63           0 : DebugDumpWriterImpl::DebugDumpWriterImpl(FILE* file_handle)
      64           0 :     : dump_file_(FileWrapper::Create()) {
      65             : #ifndef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      66           0 :   RTC_NOTREACHED();
      67             : #endif
      68           0 :   dump_file_->OpenFromFileHandle(file_handle);
      69           0 :   RTC_CHECK(dump_file_->is_open());
      70           0 : }
      71             : 
      72           0 : void DebugDumpWriterImpl::DumpNetworkMetrics(
      73             :     const Controller::NetworkMetrics& metrics,
      74             :     int64_t timestamp) {
      75             : #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      76             :   Event event;
      77             :   event.set_timestamp(timestamp);
      78             :   event.set_type(Event::NETWORK_METRICS);
      79             :   auto dump_metrics = event.mutable_network_metrics();
      80             : 
      81             :   if (metrics.uplink_bandwidth_bps)
      82             :     dump_metrics->set_uplink_bandwidth_bps(*metrics.uplink_bandwidth_bps);
      83             : 
      84             :   if (metrics.uplink_packet_loss_fraction) {
      85             :     dump_metrics->set_uplink_packet_loss_fraction(
      86             :         *metrics.uplink_packet_loss_fraction);
      87             :   }
      88             : 
      89             :   if (metrics.target_audio_bitrate_bps) {
      90             :     dump_metrics->set_target_audio_bitrate_bps(
      91             :         *metrics.target_audio_bitrate_bps);
      92             :   }
      93             : 
      94             :   if (metrics.rtt_ms)
      95             :     dump_metrics->set_rtt_ms(*metrics.rtt_ms);
      96             : 
      97             :   DumpEventToFile(event, dump_file_.get());
      98             : #endif  // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
      99           0 : }
     100             : 
     101           0 : void DebugDumpWriterImpl::DumpEncoderRuntimeConfig(
     102             :     const AudioNetworkAdaptor::EncoderRuntimeConfig& config,
     103             :     int64_t timestamp) {
     104             : #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
     105             :   Event event;
     106             :   event.set_timestamp(timestamp);
     107             :   event.set_type(Event::ENCODER_RUNTIME_CONFIG);
     108             :   auto dump_config = event.mutable_encoder_runtime_config();
     109             : 
     110             :   if (config.bitrate_bps)
     111             :     dump_config->set_bitrate_bps(*config.bitrate_bps);
     112             : 
     113             :   if (config.frame_length_ms)
     114             :     dump_config->set_frame_length_ms(*config.frame_length_ms);
     115             : 
     116             :   if (config.uplink_packet_loss_fraction) {
     117             :     dump_config->set_uplink_packet_loss_fraction(
     118             :         *config.uplink_packet_loss_fraction);
     119             :   }
     120             : 
     121             :   if (config.enable_fec)
     122             :     dump_config->set_enable_fec(*config.enable_fec);
     123             : 
     124             :   if (config.enable_dtx)
     125             :     dump_config->set_enable_dtx(*config.enable_dtx);
     126             : 
     127             :   if (config.num_channels)
     128             :     dump_config->set_num_channels(*config.num_channels);
     129             : 
     130             :   DumpEventToFile(event, dump_file_.get());
     131             : #endif  // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
     132           0 : }
     133             : 
     134           0 : std::unique_ptr<DebugDumpWriter> DebugDumpWriter::Create(FILE* file_handle) {
     135           0 :   return std::unique_ptr<DebugDumpWriter>(new DebugDumpWriterImpl(file_handle));
     136             : }
     137             : 
     138             : }  // namespace webrtc

Generated by: LCOV version 1.13