785e4992b0a7fc179e91f7a6728dbf0454f9cbe8
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / rtp_rtcp / source / rtp_packet_history.h
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  *  Class for storing RTP packets.
11  */
12
13 #ifndef WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_
14 #define WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_
15
16 #include <vector>
17
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"
21
22 namespace webrtc {
23
24 class Clock;
25 class CriticalSectionWrapper;
26
27 class RTPPacketHistory {
28  public:
29   RTPPacketHistory(Clock* clock);
30   ~RTPPacketHistory();
31
32   void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
33
34   bool StorePackets() const;
35
36   // Stores RTP packet.
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,
41                        StorageType type);
42
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);
50
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
59   // copied.
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,
64                                bool retransmit,
65                                uint8_t* packet,
66                                uint16_t* packet_length,
67                                int64_t* stored_time_ms);
68
69   bool GetBestFittingPacket(uint8_t* packet, uint16_t* packet_length,
70                             int64_t* stored_time_ms);
71
72   bool HasRTPPacket(uint16_t sequence_number) const;
73
74  private:
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);
78   void Free();
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;
82
83  private:
84   Clock* clock_;
85   CriticalSectionWrapper* critsect_;
86   bool store_;
87   uint32_t prev_index_;
88   uint16_t max_packet_length_;
89
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_;
96 };
97 }  // namespace webrtc
98 #endif  // WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_