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" | 25 #include "gpu/blink/webgraphicscontext3d_impl.h" |
26 #include "gpu/command_buffer/common/mailbox_holder.h" | |
27 #include "media/audio/null_audio_sink.h" | 26 #include "media/audio/null_audio_sink.h" |
28 #include "media/base/bind_to_current_loop.h" | 27 #include "media/base/bind_to_current_loop.h" |
29 #include "media/base/cdm_context.h" | 28 #include "media/base/cdm_context.h" |
30 #include "media/base/limits.h" | 29 #include "media/base/limits.h" |
31 #include "media/base/media_log.h" | 30 #include "media/base/media_log.h" |
32 #include "media/base/pipeline.h" | 31 #include "media/base/pipeline.h" |
33 #include "media/base/text_renderer.h" | 32 #include "media/base/text_renderer.h" |
34 #include "media/base/video_frame.h" | 33 #include "media/base/video_frame.h" |
35 #include "media/blink/buffered_data_source.h" | 34 #include "media/blink/buffered_data_source.h" |
36 #include "media/blink/encrypted_media_player_support.h" | 35 #include "media/blink/encrypted_media_player_support.h" |
37 #include "media/blink/texttrack_impl.h" | 36 #include "media/blink/texttrack_impl.h" |
38 #include "media/blink/webaudiosourceprovider_impl.h" | 37 #include "media/blink/webaudiosourceprovider_impl.h" |
39 #include "media/blink/webcontentdecryptionmodule_impl.h" | 38 #include "media/blink/webcontentdecryptionmodule_impl.h" |
40 #include "media/blink/webinbandtexttrack_impl.h" | 39 #include "media/blink/webinbandtexttrack_impl.h" |
41 #include "media/blink/webmediaplayer_delegate.h" | 40 #include "media/blink/webmediaplayer_delegate.h" |
42 #include "media/blink/webmediaplayer_params.h" | |
43 #include "media/blink/webmediaplayer_util.h" | 41 #include "media/blink/webmediaplayer_util.h" |
44 #include "media/blink/webmediasource_impl.h" | 42 #include "media/blink/webmediasource_impl.h" |
45 #include "media/filters/chunk_demuxer.h" | 43 #include "media/filters/chunk_demuxer.h" |
46 #include "media/filters/ffmpeg_demuxer.h" | 44 #include "media/filters/ffmpeg_demuxer.h" |
47 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 45 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
48 #include "third_party/WebKit/public/platform/WebRect.h" | 46 #include "third_party/WebKit/public/platform/WebRect.h" |
49 #include "third_party/WebKit/public/platform/WebSize.h" | 47 #include "third_party/WebKit/public/platform/WebSize.h" |
50 #include "third_party/WebKit/public/platform/WebString.h" | 48 #include "third_party/WebKit/public/platform/WebString.h" |
51 #include "third_party/WebKit/public/platform/WebURL.h" | 49 #include "third_party/WebKit/public/platform/WebURL.h" |
52 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 50 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 21 matching lines...) Expand all Loading... |
74 // | 72 // |
75 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 73 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
76 // like a busy loop). It gets unresponsive, although its not completely dead. | 74 // like a busy loop). It gets unresponsive, although its not completely dead. |
77 // | 75 // |
78 // Also our timers are not very accurate (especially for ogg), which becomes | 76 // Also our timers are not very accurate (especially for ogg), which becomes |
79 // evident at low speeds and on Vista. Since other speeds are risky and outside | 77 // evident at low speeds and on Vista. Since other speeds are risky and outside |
80 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 78 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
81 const double kMinRate = 0.0625; | 79 const double kMinRate = 0.0625; |
82 const double kMaxRate = 16.0; | 80 const double kMaxRate = 16.0; |
83 | 81 |
84 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
85 public: | |
86 explicit SyncPointClientImpl( | |
87 blink::WebGraphicsContext3D* web_graphics_context) | |
88 : web_graphics_context_(web_graphics_context) {} | |
89 ~SyncPointClientImpl() override {} | |
90 uint32 InsertSyncPoint() override { | |
91 return web_graphics_context_->insertSyncPoint(); | |
92 } | |
93 void WaitSyncPoint(uint32 sync_point) override { | |
94 web_graphics_context_->waitSyncPoint(sync_point); | |
95 } | |
96 | |
97 private: | |
98 blink::WebGraphicsContext3D* web_graphics_context_; | |
99 }; | |
100 | |
101 } // namespace | 82 } // namespace |
102 | 83 |
103 namespace media { | 84 namespace media { |
104 | 85 |
105 class BufferedDataSourceHostImpl; | 86 class BufferedDataSourceHostImpl; |
106 | 87 |
107 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 88 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
108 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 89 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
109 static_cast<int>(BufferedResourceLoader::k ## name), \ | 90 static_cast<int>(BufferedResourceLoader::k ## name), \ |
110 mismatching_enums) | 91 mismatching_enums) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 paused_(true), | 127 paused_(true), |
147 seeking_(false), | 128 seeking_(false), |
148 playback_rate_(0.0f), | 129 playback_rate_(0.0f), |
149 ended_(false), | 130 ended_(false), |
150 pending_seek_(false), | 131 pending_seek_(false), |
151 pending_seek_seconds_(0.0f), | 132 pending_seek_seconds_(0.0f), |
152 should_notify_time_changed_(false), | 133 should_notify_time_changed_(false), |
153 client_(client), | 134 client_(client), |
154 delegate_(delegate), | 135 delegate_(delegate), |
155 defer_load_cb_(params.defer_load_cb()), | 136 defer_load_cb_(params.defer_load_cb()), |
| 137 context_3d_cb_(params.context_3d_cb()), |
156 supports_save_(true), | 138 supports_save_(true), |
157 chunk_demuxer_(NULL), | 139 chunk_demuxer_(NULL), |
158 compositor_task_runner_(params.compositor_task_runner()), | 140 compositor_task_runner_(params.compositor_task_runner()), |
159 compositor_(new VideoFrameCompositor( | 141 compositor_(new VideoFrameCompositor( |
160 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 142 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
161 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
162 encrypted_media_support_( | 144 encrypted_media_support_( |
163 cdm_factory.Pass(), | 145 cdm_factory.Pass(), |
164 client, | 146 client, |
165 base::Bind(&WebMediaPlayerImpl::SetCdm, AsWeakPtr())), | 147 base::Bind(&WebMediaPlayerImpl::SetCdm, AsWeakPtr())), |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 515 |
534 // TODO(scherkus): Clarify paint() API contract to better understand when and | 516 // TODO(scherkus): Clarify paint() API contract to better understand when and |
535 // why it's being called. For example, today paint() is called when: | 517 // why it's being called. For example, today paint() is called when: |
536 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 518 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
537 // - We're painting to a canvas | 519 // - We're painting to a canvas |
538 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 520 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
539 scoped_refptr<VideoFrame> video_frame = | 521 scoped_refptr<VideoFrame> video_frame = |
540 GetCurrentFrameFromCompositor(); | 522 GetCurrentFrameFromCompositor(); |
541 | 523 |
542 gfx::Rect gfx_rect(rect); | 524 gfx::Rect gfx_rect(rect); |
543 | 525 Context3D context_3d; |
544 skcanvas_video_renderer_.Paint(video_frame, | 526 if (video_frame.get() && |
545 canvas, | 527 video_frame->format() == VideoFrame::NATIVE_TEXTURE) { |
546 gfx_rect, | 528 if (!context_3d_cb_.is_null()) { |
547 alpha, | 529 context_3d = context_3d_cb_.Run(); |
548 mode, | 530 } |
549 pipeline_metadata_.video_rotation); | 531 // GPU Process crashed. |
| 532 if (!context_3d.gl) |
| 533 return; |
| 534 } |
| 535 skcanvas_video_renderer_.Paint(video_frame, canvas, gfx_rect, alpha, mode, |
| 536 pipeline_metadata_.video_rotation, context_3d); |
550 } | 537 } |
551 | 538 |
552 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 539 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
553 if (data_source_) | 540 if (data_source_) |
554 return data_source_->HasSingleOrigin(); | 541 return data_source_->HasSingleOrigin(); |
555 return true; | 542 return true; |
556 } | 543 } |
557 | 544 |
558 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 545 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
559 if (data_source_) | 546 if (data_source_) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 unsigned int level, | 586 unsigned int level, |
600 unsigned int internal_format, | 587 unsigned int internal_format, |
601 unsigned int type, | 588 unsigned int type, |
602 bool premultiply_alpha, | 589 bool premultiply_alpha, |
603 bool flip_y) { | 590 bool flip_y) { |
604 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 591 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
605 | 592 |
606 scoped_refptr<VideoFrame> video_frame = | 593 scoped_refptr<VideoFrame> video_frame = |
607 GetCurrentFrameFromCompositor(); | 594 GetCurrentFrameFromCompositor(); |
608 | 595 |
609 if (!video_frame.get()) | 596 if (!video_frame.get() || |
| 597 video_frame->format() != VideoFrame::NATIVE_TEXTURE) { |
610 return false; | 598 return false; |
611 if (video_frame->format() != VideoFrame::NATIVE_TEXTURE) | 599 } |
612 return false; | |
613 | 600 |
614 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 601 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
615 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 602 // GLES2Interface. |
616 return false; | 603 gpu::gles2::GLES2Interface* gl = |
617 | 604 static_cast<gpu_blink::WebGraphicsContext3DImpl*>(web_graphics_context) |
618 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 605 ->GetGLInterface(); |
619 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 606 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
620 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 607 gl, video_frame.get(), texture, level, internal_format, type, |
621 | 608 premultiply_alpha, flip_y); |
622 // The video is stored in a unmultiplied format, so premultiply | |
623 // if necessary. | |
624 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
625 premultiply_alpha); | |
626 // Application itself needs to take care of setting the right flip_y | |
627 // value down to get the expected result. | |
628 // flip_y==true means to reverse the video orientation while | |
629 // flip_y==false means to keep the intrinsic orientation. | |
630 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
631 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
632 source_texture, | |
633 texture, | |
634 level, | |
635 internal_format, | |
636 type); | |
637 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
638 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
639 false); | |
640 | |
641 web_graphics_context->deleteTexture(source_texture); | |
642 web_graphics_context->flush(); | |
643 | |
644 SyncPointClientImpl client(web_graphics_context); | |
645 video_frame->UpdateReleaseSyncPoint(&client); | |
646 return true; | 609 return true; |
647 } | 610 } |
648 | 611 |
649 WebMediaPlayer::MediaKeyException | 612 WebMediaPlayer::MediaKeyException |
650 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 613 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
651 const unsigned char* init_data, | 614 const unsigned char* init_data, |
652 unsigned init_data_length) { | 615 unsigned init_data_length) { |
653 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 616 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
654 | 617 |
655 return encrypted_media_support_.GenerateKeyRequest( | 618 return encrypted_media_support_.GenerateKeyRequest( |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 compositor_task_runner_->PostTask(FROM_HERE, | 989 compositor_task_runner_->PostTask(FROM_HERE, |
1027 base::Bind(&GetCurrentFrameAndSignal, | 990 base::Bind(&GetCurrentFrameAndSignal, |
1028 base::Unretained(compositor_), | 991 base::Unretained(compositor_), |
1029 &video_frame, | 992 &video_frame, |
1030 &event)); | 993 &event)); |
1031 event.Wait(); | 994 event.Wait(); |
1032 return video_frame; | 995 return video_frame; |
1033 } | 996 } |
1034 | 997 |
1035 } // namespace media | 998 } // namespace media |
OLD | NEW |