| 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_impl.h" | 5 #include "content/renderer/media/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/renderer/media/texttrack_impl.h" | 31 #include "content/renderer/media/texttrack_impl.h" |
| 32 #include "content/renderer/media/webaudiosourceprovider_impl.h" | 32 #include "content/renderer/media/webaudiosourceprovider_impl.h" |
| 33 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" | 33 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 34 #include "content/renderer/media/webinbandtexttrack_impl.h" | 34 #include "content/renderer/media/webinbandtexttrack_impl.h" |
| 35 #include "content/renderer/media/webmediaplayer_delegate.h" | 35 #include "content/renderer/media/webmediaplayer_delegate.h" |
| 36 #include "content/renderer/media/webmediaplayer_params.h" | 36 #include "content/renderer/media/webmediaplayer_params.h" |
| 37 #include "content/renderer/media/webmediaplayer_util.h" | 37 #include "content/renderer/media/webmediaplayer_util.h" |
| 38 #include "content/renderer/media/webmediasource_impl.h" | 38 #include "content/renderer/media/webmediasource_impl.h" |
| 39 #include "content/renderer/pepper/pepper_webplugin_impl.h" | 39 #include "content/renderer/pepper/pepper_webplugin_impl.h" |
| 40 #include "content/renderer/render_thread_impl.h" | 40 #include "content/renderer/render_thread_impl.h" |
| 41 #include "gpu/GLES2/gl2extchromium.h" | |
| 42 #include "gpu/command_buffer/common/mailbox_holder.h" | |
| 43 #include "media/audio/null_audio_sink.h" | 41 #include "media/audio/null_audio_sink.h" |
| 44 #include "media/base/audio_hardware_config.h" | 42 #include "media/base/audio_hardware_config.h" |
| 45 #include "media/base/bind_to_current_loop.h" | 43 #include "media/base/bind_to_current_loop.h" |
| 46 #include "media/base/filter_collection.h" | 44 #include "media/base/filter_collection.h" |
| 47 #include "media/base/limits.h" | 45 #include "media/base/limits.h" |
| 48 #include "media/base/media_log.h" | 46 #include "media/base/media_log.h" |
| 49 #include "media/base/media_switches.h" | 47 #include "media/base/media_switches.h" |
| 50 #include "media/base/pipeline.h" | 48 #include "media/base/pipeline.h" |
| 51 #include "media/base/text_renderer.h" | 49 #include "media/base/text_renderer.h" |
| 52 #include "media/base/video_frame.h" | 50 #include "media/base/video_frame.h" |
| 53 #include "media/filters/audio_renderer_impl.h" | 51 #include "media/filters/audio_renderer_impl.h" |
| 54 #include "media/filters/chunk_demuxer.h" | 52 #include "media/filters/chunk_demuxer.h" |
| 55 #include "media/filters/ffmpeg_audio_decoder.h" | 53 #include "media/filters/ffmpeg_audio_decoder.h" |
| 56 #include "media/filters/ffmpeg_demuxer.h" | 54 #include "media/filters/ffmpeg_demuxer.h" |
| 57 #include "media/filters/ffmpeg_video_decoder.h" | 55 #include "media/filters/ffmpeg_video_decoder.h" |
| 58 #include "media/filters/gpu_video_accelerator_factories.h" | 56 #include "media/filters/gpu_video_accelerator_factories.h" |
| 59 #include "media/filters/gpu_video_decoder.h" | 57 #include "media/filters/gpu_video_decoder.h" |
| 60 #include "media/filters/opus_audio_decoder.h" | 58 #include "media/filters/opus_audio_decoder.h" |
| 61 #include "media/filters/video_renderer_impl.h" | 59 #include "media/filters/video_renderer_impl.h" |
| 62 #include "media/filters/vpx_video_decoder.h" | 60 #include "media/filters/vpx_video_decoder.h" |
| 63 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" | 61 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" |
| 62 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 64 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 63 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
| 65 #include "third_party/WebKit/public/platform/WebRect.h" | 64 #include "third_party/WebKit/public/platform/WebRect.h" |
| 66 #include "third_party/WebKit/public/platform/WebSize.h" | 65 #include "third_party/WebKit/public/platform/WebSize.h" |
| 67 #include "third_party/WebKit/public/platform/WebString.h" | 66 #include "third_party/WebKit/public/platform/WebString.h" |
| 68 #include "third_party/WebKit/public/platform/WebURL.h" | 67 #include "third_party/WebKit/public/platform/WebURL.h" |
| 69 #include "third_party/WebKit/public/web/WebDocument.h" | 68 #include "third_party/WebKit/public/web/WebDocument.h" |
| 70 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 69 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 71 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 70 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 72 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 71 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 73 #include "third_party/WebKit/public/web/WebView.h" | 72 #include "third_party/WebKit/public/web/WebView.h" |
| 74 #include "v8/include/v8.h" | 73 #include "v8/include/v8.h" |
| 74 #include "webkit/common/gpu/context_provider_web_context.h" |
| 75 #include "webkit/common/gpu/webgraphicscontext3d_impl.h" |
| 75 | 76 |
| 76 #if defined(ENABLE_PEPPER_CDMS) | 77 #if defined(ENABLE_PEPPER_CDMS) |
| 77 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" | 78 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" |
| 78 #endif | 79 #endif |
| 79 | 80 |
| 80 using blink::WebCanvas; | 81 using blink::WebCanvas; |
| 81 using blink::WebMediaPlayer; | 82 using blink::WebMediaPlayer; |
| 82 using blink::WebRect; | 83 using blink::WebRect; |
| 83 using blink::WebSize; | 84 using blink::WebSize; |
| 84 using blink::WebString; | 85 using blink::WebString; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 111 // | 112 // |
| 112 // Also our timers are not very accurate (especially for ogg), which becomes | 113 // Also our timers are not very accurate (especially for ogg), which becomes |
| 113 // evident at low speeds and on Vista. Since other speeds are risky and outside | 114 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 114 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 115 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 115 const double kMinRate = 0.0625; | 116 const double kMinRate = 0.0625; |
| 116 const double kMaxRate = 16.0; | 117 const double kMaxRate = 16.0; |
| 117 | 118 |
| 118 // Prefix for histograms related to Encrypted Media Extensions. | 119 // Prefix for histograms related to Encrypted Media Extensions. |
| 119 const char* kMediaEme = "Media.EME."; | 120 const char* kMediaEme = "Media.EME."; |
| 120 | 121 |
| 121 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
| 122 public: | |
| 123 explicit SyncPointClientImpl( | |
| 124 blink::WebGraphicsContext3D* web_graphics_context) | |
| 125 : web_graphics_context_(web_graphics_context) {} | |
| 126 virtual ~SyncPointClientImpl() {} | |
| 127 virtual uint32 InsertSyncPoint() OVERRIDE { | |
| 128 return web_graphics_context_->insertSyncPoint(); | |
| 129 } | |
| 130 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { | |
| 131 web_graphics_context_->waitSyncPoint(sync_point); | |
| 132 } | |
| 133 | |
| 134 private: | |
| 135 blink::WebGraphicsContext3D* web_graphics_context_; | |
| 136 }; | |
| 137 | |
| 138 } // namespace | 122 } // namespace |
| 139 | 123 |
| 140 namespace content { | 124 namespace content { |
| 141 | 125 |
| 142 class BufferedDataSourceHostImpl; | 126 class BufferedDataSourceHostImpl; |
| 143 | 127 |
| 144 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 128 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 145 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 129 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 146 static_cast<int>(BufferedResourceLoader::k ## name), \ | 130 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 147 mismatching_enums) | 131 mismatching_enums) |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 524 |
| 541 // TODO(scherkus): Clarify paint() API contract to better understand when and | 525 // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 542 // why it's being called. For example, today paint() is called when: | 526 // why it's being called. For example, today paint() is called when: |
| 543 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 527 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 544 // - We're painting to a canvas | 528 // - We're painting to a canvas |
| 545 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 529 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
| 546 scoped_refptr<media::VideoFrame> video_frame = | 530 scoped_refptr<media::VideoFrame> video_frame = |
| 547 GetCurrentFrameFromCompositor(); | 531 GetCurrentFrameFromCompositor(); |
| 548 | 532 |
| 549 gfx::Rect gfx_rect(rect); | 533 gfx::Rect gfx_rect(rect); |
| 550 skcanvas_video_renderer_.Paint(video_frame.get(), canvas, gfx_rect, alpha); | 534 scoped_refptr<cc::ContextProvider> context_provider = |
| 535 RenderThreadImpl::current()->SharedMainThreadContextProvider(); |
| 536 media::SkCanvasVideoRenderer::ContextProvider provider{ |
| 537 context_provider->ContextGL(), context_provider->GrContext()}; |
| 538 skcanvas_video_renderer_.Paint( |
| 539 video_frame.get(), canvas, gfx_rect, alpha, &provider); |
| 551 } | 540 } |
| 552 | 541 |
| 553 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 542 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
| 554 if (data_source_) | 543 if (data_source_) |
| 555 return data_source_->HasSingleOrigin(); | 544 return data_source_->HasSingleOrigin(); |
| 556 return true; | 545 return true; |
| 557 } | 546 } |
| 558 | 547 |
| 559 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 548 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
| 560 if (data_source_) | 549 if (data_source_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 unsigned int texture, | 588 unsigned int texture, |
| 600 unsigned int level, | 589 unsigned int level, |
| 601 unsigned int internal_format, | 590 unsigned int internal_format, |
| 602 unsigned int type, | 591 unsigned int type, |
| 603 bool premultiply_alpha, | 592 bool premultiply_alpha, |
| 604 bool flip_y) { | 593 bool flip_y) { |
| 605 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 594 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 606 | 595 |
| 607 scoped_refptr<media::VideoFrame> video_frame = | 596 scoped_refptr<media::VideoFrame> video_frame = |
| 608 GetCurrentFrameFromCompositor(); | 597 GetCurrentFrameFromCompositor(); |
| 609 | 598 if (!video_frame || |
| 610 if (!video_frame) | 599 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) |
| 611 return false; | |
| 612 if (video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) | |
| 613 return false; | 600 return false; |
| 614 | 601 |
| 615 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 602 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
| 616 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 603 // GLES2Interface. |
| 617 return false; | 604 gpu::gles2::GLES2Interface* gl = |
| 618 | 605 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context) |
| 619 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 606 ->GetGLInterface(); |
| 620 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 607 skcanvas_video_renderer_.CopyVideoFrameToTexture(gl, |
| 621 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 608 video_frame.get(), |
| 622 | 609 texture, |
| 623 // The video is stored in a unmultiplied format, so premultiply | 610 level, |
| 624 // if necessary. | 611 internal_format, |
| 625 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 612 type, |
| 626 premultiply_alpha); | 613 premultiply_alpha, |
| 627 // Application itself needs to take care of setting the right flip_y | 614 flip_y); |
| 628 // value down to get the expected result. | |
| 629 // flip_y==true means to reverse the video orientation while | |
| 630 // flip_y==false means to keep the intrinsic orientation. | |
| 631 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
| 632 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
| 633 source_texture, | |
| 634 texture, | |
| 635 level, | |
| 636 internal_format, | |
| 637 type); | |
| 638 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
| 639 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 640 false); | |
| 641 | |
| 642 web_graphics_context->deleteTexture(source_texture); | |
| 643 web_graphics_context->flush(); | |
| 644 | |
| 645 SyncPointClientImpl client(web_graphics_context); | |
| 646 video_frame->UpdateReleaseSyncPoint(&client); | |
| 647 return true; | 615 return true; |
| 648 } | 616 } |
| 649 | 617 |
| 650 // Helper functions to report media EME related stats to UMA. They follow the | 618 // Helper functions to report media EME related stats to UMA. They follow the |
| 651 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and | 619 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and |
| 652 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is | 620 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is |
| 653 // that UMA_* macros require the names to be constant throughout the process' | 621 // that UMA_* macros require the names to be constant throughout the process' |
| 654 // lifetime. | 622 // lifetime. |
| 655 static void EmeUMAHistogramEnumeration(const std::string& key_system, | 623 static void EmeUMAHistogramEnumeration(const std::string& key_system, |
| 656 const std::string& method, | 624 const std::string& method, |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 compositor_task_runner_->PostTask(FROM_HERE, | 1293 compositor_task_runner_->PostTask(FROM_HERE, |
| 1326 base::Bind(&GetCurrentFrameAndSignal, | 1294 base::Bind(&GetCurrentFrameAndSignal, |
| 1327 base::Unretained(compositor_), | 1295 base::Unretained(compositor_), |
| 1328 &video_frame, | 1296 &video_frame, |
| 1329 &event)); | 1297 &event)); |
| 1330 event.Wait(); | 1298 event.Wait(); |
| 1331 return video_frame; | 1299 return video_frame; |
| 1332 } | 1300 } |
| 1333 | 1301 |
| 1334 } // namespace content | 1302 } // namespace content |
| OLD | NEW |