henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 14 | #include "modules/audio_coding/neteq/packet.h" |
| 15 | #include "rtc_base/constructormagic.h" |
| 16 | #include "typedefs.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Forward declaration. |
| 21 | class DecoderDatabase; |
| 22 | |
| 23 | // This class scales timestamps for codecs that need timestamp scaling. |
| 24 | // This is done for codecs where one RTP timestamp does not correspond to |
| 25 | // one sample. |
| 26 | class TimestampScaler { |
| 27 | public: |
| 28 | explicit TimestampScaler(const DecoderDatabase& decoder_database) |
| 29 | : first_packet_received_(false), |
| 30 | numerator_(1), |
| 31 | denominator_(1), |
| 32 | external_ref_(0), |
| 33 | internal_ref_(0), |
| 34 | decoder_database_(decoder_database) {} |
| 35 | |
| 36 | virtual ~TimestampScaler() {} |
| 37 | |
| 38 | // Start over. |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 39 | virtual void Reset(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 40 | |
| 41 | // Scale the timestamp in |packet| from external to internal. |
| 42 | virtual void ToInternal(Packet* packet); |
| 43 | |
| 44 | // Scale the timestamp for all packets in |packet_list| from external to |
| 45 | // internal. |
| 46 | virtual void ToInternal(PacketList* packet_list); |
| 47 | |
| 48 | // Returns the internal equivalent of |external_timestamp|, given the |
| 49 | // RTP payload type |rtp_payload_type|. |
| 50 | virtual uint32_t ToInternal(uint32_t external_timestamp, |
| 51 | uint8_t rtp_payload_type); |
| 52 | |
| 53 | // Scales back to external timestamp. This is the inverse of ToInternal(). |
| 54 | virtual uint32_t ToExternal(uint32_t internal_timestamp) const; |
| 55 | |
| 56 | private: |
| 57 | bool first_packet_received_; |
| 58 | int numerator_; |
| 59 | int denominator_; |
| 60 | uint32_t external_ref_; |
| 61 | uint32_t internal_ref_; |
| 62 | const DecoderDatabase& decoder_database_; |
| 63 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 64 | RTC_DISALLOW_COPY_AND_ASSIGN(TimestampScaler); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 68 | #endif // MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ |