1/*
2 *  Copyright (c) 2015 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/voice_engine/channel_proxy.h"
12
13#include <utility>
14
15#include "webrtc/audio/audio_sink.h"
16#include "webrtc/base/checks.h"
17#include "webrtc/voice_engine/channel.h"
18
19namespace webrtc {
20namespace voe {
21ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {}
22
23ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
24    channel_owner_(channel_owner) {
25  RTC_CHECK(channel_owner_.channel());
26}
27
28ChannelProxy::~ChannelProxy() {}
29
30void ChannelProxy::SetRTCPStatus(bool enable) {
31  channel()->SetRTCPStatus(enable);
32}
33
34void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
35  RTC_DCHECK(thread_checker_.CalledOnValidThread());
36  int error = channel()->SetLocalSSRC(ssrc);
37  RTC_DCHECK_EQ(0, error);
38}
39
40void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
41  RTC_DCHECK(thread_checker_.CalledOnValidThread());
42  // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
43  std::string c_name_limited = c_name.substr(0, 255);
44  int error = channel()->SetRTCP_CNAME(c_name_limited.c_str());
45  RTC_DCHECK_EQ(0, error);
46}
47
48void ChannelProxy::SetSendAbsoluteSenderTimeStatus(bool enable, int id) {
49  RTC_DCHECK(thread_checker_.CalledOnValidThread());
50  int error = channel()->SetSendAbsoluteSenderTimeStatus(enable, id);
51  RTC_DCHECK_EQ(0, error);
52}
53
54void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
55  RTC_DCHECK(thread_checker_.CalledOnValidThread());
56  int error = channel()->SetSendAudioLevelIndicationStatus(enable, id);
57  RTC_DCHECK_EQ(0, error);
58}
59
60void ChannelProxy::EnableSendTransportSequenceNumber(int id) {
61  RTC_DCHECK(thread_checker_.CalledOnValidThread());
62  channel()->EnableSendTransportSequenceNumber(id);
63}
64
65void ChannelProxy::SetReceiveAbsoluteSenderTimeStatus(bool enable, int id) {
66  RTC_DCHECK(thread_checker_.CalledOnValidThread());
67  int error = channel()->SetReceiveAbsoluteSenderTimeStatus(enable, id);
68  RTC_DCHECK_EQ(0, error);
69}
70
71void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) {
72  RTC_DCHECK(thread_checker_.CalledOnValidThread());
73  int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id);
74  RTC_DCHECK_EQ(0, error);
75}
76
77void ChannelProxy::SetCongestionControlObjects(
78    RtpPacketSender* rtp_packet_sender,
79    TransportFeedbackObserver* transport_feedback_observer,
80    PacketRouter* packet_router) {
81  RTC_DCHECK(thread_checker_.CalledOnValidThread());
82  channel()->SetCongestionControlObjects(
83      rtp_packet_sender, transport_feedback_observer, packet_router);
84}
85
86CallStatistics ChannelProxy::GetRTCPStatistics() const {
87  RTC_DCHECK(thread_checker_.CalledOnValidThread());
88  CallStatistics stats = {0};
89  int error = channel()->GetRTPStatistics(stats);
90  RTC_DCHECK_EQ(0, error);
91  return stats;
92}
93
94std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
95  RTC_DCHECK(thread_checker_.CalledOnValidThread());
96  std::vector<webrtc::ReportBlock> blocks;
97  int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
98  RTC_DCHECK_EQ(0, error);
99  return blocks;
100}
101
102NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
103  RTC_DCHECK(thread_checker_.CalledOnValidThread());
104  NetworkStatistics stats = {0};
105  int error = channel()->GetNetworkStatistics(stats);
106  RTC_DCHECK_EQ(0, error);
107  return stats;
108}
109
110AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
111  RTC_DCHECK(thread_checker_.CalledOnValidThread());
112  AudioDecodingCallStats stats;
113  channel()->GetDecodingCallStatistics(&stats);
114  return stats;
115}
116
117int32_t ChannelProxy::GetSpeechOutputLevelFullRange() const {
118  RTC_DCHECK(thread_checker_.CalledOnValidThread());
119  uint32_t level = 0;
120  int error = channel()->GetSpeechOutputLevelFullRange(level);
121  RTC_DCHECK_EQ(0, error);
122  return static_cast<int32_t>(level);
123}
124
125uint32_t ChannelProxy::GetDelayEstimate() const {
126  RTC_DCHECK(thread_checker_.CalledOnValidThread());
127  return channel()->GetDelayEstimate();
128}
129
130bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type) {
131  RTC_DCHECK(thread_checker_.CalledOnValidThread());
132  return channel()->SetSendTelephoneEventPayloadType(payload_type) == 0;
133}
134
135bool ChannelProxy::SendTelephoneEventOutband(uint8_t event,
136                                             uint32_t duration_ms) {
137  RTC_DCHECK(thread_checker_.CalledOnValidThread());
138  return
139      channel()->SendTelephoneEventOutband(event, duration_ms, 10, false) == 0;
140}
141
142void ChannelProxy::SetSink(rtc::scoped_ptr<AudioSinkInterface> sink) {
143  RTC_DCHECK(thread_checker_.CalledOnValidThread());
144  channel()->SetSink(std::move(sink));
145}
146
147Channel* ChannelProxy::channel() const {
148  RTC_DCHECK(channel_owner_.channel());
149  return channel_owner_.channel();
150}
151
152}  // namespace voe
153}  // namespace webrtc
154