timestamp_scaler.h 2.1 KB

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