2013-09-12 18:30:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-26 04:44:54 -08:00
|
|
|
#include "webrtc/modules/audio_coding/acm2/acm_receiver.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
#include <stdlib.h> // malloc
|
|
|
|
|
|
|
|
|
|
#include <algorithm> // sort
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-08-25 13:08:04 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2015-01-12 21:51:21 +00:00
|
|
|
#include "webrtc/base/format_macros.h"
|
2015-05-27 22:07:35 +02:00
|
|
|
#include "webrtc/base/logging.h"
|
Revert of Safe numeric library: base/numerics (copied from Chromium) (patchset #11 id:250001 of https://codereview.webrtc.org/1753293002/ )
Reason for revert:
Looks like the Chrome iOS build is broken because of these two changes. So I'm going to have to revert. Here's the error:
https://build.chromium.org/p/tryserver.chromium.mac/builders/ios_rel_device_ninja/builds/185624/steps/compile/logs/stdio
FAILED: rm -f arch/libsafe_numerics.arm64.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.arm64.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
FAILED: rm -f arch/libsafe_numerics.armv7.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.armv7.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
ninja: build stopped: subcommand failed.
Original issue's description:
> Safe numeric library added: base/numerics (copied from Chromium)
>
> This copies the contents (unittest excluded) of base/numerics in
> chromium to base/numerics in webrtc. Files added:
> - safe_conversions.h
> - safe_conversions_impl.h
> - safe_math.h
> - safe_math_impl.h
>
> A really old version of safe_conversions[_impl].h previously existed in
> base/, this has been deleted and sources using it have been updated
> to include the new base/numerics/safe_converions.h.
>
> This CL also adds a DEPS file to webrtc/base.
>
> NOPRESUBMIT=True
> BUG=webrtc:5548, webrtc:5623
>
> Committed: https://crrev.com/de1c81b2d2196be611674aa6019b9db3a9329042
> Cr-Commit-Position: refs/heads/master@{#11907}
TBR=kjellander@webrtc.org,kwiberg@webrtc.org,tina.legrand@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5548, webrtc:5623
Review URL: https://codereview.webrtc.org/1792613002 .
Cr-Commit-Position: refs/heads/master@{#11965}
2016-03-11 17:12:32 -08:00
|
|
|
#include "webrtc/base/safe_conversions.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
|
|
|
|
#include "webrtc/common_types.h"
|
2014-12-09 10:12:53 +00:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
|
2015-11-26 04:44:54 -08:00
|
|
|
#include "webrtc/modules/audio_coding/acm2/acm_resampler.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/acm2/call_statistics.h"
|
2015-10-29 11:31:02 +01:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/include/neteq.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-10-06 04:47:28 +00:00
|
|
|
namespace acm2 {
|
|
|
|
|
|
2014-04-29 08:09:31 +00:00
|
|
|
AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config)
|
2016-09-17 08:40:13 -07:00
|
|
|
: last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
|
2016-05-25 07:37:43 -07:00
|
|
|
neteq_(NetEq::Create(config.neteq_config, config.decoder_factory)),
|
2014-04-29 08:09:31 +00:00
|
|
|
clock_(config.clock),
|
2015-11-02 08:31:23 -08:00
|
|
|
resampled_last_output_frame_(true) {
|
2014-04-29 08:09:31 +00:00
|
|
|
assert(clock_);
|
2014-10-21 06:54:23 +00:00
|
|
|
memset(last_audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AcmReceiver::~AcmReceiver() {
|
|
|
|
|
delete neteq_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::SetMinimumDelay(int delay_ms) {
|
|
|
|
|
if (neteq_->SetMinimumDelay(delay_ms))
|
|
|
|
|
return 0;
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::SetMaximumDelay(int delay_ms) {
|
|
|
|
|
if (neteq_->SetMaximumDelay(delay_ms))
|
|
|
|
|
return 0;
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::LeastRequiredDelayMs() const {
|
|
|
|
|
return neteq_->LeastRequiredDelayMs();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 08:19:52 -08:00
|
|
|
rtc::Optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2015-11-23 08:19:52 -08:00
|
|
|
return last_packet_sample_rate_hz_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 06:49:25 -08:00
|
|
|
int AcmReceiver::last_output_sample_rate_hz() const {
|
|
|
|
|
return neteq_->last_output_sample_rate_hz();
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
|
2015-11-11 10:34:00 -08:00
|
|
|
rtc::ArrayView<const uint8_t> incoming_payload) {
|
2013-09-12 18:30:26 +00:00
|
|
|
uint32_t receive_timestamp = 0;
|
|
|
|
|
const RTPHeader* header = &rtp_header.header; // Just a shorthand.
|
|
|
|
|
|
|
|
|
|
{
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2016-09-17 08:40:13 -07:00
|
|
|
const rtc::Optional<CodecInst> ci =
|
|
|
|
|
RtpHeaderToDecoder(*header, incoming_payload[0]);
|
|
|
|
|
if (!ci) {
|
2015-01-30 19:53:42 +00:00
|
|
|
LOG_F(LS_ERROR) << "Payload-type "
|
|
|
|
|
<< static_cast<int>(header->payloadType)
|
|
|
|
|
<< " is not registered.";
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2016-09-17 08:40:13 -07:00
|
|
|
receive_timestamp = NowInTimestamp(ci->plfreq);
|
|
|
|
|
|
|
|
|
|
if (STR_CASE_CMP(ci->plname, "cn") == 0) {
|
|
|
|
|
if (last_audio_decoder_ && last_audio_decoder_->channels > 1) {
|
|
|
|
|
// This is a CNG and the audio codec is not mono, so skip pushing in
|
|
|
|
|
// packets into NetEq.
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
2016-09-17 08:40:13 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
last_audio_decoder_ = ci;
|
|
|
|
|
last_packet_sample_rate_hz_ = rtc::Optional<int>(ci->plfreq);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-09 18:35:11 +00:00
|
|
|
} // |crit_sect_| is released.
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2015-11-11 10:34:00 -08:00
|
|
|
if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) <
|
|
|
|
|
0) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::InsertPacket "
|
|
|
|
|
<< static_cast<int>(header->payloadType)
|
|
|
|
|
<< " Failed to insert packet";
|
2014-06-24 13:11:22 +00:00
|
|
|
return -1;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 03:45:24 -07:00
|
|
|
int AcmReceiver::GetAudio(int desired_freq_hz,
|
|
|
|
|
AudioFrame* audio_frame,
|
|
|
|
|
bool* muted) {
|
2014-10-21 06:54:23 +00:00
|
|
|
// Accessing members, take the lock.
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2014-10-21 06:54:23 +00:00
|
|
|
|
2016-05-13 03:45:24 -07:00
|
|
|
if (neteq_->GetAudio(audio_frame, muted) != NetEq::kOK) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed.";
|
2014-06-24 13:11:22 +00:00
|
|
|
return -1;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-23 06:49:25 -08:00
|
|
|
const int current_sample_rate_hz = neteq_->last_output_sample_rate_hz();
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
// Update if resampling is required.
|
2015-11-23 06:49:25 -08:00
|
|
|
const bool need_resampling =
|
|
|
|
|
(desired_freq_hz != -1) && (current_sample_rate_hz != desired_freq_hz);
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2014-10-21 06:54:23 +00:00
|
|
|
if (need_resampling && !resampled_last_output_frame_) {
|
|
|
|
|
// Prime the resampler with the last frame.
|
|
|
|
|
int16_t temp_output[AudioFrame::kMaxDataSizeSamples];
|
2015-11-23 06:49:25 -08:00
|
|
|
int samples_per_channel_int = resampler_.Resample10Msec(
|
|
|
|
|
last_audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz,
|
2016-03-04 10:34:21 -08:00
|
|
|
audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
|
|
|
|
|
temp_output);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
if (samples_per_channel_int < 0) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::GetAudio - "
|
|
|
|
|
"Resampling last_audio_buffer_ failed.";
|
2014-10-21 06:54:23 +00:00
|
|
|
return -1;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
2014-10-21 06:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(henrik.lundin) Glitches in the output may appear if the output rate
|
|
|
|
|
// from NetEq changes. See WebRTC issue 3923.
|
|
|
|
|
if (need_resampling) {
|
2015-11-23 06:49:25 -08:00
|
|
|
int samples_per_channel_int = resampler_.Resample10Msec(
|
2016-03-04 10:34:21 -08:00
|
|
|
audio_frame->data_, current_sample_rate_hz, desired_freq_hz,
|
|
|
|
|
audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
|
|
|
|
|
audio_frame->data_);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
if (samples_per_channel_int < 0) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed.";
|
2014-10-21 06:54:23 +00:00
|
|
|
return -1;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
2016-03-04 10:34:21 -08:00
|
|
|
audio_frame->samples_per_channel_ =
|
|
|
|
|
static_cast<size_t>(samples_per_channel_int);
|
|
|
|
|
audio_frame->sample_rate_hz_ = desired_freq_hz;
|
|
|
|
|
RTC_DCHECK_EQ(
|
|
|
|
|
audio_frame->sample_rate_hz_,
|
|
|
|
|
rtc::checked_cast<int>(audio_frame->samples_per_channel_ * 100));
|
2014-10-21 06:54:23 +00:00
|
|
|
resampled_last_output_frame_ = true;
|
|
|
|
|
} else {
|
|
|
|
|
resampled_last_output_frame_ = false;
|
|
|
|
|
// We might end up here ONLY if codec is changed.
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 10:34:21 -08:00
|
|
|
// Store current audio in |last_audio_buffer_| for next time.
|
|
|
|
|
memcpy(last_audio_buffer_.get(), audio_frame->data_,
|
|
|
|
|
sizeof(int16_t) * audio_frame->samples_per_channel_ *
|
|
|
|
|
audio_frame->num_channels_);
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2013-12-13 19:17:43 +00:00
|
|
|
call_stats_.DecodedByNetEq(audio_frame->speech_type_);
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t AcmReceiver::AddCodec(int acm_codec_id,
|
|
|
|
|
uint8_t payload_type,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t channels,
|
2015-05-25 14:39:56 +02:00
|
|
|
int sample_rate_hz,
|
2015-12-09 06:20:58 -08:00
|
|
|
AudioDecoder* audio_decoder,
|
|
|
|
|
const std::string& name) {
|
2015-10-29 06:20:28 -07:00
|
|
|
const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder {
|
|
|
|
|
if (acm_codec_id == -1)
|
|
|
|
|
return NetEqDecoder::kDecoderArbitrary; // External decoder.
|
2015-11-10 22:34:18 +01:00
|
|
|
const rtc::Optional<RentACodec::CodecId> cid =
|
2015-10-29 06:20:28 -07:00
|
|
|
RentACodec::CodecIdFromIndex(acm_codec_id);
|
|
|
|
|
RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id;
|
2015-11-10 22:34:18 +01:00
|
|
|
const rtc::Optional<NetEqDecoder> ned =
|
2015-10-29 06:20:28 -07:00
|
|
|
RentACodec::NetEqDecoderFromCodecId(*cid, channels);
|
|
|
|
|
RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid);
|
|
|
|
|
return *ned;
|
|
|
|
|
}();
|
2014-03-23 09:58:48 +00:00
|
|
|
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
// The corresponding NetEq decoder ID.
|
2015-03-23 11:19:35 +00:00
|
|
|
// If this codec has been registered before.
|
2015-03-26 14:01:30 +01:00
|
|
|
auto it = decoders_.find(payload_type);
|
2015-03-23 11:19:35 +00:00
|
|
|
if (it != decoders_.end()) {
|
|
|
|
|
const Decoder& decoder = it->second;
|
2015-08-24 05:27:22 -07:00
|
|
|
if (acm_codec_id != -1 && decoder.acm_codec_id == acm_codec_id &&
|
|
|
|
|
decoder.channels == channels &&
|
2015-05-25 14:39:56 +02:00
|
|
|
decoder.sample_rate_hz == sample_rate_hz) {
|
2015-03-26 14:01:30 +01:00
|
|
|
// Re-registering the same codec. Do nothing and return.
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 05:27:22 -07:00
|
|
|
// Changing codec. First unregister the old codec, then register the new
|
|
|
|
|
// one.
|
2015-03-26 14:01:30 +01:00
|
|
|
if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type);
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-03-23 11:19:35 +00:00
|
|
|
|
|
|
|
|
decoders_.erase(it);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ret_val;
|
|
|
|
|
if (!audio_decoder) {
|
2015-12-09 06:20:58 -08:00
|
|
|
ret_val = neteq_->RegisterPayloadType(neteq_decoder, name, payload_type);
|
2013-09-12 18:30:26 +00:00
|
|
|
} else {
|
2015-12-09 06:20:58 -08:00
|
|
|
ret_val = neteq_->RegisterExternalDecoder(
|
2016-06-16 03:18:00 -07:00
|
|
|
audio_decoder, neteq_decoder, name, payload_type);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
if (ret_val != NetEq::kOK) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::AddCodec " << acm_codec_id
|
|
|
|
|
<< static_cast<int>(payload_type)
|
|
|
|
|
<< " channels: " << channels;
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 11:19:35 +00:00
|
|
|
Decoder decoder;
|
|
|
|
|
decoder.acm_codec_id = acm_codec_id;
|
|
|
|
|
decoder.payload_type = payload_type;
|
|
|
|
|
decoder.channels = channels;
|
2015-05-25 14:39:56 +02:00
|
|
|
decoder.sample_rate_hz = sample_rate_hz;
|
2015-03-26 14:01:30 +01:00
|
|
|
decoders_[payload_type] = decoder;
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AcmReceiver::FlushBuffers() {
|
|
|
|
|
neteq_->FlushBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 10:45:21 -07:00
|
|
|
void AcmReceiver::RemoveAllCodecs() {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2016-09-17 10:45:21 -07:00
|
|
|
neteq_->RemoveAllPayloadTypes();
|
|
|
|
|
decoders_.clear();
|
2016-09-17 08:40:13 -07:00
|
|
|
last_audio_decoder_ = rtc::Optional<CodecInst>();
|
2015-11-23 08:19:52 -08:00
|
|
|
last_packet_sample_rate_hz_ = rtc::Optional<int>();
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::RemoveCodec(uint8_t payload_type) {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2015-03-26 14:01:30 +01:00
|
|
|
auto it = decoders_.find(payload_type);
|
|
|
|
|
if (it == decoders_.end()) { // Such a payload-type is not registered.
|
2013-12-13 00:10:44 +00:00
|
|
|
return 0;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type);
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2016-09-17 08:40:13 -07:00
|
|
|
if (last_audio_decoder_ && payload_type == last_audio_decoder_->pltype) {
|
|
|
|
|
last_audio_decoder_ = rtc::Optional<CodecInst>();
|
2015-11-23 08:19:52 -08:00
|
|
|
last_packet_sample_rate_hz_ = rtc::Optional<int>();
|
|
|
|
|
}
|
2015-03-26 14:01:30 +01:00
|
|
|
decoders_.erase(it);
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 01:39:22 -07:00
|
|
|
rtc::Optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
|
|
|
|
|
return neteq_->GetPlayoutTimestamp();
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-22 15:39:53 -07:00
|
|
|
int AcmReceiver::FilteredCurrentDelayMs() const {
|
|
|
|
|
return neteq_->FilteredCurrentDelayMs();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 18:30:26 +00:00
|
|
|
int AcmReceiver::LastAudioCodec(CodecInst* codec) const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2015-03-26 14:01:30 +01:00
|
|
|
if (!last_audio_decoder_) {
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2016-09-17 08:40:13 -07:00
|
|
|
*codec = *last_audio_decoder_;
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 15:24:13 +00:00
|
|
|
void AcmReceiver::GetNetworkStatistics(NetworkStatistics* acm_stat) {
|
2013-09-12 18:30:26 +00:00
|
|
|
NetEqNetworkStatistics neteq_stat;
|
|
|
|
|
// NetEq function always returns zero, so we don't check the return value.
|
|
|
|
|
neteq_->NetworkStatistics(&neteq_stat);
|
|
|
|
|
|
|
|
|
|
acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms;
|
|
|
|
|
acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms;
|
2013-09-19 00:12:23 +00:00
|
|
|
acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false;
|
2013-09-12 18:30:26 +00:00
|
|
|
acm_stat->currentPacketLossRate = neteq_stat.packet_loss_rate;
|
|
|
|
|
acm_stat->currentDiscardRate = neteq_stat.packet_discard_rate;
|
|
|
|
|
acm_stat->currentExpandRate = neteq_stat.expand_rate;
|
2015-02-18 15:24:13 +00:00
|
|
|
acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate;
|
2013-09-12 18:30:26 +00:00
|
|
|
acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate;
|
|
|
|
|
acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate;
|
2015-02-18 15:24:13 +00:00
|
|
|
acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate;
|
2013-09-12 18:30:26 +00:00
|
|
|
acm_stat->clockDriftPPM = neteq_stat.clockdrift_ppm;
|
2014-04-22 10:11:21 +00:00
|
|
|
acm_stat->addedSamples = neteq_stat.added_zero_samples;
|
2015-08-25 13:08:04 +02:00
|
|
|
acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms;
|
|
|
|
|
acm_stat->medianWaitingTimeMs = neteq_stat.median_waiting_time_ms;
|
|
|
|
|
acm_stat->minWaitingTimeMs = neteq_stat.min_waiting_time_ms;
|
|
|
|
|
acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::DecoderByPayloadType(uint8_t payload_type,
|
|
|
|
|
CodecInst* codec) const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2015-03-26 14:01:30 +01:00
|
|
|
auto it = decoders_.find(payload_type);
|
|
|
|
|
if (it == decoders_.end()) {
|
2015-05-27 22:07:35 +02:00
|
|
|
LOG(LERROR) << "AcmReceiver::DecoderByPayloadType "
|
|
|
|
|
<< static_cast<int>(payload_type);
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-03-26 14:01:30 +01:00
|
|
|
const Decoder& decoder = it->second;
|
2015-11-03 12:38:27 -08:00
|
|
|
*codec = *RentACodec::CodecInstById(
|
|
|
|
|
*RentACodec::CodecIdFromIndex(decoder.acm_codec_id));
|
2015-03-23 11:19:35 +00:00
|
|
|
codec->pltype = decoder.payload_type;
|
|
|
|
|
codec->channels = decoder.channels;
|
2015-05-25 14:39:56 +02:00
|
|
|
codec->plfreq = decoder.sample_rate_hz;
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::EnableNack(size_t max_nack_list_size) {
|
2015-10-29 05:36:24 -07:00
|
|
|
neteq_->EnableNack(max_nack_list_size);
|
|
|
|
|
return 0;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AcmReceiver::DisableNack() {
|
2015-10-29 05:36:24 -07:00
|
|
|
neteq_->DisableNack();
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<uint16_t> AcmReceiver::GetNackList(
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t round_trip_time_ms) const {
|
2015-10-29 05:36:24 -07:00
|
|
|
return neteq_->GetNackList(round_trip_time_ms);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AcmReceiver::ResetInitialDelay() {
|
|
|
|
|
neteq_->SetMinimumDelay(0);
|
|
|
|
|
// TODO(turajs): Should NetEq Buffer be flushed?
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 08:40:13 -07:00
|
|
|
const rtc::Optional<CodecInst> AcmReceiver::RtpHeaderToDecoder(
|
2015-03-26 14:01:30 +01:00
|
|
|
const RTPHeader& rtp_header,
|
2015-11-11 10:34:00 -08:00
|
|
|
uint8_t payload_type) const {
|
2016-09-17 08:40:13 -07:00
|
|
|
const rtc::Optional<CodecInst> ci =
|
|
|
|
|
neteq_->GetDecoder(rtp_header.payloadType);
|
|
|
|
|
if (ci && STR_CASE_CMP(ci->plname, "red") == 0) {
|
|
|
|
|
// This is a RED packet. Get the payload of the audio codec.
|
|
|
|
|
return neteq_->GetDecoder(payload_type & 0x7f);
|
|
|
|
|
} else {
|
|
|
|
|
return ci;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const {
|
|
|
|
|
// Down-cast the time to (32-6)-bit since we only care about
|
|
|
|
|
// the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms.
|
|
|
|
|
// We masked 6 most significant bits of 32-bit so there is no overflow in
|
|
|
|
|
// the conversion from milliseconds to timestamp.
|
|
|
|
|
const uint32_t now_in_ms = static_cast<uint32_t>(
|
2014-04-22 08:18:42 +00:00
|
|
|
clock_->TimeInMilliseconds() & 0x03ffffff);
|
2013-09-12 18:30:26 +00:00
|
|
|
return static_cast<uint32_t>(
|
|
|
|
|
(decoder_sampling_rate / 1000) * now_in_ms);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 19:17:43 +00:00
|
|
|
void AcmReceiver::GetDecodingCallStatistics(
|
|
|
|
|
AudioDecodingCallStats* stats) const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2013-12-13 19:17:43 +00:00
|
|
|
*stats = call_stats_.GetDecodingStatistics();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 04:47:28 +00:00
|
|
|
} // namespace acm2
|
|
|
|
|
|
2013-09-12 18:30:26 +00:00
|
|
|
} // namespace webrtc
|