| OLD | NEW |
| 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 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 if (!(numerator_ == 1 && denominator_ == 1)) { | 71 if (!(numerator_ == 1 && denominator_ == 1)) { |
| 72 // We have a scale factor != 1. | 72 // We have a scale factor != 1. |
| 73 if (!first_packet_received_) { | 73 if (!first_packet_received_) { |
| 74 external_ref_ = external_timestamp; | 74 external_ref_ = external_timestamp; |
| 75 internal_ref_ = external_timestamp; | 75 internal_ref_ = external_timestamp; |
| 76 first_packet_received_ = true; | 76 first_packet_received_ = true; |
| 77 } | 77 } |
| 78 int32_t external_diff = external_timestamp - external_ref_; | 78 int64_t external_diff = external_timestamp - external_ref_; |
| 79 assert(denominator_ > 0); // Should not be possible. | 79 assert(denominator_ > 0); // Should not be possible. |
| 80 external_ref_ = external_timestamp; | 80 external_ref_ = external_timestamp; |
| 81 internal_ref_ += (external_diff * numerator_) / denominator_; | 81 internal_ref_ += (external_diff * numerator_) / denominator_; |
| 82 return internal_ref_; | 82 return internal_ref_; |
| 83 } else { | 83 } else { |
| 84 // No scaling. | 84 // No scaling. |
| 85 return external_timestamp; | 85 return external_timestamp; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 | 89 |
| 90 uint32_t TimestampScaler::ToExternal(uint32_t internal_timestamp) const { | 90 uint32_t TimestampScaler::ToExternal(uint32_t internal_timestamp) const { |
| 91 if (!first_packet_received_ || (numerator_ == 1 && denominator_ == 1)) { | 91 if (!first_packet_received_ || (numerator_ == 1 && denominator_ == 1)) { |
| 92 // Not initialized, or scale factor is 1. | 92 // Not initialized, or scale factor is 1. |
| 93 return internal_timestamp; | 93 return internal_timestamp; |
| 94 } else { | 94 } else { |
| 95 int32_t internal_diff = internal_timestamp - internal_ref_; | 95 int64_t internal_diff = internal_timestamp - internal_ref_; |
| 96 assert(numerator_ > 0); // Should not be possible. | 96 assert(numerator_ > 0); // Should not be possible. |
| 97 // Do not update references in this method. | 97 // Do not update references in this method. |
| 98 // Switch |denominator_| and |numerator_| to convert the other way. | 98 // Switch |denominator_| and |numerator_| to convert the other way. |
| 99 return external_ref_ + (internal_diff * denominator_) / numerator_; | 99 return external_ref_ + (internal_diff * denominator_) / numerator_; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace webrtc | 103 } // namespace webrtc |
| OLD | NEW |