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