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