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