Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 12902002: Remove WebVideoFrame, WebVideoFrameProvider, and WebVideoLayer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/media/webmediaplayer_impl.h" 5 #include "webkit/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>
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/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "cc/layers/video_layer.h"
18 #include "gpu/GLES2/gl2extchromium.h" 19 #include "gpu/GLES2/gl2extchromium.h"
19 #include "media/audio/null_audio_sink.h" 20 #include "media/audio/null_audio_sink.h"
20 #include "media/base/bind_to_loop.h" 21 #include "media/base/bind_to_loop.h"
21 #include "media/base/filter_collection.h" 22 #include "media/base/filter_collection.h"
22 #include "media/base/limits.h" 23 #include "media/base/limits.h"
23 #include "media/base/media_log.h" 24 #include "media/base/media_log.h"
24 #include "media/base/pipeline.h" 25 #include "media/base/pipeline.h"
25 #include "media/base/video_frame.h" 26 #include "media/base/video_frame.h"
26 #include "media/filters/audio_renderer_impl.h" 27 #include "media/filters/audio_renderer_impl.h"
27 #include "media/filters/chunk_demuxer.h" 28 #include "media/filters/chunk_demuxer.h"
28 #include "media/filters/video_renderer_base.h" 29 #include "media/filters/video_renderer_base.h"
29 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
30 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
31 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
32 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 33 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
36 #include "v8/include/v8.h" 37 #include "v8/include/v8.h"
38 #include "webkit/compositor_bindings/web_layer_impl.h"
37 #include "webkit/media/buffered_data_source.h" 39 #include "webkit/media/buffered_data_source.h"
38 #include "webkit/media/filter_helpers.h" 40 #include "webkit/media/filter_helpers.h"
39 #include "webkit/media/webaudiosourceprovider_impl.h" 41 #include "webkit/media/webaudiosourceprovider_impl.h"
40 #include "webkit/media/webmediaplayer_delegate.h" 42 #include "webkit/media/webmediaplayer_delegate.h"
41 #include "webkit/media/webmediaplayer_params.h" 43 #include "webkit/media/webmediaplayer_params.h"
42 #include "webkit/media/webmediaplayer_util.h" 44 #include "webkit/media/webmediaplayer_util.h"
43 #include "webkit/media/webmediasourceclient_impl.h" 45 #include "webkit/media/webmediasourceclient_impl.h"
44 #include "webkit/media/webvideoframe_impl.h"
45 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" 46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
46 47
47 using WebKit::WebCanvas; 48 using WebKit::WebCanvas;
48 using WebKit::WebMediaPlayer; 49 using WebKit::WebMediaPlayer;
49 using WebKit::WebRect; 50 using WebKit::WebRect;
50 using WebKit::WebSize; 51 using WebKit::WebSize;
51 using WebKit::WebString; 52 using WebKit::WebString;
52 using media::PipelineStatus; 53 using media::PipelineStatus;
53 54
54 namespace { 55 namespace {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 pending_seek_(false), 139 pending_seek_(false),
139 pending_seek_seconds_(0.0f), 140 pending_seek_seconds_(0.0f),
140 client_(client), 141 client_(client),
141 delegate_(delegate), 142 delegate_(delegate),
142 media_log_(params.media_log()), 143 media_log_(params.media_log()),
143 accelerated_compositing_reported_(false), 144 accelerated_compositing_reported_(false),
144 incremented_externally_allocated_memory_(false), 145 incremented_externally_allocated_memory_(false),
145 is_local_source_(false), 146 is_local_source_(false),
146 supports_save_(true), 147 supports_save_(true),
147 starting_(false), 148 starting_(false),
148 pending_repaint_(false) { 149 pending_repaint_(false),
150 video_frame_provider_client_(NULL) {
149 media_log_->AddEvent( 151 media_log_->AddEvent(
150 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 152 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
151 153
152 CHECK(media_thread_.Start()); 154 CHECK(media_thread_.Start());
153 pipeline_ = new media::Pipeline( 155 pipeline_ = new media::Pipeline(
154 media_thread_.message_loop_proxy(), media_log_); 156 media_thread_.message_loop_proxy(), media_log_);
155 157
156 // Let V8 know we started new thread if we did not do it yet. 158 // Let V8 know we started new thread if we did not do it yet.
157 // Made separate task to avoid deletion of player currently being created. 159 // Made separate task to avoid deletion of player currently being created.
158 // Also, delaying GC until after player starts gets rid of starting lag -- 160 // Also, delaying GC until after player starts gets rid of starting lag --
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 new media::NullAudioSink(media_thread_.message_loop_proxy())); 206 new media::NullAudioSink(media_thread_.message_loop_proxy()));
205 scoped_ptr<media::AudioRenderer> audio_renderer( 207 scoped_ptr<media::AudioRenderer> audio_renderer(
206 new media::AudioRendererImpl( 208 new media::AudioRendererImpl(
207 media_thread_.message_loop_proxy(), 209 media_thread_.message_loop_proxy(),
208 audio_source_provider_, 210 audio_source_provider_,
209 set_decryptor_ready_cb)); 211 set_decryptor_ready_cb));
210 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); 212 filter_collection_->SetAudioRenderer(audio_renderer.Pass());
211 } 213 }
212 214
213 WebMediaPlayerImpl::~WebMediaPlayerImpl() { 215 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
216 SetVideoFrameProviderClient(NULL);
217 // No need for a lock here, as GetCurrentFrame/PutCurrentFrame can't be
218 // called now that the client is no longer using this provider. Also, load()
219 // and this destructor are called from the same thread.
220 setStreamTextureClient(NULL);
scherkus (not reviewing) 2013/03/18 21:38:24 isn't this handled by the call to SVFPC(NULL)?
danakj 2013/03/18 21:57:59 Oh, yes! This is the one sketchy thing about this
scherkus (not reviewing) 2013/03/18 23:34:18 I'm a bit confused. An IM/VC convo might be in ord
danakj 2013/03/18 23:37:15 Without looking at the android code, it would be p
221
214 DCHECK(main_loop_->BelongsToCurrentThread()); 222 DCHECK(main_loop_->BelongsToCurrentThread());
215 Destroy(); 223 Destroy();
216 media_log_->AddEvent( 224 media_log_->AddEvent(
217 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 225 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
218 226
219 if (delegate_) 227 if (delegate_)
220 delegate_->PlayerGone(this); 228 delegate_->PlayerGone(this);
221 229
222 // Remove destruction observer if we're being destroyed but the main thread is 230 // Remove destruction observer if we're being destroyed but the main thread is
223 // still running. 231 // still running.
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 return stats.audio_bytes_decoded; 657 return stats.audio_bytes_decoded;
650 } 658 }
651 659
652 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { 660 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const {
653 DCHECK(main_loop_->BelongsToCurrentThread()); 661 DCHECK(main_loop_->BelongsToCurrentThread());
654 662
655 media::PipelineStatistics stats = pipeline_->GetStatistics(); 663 media::PipelineStatistics stats = pipeline_->GetStatistics();
656 return stats.video_bytes_decoded; 664 return stats.video_bytes_decoded;
657 } 665 }
658 666
659 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { 667 WebKit::WebLayer* WebMediaPlayerImpl::createCompositingLayer() {
660 base::AutoLock auto_lock(lock_); 668 return new webkit::WebLayerImpl(cc::VideoLayer::Create(this));
661 if (current_frame_)
662 return new WebVideoFrameImpl(current_frame_);
663 return NULL;
664 } 669 }
665 670
666 void WebMediaPlayerImpl::putCurrentFrame( 671 void WebMediaPlayerImpl::SetVideoFrameProviderClient(
667 WebKit::WebVideoFrame* web_video_frame) { 672 cc::VideoFrameProvider::Client* client) {
673 base::AutoLock auto_lock(provider_lock_);
674 if (video_frame_provider_client_)
675 video_frame_provider_client_->StopUsingProvider();
676 video_frame_provider_client_ = client;
677 setStreamTextureClient(client ? this : NULL);
678 }
679
680 scoped_refptr<media::VideoFrame> WebMediaPlayerImpl::GetCurrentFrame() {
681 base::AutoLock auto_lock(lock_);
682 return current_frame_;
683 }
684
685 void WebMediaPlayerImpl::PutCurrentFrame(
686 const scoped_refptr<media::VideoFrame>& frame) {
687 base::AutoLock auto_lock(lock_);
668 if (!accelerated_compositing_reported_) { 688 if (!accelerated_compositing_reported_) {
669 accelerated_compositing_reported_ = true; 689 accelerated_compositing_reported_ = true;
670 DCHECK(frame_->view()->isAcceleratedCompositingActive()); 690 DCHECK(frame_->view()->isAcceleratedCompositingActive());
671 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); 691 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true);
672 } 692 }
673 delete web_video_frame; 693 }
694
695 void WebMediaPlayerImpl::didReceiveFrame() {
696 // No lock since this gets called on the client's thread.
697 video_frame_provider_client_->DidReceiveFrame();
698 }
699
700 void WebMediaPlayerImpl::didUpdateMatrix(const float* matrix) {
701 // No lock since this gets called on the client's thread.
702 video_frame_provider_client_->DidUpdateMatrix(matrix);
674 } 703 }
675 704
676 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( 705 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture(
677 WebKit::WebGraphicsContext3D* web_graphics_context, 706 WebKit::WebGraphicsContext3D* web_graphics_context,
678 unsigned int texture, 707 unsigned int texture,
679 unsigned int level, 708 unsigned int level,
680 unsigned int internal_format, 709 unsigned int internal_format,
681 bool premultiply_alpha, 710 bool premultiply_alpha,
682 bool flip_y) { 711 bool flip_y) {
683 scoped_refptr<media::VideoFrame> video_frame; 712 scoped_refptr<media::VideoFrame> video_frame;
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 1229
1201 if (pending_repaint_) 1230 if (pending_repaint_)
1202 return; 1231 return;
1203 1232
1204 pending_repaint_ = true; 1233 pending_repaint_ = true;
1205 main_loop_->PostTask(FROM_HERE, base::Bind( 1234 main_loop_->PostTask(FROM_HERE, base::Bind(
1206 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); 1235 &WebMediaPlayerImpl::Repaint, AsWeakPtr()));
1207 } 1236 }
1208 1237
1209 } // namespace webkit_media 1238 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698