| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 
| 6 #define REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 
| 7 | 7 | 
| 8 #include "remoting/protocol/webrtc_frame_scheduler.h" | 8 #include "remoting/protocol/webrtc_frame_scheduler.h" | 
| 9 | 9 | 
|  | 10 #include <queue> | 
|  | 11 | 
| 10 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" | 
| 11 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" | 
| 12 #include "remoting/base/leaky_bucket.h" | 14 #include "remoting/base/leaky_bucket.h" | 
| 13 #include "remoting/base/running_samples.h" | 15 #include "remoting/base/running_samples.h" | 
| 14 #include "remoting/protocol/video_channel_state_observer.h" | 16 #include "remoting/protocol/video_channel_state_observer.h" | 
| 15 | 17 | 
| 16 namespace remoting { | 18 namespace remoting { | 
| 17 namespace protocol { | 19 namespace protocol { | 
| 18 | 20 | 
| 19 // WebrtcFrameSchedulerSimple is a simple implementation of WebrtcFrameScheduler | 21 // WebrtcFrameSchedulerSimple is a simple implementation of WebrtcFrameScheduler | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 36              const base::Closure& capture_callback) override; | 38              const base::Closure& capture_callback) override; | 
| 37   void Pause(bool pause) override; | 39   void Pause(bool pause) override; | 
| 38   bool GetEncoderFrameParams( | 40   bool GetEncoderFrameParams( | 
| 39       const webrtc::DesktopFrame& frame, | 41       const webrtc::DesktopFrame& frame, | 
| 40       WebrtcVideoEncoder::FrameParams* params_out) override; | 42       WebrtcVideoEncoder::FrameParams* params_out) override; | 
| 41   void OnFrameEncoded(const WebrtcVideoEncoder::EncodedFrame& encoded_frame, | 43   void OnFrameEncoded(const WebrtcVideoEncoder::EncodedFrame& encoded_frame, | 
| 42                       const webrtc::EncodedImageCallback::Result& send_result, | 44                       const webrtc::EncodedImageCallback::Result& send_result, | 
| 43                       HostFrameStats* frame_stats) override; | 45                       HostFrameStats* frame_stats) override; | 
| 44 | 46 | 
| 45  private: | 47  private: | 
|  | 48   // Helper class used to calculate target encoder bitrate. | 
|  | 49   class EncoderBitrateFilter { | 
|  | 50    public: | 
|  | 51     EncoderBitrateFilter(); | 
|  | 52     ~EncoderBitrateFilter(); | 
|  | 53 | 
|  | 54     void SetBandwidthEstimate(int bandwidth_kbps, base::TimeTicks now); | 
|  | 55     int GetTargetBitrateKbps(webrtc::DesktopSize size, base::TimeTicks now); | 
|  | 56 | 
|  | 57    private: | 
|  | 58     std::queue<std::pair<base::TimeTicks, int>> bandwidth_samples_; | 
|  | 59     int bandwidth_samples_sum_ = 0; | 
|  | 60 | 
|  | 61     int current_target_bitrate_; | 
|  | 62   }; | 
|  | 63 | 
| 46   void ScheduleNextFrame(base::TimeTicks now); | 64   void ScheduleNextFrame(base::TimeTicks now); | 
| 47   void CaptureNextFrame(); | 65   void CaptureNextFrame(); | 
| 48 | 66 | 
| 49   base::Closure capture_callback_; | 67   base::Closure capture_callback_; | 
| 50   bool paused_ = false; | 68   bool paused_ = false; | 
| 51   bool key_frame_request_ = false; | 69   bool key_frame_request_ = false; | 
| 52 | 70 | 
| 53   base::TimeTicks last_capture_started_time_; | 71   base::TimeTicks last_capture_started_time_; | 
| 54 | 72 | 
| 55   LeakyBucket pacing_bucket_; | 73   LeakyBucket pacing_bucket_; | 
| 56 | 74 | 
|  | 75   EncoderBitrateFilter encoder_bitrate_; | 
|  | 76 | 
| 57   // Set to true when a frame is being captured or encoded. | 77   // Set to true when a frame is being captured or encoded. | 
| 58   bool frame_pending_ = false; | 78   bool frame_pending_ = false; | 
| 59 | 79 | 
| 60   base::TimeDelta rtt_estimate_; | 80   base::TimeDelta rtt_estimate_; | 
| 61 | 81 | 
| 62   // Set to true when encoding unchanged frames for top-off. | 82   // Set to true when encoding unchanged frames for top-off. | 
| 63   bool top_off_is_active_ = false; | 83   bool top_off_is_active_ = false; | 
| 64 | 84 | 
| 65   // Accumulator for capture and encoder delay history. | 85   // Accumulator for capture and encoder delay history. | 
| 66   RunningSamples frame_processing_delay_us_; | 86   RunningSamples frame_processing_delay_us_; | 
| 67 | 87 | 
| 68   // Accumulator for updated region area in the previously encoded frames. | 88   // Accumulator for updated region area in the previously encoded frames. | 
| 69   RunningSamples updated_region_area_; | 89   RunningSamples updated_region_area_; | 
| 70 | 90 | 
| 71   base::OneShotTimer capture_timer_; | 91   base::OneShotTimer capture_timer_; | 
| 72 | 92 | 
| 73   base::ThreadChecker thread_checker_; | 93   base::ThreadChecker thread_checker_; | 
| 74   base::WeakPtrFactory<WebrtcFrameSchedulerSimple> weak_factory_; | 94   base::WeakPtrFactory<WebrtcFrameSchedulerSimple> weak_factory_; | 
| 75 }; | 95 }; | 
| 76 | 96 | 
| 77 }  // namespace protocol | 97 }  // namespace protocol | 
| 78 }  // namespace remoting | 98 }  // namespace remoting | 
| 79 | 99 | 
| 80 #endif  // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 100 #endif  // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_SIMPLE_H_ | 
| OLD | NEW | 
|---|