<commit_before>/*
 *  Copyright (c) 2012 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 "common_types.h"
#include "rtp_rtcp_impl.h"
#include "trace.h"

#ifdef MATLAB
#include "../test/BWEStandAlone/MatlabPlot.h"
extern MatlabEngine eng; // global variable defined elsewhere
#endif

#include <string.h> //memcpy
#include <cassert> //assert

// local for this file
namespace {

const float FracMS = 4.294967296E6f;

}  // namepace

#ifdef _WIN32
// disable warning C4355: 'this' : used in base member initializer list
#pragma warning(disable : 4355)
#endif

namespace webrtc {

const WebRtc_UWord16 kDefaultRtt = 200;

RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
  if (configuration.clock) {
    return new ModuleRtpRtcpImpl(configuration);
  } else {
    RtpRtcp::Configuration configuration_copy;
    memcpy(&configuration_copy, &configuration_copy,
           sizeof(RtpRtcp::Configuration));
    ModuleRTPUtility::GetSystemClock();
    ModuleRtpRtcpImpl* rtp_rtcp_instance =
        new ModuleRtpRtcpImpl(configuration_copy);
    rtp_rtcp_instance->OwnsClock();
    return rtp_rtcp_instance;
  }
}

ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
    : _rtpSender(configuration.id, configuration.audio, configuration.clock),
      _rtpReceiver(configuration.id, configuration.audio, configuration.clock,
                   this),
      _rtcpSender(configuration.id, configuration.audio, configuration.clock,
                  this),
      _rtcpReceiver(configuration.id, configuration.clock, this),
      _owns_clock(false),
      _clock(*configuration.clock),
      _id(configuration.id),
      _audio(configuration.audio),
      _collisionDetected(false),
      _lastProcessTime(configuration.clock->GetTimeInMS()),
      _lastBitrateProcessTime(configuration.clock->GetTimeInMS()),
      _lastPacketTimeoutProcessTime(configuration.clock->GetTimeInMS()),
      _packetOverHead(28),  // IPV4 UDP
      _criticalSectionModulePtrs(
          CriticalSectionWrapper::CreateCriticalSection()),
      _criticalSectionModulePtrsFeedback(
          CriticalSectionWrapper::CreateCriticalSection()),<commit_msg>Bug fix Review URL: https://webrtc-codereview.appspot.com/576009<commit_after>/*
 *  Copyright (c) 2012 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 "common_types.h"
#include "rtp_rtcp_impl.h"
#include "trace.h"

#ifdef MATLAB
#include "../test/BWEStandAlone/MatlabPlot.h"
extern MatlabEngine eng; // global variable defined elsewhere
#endif

#include <string.h> //memcpy
#include <cassert> //assert

// local for this file
namespace {

const float FracMS = 4.294967296E6f;

}  // namepace

#ifdef _WIN32
// disable warning C4355: 'this' : used in base member initializer list
#pragma warning(disable : 4355)
#endif

namespace webrtc {

const WebRtc_UWord16 kDefaultRtt = 200;

RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
  if (configuration.clock) {
    return new ModuleRtpRtcpImpl(configuration);
  } else {
    RtpRtcp::Configuration configuration_copy;
    memcpy(&configuration_copy, &configuration_copy,
           sizeof(RtpRtcp::Configuration));
    configuration_copy.clock = ModuleRTPUtility::GetSystemClock();
    ModuleRtpRtcpImpl* rtp_rtcp_instance =
        new ModuleRtpRtcpImpl(configuration_copy);
    rtp_rtcp_instance->OwnsClock();
    return rtp_rtcp_instance;
  }
}

ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
    : _rtpSender(configuration.id, configuration.audio, configuration.clock),
      _rtpReceiver(configuration.id, configuration.audio, configuration.clock,
                   this),
      _rtcpSender(configuration.id, configuration.audio, configuration.clock,
                  this),
      _rtcpReceiver(configuration.id, configuration.clock, this),
      _owns_clock(false),
      _clock(*configuration.clock),
      _id(configuration.id),
      _audio(configuration.audio),
      _collisionDetected(false),
      _lastProcessTime(configuration.clock->GetTimeInMS()),
      _lastBitrateProcessTime(configuration.clock->GetTimeInMS()),
      _lastPacketTimeoutProcessTime(configuration.clock->GetTimeInMS()),
      _packetOverHead(28),  // IPV4 UDP
      _criticalSectionModulePtrs(
          CriticalSectionWrapper::CreateCriticalSection()),
      _criticalSectionModulePtrsFeedback(
          CriticalSectionWrapper::CreateCriticalSection()),
{'fraction_non_alphanumeric': 0.09350547730829421, 'fraction_numerical': 0.014084507042253521, 'mean_word_length': 4.175101214574899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264060', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1474, 'n_words': 362}