OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glue/webmediaplayer_impl.h" | 5 #include "webkit/glue/webmediaplayer_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 message_loop_factory_(message_loop_factory), | 113 message_loop_factory_(message_loop_factory), |
114 paused_(true), | 114 paused_(true), |
115 seeking_(false), | 115 seeking_(false), |
116 playback_rate_(0.0f), | 116 playback_rate_(0.0f), |
117 pending_seek_(false), | 117 pending_seek_(false), |
118 client_(client), | 118 client_(client), |
119 proxy_(NULL), | 119 proxy_(NULL), |
120 delegate_(delegate), | 120 delegate_(delegate), |
121 media_stream_client_(media_stream_client), | 121 media_stream_client_(media_stream_client), |
122 media_log_(media_log), | 122 media_log_(media_log), |
123 is_accelerated_compositing_active_(false), | |
123 incremented_externally_allocated_memory_(false) { | 124 incremented_externally_allocated_memory_(false) { |
124 // Saves the current message loop. | 125 // Saves the current message loop. |
125 DCHECK(!main_loop_); | 126 DCHECK(!main_loop_); |
126 main_loop_ = MessageLoop::current(); | 127 main_loop_ = MessageLoop::current(); |
127 media_log_->AddEvent( | 128 media_log_->AddEvent( |
128 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 129 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
129 } | 130 } |
130 | 131 |
131 bool WebMediaPlayerImpl::Initialize( | 132 bool WebMediaPlayerImpl::Initialize( |
132 WebKit::WebFrame* frame, | 133 WebKit::WebFrame* frame, |
(...skipping 12 matching lines...) Expand all Loading... | |
145 // Also, delaying GC until after player starts gets rid of starting lag -- | 146 // Also, delaying GC until after player starts gets rid of starting lag -- |
146 // collection happens in parallel with playing. | 147 // collection happens in parallel with playing. |
147 // TODO(enal): remove when we get rid of per-audio-stream thread. | 148 // TODO(enal): remove when we get rid of per-audio-stream thread. |
148 if (!incremented_externally_allocated_memory_) { | 149 if (!incremented_externally_allocated_memory_) { |
149 MessageLoop::current()->PostTask( | 150 MessageLoop::current()->PostTask( |
150 FROM_HERE, | 151 FROM_HERE, |
151 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 152 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
152 AsWeakPtr())); | 153 AsWeakPtr())); |
153 } | 154 } |
154 | 155 |
155 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", | 156 is_accelerated_compositing_active_ = |
156 frame->view()->isAcceleratedCompositingActive()); | 157 frame->view()->isAcceleratedCompositingActive(); |
157 | 158 |
158 pipeline_ = new media::PipelineImpl(pipeline_message_loop, media_log_); | 159 pipeline_ = new media::PipelineImpl(pipeline_message_loop, media_log_); |
159 | 160 |
160 // Also we want to be notified of |main_loop_| destruction. | 161 // Also we want to be notified of |main_loop_| destruction. |
161 main_loop_->AddDestructionObserver(this); | 162 main_loop_->AddDestructionObserver(this); |
162 | 163 |
163 // Creates the proxy. | 164 // Creates the proxy. |
164 proxy_ = new WebMediaPlayerProxy(main_loop_, this); | 165 proxy_ = new WebMediaPlayerProxy(main_loop_, this); |
165 web_video_renderer->SetWebMediaPlayerProxy(proxy_); | 166 web_video_renderer->SetWebMediaPlayerProxy(proxy_); |
166 proxy_->SetVideoRenderer(web_video_renderer); | 167 proxy_->SetVideoRenderer(web_video_renderer); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 if (delegate_) | 231 if (delegate_) |
231 delegate_->PlayerGone(this); | 232 delegate_->PlayerGone(this); |
232 | 233 |
233 // Finally tell the |main_loop_| we don't want to be notified of destruction | 234 // Finally tell the |main_loop_| we don't want to be notified of destruction |
234 // event. | 235 // event. |
235 if (main_loop_) { | 236 if (main_loop_) { |
236 main_loop_->RemoveDestructionObserver(this); | 237 main_loop_->RemoveDestructionObserver(this); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
241 // Helper enum for reporting scheme histograms. | |
242 enum URLSchemeForHistogram { | |
243 kUnknownURLScheme, | |
244 kMissingURLScheme, | |
245 kHttpURLScheme, | |
246 kHttpsURLScheme, | |
247 kFileURLScheme, | |
248 kBlobURLScheme, | |
249 kDataURLScheme, | |
250 kMaxURLScheme = kDataURLScheme // Must be equal to highest enum value. | |
251 }; | |
252 | |
253 static URLSchemeForHistogram URLScheme(const GURL& url) { | |
254 if (!url.has_scheme()) return kMissingURLScheme; | |
255 if (url.SchemeIs("http")) return kHttpURLScheme; | |
256 if (url.SchemeIs("https")) return kHttpsURLScheme; | |
257 if (url.SchemeIs("file")) return kFileURLScheme; | |
258 if (url.SchemeIs("blob")) return kBlobURLScheme; | |
259 if (url.SchemeIs("data")) return kDataURLScheme; | |
scherkus (not reviewing)
2011/11/15 20:01:07
chrome-extension is another good one
what about s
Ami GONE FROM CHROMIUM
2011/11/15 20:33:28
Added.
| |
260 return kUnknownURLScheme; | |
261 } | |
262 | |
240 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { | 263 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { |
241 DCHECK_EQ(main_loop_, MessageLoop::current()); | 264 DCHECK_EQ(main_loop_, MessageLoop::current()); |
242 DCHECK(proxy_); | 265 DCHECK(proxy_); |
243 | 266 |
267 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme); | |
268 | |
244 if (media_stream_client_) { | 269 if (media_stream_client_) { |
245 bool has_video = false; | 270 bool has_video = false; |
246 bool has_audio = false; | 271 bool has_audio = false; |
247 scoped_refptr<media::VideoDecoder> new_decoder = | 272 scoped_refptr<media::VideoDecoder> new_decoder = |
248 media_stream_client_->GetVideoDecoder(url, message_loop_factory_.get()); | 273 media_stream_client_->GetVideoDecoder(url, message_loop_factory_.get()); |
249 if (new_decoder.get()) { | 274 if (new_decoder.get()) { |
250 // Remove the default decoder. | 275 // Remove the default decoder. |
251 scoped_refptr<media::VideoDecoder> old_videodecoder; | 276 scoped_refptr<media::VideoDecoder> old_videodecoder; |
252 filter_collection_->SelectVideoDecoder(&old_videodecoder); | 277 filter_collection_->SelectVideoDecoder(&old_videodecoder); |
253 filter_collection_->AddVideoDecoder(new_decoder.get()); | 278 filter_collection_->AddVideoDecoder(new_decoder.get()); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) { | 726 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) { |
702 DCHECK_EQ(main_loop_, MessageLoop::current()); | 727 DCHECK_EQ(main_loop_, MessageLoop::current()); |
703 if (status == media::PIPELINE_OK) { | 728 if (status == media::PIPELINE_OK) { |
704 // Only keep one time range starting from 0. | 729 // Only keep one time range starting from 0. |
705 WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1)); | 730 WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1)); |
706 new_buffered[0].start = 0.0f; | 731 new_buffered[0].start = 0.0f; |
707 new_buffered[0].end = | 732 new_buffered[0].end = |
708 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); | 733 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); |
709 buffered_.swap(new_buffered); | 734 buffered_.swap(new_buffered); |
710 | 735 |
736 if (hasVideo()) { | |
737 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", | |
738 is_accelerated_compositing_active_); | |
739 } | |
740 | |
711 if (pipeline_->IsLoaded()) { | 741 if (pipeline_->IsLoaded()) { |
712 SetNetworkState(WebKit::WebMediaPlayer::Loaded); | 742 SetNetworkState(WebKit::WebMediaPlayer::Loaded); |
713 } | 743 } |
714 | 744 |
715 // Since we have initialized the pipeline, say we have everything otherwise | 745 // Since we have initialized the pipeline, say we have everything otherwise |
716 // we'll remain either loading/idle. | 746 // we'll remain either loading/idle. |
717 // TODO(hclam): change this to report the correct status. | 747 // TODO(hclam): change this to report the correct status. |
718 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); | 748 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); |
719 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); | 749 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); |
720 } else { | 750 } else { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 return client_; | 898 return client_; |
869 } | 899 } |
870 | 900 |
871 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 901 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
872 DCHECK_EQ(main_loop_, MessageLoop::current()); | 902 DCHECK_EQ(main_loop_, MessageLoop::current()); |
873 incremented_externally_allocated_memory_ = true; | 903 incremented_externally_allocated_memory_ = true; |
874 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 904 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
875 } | 905 } |
876 | 906 |
877 } // namespace webkit_glue | 907 } // namespace webkit_glue |
OLD | NEW |