Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: content/renderer/media/webmediaplayer_impl.cc

Issue 445013002: media: Optimize HW Video to 2D Canvas copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
64 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 62 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
63 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
65 #include "third_party/WebKit/public/platform/WebMediaSource.h" 64 #include "third_party/WebKit/public/platform/WebMediaSource.h"
66 #include "third_party/WebKit/public/platform/WebRect.h" 65 #include "third_party/WebKit/public/platform/WebRect.h"
67 #include "third_party/WebKit/public/platform/WebSize.h" 66 #include "third_party/WebKit/public/platform/WebSize.h"
68 #include "third_party/WebKit/public/platform/WebString.h" 67 #include "third_party/WebKit/public/platform/WebString.h"
69 #include "third_party/WebKit/public/platform/WebURL.h" 68 #include "third_party/WebKit/public/platform/WebURL.h"
70 #include "third_party/WebKit/public/web/WebDocument.h" 69 #include "third_party/WebKit/public/web/WebDocument.h"
71 #include "third_party/WebKit/public/web/WebLocalFrame.h" 70 #include "third_party/WebKit/public/web/WebLocalFrame.h"
72 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 71 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
73 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 72 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
74 #include "third_party/WebKit/public/web/WebView.h" 73 #include "third_party/WebKit/public/web/WebView.h"
75 #include "v8/include/v8.h" 74 #include "v8/include/v8.h"
75 #include "webkit/common/gpu/context_provider_web_context.h"
76 #include "webkit/common/gpu/webgraphicscontext3d_impl.h"
76 77
77 #if defined(ENABLE_PEPPER_CDMS) 78 #if defined(ENABLE_PEPPER_CDMS)
78 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" 79 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
79 #endif 80 #endif
80 81
81 using blink::WebCanvas; 82 using blink::WebCanvas;
82 using blink::WebMediaPlayer; 83 using blink::WebMediaPlayer;
83 using blink::WebRect; 84 using blink::WebRect;
84 using blink::WebSize; 85 using blink::WebSize;
85 using blink::WebString; 86 using blink::WebString;
(...skipping 26 matching lines...) Expand all
112 // 113 //
113 // Also our timers are not very accurate (especially for ogg), which becomes 114 // Also our timers are not very accurate (especially for ogg), which becomes
114 // evident at low speeds and on Vista. Since other speeds are risky and outside 115 // evident at low speeds and on Vista. Since other speeds are risky and outside
115 // the norms, we think 1/16x to 16x is a safe and useful range for now. 116 // the norms, we think 1/16x to 16x is a safe and useful range for now.
116 const double kMinRate = 0.0625; 117 const double kMinRate = 0.0625;
117 const double kMaxRate = 16.0; 118 const double kMaxRate = 16.0;
118 119
119 // Prefix for histograms related to Encrypted Media Extensions. 120 // Prefix for histograms related to Encrypted Media Extensions.
120 const char* kMediaEme = "Media.EME."; 121 const char* kMediaEme = "Media.EME.";
121 122
122 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
123 public:
124 explicit SyncPointClientImpl(
125 blink::WebGraphicsContext3D* web_graphics_context)
126 : web_graphics_context_(web_graphics_context) {}
127 virtual ~SyncPointClientImpl() {}
128 virtual uint32 InsertSyncPoint() OVERRIDE {
129 return web_graphics_context_->insertSyncPoint();
130 }
131 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {
132 web_graphics_context_->waitSyncPoint(sync_point);
133 }
134
135 private:
136 blink::WebGraphicsContext3D* web_graphics_context_;
137 };
138
139 // Used for calls to decryptor_ready_cb where the result can be ignored. 123 // Used for calls to decryptor_ready_cb where the result can be ignored.
140 void DoNothing(bool) { 124 void DoNothing(bool) {
141 } 125 }
142 126
143 } // namespace 127 } // namespace
144 128
145 namespace content { 129 namespace content {
146 130
147 class BufferedDataSourceHostImpl; 131 class BufferedDataSourceHostImpl;
148 132
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 535
552 // TODO(scherkus): Clarify paint() API contract to better understand when and 536 // TODO(scherkus): Clarify paint() API contract to better understand when and
553 // why it's being called. For example, today paint() is called when: 537 // why it's being called. For example, today paint() is called when:
554 // - We haven't reached HAVE_CURRENT_DATA and need to paint black 538 // - We haven't reached HAVE_CURRENT_DATA and need to paint black
555 // - We're painting to a canvas 539 // - We're painting to a canvas
556 // See http://crbug.com/341225 http://crbug.com/342621 for details. 540 // See http://crbug.com/341225 http://crbug.com/342621 for details.
557 scoped_refptr<media::VideoFrame> video_frame = 541 scoped_refptr<media::VideoFrame> video_frame =
558 GetCurrentFrameFromCompositor(); 542 GetCurrentFrameFromCompositor();
559 543
560 gfx::Rect gfx_rect(rect); 544 gfx::Rect gfx_rect(rect);
561 545 scoped_refptr<cc::ContextProvider> context_provider =
546 RenderThreadImpl::current()->SharedMainThreadContextProvider();
547 media::SkCanvasVideoRenderer::Context3DProvider provider{
548 context_provider->ContextGL(), context_provider->GrContext()};
562 skcanvas_video_renderer_.Paint(video_frame.get(), 549 skcanvas_video_renderer_.Paint(video_frame.get(),
563 canvas, 550 canvas,
564 gfx_rect, 551 gfx_rect,
565 alpha, 552 alpha,
566 mode, 553 mode,
567 pipeline_metadata_.video_rotation); 554 pipeline_metadata_.video_rotation,
555 &provider);
568 } 556 }
569 557
570 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { 558 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const {
571 if (data_source_) 559 if (data_source_)
572 return data_source_->HasSingleOrigin(); 560 return data_source_->HasSingleOrigin();
573 return true; 561 return true;
574 } 562 }
575 563
576 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { 564 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const {
577 if (data_source_) 565 if (data_source_)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 unsigned int texture, 604 unsigned int texture,
617 unsigned int level, 605 unsigned int level,
618 unsigned int internal_format, 606 unsigned int internal_format,
619 unsigned int type, 607 unsigned int type,
620 bool premultiply_alpha, 608 bool premultiply_alpha,
621 bool flip_y) { 609 bool flip_y) {
622 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); 610 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture");
623 611
624 scoped_refptr<media::VideoFrame> video_frame = 612 scoped_refptr<media::VideoFrame> video_frame =
625 GetCurrentFrameFromCompositor(); 613 GetCurrentFrameFromCompositor();
626 614 if (!video_frame ||
627 if (!video_frame) 615 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE)
628 return false;
629 if (video_frame->format() != media::VideoFrame::NATIVE_TEXTURE)
630 return false; 616 return false;
631 617
632 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); 618 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to
633 if (mailbox_holder->texture_target != GL_TEXTURE_2D) 619 // GLES2Interface.
634 return false; 620 gpu::gles2::GLES2Interface* gl =
635 621 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context)
636 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); 622 ->GetGLInterface();
637 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( 623 skcanvas_video_renderer_.CopyVideoFrameToTexture(gl,
638 GL_TEXTURE_2D, mailbox_holder->mailbox.name); 624 video_frame.get(),
639 625 texture,
640 // The video is stored in a unmultiplied format, so premultiply 626 level,
641 // if necessary. 627 internal_format,
642 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, 628 type,
643 premultiply_alpha); 629 premultiply_alpha,
644 // Application itself needs to take care of setting the right flip_y 630 flip_y);
645 // value down to get the expected result.
646 // flip_y==true means to reverse the video orientation while
647 // flip_y==false means to keep the intrinsic orientation.
648 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
649 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D,
650 source_texture,
651 texture,
652 level,
653 internal_format,
654 type);
655 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
656 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
657 false);
658
659 web_graphics_context->deleteTexture(source_texture);
660 web_graphics_context->flush();
661
662 SyncPointClientImpl client(web_graphics_context);
663 video_frame->UpdateReleaseSyncPoint(&client);
664 return true; 631 return true;
665 } 632 }
666 633
667 // Helper functions to report media EME related stats to UMA. They follow the 634 // Helper functions to report media EME related stats to UMA. They follow the
668 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and 635 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and
669 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is 636 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is
670 // that UMA_* macros require the names to be constant throughout the process' 637 // that UMA_* macros require the names to be constant throughout the process'
671 // lifetime. 638 // lifetime.
672 static void EmeUMAHistogramEnumeration(const std::string& key_system, 639 static void EmeUMAHistogramEnumeration(const std::string& key_system,
673 const std::string& method, 640 const std::string& method,
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 compositor_task_runner_->PostTask(FROM_HERE, 1373 compositor_task_runner_->PostTask(FROM_HERE,
1407 base::Bind(&GetCurrentFrameAndSignal, 1374 base::Bind(&GetCurrentFrameAndSignal,
1408 base::Unretained(compositor_), 1375 base::Unretained(compositor_),
1409 &video_frame, 1376 &video_frame,
1410 &event)); 1377 &event));
1411 event.Wait(); 1378 event.Wait();
1412 return video_frame; 1379 return video_frame;
1413 } 1380 }
1414 1381
1415 } // namespace content 1382 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698