Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / shell / renderer / layout_test / test_video_frame_provider.cc
blob97ecb02e361ec8a5bb5c69116de8db5c2d1e6f72
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/shell/renderer/layout_test/test_video_frame_provider.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "media/base/video_frame.h"
13 namespace content {
15 TestVideoFrameProvider::TestVideoFrameProvider(
16 const gfx::Size& size,
17 const base::TimeDelta& frame_duration,
18 const base::Closure& error_cb,
19 const VideoFrameProvider::RepaintCB& repaint_cb)
20 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
21 size_(size),
22 state_(kStopped),
23 frame_duration_(frame_duration),
24 error_cb_(error_cb),
25 repaint_cb_(repaint_cb) {
28 TestVideoFrameProvider::~TestVideoFrameProvider() {}
30 void TestVideoFrameProvider::Start() {
31 DVLOG(1) << "TestVideoFrameProvider::Start";
32 DCHECK(task_runner_->BelongsToCurrentThread());
33 state_ = kStarted;
34 task_runner_->PostTask(
35 FROM_HERE, base::Bind(&TestVideoFrameProvider::GenerateFrame, this));
38 void TestVideoFrameProvider::Stop() {
39 DVLOG(1) << "TestVideoFrameProvider::Stop";
40 DCHECK(task_runner_->BelongsToCurrentThread());
41 state_ = kStopped;
44 void TestVideoFrameProvider::Play() {
45 DVLOG(1) << "TestVideoFrameProvider::Play";
46 DCHECK(task_runner_->BelongsToCurrentThread());
47 if (state_ == kPaused)
48 state_ = kStarted;
51 void TestVideoFrameProvider::Pause() {
52 DVLOG(1) << "TestVideoFrameProvider::Pause";
53 DCHECK(task_runner_->BelongsToCurrentThread());
54 if (state_ == kStarted)
55 state_ = kPaused;
58 void TestVideoFrameProvider::GenerateFrame() {
59 DVLOG(1) << "TestVideoFrameProvider::GenerateFrame";
60 DCHECK(task_runner_->BelongsToCurrentThread());
61 if (state_ == kStopped)
62 return;
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 task_runner_->PostDelayedTask(
78 FROM_HERE, base::Bind(&TestVideoFrameProvider::GenerateFrame, this),
79 frame_duration_);
82 } // namespace content