1 // Copyright 2015 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_TEST_TEST_VIDEO_RENDERER_H_
6 #define REMOTING_TEST_TEST_VIDEO_RENDERER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/thread_checker.h"
11 #include "remoting/client/video_renderer.h"
12 #include "remoting/protocol/session_config.h"
13 #include "remoting/protocol/video_stub.h"
17 class SingleThreadTaskRunner
;
30 // Processes video packets as they are received from the remote host. Must be
31 // used from a thread running a message loop and this class will use that
32 // message loop to execute the done callbacks passed by the caller of
33 // ProcessVideoPacket.
34 class TestVideoRenderer
: public VideoRenderer
, public protocol::VideoStub
{
37 ~TestVideoRenderer() override
;
39 // VideoRenderer interface.
40 void OnSessionConfig(const protocol::SessionConfig
& config
) override
;
41 ChromotingStats
* GetStats() override
;
42 protocol::VideoStub
* GetVideoStub() override
;
44 // protocol::VideoStub interface.
45 void ProcessVideoPacket(scoped_ptr
<VideoPacket
> video_packet
,
46 const base::Closure
& done
) override
;
48 // Initialize a decoder to decode video packets.
49 void SetCodecForDecoding(const protocol::ChannelConfig::Codec codec
);
51 // Returns a copy of the current frame.
52 scoped_ptr
<webrtc::DesktopFrame
> GetCurrentFrameForTest() const;
54 // Gets a weak pointer for this object.
55 base::WeakPtr
<TestVideoRenderer
> GetWeakPtr() {
56 return weak_factory_
.GetWeakPtr();
59 // Set expected rect and average color for comparison and the callback will be
60 // called when the pattern is matched.
61 void ExpectAverageColorInRect(
62 const webrtc::DesktopRect
& expected_rect
,
63 const RGBValue
& expected_average_color
,
64 const base::Closure
& image_pattern_matched_callback
);
66 // Turn on/off saving video frames to disk.
67 void SaveFrameDataToDisk(bool save_frame_data_to_disk
);
70 // The actual implementation resides in Core class.
72 scoped_ptr
<Core
> core_
;
74 // Used to ensure TestVideoRenderer methods are called on the same thread.
75 base::ThreadChecker thread_checker_
;
77 // Used to decode and process video packets.
78 scoped_ptr
<base::Thread
> video_decode_thread_
;
80 // Used to post tasks to video decode thread.
81 scoped_refptr
<base::SingleThreadTaskRunner
> video_decode_task_runner_
;
83 // Used to weakly bind |this| to methods.
84 // NOTE: Weak pointers must be invalidated before all other member variables.
85 base::WeakPtrFactory
<TestVideoRenderer
> weak_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(TestVideoRenderer
);
91 } // namespace remoting
93 #endif // REMOTING_TEST_TEST_VIDEO_RENDERER_H_