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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
| 16 #include "base/debug/crash_logging.h" | 16 #include "base/debug/crash_logging.h" |
| 17 #include "base/debug/trace_event.h" | 17 #include "base/debug/trace_event.h" |
| 18 #include "base/float_util.h" | 18 #include "base/float_util.h" |
| 19 #include "base/message_loop/message_loop_proxy.h" | 19 #include "base/message_loop/message_loop_proxy.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
| 23 #include "cc/blink/web_layer_impl.h" | 23 #include "cc/blink/web_layer_impl.h" |
| 24 #include "cc/layers/video_layer.h" | 24 #include "cc/layers/video_layer.h" |
| 25 #include "gpu/GLES2/gl2extchromium.h" | |
| 26 #include "gpu/command_buffer/common/mailbox_holder.h" | |
| 27 #include "media/audio/null_audio_sink.h" | 25 #include "media/audio/null_audio_sink.h" |
| 28 #include "media/base/audio_hardware_config.h" | 26 #include "media/base/audio_hardware_config.h" |
| 29 #include "media/base/bind_to_current_loop.h" | 27 #include "media/base/bind_to_current_loop.h" |
| 30 #include "media/base/limits.h" | 28 #include "media/base/limits.h" |
| 31 #include "media/base/media_log.h" | 29 #include "media/base/media_log.h" |
| 32 #include "media/base/pipeline.h" | 30 #include "media/base/pipeline.h" |
| 33 #include "media/base/text_renderer.h" | 31 #include "media/base/text_renderer.h" |
| 34 #include "media/base/video_frame.h" | 32 #include "media/base/video_frame.h" |
| 35 #include "media/blink/buffered_data_source.h" | 33 #include "media/blink/buffered_data_source.h" |
| 36 #include "media/blink/encrypted_media_player_support.h" | 34 #include "media/blink/encrypted_media_player_support.h" |
| 37 #include "media/blink/texttrack_impl.h" | 35 #include "media/blink/texttrack_impl.h" |
| 38 #include "media/blink/webaudiosourceprovider_impl.h" | 36 #include "media/blink/webaudiosourceprovider_impl.h" |
| 39 #include "media/blink/webinbandtexttrack_impl.h" | 37 #include "media/blink/webinbandtexttrack_impl.h" |
| 40 #include "media/blink/webmediaplayer_delegate.h" | 38 #include "media/blink/webmediaplayer_delegate.h" |
| 41 #include "media/blink/webmediaplayer_params.h" | |
| 42 #include "media/blink/webmediaplayer_util.h" | 39 #include "media/blink/webmediaplayer_util.h" |
| 43 #include "media/blink/webmediasource_impl.h" | 40 #include "media/blink/webmediasource_impl.h" |
| 44 #include "media/filters/audio_renderer_impl.h" | 41 #include "media/filters/audio_renderer_impl.h" |
| 45 #include "media/filters/chunk_demuxer.h" | 42 #include "media/filters/chunk_demuxer.h" |
| 46 #include "media/filters/ffmpeg_audio_decoder.h" | 43 #include "media/filters/ffmpeg_audio_decoder.h" |
| 47 #include "media/filters/ffmpeg_demuxer.h" | 44 #include "media/filters/ffmpeg_demuxer.h" |
| 48 #include "media/filters/ffmpeg_video_decoder.h" | 45 #include "media/filters/ffmpeg_video_decoder.h" |
| 49 #include "media/filters/gpu_video_accelerator_factories.h" | 46 #include "media/filters/gpu_video_accelerator_factories.h" |
| 50 #include "media/filters/gpu_video_decoder.h" | 47 #include "media/filters/gpu_video_decoder.h" |
| 51 #include "media/filters/opus_audio_decoder.h" | 48 #include "media/filters/opus_audio_decoder.h" |
| 52 #include "media/filters/renderer_impl.h" | 49 #include "media/filters/renderer_impl.h" |
| 53 #include "media/filters/video_renderer_impl.h" | 50 #include "media/filters/video_renderer_impl.h" |
| 54 #include "media/filters/vpx_video_decoder.h" | 51 #include "media/filters/vpx_video_decoder.h" |
| 55 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 52 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
| 56 #include "third_party/WebKit/public/platform/WebRect.h" | 53 #include "third_party/WebKit/public/platform/WebRect.h" |
| 57 #include "third_party/WebKit/public/platform/WebSize.h" | 54 #include "third_party/WebKit/public/platform/WebSize.h" |
| 58 #include "third_party/WebKit/public/platform/WebString.h" | 55 #include "third_party/WebKit/public/platform/WebString.h" |
| 59 #include "third_party/WebKit/public/platform/WebURL.h" | 56 #include "third_party/WebKit/public/platform/WebURL.h" |
| 60 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 57 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 61 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 58 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 62 #include "third_party/WebKit/public/web/WebView.h" | 59 #include "third_party/WebKit/public/web/WebView.h" |
| 60 #include "webkit/common/gpu/webgraphicscontext3d_impl.h" | |
| 63 | 61 |
| 64 using blink::WebCanvas; | 62 using blink::WebCanvas; |
| 65 using blink::WebMediaPlayer; | 63 using blink::WebMediaPlayer; |
| 66 using blink::WebRect; | 64 using blink::WebRect; |
| 67 using blink::WebSize; | 65 using blink::WebSize; |
| 68 using blink::WebString; | 66 using blink::WebString; |
| 69 | 67 |
| 70 namespace { | 68 namespace { |
| 71 | 69 |
| 72 // Limits the range of playback rate. | 70 // Limits the range of playback rate. |
| 73 // | 71 // |
| 74 // TODO(kylep): Revisit these. | 72 // TODO(kylep): Revisit these. |
| 75 // | 73 // |
| 76 // Vista has substantially lower performance than XP or Windows7. If you speed | 74 // Vista has substantially lower performance than XP or Windows7. If you speed |
| 77 // up a video too much, it can't keep up, and rendering stops updating except on | 75 // up a video too much, it can't keep up, and rendering stops updating except on |
| 78 // the time bar. For really high speeds, audio becomes a bottleneck and we just | 76 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 79 // use up the data we have, which may not achieve the speed requested, but will | 77 // use up the data we have, which may not achieve the speed requested, but will |
| 80 // not crash the tab. | 78 // not crash the tab. |
| 81 // | 79 // |
| 82 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 80 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 83 // like a busy loop). It gets unresponsive, although its not completely dead. | 81 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 84 // | 82 // |
| 85 // Also our timers are not very accurate (especially for ogg), which becomes | 83 // Also our timers are not very accurate (especially for ogg), which becomes |
| 86 // evident at low speeds and on Vista. Since other speeds are risky and outside | 84 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 87 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 85 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 88 const double kMinRate = 0.0625; | 86 const double kMinRate = 0.0625; |
| 89 const double kMaxRate = 16.0; | 87 const double kMaxRate = 16.0; |
| 90 | 88 |
| 91 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
| 92 public: | |
| 93 explicit SyncPointClientImpl( | |
| 94 blink::WebGraphicsContext3D* web_graphics_context) | |
| 95 : web_graphics_context_(web_graphics_context) {} | |
| 96 virtual ~SyncPointClientImpl() {} | |
| 97 virtual uint32 InsertSyncPoint() override { | |
| 98 return web_graphics_context_->insertSyncPoint(); | |
| 99 } | |
| 100 virtual void WaitSyncPoint(uint32 sync_point) override { | |
| 101 web_graphics_context_->waitSyncPoint(sync_point); | |
| 102 } | |
| 103 | |
| 104 private: | |
| 105 blink::WebGraphicsContext3D* web_graphics_context_; | |
| 106 }; | |
| 107 | |
| 108 } // namespace | 89 } // namespace |
| 109 | 90 |
| 110 namespace media { | 91 namespace media { |
| 111 | 92 |
| 112 class BufferedDataSourceHostImpl; | 93 class BufferedDataSourceHostImpl; |
| 113 | 94 |
| 114 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 95 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 115 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 96 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 116 static_cast<int>(BufferedResourceLoader::k ## name), \ | 97 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 117 mismatching_enums) | 98 mismatching_enums) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 paused_(true), | 132 paused_(true), |
| 152 seeking_(false), | 133 seeking_(false), |
| 153 playback_rate_(0.0f), | 134 playback_rate_(0.0f), |
| 154 ended_(false), | 135 ended_(false), |
| 155 pending_seek_(false), | 136 pending_seek_(false), |
| 156 pending_seek_seconds_(0.0f), | 137 pending_seek_seconds_(0.0f), |
| 157 should_notify_time_changed_(false), | 138 should_notify_time_changed_(false), |
| 158 client_(client), | 139 client_(client), |
| 159 delegate_(delegate), | 140 delegate_(delegate), |
| 160 defer_load_cb_(params.defer_load_cb()), | 141 defer_load_cb_(params.defer_load_cb()), |
| 142 shared_main_thread_context_provider_cb_( | |
| 143 params.shared_main_thread_context_provider_cb()), | |
| 161 gpu_factories_(params.gpu_factories()), | 144 gpu_factories_(params.gpu_factories()), |
| 162 supports_save_(true), | 145 supports_save_(true), |
| 163 chunk_demuxer_(NULL), | 146 chunk_demuxer_(NULL), |
| 164 compositor_task_runner_(params.compositor_task_runner()), | 147 compositor_task_runner_(params.compositor_task_runner()), |
| 165 compositor_(new VideoFrameCompositor( | 148 compositor_(new VideoFrameCompositor( |
| 166 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 149 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 167 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 150 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 168 text_track_index_(0), | 151 text_track_index_(0), |
| 169 encrypted_media_support_( | 152 encrypted_media_support_( |
| 170 params.CreateEncryptedMediaPlayerSupport(client)), | 153 params.CreateEncryptedMediaPlayerSupport(client)), |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 | 505 |
| 523 // TODO(scherkus): Clarify paint() API contract to better understand when and | 506 // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 524 // why it's being called. For example, today paint() is called when: | 507 // why it's being called. For example, today paint() is called when: |
| 525 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 508 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 526 // - We're painting to a canvas | 509 // - We're painting to a canvas |
| 527 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 510 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
| 528 scoped_refptr<VideoFrame> video_frame = | 511 scoped_refptr<VideoFrame> video_frame = |
| 529 GetCurrentFrameFromCompositor(); | 512 GetCurrentFrameFromCompositor(); |
| 530 | 513 |
| 531 gfx::Rect gfx_rect(rect); | 514 gfx::Rect gfx_rect(rect); |
| 532 | 515 media::SkCanvasVideoRenderer::Context3DProvider provider{NULL, NULL}; |
| 533 skcanvas_video_renderer_.Paint(video_frame, | 516 if (!shared_main_thread_context_provider_cb_.is_null()) { |
| 517 cc::ContextProvider* context_provider = | |
| 518 shared_main_thread_context_provider_cb_.Run(); | |
|
scherkus (not reviewing)
2014/10/13 17:48:41
is the context guaranteed to not change throughout
| |
| 519 if (context_provider) { | |
| 520 provider.gl = context_provider->ContextGL(); | |
| 521 provider.gr_context = context_provider->GrContext(); | |
| 522 } | |
| 523 } | |
| 524 skcanvas_video_renderer_.Paint(video_frame.get(), | |
| 534 canvas, | 525 canvas, |
| 535 gfx_rect, | 526 gfx_rect, |
| 536 alpha, | 527 alpha, |
| 537 mode, | 528 mode, |
| 538 pipeline_metadata_.video_rotation); | 529 pipeline_metadata_.video_rotation, |
| 530 &provider); | |
| 539 } | 531 } |
| 540 | 532 |
| 541 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 533 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
| 542 if (data_source_) | 534 if (data_source_) |
| 543 return data_source_->HasSingleOrigin(); | 535 return data_source_->HasSingleOrigin(); |
| 544 return true; | 536 return true; |
| 545 } | 537 } |
| 546 | 538 |
| 547 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 539 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
| 548 if (data_source_) | 540 if (data_source_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 unsigned int level, | 580 unsigned int level, |
| 589 unsigned int internal_format, | 581 unsigned int internal_format, |
| 590 unsigned int type, | 582 unsigned int type, |
| 591 bool premultiply_alpha, | 583 bool premultiply_alpha, |
| 592 bool flip_y) { | 584 bool flip_y) { |
| 593 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 585 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 594 | 586 |
| 595 scoped_refptr<VideoFrame> video_frame = | 587 scoped_refptr<VideoFrame> video_frame = |
| 596 GetCurrentFrameFromCompositor(); | 588 GetCurrentFrameFromCompositor(); |
| 597 | 589 |
| 598 if (!video_frame.get()) | 590 if (!video_frame.get() || |
| 591 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) { | |
| 599 return false; | 592 return false; |
| 600 if (video_frame->format() != VideoFrame::NATIVE_TEXTURE) | 593 } |
| 601 return false; | |
| 602 | 594 |
| 603 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 595 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
| 604 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 596 // GLES2Interface. |
| 605 return false; | 597 gpu::gles2::GLES2Interface* gl = |
| 606 | 598 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context) |
| 607 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 599 ->GetGLInterface(); |
| 608 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 600 skcanvas_video_renderer_.CopyVideoFrameToTexture(gl, |
|
scherkus (not reviewing)
2014/10/15 17:10:23
use SkCanvasVideoRenderer:: instead of the object
| |
| 609 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 601 video_frame.get(), |
| 610 | 602 texture, |
| 611 // The video is stored in a unmultiplied format, so premultiply | 603 level, |
| 612 // if necessary. | 604 internal_format, |
| 613 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 605 type, |
| 614 premultiply_alpha); | 606 premultiply_alpha, |
| 615 // Application itself needs to take care of setting the right flip_y | 607 flip_y); |
| 616 // value down to get the expected result. | |
| 617 // flip_y==true means to reverse the video orientation while | |
| 618 // flip_y==false means to keep the intrinsic orientation. | |
| 619 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
| 620 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
| 621 source_texture, | |
| 622 texture, | |
| 623 level, | |
| 624 internal_format, | |
| 625 type); | |
| 626 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
| 627 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 628 false); | |
| 629 | |
| 630 web_graphics_context->deleteTexture(source_texture); | |
| 631 web_graphics_context->flush(); | |
| 632 | |
| 633 SyncPointClientImpl client(web_graphics_context); | |
| 634 video_frame->UpdateReleaseSyncPoint(&client); | |
| 635 return true; | 608 return true; |
| 636 } | 609 } |
| 637 | 610 |
| 638 WebMediaPlayer::MediaKeyException | 611 WebMediaPlayer::MediaKeyException |
| 639 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 612 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 640 const unsigned char* init_data, | 613 const unsigned char* init_data, |
| 641 unsigned init_data_length) { | 614 unsigned init_data_length) { |
| 642 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 615 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 643 | 616 |
| 644 return encrypted_media_support_->GenerateKeyRequest( | 617 return encrypted_media_support_->GenerateKeyRequest( |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 compositor_task_runner_->PostTask(FROM_HERE, | 994 compositor_task_runner_->PostTask(FROM_HERE, |
| 1022 base::Bind(&GetCurrentFrameAndSignal, | 995 base::Bind(&GetCurrentFrameAndSignal, |
| 1023 base::Unretained(compositor_), | 996 base::Unretained(compositor_), |
| 1024 &video_frame, | 997 &video_frame, |
| 1025 &event)); | 998 &event)); |
| 1026 event.Wait(); | 999 event.Wait(); |
| 1027 return video_frame; | 1000 return video_frame; |
| 1028 } | 1001 } |
| 1029 | 1002 |
| 1030 } // namespace media | 1003 } // namespace media |
| OLD | NEW |