OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/audio/audio_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "webrtc/audio/conversion.h" | |
15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/voice_engine/include/voe_audio_processing.h" | |
19 #include "webrtc/voice_engine/include/voe_codec.h" | |
20 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | |
21 #include "webrtc/voice_engine/include/voe_volume_control.h" | |
17 | 22 |
18 namespace webrtc { | 23 namespace webrtc { |
19 std::string AudioSendStream::Config::Rtp::ToString() const { | 24 std::string AudioSendStream::Config::Rtp::ToString() const { |
20 std::stringstream ss; | 25 std::stringstream ss; |
21 ss << "{ssrc: " << ssrc; | 26 ss << "{ssrc: " << ssrc; |
22 ss << ", extensions: ["; | 27 ss << ", extensions: ["; |
23 for (size_t i = 0; i < extensions.size(); ++i) { | 28 for (size_t i = 0; i < extensions.size(); ++i) { |
24 ss << extensions[i].ToString(); | 29 ss << extensions[i].ToString(); |
25 if (i != extensions.size() - 1) | 30 if (i != extensions.size() - 1) { |
26 ss << ", "; | 31 ss << ", "; |
32 } | |
27 } | 33 } |
28 ss << ']'; | 34 ss << ']'; |
29 ss << '}'; | 35 ss << '}'; |
30 return ss.str(); | 36 return ss.str(); |
31 } | 37 } |
32 | 38 |
33 std::string AudioSendStream::Config::ToString() const { | 39 std::string AudioSendStream::Config::ToString() const { |
34 std::stringstream ss; | 40 std::stringstream ss; |
35 ss << "{rtp: " << rtp.ToString(); | 41 ss << "{rtp: " << rtp.ToString(); |
36 ss << ", voe_channel_id: " << voe_channel_id; | 42 ss << ", voe_channel_id: " << voe_channel_id; |
37 // TODO(solenberg): Encoder config. | 43 // TODO(solenberg): Encoder config. |
38 ss << ", cng_payload_type: " << cng_payload_type; | 44 ss << ", cng_payload_type: " << cng_payload_type; |
39 ss << ", red_payload_type: " << red_payload_type; | 45 ss << ", red_payload_type: " << red_payload_type; |
40 ss << '}'; | 46 ss << '}'; |
41 return ss.str(); | 47 return ss.str(); |
42 } | 48 } |
43 | 49 |
44 namespace internal { | 50 namespace internal { |
45 AudioSendStream::AudioSendStream(const webrtc::AudioSendStream::Config& config) | 51 AudioSendStream::AudioSendStream(const webrtc::AudioSendStream::Config& config, |
46 : config_(config) { | 52 VoiceEngine* voice_engine) |
53 : config_(config), | |
54 voice_engine_(voice_engine), | |
55 voe_base_(voice_engine) { | |
47 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 56 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
48 RTC_DCHECK(config.voe_channel_id != -1); | 57 RTC_DCHECK(config.voe_channel_id != -1); |
58 RTC_DCHECK(voice_engine_ != nullptr); | |
kwiberg-webrtc
2015/10/26 13:19:53
Just RTC_DCHECK(voice_engine_);? Otherwise, RTC_DC
the sun
2015/10/26 14:44:02
Done.
| |
49 } | 59 } |
50 | 60 |
51 AudioSendStream::~AudioSendStream() { | 61 AudioSendStream::~AudioSendStream() { |
62 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
52 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 63 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
53 } | 64 } |
54 | 65 |
55 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { | 66 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { |
56 return webrtc::AudioSendStream::Stats(); | 67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
68 webrtc::AudioSendStream::Stats stats; | |
69 stats.local_ssrc = config_.rtp.ssrc; | |
70 ScopedVoEInterface<VoEAudioProcessing> processing(voice_engine_); | |
71 ScopedVoEInterface<VoECodec> codec(voice_engine_); | |
72 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine_); | |
73 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine_); | |
74 unsigned int ssrc = 0; | |
75 webrtc::CallStatistics call_stats = {0}; | |
76 if (rtp->GetLocalSSRC(config_.voe_channel_id, ssrc) == -1 || | |
77 rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats) == -1) { | |
78 return stats; | |
79 } | |
80 | |
81 stats.bytes_sent = call_stats.bytesSent; | |
82 stats.packets_sent = call_stats.packetsSent; | |
83 | |
84 webrtc::CodecInst codec_inst = {0}; | |
85 if (codec->GetSendCodec(config_.voe_channel_id, codec_inst) != -1) { | |
86 RTC_DCHECK(codec_inst.pltype != -1); | |
kwiberg-webrtc
2015/10/26 13:19:53
RTC_DCHECK_NE
the sun
2015/10/26 14:44:02
Done.
| |
87 stats.codec_name = codec_inst.plname; | |
88 | |
89 // Get data from the last remote RTCP report. | |
90 std::vector<webrtc::ReportBlock> blocks; | |
91 if (rtp->GetRemoteRTCPReportBlocks(config_.voe_channel_id, &blocks) != -1) { | |
92 for (const webrtc::ReportBlock& block : blocks) { | |
93 // Lookup report for send ssrc only. | |
94 if (block.source_SSRC == stats.local_ssrc) { | |
95 stats.packets_lost = block.cumulative_num_packets_lost; | |
96 stats.fraction_lost = Q8ToFloat(block.fraction_lost); | |
97 stats.ext_seqnum = block.extended_highest_sequence_number; | |
98 // Convert samples to milliseconds. | |
99 if (codec_inst.plfreq / 1000 > 0) { | |
100 stats.jitter_ms = | |
101 block.interarrival_jitter / (codec_inst.plfreq / 1000); | |
102 } | |
103 break; | |
104 } | |
105 } | |
106 } | |
107 } | |
108 | |
109 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine | |
110 // returns 0 to indicate an error value. | |
111 if (call_stats.rttMs > 0) { | |
112 stats.rtt_ms = call_stats.rttMs; | |
113 } | |
114 | |
115 // Local speech level. | |
116 { | |
117 unsigned int level = 0; | |
118 if (volume->GetSpeechInputLevelFullRange(level) != -1) { | |
119 stats.audio_level = static_cast<int32_t>(level); | |
120 } | |
121 } | |
122 | |
123 // TODO(ajm): Re-enable this metric once we have a reliable implementation. | |
124 stats.aec_quality_min = -1; | |
125 | |
126 bool echo_metrics_on = false; | |
127 if (processing->GetEcMetricsStatus(echo_metrics_on) != -1 && | |
128 echo_metrics_on) { | |
129 // These can also be negative, but in practice -1 is only used to signal | |
130 // insufficient data, since the resolution is limited to multiples of 4 ms. | |
kwiberg-webrtc
2015/10/26 13:19:53
:-)
the sun
2015/10/26 14:44:02
This is actually copy+paste. There's some likeliho
| |
131 int median = -1; | |
132 int std = -1; | |
133 float dummy = 0.0f; | |
134 if (processing->GetEcDelayMetrics(median, std, dummy) != -1) { | |
135 stats.echo_delay_median_ms = median; | |
136 stats.echo_delay_std_ms = std; | |
137 } | |
138 | |
139 // These can take on valid negative values, so use the lowest possible level | |
140 // as default rather than -1. | |
kwiberg-webrtc
2015/10/26 13:19:53
:-)
the sun
2015/10/26 14:44:02
Acknowledged.
| |
141 int erl = -100; | |
142 int erle = -100; | |
143 int dummy1 = 0; | |
144 int dummy2 = 0; | |
145 if (processing->GetEchoMetrics(erl, erle, dummy1, dummy2) != -1) { | |
146 stats.echo_return_loss = erl; | |
147 stats.echo_return_loss_enhancement = erle; | |
148 } | |
149 } | |
150 | |
151 // TODO(solenberg): Collect typing noise warnings here too! | |
152 // bool typing_noise_detected = typing_noise_detected_; | |
153 | |
154 return stats; | |
155 } | |
156 | |
157 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | |
158 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
159 return config_; | |
57 } | 160 } |
58 | 161 |
59 void AudioSendStream::Start() { | 162 void AudioSendStream::Start() { |
163 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
60 } | 164 } |
61 | 165 |
62 void AudioSendStream::Stop() { | 166 void AudioSendStream::Stop() { |
167 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
63 } | 168 } |
64 | 169 |
65 void AudioSendStream::SignalNetworkState(NetworkState state) { | 170 void AudioSendStream::SignalNetworkState(NetworkState state) { |
171 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
66 } | 172 } |
67 | 173 |
68 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 174 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
175 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
176 // calls on the worker thread. We should move towards always using a network | |
177 // thread. Then this check can be enabled. | |
178 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
69 return false; | 179 return false; |
70 } | 180 } |
71 } // namespace internal | 181 } // namespace internal |
72 } // namespace webrtc | 182 } // namespace webrtc |
OLD | NEW |