15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class chooses a capture interval so as to limit CPU usage to not exceed 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a specified %age. It bases this on the CPU usage of recent capture and encode 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// operations, and on the number of available CPUs. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_ 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define REMOTING_HOST_CAPTURE_SCHEDULER_H_ 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/base/running_average.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CaptureScheduler { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CaptureScheduler(); 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~CaptureScheduler(); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the time to wait after initiating a capture before triggering 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the next. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeDelta NextCaptureDelay(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Records time spent on capturing and encoding. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RecordCaptureTime(base::TimeDelta capture_time); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RecordEncodeTime(base::TimeDelta encode_time); 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Overrides the number of processors for testing. 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetNumOfProcessorsForTest(int num_of_processors); 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_of_processors_; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RunningAverage capture_time_; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RunningAverage encode_time_; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace remoting 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ 44