1 // Copyright 2013 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 #include "content/test/test_video_frame_provider.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "media/base/video_frame.h"
14 TestVideoFrameProvider::TestVideoFrameProvider(
15 const gfx::Size
& size
,
16 const base::TimeDelta
& frame_duration
,
17 const base::Closure
& error_cb
,
18 const VideoFrameProvider::RepaintCB
& repaint_cb
)
19 : message_loop_proxy_(base::MessageLoopProxy::current()),
22 frame_duration_(frame_duration
),
24 repaint_cb_(repaint_cb
) {
27 TestVideoFrameProvider::~TestVideoFrameProvider() {}
29 void TestVideoFrameProvider::Start() {
30 DVLOG(1) << "TestVideoFrameProvider::Start";
31 DCHECK(message_loop_proxy_
->BelongsToCurrentThread());
33 message_loop_proxy_
->PostTask(
35 base::Bind(&TestVideoFrameProvider::GenerateFrame
, this));
38 void TestVideoFrameProvider::Stop() {
39 DVLOG(1) << "TestVideoFrameProvider::Stop";
40 DCHECK(message_loop_proxy_
->BelongsToCurrentThread());
44 void TestVideoFrameProvider::Play() {
45 DVLOG(1) << "TestVideoFrameProvider::Play";
46 DCHECK(message_loop_proxy_
->BelongsToCurrentThread());
47 if (state_
== kPaused
)
51 void TestVideoFrameProvider::Pause() {
52 DVLOG(1) << "TestVideoFrameProvider::Pause";
53 DCHECK(message_loop_proxy_
->BelongsToCurrentThread());
54 if (state_
== kStarted
)
58 void TestVideoFrameProvider::GenerateFrame() {
59 DVLOG(1) << "TestVideoFrameProvider::GenerateFrame";
60 DCHECK(message_loop_proxy_
->BelongsToCurrentThread());
61 if (state_
== kStopped
)
64 if (state_
== kStarted
) {
65 // Always allocate a new frame filled with white color.
66 scoped_refptr
<media::VideoFrame
> video_frame
=
67 media::VideoFrame::CreateColorFrame(
68 size_
, 255, 128, 128, current_time_
);
70 // TODO(wjia): set pixel data to pre-defined patterns if it's desired to
71 // verify frame content.
73 repaint_cb_
.Run(video_frame
);
76 current_time_
+= frame_duration_
;
77 message_loop_proxy_
->PostDelayedTask(
79 base::Bind(&TestVideoFrameProvider::GenerateFrame
, this),
83 } // namespace content