Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet_history.h

Issue 1945773002: RtpPacketHistory rewritten to use RtpPacket class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 *
10 * Class for storing RTP packets.
11 */ 9 */
12 10
13 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_ 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
14 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_ 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
15 13
14 #include <memory>
16 #include <vector> 15 #include <vector>
17 16
17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/base/criticalsection.h" 18 #include "webrtc/base/criticalsection.h"
19 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
20 #include "webrtc/modules/include/module_common_types.h"
21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "webrtc/typedefs.h" 21 #include "webrtc/typedefs.h"
23 22
24 namespace webrtc { 23 namespace webrtc {
25 24
26 class Clock; 25 class Clock;
26 class RtpPacketToSend;
27 27
28 static const size_t kMaxHistoryCapacity = 9600; 28 class RtpPacketHistory {
29
30 class RTPPacketHistory {
31 public: 29 public:
32 explicit RTPPacketHistory(Clock* clock); 30 static constexpr size_t kMaxCapacity = 9600;
33 ~RTPPacketHistory(); 31 explicit RtpPacketHistory(Clock* clock);
32 ~RtpPacketHistory();
34 33
35 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); 34 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
36
37 bool StorePackets() const; 35 bool StorePackets() const;
38 36
39 // Stores RTP packet. 37 void PutRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
40 int32_t PutRTPPacket(const uint8_t* packet, 38 StorageType type,
41 size_t packet_length, 39 bool sent);
42 int64_t capture_time_ms,
43 StorageType type);
44 40
45 // Gets stored RTP packet corresponding to the input sequence number. 41 // Gets stored RTP packet corresponding to the input |sequence number|.
46 // The packet is copied to the buffer pointed to by ptr_rtp_packet. 42 // Returns nullptr if packet is not found.
47 // The rtp_packet_length should show the available buffer size. 43 // |min_elapsed_time_ms| is the minimum time that must have elapsed since
48 // Returns true if packet is found. 44 // the last time the packet was resent (parameter is ignored if set to zero).
49 // packet_length: returns the copied packet length on success. 45 // If the packet is found but the minimum time has not elapsed, returns
50 // min_elapsed_time_ms: the minimum time that must have elapsed since the last 46 // nullptr.
51 // time the packet was resent (parameter is ignored if set to zero). 47 std::unique_ptr<RtpPacketToSend> GetPacketAndSetSendTime(
52 // If the packet is found but the minimum time has not elapsed, no bytes are 48 uint16_t sequence_number,
53 // copied. 49 int64_t min_elapsed_time_ms,
54 // stored_time_ms: returns the time when the packet was stored. 50 bool retransmit);
55 bool GetPacketAndSetSendTime(uint16_t sequence_number,
56 int64_t min_elapsed_time_ms,
57 bool retransmit,
58 uint8_t* packet,
59 size_t* packet_length,
60 int64_t* stored_time_ms);
61 51
62 bool GetBestFittingPacket(uint8_t* packet, size_t* packet_length, 52 std::unique_ptr<RtpPacketToSend> GetBestFittingPacket(
63 int64_t* stored_time_ms); 53 size_t packet_size) const;
64 54
65 bool HasRTPPacket(uint16_t sequence_number) const; 55 bool HasRtpPacket(uint16_t sequence_number) const;
66
67 bool SetSent(uint16_t sequence_number);
68 56
69 private: 57 private:
70 void GetPacket(int index, 58 struct StoredPacket {
71 uint8_t* packet, 59 uint16_t sequence_number = 0;
72 size_t* packet_length, 60 int64_t send_time = 0;
73 int64_t* stored_time_ms) const 61 StorageType storage_type = kDontRetransmit;
62 bool has_been_retransmitted = false;
63
64 std::unique_ptr<RtpPacketToSend> packet;
65 };
66
67 std::unique_ptr<RtpPacketToSend> GetPacket(int index) const
74 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 68 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
75 void Allocate(size_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(critsect_); 69 void Allocate(size_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
76 void Free() EXCLUSIVE_LOCKS_REQUIRED(critsect_); 70 void Free() EXCLUSIVE_LOCKS_REQUIRED(critsect_);
77 void VerifyAndAllocatePacketLength(size_t packet_length, uint32_t start_index) 71 bool FindSeqNum(uint16_t sequence_number, int* index) const
78 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
79 bool FindSeqNum(uint16_t sequence_number, int32_t* index) const
80 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 72 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
81 int FindBestFittingPacket(size_t size) const 73 int FindBestFittingPacket(size_t size) const
82 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 74 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
83 75
84 private:
85 Clock* clock_; 76 Clock* clock_;
86 rtc::CriticalSection critsect_; 77 rtc::CriticalSection critsect_;
87 bool store_ GUARDED_BY(critsect_); 78 bool store_ GUARDED_BY(critsect_);
88 uint32_t prev_index_ GUARDED_BY(critsect_); 79 uint32_t prev_index_ GUARDED_BY(critsect_);
80 std::vector<StoredPacket> stored_packets_ GUARDED_BY(critsect_);
89 81
90 struct StoredPacket { 82 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpPacketHistory);
91 StoredPacket();
92 uint16_t sequence_number = 0;
93 int64_t time_ms = 0;
94 int64_t send_time = 0;
95 StorageType storage_type = kDontRetransmit;
96 bool has_been_retransmitted = false;
97
98 uint8_t data[IP_PACKET_SIZE];
99 size_t length = 0;
100 };
101 std::vector<StoredPacket> stored_packets_ GUARDED_BY(critsect_);
102 }; 83 };
103 } // namespace webrtc 84 } // namespace webrtc
104 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_ 85 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_HISTORY_H_
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698