Chromium Code Reviews| Index: webrtc/modules/video_coding/frame_buffer2.h |
| diff --git a/webrtc/modules/video_coding/frame_buffer2.h b/webrtc/modules/video_coding/frame_buffer2.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c61867d7675e55af584c3da8c6156c3b3a290a62 |
| --- /dev/null |
| +++ b/webrtc/modules/video_coding/frame_buffer2.h |
| @@ -0,0 +1,97 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |
| +#define WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |
| + |
| +#include <array> |
| +#include <map> |
| +#include <memory> |
| +#include <utility> |
| + |
| +#include "webrtc/base/criticalsection.h" |
| +#include "webrtc/base/event.h" |
| +#include "webrtc/base/thread_annotations.h" |
| +#include "webrtc/modules/video_coding/frame_object.h" |
| +#include "webrtc/modules/video_coding/jitter_estimator.h" |
| +#include "webrtc/modules/video_coding/sequence_number_util.h" |
| +#include "webrtc/modules/video_coding/timing.h" |
| +#include "webrtc/system_wrappers/include/clock.h" |
| + |
| +namespace webrtc { |
| +namespace video_coding { |
| + |
| +class FrameBuffer { |
| + public: |
| + FrameBuffer(Clock* clock, |
| + VCMJitterEstimator* jitter_estimator, |
| + VCMTiming* timing); |
| + |
| + // Insert a frame into the frame buffer. |
| + void InsertFrame(std::unique_ptr<FrameObject> frame); |
| + |
| + // Get the next frame for decoding. Will return at latest after |
| + // |max_wait_time|, with either a managed FrameObject or an empty |
| + // unique ptr if there is no available frame for decoding. |
| + std::unique_ptr<FrameObject> NextFrame(int64_t max_wait_time); |
|
danilchap
2016/05/13 15:33:56
max_wait_time_ms
philipel
2016/05/17 09:16:41
Done.
|
| + |
| + private: |
| + // The maximum age of a frame stored in the frame buffer, compared to |
| + // |newest_picture_id_|. |
| + static const int kMaxFrameAge = 4096; |
| + |
| + // The maximum number of frames stored in the frame buffer. |
| + static const int kMaxStoredFrames = 256; |
| + |
| + // The maximum number of spatial layers. |
| + static const int kMaxSpatialLayers = 5; |
| + |
| + // Determines whether a frame is continuous. |
| + bool IsContinuous(const FrameObject& frame) const |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + // For every picture id, keep information whether a frame has been decoded |
| + // for a given spatial layer. |
| + std::map<uint16_t, |
| + std::array<bool, kMaxSpatialLayers>, |
| + DescendingSeqNumComp<uint16_t>> decoded_frames_ GUARDED_BY(crit_); |
| + |
| + // Comparator used to sort frames, first on their picture id, and second |
| + // on their spatial layer. |
| + struct FrameComp { |
| + bool operator()(const std::pair<uint16_t, uint8_t>& f1, |
|
danilchap
2016/05/13 15:33:56
probably better make this static if you want to ke
philipel
2016/05/17 09:16:41
I don't really understand...
danilchap
2016/05/17 12:35:02
i.e. static bool operator()(<same as before>) cons
philipel
2016/05/17 14:57:04
Acknowledged.
|
| + const std::pair<uint16_t, uint8_t>& f2) const { |
| + // first = picture id |
| + // second = spatial layer |
| + if (f1.first == f2.first) |
| + return f1.second < f2.second; |
| + return AheadOf(f2.first, f1.first); |
| + } |
| + }; |
| + |
| + // The actual buffer that holds the FrameObjects, the key being the |
| + // tuple (picture id, spatial layer). |
| + std::map<std::pair<uint16_t, uint8_t>, |
|
danilchap
2016/05/13 15:33:56
may be instead of using pair as key and creating s
philipel
2016/05/17 09:16:41
Acknowledged.
|
| + std::unique_ptr<FrameObject>, |
| + FrameComp> frames_ GUARDED_BY(crit_); |
| + |
| + rtc::CriticalSection crit_; |
| + Clock* clock_; |
|
danilchap
2016/05/13 15:33:56
Clock* const clock_;
philipel
2016/05/17 09:16:41
Done.
|
| + rtc::Event frame_inserted_event_; |
| + VCMJitterEstimator* jitter_estimator_; |
|
danilchap
2016/05/13 15:33:57
VCMJitterEstimator* const jitter_estimator_;
philipel
2016/05/17 09:16:41
Done.
|
| + VCMTiming* timing_; |
|
danilchap
2016/05/13 15:33:56
const VCMTiming* const timing_;
philipel
2016/05/17 09:16:41
Done.
|
| + int newest_picture_id_ GUARDED_BY(crit_); |
| +}; |
| + |
| + |
| +} // namespace video_coding |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |