OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/media/webmediaplayer_ms.h" |
| 6 |
| 7 #include <limits> |
| 8 #include <string> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" |
| 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/metrics/histogram.h" |
| 15 #include "base/string_number_conversions.h" |
| 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "media/audio/null_audio_sink.h" |
| 18 #include "media/base/filter_collection.h" |
| 19 #include "media/base/limits.h" |
| 20 #include "media/base/media_log.h" |
| 21 #include "media/base/media_switches.h" |
| 22 #include "media/base/pipeline.h" |
| 23 #include "media/base/video_frame.h" |
| 24 #include "media/filters/audio_renderer_impl.h" |
| 25 #include "media/filters/video_renderer_base.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 32 #include "v8/include/v8.h" |
| 33 #include "webkit/media/buffered_data_source.h" |
| 34 #include "webkit/media/filter_helpers.h" |
| 35 #include "webkit/media/key_systems.h" |
| 36 #include "webkit/media/media_stream_client.h" |
| 37 #include "webkit/media/video_frame_provider.h" |
| 38 #include "webkit/media/webmediaplayer_delegate.h" |
| 39 #include "webkit/media/webmediaplayer_proxy.h" |
| 40 #include "webkit/media/webmediaplayer_util.h" |
| 41 #include "webkit/media/webvideoframe_impl.h" |
| 42 |
| 43 using WebKit::WebCanvas; |
| 44 using WebKit::WebMediaPlayer; |
| 45 using WebKit::WebRect; |
| 46 using WebKit::WebSize; |
| 47 using WebKit::WebString; |
| 48 using media::NetworkEvent; |
| 49 using media::PipelineStatus; |
| 50 |
| 51 namespace { |
| 52 |
| 53 // Helper enum for reporting scheme histograms. |
| 54 enum URLSchemeForHistogram { |
| 55 kUnknownURLScheme, |
| 56 kMissingURLScheme, |
| 57 kHttpURLScheme, |
| 58 kHttpsURLScheme, |
| 59 kFtpURLScheme, |
| 60 kChromeExtensionURLScheme, |
| 61 kJavascriptURLScheme, |
| 62 kFileURLScheme, |
| 63 kBlobURLScheme, |
| 64 kDataURLScheme, |
| 65 kFileSystemScheme, |
| 66 kMaxURLScheme = kFileSystemScheme // Must be equal to highest enum value. |
| 67 }; |
| 68 |
| 69 URLSchemeForHistogram URLScheme(const GURL& url) { |
| 70 if (!url.has_scheme()) return kMissingURLScheme; |
| 71 if (url.SchemeIs("http")) return kHttpURLScheme; |
| 72 if (url.SchemeIs("https")) return kHttpsURLScheme; |
| 73 if (url.SchemeIs("ftp")) return kFtpURLScheme; |
| 74 if (url.SchemeIs("chrome-extension")) return kChromeExtensionURLScheme; |
| 75 if (url.SchemeIs("javascript")) return kJavascriptURLScheme; |
| 76 if (url.SchemeIs("file")) return kFileURLScheme; |
| 77 if (url.SchemeIs("blob")) return kBlobURLScheme; |
| 78 if (url.SchemeIs("data")) return kDataURLScheme; |
| 79 if (url.SchemeIs("filesystem")) return kFileSystemScheme; |
| 80 return kUnknownURLScheme; |
| 81 } |
| 82 |
| 83 // Amount of extra memory used by each player instance reported to V8. |
| 84 // It is not exact number -- first, it differs on different platforms, |
| 85 // and second, it is very hard to calculate. Instead, use some arbitrary |
| 86 // value that will cause garbage collection from time to time. We don't want |
| 87 // it to happen on every allocation, but don't want 5k players to sit in memory |
| 88 // either. Looks that chosen constant achieves both goals, at least for audio |
| 89 // objects. (Do not worry about video objects yet, JS programs do not create |
| 90 // thousands of them...) |
| 91 const int kPlayerExtraMemory = 1024 * 1024; |
| 92 |
| 93 // Limits the range of playback rate. |
| 94 // |
| 95 // TODO(kylep): Revisit these. |
| 96 // |
| 97 // Vista has substantially lower performance than XP or Windows7. If you speed |
| 98 // up a video too much, it can't keep up, and rendering stops updating except on |
| 99 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 100 // use up the data we have, which may not achieve the speed requested, but will |
| 101 // not crash the tab. |
| 102 // |
| 103 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 104 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 105 // |
| 106 // Also our timers are not very accurate (especially for ogg), which becomes |
| 107 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 108 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 109 const float kMinRate = 0.0625f; |
| 110 const float kMaxRate = 16.0f; |
| 111 |
| 112 } // namespace |
| 113 |
| 114 namespace webkit_media { |
| 115 |
| 116 WebMediaPlayerMSProxy::WebMediaPlayerMSProxy() |
| 117 : render_message_loop_(base::MessageLoopProxy::current()) { |
| 118 //LOG(INFO) << "?????WebMediaPlayerMSProxy::WebMediaPlayerMSProxy called, ml = "
<< render_message_loop_.get(); |
| 119 } |
| 120 |
| 121 WebMediaPlayerMSProxy::~WebMediaPlayerMSProxy() {} |
| 122 |
| 123 void WebMediaPlayerMSProxy::WebMediaPlayerMSProxy::Repaint() { |
| 124 if (!render_message_loop_->BelongsToCurrentThread()) { |
| 125 render_message_loop_->PostTask( |
| 126 FROM_HERE, |
| 127 base::Bind(&WebMediaPlayerMSProxy::Repaint, this)); |
| 128 return; |
| 129 } |
| 130 |
| 131 //LOG(INFO) << "?????WebMediaPlayerMSProxy::Repaint called---------"; |
| 132 if (listener_) |
| 133 listener_->Repaint(); |
| 134 } |
| 135 |
| 136 void WebMediaPlayerMSProxy::Paint( |
| 137 SkCanvas* canvas, const gfx::Rect& dest_rect, uint8_t alpha) { |
| 138 } |
| 139 |
| 140 WebMediaPlayerMS::WebMediaPlayerMS( |
| 141 WebKit::WebFrame* frame, |
| 142 WebKit::WebMediaPlayerClient* client, |
| 143 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 144 media::MessageLoopFactory* message_loop_factory, |
| 145 MediaStreamClient* media_stream_client, |
| 146 media::MediaLog* media_log) |
| 147 : frame_(frame), |
| 148 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 149 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 150 main_loop_(MessageLoop::current()), |
| 151 message_loop_factory_(message_loop_factory), |
| 152 client_(client), |
| 153 proxy_(new WebMediaPlayerMSProxy()), |
| 154 delegate_(delegate), |
| 155 media_stream_client_(media_stream_client), |
| 156 frame_provider_paused_(true), |
| 157 media_log_(media_log), |
| 158 accelerated_compositing_reported_(false), |
| 159 incremented_externally_allocated_memory_(false) { |
| 160 DCHECK(media_stream_client); |
| 161 media_log_->AddEvent( |
| 162 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 163 printf("WebMediaPlayerMS::WebMediaPlayerMS, cccccccccreated\n"); |
| 164 |
| 165 // Let V8 know we started new thread if we did not did it yet. |
| 166 // Made separate task to avoid deletion of player currently being created. |
| 167 // Also, delaying GC until after player starts gets rid of starting lag -- |
| 168 // collection happens in parallel with playing. |
| 169 // |
| 170 // TODO(enal): remove when we get rid of per-audio-stream thread. |
| 171 MessageLoop::current()->PostTask( |
| 172 FROM_HERE, |
| 173 base::Bind(&WebMediaPlayerMS::IncrementExternallyAllocatedMemory, |
| 174 AsWeakPtr())); |
| 175 |
| 176 // Also we want to be notified of |main_loop_| destruction. |
| 177 main_loop_->AddDestructionObserver(this); |
| 178 } |
| 179 |
| 180 WebMediaPlayerMS::~WebMediaPlayerMS() { |
| 181 printf("WebMediaPlayerMS::~WebMediaPlayerMS, dddddddddddddeleted\n"); |
| 182 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 183 Destroy(); |
| 184 media_log_->AddEvent( |
| 185 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
| 186 |
| 187 if (delegate_) |
| 188 delegate_->PlayerGone(this); |
| 189 |
| 190 // Finally tell the |main_loop_| we don't want to be notified of destruction |
| 191 // event. |
| 192 if (main_loop_) { |
| 193 main_loop_->RemoveDestructionObserver(this); |
| 194 } |
| 195 } |
| 196 |
| 197 void WebMediaPlayerMS::load(const WebKit::WebURL& url) { |
| 198 //printf("WebMediaPlayerMS::load\n"); |
| 199 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 200 |
| 201 GURL gurl(url); |
| 202 |
| 203 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 204 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 205 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
| 206 |
| 207 // Check if this url is media stream. |
| 208 proxy_->SetListener(this); |
| 209 frame_provider_ = media_stream_client_->GetVideoFrameProvider( |
| 210 url, base::Bind(&WebMediaPlayerMSProxy::Repaint, proxy_)); |
| 211 if (frame_provider_) { |
| 212 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 213 client_->sourceOpened(); |
| 214 client_->setOpaque(true); |
| 215 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 216 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 217 } |
| 218 } |
| 219 |
| 220 void WebMediaPlayerMS::cancelLoad() { |
| 221 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 222 } |
| 223 |
| 224 void WebMediaPlayerMS::play() { |
| 225 //printf("WebMediaPlayerMS::play\n"); |
| 226 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 227 if (frame_provider_) { |
| 228 frame_provider_paused_ = false; |
| 229 frame_provider_->Start(); |
| 230 client_->sizeChanged(); |
| 231 } |
| 232 |
| 233 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); |
| 234 |
| 235 if (delegate_) |
| 236 delegate_->DidPlay(this); |
| 237 } |
| 238 |
| 239 void WebMediaPlayerMS::pause() { |
| 240 //printf("WebMediaPlayerMS::pause\n"); |
| 241 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 242 |
| 243 frame_provider_paused_ = true; |
| 244 |
| 245 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); |
| 246 |
| 247 if (delegate_) |
| 248 delegate_->DidPause(this); |
| 249 } |
| 250 |
| 251 bool WebMediaPlayerMS::supportsFullscreen() const { |
| 252 //printf("WebMediaPlayerMS::supportsFullscreen\n"); |
| 253 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 254 return true; |
| 255 } |
| 256 |
| 257 bool WebMediaPlayerMS::supportsSave() const { |
| 258 //printf("WebMediaPlayerMS::supportsSave\n"); |
| 259 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 260 return true; |
| 261 } |
| 262 |
| 263 void WebMediaPlayerMS::seek(float seconds) { |
| 264 //printf("WebMediaPlayerMS::seek, %f\n", seconds); |
| 265 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 266 } |
| 267 |
| 268 void WebMediaPlayerMS::setEndTime(float seconds) { |
| 269 //printf("WebMediaPlayerMS::setEndTime, %f\n", seconds); |
| 270 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 271 } |
| 272 |
| 273 void WebMediaPlayerMS::setRate(float rate) { |
| 274 //printf("WebMediaPlayerMS::setRate, %f\n", rate); |
| 275 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 276 } |
| 277 |
| 278 void WebMediaPlayerMS::setVolume(float volume) { |
| 279 //printf("WebMediaPlayerMS::setVolume, %f\n", volume); |
| 280 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 281 } |
| 282 |
| 283 void WebMediaPlayerMS::setVisible(bool visible) { |
| 284 //printf("WebMediaPlayerMS::setVisible, %s\n", visible ? "true" : "false"); |
| 285 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 286 } |
| 287 |
| 288 void WebMediaPlayerMS::setPreload(WebMediaPlayer::Preload preload) { |
| 289 //printf("WebMediaPlayerMS::setPreload, preload=%d\n", preload); |
| 290 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 291 } |
| 292 |
| 293 bool WebMediaPlayerMS::totalBytesKnown() { |
| 294 //printf("WebMediaPlayerMS::totalBytesKnown, false\n"); |
| 295 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 296 |
| 297 return false; |
| 298 } |
| 299 |
| 300 bool WebMediaPlayerMS::hasVideo() const { |
| 301 //printf("WebMediaPlayerMS::hasVideo, true\n"); |
| 302 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 303 |
| 304 return true; |
| 305 } |
| 306 |
| 307 bool WebMediaPlayerMS::hasAudio() const { |
| 308 //printf("WebMediaPlayerMS::hasAudio, false\n"); |
| 309 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 310 |
| 311 return false; |
| 312 } |
| 313 |
| 314 WebKit::WebSize WebMediaPlayerMS::naturalSize() const { |
| 315 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 316 gfx::Size size(320, 240); |
| 317 //video_frame_provider_->GetNaturalVideoSize(&size); |
| 318 //printf("WebMediaPlayerMS::naturalSize, (%d, %d)\n", size.width(), size.heigh
t()); |
| 319 return WebKit::WebSize(size); |
| 320 } |
| 321 |
| 322 bool WebMediaPlayerMS::paused() const { |
| 323 //printf("WebMediaPlayerMS::paused, %s\n", frame_provider_paused_ ? "true" : "
false"); |
| 324 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 325 |
| 326 return frame_provider_paused_; |
| 327 } |
| 328 |
| 329 bool WebMediaPlayerMS::seeking() const { |
| 330 //printf("WebMediaPlayerMS::seeking, false\n"); |
| 331 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 332 return false; |
| 333 } |
| 334 |
| 335 float WebMediaPlayerMS::duration() const { |
| 336 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 337 return std::numeric_limits<float>::infinity(); |
| 338 } |
| 339 |
| 340 float WebMediaPlayerMS::currentTime() const { |
| 341 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 342 return static_cast<float>((base::Time::Now() - base::Time()).InSecondsF()); |
| 343 } |
| 344 |
| 345 int WebMediaPlayerMS::dataRate() const { |
| 346 //printf("WebMediaPlayerMS::dataRate\n"); |
| 347 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 348 return 0; |
| 349 } |
| 350 |
| 351 WebMediaPlayer::NetworkState WebMediaPlayerMS::networkState() const { |
| 352 //printf("WebMediaPlayerMS::networkState, %d\n", network_state_); |
| 353 return network_state_; |
| 354 } |
| 355 |
| 356 WebMediaPlayer::ReadyState WebMediaPlayerMS::readyState() const { |
| 357 //printf("WebMediaPlayerMS::readyState, %d\n", ready_state_); |
| 358 return ready_state_; |
| 359 } |
| 360 |
| 361 const WebKit::WebTimeRanges& WebMediaPlayerMS::buffered() { |
| 362 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 363 //printf("WebMediaPlayerMS::buffered, buffered_.size = %d\n", static_cast<int>
(buffered_.size())); |
| 364 return buffered_; |
| 365 } |
| 366 |
| 367 float WebMediaPlayerMS::maxTimeSeekable() const { |
| 368 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 369 return 0.0f; |
| 370 } |
| 371 |
| 372 unsigned long long WebMediaPlayerMS::bytesLoaded() const { |
| 373 //printf("WebMediaPlayerMS::bytesLoaded, 0\n"); |
| 374 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 375 return 0; |
| 376 } |
| 377 |
| 378 unsigned long long WebMediaPlayerMS::totalBytes() const { |
| 379 //printf("WebMediaPlayerMS::totalBytes, %d\n", static_cast<int>(pipeline_->Get
TotalBytes())); |
| 380 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 381 return 0; |
| 382 } |
| 383 |
| 384 void WebMediaPlayerMS::setSize(const WebSize& size) { |
| 385 //printf("WebMediaPlayerMS::setSize\n"); |
| 386 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 387 |
| 388 // Don't need to do anything as we use the dimensions passed in via paint(). |
| 389 } |
| 390 |
| 391 // This variant (without alpha) is just present during staging of this API |
| 392 // change. Later we will again only have one virtual paint(). |
| 393 void WebMediaPlayerMS::paint(WebKit::WebCanvas* canvas, |
| 394 const WebKit::WebRect& rect) { |
| 395 paint(canvas, rect, 0xFF); |
| 396 } |
| 397 |
| 398 void WebMediaPlayerMS::paint(WebCanvas* canvas, |
| 399 const WebRect& rect, |
| 400 uint8_t alpha) { |
| 401 //printf("WebMediaPlayerMS::paint\n"); |
| 402 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 403 DCHECK(proxy_); |
| 404 |
| 405 #if WEBKIT_USING_SKIA |
| 406 proxy_->Paint(canvas, rect, alpha); |
| 407 #elif WEBKIT_USING_CG |
| 408 // Get the current scaling in X and Y. |
| 409 CGAffineTransform mat = CGContextGetCTM(canvas); |
| 410 float scale_x = sqrt(mat.a * mat.a + mat.b * mat.b); |
| 411 float scale_y = sqrt(mat.c * mat.c + mat.d * mat.d); |
| 412 float inverse_scale_x = SkScalarNearlyZero(scale_x) ? 0.0f : 1.0f / scale_x; |
| 413 float inverse_scale_y = SkScalarNearlyZero(scale_y) ? 0.0f : 1.0f / scale_y; |
| 414 int scaled_width = static_cast<int>(rect.width * fabs(scale_x)); |
| 415 int scaled_height = static_cast<int>(rect.height * fabs(scale_y)); |
| 416 |
| 417 // Make sure we don't create a huge canvas. |
| 418 // TODO(hclam): Respect the aspect ratio. |
| 419 if (scaled_width > static_cast<int>(media::limits::kMaxCanvas)) |
| 420 scaled_width = media::limits::kMaxCanvas; |
| 421 if (scaled_height > static_cast<int>(media::limits::kMaxCanvas)) |
| 422 scaled_height = media::limits::kMaxCanvas; |
| 423 |
| 424 // If there is no preexisting platform canvas, or if the size has |
| 425 // changed, recreate the canvas. This is to avoid recreating the bitmap |
| 426 // buffer over and over for each frame of video. |
| 427 if (!skia_canvas_.get() || |
| 428 skia_canvas_->getDevice()->width() != scaled_width || |
| 429 skia_canvas_->getDevice()->height() != scaled_height) { |
| 430 skia_canvas_.reset( |
| 431 new skia::PlatformCanvas(scaled_width, scaled_height, true)); |
| 432 } |
| 433 |
| 434 // Draw to our temporary skia canvas. |
| 435 gfx::Rect normalized_rect(scaled_width, scaled_height); |
| 436 proxy_->Paint(skia_canvas_.get(), normalized_rect); |
| 437 |
| 438 // The mac coordinate system is flipped vertical from the normal skia |
| 439 // coordinates. During painting of the frame, flip the coordinates |
| 440 // system and, for simplicity, also translate the clip rectangle to |
| 441 // start at 0,0. |
| 442 CGContextSaveGState(canvas); |
| 443 CGContextTranslateCTM(canvas, rect.x, rect.height + rect.y); |
| 444 CGContextScaleCTM(canvas, inverse_scale_x, -inverse_scale_y); |
| 445 |
| 446 // We need a local variable CGRect version for DrawToContext. |
| 447 CGRect normalized_cgrect = |
| 448 CGRectMake(normalized_rect.x(), normalized_rect.y(), |
| 449 normalized_rect.width(), normalized_rect.height()); |
| 450 |
| 451 // Copy the frame rendered to our temporary skia canvas onto the passed in |
| 452 // canvas. |
| 453 skia::DrawToNativeContext(skia_canvas_.get(), canvas, 0, 0, |
| 454 &normalized_cgrect); |
| 455 |
| 456 CGContextRestoreGState(canvas); |
| 457 #else |
| 458 NOTIMPLEMENTED() << "We only support rendering to skia or CG"; |
| 459 #endif |
| 460 } |
| 461 |
| 462 bool WebMediaPlayerMS::hasSingleSecurityOrigin() const { |
| 463 //printf("WebMediaPlayerMS::hasSingleSecurityOrigin\n"); |
| 464 return true; |
| 465 } |
| 466 |
| 467 WebMediaPlayer::MovieLoadType WebMediaPlayerMS::movieLoadType() const { |
| 468 //printf("WebMediaPlayerMS::movieLoadType, %d\n", pipeline_->IsStreaming() ? W
ebKit::WebMediaPlayer::LiveStream : WebKit::WebMediaPlayer::Unknown); |
| 469 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 470 return WebMediaPlayer::MovieLoadTypeUnknown; |
| 471 } |
| 472 |
| 473 float WebMediaPlayerMS::mediaTimeForTimeValue(float timeValue) const { |
| 474 //printf("WebMediaPlayerMS::mediaTimeForTimeValue, %f\n", ConvertSecondsToTime
stamp(timeValue).InSecondsF()); |
| 475 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 476 } |
| 477 |
| 478 unsigned WebMediaPlayerMS::decodedFrameCount() const { |
| 479 //printf("WebMediaPlayerMS::decodedFrameCount, %d\n", static_cast<int>(pipelin
e_->GetStatistics().video_frames_decoded)); |
| 480 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 481 NOTIMPLEMENTED(); |
| 482 return 0; |
| 483 } |
| 484 |
| 485 unsigned WebMediaPlayerMS::droppedFrameCount() const { |
| 486 //printf("WebMediaPlayerMS::droppedFrameCount\n"); |
| 487 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 488 NOTIMPLEMENTED(); |
| 489 return 0; |
| 490 } |
| 491 |
| 492 unsigned WebMediaPlayerMS::audioDecodedByteCount() const { |
| 493 //printf("WebMediaPlayerMS::audioDecodedByteCount\n"); |
| 494 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 495 NOTIMPLEMENTED(); |
| 496 return 0; |
| 497 } |
| 498 |
| 499 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { |
| 500 //printf("WebMediaPlayerMS::videoDecodedByteCount\n"); |
| 501 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 502 NOTIMPLEMENTED(); |
| 503 return 0; |
| 504 } |
| 505 |
| 506 WebKit::WebVideoFrame* WebMediaPlayerMS::getCurrentFrame() { |
| 507 ////printf("WebMediaPlayerMS::getCurrentFrame\n"); |
| 508 scoped_refptr<media::VideoFrame> video_frame; |
| 509 frame_provider_->GetCurrentFrame(&video_frame); |
| 510 if (video_frame.get()) |
| 511 return new webkit_media::WebVideoFrameImpl(video_frame); |
| 512 return NULL; |
| 513 } |
| 514 |
| 515 void WebMediaPlayerMS::putCurrentFrame( |
| 516 WebKit::WebVideoFrame* web_video_frame) { |
| 517 //printf("WebMediaPlayerMS::putCurrentFrame\n"); |
| 518 if (!accelerated_compositing_reported_) { |
| 519 accelerated_compositing_reported_ = true; |
| 520 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", |
| 521 frame_->view()->isAcceleratedCompositingActive()); |
| 522 } |
| 523 if (web_video_frame) { |
| 524 scoped_refptr<media::VideoFrame> video_frame( |
| 525 WebVideoFrameImpl::toVideoFrame(web_video_frame)); |
| 526 frame_provider_->PutCurrentFrame(video_frame); |
| 527 delete web_video_frame; |
| 528 } else { |
| 529 frame_provider_->PutCurrentFrame(NULL); |
| 530 } |
| 531 } |
| 532 |
| 533 void WebMediaPlayerMS::WillDestroyCurrentMessageLoop() { |
| 534 //printf("WebMediaPlayerMS::WillDestroyCurrentMessageLoop\n"); |
| 535 Destroy(); |
| 536 main_loop_ = NULL; |
| 537 } |
| 538 |
| 539 void WebMediaPlayerMS::Repaint() { |
| 540 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 541 //printf("WebMediaPlayerMS::Repaint: call client repaint()\n"); |
| 542 GetClient()->repaint(); |
| 543 } |
| 544 |
| 545 void WebMediaPlayerMS::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 546 //printf("WebMediaPlayerMS::SetNetworkState, calling client networkStateChange
d, state=%d\n", state); |
| 547 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 548 DVLOG(1) << "SetNetworkState: " << state; |
| 549 network_state_ = state; |
| 550 // Always notify to ensure client has the latest value. |
| 551 GetClient()->networkStateChanged(); |
| 552 } |
| 553 |
| 554 void WebMediaPlayerMS::SetReadyState(WebMediaPlayer::ReadyState state) { |
| 555 //printf("WebMediaPlayerMS::SetReadyState, calling client readyStateChanged, s
tate=%d\n", state); |
| 556 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 557 DVLOG(1) << "SetReadyState: " << state; |
| 558 ready_state_ = state; |
| 559 // Always notify to ensure client has the latest value. |
| 560 GetClient()->readyStateChanged(); |
| 561 } |
| 562 |
| 563 void WebMediaPlayerMS::Destroy() { |
| 564 printf("WebMediaPlayerMS::Destroy\n"); |
| 565 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 566 |
| 567 // Tell the data source to abort any pending reads so that the pipeline is |
| 568 // not blocked when issuing stop commands to the other filters. |
| 569 if (proxy_) { |
| 570 proxy_->SetListener(NULL); |
| 571 proxy_ = NULL; |
| 572 } |
| 573 |
| 574 if (frame_provider_) { |
| 575 base::WaitableEvent event(false, false); |
| 576 frame_provider_->Stop(base::Bind(&base::WaitableEvent::Signal, |
| 577 base::Unretained(&event))); |
| 578 event.Wait(); |
| 579 } |
| 580 |
| 581 // Let V8 know we are not using extra resources anymore. |
| 582 if (incremented_externally_allocated_memory_) { |
| 583 v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory); |
| 584 incremented_externally_allocated_memory_ = false; |
| 585 } |
| 586 |
| 587 message_loop_factory_.reset(); |
| 588 } |
| 589 |
| 590 WebKit::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { |
| 591 //printf("WebMediaPlayerMS::GetClient\n"); |
| 592 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 593 DCHECK(client_); |
| 594 return client_; |
| 595 } |
| 596 |
| 597 void WebMediaPlayerMS::IncrementExternallyAllocatedMemory() { |
| 598 printf("WebMediaPlayerMS::IncrementExternallyAllocatedMemory\n"); |
| 599 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 600 incremented_externally_allocated_memory_ = true; |
| 601 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 602 } |
| 603 |
| 604 } // namespace webkit_media |
OLD | NEW |