Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: webrtc/modules/audio_coding/neteq/timestamp_scaler.cc

Issue 2270063006: TimestampScaler no longer depends on NetEqDecoder to figure out scaling. (Closed)
Patch Set: Make sure the diffs are calculated properly as signed. Also use auto. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" 11 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h"
12 12
13 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" 13 #include "webrtc/modules/audio_coding/neteq/decoder_database.h"
14 #include "webrtc/modules/audio_coding/neteq/defines.h"
15 #include "webrtc/system_wrappers/include/logging.h" 14 #include "webrtc/system_wrappers/include/logging.h"
16 15
17 namespace webrtc { 16 namespace webrtc {
18 17
19 void TimestampScaler::Reset() { 18 void TimestampScaler::Reset() {
20 first_packet_received_ = false; 19 first_packet_received_ = false;
21 } 20 }
22 21
23 void TimestampScaler::ToInternal(Packet* packet) { 22 void TimestampScaler::ToInternal(Packet* packet) {
24 if (!packet) { 23 if (!packet) {
(...skipping 11 matching lines...) Expand all
36 } 35 }
37 36
38 uint32_t TimestampScaler::ToInternal(uint32_t external_timestamp, 37 uint32_t TimestampScaler::ToInternal(uint32_t external_timestamp,
39 uint8_t rtp_payload_type) { 38 uint8_t rtp_payload_type) {
40 const DecoderDatabase::DecoderInfo* info = 39 const DecoderDatabase::DecoderInfo* info =
41 decoder_database_.GetDecoderInfo(rtp_payload_type); 40 decoder_database_.GetDecoderInfo(rtp_payload_type);
42 if (!info) { 41 if (!info) {
43 // Payload type is unknown. Do not scale. 42 // Payload type is unknown. Do not scale.
44 return external_timestamp; 43 return external_timestamp;
45 } 44 }
46 switch (info->codec_type) { 45 if (!(info->IsComfortNoise() || info->IsDtmf())) {
47 case NetEqDecoder::kDecoderG722: 46 // Do not change the timestamp scaling settings for DTMF or CNG.
48 case NetEqDecoder::kDecoderG722_2ch: { 47 numerator_ = info->SampleRateHz();
49 // Use timestamp scaling with factor 2 (two output samples per RTP 48 if (info->codec_type == NetEqDecoder::kDecoderArbitrary) {
50 // timestamp). 49 // We have no format mapping for "arbitrary" external codecs, so we cannot
51 numerator_ = 2; 50 // support timestamp scaling of them.
52 denominator_ = 1; 51 denominator_ = numerator_;
53 break; 52 } else {
54 } 53 denominator_ = info->GetFormat().clockrate_hz;
55 case NetEqDecoder::kDecoderAVT:
56 case NetEqDecoder::kDecoderCNGnb:
57 case NetEqDecoder::kDecoderCNGwb:
58 case NetEqDecoder::kDecoderCNGswb32kHz:
59 case NetEqDecoder::kDecoderCNGswb48kHz: {
60 // Do not change the timestamp scaling settings for DTMF or CNG.
61 break;
62 }
63 default: {
64 // Do not use timestamp scaling for any other codec.
65 numerator_ = 1;
66 denominator_ = 1;
67 break;
68 } 54 }
69 } 55 }
70 56 if (numerator_ != denominator_) {
71 if (!(numerator_ == 1 && denominator_ == 1)) {
72 // We have a scale factor != 1. 57 // We have a scale factor != 1.
73 if (!first_packet_received_) { 58 if (!first_packet_received_) {
74 external_ref_ = external_timestamp; 59 external_ref_ = external_timestamp;
75 internal_ref_ = external_timestamp; 60 internal_ref_ = external_timestamp;
76 first_packet_received_ = true; 61 first_packet_received_ = true;
77 } 62 }
78 int64_t external_diff = external_timestamp - external_ref_; 63 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.
79 assert(denominator_ > 0); // Should not be possible. 64 assert(denominator_ > 0); // Should not be possible.
80 external_ref_ = external_timestamp; 65 external_ref_ = external_timestamp;
81 internal_ref_ += (external_diff * numerator_) / denominator_; 66 internal_ref_ += (external_diff * numerator_) / denominator_;
82 return internal_ref_; 67 return internal_ref_;
83 } else { 68 } else {
84 // No scaling. 69 // No scaling.
85 return external_timestamp; 70 return external_timestamp;
86 } 71 }
87 } 72 }
88 73
89 74
90 uint32_t TimestampScaler::ToExternal(uint32_t internal_timestamp) const { 75 uint32_t TimestampScaler::ToExternal(uint32_t internal_timestamp) const {
91 if (!first_packet_received_ || (numerator_ == 1 && denominator_ == 1)) { 76 if (!first_packet_received_ || (numerator_ == denominator_)) {
92 // Not initialized, or scale factor is 1. 77 // Not initialized, or scale factor is 1.
93 return internal_timestamp; 78 return internal_timestamp;
94 } else { 79 } else {
95 int64_t internal_diff = internal_timestamp - internal_ref_; 80 int64_t internal_diff = int64_t{internal_timestamp} - internal_ref_;
96 assert(numerator_ > 0); // Should not be possible. 81 assert(numerator_ > 0); // Should not be possible.
97 // Do not update references in this method. 82 // Do not update references in this method.
98 // Switch |denominator_| and |numerator_| to convert the other way. 83 // Switch |denominator_| and |numerator_| to convert the other way.
99 return external_ref_ + (internal_diff * denominator_) / numerator_; 84 return external_ref_ + (internal_diff * denominator_) / numerator_;
100 } 85 }
101 } 86 }
102 87
103 } // namespace webrtc 88 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698