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

Side by Side Diff: webrtc/modules/video_coding/packet_buffer.h

Issue 2199133004: PacketBuffer is now ref counted. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: #include <utility> for std::move 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_
13 13
14 #include <vector> 14 #include <vector>
15 #include <memory>
15 16
16 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/criticalsection.h"
18 #include "webrtc/base/scoped_ref_ptr.h"
17 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
18 #include "webrtc/modules/include/module_common_types.h" 20 #include "webrtc/modules/include/module_common_types.h"
19 #include "webrtc/modules/video_coding/packet.h" 21 #include "webrtc/modules/video_coding/packet.h"
20 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" 22 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h"
21 #include "webrtc/modules/video_coding/sequence_number_util.h" 23 #include "webrtc/modules/video_coding/sequence_number_util.h"
22 24
23 namespace webrtc { 25 namespace webrtc {
24 26
25 class Clock; 27 class Clock;
26 28
27 namespace video_coding { 29 namespace video_coding {
28 30
29 class FrameObject; 31 class FrameObject;
30 class RtpFrameObject; 32 class RtpFrameObject;
31 33
32 class OnCompleteFrameCallback { 34 // A received frame is a frame which has received all its packets.
35 class OnReceivedFrameCallback {
33 public: 36 public:
34 virtual ~OnCompleteFrameCallback() {} 37 virtual ~OnReceivedFrameCallback() {}
35 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; 38 virtual void OnReceivedFrame(std::unique_ptr<RtpFrameObject> frame) = 0;
36 }; 39 };
37 40
38 class PacketBuffer { 41 class PacketBuffer {
39 public: 42 public:
43 static rtc::scoped_refptr<PacketBuffer> Create(
44 Clock* clock,
45 size_t start_buffer_size,
46 size_t max_buffer_size,
47 OnReceivedFrameCallback* frame_callback);
48
49 virtual ~PacketBuffer();
50
51 // Made virtual for testing.
52 virtual bool InsertPacket(const VCMPacket& packet);
53 void ClearTo(uint16_t seq_num);
54 void Clear();
55
56 int AddRef() const;
57 int Release() const;
58
59 protected:
40 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2. 60 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2.
41 PacketBuffer(Clock* clock, 61 PacketBuffer(Clock* clock,
42 size_t start_buffer_size, 62 size_t start_buffer_size,
43 size_t max_buffer_size, 63 size_t max_buffer_size,
44 OnCompleteFrameCallback* frame_callback); 64 OnReceivedFrameCallback* frame_callback);
45
46 bool InsertPacket(const VCMPacket& packet);
47 void ClearTo(uint16_t seq_num);
48 void Clear();
49 65
50 private: 66 private:
51 friend RtpFrameObject; 67 friend RtpFrameObject;
52 // Since we want the packet buffer to be as packet type agnostic 68 // Since we want the packet buffer to be as packet type agnostic
53 // as possible we extract only the information needed in order 69 // as possible we extract only the information needed in order
54 // to determine whether a sequence of packets is continuous or not. 70 // to determine whether a sequence of packets is continuous or not.
55 struct ContinuityInfo { 71 struct ContinuityInfo {
56 // The sequence number of the packet. 72 // The sequence number of the packet.
57 uint16_t seq_num = 0; 73 uint16_t seq_num = 0;
58 74
(...skipping 19 matching lines...) Expand all
78 bool ExpandBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_); 94 bool ExpandBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_);
79 95
80 // Test if all previous packets has arrived for the given sequence number. 96 // Test if all previous packets has arrived for the given sequence number.
81 bool IsContinuous(uint16_t seq_num) const EXCLUSIVE_LOCKS_REQUIRED(crit_); 97 bool IsContinuous(uint16_t seq_num) const EXCLUSIVE_LOCKS_REQUIRED(crit_);
82 98
83 // Test if all packets of a frame has arrived, and if so, creates a frame. 99 // Test if all packets of a frame has arrived, and if so, creates a frame.
84 // May create multiple frames per invocation. 100 // May create multiple frames per invocation.
85 void FindFrames(uint16_t seq_num) EXCLUSIVE_LOCKS_REQUIRED(crit_); 101 void FindFrames(uint16_t seq_num) EXCLUSIVE_LOCKS_REQUIRED(crit_);
86 102
87 // Copy the bitstream for |frame| to |destination|. 103 // Copy the bitstream for |frame| to |destination|.
88 bool GetBitstream(const RtpFrameObject& frame, uint8_t* destination); 104 // Virtual for testing.
105 virtual bool GetBitstream(const RtpFrameObject& frame, uint8_t* destination);
89 106
90 // Get the packet with sequence number |seq_num|. 107 // Get the packet with sequence number |seq_num|.
91 VCMPacket* GetPacket(uint16_t seq_num); 108 // Virtual for testing.
109 virtual VCMPacket* GetPacket(uint16_t seq_num);
92 110
93 // Mark all slots used by |frame| as not used. 111 // Mark all slots used by |frame| as not used.
94 void ReturnFrame(RtpFrameObject* frame); 112 // Virtual for testing.
113 virtual void ReturnFrame(RtpFrameObject* frame);
95 114
96 rtc::CriticalSection crit_; 115 rtc::CriticalSection crit_;
97 116
98 // Buffer size_ and max_size_ must always be a power of two. 117 // Buffer size_ and max_size_ must always be a power of two.
99 size_t size_ GUARDED_BY(crit_); 118 size_t size_ GUARDED_BY(crit_);
100 const size_t max_size_; 119 const size_t max_size_;
101 120
102 // The fist sequence number currently in the buffer. 121 // The fist sequence number currently in the buffer.
103 uint16_t first_seq_num_ GUARDED_BY(crit_); 122 uint16_t first_seq_num_ GUARDED_BY(crit_);
104 123
105 // The last sequence number currently in the buffer. 124 // The last sequence number currently in the buffer.
106 uint16_t last_seq_num_ GUARDED_BY(crit_); 125 uint16_t last_seq_num_ GUARDED_BY(crit_);
107 126
108 // If the packet buffer has received its first packet. 127 // If the packet buffer has received its first packet.
109 bool first_packet_received_ GUARDED_BY(crit_); 128 bool first_packet_received_ GUARDED_BY(crit_);
110 129
111 // Buffer that holds the inserted packets. 130 // Buffer that holds the inserted packets.
112 std::vector<VCMPacket> data_buffer_ GUARDED_BY(crit_); 131 std::vector<VCMPacket> data_buffer_ GUARDED_BY(crit_);
113 132
114 // Buffer that holds the information about which slot that is currently in use 133 // Buffer that holds the information about which slot that is currently in use
115 // and information needed to determine the continuity between packets. 134 // and information needed to determine the continuity between packets.
116 std::vector<ContinuityInfo> sequence_buffer_ GUARDED_BY(crit_); 135 std::vector<ContinuityInfo> sequence_buffer_ GUARDED_BY(crit_);
117 136
118 // Frames that have received all their packets are handed off to the 137 // Called when a received frame is found.
119 // |reference_finder_| which finds the dependencies between the frames. 138 OnReceivedFrameCallback* const received_frame_callback_;
120 RtpFrameReferenceFinder reference_finder_; 139
140 mutable volatile int ref_count_ = 0;
121 }; 141 };
122 142
123 } // namespace video_coding 143 } // namespace video_coding
124 } // namespace webrtc 144 } // namespace webrtc
125 145
126 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ 146 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/frame_object.h ('k') | webrtc/modules/video_coding/packet_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698