OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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 | |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | |
12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | |
13 | |
14 #include <vector> | |
15 | |
16 #include "webrtc/base/criticalsection.h" | |
17 #include "webrtc/base/scoped_ptr.h" | |
18 #include "webrtc/base/thread_annotations.h" | |
19 #include "webrtc/modules/video_coding/packet.h" | |
20 | |
21 namespace webrtc { | |
22 namespace video_coding { | |
23 | |
24 class FrameObject; | |
25 class RtpFrameObject; | |
26 | |
27 class OnCompleteFrameCallback { | |
28 public: | |
29 virtual ~OnCompleteFrameCallback() {} | |
30 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; | |
31 }; | |
32 | |
33 class PacketBuffer { | |
34 public: | |
35 PacketBuffer(size_t start_buffer_size, | |
stefan-webrtc
2016/03/30 11:59:32
Comment on power of 2 requirements.
philipel
2016/03/30 12:40:11
Done.
| |
36 size_t max_buffer_size, | |
37 OnCompleteFrameCallback* frame_callback); | |
38 bool InsertPacket(const VCMPacket& packet); | |
39 void ClearUpTo(uint16_t seq_num); | |
40 void Flush(); | |
41 | |
42 private: | |
43 friend RtpFrameObject; | |
44 // Since we want the packet buffer to be as packet type agnostic | |
45 // as possible we extract only the information needed in order | |
46 // to determin whether a sequence of packets is continuous or not. | |
47 struct ContinuityInfo { | |
48 uint16_t seq_num = 0; | |
49 bool frame_begin = false; | |
50 bool frame_end = false; | |
51 bool used = false; | |
52 bool continuous = false; | |
53 }; | |
54 | |
55 bool ExpandBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
56 bool IsContinuous(uint16_t seq_num) const EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
57 void FindCompleteFrames(uint16_t seq_num) EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
58 bool GetBitstream(const RtpFrameObject& frame, uint8_t* destination); | |
59 void ReturnFrame(RtpFrameObject* frame); | |
60 | |
61 rtc::CriticalSection crit_; | |
62 | |
63 // Buffer size_ and max_size_ must always be a power of two. | |
64 size_t size_ GUARDED_BY(crit_); | |
65 const size_t max_size_; | |
66 | |
67 uint16_t clear_up_to_ GUARDED_BY(crit_); | |
68 bool initialized_ GUARDED_BY(crit_); | |
69 std::vector<VCMPacket> data_buffer_ GUARDED_BY(crit_); | |
70 std::vector<ContinuityInfo> sequence_buffer_ GUARDED_BY(crit_); | |
71 | |
72 | |
73 OnCompleteFrameCallback* const frame_callback_; | |
74 }; | |
75 | |
76 } // namespace video_coding | |
77 } // namespace webrtc | |
78 | |
79 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | |
OLD | NEW |