xref: /aosp_15_r20/external/webrtc/video/frame_decode_timing.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 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 VIDEO_FRAME_DECODE_TIMING_H_
12 #define VIDEO_FRAME_DECODE_TIMING_H_
13 
14 #include <stdint.h>
15 
16 #include <functional>
17 
18 #include "api/task_queue/pending_task_safety_flag.h"
19 #include "api/task_queue/task_queue_base.h"
20 #include "modules/video_coding/timing/timing.h"
21 #include "system_wrappers/include/clock.h"
22 
23 namespace webrtc {
24 
25 class FrameDecodeTiming {
26  public:
27   FrameDecodeTiming(Clock* clock, webrtc::VCMTiming const* timing);
28   ~FrameDecodeTiming() = default;
29   FrameDecodeTiming(const FrameDecodeTiming&) = delete;
30   FrameDecodeTiming& operator=(const FrameDecodeTiming&) = delete;
31 
32   // Any frame that has decode delay more than this in the past can be
33   // fast-forwarded.
34   static constexpr TimeDelta kMaxAllowedFrameDelay = TimeDelta::Millis(5);
35 
36   struct FrameSchedule {
37     Timestamp latest_decode_time;
38     Timestamp render_time;
39   };
40 
41   absl::optional<FrameSchedule> OnFrameBufferUpdated(
42       uint32_t next_temporal_unit_rtp,
43       uint32_t last_temporal_unit_rtp,
44       TimeDelta max_wait_for_frame,
45       bool too_many_frames_queued);
46 
47  private:
48   Clock* const clock_;
49   webrtc::VCMTiming const* const timing_;
50 };
51 
52 }  // namespace webrtc
53 
54 #endif  // VIDEO_FRAME_DECODE_TIMING_H_
55