| 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 "content/renderer/media/webmediaplayer_ms.h" | 5 #include "content/renderer/media/webmediaplayer_ms.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "third_party/WebKit/public/platform/WebURL.h" | 32 #include "third_party/WebKit/public/platform/WebURL.h" |
| 33 #include "third_party/WebKit/public/web/WebFrame.h" | 33 #include "third_party/WebKit/public/web/WebFrame.h" |
| 34 #include "third_party/WebKit/public/web/WebView.h" | 34 #include "third_party/WebKit/public/web/WebView.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 | 36 |
| 37 using blink::WebCanvas; | 37 using blink::WebCanvas; |
| 38 using blink::WebMediaPlayer; | 38 using blink::WebMediaPlayer; |
| 39 using blink::WebRect; | 39 using blink::WebRect; |
| 40 using blink::WebSize; | 40 using blink::WebSize; |
| 41 | 41 |
| 42 namespace content { |
| 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // This function copies a YV12 or NATIVE_TEXTURE to a new YV12 | 46 // This function copies a YV12 or NATIVE_TEXTURE to a new YV12 |
| 45 // media::VideoFrame. | 47 // media::VideoFrame. |
| 46 scoped_refptr<media::VideoFrame> CopyFrameToYV12( | 48 scoped_refptr<media::VideoFrame> CopyFrameToYV12( |
| 47 const scoped_refptr<media::VideoFrame>& frame) { | 49 const scoped_refptr<media::VideoFrame>& frame, |
| 50 media::SkCanvasVideoRenderer* video_renderer) { |
| 48 DCHECK(frame->format() == media::VideoFrame::YV12 || | 51 DCHECK(frame->format() == media::VideoFrame::YV12 || |
| 49 frame->format() == media::VideoFrame::I420 || | 52 frame->format() == media::VideoFrame::I420 || |
| 50 frame->format() == media::VideoFrame::NATIVE_TEXTURE); | 53 frame->format() == media::VideoFrame::NATIVE_TEXTURE); |
| 51 scoped_refptr<media::VideoFrame> new_frame = | 54 scoped_refptr<media::VideoFrame> new_frame = |
| 52 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 55 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 53 frame->coded_size(), | 56 frame->coded_size(), |
| 54 frame->visible_rect(), | 57 frame->visible_rect(), |
| 55 frame->natural_size(), | 58 frame->natural_size(), |
| 56 frame->timestamp()); | 59 frame->timestamp()); |
| 57 | 60 |
| 58 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 61 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 59 SkBitmap bitmap; | 62 SkBitmap bitmap; |
| 60 bitmap.allocN32Pixels(frame->visible_rect().width(), | 63 bitmap.allocN32Pixels(frame->visible_rect().width(), |
| 61 frame->visible_rect().height()); | 64 frame->visible_rect().height()); |
| 62 frame->ReadPixelsFromNativeTexture(bitmap); | 65 SkCanvas canvas(bitmap); |
| 63 | 66 |
| 67 cc::ContextProvider* provider = |
| 68 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
| 69 if (provider) { |
| 70 media::Context3D context_3d = |
| 71 media::Context3D(provider->ContextGL(), provider->GrContext()); |
| 72 DCHECK(context_3d.gl); |
| 73 video_renderer->Copy(frame.get(), &canvas, context_3d); |
| 74 } else { |
| 75 // GPU Process crashed. |
| 76 bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 77 } |
| 64 media::CopyRGBToVideoFrame( | 78 media::CopyRGBToVideoFrame( |
| 65 reinterpret_cast<uint8*>(bitmap.getPixels()), | 79 reinterpret_cast<uint8*>(bitmap.getPixels()), |
| 66 bitmap.rowBytes(), | 80 bitmap.rowBytes(), |
| 67 frame->visible_rect(), | 81 frame->visible_rect(), |
| 68 new_frame.get()); | 82 new_frame.get()); |
| 69 } else { | 83 } else { |
| 70 size_t number_of_planes = | 84 size_t number_of_planes = |
| 71 media::VideoFrame::NumPlanes(frame->format()); | 85 media::VideoFrame::NumPlanes(frame->format()); |
| 72 for (size_t i = 0; i < number_of_planes; ++i) { | 86 for (size_t i = 0; i < number_of_planes; ++i) { |
| 73 media::CopyPlane(i, frame->data(i), frame->stride(i), | 87 media::CopyPlane(i, frame->data(i), frame->stride(i), |
| 74 frame->rows(i), new_frame.get()); | 88 frame->rows(i), new_frame.get()); |
| 75 } | 89 } |
| 76 } | 90 } |
| 77 return new_frame; | 91 return new_frame; |
| 78 } | 92 } |
| 79 | 93 |
| 80 } // anonymous namespace | 94 } // anonymous namespace |
| 81 | 95 |
| 82 namespace content { | |
| 83 | |
| 84 WebMediaPlayerMS::WebMediaPlayerMS( | 96 WebMediaPlayerMS::WebMediaPlayerMS( |
| 85 blink::WebFrame* frame, | 97 blink::WebFrame* frame, |
| 86 blink::WebMediaPlayerClient* client, | 98 blink::WebMediaPlayerClient* client, |
| 87 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 99 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 88 media::MediaLog* media_log, | 100 media::MediaLog* media_log, |
| 89 scoped_ptr<MediaStreamRendererFactory> factory) | 101 scoped_ptr<MediaStreamRendererFactory> factory) |
| 90 : frame_(frame), | 102 : frame_(frame), |
| 91 network_state_(WebMediaPlayer::NetworkStateEmpty), | 103 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 92 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 104 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 93 buffered_(static_cast<size_t>(0)), | 105 buffered_(static_cast<size_t>(0)), |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 225 |
| 214 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); | 226 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); |
| 215 | 227 |
| 216 if (!current_frame_.get()) | 228 if (!current_frame_.get()) |
| 217 return; | 229 return; |
| 218 | 230 |
| 219 // Copy the frame so that rendering can show the last received frame. | 231 // Copy the frame so that rendering can show the last received frame. |
| 220 // The original frame must not be referenced when the player is paused since | 232 // The original frame must not be referenced when the player is paused since |
| 221 // there might be a finite number of available buffers. E.g, video that | 233 // there might be a finite number of available buffers. E.g, video that |
| 222 // originates from a video camera. | 234 // originates from a video camera. |
| 223 scoped_refptr<media::VideoFrame> new_frame = CopyFrameToYV12(current_frame_); | 235 scoped_refptr<media::VideoFrame> new_frame = |
| 236 CopyFrameToYV12(current_frame_, &video_renderer_); |
| 237 |
| 224 base::AutoLock auto_lock(current_frame_lock_); | 238 base::AutoLock auto_lock(current_frame_lock_); |
| 225 current_frame_ = new_frame; | 239 current_frame_ = new_frame; |
| 226 } | 240 } |
| 227 | 241 |
| 228 bool WebMediaPlayerMS::supportsSave() const { | 242 bool WebMediaPlayerMS::supportsSave() const { |
| 229 DCHECK(thread_checker_.CalledOnValidThread()); | 243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 230 return false; | 244 return false; |
| 231 } | 245 } |
| 232 | 246 |
| 233 void WebMediaPlayerMS::seek(double seconds) { | 247 void WebMediaPlayerMS::seek(double seconds) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 GetClient()->readyStateChanged(); | 536 GetClient()->readyStateChanged(); |
| 523 } | 537 } |
| 524 | 538 |
| 525 blink::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { | 539 blink::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { |
| 526 DCHECK(thread_checker_.CalledOnValidThread()); | 540 DCHECK(thread_checker_.CalledOnValidThread()); |
| 527 DCHECK(client_); | 541 DCHECK(client_); |
| 528 return client_; | 542 return client_; |
| 529 } | 543 } |
| 530 | 544 |
| 531 } // namespace content | 545 } // namespace content |
| OLD | NEW |