| 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" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 81 // | 78 // |
| 82 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 79 // 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. | 80 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 84 // | 81 // |
| 85 // Also our timers are not very accurate (especially for ogg), which becomes | 82 // 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 | 83 // 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. | 84 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 88 const double kMinRate = 0.0625; | 85 const double kMinRate = 0.0625; |
| 89 const double kMaxRate = 16.0; | 86 const double kMaxRate = 16.0; |
| 90 | 87 |
| 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 | 88 } // namespace |
| 109 | 89 |
| 110 namespace media { | 90 namespace media { |
| 111 | 91 |
| 112 class BufferedDataSourceHostImpl; | 92 class BufferedDataSourceHostImpl; |
| 113 | 93 |
| 114 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 94 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 115 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 95 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 116 static_cast<int>(BufferedResourceLoader::k ## name), \ | 96 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 117 mismatching_enums) | 97 mismatching_enums) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 paused_(true), | 132 paused_(true), |
| 153 seeking_(false), | 133 seeking_(false), |
| 154 playback_rate_(0.0f), | 134 playback_rate_(0.0f), |
| 155 ended_(false), | 135 ended_(false), |
| 156 pending_seek_(false), | 136 pending_seek_(false), |
| 157 pending_seek_seconds_(0.0f), | 137 pending_seek_seconds_(0.0f), |
| 158 should_notify_time_changed_(false), | 138 should_notify_time_changed_(false), |
| 159 client_(client), | 139 client_(client), |
| 160 delegate_(delegate), | 140 delegate_(delegate), |
| 161 defer_load_cb_(params.defer_load_cb()), | 141 defer_load_cb_(params.defer_load_cb()), |
| 142 context_3d_provider_cb_(params.context_3d_provider_cb()), |
| 162 gpu_factories_(params.gpu_factories()), | 143 gpu_factories_(params.gpu_factories()), |
| 163 supports_save_(true), | 144 supports_save_(true), |
| 164 chunk_demuxer_(NULL), | 145 chunk_demuxer_(NULL), |
| 165 compositor_task_runner_(params.compositor_task_runner()), | 146 compositor_task_runner_(params.compositor_task_runner()), |
| 166 compositor_(new VideoFrameCompositor( | 147 compositor_(new VideoFrameCompositor( |
| 167 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 148 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 168 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 149 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 169 text_track_index_(0), | 150 text_track_index_(0), |
| 170 encrypted_media_support_( | 151 encrypted_media_support_( |
| 171 params.CreateEncryptedMediaPlayerSupport(client)), | 152 params.CreateEncryptedMediaPlayerSupport(client)), |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 510 |
| 530 // TODO(scherkus): Clarify paint() API contract to better understand when and | 511 // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 531 // why it's being called. For example, today paint() is called when: | 512 // 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 | 513 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 533 // - We're painting to a canvas | 514 // - We're painting to a canvas |
| 534 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 515 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
| 535 scoped_refptr<VideoFrame> video_frame = | 516 scoped_refptr<VideoFrame> video_frame = |
| 536 GetCurrentFrameFromCompositor(); | 517 GetCurrentFrameFromCompositor(); |
| 537 | 518 |
| 538 gfx::Rect gfx_rect(rect); | 519 gfx::Rect gfx_rect(rect); |
| 539 | 520 scoped_ptr<blink::WebGraphicsContext3DProvider> provider; |
| 540 skcanvas_video_renderer_.Paint(video_frame, | 521 if (video_frame.get() && |
| 541 canvas, | 522 video_frame->format() == VideoFrame::NATIVE_TEXTURE) { |
| 542 gfx_rect, | 523 if (!context_3d_provider_cb_.is_null()) { |
| 543 alpha, | 524 provider = context_3d_provider_cb_.Run(); |
| 544 mode, | 525 } |
| 545 pipeline_metadata_.video_rotation); | 526 // GPU Process crashed. |
| 527 if (!provider.get()) |
| 528 return; |
| 529 } |
| 530 skcanvas_video_renderer_.Paint(video_frame, canvas, gfx_rect, alpha, mode, |
| 531 pipeline_metadata_.video_rotation, |
| 532 provider.Pass()); |
| 546 } | 533 } |
| 547 | 534 |
| 548 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 535 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
| 549 if (data_source_) | 536 if (data_source_) |
| 550 return data_source_->HasSingleOrigin(); | 537 return data_source_->HasSingleOrigin(); |
| 551 return true; | 538 return true; |
| 552 } | 539 } |
| 553 | 540 |
| 554 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 541 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
| 555 if (data_source_) | 542 if (data_source_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 unsigned int level, | 582 unsigned int level, |
| 596 unsigned int internal_format, | 583 unsigned int internal_format, |
| 597 unsigned int type, | 584 unsigned int type, |
| 598 bool premultiply_alpha, | 585 bool premultiply_alpha, |
| 599 bool flip_y) { | 586 bool flip_y) { |
| 600 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 587 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 601 | 588 |
| 602 scoped_refptr<VideoFrame> video_frame = | 589 scoped_refptr<VideoFrame> video_frame = |
| 603 GetCurrentFrameFromCompositor(); | 590 GetCurrentFrameFromCompositor(); |
| 604 | 591 |
| 605 if (!video_frame.get()) | 592 if (!video_frame.get() || |
| 593 video_frame->format() != VideoFrame::NATIVE_TEXTURE) { |
| 606 return false; | 594 return false; |
| 607 if (video_frame->format() != VideoFrame::NATIVE_TEXTURE) | 595 } |
| 608 return false; | |
| 609 | 596 |
| 610 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 597 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
| 611 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 598 web_graphics_context, video_frame.get(), texture, level, internal_format, |
| 612 return false; | 599 type, premultiply_alpha, flip_y); |
| 613 | |
| 614 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | |
| 615 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | |
| 616 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | |
| 617 | |
| 618 // The video is stored in a unmultiplied format, so premultiply | |
| 619 // if necessary. | |
| 620 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
| 621 premultiply_alpha); | |
| 622 // Application itself needs to take care of setting the right 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; | 600 return true; |
| 643 } | 601 } |
| 644 | 602 |
| 645 WebMediaPlayer::MediaKeyException | 603 WebMediaPlayer::MediaKeyException |
| 646 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 604 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 647 const unsigned char* init_data, | 605 const unsigned char* init_data, |
| 648 unsigned init_data_length) { | 606 unsigned init_data_length) { |
| 649 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 607 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 650 | 608 |
| 651 return encrypted_media_support_->GenerateKeyRequest( | 609 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, | 990 compositor_task_runner_->PostTask(FROM_HERE, |
| 1033 base::Bind(&GetCurrentFrameAndSignal, | 991 base::Bind(&GetCurrentFrameAndSignal, |
| 1034 base::Unretained(compositor_), | 992 base::Unretained(compositor_), |
| 1035 &video_frame, | 993 &video_frame, |
| 1036 &event)); | 994 &event)); |
| 1037 event.Wait(); | 995 event.Wait(); |
| 1038 return video_frame; | 996 return video_frame; |
| 1039 } | 997 } |
| 1040 | 998 |
| 1041 } // namespace media | 999 } // namespace media |
| OLD | NEW |