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/bind_to_current_loop.h" | 26 #include "media/base/bind_to_current_loop.h" |
29 #include "media/base/cdm_context.h" | 27 #include "media/base/cdm_context.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/chunk_demuxer.h" | 42 #include "media/filters/chunk_demuxer.h" |
46 #include "media/filters/ffmpeg_demuxer.h" | 43 #include "media/filters/ffmpeg_demuxer.h" |
47 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 44 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
48 #include "third_party/WebKit/public/platform/WebRect.h" | 45 #include "third_party/WebKit/public/platform/WebRect.h" |
49 #include "third_party/WebKit/public/platform/WebSize.h" | 46 #include "third_party/WebKit/public/platform/WebSize.h" |
50 #include "third_party/WebKit/public/platform/WebString.h" | 47 #include "third_party/WebKit/public/platform/WebString.h" |
51 #include "third_party/WebKit/public/platform/WebURL.h" | 48 #include "third_party/WebKit/public/platform/WebURL.h" |
52 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 49 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
53 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 50 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
54 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 51 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
55 #include "third_party/WebKit/public/web/WebView.h" | 52 #include "third_party/WebKit/public/web/WebView.h" |
| 53 #include "webkit/common/gpu/webgraphicscontext3d_impl.h" |
56 | 54 |
57 using blink::WebCanvas; | 55 using blink::WebCanvas; |
58 using blink::WebMediaPlayer; | 56 using blink::WebMediaPlayer; |
59 using blink::WebRect; | 57 using blink::WebRect; |
60 using blink::WebSize; | 58 using blink::WebSize; |
61 using blink::WebString; | 59 using blink::WebString; |
62 | 60 |
63 namespace { | 61 namespace { |
64 | 62 |
65 // Limits the range of playback rate. | 63 // Limits the range of playback rate. |
66 // | 64 // |
67 // TODO(kylep): Revisit these. | 65 // TODO(kylep): Revisit these. |
68 // | 66 // |
69 // Vista has substantially lower performance than XP or Windows7. If you speed | 67 // Vista has substantially lower performance than XP or Windows7. If you speed |
70 // up a video too much, it can't keep up, and rendering stops updating except on | 68 // up a video too much, it can't keep up, and rendering stops updating except on |
71 // the time bar. For really high speeds, audio becomes a bottleneck and we just | 69 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
72 // use up the data we have, which may not achieve the speed requested, but will | 70 // use up the data we have, which may not achieve the speed requested, but will |
73 // not crash the tab. | 71 // not crash the tab. |
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 text_track_index_(0), | 144 text_track_index_(0), |
163 encrypted_media_support_( | 145 encrypted_media_support_( |
164 cdm_factory.Pass(), | 146 cdm_factory.Pass(), |
165 client, | 147 client, |
(...skipping 365 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 compositor_task_runner_->PostTask(FROM_HERE, | 988 compositor_task_runner_->PostTask(FROM_HERE, |
1026 base::Bind(&GetCurrentFrameAndSignal, | 989 base::Bind(&GetCurrentFrameAndSignal, |
1027 base::Unretained(compositor_), | 990 base::Unretained(compositor_), |
1028 &video_frame, | 991 &video_frame, |
1029 &event)); | 992 &event)); |
1030 event.Wait(); | 993 event.Wait(); |
1031 return video_frame; | 994 return video_frame; |
1032 } | 995 } |
1033 | 996 |
1034 } // namespace media | 997 } // namespace media |
OLD | NEW |