blob: 9973c1ff0877a4b8d47c65d061cc26ff7be5e9a7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org327ada12012-05-30 10:45:18 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef COMMON_VIDEO_VIDEO_RENDER_FRAMES_H_
12#define COMMON_VIDEO_VIDEO_RENDER_FRAMES_H_
Peter Boström9a638662015-05-13 13:28:11 +020013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Peter Boström9a638662015-05-13 13:28:11 +020015#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
henrike@webrtc.org79cf3ac2014-01-13 15:21:30 +000017#include <list>
18
Danil Chapovalov196100e2018-06-21 10:17:24 +020019#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/video/video_frame.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22namespace webrtc {
23
24// Class definitions
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000025class VideoRenderFrames {
26 public:
tommi2e82f382016-06-21 00:26:43 -070027 explicit VideoRenderFrames(uint32_t render_delay_ms);
28 VideoRenderFrames(const VideoRenderFrames&) = delete;
Mirko Bonadeid93a51d2018-07-17 15:47:51 +020029 ~VideoRenderFrames();
niklase@google.com470e71d2011-07-07 08:21:25 +000030
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000031 // Add a frame to the render queue
tommiede07592017-02-27 07:16:10 -080032 int32_t AddFrame(VideoFrame&& new_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
nissee5e52922016-05-25 06:25:17 -070034 // Get a frame for rendering, or false if it's not time to render.
Danil Chapovalov196100e2018-06-21 10:17:24 +020035 absl::optional<VideoFrame> FrameToRender();
niklase@google.com470e71d2011-07-07 08:21:25 +000036
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000037 // Returns the number of ms to next frame to render
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000038 uint32_t TimeToNextFrameRelease();
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tommiede07592017-02-27 07:16:10 -080040 bool HasPendingFrames() const;
tommi686aa372017-02-27 05:10:37 -080041
tommiede07592017-02-27 07:16:10 -080042 private:
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000043 // Sorted list with framed to be rendered, oldest first.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070044 std::list<VideoFrame> incoming_frames_;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000046 // Estimated delay from a frame is released until it's rendered.
tommi2e82f382016-06-21 00:26:43 -070047 const uint32_t render_delay_ms_;
tommiede07592017-02-27 07:16:10 -080048
49 int64_t last_render_time_ms_ = 0;
Stefan Holmer0a5792e2018-10-05 13:47:12 +020050 size_t frames_dropped_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051};
52
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000053} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000054
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#endif // COMMON_VIDEO_VIDEO_RENDER_FRAMES_H_