Chromium Code Reviews| Index: webrtc/modules/audio_coding/neteq/timestamp_scaler.cc |
| diff --git a/webrtc/modules/audio_coding/neteq/timestamp_scaler.cc b/webrtc/modules/audio_coding/neteq/timestamp_scaler.cc |
| index b228e017b2a30ffbcd70364d9d48d97e2b8d29f6..5d13bf9e1c66b307622363ab65019b8f997f4a9c 100644 |
| --- a/webrtc/modules/audio_coding/neteq/timestamp_scaler.cc |
| +++ b/webrtc/modules/audio_coding/neteq/timestamp_scaler.cc |
| @@ -11,7 +11,6 @@ |
| #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" |
| #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
| -#include "webrtc/modules/audio_coding/neteq/defines.h" |
| #include "webrtc/system_wrappers/include/logging.h" |
| namespace webrtc { |
| @@ -43,39 +42,25 @@ uint32_t TimestampScaler::ToInternal(uint32_t external_timestamp, |
| // Payload type is unknown. Do not scale. |
| return external_timestamp; |
| } |
| - switch (info->codec_type) { |
| - case NetEqDecoder::kDecoderG722: |
| - case NetEqDecoder::kDecoderG722_2ch: { |
| - // Use timestamp scaling with factor 2 (two output samples per RTP |
| - // timestamp). |
| - numerator_ = 2; |
| - denominator_ = 1; |
| - break; |
| - } |
| - case NetEqDecoder::kDecoderAVT: |
| - case NetEqDecoder::kDecoderCNGnb: |
| - case NetEqDecoder::kDecoderCNGwb: |
| - case NetEqDecoder::kDecoderCNGswb32kHz: |
| - case NetEqDecoder::kDecoderCNGswb48kHz: { |
| - // Do not change the timestamp scaling settings for DTMF or CNG. |
| - break; |
| - } |
| - default: { |
| - // Do not use timestamp scaling for any other codec. |
| - numerator_ = 1; |
| - denominator_ = 1; |
| - break; |
| + if (!(info->IsComfortNoise() || info->IsDtmf())) { |
| + // Do not change the timestamp scaling settings for DTMF or CNG. |
| + numerator_ = info->SampleRateHz(); |
| + if (info->codec_type == NetEqDecoder::kDecoderArbitrary) { |
| + // We have no format mapping for "arbitrary" external codecs, so we cannot |
| + // support timestamp scaling of them. |
| + denominator_ = numerator_; |
| + } else { |
| + denominator_ = info->GetFormat().clockrate_hz; |
| } |
| } |
| - |
| - if (!(numerator_ == 1 && denominator_ == 1)) { |
| + if (numerator_ != denominator_) { |
| // We have a scale factor != 1. |
| if (!first_packet_received_) { |
| external_ref_ = external_timestamp; |
| internal_ref_ = external_timestamp; |
| first_packet_received_ = true; |
| } |
| - int64_t external_diff = external_timestamp - external_ref_; |
| + int64_t external_diff = int64_t{external_timestamp} - external_ref_; |
|
ossu
2016/08/26 11:20:51
These lines did unsigned 32 bit subtractions and p
kwiberg-webrtc
2016/08/26 11:40:57
Acknowledged.
Consider making it const too.
ossu
2016/08/26 11:47:31
Acknowledged.
|
| assert(denominator_ > 0); // Should not be possible. |
| external_ref_ = external_timestamp; |
| internal_ref_ += (external_diff * numerator_) / denominator_; |
| @@ -88,11 +73,11 @@ uint32_t TimestampScaler::ToInternal(uint32_t external_timestamp, |
| uint32_t TimestampScaler::ToExternal(uint32_t internal_timestamp) const { |
| - if (!first_packet_received_ || (numerator_ == 1 && denominator_ == 1)) { |
| + if (!first_packet_received_ || (numerator_ == denominator_)) { |
| // Not initialized, or scale factor is 1. |
| return internal_timestamp; |
| } else { |
| - int64_t internal_diff = internal_timestamp - internal_ref_; |
| + int64_t internal_diff = int64_t{internal_timestamp} - internal_ref_; |
| assert(numerator_ > 0); // Should not be possible. |
| // Do not update references in this method. |
| // Switch |denominator_| and |numerator_| to convert the other way. |