2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
10 * Class for storing RTP packets.
13 #ifndef WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_
14 #define WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_
18 #include "webrtc/modules/interface/module_common_types.h"
19 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
20 #include "webrtc/typedefs.h"
25 class CriticalSectionWrapper;
27 class RTPPacketHistory {
29 RTPPacketHistory(Clock* clock);
32 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
34 bool StorePackets() const;
37 int32_t PutRTPPacket(const uint8_t* packet,
38 uint16_t packet_length,
39 uint16_t max_packet_length,
40 int64_t capture_time_ms,
43 // Replaces the stored RTP packet with matching sequence number with the
44 // RTP header of the provided packet.
45 // Note: Calling this function assumes that the RTP header length should not
46 // have changed since the packet was stored.
47 int32_t ReplaceRTPHeader(const uint8_t* packet,
48 uint16_t sequence_number,
49 uint16_t rtp_header_length);
51 // Gets stored RTP packet corresponding to the input sequence number.
52 // The packet is copied to the buffer pointed to by ptr_rtp_packet.
53 // The rtp_packet_length should show the available buffer size.
54 // Returns true if packet is found.
55 // rtp_packet_length: returns the copied packet length on success.
56 // min_elapsed_time_ms: the minimum time that must have elapsed since the last
57 // time the packet was resent (parameter is ignored if set to zero).
58 // If the packet is found but the minimum time has not elaped, no bytes are
60 // stored_time_ms: returns the time when the packet was stored.
61 // type: returns the storage type set in PutRTPPacket.
62 bool GetPacketAndSetSendTime(uint16_t sequence_number,
63 uint32_t min_elapsed_time_ms,
66 uint16_t* packet_length,
67 int64_t* stored_time_ms);
69 bool GetBestFittingPacket(uint8_t* packet, uint16_t* packet_length,
70 int64_t* stored_time_ms);
72 bool HasRTPPacket(uint16_t sequence_number) const;
75 void GetPacket(int index, uint8_t* packet, uint16_t* packet_length,
76 int64_t* stored_time_ms) const;
77 void Allocate(uint16_t number_to_store);
79 void VerifyAndAllocatePacketLength(uint16_t packet_length);
80 bool FindSeqNum(uint16_t sequence_number, int32_t* index) const;
81 int FindBestFittingPacket(uint16_t size) const;
85 CriticalSectionWrapper* critsect_;
88 uint16_t max_packet_length_;
90 std::vector<std::vector<uint8_t> > stored_packets_;
91 std::vector<uint16_t> stored_seq_nums_;
92 std::vector<uint16_t> stored_lengths_;
93 std::vector<int64_t> stored_times_;
94 std::vector<int64_t> stored_send_times_;
95 std::vector<StorageType> stored_types_;
98 #endif // WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_