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 11 #ifndef MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 12 #define MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 13 14 #include "modules/audio_coding/neteq/packet.h" 15 #include "rtc_base/constructor_magic.h" 16 17 namespace webrtc { 18 19 // Forward declaration. 20 class DecoderDatabase; 21 22 // This class scales timestamps for codecs that need timestamp scaling. 23 // This is done for codecs where one RTP timestamp does not correspond to 24 // one sample. 25 class TimestampScaler { 26 public: TimestampScaler(const DecoderDatabase & decoder_database)27 explicit TimestampScaler(const DecoderDatabase& decoder_database) 28 : first_packet_received_(false), 29 numerator_(1), 30 denominator_(1), 31 external_ref_(0), 32 internal_ref_(0), 33 decoder_database_(decoder_database) {} 34 ~TimestampScaler()35 virtual ~TimestampScaler() {} 36 37 // Start over. 38 virtual void Reset(); 39 40 // Scale the timestamp in |packet| from external to internal. 41 virtual void ToInternal(Packet* packet); 42 43 // Scale the timestamp for all packets in |packet_list| from external to 44 // internal. 45 virtual void ToInternal(PacketList* packet_list); 46 47 // Returns the internal equivalent of |external_timestamp|, given the 48 // RTP payload type |rtp_payload_type|. 49 virtual uint32_t ToInternal(uint32_t external_timestamp, 50 uint8_t rtp_payload_type); 51 52 // Scales back to external timestamp. This is the inverse of ToInternal(). 53 virtual uint32_t ToExternal(uint32_t internal_timestamp) const; 54 55 private: 56 bool first_packet_received_; 57 int numerator_; 58 int denominator_; 59 uint32_t external_ref_; 60 uint32_t internal_ref_; 61 const DecoderDatabase& decoder_database_; 62 63 RTC_DISALLOW_COPY_AND_ASSIGN(TimestampScaler); 64 }; 65 66 } // namespace webrtc 67 #endif // MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 68