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 "content/renderer/media/webmediaplayer_impl.h" | 5 #include "content/renderer/media/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> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/renderer/media/crypto/encrypted_media_player_support.h" | 27 #include "content/renderer/media/crypto/encrypted_media_player_support.h" |
28 #include "content/renderer/media/render_media_log.h" | 28 #include "content/renderer/media/render_media_log.h" |
29 #include "content/renderer/media/texttrack_impl.h" | 29 #include "content/renderer/media/texttrack_impl.h" |
30 #include "content/renderer/media/webaudiosourceprovider_impl.h" | 30 #include "content/renderer/media/webaudiosourceprovider_impl.h" |
31 #include "content/renderer/media/webinbandtexttrack_impl.h" | 31 #include "content/renderer/media/webinbandtexttrack_impl.h" |
32 #include "content/renderer/media/webmediaplayer_delegate.h" | 32 #include "content/renderer/media/webmediaplayer_delegate.h" |
33 #include "content/renderer/media/webmediaplayer_params.h" | 33 #include "content/renderer/media/webmediaplayer_params.h" |
34 #include "content/renderer/media/webmediaplayer_util.h" | 34 #include "content/renderer/media/webmediaplayer_util.h" |
35 #include "content/renderer/media/webmediasource_impl.h" | 35 #include "content/renderer/media/webmediasource_impl.h" |
36 #include "content/renderer/render_thread_impl.h" | 36 #include "content/renderer/render_thread_impl.h" |
37 #include "gpu/GLES2/gl2extchromium.h" | |
38 #include "gpu/command_buffer/common/mailbox_holder.h" | |
39 #include "media/audio/null_audio_sink.h" | 37 #include "media/audio/null_audio_sink.h" |
40 #include "media/base/audio_hardware_config.h" | 38 #include "media/base/audio_hardware_config.h" |
41 #include "media/base/bind_to_current_loop.h" | 39 #include "media/base/bind_to_current_loop.h" |
42 #include "media/base/filter_collection.h" | 40 #include "media/base/filter_collection.h" |
43 #include "media/base/limits.h" | 41 #include "media/base/limits.h" |
44 #include "media/base/media_log.h" | 42 #include "media/base/media_log.h" |
45 #include "media/base/media_switches.h" | 43 #include "media/base/media_switches.h" |
46 #include "media/base/pipeline.h" | 44 #include "media/base/pipeline.h" |
47 #include "media/base/text_renderer.h" | 45 #include "media/base/text_renderer.h" |
48 #include "media/base/video_frame.h" | 46 #include "media/base/video_frame.h" |
49 #include "media/filters/audio_renderer_impl.h" | 47 #include "media/filters/audio_renderer_impl.h" |
50 #include "media/filters/chunk_demuxer.h" | 48 #include "media/filters/chunk_demuxer.h" |
51 #include "media/filters/ffmpeg_audio_decoder.h" | 49 #include "media/filters/ffmpeg_audio_decoder.h" |
52 #include "media/filters/ffmpeg_demuxer.h" | 50 #include "media/filters/ffmpeg_demuxer.h" |
53 #include "media/filters/ffmpeg_video_decoder.h" | 51 #include "media/filters/ffmpeg_video_decoder.h" |
54 #include "media/filters/gpu_video_accelerator_factories.h" | 52 #include "media/filters/gpu_video_accelerator_factories.h" |
55 #include "media/filters/gpu_video_decoder.h" | 53 #include "media/filters/gpu_video_decoder.h" |
56 #include "media/filters/opus_audio_decoder.h" | 54 #include "media/filters/opus_audio_decoder.h" |
57 #include "media/filters/renderer_impl.h" | 55 #include "media/filters/renderer_impl.h" |
58 #include "media/filters/video_renderer_impl.h" | 56 #include "media/filters/video_renderer_impl.h" |
59 #include "media/filters/vpx_video_decoder.h" | 57 #include "media/filters/vpx_video_decoder.h" |
60 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 58 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
61 #include "third_party/WebKit/public/platform/WebRect.h" | 59 #include "third_party/WebKit/public/platform/WebRect.h" |
62 #include "third_party/WebKit/public/platform/WebSize.h" | 60 #include "third_party/WebKit/public/platform/WebSize.h" |
63 #include "third_party/WebKit/public/platform/WebString.h" | 61 #include "third_party/WebKit/public/platform/WebString.h" |
64 #include "third_party/WebKit/public/platform/WebURL.h" | 62 #include "third_party/WebKit/public/platform/WebURL.h" |
65 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 63 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
66 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 64 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
67 #include "third_party/WebKit/public/web/WebView.h" | 65 #include "third_party/WebKit/public/web/WebView.h" |
| 66 #include "webkit/common/gpu/context_provider_web_context.h" |
| 67 #include "webkit/common/gpu/webgraphicscontext3d_impl.h" |
68 | 68 |
69 using blink::WebCanvas; | 69 using blink::WebCanvas; |
70 using blink::WebMediaPlayer; | 70 using blink::WebMediaPlayer; |
71 using blink::WebRect; | 71 using blink::WebRect; |
72 using blink::WebSize; | 72 using blink::WebSize; |
73 using blink::WebString; | 73 using blink::WebString; |
74 using media::PipelineStatus; | 74 using media::PipelineStatus; |
75 | 75 |
76 namespace { | 76 namespace { |
77 | 77 |
78 // Limits the range of playback rate. | 78 // Limits the range of playback rate. |
79 // | 79 // |
80 // TODO(kylep): Revisit these. | 80 // TODO(kylep): Revisit these. |
81 // | 81 // |
82 // Vista has substantially lower performance than XP or Windows7. If you speed | 82 // Vista has substantially lower performance than XP or Windows7. If you speed |
83 // up a video too much, it can't keep up, and rendering stops updating except on | 83 // up a video too much, it can't keep up, and rendering stops updating except on |
84 // the time bar. For really high speeds, audio becomes a bottleneck and we just | 84 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
85 // use up the data we have, which may not achieve the speed requested, but will | 85 // use up the data we have, which may not achieve the speed requested, but will |
86 // not crash the tab. | 86 // not crash the tab. |
87 // | 87 // |
88 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 88 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
89 // like a busy loop). It gets unresponsive, although its not completely dead. | 89 // like a busy loop). It gets unresponsive, although its not completely dead. |
90 // | 90 // |
91 // Also our timers are not very accurate (especially for ogg), which becomes | 91 // Also our timers are not very accurate (especially for ogg), which becomes |
92 // evident at low speeds and on Vista. Since other speeds are risky and outside | 92 // evident at low speeds and on Vista. Since other speeds are risky and outside |
93 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 93 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
94 const double kMinRate = 0.0625; | 94 const double kMinRate = 0.0625; |
95 const double kMaxRate = 16.0; | 95 const double kMaxRate = 16.0; |
96 | 96 |
97 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
98 public: | |
99 explicit SyncPointClientImpl( | |
100 blink::WebGraphicsContext3D* web_graphics_context) | |
101 : web_graphics_context_(web_graphics_context) {} | |
102 virtual ~SyncPointClientImpl() {} | |
103 virtual uint32 InsertSyncPoint() OVERRIDE { | |
104 return web_graphics_context_->insertSyncPoint(); | |
105 } | |
106 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { | |
107 web_graphics_context_->waitSyncPoint(sync_point); | |
108 } | |
109 | |
110 private: | |
111 blink::WebGraphicsContext3D* web_graphics_context_; | |
112 }; | |
113 | |
114 } // namespace | 97 } // namespace |
115 | 98 |
116 namespace content { | 99 namespace content { |
117 | 100 |
118 class BufferedDataSourceHostImpl; | 101 class BufferedDataSourceHostImpl; |
119 | 102 |
120 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 103 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
121 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 104 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
122 static_cast<int>(BufferedResourceLoader::k ## name), \ | 105 static_cast<int>(BufferedResourceLoader::k ## name), \ |
123 mismatching_enums) | 106 mismatching_enums) |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 494 |
512 // TODO(scherkus): Clarify paint() API contract to better understand when and | 495 // TODO(scherkus): Clarify paint() API contract to better understand when and |
513 // why it's being called. For example, today paint() is called when: | 496 // why it's being called. For example, today paint() is called when: |
514 // - We haven't reached HAVE_CURRENT_DATA and need to paint black | 497 // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
515 // - We're painting to a canvas | 498 // - We're painting to a canvas |
516 // See http://crbug.com/341225 http://crbug.com/342621 for details. | 499 // See http://crbug.com/341225 http://crbug.com/342621 for details. |
517 scoped_refptr<media::VideoFrame> video_frame = | 500 scoped_refptr<media::VideoFrame> video_frame = |
518 GetCurrentFrameFromCompositor(); | 501 GetCurrentFrameFromCompositor(); |
519 | 502 |
520 gfx::Rect gfx_rect(rect); | 503 gfx::Rect gfx_rect(rect); |
521 | 504 scoped_refptr<cc::ContextProvider> context_provider = |
| 505 RenderThreadImpl::current()->SharedMainThreadContextProvider(); |
| 506 media::SkCanvasVideoRenderer::Context3DProvider provider{ |
| 507 context_provider->ContextGL(), context_provider->GrContext()}; |
522 skcanvas_video_renderer_.Paint(video_frame.get(), | 508 skcanvas_video_renderer_.Paint(video_frame.get(), |
523 canvas, | 509 canvas, |
524 gfx_rect, | 510 gfx_rect, |
525 alpha, | 511 alpha, |
526 mode, | 512 mode, |
527 pipeline_metadata_.video_rotation); | 513 pipeline_metadata_.video_rotation, |
| 514 &provider); |
528 } | 515 } |
529 | 516 |
530 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { | 517 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
531 if (data_source_) | 518 if (data_source_) |
532 return data_source_->HasSingleOrigin(); | 519 return data_source_->HasSingleOrigin(); |
533 return true; | 520 return true; |
534 } | 521 } |
535 | 522 |
536 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { | 523 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
537 if (data_source_) | 524 if (data_source_) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 unsigned int level, | 564 unsigned int level, |
578 unsigned int internal_format, | 565 unsigned int internal_format, |
579 unsigned int type, | 566 unsigned int type, |
580 bool premultiply_alpha, | 567 bool premultiply_alpha, |
581 bool flip_y) { | 568 bool flip_y) { |
582 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); | 569 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
583 | 570 |
584 scoped_refptr<media::VideoFrame> video_frame = | 571 scoped_refptr<media::VideoFrame> video_frame = |
585 GetCurrentFrameFromCompositor(); | 572 GetCurrentFrameFromCompositor(); |
586 | 573 |
587 if (!video_frame.get()) | 574 if (!video_frame || |
588 return false; | 575 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) |
589 if (video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) | |
590 return false; | 576 return false; |
591 | 577 |
592 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 578 // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
593 if (mailbox_holder->texture_target != GL_TEXTURE_2D) | 579 // GLES2Interface. |
594 return false; | 580 gpu::gles2::GLES2Interface* gl = |
595 | 581 static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context) |
596 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 582 ->GetGLInterface(); |
597 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 583 skcanvas_video_renderer_.CopyVideoFrameToTexture(gl, |
598 GL_TEXTURE_2D, mailbox_holder->mailbox.name); | 584 video_frame.get(), |
599 | 585 texture, |
600 // The video is stored in a unmultiplied format, so premultiply | 586 level, |
601 // if necessary. | 587 internal_format, |
602 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 588 type, |
603 premultiply_alpha); | 589 premultiply_alpha, |
604 // Application itself needs to take care of setting the right flip_y | 590 flip_y); |
605 // value down to get the expected result. | |
606 // flip_y==true means to reverse the video orientation while | |
607 // flip_y==false means to keep the intrinsic orientation. | |
608 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | |
609 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, | |
610 source_texture, | |
611 texture, | |
612 level, | |
613 internal_format, | |
614 type); | |
615 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | |
616 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | |
617 false); | |
618 | |
619 web_graphics_context->deleteTexture(source_texture); | |
620 web_graphics_context->flush(); | |
621 | |
622 SyncPointClientImpl client(web_graphics_context); | |
623 video_frame->UpdateReleaseSyncPoint(&client); | |
624 return true; | 591 return true; |
625 } | 592 } |
626 | 593 |
627 WebMediaPlayer::MediaKeyException | 594 WebMediaPlayer::MediaKeyException |
628 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, | 595 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
629 const unsigned char* init_data, | 596 const unsigned char* init_data, |
630 unsigned init_data_length) { | 597 unsigned init_data_length) { |
631 DCHECK(main_loop_->BelongsToCurrentThread()); | 598 DCHECK(main_loop_->BelongsToCurrentThread()); |
632 | 599 |
633 return encrypted_media_support_->GenerateKeyRequest( | 600 return encrypted_media_support_->GenerateKeyRequest( |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 compositor_task_runner_->PostTask(FROM_HERE, | 995 compositor_task_runner_->PostTask(FROM_HERE, |
1029 base::Bind(&GetCurrentFrameAndSignal, | 996 base::Bind(&GetCurrentFrameAndSignal, |
1030 base::Unretained(compositor_), | 997 base::Unretained(compositor_), |
1031 &video_frame, | 998 &video_frame, |
1032 &event)); | 999 &event)); |
1033 event.Wait(); | 1000 event.Wait(); |
1034 return video_frame; | 1001 return video_frame; |
1035 } | 1002 } |
1036 | 1003 |
1037 } // namespace content | 1004 } // namespace content |
OLD | NEW |