Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: remoting/host/capture_scheduler.h

Issue 1462063004: Move VideoFramePump to remoting/protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/BUILD.gn ('k') | remoting/host/capture_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_
6 #define REMOTING_HOST_CAPTURE_SCHEDULER_H_
7
8 #include "base/callback.h"
9 #include "base/threading/thread_checker.h"
10 #include "base/time/tick_clock.h"
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "remoting/base/running_average.h"
14 #include "remoting/protocol/video_feedback_stub.h"
15
16 namespace remoting {
17
18 class VideoPacket;
19
20 // CaptureScheduler is used by the VideoFramePump to schedule frame capturer,
21 // taking into account capture delay, encoder delay, network bandwidth, etc.
22 // It implements VideoFeedbackStub to receive frame acknowledgments from the
23 // client.
24 //
25 // It attempts to achieve the following goals when scheduling frames:
26 // - Keep round-trip latency as low a possible.
27 // - Parallelize capture, encode and transmission, to achieve frame rate as
28 // close to the target of 30fps as possible.
29 // - Limit CPU usage to 50%.
30 class CaptureScheduler : public protocol::VideoFeedbackStub {
31 public:
32 explicit CaptureScheduler(const base::Closure& capture_closure);
33 ~CaptureScheduler() override;
34
35 // Starts the scheduler.
36 void Start();
37
38 // Pauses or unpauses the stream.
39 void Pause(bool pause);
40
41 // Notifies the scheduler that a capture has been completed.
42 void OnCaptureCompleted();
43
44 // Notifies the scheduler that a frame has been encoded. The scheduler can
45 // change |packet| if necessary, e.g. set |frame_id|.
46 void OnFrameEncoded(VideoPacket* packet);
47
48 // Notifies the scheduler that a frame has been sent.
49 void OnFrameSent();
50
51 // VideoFeedbackStub interface.
52 void ProcessVideoAck(scoped_ptr<VideoAck> video_ack) override;
53
54 // Sets minimum interval between frames.
55 void set_minimum_interval(base::TimeDelta minimum_interval) {
56 minimum_interval_ = minimum_interval;
57 }
58
59 // Helper functions for tests.
60 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
61 void SetTimerForTest(scoped_ptr<base::Timer> timer);
62 void SetNumOfProcessorsForTest(int num_of_processors);
63
64 private:
65 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time.
66 // Doesn't do anything if next frame cannot be captured yet (e.g. because
67 // there are too many frames being processed).
68 void ScheduleNextCapture();
69
70 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a
71 // new frame.
72 void CaptureNextFrame();
73
74 base::Closure capture_closure_;
75
76 scoped_ptr<base::TickClock> tick_clock_;
77
78 // Timer used to schedule CaptureNextFrame().
79 scoped_ptr<base::Timer> capture_timer_;
80
81 // Minimum interval between frames that determines maximum possible framerate.
82 base::TimeDelta minimum_interval_;
83
84 int num_of_processors_;
85
86 RunningAverage capture_time_;
87 RunningAverage encode_time_;
88
89 // Number of frames pending encoding.
90 int num_encoding_frames_;
91
92 // Number of outgoing frames for which we haven't received an acknowledgment.
93 int num_unacknowledged_frames_;
94
95 // Set to true when capture is pending.
96 bool capture_pending_;
97
98 // Time at which the last capture started. Used to schedule |capture_timer_|.
99 base::TimeTicks last_capture_started_time_;
100
101 bool is_paused_;
102
103 // Frame ID to be assigned to the next outgoing video frame.
104 uint32_t next_frame_id_;
105
106 base::ThreadChecker thread_checker_;
107
108 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler);
109 };
110
111 } // namespace remoting
112
113 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « remoting/host/BUILD.gn ('k') | remoting/host/capture_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698