• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2020 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_CHAIN_DIFF_CALCULATOR_H_
12 #define MODULES_VIDEO_CODING_CHAIN_DIFF_CALCULATOR_H_
13 
14 #include <stdint.h>
15 
16 #include <vector>
17 
18 #include "absl/container/inlined_vector.h"
19 #include "absl/types/optional.h"
20 
21 namespace webrtc {
22 
23 // This class is thread compatible.
24 class ChainDiffCalculator {
25  public:
26   ChainDiffCalculator() = default;
27   ChainDiffCalculator(const ChainDiffCalculator&) = default;
28   ChainDiffCalculator& operator=(const ChainDiffCalculator&) = default;
29 
30   // Restarts chains, i.e. for position where chains[i] == true next chain_diff
31   // will be 0. Saves chains.size() as number of chains in the stream.
32   void Reset(const std::vector<bool>& chains);
33 
34   // Returns chain diffs based on flags if frame is part of the chain.
35   absl::InlinedVector<int, 4> From(int64_t frame_id,
36                                    const std::vector<bool>& chains);
37 
38  private:
39   absl::InlinedVector<int, 4> ChainDiffs(int64_t frame_id) const;
40 
41   absl::InlinedVector<absl::optional<int64_t>, 4> last_frame_in_chain_;
42 };
43 
44 }  // namespace webrtc
45 
46 #endif  // MODULES_VIDEO_CODING_CHAIN_DIFF_CALCULATOR_H_
47