Fix AudioPump to pause the stream when the network is congested.
[chromium-blink-merge.git] / remoting / client / software_video_renderer.h
blob11be6dc0eae679c7800a71911b722ed4798f1fb1
1 // Copyright 2014 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.
5 #ifndef REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_
6 #define REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "remoting/client/chromoting_stats.h"
11 #include "remoting/client/frame_consumer_proxy.h"
12 #include "remoting/client/frame_producer.h"
13 #include "remoting/client/video_renderer.h"
14 #include "remoting/protocol/video_stub.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
17 namespace base {
18 class SingleThreadTaskRunner;
19 } // namespace base
21 namespace remoting {
23 class ChromotingStats;
25 // Implementation of VideoRenderer interface that decodes frame on CPU (on a
26 // decode thread) and then passes decoded frames to a FrameConsumer.
27 // FrameProducer methods can be called on any thread. All other methods must be
28 // called on the main thread. Owned must ensure that this class outlives
29 // FrameConsumer (which calls FrameProducer interface).
30 class SoftwareVideoRenderer : public VideoRenderer,
31 public protocol::VideoStub,
32 public FrameProducer,
33 public base::NonThreadSafe {
34 public:
35 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|,
36 // outputting to |consumer|. The |main_task_runner_| is responsible for
37 // receiving and queueing packets. The |decode_task_runner_| is responsible
38 // for decoding the video packets.
39 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer.
40 SoftwareVideoRenderer(
41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
42 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner,
43 scoped_refptr<FrameConsumerProxy> consumer);
44 ~SoftwareVideoRenderer() override;
46 // VideoRenderer interface.
47 void OnSessionConfig(const protocol::SessionConfig& config) override;
48 ChromotingStats* GetStats() override;
49 protocol::VideoStub* GetVideoStub() override;
51 // protocol::VideoStub interface.
52 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
53 const base::Closure& done) override;
55 // FrameProducer implementation. These methods may be called before we are
56 // Initialize()d, or we know the source screen size. These methods may be
57 // called on any thread.
59 // TODO(sergeyu): On Android a separate display thread is used for drawing.
60 // FrameConsumer calls FrameProducer on that thread. Can we avoid having a
61 // separate display thread? E.g. can we do everything on the decode thread?
62 void DrawBuffer(webrtc::DesktopFrame* buffer) override;
63 void InvalidateRegion(const webrtc::DesktopRegion& region) override;
64 void RequestReturnBuffers(const base::Closure& done) override;
65 void SetOutputSizeAndClip(const webrtc::DesktopSize& view_size,
66 const webrtc::DesktopRect& clip_area) override;
68 private:
69 class Core;
71 // Callback method when a VideoPacket is processed. |decode_start| contains
72 // the timestamp when the packet will start to be processed.
73 void OnPacketDone(base::Time decode_start, const base::Closure& done);
75 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_;
76 scoped_ptr<Core> core_;
78 ChromotingStats stats_;
80 // Keep track of the latest event timestamp bounced back from the host.
81 int64 latest_event_timestamp_;
83 base::WeakPtrFactory<SoftwareVideoRenderer> weak_factory_;
85 DISALLOW_COPY_AND_ASSIGN(SoftwareVideoRenderer);
88 } // namespace remoting
90 #endif // REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_