2012-01-16 11:06:31 +00:00
|
|
|
/*
|
2012-07-03 10:41:54 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2012-01-16 11:06:31 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
|
2012-01-16 11:06:31 +00:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
#include <memory>
|
2012-01-16 11:06:31 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
|
|
|
|
#include "rtc_base/constructormagic.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
|
#include "typedefs.h"
|
2012-01-16 11:06:31 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-01-17 14:01:20 +00:00
|
|
|
class Clock;
|
2016-08-03 18:27:40 +02:00
|
|
|
class RtpPacketToSend;
|
2012-01-16 11:06:31 +00:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
class RtpPacketHistory {
|
2012-01-16 11:06:31 +00:00
|
|
|
public:
|
2016-08-03 18:27:40 +02:00
|
|
|
static constexpr size_t kMaxCapacity = 9600;
|
|
|
|
|
explicit RtpPacketHistory(Clock* clock);
|
|
|
|
|
~RtpPacketHistory();
|
2012-01-16 11:06:31 +00:00
|
|
|
|
|
|
|
|
void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
|
|
|
|
|
bool StorePackets() const;
|
|
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
void PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
|
|
|
|
|
StorageType type,
|
|
|
|
|
bool sent);
|
|
|
|
|
|
|
|
|
|
// Gets stored RTP packet corresponding to the input |sequence number|.
|
|
|
|
|
// Returns nullptr if packet is not found.
|
|
|
|
|
// |min_elapsed_time_ms| is the minimum time that must have elapsed since
|
|
|
|
|
// the last time the packet was resent (parameter is ignored if set to zero).
|
|
|
|
|
// If the packet is found but the minimum time has not elapsed, returns
|
|
|
|
|
// nullptr.
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> GetPacketAndSetSendTime(
|
|
|
|
|
uint16_t sequence_number,
|
|
|
|
|
int64_t min_elapsed_time_ms,
|
|
|
|
|
bool retransmit);
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> GetBestFittingPacket(
|
|
|
|
|
size_t packet_size) const;
|
|
|
|
|
|
|
|
|
|
bool HasRtpPacket(uint16_t sequence_number) const;
|
2015-01-29 09:09:17 +00:00
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
private:
|
2016-08-03 18:27:40 +02:00
|
|
|
struct StoredPacket {
|
|
|
|
|
uint16_t sequence_number = 0;
|
|
|
|
|
int64_t send_time = 0;
|
|
|
|
|
StorageType storage_type = kDontRetransmit;
|
|
|
|
|
bool has_been_retransmitted = false;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> packet;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> GetPacket(int index) const
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
|
|
|
|
void Allocate(size_t number_to_store) RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
|
|
|
|
void Free() RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
2016-08-03 18:27:40 +02:00
|
|
|
bool FindSeqNum(uint16_t sequence_number, int* index) const
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
2015-01-29 09:09:17 +00:00
|
|
|
int FindBestFittingPacket(size_t size) const
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
2012-01-16 11:06:31 +00:00
|
|
|
|
2013-01-21 07:42:11 +00:00
|
|
|
Clock* clock_;
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CriticalSection critsect_;
|
2017-09-07 07:53:45 -07:00
|
|
|
bool store_ RTC_GUARDED_BY(critsect_);
|
|
|
|
|
uint32_t prev_index_ RTC_GUARDED_BY(critsect_);
|
|
|
|
|
std::vector<StoredPacket> stored_packets_ RTC_GUARDED_BY(critsect_);
|
2016-08-03 18:27:40 +02:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpPacketHistory);
|
2012-01-16 11:06:31 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
|