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 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2. |
| 36 PacketBuffer(size_t start_buffer_size, |
| 37 size_t max_buffer_size, |
| 38 OnCompleteFrameCallback* frame_callback); |
| 39 |
| 40 bool InsertPacket(const VCMPacket& packet); |
| 41 void ClearTo(uint16_t seq_num); |
| 42 void Flush(); |
| 43 |
| 44 private: |
| 45 friend RtpFrameObject; |
| 46 // Since we want the packet buffer to be as packet type agnostic |
| 47 // as possible we extract only the information needed in order |
| 48 // to determin whether a sequence of packets is continuous or not. |
| 49 struct ContinuityInfo { |
| 50 uint16_t seq_num = 0; |
| 51 bool frame_begin = false; |
| 52 bool frame_end = false; |
| 53 bool used = false; |
| 54 bool continuous = false; |
| 55 }; |
| 56 |
| 57 bool ExpandBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 58 bool IsContinuous(uint16_t seq_num) const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 59 void FindCompleteFrames(uint16_t seq_num) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 60 bool GetBitstream(const RtpFrameObject& frame, uint8_t* destination); |
| 61 void ReturnFrame(RtpFrameObject* frame); |
| 62 |
| 63 rtc::CriticalSection crit_; |
| 64 |
| 65 // Buffer size_ and max_size_ must always be a power of two. |
| 66 size_t size_ GUARDED_BY(crit_); |
| 67 const size_t max_size_; |
| 68 |
| 69 uint16_t last_seq_num_ GUARDED_BY(crit_); |
| 70 uint16_t first_seq_num_ GUARDED_BY(crit_); |
| 71 bool initialized_ GUARDED_BY(crit_); |
| 72 std::vector<VCMPacket> data_buffer_ GUARDED_BY(crit_); |
| 73 std::vector<ContinuityInfo> sequence_buffer_ GUARDED_BY(crit_); |
| 74 |
| 75 OnCompleteFrameCallback* const frame_callback_; |
| 76 }; |
| 77 |
| 78 } // namespace video_coding |
| 79 } // namespace webrtc |
| 80 |
| 81 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ |
OLD | NEW |