| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "webkit/renderer/media/simple_video_frame_provider.h" | 5 #include "content/shell/renderer/shell_video_frame_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 11 | 11 |
| 12 namespace webkit_media { | 12 namespace content { |
| 13 | 13 |
| 14 SimpleVideoFrameProvider::SimpleVideoFrameProvider( | 14 ShellVideoFrameProvider::ShellVideoFrameProvider( |
| 15 const gfx::Size& size, | 15 const gfx::Size& size, |
| 16 const base::TimeDelta& frame_duration, | 16 const base::TimeDelta& frame_duration, |
| 17 const base::Closure& error_cb, | 17 const base::Closure& error_cb, |
| 18 const VideoFrameProvider::RepaintCB& repaint_cb) | 18 const VideoFrameProvider::RepaintCB& repaint_cb) |
| 19 : message_loop_proxy_(base::MessageLoopProxy::current()), | 19 : message_loop_proxy_(base::MessageLoopProxy::current()), |
| 20 size_(size), | 20 size_(size), |
| 21 state_(kStopped), | 21 state_(kStopped), |
| 22 frame_duration_(frame_duration), | 22 frame_duration_(frame_duration), |
| 23 error_cb_(error_cb), | 23 error_cb_(error_cb), |
| 24 repaint_cb_(repaint_cb) { | 24 repaint_cb_(repaint_cb) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 SimpleVideoFrameProvider::~SimpleVideoFrameProvider() {} | 27 ShellVideoFrameProvider::~ShellVideoFrameProvider() {} |
| 28 | 28 |
| 29 void SimpleVideoFrameProvider::Start() { | 29 void ShellVideoFrameProvider::Start() { |
| 30 DVLOG(1) << "SimpleVideoFrameProvider::Start"; | 30 DVLOG(1) << "ShellVideoFrameProvider::Start"; |
| 31 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 31 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 32 state_ = kStarted; | 32 state_ = kStarted; |
| 33 message_loop_proxy_->PostTask( | 33 message_loop_proxy_->PostTask( |
| 34 FROM_HERE, | 34 FROM_HERE, |
| 35 base::Bind(&SimpleVideoFrameProvider::GenerateFrame, this)); | 35 base::Bind(&ShellVideoFrameProvider::GenerateFrame, this)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SimpleVideoFrameProvider::Stop() { | 38 void ShellVideoFrameProvider::Stop() { |
| 39 DVLOG(1) << "SimpleVideoFrameProvider::Stop"; | 39 DVLOG(1) << "ShellVideoFrameProvider::Stop"; |
| 40 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 40 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 41 state_ = kStopped; | 41 state_ = kStopped; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SimpleVideoFrameProvider::Play() { | 44 void ShellVideoFrameProvider::Play() { |
| 45 DVLOG(1) << "SimpleVideoFrameProvider::Play"; | 45 DVLOG(1) << "ShellVideoFrameProvider::Play"; |
| 46 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 46 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 47 if (state_ == kPaused) | 47 if (state_ == kPaused) |
| 48 state_ = kStarted; | 48 state_ = kStarted; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SimpleVideoFrameProvider::Pause() { | 51 void ShellVideoFrameProvider::Pause() { |
| 52 DVLOG(1) << "SimpleVideoFrameProvider::Pause"; | 52 DVLOG(1) << "ShellVideoFrameProvider::Pause"; |
| 53 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 53 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 54 if (state_ == kStarted) | 54 if (state_ == kStarted) |
| 55 state_ = kPaused; | 55 state_ = kPaused; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void SimpleVideoFrameProvider::GenerateFrame() { | 58 void ShellVideoFrameProvider::GenerateFrame() { |
| 59 DVLOG(1) << "SimpleVideoFrameProvider::GenerateFrame"; | 59 DVLOG(1) << "ShellVideoFrameProvider::GenerateFrame"; |
| 60 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 60 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 61 if (state_ == kStopped) | 61 if (state_ == kStopped) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 if (state_ == kStarted) { | 64 if (state_ == kStarted) { |
| 65 // Always allocate a new frame filled with white color. | 65 // Always allocate a new frame filled with white color. |
| 66 scoped_refptr<media::VideoFrame> video_frame = | 66 scoped_refptr<media::VideoFrame> video_frame = |
| 67 media::VideoFrame::CreateColorFrame( | 67 media::VideoFrame::CreateColorFrame( |
| 68 size_, 255, 128, 128, current_time_); | 68 size_, 255, 128, 128, current_time_); |
| 69 | 69 |
| 70 // TODO(wjia): set pixel data to pre-defined patterns if it's desired to | 70 // TODO(wjia): set pixel data to pre-defined patterns if it's desired to |
| 71 // verify frame content. | 71 // verify frame content. |
| 72 | 72 |
| 73 repaint_cb_.Run(video_frame); | 73 repaint_cb_.Run(video_frame); |
| 74 } | 74 } |
| 75 | 75 |
| 76 current_time_ += frame_duration_; | 76 current_time_ += frame_duration_; |
| 77 message_loop_proxy_->PostDelayedTask( | 77 message_loop_proxy_->PostDelayedTask( |
| 78 FROM_HERE, | 78 FROM_HERE, |
| 79 base::Bind(&SimpleVideoFrameProvider::GenerateFrame, this), | 79 base::Bind(&ShellVideoFrameProvider::GenerateFrame, this), |
| 80 frame_duration_); | 80 frame_duration_); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace webkit_media | 83 } // namespace content |
| OLD | NEW |