Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | |
| 6 #define REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/single_thread_task_runner.h" | |
| 13 #include "base/task/cancelable_task_tracker.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 #include "remoting/codec/video_encoder.h" | |
| 17 #include "remoting/protocol/webrtc_transport.h" | |
| 18 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | |
| 19 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
| 20 | |
| 21 namespace remoting { | |
| 22 namespace protocol { | |
| 23 | |
| 24 // Class responsible for scheduling frames for encode and hand-over to | |
| 25 // WebRtc transport for sending across the network. | |
| 26 class WebRtcFrameScheduler : public webrtc::DesktopCapturer::Callback { | |
|
Sergey Ulanov
2016/03/31 22:06:19
nit: In other places we use Webrtc prefix with low
Irfan
2016/04/05 21:23:27
I feel like this is something remoting should fix
| |
| 27 public: | |
| 28 typedef base::Callback<void(const webrtc::DesktopSize& size)> SizeCallback; | |
| 29 | |
| 30 WebRtcFrameScheduler( | |
| 31 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | |
| 32 scoped_ptr<webrtc::DesktopCapturer> capturer, | |
| 33 WebrtcTransport* webrtc_transport, | |
| 34 scoped_ptr<VideoEncoder> encoder); | |
| 35 ~WebRtcFrameScheduler() override; | |
| 36 | |
| 37 // Starts scheduling frames to be encoded and transported. | |
| 38 void Start(); | |
| 39 // Stops scheduling frames. | |
| 40 void Stop(); | |
| 41 | |
| 42 void SetSizeCallback(const SizeCallback& size_callback); | |
| 43 | |
| 44 private: | |
| 45 // webrtc::DesktopCapturer::Callback interface. | |
| 46 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | |
| 47 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | |
| 48 | |
| 49 // Callback for CaptureScheduler. | |
| 50 void CaptureNextFrame(); | |
| 51 | |
| 52 // Task running on the encoder thread to encode the |frame|. | |
| 53 void EncodeFrame(scoped_ptr<webrtc::DesktopFrame> frame); | |
| 54 void OnFrameEncoded(); | |
| 55 | |
| 56 void SetKeyFrameRequest(); | |
| 57 bool ClearAndGetKeyFrameRequest(); | |
| 58 | |
| 59 // Protects |key_frame_request_|. | |
| 60 mutable base::Lock lock_; | |
| 61 bool key_frame_request_; | |
| 62 | |
| 63 bool capture_pending_; | |
| 64 bool encode_pending_; | |
| 65 | |
| 66 webrtc::DesktopSize frame_size_; | |
| 67 SizeCallback size_callback_; | |
| 68 | |
| 69 // Task runner used to run |encoder_|. | |
| 70 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | |
| 71 base::CancelableTaskTracker task_tracker_; | |
| 72 base::CancelableTaskTracker::TaskId task_id_; | |
|
Sergey Ulanov
2016/03/31 22:06:19
task_id_ is not used anywhere.
Irfan
2016/04/05 21:23:27
Done.
| |
| 73 | |
| 74 // Capturer used to capture the screen. | |
| 75 scoped_ptr<webrtc::DesktopCapturer> capturer_; | |
| 76 | |
| 77 scoped_ptr<base::RepeatingTimer> capture_timer_; | |
| 78 | |
| 79 // Used to send across encoded frames. | |
| 80 WebrtcTransport* webrtc_transport_; | |
| 81 | |
| 82 // Used to encode captured frames. Always accessed on the encode thread. | |
| 83 scoped_ptr<VideoEncoder> encoder_; | |
| 84 | |
| 85 base::ThreadChecker thread_checker_; | |
| 86 base::TimeTicks last_capture_ticks_; | |
| 87 | |
| 88 base::WeakPtrFactory<WebRtcFrameScheduler> weak_factory_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(WebRtcFrameScheduler); | |
| 91 }; | |
| 92 | |
| 93 } // namespace protocol | |
| 94 } // namespace remoting | |
| 95 | |
| 96 #endif // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | |
| OLD | NEW |