chain_diff_calculator.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef MODULES_VIDEO_CODING_CHAIN_DIFF_CALCULATOR_H_
  11. #define MODULES_VIDEO_CODING_CHAIN_DIFF_CALCULATOR_H_
  12. #include <stdint.h>
  13. #include <vector>
  14. #include "absl/container/inlined_vector.h"
  15. #include "absl/types/optional.h"
  16. namespace webrtc {
  17. // This class is thread compatible.
  18. class ChainDiffCalculator {
  19. public:
  20. ChainDiffCalculator() = default;
  21. ChainDiffCalculator(const ChainDiffCalculator&) = default;
  22. ChainDiffCalculator& operator=(const ChainDiffCalculator&) = default;
  23. // Restarts chains, i.e. for position where chains[i] == true next chain_diff
  24. // will be 0. Saves chains.size() as number of chains in the stream.
  25. void Reset(const std::vector<bool>& chains);
  26. // Returns chain diffs based on flags if frame is part of the chain.
  27. absl::InlinedVector<int, 4> From(int64_t frame_id,
  28. const std::vector<bool>& chains);
  29. private:
  30. absl::InlinedVector<int, 4> ChainDiffs(int64_t frame_id) const;
  31. absl::InlinedVector<absl::optional<int64_t>, 4> last_frame_in_chain_;
  32. };
  33. } // namespace webrtc
  34. #endif // MODULES_VIDEO_CODING_CHAIN_DIFF_CALCULATOR_H_