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" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | // Forward declaration. |
| 19 | class DecoderDatabase; |
| 20 | |
| 21 | // This class scales timestamps for codecs that need timestamp scaling. |
| 22 | // This is done for codecs where one RTP timestamp does not correspond to |
| 23 | // one sample. |
| 24 | class TimestampScaler { |
| 25 | public: |
| 26 | explicit TimestampScaler(const DecoderDatabase& decoder_database) |
| 27 | : first_packet_received_(false), |
| 28 | numerator_(1), |
| 29 | denominator_(1), |
| 30 | external_ref_(0), |
| 31 | internal_ref_(0), |
| 32 | decoder_database_(decoder_database) {} |
| 33 | |
| 34 | virtual ~TimestampScaler() {} |
| 35 | |
Byoungchan Lee | 604fd2f | 2022-01-21 09:49:39 +0900 | [diff] [blame] | 36 | TimestampScaler(const TimestampScaler&) = delete; |
| 37 | TimestampScaler& operator=(const TimestampScaler&) = delete; |
| 38 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 39 | // Start over. |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 40 | virtual void Reset(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 41 | |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 42 | // Scale the timestamp in `packet` from external to internal. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 43 | virtual void ToInternal(Packet* packet); |
| 44 | |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 45 | // Scale the timestamp for all packets in `packet_list` from external to |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 46 | // internal. |
| 47 | virtual void ToInternal(PacketList* packet_list); |
| 48 | |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 49 | // Returns the internal equivalent of `external_timestamp`, given the |
| 50 | // RTP payload type `rtp_payload_type`. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 51 | virtual uint32_t ToInternal(uint32_t external_timestamp, |
| 52 | uint8_t rtp_payload_type); |
| 53 | |
| 54 | // Scales back to external timestamp. This is the inverse of ToInternal(). |
| 55 | virtual uint32_t ToExternal(uint32_t internal_timestamp) const; |
| 56 | |
| 57 | private: |
| 58 | bool first_packet_received_; |
| 59 | int numerator_; |
| 60 | int denominator_; |
| 61 | uint32_t external_ref_; |
| 62 | uint32_t internal_ref_; |
| 63 | const DecoderDatabase& decoder_database_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 67 | #endif // MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ |