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 ~SyncPointClientImpl() override {} | |
| 97 uint32 InsertSyncPoint() override { | |
| 98 return web_graphics_context_->insertSyncPoint(); | |
| 99 } | |
| 100 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 paused_(true), | 133 paused_(true), |
| 153 seeking_(false), | 134 seeking_(false), |
| 154 playback_rate_(0.0f), | 135 playback_rate_(0.0f), |
| 155 ended_(false), | 136 ended_(false), |
| 156 pending_seek_(false), | 137 pending_seek_(false), |
| 157 pending_seek_seconds_(0.0f), | 138 pending_seek_seconds_(0.0f), |
| 158 should_notify_time_changed_(false), | 139 should_notify_time_changed_(false), |
| 159 client_(client), | 140 client_(client), |
| 160 delegate_(delegate), | 141 delegate_(delegate), |
| 161 defer_load_cb_(params.defer_load_cb()), | 142 defer_load_cb_(params.defer_load_cb()), |
| 143 shared_main_thread_context_3d_provider_cb_( | |
| 144 params.shared_main_thread_context_3d_provider_cb()), | |
| 162 gpu_factories_(params.gpu_factories()), | 145 gpu_factories_(params.gpu_factories()), |
| 163 supports_save_(true), | 146 supports_save_(true), |
| 164 chunk_demuxer_(NULL), | 147 chunk_demuxer_(NULL), |
| 165 compositor_task_runner_(params.compositor_task_runner()), | 148 compositor_task_runner_(params.compositor_task_runner()), |
| 166 compositor_(new VideoFrameCompositor( | 149 compositor_(new VideoFrameCompositor( |
| 167 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 150 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 168 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 151 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 169 text_track_index_(0), | 152 text_track_index_(0), |
| 170 encrypted_media_support_( | 153 encrypted_media_support_( |
| 171 params.CreateEncryptedMediaPlayerSupport(client)), | 154 params.CreateEncryptedMediaPlayerSupport(client)), |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 512 |
| 530 // TODO(scherkus): Clarify paint() API contract to better understand when and | 513 // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 531 // why it's being called. For example, today paint() is called when: | 514 // why it's being called. For example, today paint() is called when: |
| 532 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 515 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 533 // - We're painting to a canvas | 516 // - We're painting to a canvas |
| 534 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 517 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
| 535 scoped_refptr<VideoFrame> video_frame = | 518 scoped_refptr<VideoFrame> video_frame = |
| 536 GetCurrentFrameFromCompositor(); | 519 GetCurrentFrameFromCompositor(); |
| 537 | 520 |
| 538 gfx::Rect gfx_rect(rect); | 521 gfx::Rect gfx_rect(rect); |
| 539 | 522 Context3DProvider provider{nullptr, nullptr}; |
| 540 skcanvas_video_renderer_.Paint(video_frame, | 523 if (canvas->getGrContext() || |
| 524 (video_frame.get() && | |
|
scherkus (not reviewing)
2014/10/30 20:40:11
nit: is .get() needed?
dshwang
2014/10/31 09:29:16
needed.
| |
| 525 video_frame->format() == media::VideoFrame::NATIVE_TEXTURE)) { | |
| 526 if (!shared_main_thread_context_3d_provider_cb_.is_null()) { | |
| 527 provider = shared_main_thread_context_3d_provider_cb_.Run(); | |
| 528 } | |
| 529 // GPU Process crashed. | |
| 530 if (!provider.gl) | |
| 531 return; | |
| 532 } | |
| 533 skcanvas_video_renderer_.Paint(video_frame.get(), | |
|
scherkus (not reviewing)
2014/10/30 20:40:11
nit: is .get() needed?
dshwang
2014/10/31 09:29:16
not needed.
| |
| 541 canvas, | 534 canvas, |
| 542 gfx_rect, | 535 gfx_rect, |
| 543 alpha, | 536 alpha, |
| 544 mode, | 537 mode, |
| 545 pipeline_metadata_.video_rotation); | 538 pipeline_metadata_.video_rotation, |
| 539 provider); | |
| 546 } | 540 } |
| 547 | 541 |
| 548 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 542 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
| 549 if (data_source_) | 543 if (data_source_) |
| 550 return data_source_->HasSingleOrigin(); | 544 return data_source_->HasSingleOrigin(); |
| 551 return true; | 545 return true; |
| 552 } | 546 } |
| 553 | 547 |
| 554 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 548 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
| 555 if (data_source_) | 549 if (data_source_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 unsigned int level, | 589 unsigned int level, |
| 596 unsigned int internal_format, | 590 unsigned int internal_format, |
| 597 unsigned int type, | 591 unsigned int type, |
| 598 bool premultiply_alpha, | 592 bool premultiply_alpha, |
| 599 bool flip_y) { | 593 bool flip_y) { |
| 600 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 594 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 601 | 595 |
| 602 scoped_refptr<VideoFrame> video_frame = | 596 scoped_refptr<VideoFrame> video_frame = |
| 603 GetCurrentFrameFromCompositor(); | 597 GetCurrentFrameFromCompositor(); |
| 604 | 598 |
| 605 if (!video_frame.get()) | 599 if (!video_frame.get() || |
|
scherkus (not reviewing)
2014/10/30 20:40:11
nit: is .get() needed?
dshwang
2014/10/31 09:29:16
needed
| |
| 600 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) { | |
| 606 return false; | 601 return false; |
| 607 if (video_frame->format() != VideoFrame::NATIVE_TEXTURE) | 602 } |
| 608 return false; | |
| 609 | 603 |
| 610 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 604 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
| 611 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 605 // GLES2Interface. |
| 612 return false; | 606 gpu::gles2::GLES2Interface* gl = |
| 613 | 607 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context) |
| 614 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 608 ->GetGLInterface(); |
| 615 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 609 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture(gl, |
| 616 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 610 video_frame.get(), |
|
scherkus (not reviewing)
2014/10/30 20:40:11
nit: is .get() needed?
dshwang
2014/10/31 09:29:16
needed
| |
| 617 | 611 texture, |
| 618 // The video is stored in a unmultiplied format, so premultiply | 612 level, |
| 619 // if necessary. | 613 internal_format, |
| 620 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 614 type, |
| 621 premultiply_alpha); | 615 premultiply_alpha, |
| 622 // Application itself needs to take care of setting the right flip_y | 616 flip_y); |
| 623 // value down to get the expected result. | |
| 624 // flip_y==true means to reverse the video orientation while | |
| 625 // flip_y==false means to keep the intrinsic orientation. | |
| 626 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
| 627 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
| 628 source_texture, | |
| 629 texture, | |
| 630 level, | |
| 631 internal_format, | |
| 632 type); | |
| 633 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
| 634 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 635 false); | |
| 636 | |
| 637 web_graphics_context->deleteTexture(source_texture); | |
| 638 web_graphics_context->flush(); | |
| 639 | |
| 640 SyncPointClientImpl client(web_graphics_context); | |
| 641 video_frame->UpdateReleaseSyncPoint(&client); | |
| 642 return true; | 617 return true; |
| 643 } | 618 } |
| 644 | 619 |
| 645 WebMediaPlayer::MediaKeyException | 620 WebMediaPlayer::MediaKeyException |
| 646 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 621 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 647 const unsigned char* init_data, | 622 const unsigned char* init_data, |
| 648 unsigned init_data_length) { | 623 unsigned init_data_length) { |
| 649 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 624 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 650 | 625 |
| 651 return encrypted_media_support_->GenerateKeyRequest( | 626 return encrypted_media_support_->GenerateKeyRequest( |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 compositor_task_runner_->PostTask(FROM_HERE, | 1007 compositor_task_runner_->PostTask(FROM_HERE, |
| 1033 base::Bind(&GetCurrentFrameAndSignal, | 1008 base::Bind(&GetCurrentFrameAndSignal, |
| 1034 base::Unretained(compositor_), | 1009 base::Unretained(compositor_), |
| 1035 &video_frame, | 1010 &video_frame, |
| 1036 &event)); | 1011 &event)); |
| 1037 event.Wait(); | 1012 event.Wait(); |
| 1038 return video_frame; | 1013 return video_frame; |
| 1039 } | 1014 } |
| 1040 | 1015 |
| 1041 } // namespace media | 1016 } // namespace media |
| OLD | NEW |