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 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "content/public/renderer/media_stream_renderer_factory.h" | 21 #include "content/public/renderer/media_stream_renderer_factory.h" |
| 22 #include "content/public/renderer/render_view.h" | 22 #include "content/public/renderer/render_view.h" |
| 23 #include "content/public/renderer/video_frame_provider.h" | 23 #include "content/public/renderer/video_frame_provider.h" |
| 24 #include "content/renderer/render_frame_impl.h" | 24 #include "content/renderer/render_frame_impl.h" |
| 25 #include "content/renderer/render_thread_impl.h" | 25 #include "content/renderer/render_thread_impl.h" |
| 26 #include "gpu/blink/webgraphicscontext3d_impl.h" | 26 #include "gpu/blink/webgraphicscontext3d_impl.h" |
| 27 #include "media/base/media_log.h" | 27 #include "media/base/media_log.h" |
| 28 #include "media/base/media_switches.h" | 28 #include "media/base/media_switches.h" |
| 29 #include "media/base/video_frame.h" | 29 #include "media/base/video_frame.h" |
| 30 #include "media/base/video_rotation.h" | 30 #include "media/base/video_rotation.h" |
| 31 #include "media/base/video_util.h" | |
| 32 #include "media/blink/webmediaplayer_delegate.h" | 31 #include "media/blink/webmediaplayer_delegate.h" |
| 33 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 32 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 34 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 33 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 35 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 34 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 36 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 35 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 37 #include "third_party/WebKit/public/platform/WebRect.h" | 36 #include "third_party/WebKit/public/platform/WebRect.h" |
| 38 #include "third_party/WebKit/public/platform/WebSize.h" | 37 #include "third_party/WebKit/public/platform/WebSize.h" |
| 39 #include "third_party/WebKit/public/platform/WebURL.h" | 38 #include "third_party/WebKit/public/platform/WebURL.h" |
| 40 #include "third_party/WebKit/public/web/WebFrame.h" | 39 #include "third_party/WebKit/public/web/WebFrame.h" |
| 41 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" | 40 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" |
| 42 #include "third_party/WebKit/public/web/WebView.h" | 41 #include "third_party/WebKit/public/web/WebView.h" |
| 42 #include "third_party/libyuv/include/libyuv/convert.h" | |
| 43 #include "third_party/libyuv/include/libyuv/video_common.h" | |
| 43 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
| 44 | 45 |
| 45 using blink::WebCanvas; | 46 using blink::WebCanvas; |
| 46 using blink::WebMediaPlayer; | 47 using blink::WebMediaPlayer; |
| 47 using blink::WebRect; | 48 using blink::WebRect; |
| 48 using blink::WebSize; | 49 using blink::WebSize; |
| 49 | 50 |
| 50 namespace content { | 51 namespace content { |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 54 // This function copies |frame| to a new YV12 media::VideoFrame. | 55 // This function copies |frame| to a new I420 media::VideoFrame. |
| 55 scoped_refptr<media::VideoFrame> CopyFrameToYV12( | 56 scoped_refptr<media::VideoFrame> CopyFrameToI420( |
| 56 const scoped_refptr<media::VideoFrame>& frame, | 57 const scoped_refptr<media::VideoFrame>& frame, |
| 57 media::SkCanvasVideoRenderer* video_renderer) { | 58 media::SkCanvasVideoRenderer* video_renderer) { |
| 58 const scoped_refptr<media::VideoFrame> new_frame = | 59 const scoped_refptr<media::VideoFrame> new_frame = |
| 59 media::VideoFrame::CreateFrame(media::PIXEL_FORMAT_YV12, | 60 media::VideoFrame::CreateFrame(media::PIXEL_FORMAT_YV12, |
| 60 frame->coded_size(), frame->visible_rect(), | 61 frame->coded_size(), frame->visible_rect(), |
| 61 frame->natural_size(), frame->timestamp()); | 62 frame->natural_size(), frame->timestamp()); |
| 63 const gfx::Size& size = frame->coded_size(); | |
| 62 | 64 |
| 63 if (frame->HasTextures()) { | 65 if (frame->HasTextures()) { |
| 64 DCHECK(frame->format() == media::PIXEL_FORMAT_ARGB || | |
| 65 frame->format() == media::PIXEL_FORMAT_XRGB); | |
| 66 SkBitmap bitmap; | 66 SkBitmap bitmap; |
| 67 bitmap.allocN32Pixels(frame->visible_rect().width(), | 67 bitmap.allocN32Pixels(frame->visible_rect().width(), |
| 68 frame->visible_rect().height()); | 68 frame->visible_rect().height()); |
| 69 SkCanvas canvas(bitmap); | 69 SkCanvas canvas(bitmap); |
| 70 | 70 |
| 71 cc::ContextProvider* const provider = | 71 cc::ContextProvider* const provider = |
| 72 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 72 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
| 73 if (provider) { | 73 if (provider) { |
| 74 const media::Context3D context_3d = | 74 const media::Context3D context_3d = |
| 75 media::Context3D(provider->ContextGL(), provider->GrContext()); | 75 media::Context3D(provider->ContextGL(), provider->GrContext()); |
| 76 DCHECK(context_3d.gl); | 76 DCHECK(context_3d.gl); |
| 77 video_renderer->Copy(frame.get(), &canvas, context_3d); | 77 video_renderer->Copy(frame.get(), &canvas, context_3d); |
| 78 } else { | 78 } else { |
| 79 // GPU Process crashed. | 79 // GPU Process crashed. |
| 80 bitmap.eraseColor(SK_ColorTRANSPARENT); | 80 bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 81 } | 81 } |
| 82 media::CopyRGBToVideoFrame(reinterpret_cast<uint8*>(bitmap.getPixels()), | 82 libyuv::ConvertToI420(reinterpret_cast<uint8*>(bitmap.getPixels()), |
|
fbarchard
2015/10/14 06:47:36
Consider calling ARGBToI420.
ConvertToI420 expect
emircan
2015/10/14 21:02:32
Done.
| |
| 83 bitmap.rowBytes(), | 83 bitmap.getSize(), |
| 84 frame->visible_rect(), | 84 new_frame->data(media::VideoFrame::kYPlane), |
| 85 new_frame.get()); | 85 new_frame->stride(media::VideoFrame::kYPlane), |
| 86 new_frame->data(media::VideoFrame::kUPlane), | |
| 87 new_frame->stride(media::VideoFrame::kUPlane), | |
| 88 new_frame->data(media::VideoFrame::kVPlane), | |
| 89 new_frame->stride(media::VideoFrame::kVPlane), | |
| 90 0 /* crop_x */, | |
| 91 0 /* crop_y */, | |
| 92 bitmap.dimensions().fWidth, | |
| 93 bitmap.dimensions().fHeight, | |
| 94 size.width(), size.height(), | |
| 95 libyuv::kRotate0, libyuv::FOURCC_ARGB); | |
|
fbarchard
2015/10/14 06:47:36
Most code in media expects ABGR for Android. Can
emircan
2015/10/14 21:02:32
Sorry, I couldn't understand what you mean there.
fbarchard
2015/10/15 17:43:26
In media/blink/skcanvas_video_renderer.cc there ar
| |
| 86 } else { | 96 } else { |
| 87 DCHECK(frame->IsMappable()); | 97 DCHECK(frame->IsMappable()); |
| 88 DCHECK(frame->format() == media::PIXEL_FORMAT_YV12 || | 98 DCHECK(frame->format() == media::PIXEL_FORMAT_YV12 || |
| 89 frame->format() == media::PIXEL_FORMAT_I420); | 99 frame->format() == media::PIXEL_FORMAT_I420); |
| 90 for (size_t i = 0; i < media::VideoFrame::NumPlanes(frame->format()); ++i) { | 100 libyuv::I420Copy(frame->data(media::VideoFrame::kYPlane), |
| 91 media::CopyPlane(i, frame->data(i), frame->stride(i), | 101 frame->stride(media::VideoFrame::kYPlane), |
| 92 frame->rows(i), new_frame.get()); | 102 frame->data(media::VideoFrame::kUPlane), |
| 93 } | 103 frame->stride(media::VideoFrame::kUPlane), |
| 104 frame->data(media::VideoFrame::kVPlane), | |
| 105 frame->stride(media::VideoFrame::kVPlane), | |
| 106 new_frame->data(media::VideoFrame::kYPlane), | |
| 107 new_frame->stride(media::VideoFrame::kYPlane), | |
| 108 new_frame->data(media::VideoFrame::kUPlane), | |
| 109 new_frame->stride(media::VideoFrame::kUPlane), | |
| 110 new_frame->data(media::VideoFrame::kVPlane), | |
| 111 new_frame->stride(media::VideoFrame::kVPlane), | |
| 112 size.width(), size.height()); | |
| 94 } | 113 } |
| 95 return new_frame; | 114 return new_frame; |
| 96 } | 115 } |
| 97 | 116 |
| 98 } // anonymous namespace | 117 } // anonymous namespace |
| 99 | 118 |
| 100 WebMediaPlayerMS::WebMediaPlayerMS( | 119 WebMediaPlayerMS::WebMediaPlayerMS( |
| 101 blink::WebFrame* frame, | 120 blink::WebFrame* frame, |
| 102 blink::WebMediaPlayerClient* client, | 121 blink::WebMediaPlayerClient* client, |
| 103 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 122 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 DCHECK(thread_checker_.CalledOnValidThread()); | 744 DCHECK(thread_checker_.CalledOnValidThread()); |
| 726 base::AutoLock auto_lock(current_frame_lock_); | 745 base::AutoLock auto_lock(current_frame_lock_); |
| 727 if (!current_frame_.get()) | 746 if (!current_frame_.get()) |
| 728 return; | 747 return; |
| 729 | 748 |
| 730 // Copy the frame so that rendering can show the last received frame. | 749 // Copy the frame so that rendering can show the last received frame. |
| 731 // The original frame must not be referenced when the player is paused since | 750 // The original frame must not be referenced when the player is paused since |
| 732 // there might be a finite number of available buffers. E.g, video that | 751 // there might be a finite number of available buffers. E.g, video that |
| 733 // originates from a video camera. | 752 // originates from a video camera. |
| 734 scoped_refptr<media::VideoFrame> new_frame = | 753 scoped_refptr<media::VideoFrame> new_frame = |
| 735 CopyFrameToYV12(current_frame_, renderer); | 754 CopyFrameToI420(current_frame_, renderer); |
| 736 | 755 |
| 737 current_frame_ = new_frame; | 756 current_frame_ = new_frame; |
| 738 } | 757 } |
| 739 | 758 |
| 740 gfx::Size WebMediaPlayerMS::Compositor::GetCurrentSize() { | 759 gfx::Size WebMediaPlayerMS::Compositor::GetCurrentSize() { |
| 741 base::AutoLock auto_lock(current_frame_lock_); | 760 base::AutoLock auto_lock(current_frame_lock_); |
| 742 return current_frame_.get() ? current_frame_->natural_size() : gfx::Size(); | 761 return current_frame_.get() ? current_frame_->natural_size() : gfx::Size(); |
| 743 } | 762 } |
| 744 | 763 |
| 745 base::TimeDelta WebMediaPlayerMS::Compositor::GetCurrentTime() { | 764 base::TimeDelta WebMediaPlayerMS::Compositor::GetCurrentTime() { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 768 bool WebMediaPlayerMS::Compositor::GetAlgorithmEnabled() { | 787 bool WebMediaPlayerMS::Compositor::GetAlgorithmEnabled() { |
| 769 DCHECK(thread_checker_.CalledOnValidThread()); | 788 DCHECK(thread_checker_.CalledOnValidThread()); |
| 770 return !!frame_pool_; | 789 return !!frame_pool_; |
| 771 } | 790 } |
| 772 | 791 |
| 773 void WebMediaPlayerMS::Compositor::SetSerial(uint32 serial) { | 792 void WebMediaPlayerMS::Compositor::SetSerial(uint32 serial) { |
| 774 DCHECK(thread_checker_.CalledOnValidThread()); | 793 DCHECK(thread_checker_.CalledOnValidThread()); |
| 775 serial_ = serial; | 794 serial_ = serial; |
| 776 } | 795 } |
| 777 } // namespace content | 796 } // namespace content |
| OLD | NEW |