| 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/webcontentdecryptionmodule_impl.h" | 37 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 40 #include "media/blink/webinbandtexttrack_impl.h" | 38 #include "media/blink/webinbandtexttrack_impl.h" |
| 41 #include "media/blink/webmediaplayer_delegate.h" | 39 #include "media/blink/webmediaplayer_delegate.h" |
| 42 #include "media/blink/webmediaplayer_params.h" | |
| 43 #include "media/blink/webmediaplayer_util.h" | 40 #include "media/blink/webmediaplayer_util.h" |
| 44 #include "media/blink/webmediasource_impl.h" | 41 #include "media/blink/webmediasource_impl.h" |
| 45 #include "media/filters/audio_renderer_impl.h" | 42 #include "media/filters/audio_renderer_impl.h" |
| 46 #include "media/filters/chunk_demuxer.h" | 43 #include "media/filters/chunk_demuxer.h" |
| 47 #include "media/filters/ffmpeg_audio_decoder.h" | 44 #include "media/filters/ffmpeg_audio_decoder.h" |
| 48 #include "media/filters/ffmpeg_demuxer.h" | 45 #include "media/filters/ffmpeg_demuxer.h" |
| 49 #include "media/filters/ffmpeg_video_decoder.h" | 46 #include "media/filters/ffmpeg_video_decoder.h" |
| 50 #include "media/filters/gpu_video_accelerator_factories.h" | 47 #include "media/filters/gpu_video_accelerator_factories.h" |
| 51 #include "media/filters/gpu_video_decoder.h" | 48 #include "media/filters/gpu_video_decoder.h" |
| 52 #include "media/filters/opus_audio_decoder.h" | 49 #include "media/filters/opus_audio_decoder.h" |
| 53 #include "media/filters/renderer_impl.h" | 50 #include "media/filters/renderer_impl.h" |
| 54 #include "media/filters/video_renderer_impl.h" | 51 #include "media/filters/video_renderer_impl.h" |
| 55 #include "media/filters/vpx_video_decoder.h" | 52 #include "media/filters/vpx_video_decoder.h" |
| 56 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 53 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
| 57 #include "third_party/WebKit/public/platform/WebRect.h" | 54 #include "third_party/WebKit/public/platform/WebRect.h" |
| 58 #include "third_party/WebKit/public/platform/WebSize.h" | 55 #include "third_party/WebKit/public/platform/WebSize.h" |
| 59 #include "third_party/WebKit/public/platform/WebString.h" | 56 #include "third_party/WebKit/public/platform/WebString.h" |
| 60 #include "third_party/WebKit/public/platform/WebURL.h" | 57 #include "third_party/WebKit/public/platform/WebURL.h" |
| 61 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 58 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 62 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 59 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 63 #include "third_party/WebKit/public/web/WebView.h" | 60 #include "third_party/WebKit/public/web/WebView.h" |
| 61 #include "webkit/common/gpu/webgraphicscontext3d_impl.h" |
| 64 | 62 |
| 65 using blink::WebCanvas; | 63 using blink::WebCanvas; |
| 66 using blink::WebMediaPlayer; | 64 using blink::WebMediaPlayer; |
| 67 using blink::WebRect; | 65 using blink::WebRect; |
| 68 using blink::WebSize; | 66 using blink::WebSize; |
| 69 using blink::WebString; | 67 using blink::WebString; |
| 70 | 68 |
| 71 namespace { | 69 namespace { |
| 72 | 70 |
| 73 // Limits the range of playback rate. | 71 // Limits the range of playback rate. |
| 74 // | 72 // |
| 75 // TODO(kylep): Revisit these. | 73 // TODO(kylep): Revisit these. |
| 76 // | 74 // |
| 77 // Vista has substantially lower performance than XP or Windows7. If you speed | 75 // Vista has substantially lower performance than XP or Windows7. If you speed |
| 78 // up a video too much, it can't keep up, and rendering stops updating except on | 76 // up a video too much, it can't keep up, and rendering stops updating except on |
| 79 // the time bar. For really high speeds, audio becomes a bottleneck and we just | 77 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 80 // use up the data we have, which may not achieve the speed requested, but will | 78 // use up the data we have, which may not achieve the speed requested, but will |
| 81 // not crash the tab. | 79 // not crash the tab. |
| 82 // | 80 // |
| 83 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 81 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 84 // like a busy loop). It gets unresponsive, although its not completely dead. | 82 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 85 // | 83 // |
| 86 // Also our timers are not very accurate (especially for ogg), which becomes | 84 // Also our timers are not very accurate (especially for ogg), which becomes |
| 87 // evident at low speeds and on Vista. Since other speeds are risky and outside | 85 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 88 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 86 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 89 const double kMinRate = 0.0625; | 87 const double kMinRate = 0.0625; |
| 90 const double kMaxRate = 16.0; | 88 const double kMaxRate = 16.0; |
| 91 | 89 |
| 92 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
| 93 public: | |
| 94 explicit SyncPointClientImpl( | |
| 95 blink::WebGraphicsContext3D* web_graphics_context) | |
| 96 : web_graphics_context_(web_graphics_context) {} | |
| 97 ~SyncPointClientImpl() override {} | |
| 98 uint32 InsertSyncPoint() override { | |
| 99 return web_graphics_context_->insertSyncPoint(); | |
| 100 } | |
| 101 void WaitSyncPoint(uint32 sync_point) override { | |
| 102 web_graphics_context_->waitSyncPoint(sync_point); | |
| 103 } | |
| 104 | |
| 105 private: | |
| 106 blink::WebGraphicsContext3D* web_graphics_context_; | |
| 107 }; | |
| 108 | |
| 109 } // namespace | 90 } // namespace |
| 110 | 91 |
| 111 namespace media { | 92 namespace media { |
| 112 | 93 |
| 113 class BufferedDataSourceHostImpl; | 94 class BufferedDataSourceHostImpl; |
| 114 | 95 |
| 115 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 96 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 116 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 97 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 117 static_cast<int>(BufferedResourceLoader::k ## name), \ | 98 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 118 mismatching_enums) | 99 mismatching_enums) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 paused_(true), | 135 paused_(true), |
| 155 seeking_(false), | 136 seeking_(false), |
| 156 playback_rate_(0.0f), | 137 playback_rate_(0.0f), |
| 157 ended_(false), | 138 ended_(false), |
| 158 pending_seek_(false), | 139 pending_seek_(false), |
| 159 pending_seek_seconds_(0.0f), | 140 pending_seek_seconds_(0.0f), |
| 160 should_notify_time_changed_(false), | 141 should_notify_time_changed_(false), |
| 161 client_(client), | 142 client_(client), |
| 162 delegate_(delegate), | 143 delegate_(delegate), |
| 163 defer_load_cb_(params.defer_load_cb()), | 144 defer_load_cb_(params.defer_load_cb()), |
| 145 context_3d_cb_(params.context_3d_cb()), |
| 164 gpu_factories_(params.gpu_factories()), | 146 gpu_factories_(params.gpu_factories()), |
| 165 supports_save_(true), | 147 supports_save_(true), |
| 166 chunk_demuxer_(NULL), | 148 chunk_demuxer_(NULL), |
| 167 compositor_task_runner_(params.compositor_task_runner()), | 149 compositor_task_runner_(params.compositor_task_runner()), |
| 168 compositor_(new VideoFrameCompositor( | 150 compositor_(new VideoFrameCompositor( |
| 169 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 151 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 170 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 152 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 171 text_track_index_(0), | 153 text_track_index_(0), |
| 172 encrypted_media_support_( | 154 encrypted_media_support_( |
| 173 cdm_factory.Pass(), | 155 cdm_factory.Pass(), |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 513 |
| 532 // TODO(scherkus): Clarify paint() API contract to better understand when and | 514 // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 533 // why it's being called. For example, today paint() is called when: | 515 // why it's being called. For example, today paint() is called when: |
| 534 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 516 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 535 // - We're painting to a canvas | 517 // - We're painting to a canvas |
| 536 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 518 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
| 537 scoped_refptr<VideoFrame> video_frame = | 519 scoped_refptr<VideoFrame> video_frame = |
| 538 GetCurrentFrameFromCompositor(); | 520 GetCurrentFrameFromCompositor(); |
| 539 | 521 |
| 540 gfx::Rect gfx_rect(rect); | 522 gfx::Rect gfx_rect(rect); |
| 541 | 523 Context3D context_3d; |
| 542 skcanvas_video_renderer_.Paint(video_frame, | 524 if (video_frame.get() && |
| 543 canvas, | 525 video_frame->format() == VideoFrame::NATIVE_TEXTURE) { |
| 544 gfx_rect, | 526 if (!context_3d_cb_.is_null()) { |
| 545 alpha, | 527 context_3d = context_3d_cb_.Run(); |
| 546 mode, | 528 } |
| 547 pipeline_metadata_.video_rotation); | 529 // GPU Process crashed. |
| 530 if (!context_3d.gl) |
| 531 return; |
| 532 } |
| 533 skcanvas_video_renderer_.Paint(video_frame, canvas, gfx_rect, alpha, mode, |
| 534 pipeline_metadata_.video_rotation, context_3d); |
| 548 } | 535 } |
| 549 | 536 |
| 550 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 537 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
| 551 if (data_source_) | 538 if (data_source_) |
| 552 return data_source_->HasSingleOrigin(); | 539 return data_source_->HasSingleOrigin(); |
| 553 return true; | 540 return true; |
| 554 } | 541 } |
| 555 | 542 |
| 556 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 543 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
| 557 if (data_source_) | 544 if (data_source_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 unsigned int level, | 584 unsigned int level, |
| 598 unsigned int internal_format, | 585 unsigned int internal_format, |
| 599 unsigned int type, | 586 unsigned int type, |
| 600 bool premultiply_alpha, | 587 bool premultiply_alpha, |
| 601 bool flip_y) { | 588 bool flip_y) { |
| 602 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 589 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 603 | 590 |
| 604 scoped_refptr<VideoFrame> video_frame = | 591 scoped_refptr<VideoFrame> video_frame = |
| 605 GetCurrentFrameFromCompositor(); | 592 GetCurrentFrameFromCompositor(); |
| 606 | 593 |
| 607 if (!video_frame.get()) | 594 if (!video_frame.get() || |
| 595 video_frame->format() != VideoFrame::NATIVE_TEXTURE) { |
| 608 return false; | 596 return false; |
| 609 if (video_frame->format() != VideoFrame::NATIVE_TEXTURE) | 597 } |
| 610 return false; | |
| 611 | 598 |
| 612 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 599 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
| 613 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 600 // GLES2Interface. |
| 614 return false; | 601 gpu::gles2::GLES2Interface* gl = |
| 615 | 602 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context) |
| 616 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 603 ->GetGLInterface(); |
| 617 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 604 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
| 618 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 605 gl, video_frame.get(), texture, level, internal_format, type, |
| 619 | 606 premultiply_alpha, flip_y); |
| 620 // The video is stored in a unmultiplied format, so premultiply | |
| 621 // if necessary. | |
| 622 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 623 premultiply_alpha); | |
| 624 // Application itself needs to take care of setting the right flip_y | |
| 625 // value down to get the expected result. | |
| 626 // flip_y==true means to reverse the video orientation while | |
| 627 // flip_y==false means to keep the intrinsic orientation. | |
| 628 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
| 629 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
| 630 source_texture, | |
| 631 texture, | |
| 632 level, | |
| 633 internal_format, | |
| 634 type); | |
| 635 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
| 636 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 637 false); | |
| 638 | |
| 639 web_graphics_context->deleteTexture(source_texture); | |
| 640 web_graphics_context->flush(); | |
| 641 | |
| 642 SyncPointClientImpl client(web_graphics_context); | |
| 643 video_frame->UpdateReleaseSyncPoint(&client); | |
| 644 return true; | 607 return true; |
| 645 } | 608 } |
| 646 | 609 |
| 647 WebMediaPlayer::MediaKeyException | 610 WebMediaPlayer::MediaKeyException |
| 648 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 611 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 649 const unsigned char* init_data, | 612 const unsigned char* init_data, |
| 650 unsigned init_data_length) { | 613 unsigned init_data_length) { |
| 651 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 614 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 652 | 615 |
| 653 return encrypted_media_support_.GenerateKeyRequest( | 616 return encrypted_media_support_.GenerateKeyRequest( |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 compositor_task_runner_->PostTask(FROM_HERE, | 1007 compositor_task_runner_->PostTask(FROM_HERE, |
| 1045 base::Bind(&GetCurrentFrameAndSignal, | 1008 base::Bind(&GetCurrentFrameAndSignal, |
| 1046 base::Unretained(compositor_), | 1009 base::Unretained(compositor_), |
| 1047 &video_frame, | 1010 &video_frame, |
| 1048 &event)); | 1011 &event)); |
| 1049 event.Wait(); | 1012 event.Wait(); |
| 1050 return video_frame; | 1013 return video_frame; |
| 1051 } | 1014 } |
| 1052 | 1015 |
| 1053 } // namespace media | 1016 } // namespace media |
| OLD | NEW |