rtp_packet_history.h revision 7e9315b42ebe8f7df860030af93618de81326503
1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* 2f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Use of this source code is governed by a BSD-style license 5cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky * that can be found in the LICENSE file in the root of the source 6cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky * tree. An additional intellectual property rights grant can be found 7f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka * in the file PATENTS. All contributing project authors may 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * be found in the AUTHORS file in the root of the source tree. 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Class for storing RTP packets. 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_ 14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_ 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <vector> 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "webrtc/modules/interface/module_common_types.h" 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "webrtc/typedefs.h" 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 22baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace webrtc { 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 24baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass Clock; 25baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CriticalSectionWrapper; 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 27baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass RTPPacketHistory { 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public: 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync RTPPacketHistory(Clock* clock); 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ~RTPPacketHistory(); 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void SetStorePacketsStatus(bool enable, uint16_t number_to_store); 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool StorePackets() const; 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // Stores RTP packet. 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int32_t PutRTPPacket(const uint8_t* packet, 38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t packet_length, 39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t max_packet_length, 40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int64_t capture_time_ms, 41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync StorageType type); 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // Replaces the stored RTP packet with matching sequence number with the 44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // RTP header of the provided packet. 45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // Note: Calling this function assumes that the RTP header length should not 46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // have changed since the packet was stored. 47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int32_t ReplaceRTPHeader(const uint8_t* packet, 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t sequence_number, 49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t rtp_header_length); 50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // Gets stored RTP packet corresponding to the input sequence number. 52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // The packet is copied to the buffer pointed to by ptr_rtp_packet. 53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // The rtp_packet_length should show the available buffer size. 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // Returns true if packet is found. 55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // rtp_packet_length: returns the copied packet length on success. 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // min_elapsed_time_ms: the minimum time that must have elapsed since the last 57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // time the packet was resent (parameter is ignored if set to zero). 58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // If the packet is found but the minimum time has not elaped, no bytes are 59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // copied. 60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // stored_time_ms: returns the time when the packet was stored. 61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // type: returns the storage type set in PutRTPPacket. 62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool GetPacketAndSetSendTime(uint16_t sequence_number, 63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint32_t min_elapsed_time_ms, 64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool retransmit, 65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint8_t* packet, 66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t* packet_length, 67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int64_t* stored_time_ms); 68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 69f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka bool GetBestFittingPacket(uint8_t* packet, uint16_t* packet_length, 70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int64_t* stored_time_ms); 71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool HasRTPPacket(uint16_t sequence_number) const; 73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync private: 75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void GetPacket(int index, uint8_t* packet, uint16_t* packet_length, 76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int64_t* stored_time_ms) const; 77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void Allocate(uint16_t number_to_store); 78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void Free(); 79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void VerifyAndAllocatePacketLength(uint16_t packet_length); 80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool FindSeqNum(uint16_t sequence_number, int32_t* index) const; 81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int FindBestFittingPacket(uint16_t size) const; 82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync private: 84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Clock* clock_; 85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CriticalSectionWrapper* critsect_; 86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool store_; 87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint32_t prev_index_; 88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync uint16_t max_packet_length_; 89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<std::vector<uint8_t> > stored_packets_; 91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<uint16_t> stored_seq_nums_; 92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<uint16_t> stored_lengths_; 93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<int64_t> stored_times_; 94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<int64_t> stored_send_times_; 95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync std::vector<StorageType> stored_types_; 96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} // namespace webrtc 98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif // WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_ 99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync