OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 5 #ifndef REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
6 #define REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 6 #define REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
10 #include "remoting/client/chromoting_stats.h" | 11 #include "remoting/client/chromoting_stats.h" |
11 #include "remoting/client/frame_consumer_proxy.h" | 12 #include "remoting/client/frame_consumer.h" |
12 #include "remoting/client/frame_producer.h" | 13 #include "remoting/client/frame_producer.h" |
13 #include "remoting/client/video_renderer.h" | 14 #include "remoting/client/video_renderer.h" |
14 #include "remoting/protocol/video_stub.h" | 15 #include "remoting/protocol/video_stub.h" |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
19 } // namespace base | 20 } // namespace base |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 | 23 |
23 class ChromotingStats; | 24 class ChromotingStats; |
24 | 25 |
25 // Implementation of VideoRenderer interface that decodes frame on CPU (on a | 26 // Implementation of VideoRenderer interface that decodes frame on CPU (on a |
26 // decode thread) and then passes decoded frames to a FrameConsumer. | 27 // 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 // 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 // called on the main thread. |
29 // FrameConsumer (which calls FrameProducer interface). | |
30 class SoftwareVideoRenderer : public VideoRenderer, | 30 class SoftwareVideoRenderer : public VideoRenderer, |
31 public protocol::VideoStub, | 31 public protocol::VideoStub, |
32 public FrameProducer, | 32 public FrameProducer, |
33 public base::NonThreadSafe { | 33 public base::NonThreadSafe { |
34 public: | 34 public: |
35 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, | 35 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, |
36 // outputting to |consumer|. The |main_task_runner_| is responsible for | 36 // outputting to |consumer|. The |main_task_runner_| is responsible for |
37 // receiving and queueing packets. The |decode_task_runner_| is responsible | 37 // receiving and queueing packets. The |decode_task_runner_| is responsible |
38 // for decoding the video packets. | 38 // for decoding the video packets. |consumer| must remain valid until the |
39 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. | 39 // SoftwareVideoRenderer is destroyed, but the caller must also ensure that |
| 40 // the |consumer| makes no more FrameProducer API calls beyond that point. |
40 SoftwareVideoRenderer( | 41 SoftwareVideoRenderer( |
41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 42 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
42 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
43 scoped_refptr<FrameConsumerProxy> consumer); | 44 FrameConsumer* consumer); |
44 ~SoftwareVideoRenderer() override; | 45 ~SoftwareVideoRenderer() override; |
45 | 46 |
46 // VideoRenderer interface. | 47 // VideoRenderer interface. |
47 void OnSessionConfig(const protocol::SessionConfig& config) override; | 48 void OnSessionConfig(const protocol::SessionConfig& config) override; |
48 ChromotingStats* GetStats() override; | 49 ChromotingStats* GetStats() override; |
49 protocol::VideoStub* GetVideoStub() override; | 50 protocol::VideoStub* GetVideoStub() override; |
50 | 51 |
51 // protocol::VideoStub interface. | 52 // protocol::VideoStub interface. |
52 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 53 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
53 const base::Closure& done) override; | 54 const base::Closure& done) override; |
(...skipping 19 matching lines...) Expand all Loading... |
73 void OnPacketDone(base::Time decode_start, const base::Closure& done); | 74 void OnPacketDone(base::Time decode_start, const base::Closure& done); |
74 | 75 |
75 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | 76 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; |
76 scoped_ptr<Core> core_; | 77 scoped_ptr<Core> core_; |
77 | 78 |
78 ChromotingStats stats_; | 79 ChromotingStats stats_; |
79 | 80 |
80 // Keep track of the latest event timestamp bounced back from the host. | 81 // Keep track of the latest event timestamp bounced back from the host. |
81 int64 latest_event_timestamp_; | 82 int64 latest_event_timestamp_; |
82 | 83 |
| 84 // Used to decouple the Core from the FrameConsumer during teardown. |
| 85 base::WeakPtrFactory<FrameConsumer> weak_frame_consumer_; |
| 86 |
83 base::WeakPtrFactory<SoftwareVideoRenderer> weak_factory_; | 87 base::WeakPtrFactory<SoftwareVideoRenderer> weak_factory_; |
84 | 88 |
85 DISALLOW_COPY_AND_ASSIGN(SoftwareVideoRenderer); | 89 DISALLOW_COPY_AND_ASSIGN(SoftwareVideoRenderer); |
86 }; | 90 }; |
87 | 91 |
88 } // namespace remoting | 92 } // namespace remoting |
89 | 93 |
90 #endif // REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 94 #endif // REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
OLD | NEW |