#include <string>
#include <vector>
-#include "talk/base/base64.h"
-#include "talk/base/byteorder.h"
-#include "talk/base/common.h"
-#include "talk/base/helpers.h"
-#include "talk/base/logging.h"
-#include "talk/base/stringencode.h"
-#include "talk/base/stringutils.h"
#include "talk/media/base/audiorenderer.h"
#include "talk/media/base/constants.h"
#include "talk/media/base/streamparams.h"
#include "talk/media/base/voiceprocessor.h"
#include "talk/media/webrtc/webrtcvoe.h"
+#include "webrtc/base/base64.h"
+#include "webrtc/base/byteorder.h"
+#include "webrtc/base/common.h"
+#include "webrtc/base/helpers.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/base/stringencode.h"
+#include "webrtc/base/stringutils.h"
#include "webrtc/common.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
static const int kDefaultAudioDeviceId = 0;
#endif
-// extension header for audio levels, as defined in
-// http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
-static const char kRtpAudioLevelHeaderExtension[] =
- "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
-static const int kRtpAudioLevelHeaderExtensionId = 1;
-
static const char kIsacCodecName[] = "ISAC";
static const char kL16CodecName[] = "L16";
// Codec parameters for Opus.
// Default audio dscp value.
// See http://tools.ietf.org/html/rfc2474 for details.
// See also http://tools.ietf.org/html/draft-jennings-rtcweb-qos-00
-static const talk_base::DiffServCodePoint kAudioDscpValue = talk_base::DSCP_EF;
+static const rtc::DiffServCodePoint kAudioDscpValue = rtc::DSCP_EF;
// Ensure we open the file in a writeable path on ChromeOS and Android. This
// workaround can be removed when it's possible to specify a filename for audio
return ss.str();
}
-static void LogMultiline(talk_base::LoggingSeverity sev, char* text) {
+static void LogMultiline(rtc::LoggingSeverity sev, char* text) {
const char* delim = "\r\n";
for (char* tok = strtok(text, delim); tok; tok = strtok(NULL, delim)) {
LOG_V(sev) << tok;
static int SeverityToFilter(int severity) {
int filter = webrtc::kTraceNone;
switch (severity) {
- case talk_base::LS_VERBOSE:
+ case rtc::LS_VERBOSE:
filter |= webrtc::kTraceAll;
- case talk_base::LS_INFO:
+ case rtc::LS_INFO:
filter |= (webrtc::kTraceStateInfo | webrtc::kTraceInfo);
- case talk_base::LS_WARNING:
+ case rtc::LS_WARNING:
filter |= (webrtc::kTraceTerseInfo | webrtc::kTraceWarning);
- case talk_base::LS_ERROR:
+ case rtc::LS_ERROR:
filter |= (webrtc::kTraceError | webrtc::kTraceCritical);
}
return filter;
return false;
}
+static bool IsTelephoneEventCodec(const std::string& name) {
+ return _stricmp(name.c_str(), "telephone-event") == 0;
+}
+
+static bool IsCNCodec(const std::string& name) {
+ return _stricmp(name.c_str(), "CN") == 0;
+}
+
+static bool IsRedCodec(const std::string& name) {
+ return _stricmp(name.c_str(), "red") == 0;
+}
+
static bool FindCodec(const std::vector<AudioCodec>& codecs,
const AudioCodec& codec,
AudioCodec* found_codec) {
options.adjust_agc_delta.Set(0);
options.experimental_agc.Set(false);
options.experimental_aec.Set(false);
+ options.experimental_ns.Set(false);
options.aec_dump.Set(false);
- options.experimental_acm.Set(false);
+ options.opus_fec.Set(false);
return options;
}
private:
WebRtcVoiceEngine *engine_;
int webrtc_channel_;
- talk_base::scoped_ptr<WebRtcSoundclipStream> stream_;
+ rtc::scoped_ptr<WebRtcSoundclipStream> stream_;
};
WebRtcVoiceEngine::WebRtcVoiceEngine()
log_filter_(SeverityToFilter(kDefaultLogSeverity)),
is_dumping_aec_(false),
desired_local_monitor_enable_(false),
- use_experimental_acm_(false),
tx_processor_ssrc_(0),
rx_processor_ssrc_(0) {
Construct();
log_filter_(SeverityToFilter(kDefaultLogSeverity)),
is_dumping_aec_(false),
desired_local_monitor_enable_(false),
- use_experimental_acm_(false),
tx_processor_ssrc_(0),
rx_processor_ssrc_(0) {
Construct();
// Load our RTP Header extensions.
rtp_header_extensions_.push_back(
RtpHeaderExtension(kRtpAudioLevelHeaderExtension,
- kRtpAudioLevelHeaderExtensionId));
+ kRtpAudioLevelHeaderExtensionDefaultId));
+ rtp_header_extensions_.push_back(
+ RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension,
+ kRtpAbsoluteSenderTimeHeaderExtensionDefaultId));
options_ = GetDefaultEngineOptions();
-
- // Initialize the VoE Configuration to the default ACM.
- voe_config_.Set<webrtc::AudioCodingModuleFactory>(
- new webrtc::AudioCodingModuleFactory);
}
static bool IsOpus(const AudioCodec& codec) {
// True if params["stereo"] == "1"
static bool IsOpusStereoEnabled(const AudioCodec& codec) {
- CodecParameterMap::const_iterator param =
- codec.params.find(kCodecParamStereo);
- if (param == codec.params.end()) {
- return false;
- }
- return param->second == kParamValueTrue;
+ int value;
+ return codec.GetParam(kCodecParamStereo, &value) && value == 1;
}
static bool IsValidOpusBitrate(int bitrate) {
return bitrate;
}
+// Return true if params[kCodecParamUseInbandFec] == "1", false
+// otherwise.
+static bool IsOpusFecEnabled(const AudioCodec& codec) {
+ int value;
+ return codec.GetParam(kCodecParamUseInbandFec, &value) && value == 1;
+}
+
+// Set params[kCodecParamUseInbandFec]. Caller should make sure codec is Opus.
+static void SetOpusFec(AudioCodec* codec, bool opus_fec) {
+ if (opus_fec) {
+ codec->SetParam(kCodecParamUseInbandFec, 1);
+ } else {
+ codec->RemoveParam(kCodecParamUseInbandFec);
+ }
+}
+
void WebRtcVoiceEngine::ConstructCodecs() {
LOG(LS_INFO) << "WebRtc VoiceEngine codecs:";
int ncodecs = voe_wrapper_->codec()->NumOfCodecs();
// Only add fmtp parameters that differ from the spec.
if (kPreferredMinPTime != kOpusDefaultMinPTime) {
codec.params[kCodecParamMinPTime] =
- talk_base::ToString(kPreferredMinPTime);
+ rtc::ToString(kPreferredMinPTime);
}
if (kPreferredMaxPTime != kOpusDefaultMaxPTime) {
codec.params[kCodecParamMaxPTime] =
- talk_base::ToString(kPreferredMaxPTime);
+ rtc::ToString(kPreferredMaxPTime);
}
// TODO(hellner): Add ptime, sprop-stereo, stereo and useinbandfec
// when they can be set to values other than the default.
+ SetOpusFec(&codec, false);
}
codecs_.push_back(codec);
} else {
tracing_->SetTraceCallback(NULL);
}
-bool WebRtcVoiceEngine::Init(talk_base::Thread* worker_thread) {
+bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) {
LOG(LS_INFO) << "WebRtcVoiceEngine::Init";
bool res = InitInternal();
if (res) {
bool WebRtcVoiceEngine::InitInternal() {
// Temporarily turn logging level up for the Init call
int old_filter = log_filter_;
- int extended_filter = log_filter_ | SeverityToFilter(talk_base::LS_INFO);
+ int extended_filter = log_filter_ | SeverityToFilter(rtc::LS_INFO);
SetTraceFilter(extended_filter);
SetTraceOptions("");
char buffer[1024] = "";
voe_wrapper_->base()->GetVersion(buffer);
LOG(LS_INFO) << "WebRtc VoiceEngine Version:";
- LogMultiline(talk_base::LS_INFO, buffer);
+ LogMultiline(rtc::LS_INFO, buffer);
// Save the default AGC configuration settings. This must happen before
// calling SetOptions or the default will be overwritten.
options.typing_detection.Set(false);
options.experimental_agc.Set(false);
options.experimental_aec.Set(false);
+ options.experimental_ns.Set(false);
#endif
LOG(LS_INFO) << "Applying audio options: " << options.ToString();
- // Configure whether ACM1 or ACM2 is used.
- bool enable_acm2 = false;
- if (options.experimental_acm.Get(&enable_acm2)) {
- EnableExperimentalAcm(enable_acm2);
- }
-
webrtc::VoEAudioProcessing* voep = voe_wrapper_->processing();
bool echo_cancellation;
}
}
+ bool experimental_ns;
+ if (options.experimental_ns.Get(&experimental_ns)) {
+ webrtc::AudioProcessing* audioproc =
+ voe_wrapper_->base()->audio_processing();
+#ifdef USE_WEBRTC_DEV_BRANCH
+ webrtc::Config config;
+ config.Set<webrtc::ExperimentalNs>(new webrtc::ExperimentalNs(
+ experimental_ns));
+ audioproc->SetExtraOptions(config);
+#else
+ // We check audioproc for the benefit of tests, since FakeWebRtcVoiceEngine
+ // returns NULL on audio_processing().
+ if (audioproc) {
+ if (audioproc->EnableExperimentalNs(experimental_ns) == -1) {
+ LOG_RTCERR1(EnableExperimentalNs, experimental_ns);
+ return false;
+ }
+ } else {
+ LOG(LS_VERBOSE) << "Experimental noise suppression set to "
+ << experimental_ns;
+ }
+#endif
+ }
+
bool highpass_filter;
if (options.highpass_filter.Get(&highpass_filter)) {
+ LOG(LS_INFO) << "High pass filter enabled? " << highpass_filter;
if (voep->EnableHighPassFilter(highpass_filter) == -1) {
LOG_RTCERR1(SetHighpassFilterStatus, highpass_filter);
return false;
bool stereo_swapping;
if (options.stereo_swapping.Get(&stereo_swapping)) {
+ LOG(LS_INFO) << "Stereo swapping enabled? " << stereo_swapping;
voep->EnableStereoChannelSwapping(stereo_swapping);
if (voep->IsStereoChannelSwappingEnabled() != stereo_swapping) {
LOG_RTCERR1(EnableStereoChannelSwapping, stereo_swapping);
bool typing_detection;
if (options.typing_detection.Get(&typing_detection)) {
+ LOG(LS_INFO) << "Typing detection is enabled? " << typing_detection;
if (voep->SetTypingDetectionStatus(typing_detection) == -1) {
// In case of error, log the info and continue
LOG_RTCERR1(SetTypingDetectionStatus, typing_detection);
int adjust_agc_delta;
if (options.adjust_agc_delta.Get(&adjust_agc_delta)) {
+ LOG(LS_INFO) << "Adjust agc delta is " << adjust_agc_delta;
if (!AdjustAgcLevel(adjust_agc_delta)) {
return false;
}
bool aec_dump;
if (options.aec_dump.Get(&aec_dump)) {
+ LOG(LS_INFO) << "Aec dump is enabled? " << aec_dump;
if (aec_dump)
StartAecDump(kAecDumpByAudioOptionFilename);
else
bool experimental_aec;
if (options.experimental_aec.Get(&experimental_aec)) {
+ LOG(LS_INFO) << "Experimental aec is " << experimental_aec;
webrtc::AudioProcessing* audioproc =
voe_wrapper_->base()->audio_processing();
// We check audioproc for the benefit of tests, since FakeWebRtcVoiceEngine
uint32 recording_sample_rate;
if (options.recording_sample_rate.Get(&recording_sample_rate)) {
+ LOG(LS_INFO) << "Recording sample rate is " << recording_sample_rate;
if (voe_wrapper_->hw()->SetRecordingSampleRate(recording_sample_rate)) {
LOG_RTCERR1(SetRecordingSampleRate, recording_sample_rate);
}
uint32 playout_sample_rate;
if (options.playout_sample_rate.Get(&playout_sample_rate)) {
+ LOG(LS_INFO) << "Playout sample rate is " << playout_sample_rate;
if (voe_wrapper_->hw()->SetPlayoutSampleRate(playout_sample_rate)) {
LOG_RTCERR1(SetPlayoutSampleRate, playout_sample_rate);
}
}
+ bool opus_fec;
+ if (options.opus_fec.Get(&opus_fec)) {
+ LOG(LS_INFO) << "Opus FEC is enabled? " << opus_fec;
+ for (std::vector<AudioCodec>::iterator it = codecs_.begin();
+ it != codecs_.end(); ++it) {
+ if (IsOpus(*it))
+ SetOpusFec(&(*it), opus_fec);
+ }
+ }
return true;
}
bool WebRtcVoiceEngine::SetDevices(const Device* in_device,
const Device* out_device) {
#if !defined(IOS)
- int in_id = in_device ? talk_base::FromString<int>(in_device->id) :
+ int in_id = in_device ? rtc::FromString<int>(in_device->id) :
kDefaultAudioDeviceId;
- int out_id = out_device ? talk_base::FromString<int>(out_device->id) :
+ int out_id = out_device ? rtc::FromString<int>(out_device->id) :
kDefaultAudioDeviceId;
// The device manager uses -1 as the default device, which was the case for
// VoE 3.5. VoE 4.0, however, uses 0 as the default in Linux and Mac.
LOG_RTCERR2(SetRecordingDevice, in_name, in_id);
ret = false;
}
+ webrtc::AudioProcessing* ap = voe()->base()->audio_processing();
+ if (ap)
+ ap->Initialize();
}
// Find the playout device id in VoiceEngine and set playout device.
void WebRtcVoiceEngine::SetTraceOptions(const std::string& options) {
// Set encrypted trace file.
std::vector<std::string> opts;
- talk_base::tokenize(options, ' ', '"', '"', &opts);
+ rtc::tokenize(options, ' ', '"', '"', &opts);
std::vector<std::string>::iterator tracefile =
std::find(opts.begin(), opts.end(), "tracefile");
if (tracefile != opts.end() && ++tracefile != opts.end()) {
std::vector<std::string>::iterator tracefilter =
std::find(opts.begin(), opts.end(), "tracefilter");
if (tracefilter != opts.end() && ++tracefilter != opts.end()) {
- if (!tracing_->SetTraceFilter(talk_base::FromString<int>(*tracefilter))) {
+ if (!tracing_->SetTraceFilter(rtc::FromString<int>(*tracefilter))) {
LOG_RTCERR1(SetTraceFilter, *tracefilter);
}
}
return false;
}
-void WebRtcVoiceEngine::EnableExperimentalAcm(bool enable) {
- if (enable == use_experimental_acm_)
- return;
- if (enable) {
- LOG(LS_INFO) << "VoiceEngine is set to use new ACM (ACM2 + NetEq4).";
- voe_config_.Set<webrtc::AudioCodingModuleFactory>(
- new webrtc::NewAudioCodingModuleFactory());
- } else {
- LOG(LS_INFO) << "VoiceEngine is set to use legacy ACM (ACM1 + Neteq3).";
- voe_config_.Set<webrtc::AudioCodingModuleFactory>(
- new webrtc::AudioCodingModuleFactory());
- }
- use_experimental_acm_ = enable;
-}
-
void WebRtcVoiceEngine::Print(webrtc::TraceLevel level, const char* trace,
int length) {
- talk_base::LoggingSeverity sev = talk_base::LS_VERBOSE;
+ rtc::LoggingSeverity sev = rtc::LS_VERBOSE;
if (level == webrtc::kTraceError || level == webrtc::kTraceCritical)
- sev = talk_base::LS_ERROR;
+ sev = rtc::LS_ERROR;
else if (level == webrtc::kTraceWarning)
- sev = talk_base::LS_WARNING;
+ sev = rtc::LS_WARNING;
else if (level == webrtc::kTraceStateInfo || level == webrtc::kTraceInfo)
- sev = talk_base::LS_INFO;
+ sev = rtc::LS_INFO;
else if (level == webrtc::kTraceTerseInfo)
- sev = talk_base::LS_INFO;
+ sev = rtc::LS_INFO;
// Skip past boilerplate prefix text
if (length < 72) {
}
void WebRtcVoiceEngine::CallbackOnError(int channel_num, int err_code) {
- talk_base::CritScope lock(&channels_cs_);
+ rtc::CritScope lock(&channels_cs_);
WebRtcVoiceMediaChannel* channel = NULL;
uint32 ssrc = 0;
LOG(LS_WARNING) << "VoiceEngine error " << err_code << " reported on channel "
}
void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel *channel) {
- talk_base::CritScope lock(&channels_cs_);
+ rtc::CritScope lock(&channels_cs_);
channels_.push_back(channel);
}
void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel *channel) {
- talk_base::CritScope lock(&channels_cs_);
+ rtc::CritScope lock(&channels_cs_);
ChannelList::iterator i = std::find(channels_.begin(),
channels_.end(),
channel);
return true;
}
-bool WebRtcVoiceEngine::StartAecDump(talk_base::PlatformFile file) {
- FILE* aec_dump_file_stream = talk_base::FdopenPlatformFileForWriting(file);
+bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file) {
+ FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file);
if (!aec_dump_file_stream) {
LOG(LS_ERROR) << "Could not open AEC dump file stream.";
- if (!talk_base::ClosePlatformFile(file))
+ if (!rtc::ClosePlatformFile(file))
LOG(LS_WARNING) << "Could not close file.";
return false;
}
webrtc::ProcessingTypes processing_type;
{
- talk_base::CritScope cs(&signal_media_critical_);
+ rtc::CritScope cs(&signal_media_critical_);
if (direction == MPD_RX) {
processing_type = webrtc::kPlaybackAllChannelsMixed;
if (SignalRxMediaFrame.is_empty()) {
int deregister_id = -1;
{
- talk_base::CritScope cs(&signal_media_critical_);
+ rtc::CritScope cs(&signal_media_critical_);
if ((processor_direction & channel_direction) != 0 && !signal->is_empty()) {
signal->disconnect(voice_processor);
int channel_id = -1;
int length,
int sampling_freq,
bool is_stereo) {
- talk_base::CritScope cs(&signal_media_critical_);
+ rtc::CritScope cs(&signal_media_critical_);
AudioFrame frame(audio10ms, length, sampling_freq, is_stereo);
if (type == webrtc::kPlaybackAllChannelsMixed) {
SignalRxMediaFrame(rx_processor_ssrc_, MPD_RX, &frame);
return CreateVoiceChannel(voe_wrapper_sc_.get());
}
-// This struct relies on the generated copy constructor and assignment operator
-// since it is used in an stl::map.
-struct WebRtcVoiceMediaChannel::WebRtcVoiceChannelInfo {
- WebRtcVoiceChannelInfo() : channel(-1), renderer(NULL) {}
- WebRtcVoiceChannelInfo(int ch, AudioRenderer* r)
- : channel(ch),
- renderer(r) {}
- ~WebRtcVoiceChannelInfo() {}
+class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer
+ : public AudioRenderer::Sink {
+ public:
+ WebRtcVoiceChannelRenderer(int ch,
+ webrtc::AudioTransport* voe_audio_transport)
+ : channel_(ch),
+ voe_audio_transport_(voe_audio_transport),
+ renderer_(NULL) {
+ }
+ virtual ~WebRtcVoiceChannelRenderer() {
+ Stop();
+ }
+
+ // Starts the rendering by setting a sink to the renderer to get data
+ // callback.
+ // This method is called on the libjingle worker thread.
+ // TODO(xians): Make sure Start() is called only once.
+ void Start(AudioRenderer* renderer) {
+ rtc::CritScope lock(&lock_);
+ ASSERT(renderer != NULL);
+ if (renderer_ != NULL) {
+ ASSERT(renderer_ == renderer);
+ return;
+ }
+
+ // TODO(xians): Remove AddChannel() call after Chrome turns on APM
+ // in getUserMedia by default.
+ renderer->AddChannel(channel_);
+ renderer->SetSink(this);
+ renderer_ = renderer;
+ }
+
+ // Stops rendering by setting the sink of the renderer to NULL. No data
+ // callback will be received after this method.
+ // This method is called on the libjingle worker thread.
+ void Stop() {
+ rtc::CritScope lock(&lock_);
+ if (renderer_ == NULL)
+ return;
+
+ renderer_->RemoveChannel(channel_);
+ renderer_->SetSink(NULL);
+ renderer_ = NULL;
+ }
+
+ // AudioRenderer::Sink implementation.
+ // This method is called on the audio thread.
+ virtual void OnData(const void* audio_data,
+ int bits_per_sample,
+ int sample_rate,
+ int number_of_channels,
+ int number_of_frames) OVERRIDE {
+ voe_audio_transport_->OnData(channel_,
+ audio_data,
+ bits_per_sample,
+ sample_rate,
+ number_of_channels,
+ number_of_frames);
+ }
+
+ // Callback from the |renderer_| when it is going away. In case Start() has
+ // never been called, this callback won't be triggered.
+ virtual void OnClose() OVERRIDE {
+ rtc::CritScope lock(&lock_);
+ // Set |renderer_| to NULL to make sure no more callback will get into
+ // the renderer.
+ renderer_ = NULL;
+ }
+
+ // Accessor to the VoE channel ID.
+ int channel() const { return channel_; }
+
+ private:
+ const int channel_;
+ webrtc::AudioTransport* const voe_audio_transport_;
+
+ // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler.
+ // PeerConnection will make sure invalidating the pointer before the object
+ // goes away.
+ AudioRenderer* renderer_;
- int channel;
- AudioRenderer* renderer;
+ // Protects |renderer_| in Start(), Stop() and OnClose().
+ rtc::CriticalSection lock_;
};
// WebRtcVoiceMediaChannel
}
}
if (dscp_option_changed) {
- talk_base::DiffServCodePoint dscp = talk_base::DSCP_DEFAULT;
+ rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT;
if (options_.dscp.GetWithDefaultIfUnset(false))
dscp = kAudioDscpValue;
if (MediaChannel::SetDscp(dscp) != 0) {
for (ChannelMap::iterator it = receive_channels_.begin();
it != receive_channels_.end() && ret; ++it) {
if (engine()->voe()->codec()->SetRecPayloadType(
- it->second.channel, voe_codec) == -1) {
- LOG_RTCERR2(SetRecPayloadType, it->second.channel,
+ it->second->channel(), voe_codec) == -1) {
+ LOG_RTCERR2(SetRecPayloadType, it->second->channel(),
ToString(voe_codec));
ret = false;
}
bool WebRtcVoiceMediaChannel::SetSendCodecs(
int channel, const std::vector<AudioCodec>& codecs) {
- // Disable VAD, and FEC unless we know the other side wants them.
+ // Disable VAD, FEC, and RED unless we know the other side wants them.
engine()->voe()->codec()->SetVADStatus(channel, false);
engine()->voe()->rtp()->SetNACKStatus(channel, false, 0);
+#ifdef USE_WEBRTC_DEV_BRANCH
+ engine()->voe()->rtp()->SetREDStatus(channel, false);
+ engine()->voe()->codec()->SetFECStatus(channel, false);
+#else
+ // TODO(minyue): Remove code under #else case after new WebRTC roll.
engine()->voe()->rtp()->SetFECStatus(channel, false);
+#endif // USE_WEBRTC_DEV_BRANCH
// Scan through the list to figure out the codec to use for sending, along
// with the proper configuration for VAD and DTMF.
- bool first = true;
+ bool found_send_codec = false;
webrtc::CodecInst send_codec;
memset(&send_codec, 0, sizeof(send_codec));
+ bool nack_enabled = nack_enabled_;
+ bool enable_codec_fec = false;
+
+ // Set send codec (the first non-telephone-event/CN codec)
for (std::vector<AudioCodec>::const_iterator it = codecs.begin();
it != codecs.end(); ++it) {
// Ignore codecs we don't know about. The negotiation step should prevent
continue;
}
+ if (IsTelephoneEventCodec(it->name) || IsCNCodec(it->name)) {
+ // Skip telephone-event/CN codec, which will be handled later.
+ continue;
+ }
+
// If OPUS, change what we send according to the "stereo" codec
// parameter, and not the "channels" parameter. We set
// voe_codec.channels to 2 if "stereo=1" and 1 otherwise. If
}
}
+ // We'll use the first codec in the list to actually send audio data.
+ // Be sure to use the payload type requested by the remote side.
+ // "red", for RED audio, is a special case where the actual codec to be
+ // used is specified in params.
+ if (IsRedCodec(it->name)) {
+ // Parse out the RED parameters. If we fail, just ignore RED;
+ // we don't support all possible params/usage scenarios.
+ if (!GetRedSendCodec(*it, codecs, &send_codec)) {
+ continue;
+ }
+
+ // Enable redundant encoding of the specified codec. Treat any
+ // failure as a fatal internal error.
+#ifdef USE_WEBRTC_DEV_BRANCH
+ LOG(LS_INFO) << "Enabling RED on channel " << channel;
+ if (engine()->voe()->rtp()->SetREDStatus(channel, true, it->id) == -1) {
+ LOG_RTCERR3(SetREDStatus, channel, true, it->id);
+#else
+ // TODO(minyue): Remove code under #else case after new WebRTC roll.
+ LOG(LS_INFO) << "Enabling FEC";
+ if (engine()->voe()->rtp()->SetFECStatus(channel, true, it->id) == -1) {
+ LOG_RTCERR3(SetFECStatus, channel, true, it->id);
+#endif // USE_WEBRTC_DEV_BRANCH
+ return false;
+ }
+ } else {
+ send_codec = voe_codec;
+ nack_enabled = IsNackEnabled(*it);
+ // For Opus as the send codec, we enable inband FEC if requested.
+ enable_codec_fec = IsOpus(*it) && IsOpusFecEnabled(*it);
+ }
+ found_send_codec = true;
+ break;
+ }
+
+ if (nack_enabled_ != nack_enabled) {
+ SetNack(channel, nack_enabled);
+ nack_enabled_ = nack_enabled;
+ }
+
+ if (!found_send_codec) {
+ LOG(LS_WARNING) << "Received empty list of codecs.";
+ return false;
+ }
+
+ // Set the codec immediately, since SetVADStatus() depends on whether
+ // the current codec is mono or stereo.
+ if (!SetSendCodec(channel, send_codec))
+ return false;
+
+ // FEC should be enabled after SetSendCodec.
+ if (enable_codec_fec) {
+ LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel "
+ << channel;
+#ifdef USE_WEBRTC_DEV_BRANCH
+ if (engine()->voe()->codec()->SetFECStatus(channel, true) == -1) {
+ // Enable codec internal FEC. Treat any failure as fatal internal error.
+ LOG_RTCERR2(SetFECStatus, channel, true);
+ return false;
+ }
+#endif // USE_WEBRTC_DEV_BRANCH
+ }
+
+ // Always update the |send_codec_| to the currently set send codec.
+ send_codec_.reset(new webrtc::CodecInst(send_codec));
+
+ if (send_bw_setting_) {
+ SetSendBandwidthInternal(send_bw_bps_);
+ }
+
+ // Loop through the codecs list again to config the telephone-event/CN codec.
+ for (std::vector<AudioCodec>::const_iterator it = codecs.begin();
+ it != codecs.end(); ++it) {
+ // Ignore codecs we don't know about. The negotiation step should prevent
+ // this, but double-check to be sure.
+ webrtc::CodecInst voe_codec;
+ if (!engine()->FindWebRtcCodec(*it, &voe_codec)) {
+ LOG(LS_WARNING) << "Unknown codec " << ToString(*it);
+ continue;
+ }
+
// Find the DTMF telephone event "codec" and tell VoiceEngine channels
// about it.
- if (_stricmp(it->name.c_str(), "telephone-event") == 0 ||
- _stricmp(it->name.c_str(), "audio/telephone-event") == 0) {
+ if (IsTelephoneEventCodec(it->name)) {
if (engine()->voe()->dtmf()->SetSendTelephoneEventPayloadType(
channel, it->id) == -1) {
LOG_RTCERR2(SetSendTelephoneEventPayloadType, channel, it->id);
return false;
}
- }
-
- // Turn voice activity detection/comfort noise on if supported.
- // Set the wideband CN payload type appropriately.
- // (narrowband always uses the static payload type 13).
- if (_stricmp(it->name.c_str(), "CN") == 0) {
+ } else if (IsCNCodec(it->name)) {
+ // Turn voice activity detection/comfort noise on if supported.
+ // Set the wideband CN payload type appropriately.
+ // (narrowband always uses the static payload type 13).
webrtc::PayloadFrequencies cn_freq;
switch (it->clockrate) {
case 8000:
// send the offer.
}
}
-
// Only turn on VAD if we have a CN payload type that matches the
// clockrate for the codec we are going to use.
if (it->clockrate == send_codec.plfreq) {
}
}
}
-
- // We'll use the first codec in the list to actually send audio data.
- // Be sure to use the payload type requested by the remote side.
- // "red", for FEC audio, is a special case where the actual codec to be
- // used is specified in params.
- if (first) {
- if (_stricmp(it->name.c_str(), "red") == 0) {
- // Parse out the RED parameters. If we fail, just ignore RED;
- // we don't support all possible params/usage scenarios.
- if (!GetRedSendCodec(*it, codecs, &send_codec)) {
- continue;
- }
-
- // Enable redundant encoding of the specified codec. Treat any
- // failure as a fatal internal error.
- LOG(LS_INFO) << "Enabling FEC";
- if (engine()->voe()->rtp()->SetFECStatus(channel, true, it->id) == -1) {
- LOG_RTCERR3(SetFECStatus, channel, true, it->id);
- return false;
- }
- } else {
- send_codec = voe_codec;
- nack_enabled_ = IsNackEnabled(*it);
- SetNack(channel, nack_enabled_);
- }
- first = false;
- // Set the codec immediately, since SetVADStatus() depends on whether
- // the current codec is mono or stereo.
- if (!SetSendCodec(channel, send_codec))
- return false;
- }
- }
-
- // If we're being asked to set an empty list of codecs, due to a buggy client,
- // choose the most common format: PCMU
- if (first) {
- LOG(LS_WARNING) << "Received empty list of codecs; using PCMU/8000";
- AudioCodec codec(0, "PCMU", 8000, 0, 1, 0);
- engine()->FindWebRtcCodec(codec, &send_codec);
- if (!SetSendCodec(channel, send_codec))
- return false;
- }
-
- // Always update the |send_codec_| to the currently set send codec.
- send_codec_.reset(new webrtc::CodecInst(send_codec));
-
- if (send_bw_setting_) {
- SetSendBandwidthInternal(send_bw_bps_);
}
-
return true;
}
send_codecs_ = codecs;
for (ChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
- if (!SetSendCodecs(iter->second.channel, codecs)) {
+ if (!SetSendCodecs(iter->second->channel(), codecs)) {
return false;
}
}
+ // Set nack status on receive channels and update |nack_enabled_|.
SetNack(receive_channels_, nack_enabled_);
-
return true;
}
bool nack_enabled) {
for (ChannelMap::const_iterator it = channels.begin();
it != channels.end(); ++it) {
- SetNack(it->second.channel, nack_enabled);
+ SetNack(it->second->channel(), nack_enabled);
}
}
<< ", bitrate=" << send_codec.rate;
for (ChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
- if (!SetSendCodec(iter->second.channel, send_codec))
+ if (!SetSendCodec(iter->second->channel(), send_codec))
return false;
}
LOG(LS_INFO) << "Send channel " << channel << " selected voice codec "
<< ToString(send_codec) << ", bitrate=" << send_codec.rate;
+ webrtc::CodecInst current_codec;
+ if (engine()->voe()->codec()->GetSendCodec(channel, current_codec) == 0 &&
+ (send_codec == current_codec)) {
+ // Codec is already configured, we can return without setting it again.
+ return true;
+ }
+
if (engine()->voe()->codec()->SetSendCodec(channel, send_codec) == -1) {
LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec));
return false;
bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions(
const std::vector<RtpHeaderExtension>& extensions) {
- // We don't support any incoming extensions headers right now.
+ if (receive_extensions_ == extensions) {
+ return true;
+ }
+
+ // The default channel may or may not be in |receive_channels_|. Set the rtp
+ // header extensions for default channel regardless.
+ if (!SetChannelRecvRtpHeaderExtensions(voe_channel(), extensions)) {
+ return false;
+ }
+
+ // Loop through all receive channels and enable/disable the extensions.
+ for (ChannelMap::const_iterator channel_it = receive_channels_.begin();
+ channel_it != receive_channels_.end(); ++channel_it) {
+ if (!SetChannelRecvRtpHeaderExtensions(channel_it->second->channel(),
+ extensions)) {
+ return false;
+ }
+ }
+
+ receive_extensions_ = extensions;
+ return true;
+}
+
+bool WebRtcVoiceMediaChannel::SetChannelRecvRtpHeaderExtensions(
+ int channel_id, const std::vector<RtpHeaderExtension>& extensions) {
+ const RtpHeaderExtension* audio_level_extension =
+ FindHeaderExtension(extensions, kRtpAudioLevelHeaderExtension);
+ if (!SetHeaderExtension(
+ &webrtc::VoERTP_RTCP::SetReceiveAudioLevelIndicationStatus, channel_id,
+ audio_level_extension)) {
+ return false;
+ }
+
+ const RtpHeaderExtension* send_time_extension =
+ FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
+ if (!SetHeaderExtension(
+ &webrtc::VoERTP_RTCP::SetReceiveAbsoluteSenderTimeStatus, channel_id,
+ send_time_extension)) {
+ return false;
+ }
return true;
}
bool WebRtcVoiceMediaChannel::SetSendRtpHeaderExtensions(
const std::vector<RtpHeaderExtension>& extensions) {
- // Enable the audio level extension header if requested.
- std::vector<RtpHeaderExtension>::const_iterator it;
- for (it = extensions.begin(); it != extensions.end(); ++it) {
- if (it->uri == kRtpAudioLevelHeaderExtension) {
- break;
- }
+ if (send_extensions_ == extensions) {
+ return true;
}
- bool enable = (it != extensions.end());
- int id = 0;
+ // The default channel may or may not be in |send_channels_|. Set the rtp
+ // header extensions for default channel regardless.
- if (enable) {
- id = it->id;
- if (id < kMinRtpHeaderExtensionId ||
- id > kMaxRtpHeaderExtensionId) {
- LOG(LS_WARNING) << "Invalid RTP header extension id " << id;
- return false;
- }
+ if (!SetChannelSendRtpHeaderExtensions(voe_channel(), extensions)) {
+ return false;
}
- LOG(LS_INFO) << "Enabling audio level header extension with ID " << id;
- for (ChannelMap::const_iterator iter = send_channels_.begin();
- iter != send_channels_.end(); ++iter) {
- if (engine()->voe()->rtp()->SetRTPAudioLevelIndicationStatus(
- iter->second.channel, enable, id) == -1) {
- LOG_RTCERR3(SetRTPAudioLevelIndicationStatus,
- iter->second.channel, enable, id);
+ // Loop through all send channels and enable/disable the extensions.
+ for (ChannelMap::const_iterator channel_it = send_channels_.begin();
+ channel_it != send_channels_.end(); ++channel_it) {
+ if (!SetChannelSendRtpHeaderExtensions(channel_it->second->channel(),
+ extensions)) {
return false;
}
}
+ send_extensions_ = extensions;
+ return true;
+}
+
+bool WebRtcVoiceMediaChannel::SetChannelSendRtpHeaderExtensions(
+ int channel_id, const std::vector<RtpHeaderExtension>& extensions) {
+ const RtpHeaderExtension* audio_level_extension =
+ FindHeaderExtension(extensions, kRtpAudioLevelHeaderExtension);
+
+ if (!SetHeaderExtension(
+ &webrtc::VoERTP_RTCP::SetSendAudioLevelIndicationStatus, channel_id,
+ audio_level_extension)) {
+ return false;
+ }
+
+ const RtpHeaderExtension* send_time_extension =
+ FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
+ if (!SetHeaderExtension(
+ &webrtc::VoERTP_RTCP::SetSendAbsoluteSenderTimeStatus, channel_id,
+ send_time_extension)) {
+ return false;
+ }
+
return true;
}
}
for (ChannelMap::iterator it = receive_channels_.begin();
it != receive_channels_.end() && result; ++it) {
- if (!SetPlayout(it->second.channel, playout)) {
+ if (!SetPlayout(it->second->channel(), playout)) {
LOG(LS_ERROR) << "SetPlayout " << playout << " on channel "
- << it->second.channel << " failed";
+ << it->second->channel() << " failed";
result = false;
}
}
// Change the settings on each send channel.
for (ChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
- if (!ChangeSend(iter->second.channel, send))
+ if (!ChangeSend(iter->second->channel(), send))
return false;
}
return true;
}
+// TODO(ronghuawu): Change this method to return bool.
void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) {
if (engine()->voe()->network()->RegisterExternalTransport(
channel, *this) == -1) {
// Reset all recv codecs; they will be enabled via SetRecvCodecs.
ResetRecvCodecs(channel);
+
+ // Set RTP header extension for the new channel.
+ SetChannelSendRtpHeaderExtensions(channel, send_extensions_);
}
bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) {
bool default_channel_is_available = true;
for (ChannelMap::const_iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
- if (IsDefaultChannel(iter->second.channel)) {
+ if (IsDefaultChannel(iter->second->channel())) {
default_channel_is_available = false;
break;
}
// Save the channel to send_channels_, so that RemoveSendStream() can still
// delete the channel in case failure happens below.
- send_channels_[sp.first_ssrc()] = WebRtcVoiceChannelInfo(channel, NULL);
+ webrtc::AudioTransport* audio_transport =
+ engine()->voe()->base()->audio_transport();
+ send_channels_.insert(std::make_pair(
+ sp.first_ssrc(),
+ new WebRtcVoiceChannelRenderer(channel, audio_transport)));
// Set the send (local) SSRC.
// If there are multiple send SSRCs, we can only set the first one here, and
for (ChannelMap::const_iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
// Only update the SSRC for non-default channels.
- if (!IsDefaultChannel(it->second.channel)) {
- if (engine()->voe()->rtp()->SetLocalSSRC(it->second.channel,
+ if (!IsDefaultChannel(it->second->channel())) {
+ if (engine()->voe()->rtp()->SetLocalSSRC(it->second->channel(),
sp.first_ssrc()) != 0) {
- LOG_RTCERR2(SetLocalSSRC, it->second.channel, sp.first_ssrc());
+ LOG_RTCERR2(SetLocalSSRC, it->second->channel(), sp.first_ssrc());
return false;
}
}
return false;
}
- int channel = it->second.channel;
+ int channel = it->second->channel();
ChangeSend(channel, SEND_NOTHING);
- // Notify the audio renderer that the send channel is going away.
- if (it->second.renderer)
- it->second.renderer->RemoveChannel(channel);
+ // Delete the WebRtcVoiceChannelRenderer object connected to the channel,
+ // this will disconnect the audio renderer with the send channel.
+ delete it->second;
+ send_channels_.erase(it);
if (IsDefaultChannel(channel)) {
// Do not delete the default channel since the receive channels depend on
return false;
}
- send_channels_.erase(it);
if (send_channels_.empty())
ChangeSend(SEND_NOTHING);
}
bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) {
- talk_base::CritScope lock(&receive_channels_cs_);
+ rtc::CritScope lock(&receive_channels_cs_);
if (!VERIFY(sp.ssrcs.size() == 1))
return false;
// Reuse default channel for recv stream in non-conference mode call
// when the default channel is not being used.
+ webrtc::AudioTransport* audio_transport =
+ engine()->voe()->base()->audio_transport();
if (!InConferenceMode() && default_receive_ssrc_ == 0) {
LOG(LS_INFO) << "Recv stream " << sp.first_ssrc()
<< " reuse default channel";
default_receive_ssrc_ = sp.first_ssrc();
receive_channels_.insert(std::make_pair(
- default_receive_ssrc_, WebRtcVoiceChannelInfo(voe_channel(), NULL)));
+ default_receive_ssrc_,
+ new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport)));
return SetPlayout(voe_channel(), playout_);
}
}
receive_channels_.insert(
- std::make_pair(ssrc, WebRtcVoiceChannelInfo(channel, NULL)));
+ std::make_pair(
+ ssrc, new WebRtcVoiceChannelRenderer(channel, audio_transport)));
LOG(LS_INFO) << "New audio stream " << ssrc
<< " registered to VoiceEngine channel #"
}
SetNack(channel, nack_enabled_);
+ // Set RTP header extension for the new channel.
+ if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) {
+ return false;
+ }
+
return SetPlayout(channel, playout_);
}
bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) {
- talk_base::CritScope lock(&receive_channels_cs_);
+ rtc::CritScope lock(&receive_channels_cs_);
ChannelMap::iterator it = receive_channels_.find(ssrc);
if (it == receive_channels_.end()) {
LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
return false;
}
+ // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this
+ // will disconnect the audio renderer with the receive channel.
+ // Cache the channel before the deletion.
+ const int channel = it->second->channel();
+ delete it->second;
+ receive_channels_.erase(it);
+
if (ssrc == default_receive_ssrc_) {
- ASSERT(IsDefaultChannel(it->second.channel));
+ ASSERT(IsDefaultChannel(channel));
// Recycle the default channel is for recv stream.
if (playout_)
SetPlayout(voe_channel(), false);
- if (it->second.renderer)
- it->second.renderer->RemoveChannel(voe_channel());
-
default_receive_ssrc_ = 0;
- receive_channels_.erase(it);
return true;
}
- // Non default channel.
- // Notify the renderer that channel is going away.
- if (it->second.renderer)
- it->second.renderer->RemoveChannel(it->second.channel);
-
LOG(LS_INFO) << "Removing audio stream " << ssrc
- << " with VoiceEngine channel #" << it->second.channel << ".";
- if (!DeleteChannel(it->second.channel)) {
- // Erase the entry anyhow.
- receive_channels_.erase(it);
+ << " with VoiceEngine channel #" << channel << ".";
+ if (!DeleteChannel(channel))
return false;
- }
- receive_channels_.erase(it);
bool enable_default_channel_playout = false;
if (receive_channels_.empty()) {
// The last stream was removed. We can now enable the default
return true;
}
- AudioRenderer* remote_renderer = it->second.renderer;
- if (renderer) {
- ASSERT(remote_renderer == NULL || remote_renderer == renderer);
- if (!remote_renderer) {
- renderer->AddChannel(it->second.channel);
- }
- } else if (remote_renderer) {
- // |renderer| == NULL, remove the channel from the renderer.
- remote_renderer->RemoveChannel(it->second.channel);
- }
+ if (renderer)
+ it->second->Start(renderer);
+ else
+ it->second->Stop();
- // Assign the new value to the struct.
- it->second.renderer = renderer;
return true;
}
return true;
}
- AudioRenderer* local_renderer = it->second.renderer;
- if (renderer) {
- ASSERT(local_renderer == NULL || local_renderer == renderer);
- if (!local_renderer)
- renderer->AddChannel(it->second.channel);
- } else if (local_renderer) {
- local_renderer->RemoveChannel(it->second.channel);
- }
+ if (renderer)
+ it->second->Start(renderer);
+ else
+ it->second->Stop();
- // Assign the new value to the struct.
- it->second.renderer = renderer;
return true;
}
actives->clear();
for (ChannelMap::iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
- int level = GetOutputLevel(it->second.channel);
+ int level = GetOutputLevel(it->second->channel());
if (level > 0) {
actives->push_back(std::make_pair(it->first, level));
}
int highest = GetOutputLevel(voe_channel());
for (ChannelMap::iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
- int level = GetOutputLevel(it->second.channel);
- highest = talk_base::_max(level, highest);
+ int level = GetOutputLevel(it->second->channel());
+ highest = rtc::_max(level, highest);
}
return highest;
}
bool WebRtcVoiceMediaChannel::SetOutputScaling(
uint32 ssrc, double left, double right) {
- talk_base::CritScope lock(&receive_channels_cs_);
+ rtc::CritScope lock(&receive_channels_cs_);
// Collect the channels to scale the output volume.
std::vector<int> channels;
if (0 == ssrc) { // Collect all channels, including the default one.
channels.push_back(voe_channel());
for (ChannelMap::const_iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
- channels.push_back(it->second.channel);
+ channels.push_back(it->second->channel());
}
} else { // Collect only the channel of the specified ssrc.
int channel = GetReceiveChannelNum(ssrc);
// Scale the output volume for the collected channels. We first normalize to
// scale the volume and then set the left and right pan.
- float scale = static_cast<float>(talk_base::_max(left, right));
+ float scale = static_cast<float>(rtc::_max(left, right));
if (scale > 0.0001f) {
left /= scale;
right /= scale;
uint32 ssrc, double* left, double* right) {
if (!left || !right) return false;
- talk_base::CritScope lock(&receive_channels_cs_);
+ rtc::CritScope lock(&receive_channels_cs_);
// Determine which channel based on ssrc.
int channel = (0 == ssrc) ? voe_channel() : GetReceiveChannelNum(ssrc);
if (channel == -1) {
bool default_channel_is_inuse = false;
for (ChannelMap::const_iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
- if (IsDefaultChannel(iter->second.channel)) {
+ if (IsDefaultChannel(iter->second->channel())) {
default_channel_is_inuse = true;
break;
}
if (default_channel_is_inuse) {
channel = voe_channel();
} else if (!send_channels_.empty()) {
- channel = send_channels_.begin()->second.channel;
+ channel = send_channels_.begin()->second->channel();
}
} else {
channel = GetSendChannelNum(ssrc);
}
void WebRtcVoiceMediaChannel::OnPacketReceived(
- talk_base::Buffer* packet, const talk_base::PacketTime& packet_time) {
+ rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
// Pick which channel to send this packet to. If this packet doesn't match
// any multiplexed streams, just send it to the default channel. Otherwise,
// send it to the specific decoder instance for that stream.
}
void WebRtcVoiceMediaChannel::OnRtcpReceived(
- talk_base::Buffer* packet, const talk_base::PacketTime& packet_time) {
+ rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
// Sending channels need all RTCP packets with feedback information.
// Even sender reports can contain attached report blocks.
// Receiving channels need sender reports in order to create
for (ChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) {
// Make sure not sending the same packet to default channel more than once.
- if (IsDefaultChannel(iter->second.channel) && has_sent_to_default_channel)
+ if (IsDefaultChannel(iter->second->channel()) &&
+ has_sent_to_default_channel)
continue;
engine()->voe()->network()->ReceivedRTCPPacket(
- iter->second.channel,
+ iter->second->channel(),
packet->data(),
static_cast<unsigned int>(packet->length()));
}
LOG_RTCERR2(SetInputMute, channel, muted);
return false;
}
+ // We set the AGC to mute state only when all the channels are muted.
+ // This implementation is not ideal, instead we should signal the AGC when
+ // the mic channel is muted/unmuted. We can't do it today because there
+ // is no good way to know which stream is mapping to the mic channel.
+ bool all_muted = muted;
+ for (ChannelMap::const_iterator iter = send_channels_.begin();
+ iter != send_channels_.end() && all_muted; ++iter) {
+ if (engine()->voe()->volume()->GetInputMute(iter->second->channel(),
+ all_muted)) {
+ LOG_RTCERR1(GetInputMute, iter->second->channel());
+ return false;
+ }
+ }
+
+ webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing();
+ if (ap)
+ ap->set_output_will_be_muted(all_muted);
return true;
}
for (ChannelMap::const_iterator channel_iter = send_channels_.begin();
channel_iter != send_channels_.end(); ++channel_iter) {
- const int channel = channel_iter->second.channel;
+ const int channel = channel_iter->second->channel();
// Fill in the sender info, based on what we know, and what the
// remote side told us it got from its RTCP report.
std::vector<int> channels;
for (ChannelMap::const_iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
- channels.push_back(it->second.channel);
+ channels.push_back(it->second->channel());
}
if (channels.empty()) {
channels.push_back(voe_channel());
rinfo.fraction_lost = static_cast<float>(cs.fractionLost) / (1 << 8);
rinfo.packets_lost = cs.cumulativeLost;
rinfo.ext_seqnum = cs.extendedMax;
+#ifdef USE_WEBRTC_DEV_BRANCH
+ rinfo.capture_start_ntp_time_ms = cs.capture_start_ntp_time_ms_;
+#endif
+ if (codec.pltype != -1) {
+ rinfo.codec_name = codec.plname;
+ }
// Convert samples to milliseconds.
if (codec.plfreq / 1000 > 0) {
rinfo.jitter_ms = cs.jitterSamples / (codec.plfreq / 1000);
rinfo.expand_rate =
static_cast<float>(ns.currentExpandRate) / (1 << 14);
}
+
+ webrtc::AudioDecodingCallStats ds;
+ if (engine()->voe()->neteq() &&
+ engine()->voe()->neteq()->GetDecodingCallStatistics(
+ *it, &ds) != -1) {
+ rinfo.decoding_calls_to_silence_generator =
+ ds.calls_to_silence_generator;
+ rinfo.decoding_calls_to_neteq = ds.calls_to_neteq;
+ rinfo.decoding_normal = ds.decoded_normal;
+ rinfo.decoding_plc = ds.decoded_plc;
+ rinfo.decoding_cng = ds.decoded_cng;
+ rinfo.decoding_plc_cng = ds.decoded_plc_cng;
+ }
+
if (engine()->voe()->sync()) {
int jitter_buffer_delay_ms = 0;
int playout_buffer_delay_ms = 0;
}
bool WebRtcVoiceMediaChannel::FindSsrc(int channel_num, uint32* ssrc) {
- talk_base::CritScope lock(&receive_channels_cs_);
+ rtc::CritScope lock(&receive_channels_cs_);
ASSERT(ssrc != NULL);
if (channel_num == -1 && send_ != SEND_NOTHING) {
// Sometimes the VoiceEngine core will throw error with channel_num = -1.
// Check whether this is a sending channel.
for (ChannelMap::const_iterator it = send_channels_.begin();
it != send_channels_.end(); ++it) {
- if (it->second.channel == channel_num) {
+ if (it->second->channel() == channel_num) {
// This is a sending channel.
uint32 local_ssrc = 0;
if (engine()->voe()->rtp()->GetLocalSSRC(
// Check whether this is a receiving channel.
for (ChannelMap::const_iterator it = receive_channels_.begin();
it != receive_channels_.end(); ++it) {
- if (it->second.channel == channel_num) {
+ if (it->second->channel() == channel_num) {
*ssrc = it->first;
return true;
}
int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) {
ChannelMap::iterator it = receive_channels_.find(ssrc);
if (it != receive_channels_.end())
- return it->second.channel;
+ return it->second->channel();
return (ssrc == default_receive_ssrc_) ? voe_channel() : -1;
}
int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) {
ChannelMap::iterator it = send_channels_.find(ssrc);
if (it != send_channels_.end())
- return it->second.channel;
+ return it->second->channel();
return -1;
}
if (it != red_codec.params.end()) {
red_params = it->second;
std::vector<std::string> red_pts;
- if (talk_base::split(red_params, '/', &red_pts) != 2 ||
+ if (rtc::split(red_params, '/', &red_pts) != 2 ||
red_pts[0] != red_pts[1] ||
- !talk_base::FromString(red_pts[0], &red_pt)) {
+ !rtc::FromString(red_pts[0], &red_pt)) {
LOG(LS_WARNING) << "RED params " << red_params << " not supported.";
return false;
}
size_t ssrc_pos = (!rtcp) ? 8 : 4;
uint32 ssrc = 0;
if (len >= (ssrc_pos + sizeof(ssrc))) {
- ssrc = talk_base::GetBE32(static_cast<const char*>(data) + ssrc_pos);
+ ssrc = rtc::GetBE32(static_cast<const char*>(data) + ssrc_pos);
}
return ssrc;
}
}
}
+bool WebRtcVoiceMediaChannel::SetHeaderExtension(ExtensionSetterFunction setter,
+ int channel_id, const RtpHeaderExtension* extension) {
+ bool enable = false;
+ int id = 0;
+ std::string uri;
+ if (extension) {
+ enable = true;
+ id = extension->id;
+ uri = extension->uri;
+ }
+ if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) {
+ LOG_RTCERR4(*setter, uri, channel_id, enable, id);
+ return false;
+ }
+ return true;
+}
+
int WebRtcSoundclipStream::Read(void *buf, int len) {
size_t res = 0;
mem_.Read(buf, len, &res, NULL);