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