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