19a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org/* 29a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 39a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * 49a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * Use of this source code is governed by a BSD-style license 59a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * that can be found in the LICENSE file in the root of the source 69a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * tree. An additional intellectual property rights grant can be found 79a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * in the file PATENTS. All contributing project authors may 89a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org * be found in the AUTHORS file in the root of the source tree. 99a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org */ 109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 11e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 12e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 14774b3d38a4a0f1a8ec08972a3c543cb5d607ce13henrike@webrtc.org#include "webrtc/base/constructormagic.h" 15e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/packet.h" 169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/typedefs.h" 179a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgnamespace webrtc { 199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Forward declaration. 219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass DecoderDatabase; 229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// This class scales timestamps for codecs that need timestamp scaling. 249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// This is done for codecs where one RTP timestamp does not correspond to 259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// one sample. 269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass TimestampScaler { 279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org public: 289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org explicit TimestampScaler(const DecoderDatabase& decoder_database) 299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org : first_packet_received_(false), 309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org numerator_(1), 319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org denominator_(1), 329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org external_ref_(0), 339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org internal_ref_(0), 349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org decoder_database_(decoder_database) {} 359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual ~TimestampScaler() {} 379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // Start over. 399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual void Reset() { first_packet_received_ = false; } 409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // Scale the timestamp in |packet| from external to internal. 429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual void ToInternal(Packet* packet); 439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // Scale the timestamp for all packets in |packet_list| from external to 459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // internal. 469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual void ToInternal(PacketList* packet_list); 479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // Returns the internal equivalent of |external_timestamp|, given the 499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // RTP payload type |rtp_payload_type|. 509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual uint32_t ToInternal(uint32_t external_timestamp, 519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org uint8_t rtp_payload_type); 529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org // Scales back to external timestamp. This is the inverse of ToInternal(). 549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org virtual uint32_t ToExternal(uint32_t internal_timestamp) const; 559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org private: 579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org bool first_packet_received_; 589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org int numerator_; 599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org int denominator_; 609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org uint32_t external_ref_; 619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org uint32_t internal_ref_; 629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org const DecoderDatabase& decoder_database_; 639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org DISALLOW_COPY_AND_ASSIGN(TimestampScaler); 659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}; 669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org 679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org} // namespace webrtc 68e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TIMESTAMP_SCALER_H_ 69