Home | History | Annotate | Download | only in source
      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 #include "webrtc/system_wrappers/interface/thread_annotations.h"
     22 
     23 namespace webrtc {
     24 
     25 class Clock;
     26 class CriticalSectionWrapper;
     27 
     28 class RTPPacketHistory {
     29  public:
     30   RTPPacketHistory(Clock* clock);
     31   ~RTPPacketHistory();
     32 
     33   void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
     34 
     35   bool StorePackets() const;
     36 
     37   // Stores RTP packet.
     38   int32_t PutRTPPacket(const uint8_t* packet,
     39                        uint16_t packet_length,
     40                        uint16_t max_packet_length,
     41                        int64_t capture_time_ms,
     42                        StorageType type);
     43 
     44   // Gets stored RTP packet corresponding to the input sequence number.
     45   // The packet is copied to the buffer pointed to by ptr_rtp_packet.
     46   // The rtp_packet_length should show the available buffer size.
     47   // Returns true if packet is found.
     48   // rtp_packet_length: returns the copied packet length on success.
     49   // min_elapsed_time_ms: the minimum time that must have elapsed since the last
     50   // time the packet was resent (parameter is ignored if set to zero).
     51   // If the packet is found but the minimum time has not elaped, no bytes are
     52   // copied.
     53   // stored_time_ms: returns the time when the packet was stored.
     54   // type: returns the storage type set in PutRTPPacket.
     55   bool GetPacketAndSetSendTime(uint16_t sequence_number,
     56                                uint32_t min_elapsed_time_ms,
     57                                bool retransmit,
     58                                uint8_t* packet,
     59                                uint16_t* packet_length,
     60                                int64_t* stored_time_ms);
     61 
     62   bool GetBestFittingPacket(uint8_t* packet, uint16_t* packet_length,
     63                             int64_t* stored_time_ms);
     64 
     65   bool HasRTPPacket(uint16_t sequence_number) const;
     66 
     67  private:
     68   void GetPacket(int index, uint8_t* packet, uint16_t* packet_length,
     69                  int64_t* stored_time_ms) const;
     70   void Allocate(uint16_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
     71   void Free() EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
     72   void VerifyAndAllocatePacketLength(uint16_t packet_length);
     73   bool FindSeqNum(uint16_t sequence_number, int32_t* index) const;
     74   int FindBestFittingPacket(uint16_t size) const;
     75 
     76  private:
     77   Clock* clock_;
     78   CriticalSectionWrapper* critsect_;
     79   bool store_;
     80   uint32_t prev_index_;
     81   uint16_t max_packet_length_;
     82 
     83   std::vector<std::vector<uint8_t> > stored_packets_;
     84   std::vector<uint16_t> stored_seq_nums_;
     85   std::vector<uint16_t> stored_lengths_;
     86   std::vector<int64_t> stored_times_;
     87   std::vector<int64_t> stored_send_times_;
     88   std::vector<StorageType> stored_types_;
     89 };
     90 }  // namespace webrtc
     91 #endif  // WEBRTC_MODULES_RTP_RTCP_RTP_PACKET_HISTORY_H_
     92