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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/acm2/acm_receiver.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <cstdint>
|
2013-09-12 18:30:26 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-10-22 09:48:08 +02:00
|
|
|
#include "absl/strings/match.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "api/audio/audio_frame.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/audio_codecs/audio_decoder.h"
|
|
|
|
|
#include "modules/audio_coding/acm2/acm_resampler.h"
|
|
|
|
|
#include "modules/audio_coding/acm2/call_statistics.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/include/neteq.h"
|
2018-04-12 22:44:09 +02:00
|
|
|
#include "modules/include/module_common_types.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2017-11-22 10:42:26 +01:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
2018-04-03 13:40:05 +02:00
|
|
|
#include "rtc_base/strings/audio_format_to_string.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/clock.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-20 03:07:46 -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) {
|
2017-06-08 09:03:55 +02:00
|
|
|
RTC_DCHECK(clock_);
|
2018-05-07 13:47:28 +02:00
|
|
|
memset(last_audio_buffer_.get(), 0,
|
|
|
|
|
sizeof(int16_t) * AudioFrame::kMaxDataSizeSamples);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-06-14 14:13:02 +02:00
|
|
|
AcmReceiver::~AcmReceiver() = default;
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
int AcmReceiver::SetMinimumDelay(int delay_ms) {
|
|
|
|
|
if (neteq_->SetMinimumDelay(delay_ms))
|
|
|
|
|
return 0;
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_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;
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
|
2013-09-12 18:30:26 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 13:49:26 +01:00
|
|
|
bool AcmReceiver::SetBaseMinimumDelayMs(int delay_ms) {
|
|
|
|
|
return neteq_->SetBaseMinimumDelayMs(delay_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AcmReceiver::GetBaseMinimumDelayMs() const {
|
|
|
|
|
return neteq_->GetBaseMinimumDelayMs();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
if (!last_decoder_) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return last_decoder_->second.clockrate_hz;
|
2015-11-23 08:19:52 -08:00
|
|
|
}
|
|
|
|
|
|
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) {
|
Handle padded audio packets correctly
RTP packets can be padded with extra data at the end of the payload. The usable
payload length of the packet should then be reduced with the padding length,
since the padding must be discarded. This was not the case; instead, the entire
payload, including padding data, was forwarded to the audio channel and in the
end to the decoder.
A special case of padding is packets which are empty except for the padding.
That is, they carry no usable payload. These packets are sometimes used for
probing the network and were discarded in
RTPReceiverAudio::ParseAudioCodecSpecific. The result is that NetEq never sees
those empty packets, just the holes in the sequence number series; this can
throw off the target buffer calculations.
With this change, the empty (after removing the padding) packets are let through,
all the way down to NetEq, to a new method called NetEq::InsertEmptyPacket. This
method notifies the DelayManager that an empty packet was received.
BUG=webrtc:7610, webrtc:7625
Review-Url: https://codereview.webrtc.org/2870043003
Cr-Commit-Position: refs/heads/master@{#18083}
2017-05-10 07:38:01 -07:00
|
|
|
if (incoming_payload.empty()) {
|
|
|
|
|
neteq_->InsertEmptyPacket(rtp_header.header);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
const RTPHeader& header = rtp_header.header; // Just a shorthand.
|
|
|
|
|
int payload_type = header.payloadType;
|
|
|
|
|
auto format = neteq_->GetDecoderFormat(payload_type);
|
|
|
|
|
if (format && absl::EqualsIgnoreCase(format->name, "red")) {
|
|
|
|
|
// This is a RED packet. Get the format of the audio codec.
|
|
|
|
|
payload_type = incoming_payload[0] & 0x7f;
|
|
|
|
|
format = neteq_->GetDecoderFormat(payload_type);
|
|
|
|
|
}
|
|
|
|
|
if (!format) {
|
|
|
|
|
RTC_LOG_F(LS_ERROR) << "Payload-type "
|
|
|
|
|
<< payload_type
|
|
|
|
|
<< " is not registered.";
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 18:30:26 +00:00
|
|
|
{
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
if (absl::EqualsIgnoreCase(format->name, "cn")) {
|
|
|
|
|
if (last_decoder_ && last_decoder_->second.num_channels > 1) {
|
2016-09-20 03:07:46 -07:00
|
|
|
// 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-20 03:07:46 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
RTC_DCHECK(format);
|
|
|
|
|
last_decoder_ = std::make_pair(payload_type, *format);
|
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
|
|
|
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
uint32_t receive_timestamp = NowInTimestamp(format->clockrate_hz);
|
|
|
|
|
if (neteq_->InsertPacket(header, incoming_payload, receive_timestamp) < 0) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LERROR) << "AcmReceiver::InsertPacket "
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
<< static_cast<int>(header.payloadType)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< " 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) {
|
2016-09-20 01:47:12 -07:00
|
|
|
RTC_DCHECK(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) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_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) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_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) {
|
2017-06-12 12:45:32 -07:00
|
|
|
// TODO(yujo): handle this more efficiently for muted frames.
|
2015-11-23 06:49:25 -08:00
|
|
|
int samples_per_channel_int = resampler_.Resample10Msec(
|
2017-06-12 12:45:32 -07:00
|
|
|
audio_frame->data(), current_sample_rate_hz, desired_freq_hz,
|
2016-03-04 10:34:21 -08:00
|
|
|
audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
|
2017-06-12 12:45:32 -07:00
|
|
|
audio_frame->mutable_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) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_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_,
|
2017-03-01 18:52:48 -08:00
|
|
|
rtc::dchecked_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.
|
2017-06-12 12:45:32 -07:00
|
|
|
memcpy(last_audio_buffer_.get(), audio_frame->data(),
|
2016-03-04 10:34:21 -08:00
|
|
|
sizeof(int16_t) * audio_frame->samples_per_channel_ *
|
|
|
|
|
audio_frame->num_channels_);
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2016-09-20 01:47:12 -07:00
|
|
|
call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted);
|
2013-09-12 18:30:26 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 07:15:49 -07:00
|
|
|
void AcmReceiver::SetCodecs(const std::map<int, SdpAudioFormat>& codecs) {
|
|
|
|
|
neteq_->SetCodecs(codecs);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 18:30:26 +00:00
|
|
|
void AcmReceiver::FlushBuffers() {
|
|
|
|
|
neteq_->FlushBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-20 04:02:25 -07:00
|
|
|
void AcmReceiver::RemoveAllCodecs() {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2016-09-20 04:02:25 -07:00
|
|
|
neteq_->RemoveAllPayloadTypes();
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
last_decoder_ = absl::nullopt;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
|
2016-04-06 01:39:22 -07:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 09:14:04 +01:00
|
|
|
int AcmReceiver::TargetDelayMs() const {
|
|
|
|
|
return neteq_->TargetDelayMs();
|
|
|
|
|
}
|
|
|
|
|
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
absl::optional<std::pair<int, SdpAudioFormat>>
|
|
|
|
|
AcmReceiver::LastDecoder() const {
|
2016-01-20 13:39:36 +01:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
if (!last_decoder_) {
|
|
|
|
|
return absl::nullopt;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
RTC_DCHECK_NE(-1, last_decoder_->first); // Payload type should be valid.
|
|
|
|
|
return last_decoder_;
|
2016-10-12 11:04:10 -07:00
|
|
|
}
|
|
|
|
|
|
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->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;
|
2017-08-23 15:59:38 +02:00
|
|
|
acm_stat->currentSecondaryDiscardedRate = neteq_stat.secondary_discarded_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;
|
2017-08-24 17:15:13 -07:00
|
|
|
|
|
|
|
|
NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics();
|
|
|
|
|
acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received;
|
|
|
|
|
acm_stat->concealedSamples = neteq_lifetime_stat.concealed_samples;
|
2017-09-18 09:28:20 +02:00
|
|
|
acm_stat->concealmentEvents = neteq_lifetime_stat.concealment_events;
|
2017-10-02 12:00:34 +02:00
|
|
|
acm_stat->jitterBufferDelayMs = neteq_lifetime_stat.jitter_buffer_delay_ms;
|
2019-01-15 15:46:29 +01:00
|
|
|
acm_stat->jitterBufferEmittedCount =
|
|
|
|
|
neteq_lifetime_stat.jitter_buffer_emitted_count;
|
2018-11-27 12:52:16 +01:00
|
|
|
acm_stat->delayedPacketOutageSamples =
|
|
|
|
|
neteq_lifetime_stat.delayed_packet_outage_samples;
|
2018-11-22 17:21:10 +01:00
|
|
|
|
|
|
|
|
NetEqOperationsAndState neteq_operations_and_state =
|
|
|
|
|
neteq_->GetOperationsAndState();
|
|
|
|
|
acm_stat->packetBufferFlushes =
|
|
|
|
|
neteq_operations_and_state.packet_buffer_flushes;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 =
|
2014-04-22 08:18:42 +00:00
|
|
|
static_cast<uint32_t>(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
|