1 /* 2 * Copyright (c) 2019 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 MODULES_VIDEO_CODING_UTILITY_DECODED_FRAMES_HISTORY_H_ 12 #define MODULES_VIDEO_CODING_UTILITY_DECODED_FRAMES_HISTORY_H_ 13 14 #include <stdint.h> 15 16 #include <bitset> 17 #include <vector> 18 19 #include "absl/types/optional.h" 20 #include "api/video/encoded_frame.h" 21 22 namespace webrtc { 23 namespace video_coding { 24 25 class DecodedFramesHistory { 26 public: 27 // window_size - how much frames back to the past are actually remembered. 28 explicit DecodedFramesHistory(size_t window_size); 29 ~DecodedFramesHistory(); 30 // Called for each decoded frame. Assumes picture id's are non-decreasing. 31 void InsertDecoded(const VideoLayerFrameId& frameid, uint32_t timestamp); 32 // Query if the following (picture_id, spatial_id) pair was inserted before. 33 // Should be at most less by window_size-1 than the last inserted picture id. 34 bool WasDecoded(const VideoLayerFrameId& frameid); 35 36 void Clear(); 37 38 absl::optional<VideoLayerFrameId> GetLastDecodedFrameId(); 39 absl::optional<uint32_t> GetLastDecodedFrameTimestamp(); 40 41 private: 42 struct LayerHistory { 43 LayerHistory(); 44 ~LayerHistory(); 45 // Cyclic bitset buffer. Stores last known |window_size| bits. 46 std::vector<bool> buffer; 47 absl::optional<int64_t> last_picture_id; 48 }; 49 50 int PictureIdToIndex(int64_t frame_id) const; 51 52 const int window_size_; 53 std::vector<LayerHistory> layers_; 54 absl::optional<VideoLayerFrameId> last_decoded_frame_; 55 absl::optional<uint32_t> last_decoded_frame_timestamp_; 56 }; 57 58 } // namespace video_coding 59 } // namespace webrtc 60 #endif // MODULES_VIDEO_CODING_UTILITY_DECODED_FRAMES_HISTORY_H_ 61