2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <assert.h> // assert
|
2013-02-05 15:12:39 +00:00
|
|
|
#include <math.h> // pow()
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <string.h> // memcpy()
|
2013-02-05 15:12:39 +00:00
|
|
|
|
2016-11-24 09:34:46 -08:00
|
|
|
#include "webrtc/common_types.h"
|
2015-10-28 16:39:33 +01:00
|
|
|
#include "webrtc/base/logging.h"
|
2015-10-20 23:00:48 -07:00
|
|
|
#include "webrtc/base/trace_event.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2013-08-15 23:38:54 +00:00
|
|
|
RTPReceiverStrategy* RTPReceiverStrategy::CreateAudioStrategy(
|
2016-03-30 02:42:32 -07:00
|
|
|
RtpData* data_callback) {
|
|
|
|
|
return new RTPReceiverAudio(data_callback);
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-30 02:42:32 -07:00
|
|
|
RTPReceiverAudio::RTPReceiverAudio(RtpData* data_callback)
|
2013-02-05 15:12:39 +00:00
|
|
|
: RTPReceiverStrategy(data_callback),
|
2016-09-22 03:36:27 -07:00
|
|
|
TelephoneEventHandler(),
|
|
|
|
|
telephone_event_forward_to_decoder_(false),
|
2013-02-05 15:12:39 +00:00
|
|
|
telephone_event_payload_type_(-1),
|
|
|
|
|
cng_nb_payload_type_(-1),
|
|
|
|
|
cng_wb_payload_type_(-1),
|
|
|
|
|
cng_swb_payload_type_(-1),
|
|
|
|
|
cng_fb_payload_type_(-1),
|
2013-08-15 23:38:54 +00:00
|
|
|
num_energy_(0),
|
2016-03-30 02:42:32 -07:00
|
|
|
current_remote_energy_() {
|
2012-12-18 15:40:53 +00:00
|
|
|
last_payload_.Audio.channels = 1;
|
2013-08-15 23:38:54 +00:00
|
|
|
memset(current_remote_energy_, 0, sizeof(current_remote_energy_));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 03:36:27 -07:00
|
|
|
// Outband TelephoneEvent(DTMF) detection
|
|
|
|
|
void RTPReceiverAudio::SetTelephoneEventForwardToDecoder(
|
|
|
|
|
bool forward_to_decoder) {
|
|
|
|
|
rtc::CritScope lock(&crit_sect_);
|
|
|
|
|
telephone_event_forward_to_decoder_ = forward_to_decoder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is forwarding of outband telephone events turned on/off?
|
|
|
|
|
bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const {
|
|
|
|
|
rtc::CritScope lock(&crit_sect_);
|
|
|
|
|
return telephone_event_forward_to_decoder_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
bool RTPReceiverAudio::TelephoneEventPayloadType(
|
2013-08-15 23:38:54 +00:00
|
|
|
int8_t payload_type) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2015-02-23 21:28:22 +00:00
|
|
|
return telephone_event_payload_type_ == payload_type;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
return payload_type == cng_nb_payload_type_ ||
|
|
|
|
|
payload_type == cng_wb_payload_type_ ||
|
|
|
|
|
payload_type == cng_swb_payload_type_ ||
|
|
|
|
|
payload_type == cng_fb_payload_type_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
bool RTPReceiverAudio::ShouldReportCsrcChanges(uint8_t payload_type) const {
|
2013-01-22 12:31:01 +00:00
|
|
|
// Don't do this for DTMF packets, otherwise it's fine.
|
|
|
|
|
return !TelephoneEventPayloadType(payload_type);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// - Sample based or frame based codecs based on RFC 3551
|
|
|
|
|
// -
|
|
|
|
|
// - NOTE! There is one error in the RFC, stating G.722 uses 8 bits/samples.
|
|
|
|
|
// - The correct rate is 4 bits/sample.
|
|
|
|
|
// -
|
|
|
|
|
// - name of sampling default
|
|
|
|
|
// - encoding sample/frame bits/sample rate ms/frame ms/packet
|
|
|
|
|
// -
|
|
|
|
|
// - Sample based audio codecs
|
|
|
|
|
// - DVI4 sample 4 var. 20
|
|
|
|
|
// - G722 sample 4 16,000 20
|
|
|
|
|
// - G726-40 sample 5 8,000 20
|
|
|
|
|
// - G726-32 sample 4 8,000 20
|
|
|
|
|
// - G726-24 sample 3 8,000 20
|
|
|
|
|
// - G726-16 sample 2 8,000 20
|
|
|
|
|
// - L8 sample 8 var. 20
|
|
|
|
|
// - L16 sample 16 var. 20
|
|
|
|
|
// - PCMA sample 8 var. 20
|
|
|
|
|
// - PCMU sample 8 var. 20
|
|
|
|
|
// -
|
|
|
|
|
// - Frame based audio codecs
|
|
|
|
|
// - G723 frame N/A 8,000 30 30
|
|
|
|
|
// - G728 frame N/A 8,000 2.5 20
|
|
|
|
|
// - G729 frame N/A 8,000 10 20
|
|
|
|
|
// - G729D frame N/A 8,000 10 20
|
|
|
|
|
// - G729E frame N/A 8,000 10 20
|
|
|
|
|
// - GSM frame N/A 8,000 20 20
|
|
|
|
|
// - GSM-EFR frame N/A 8,000 20 20
|
|
|
|
|
// - LPC frame N/A 8,000 20 20
|
|
|
|
|
// - MPA frame N/A var. var.
|
|
|
|
|
// -
|
|
|
|
|
// - G7221 frame N/A
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t RTPReceiverAudio::OnNewPayloadTypeCreated(
|
2016-11-24 09:34:46 -08:00
|
|
|
const CodecInst& audio_codec) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2012-12-13 10:48:24 +00:00
|
|
|
|
2016-11-24 09:34:46 -08:00
|
|
|
if (RtpUtility::StringCompare(audio_codec.plname, "telephone-event", 15)) {
|
|
|
|
|
telephone_event_payload_type_ = audio_codec.pltype;
|
2012-01-24 17:16:59 +00:00
|
|
|
}
|
2016-11-24 09:34:46 -08:00
|
|
|
if (RtpUtility::StringCompare(audio_codec.plname, "cn", 2)) {
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
// We support comfort noise at four different frequencies.
|
2016-11-24 09:34:46 -08:00
|
|
|
if (audio_codec.plfreq == 8000) {
|
|
|
|
|
cng_nb_payload_type_ = audio_codec.pltype;
|
|
|
|
|
} else if (audio_codec.plfreq == 16000) {
|
|
|
|
|
cng_wb_payload_type_ = audio_codec.pltype;
|
|
|
|
|
} else if (audio_codec.plfreq == 32000) {
|
|
|
|
|
cng_swb_payload_type_ = audio_codec.pltype;
|
|
|
|
|
} else if (audio_codec.plfreq == 48000) {
|
|
|
|
|
cng_fb_payload_type_ = audio_codec.pltype;
|
2012-01-24 17:16:59 +00:00
|
|
|
} else {
|
|
|
|
|
assert(false);
|
2013-02-04 13:23:07 +00:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-24 17:16:59 +00:00
|
|
|
}
|
2013-02-04 13:23:07 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
int32_t RTPReceiverAudio::ParseRtpPacket(WebRtcRTPHeader* rtp_header,
|
|
|
|
|
const PayloadUnion& specific_payload,
|
|
|
|
|
bool is_red,
|
2013-09-06 13:40:11 +00:00
|
|
|
const uint8_t* payload,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t payload_length,
|
2013-08-15 23:38:54 +00:00
|
|
|
int64_t timestamp_ms,
|
|
|
|
|
bool is_first_packet) {
|
2015-02-16 12:06:00 +00:00
|
|
|
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "Audio::ParseRtp",
|
|
|
|
|
"seqnum", rtp_header->header.sequenceNumber, "timestamp",
|
|
|
|
|
rtp_header->header.timestamp);
|
2013-05-29 12:12:51 +00:00
|
|
|
rtp_header->type.Audio.numEnergy = rtp_header->header.numCSRCs;
|
2013-08-15 23:38:54 +00:00
|
|
|
num_energy_ = rtp_header->type.Audio.numEnergy;
|
|
|
|
|
if (rtp_header->type.Audio.numEnergy > 0 &&
|
|
|
|
|
rtp_header->type.Audio.numEnergy <= kRtpCsrcSize) {
|
|
|
|
|
memcpy(current_remote_energy_,
|
|
|
|
|
rtp_header->type.Audio.arrOfEnergy,
|
|
|
|
|
rtp_header->type.Audio.numEnergy);
|
|
|
|
|
}
|
2013-02-05 15:12:39 +00:00
|
|
|
|
2016-04-07 15:36:45 -07:00
|
|
|
if (first_packet_received_()) {
|
|
|
|
|
LOG(LS_INFO) << "Received first audio RTP packet";
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
return ParseAudioCodecSpecific(rtp_header,
|
2013-09-06 13:40:11 +00:00
|
|
|
payload,
|
2013-09-26 15:21:26 +00:00
|
|
|
payload_length,
|
2013-02-05 15:12:39 +00:00
|
|
|
specific_payload.Audio,
|
|
|
|
|
is_red);
|
2012-12-18 15:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTPAliveType RTPReceiverAudio::ProcessDeadOrAlive(
|
2013-04-08 11:08:41 +00:00
|
|
|
uint16_t last_payload_length) const {
|
2013-02-05 15:12:39 +00:00
|
|
|
|
|
|
|
|
// Our CNG is 9 bytes; if it's a likely CNG the receiver needs to check
|
|
|
|
|
// kRtpNoRtp against NetEq speech_type kOutputPLCtoCNG.
|
|
|
|
|
if (last_payload_length < 10) { // our CNG is 9 bytes
|
|
|
|
|
return kRtpNoRtp;
|
|
|
|
|
} else {
|
|
|
|
|
return kRtpDead;
|
|
|
|
|
}
|
2012-12-18 15:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
void RTPReceiverAudio::CheckPayloadChanged(int8_t payload_type,
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
PayloadUnion* /* specific_payload */,
|
2013-08-15 23:38:54 +00:00
|
|
|
bool* should_discard_changes) {
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
*should_discard_changes =
|
|
|
|
|
TelephoneEventPayloadType(payload_type) || CNGPayloadType(payload_type);
|
2012-12-18 15:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
int RTPReceiverAudio::Energy(uint8_t array_of_energy[kRtpCsrcSize]) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_sect_);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
assert(num_energy_ <= kRtpCsrcSize);
|
|
|
|
|
|
|
|
|
|
if (num_energy_ > 0) {
|
|
|
|
|
memcpy(array_of_energy, current_remote_energy_,
|
|
|
|
|
sizeof(uint8_t) * num_energy_);
|
|
|
|
|
}
|
|
|
|
|
return num_energy_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t RTPReceiverAudio::InvokeOnInitializeDecoder(
|
2013-02-05 15:12:39 +00:00
|
|
|
RtpFeedback* callback,
|
2013-08-15 23:38:54 +00:00
|
|
|
int8_t payload_type,
|
2013-02-05 15:12:39 +00:00
|
|
|
const char payload_name[RTP_PAYLOAD_NAME_SIZE],
|
2013-08-15 23:38:54 +00:00
|
|
|
const PayloadUnion& specific_payload) const {
|
2015-09-17 23:03:57 +02:00
|
|
|
if (-1 ==
|
|
|
|
|
callback->OnInitializeDecoder(
|
|
|
|
|
payload_type, payload_name, specific_payload.Audio.frequency,
|
|
|
|
|
specific_payload.Audio.channels, specific_payload.Audio.rate)) {
|
2014-04-08 11:06:12 +00:00
|
|
|
LOG(LS_ERROR) << "Failed to create decoder for payload type: "
|
2015-01-30 19:53:42 +00:00
|
|
|
<< payload_name << "/" << static_cast<int>(payload_type);
|
2012-12-18 15:40:53 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// We are not allowed to have any critsects when calling data_callback.
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t RTPReceiverAudio::ParseAudioCodecSpecific(
|
2013-02-05 15:12:39 +00:00
|
|
|
WebRtcRTPHeader* rtp_header,
|
2013-04-08 11:08:41 +00:00
|
|
|
const uint8_t* payload_data,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t payload_length,
|
2013-08-15 23:38:54 +00:00
|
|
|
const AudioPayload& audio_specific,
|
|
|
|
|
bool is_red) {
|
2013-02-05 15:12:39 +00:00
|
|
|
|
|
|
|
|
if (payload_length == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
bool telephone_event_packet =
|
|
|
|
|
TelephoneEventPayloadType(rtp_header->header.payloadType);
|
|
|
|
|
if (telephone_event_packet) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2013-02-05 15:12:39 +00:00
|
|
|
|
|
|
|
|
// RFC 4733 2.3
|
|
|
|
|
// 0 1 2 3
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | event |E|R| volume | duration |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
//
|
|
|
|
|
if (payload_length % 4 != 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t number_of_events = payload_length / 4;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// sanity
|
|
|
|
|
if (number_of_events >= MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS) {
|
|
|
|
|
number_of_events = MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS;
|
|
|
|
|
}
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
for (size_t n = 0; n < number_of_events; ++n) {
|
2013-02-05 15:12:39 +00:00
|
|
|
bool end = (payload_data[(4 * n) + 1] & 0x80) ? true : false;
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::set<uint8_t>::iterator event =
|
2013-02-05 15:12:39 +00:00
|
|
|
telephone_event_reported_.find(payload_data[4 * n]);
|
|
|
|
|
|
|
|
|
|
if (event != telephone_event_reported_.end()) {
|
|
|
|
|
// we have already seen this event
|
|
|
|
|
if (end) {
|
|
|
|
|
telephone_event_reported_.erase(payload_data[4 * n]);
|
2012-12-13 10:48:24 +00:00
|
|
|
}
|
2013-02-05 15:12:39 +00:00
|
|
|
} else {
|
|
|
|
|
if (end) {
|
|
|
|
|
// don't add if it's a end of a tone
|
|
|
|
|
} else {
|
|
|
|
|
telephone_event_reported_.insert(payload_data[4 * n]);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-02-05 15:12:39 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// RFC 4733 2.5.1.3 & 2.5.2.3 Long-Duration Events
|
|
|
|
|
// should not be a problem since we don't care about the duration
|
2012-12-13 10:48:24 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// RFC 4733 See 2.5.1.5. & 2.5.2.4. Multiple Events in a Packet
|
|
|
|
|
}
|
2012-12-13 10:48:24 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2012-12-13 10:48:24 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// Check if this is a CNG packet, receiver might want to know
|
RTPReceiverAudio: Removed frequency from CNGPayloadType and cleaned up
CheckPayloadChanged.
Removed last_received_frequency_, cng_payload_type_,
g722_payload_type_ and last_received_g722_ from RTPReceiverAudio and
cleaned up most of the related, now dead code.
Since g722_payload_type_ was never set, neither was
last_received_g722_, which means the frequency change in
CNGPayloadType was never done. Setting the frequency to the standard
values also proved unnecessary, since they were already set before the
call. Even if frequency would have been changed by RTPReceiverAudio, I
was not able to find a place where that would actually have
mattered. The ACM and NetEq, for example, which eventually gets these
packages, don't care about that value.
Also, GetPayloadTypeFrequency was never called, so keeping track of
last_received_frequency_ proved unnecessary.
cng_payload_type_ was stored to be able to check in CNGPayloadType if
cng_payload_type_has_changed. This flag was also never read, so these
all disappear.
The main reason for starting this change was to root out any G722
specific code we have sprinkled around the code base (specifically
dealing with the fact that for G722 clock rate != sample rate). In
this case, once I started pulling at one end of the string, the whole
thing came unraveled.
BUG=webrtc:5805
Review-Url: https://codereview.webrtc.org/2383103002
Cr-Commit-Position: refs/heads/master@{#14530}
2016-10-05 08:44:22 -07:00
|
|
|
if (CNGPayloadType(rtp_header->header.payloadType)) {
|
2013-02-05 15:12:39 +00:00
|
|
|
rtp_header->type.Audio.isCNG = true;
|
|
|
|
|
rtp_header->frameType = kAudioFrameCN;
|
|
|
|
|
} else {
|
|
|
|
|
rtp_header->frameType = kAudioFrameSpeech;
|
|
|
|
|
rtp_header->type.Audio.isCNG = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if it's a DTMF event, hence something we can playout
|
|
|
|
|
if (telephone_event_packet) {
|
2016-09-22 03:36:27 -07:00
|
|
|
if (!telephone_event_forward_to_decoder_) {
|
|
|
|
|
// don't forward event to decoder
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-04-08 11:08:41 +00:00
|
|
|
std::set<uint8_t>::iterator first =
|
2013-02-05 15:12:39 +00:00
|
|
|
telephone_event_reported_.begin();
|
|
|
|
|
if (first != telephone_event_reported_.end() && *first > 15) {
|
|
|
|
|
// don't forward non DTMF events
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-02-05 15:12:39 +00:00
|
|
|
}
|
2013-09-06 13:40:11 +00:00
|
|
|
// TODO(holmer): Break this out to have RED parsing handled generically.
|
2013-02-05 15:12:39 +00:00
|
|
|
if (is_red && !(payload_data[0] & 0x80)) {
|
|
|
|
|
// we recive only one frame packed in a RED packet remove the RED wrapper
|
|
|
|
|
rtp_header->header.payloadType = payload_data[0];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-02-05 15:12:39 +00:00
|
|
|
// only one frame in the RED strip the one byte to help NetEq
|
2013-01-14 10:01:55 +00:00
|
|
|
return data_callback_->OnReceivedPayloadData(
|
2013-02-05 15:12:39 +00:00
|
|
|
payload_data + 1, payload_length - 1, rtp_header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtp_header->type.Audio.channel = audio_specific.channels;
|
|
|
|
|
return data_callback_->OnReceivedPayloadData(
|
|
|
|
|
payload_data, payload_length, rtp_header);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-02-05 15:12:39 +00:00
|
|
|
} // namespace webrtc
|