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
3 // found in the LICENSE file.
5 #include "content/renderer/media/webmediaplayer_impl.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/callback_helpers.h"
15 #include "base/command_line.h"
16 #include "base/debug/alias.h"
17 #include "base/debug/crash_logging.h"
18 #include "base/debug/trace_event.h"
19 #include "base/message_loop/message_loop_proxy.h"
20 #include "base/metrics/histogram.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/waitable_event.h"
24 #include "cc/layers/video_layer.h"
25 #include "content/public/common/content_switches.h"
26 #include "content/public/renderer/render_frame.h"
27 #include "content/renderer/media/buffered_data_source.h"
28 #include "content/renderer/media/crypto/key_systems.h"
29 #include "content/renderer/media/render_media_log.h"
30 #include "content/renderer/media/texttrack_impl.h"
31 #include "content/renderer/media/webaudiosourceprovider_impl.h"
32 #include "content/renderer/media/webcontentdecryptionmodule_impl.h"
33 #include "content/renderer/media/webinbandtexttrack_impl.h"
34 #include "content/renderer/media/webmediaplayer_delegate.h"
35 #include "content/renderer/media/webmediaplayer_params.h"
36 #include "content/renderer/media/webmediaplayer_util.h"
37 #include "content/renderer/media/webmediasource_impl.h"
38 #include "content/renderer/pepper/pepper_webplugin_impl.h"
39 #include "content/renderer/render_thread_impl.h"
40 #include "gpu/GLES2/gl2extchromium.h"
41 #include "gpu/command_buffer/common/mailbox_holder.h"
42 #include "media/audio/null_audio_sink.h"
43 #include "media/base/audio_hardware_config.h"
44 #include "media/base/bind_to_current_loop.h"
45 #include "media/base/filter_collection.h"
46 #include "media/base/limits.h"
47 #include "media/base/media_log.h"
48 #include "media/base/media_switches.h"
49 #include "media/base/pipeline.h"
50 #include "media/base/text_renderer.h"
51 #include "media/base/video_frame.h"
52 #include "media/filters/audio_renderer_impl.h"
53 #include "media/filters/chunk_demuxer.h"
54 #include "media/filters/ffmpeg_audio_decoder.h"
55 #include "media/filters/ffmpeg_demuxer.h"
56 #include "media/filters/ffmpeg_video_decoder.h"
57 #include "media/filters/gpu_video_accelerator_factories.h"
58 #include "media/filters/gpu_video_decoder.h"
59 #include "media/filters/opus_audio_decoder.h"
60 #include "media/filters/video_renderer_impl.h"
61 #include "media/filters/vpx_video_decoder.h"
62 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h"
63 #include "third_party/WebKit/public/platform/WebMediaSource.h"
64 #include "third_party/WebKit/public/platform/WebRect.h"
65 #include "third_party/WebKit/public/platform/WebSize.h"
66 #include "third_party/WebKit/public/platform/WebString.h"
67 #include "third_party/WebKit/public/platform/WebURL.h"
68 #include "third_party/WebKit/public/web/WebDocument.h"
69 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
70 #include "third_party/WebKit/public/web/WebView.h"
71 #include "v8/include/v8.h"
72 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
74 #if defined(ENABLE_PEPPER_CDMS)
75 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
78 using blink::WebCanvas;
79 using blink::WebMediaPlayer;
82 using blink::WebString;
83 using media::PipelineStatus;
87 // Amount of extra memory used by each player instance reported to V8.
88 // It is not exact number -- first, it differs on different platforms,
89 // and second, it is very hard to calculate. Instead, use some arbitrary
90 // value that will cause garbage collection from time to time. We don't want
91 // it to happen on every allocation, but don't want 5k players to sit in memory
92 // either. Looks that chosen constant achieves both goals, at least for audio
93 // objects. (Do not worry about video objects yet, JS programs do not create
94 // thousands of them...)
95 const int kPlayerExtraMemory = 1024 * 1024;
97 // Limits the range of playback rate.
99 // TODO(kylep): Revisit these.
101 // Vista has substantially lower performance than XP or Windows7. If you speed
102 // up a video too much, it can't keep up, and rendering stops updating except on
103 // the time bar. For really high speeds, audio becomes a bottleneck and we just
104 // use up the data we have, which may not achieve the speed requested, but will
105 // not crash the tab.
107 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems
108 // like a busy loop). It gets unresponsive, although its not completely dead.
110 // Also our timers are not very accurate (especially for ogg), which becomes
111 // evident at low speeds and on Vista. Since other speeds are risky and outside
112 // the norms, we think 1/16x to 16x is a safe and useful range for now.
113 const double kMinRate = 0.0625;
114 const double kMaxRate = 16.0;
116 // Prefix for histograms related to Encrypted Media Extensions.
117 const char* kMediaEme = "Media.EME.";
123 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
124 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \
125 static_cast<int>(BufferedResourceLoader::k ## name), \
127 COMPILE_ASSERT_MATCHING_ENUM(Unspecified);
128 COMPILE_ASSERT_MATCHING_ENUM(Anonymous);
129 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials);
130 #undef COMPILE_ASSERT_MATCHING_ENUM
132 #define BIND_TO_RENDER_LOOP(function) \
133 (DCHECK(main_loop_->BelongsToCurrentThread()), \
134 media::BindToCurrentLoop(base::Bind(function, AsWeakPtr())))
136 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log,
137 const std::string& error) {
138 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error));
141 WebMediaPlayerImpl::WebMediaPlayerImpl(
142 blink::WebFrame* frame,
143 blink::WebMediaPlayerClient* client,
144 base::WeakPtr<WebMediaPlayerDelegate> delegate,
145 const WebMediaPlayerParams& params)
147 network_state_(WebMediaPlayer::NetworkStateEmpty),
148 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
149 main_loop_(base::MessageLoopProxy::current()),
151 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()),
152 media_log_(new RenderMediaLog()),
153 pipeline_(media_loop_, media_log_.get()),
156 playback_rate_(0.0f),
157 pending_seek_(false),
158 pending_seek_seconds_(0.0f),
161 defer_load_cb_(params.defer_load_cb()),
162 accelerated_compositing_reported_(false),
163 incremented_externally_allocated_memory_(false),
164 gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()),
165 is_local_source_(false),
166 supports_save_(true),
168 chunk_demuxer_(NULL),
169 compositor_( // Threaded compositing isn't enabled universally yet.
170 (RenderThreadImpl::current()->compositor_message_loop_proxy()
171 ? RenderThreadImpl::current()->compositor_message_loop_proxy()
172 : base::MessageLoopProxy::current()),
173 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChange)),
174 text_track_index_(0),
176 media_log_->AddEvent(
177 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
179 // |gpu_factories_| requires that its entry points be called on its
180 // |GetTaskRunner()|. Since |pipeline_| will own decoders created from the
181 // factories, require that their message loops are identical.
182 DCHECK(!gpu_factories_ || (gpu_factories_->GetTaskRunner() == media_loop_));
184 // Let V8 know we started new thread if we did not do it yet.
185 // Made separate task to avoid deletion of player currently being created.
186 // Also, delaying GC until after player starts gets rid of starting lag --
187 // collection happens in parallel with playing.
189 // TODO(enal): remove when we get rid of per-audio-stream thread.
190 main_loop_->PostTask(
192 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory,
195 // Use the null sink if no sink was provided.
196 audio_source_provider_ = new WebAudioSourceProviderImpl(
197 params.audio_renderer_sink().get()
198 ? params.audio_renderer_sink()
199 : new media::NullAudioSink(media_loop_));
202 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
203 client_->setWebLayer(NULL);
205 DCHECK(main_loop_->BelongsToCurrentThread());
206 media_log_->AddEvent(
207 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
210 delegate_->PlayerGone(this);
212 // Abort any pending IO so stopping the pipeline doesn't get blocked.
214 data_source_->Abort();
215 if (chunk_demuxer_) {
216 chunk_demuxer_->Shutdown();
217 chunk_demuxer_ = NULL;
220 gpu_factories_ = NULL;
222 // Make sure to kill the pipeline so there's no more media threads running.
223 // Note: stopping the pipeline might block for a long time.
224 base::WaitableEvent waiter(false, false);
226 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter)));
229 // Let V8 know we are not using extra resources anymore.
230 if (incremented_externally_allocated_memory_) {
231 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
232 -kPlayerExtraMemory);
233 incremented_externally_allocated_memory_ = false;
239 // Helper enum for reporting scheme histograms.
240 enum URLSchemeForHistogram {
246 kChromeExtensionURLScheme,
247 kJavascriptURLScheme,
252 kMaxURLScheme = kFileSystemScheme // Must be equal to highest enum value.
255 URLSchemeForHistogram URLScheme(const GURL& url) {
256 if (!url.has_scheme()) return kMissingURLScheme;
257 if (url.SchemeIs("http")) return kHttpURLScheme;
258 if (url.SchemeIs("https")) return kHttpsURLScheme;
259 if (url.SchemeIs("ftp")) return kFtpURLScheme;
260 if (url.SchemeIs("chrome-extension")) return kChromeExtensionURLScheme;
261 if (url.SchemeIs("javascript")) return kJavascriptURLScheme;
262 if (url.SchemeIs("file")) return kFileURLScheme;
263 if (url.SchemeIs("blob")) return kBlobURLScheme;
264 if (url.SchemeIs("data")) return kDataURLScheme;
265 if (url.SchemeIs("filesystem")) return kFileSystemScheme;
266 return kUnknownURLScheme;
271 void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url,
272 CORSMode cors_mode) {
273 if (!defer_load_cb_.is_null()) {
274 defer_load_cb_.Run(base::Bind(
275 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode));
278 DoLoad(load_type, url, cors_mode);
281 void WebMediaPlayerImpl::DoLoad(LoadType load_type,
282 const blink::WebURL& url,
283 CORSMode cors_mode) {
284 DCHECK(main_loop_->BelongsToCurrentThread());
287 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme);
289 // Set subresource URL for crash reporting.
290 base::debug::SetCrashKeyValue("subresource_url", gurl.spec());
292 load_type_ = load_type;
294 // Handle any volume/preload changes that occurred before load().
295 setVolume(client_->volume());
296 setPreload(client_->preload());
298 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
299 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing);
300 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
302 // Media source pipelines can start immediately.
303 if (load_type == LoadTypeMediaSource) {
304 supports_save_ = false;
309 // Otherwise it's a regular request which requires resolving the URL first.
310 data_source_.reset(new BufferedDataSource(
314 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
315 data_source_->Initialize(
316 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
318 &WebMediaPlayerImpl::DataSourceInitialized,
321 is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS();
324 void WebMediaPlayerImpl::play() {
325 DCHECK(main_loop_->BelongsToCurrentThread());
328 pipeline_.SetPlaybackRate(playback_rate_);
330 data_source_->MediaIsPlaying();
332 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY));
335 delegate_->DidPlay(this);
338 void WebMediaPlayerImpl::pause() {
339 DCHECK(main_loop_->BelongsToCurrentThread());
342 pipeline_.SetPlaybackRate(0.0f);
344 data_source_->MediaIsPaused();
345 paused_time_ = pipeline_.GetMediaTime();
347 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE));
350 delegate_->DidPause(this);
353 bool WebMediaPlayerImpl::supportsSave() const {
354 DCHECK(main_loop_->BelongsToCurrentThread());
355 return supports_save_;
358 void WebMediaPlayerImpl::seek(double seconds) {
359 DCHECK(main_loop_->BelongsToCurrentThread());
361 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata)
362 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
364 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
366 if (starting_ || seeking_) {
367 pending_seek_ = true;
368 pending_seek_seconds_ = seconds;
370 chunk_demuxer_->CancelPendingSeek(seek_time);
374 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
376 // Update our paused time.
378 paused_time_ = seek_time;
383 chunk_demuxer_->StartWaitingForSeek(seek_time);
385 // Kick off the asynchronous seek!
388 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek));
391 void WebMediaPlayerImpl::setRate(double rate) {
392 DCHECK(main_loop_->BelongsToCurrentThread());
394 // TODO(kylep): Remove when support for negatives is added. Also, modify the
395 // following checks so rewind uses reasonable values also.
399 // Limit rates to reasonable values by clamping.
403 else if (rate > kMaxRate)
407 playback_rate_ = rate;
409 pipeline_.SetPlaybackRate(rate);
411 data_source_->MediaPlaybackRateChanged(rate);
415 void WebMediaPlayerImpl::setVolume(double volume) {
416 DCHECK(main_loop_->BelongsToCurrentThread());
418 pipeline_.SetVolume(volume);
421 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
422 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \
423 static_cast<int>(content::chromium_name), \
425 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE);
426 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA);
427 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO);
428 #undef COMPILE_ASSERT_MATCHING_ENUM
430 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) {
431 DCHECK(main_loop_->BelongsToCurrentThread());
434 data_source_->SetPreload(static_cast<content::Preload>(preload));
437 bool WebMediaPlayerImpl::hasVideo() const {
438 DCHECK(main_loop_->BelongsToCurrentThread());
440 return pipeline_metadata_.has_video;
443 bool WebMediaPlayerImpl::hasAudio() const {
444 DCHECK(main_loop_->BelongsToCurrentThread());
446 return pipeline_metadata_.has_audio;
449 blink::WebSize WebMediaPlayerImpl::naturalSize() const {
450 DCHECK(main_loop_->BelongsToCurrentThread());
452 return blink::WebSize(pipeline_metadata_.natural_size);
455 bool WebMediaPlayerImpl::paused() const {
456 DCHECK(main_loop_->BelongsToCurrentThread());
458 return pipeline_.GetPlaybackRate() == 0.0f;
461 bool WebMediaPlayerImpl::seeking() const {
462 DCHECK(main_loop_->BelongsToCurrentThread());
464 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
470 double WebMediaPlayerImpl::duration() const {
471 DCHECK(main_loop_->BelongsToCurrentThread());
473 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
474 return std::numeric_limits<double>::quiet_NaN();
476 return GetPipelineDuration();
479 double WebMediaPlayerImpl::currentTime() const {
480 DCHECK(main_loop_->BelongsToCurrentThread());
481 return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF();
484 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const {
485 DCHECK(main_loop_->BelongsToCurrentThread());
486 return network_state_;
489 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const {
490 DCHECK(main_loop_->BelongsToCurrentThread());
494 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() {
495 DCHECK(main_loop_->BelongsToCurrentThread());
496 blink::WebTimeRanges web_ranges(
497 ConvertToWebTimeRanges(pipeline_.GetBufferedTimeRanges()));
498 buffered_.swap(web_ranges);
502 double WebMediaPlayerImpl::maxTimeSeekable() const {
503 DCHECK(main_loop_->BelongsToCurrentThread());
505 // If we haven't even gotten to ReadyStateHaveMetadata yet then just
506 // return 0 so that the seekable range is empty.
507 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
510 // We don't support seeking in streaming media.
511 if (data_source_ && data_source_->IsStreaming())
516 bool WebMediaPlayerImpl::didLoadingProgress() const {
517 DCHECK(main_loop_->BelongsToCurrentThread());
519 return pipeline_.DidLoadingProgress();
522 void WebMediaPlayerImpl::paint(WebCanvas* canvas,
524 unsigned char alpha) {
525 DCHECK(main_loop_->BelongsToCurrentThread());
527 if (!accelerated_compositing_reported_) {
528 accelerated_compositing_reported_ = true;
529 // Normally paint() is only called in non-accelerated rendering, but there
530 // are exceptions such as webgl where compositing is used in the WebView but
531 // video frames are still rendered to a canvas.
532 UMA_HISTOGRAM_BOOLEAN(
533 "Media.AcceleratedCompositingActive",
534 frame_->view()->isAcceleratedCompositingActive());
537 // TODO(scherkus): Clarify paint() API contract to better understand when and
538 // why it's being called. For example, today paint() is called when:
539 // - We haven't reached HAVE_CURRENT_DATA and need to paint black
540 // - We're painting to a canvas
541 // See http://crbug.com/341225 http://crbug.com/342621 for details.
542 scoped_refptr<media::VideoFrame> video_frame = compositor_.GetCurrentFrame();
544 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint");
545 gfx::Rect gfx_rect(rect);
546 skcanvas_video_renderer_.Paint(video_frame.get(), canvas, gfx_rect, alpha);
549 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const {
551 return data_source_->HasSingleOrigin();
555 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const {
557 return data_source_->DidPassCORSAccessCheck();
561 double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const {
562 return ConvertSecondsToTimestamp(timeValue).InSecondsF();
565 unsigned WebMediaPlayerImpl::decodedFrameCount() const {
566 DCHECK(main_loop_->BelongsToCurrentThread());
568 media::PipelineStatistics stats = pipeline_.GetStatistics();
569 return stats.video_frames_decoded;
572 unsigned WebMediaPlayerImpl::droppedFrameCount() const {
573 DCHECK(main_loop_->BelongsToCurrentThread());
575 media::PipelineStatistics stats = pipeline_.GetStatistics();
577 unsigned frames_dropped = stats.video_frames_dropped;
579 frames_dropped += const_cast<VideoFrameCompositor&>(compositor_)
580 .GetFramesDroppedBeforeCompositorWasNotified();
582 DCHECK_LE(frames_dropped, stats.video_frames_decoded);
583 return frames_dropped;
586 unsigned WebMediaPlayerImpl::audioDecodedByteCount() const {
587 DCHECK(main_loop_->BelongsToCurrentThread());
589 media::PipelineStatistics stats = pipeline_.GetStatistics();
590 return stats.audio_bytes_decoded;
593 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const {
594 DCHECK(main_loop_->BelongsToCurrentThread());
596 media::PipelineStatistics stats = pipeline_.GetStatistics();
597 return stats.video_bytes_decoded;
600 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture(
601 blink::WebGraphicsContext3D* web_graphics_context,
602 unsigned int texture,
604 unsigned int internal_format,
606 bool premultiply_alpha,
608 scoped_refptr<media::VideoFrame> video_frame = compositor_.GetCurrentFrame();
610 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture");
614 if (video_frame->format() != media::VideoFrame::NATIVE_TEXTURE)
617 gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder();
618 if (mailbox_holder->texture_target != GL_TEXTURE_2D)
621 // Since this method changes which texture is bound to the TEXTURE_2D target,
622 // ideally it would restore the currently-bound texture before returning.
623 // The cost of getIntegerv is sufficiently high, however, that we want to
624 // avoid it in user builds. As a result assume (below) that |texture| is
625 // bound when this method is called, and only verify this fact when
628 GLint bound_texture = 0;
629 web_graphics_context->getIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
630 DCHECK_EQ(static_cast<GLuint>(bound_texture), texture);
633 uint32 source_texture = web_graphics_context->createTexture();
635 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point);
636 web_graphics_context->bindTexture(GL_TEXTURE_2D, source_texture);
637 web_graphics_context->consumeTextureCHROMIUM(GL_TEXTURE_2D,
638 mailbox_holder->mailbox.name);
640 // The video is stored in a unmultiplied format, so premultiply
642 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
644 // Application itself needs to take care of setting the right flip_y
645 // value down to get the expected result.
646 // flip_y==true means to reverse the video orientation while
647 // flip_y==false means to keep the intrinsic orientation.
648 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
649 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D,
655 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
656 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
659 // Restore the state for TEXTURE_2D binding point as mentioned above.
660 web_graphics_context->bindTexture(GL_TEXTURE_2D, texture);
662 web_graphics_context->deleteTexture(source_texture);
663 web_graphics_context->flush();
667 // Helper functions to report media EME related stats to UMA. They follow the
668 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and
669 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is
670 // that UMA_* macros require the names to be constant throughout the process'
672 static void EmeUMAHistogramEnumeration(const std::string& key_system,
673 const std::string& method,
675 int boundary_value) {
676 base::LinearHistogram::FactoryGet(
677 kMediaEme + KeySystemNameForUMA(key_system) + "." + method,
678 1, boundary_value, boundary_value + 1,
679 base::Histogram::kUmaTargetedHistogramFlag)->Add(sample);
682 static void EmeUMAHistogramCounts(const std::string& key_system,
683 const std::string& method,
685 // Use the same parameters as UMA_HISTOGRAM_COUNTS.
686 base::Histogram::FactoryGet(
687 kMediaEme + KeySystemNameForUMA(key_system) + "." + method,
688 1, 1000000, 50, base::Histogram::kUmaTargetedHistogramFlag)->Add(sample);
691 // Helper enum for reporting generateKeyRequest/addKey histograms.
692 enum MediaKeyException {
695 kKeySystemNotSupported,
697 kMaxMediaKeyException
700 static MediaKeyException MediaKeyExceptionForUMA(
701 WebMediaPlayer::MediaKeyException e) {
703 case WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported:
704 return kKeySystemNotSupported;
705 case WebMediaPlayer::MediaKeyExceptionInvalidPlayerState:
706 return kInvalidPlayerState;
707 case WebMediaPlayer::MediaKeyExceptionNoError:
710 return kUnknownResultId;
714 // Helper for converting |key_system| name and exception |e| to a pair of enum
715 // values from above, for reporting to UMA.
716 static void ReportMediaKeyExceptionToUMA(const std::string& method,
717 const std::string& key_system,
718 WebMediaPlayer::MediaKeyException e) {
719 MediaKeyException result_id = MediaKeyExceptionForUMA(e);
720 DCHECK_NE(result_id, kUnknownResultId) << e;
721 EmeUMAHistogramEnumeration(
722 key_system, method, result_id, kMaxMediaKeyException);
725 // Convert a WebString to ASCII, falling back on an empty string in the case
726 // of a non-ASCII string.
727 static std::string ToASCIIOrEmpty(const blink::WebString& string) {
728 return IsStringASCII(string) ? base::UTF16ToASCII(string) : std::string();
731 WebMediaPlayer::MediaKeyException
732 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system,
733 const unsigned char* init_data,
734 unsigned init_data_length) {
735 DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": "
736 << std::string(reinterpret_cast<const char*>(init_data),
737 static_cast<size_t>(init_data_length));
739 std::string ascii_key_system =
740 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system));
742 WebMediaPlayer::MediaKeyException e =
743 GenerateKeyRequestInternal(ascii_key_system, init_data, init_data_length);
744 ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e);
748 // Guess the type of |init_data|. This is only used to handle some corner cases
749 // so we keep it as simple as possible without breaking major use cases.
750 static std::string GuessInitDataType(const unsigned char* init_data,
751 unsigned init_data_length) {
752 // Most WebM files use KeyId of 16 bytes. MP4 init data are always >16 bytes.
753 if (init_data_length == 16)
759 WebMediaPlayer::MediaKeyException
760 WebMediaPlayerImpl::GenerateKeyRequestInternal(const std::string& key_system,
761 const unsigned char* init_data,
762 unsigned init_data_length) {
763 DCHECK(main_loop_->BelongsToCurrentThread());
765 if (!IsConcreteSupportedKeySystem(key_system))
766 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
768 // We do not support run-time switching between key systems for now.
769 if (current_key_system_.empty()) {
770 if (!proxy_decryptor_) {
771 proxy_decryptor_.reset(new ProxyDecryptor(
772 #if defined(ENABLE_PEPPER_CDMS)
773 // Create() must be called synchronously as |frame_| may not be
775 base::Bind(&PepperCdmWrapperImpl::Create, frame_),
777 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded),
778 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError),
779 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage)));
782 if (!proxy_decryptor_->InitializeCDM(key_system, frame_->document().url()))
783 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
785 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) {
786 base::ResetAndReturn(&decryptor_ready_cb_)
787 .Run(proxy_decryptor_->GetDecryptor());
790 current_key_system_ = key_system;
791 } else if (key_system != current_key_system_) {
792 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
795 std::string init_data_type = init_data_type_;
796 if (init_data_type.empty())
797 init_data_type = GuessInitDataType(init_data, init_data_length);
799 // TODO(xhwang): We assume all streams are from the same container (thus have
800 // the same "type") for now. In the future, the "type" should be passed down
801 // from the application.
802 if (!proxy_decryptor_->GenerateKeyRequest(
803 init_data_type, init_data, init_data_length)) {
804 current_key_system_.clear();
805 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
808 return WebMediaPlayer::MediaKeyExceptionNoError;
811 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
812 const WebString& key_system,
813 const unsigned char* key,
815 const unsigned char* init_data,
816 unsigned init_data_length,
817 const WebString& session_id) {
818 DVLOG(1) << "addKey: " << base::string16(key_system) << ": "
819 << std::string(reinterpret_cast<const char*>(key),
820 static_cast<size_t>(key_length)) << ", "
821 << std::string(reinterpret_cast<const char*>(init_data),
822 static_cast<size_t>(init_data_length)) << " ["
823 << base::string16(session_id) << "]";
825 std::string ascii_key_system =
826 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system));
827 std::string ascii_session_id = ToASCIIOrEmpty(session_id);
829 WebMediaPlayer::MediaKeyException e = AddKeyInternal(ascii_key_system,
835 ReportMediaKeyExceptionToUMA("addKey", ascii_key_system, e);
839 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal(
840 const std::string& key_system,
841 const unsigned char* key,
843 const unsigned char* init_data,
844 unsigned init_data_length,
845 const std::string& session_id) {
847 DCHECK_GT(key_length, 0u);
849 if (!IsConcreteSupportedKeySystem(key_system))
850 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
852 if (current_key_system_.empty() || key_system != current_key_system_)
853 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
855 proxy_decryptor_->AddKey(
856 key, key_length, init_data, init_data_length, session_id);
857 return WebMediaPlayer::MediaKeyExceptionNoError;
860 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
861 const WebString& key_system,
862 const WebString& session_id) {
863 DVLOG(1) << "cancelKeyRequest: " << base::string16(key_system) << ": "
864 << " [" << base::string16(session_id) << "]";
866 std::string ascii_key_system =
867 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system));
868 std::string ascii_session_id = ToASCIIOrEmpty(session_id);
870 WebMediaPlayer::MediaKeyException e =
871 CancelKeyRequestInternal(ascii_key_system, ascii_session_id);
872 ReportMediaKeyExceptionToUMA("cancelKeyRequest", ascii_key_system, e);
876 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::CancelKeyRequestInternal(
877 const std::string& key_system,
878 const std::string& session_id) {
879 if (!IsConcreteSupportedKeySystem(key_system))
880 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
882 if (current_key_system_.empty() || key_system != current_key_system_)
883 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
885 proxy_decryptor_->CancelKeyRequest(session_id);
886 return WebMediaPlayer::MediaKeyExceptionNoError;
889 void WebMediaPlayerImpl::setContentDecryptionModule(
890 blink::WebContentDecryptionModule* cdm) {
891 DCHECK(main_loop_->BelongsToCurrentThread());
893 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
897 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm);
899 if (web_cdm_ && !decryptor_ready_cb_.is_null())
900 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor());
903 void WebMediaPlayerImpl::InvalidateOnMainThread() {
904 DCHECK(main_loop_->BelongsToCurrentThread());
905 TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread");
910 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
911 DCHECK(main_loop_->BelongsToCurrentThread());
915 pending_seek_ = false;
916 seek(pending_seek_seconds_);
920 if (status != media::PIPELINE_OK) {
921 OnPipelineError(status);
925 // Update our paused time.
927 paused_time_ = pipeline_.GetMediaTime();
929 client_->timeChanged();
932 void WebMediaPlayerImpl::OnPipelineEnded() {
933 DCHECK(main_loop_->BelongsToCurrentThread());
934 client_->timeChanged();
937 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
938 DCHECK(main_loop_->BelongsToCurrentThread());
939 DCHECK_NE(error, media::PIPELINE_OK);
941 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) {
942 // Any error that occurs before reaching ReadyStateHaveMetadata should
943 // be considered a format error.
944 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
946 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
947 // should know when to invalidate themselves http://crbug.com/337015
948 InvalidateOnMainThread();
952 SetNetworkState(PipelineErrorToNetworkState(error));
954 if (error == media::PIPELINE_ERROR_DECRYPT)
955 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1);
957 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
958 // should know when to invalidate themselves http://crbug.com/337015
959 InvalidateOnMainThread();
962 void WebMediaPlayerImpl::OnPipelineMetadata(
963 media::PipelineMetadata metadata) {
964 DVLOG(1) << "OnPipelineMetadata";
966 pipeline_metadata_ = metadata;
968 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
971 DCHECK(!video_weblayer_);
972 video_weblayer_.reset(new webkit::WebLayerImpl(
973 cc::VideoLayer::Create(compositor_.GetVideoFrameProvider())));
974 client_->setWebLayer(video_weblayer_.get());
977 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
978 // should know when to invalidate themselves http://crbug.com/337015
979 InvalidateOnMainThread();
982 void WebMediaPlayerImpl::OnPipelinePrerollCompleted() {
983 DVLOG(1) << "OnPipelinePrerollCompleted";
985 // Only transition to ReadyStateHaveEnoughData if we don't have
986 // any pending seeks because the transition can cause Blink to
987 // report that the most recent seek has completed.
988 if (!pending_seek_) {
989 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
991 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
992 // should know when to invalidate themselves http://crbug.com/337015
993 InvalidateOnMainThread();
997 void WebMediaPlayerImpl::OnDemuxerOpened() {
998 DCHECK(main_loop_->BelongsToCurrentThread());
999 client_->mediaSourceOpened(new WebMediaSourceImpl(
1000 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_)));
1003 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) {
1004 DCHECK(main_loop_->BelongsToCurrentThread());
1005 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1);
1007 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)),
1008 WebString::fromUTF8(session_id));
1011 void WebMediaPlayerImpl::OnNeedKey(const std::string& type,
1012 const std::vector<uint8>& init_data) {
1013 DCHECK(main_loop_->BelongsToCurrentThread());
1015 // Do not fire NeedKey event if encrypted media is not enabled.
1016 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() &&
1017 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) {
1021 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1);
1023 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_);
1024 if (init_data_type_.empty())
1025 init_data_type_ = type;
1027 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0];
1029 WebString::fromUTF8(type), init_data_ptr, init_data.size());
1032 void WebMediaPlayerImpl::OnAddTextTrack(
1033 const media::TextTrackConfig& config,
1034 const media::AddTextTrackDoneCB& done_cb) {
1035 DCHECK(main_loop_->BelongsToCurrentThread());
1037 const WebInbandTextTrackImpl::Kind web_kind =
1038 static_cast<WebInbandTextTrackImpl::Kind>(config.kind());
1039 const blink::WebString web_label =
1040 blink::WebString::fromUTF8(config.label());
1041 const blink::WebString web_language =
1042 blink::WebString::fromUTF8(config.language());
1043 const blink::WebString web_id =
1044 blink::WebString::fromUTF8(config.id());
1046 scoped_ptr<WebInbandTextTrackImpl> web_inband_text_track(
1047 new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id,
1048 text_track_index_++));
1050 scoped_ptr<media::TextTrack> text_track(
1051 new TextTrackImpl(main_loop_, client_, web_inband_text_track.Pass()));
1053 done_cb.Run(text_track.Pass());
1056 void WebMediaPlayerImpl::OnKeyError(const std::string& session_id,
1057 media::MediaKeys::KeyError error_code,
1058 uint32 system_code) {
1059 DCHECK(main_loop_->BelongsToCurrentThread());
1061 EmeUMAHistogramEnumeration(current_key_system_, "KeyError",
1062 error_code, media::MediaKeys::kMaxKeyError);
1064 unsigned short short_system_code = 0;
1065 if (system_code > std::numeric_limits<unsigned short>::max()) {
1066 LOG(WARNING) << "system_code exceeds unsigned short limit.";
1067 short_system_code = std::numeric_limits<unsigned short>::max();
1069 short_system_code = static_cast<unsigned short>(system_code);
1073 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)),
1074 WebString::fromUTF8(session_id),
1075 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
1079 void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id,
1080 const std::vector<uint8>& message,
1081 const std::string& default_url) {
1082 DCHECK(main_loop_->BelongsToCurrentThread());
1084 const GURL default_url_gurl(default_url);
1085 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
1086 << "Invalid URL in default_url: " << default_url;
1088 client_->keyMessage(
1089 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)),
1090 WebString::fromUTF8(session_id),
1091 message.empty() ? NULL : &message[0],
1096 void WebMediaPlayerImpl::SetOpaque(bool opaque) {
1097 DCHECK(main_loop_->BelongsToCurrentThread());
1099 client_->setOpaque(opaque);
1102 void WebMediaPlayerImpl::DataSourceInitialized(const GURL& gurl, bool success) {
1103 DCHECK(main_loop_->BelongsToCurrentThread());
1106 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
1108 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
1109 // should know when to invalidate themselves http://crbug.com/337015
1110 InvalidateOnMainThread();
1117 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) {
1118 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading)
1119 SetNetworkState(WebMediaPlayer::NetworkStateIdle);
1120 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle)
1121 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
1122 media_log_->AddEvent(
1123 media_log_->CreateBooleanEvent(
1124 media::MediaLogEvent::NETWORK_ACTIVITY_SET,
1125 "is_downloading_data", is_downloading));
1128 void WebMediaPlayerImpl::StartPipeline() {
1129 DCHECK(main_loop_->BelongsToCurrentThread());
1130 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1132 // Keep track if this is a MSE or non-MSE playback.
1133 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback",
1134 (load_type_ == LoadTypeMediaSource));
1136 // Figure out which demuxer to use.
1137 if (load_type_ != LoadTypeMediaSource) {
1138 DCHECK(!chunk_demuxer_);
1139 DCHECK(data_source_);
1141 demuxer_.reset(new media::FFmpegDemuxer(
1142 media_loop_, data_source_.get(),
1143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey),
1146 DCHECK(!chunk_demuxer_);
1147 DCHECK(!data_source_);
1149 chunk_demuxer_ = new media::ChunkDemuxer(
1150 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened),
1151 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey),
1152 base::Bind(&LogMediaSourceError, media_log_),
1154 demuxer_.reset(chunk_demuxer_);
1157 scoped_ptr<media::FilterCollection> filter_collection(
1158 new media::FilterCollection());
1159 filter_collection->SetDemuxer(demuxer_.get());
1161 media::SetDecryptorReadyCB set_decryptor_ready_cb =
1162 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetDecryptorReadyCB);
1164 // Create our audio decoders and renderer.
1165 ScopedVector<media::AudioDecoder> audio_decoders;
1166 audio_decoders.push_back(new media::FFmpegAudioDecoder(media_loop_));
1167 audio_decoders.push_back(new media::OpusAudioDecoder(media_loop_));
1169 scoped_ptr<media::AudioRenderer> audio_renderer(new media::AudioRendererImpl(
1171 audio_source_provider_.get(),
1172 audio_decoders.Pass(),
1173 set_decryptor_ready_cb,
1174 RenderThreadImpl::current()->GetAudioHardwareConfig()));
1175 filter_collection->SetAudioRenderer(audio_renderer.Pass());
1177 // Create our video decoders and renderer.
1178 ScopedVector<media::VideoDecoder> video_decoders;
1180 if (gpu_factories_.get()) {
1181 video_decoders.push_back(
1182 new media::GpuVideoDecoder(gpu_factories_, media_log_));
1185 #if !defined(MEDIA_DISABLE_LIBVPX)
1186 video_decoders.push_back(new media::VpxVideoDecoder(media_loop_));
1187 #endif // !defined(MEDIA_DISABLE_LIBVPX)
1189 video_decoders.push_back(new media::FFmpegVideoDecoder(media_loop_));
1191 scoped_ptr<media::VideoRenderer> video_renderer(
1192 new media::VideoRendererImpl(
1194 video_decoders.Pass(),
1195 set_decryptor_ready_cb,
1196 base::Bind(&WebMediaPlayerImpl::FrameReady, base::Unretained(this)),
1197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque),
1199 filter_collection->SetVideoRenderer(video_renderer.Pass());
1201 if (cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) {
1202 scoped_ptr<media::TextRenderer> text_renderer(
1203 new media::TextRenderer(
1205 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnAddTextTrack)));
1207 filter_collection->SetTextRenderer(text_renderer.Pass());
1210 // ... and we're ready to go!
1213 filter_collection.Pass(),
1214 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded),
1215 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError),
1216 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek),
1217 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata),
1218 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelinePrerollCompleted),
1219 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange));
1222 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1223 DCHECK(main_loop_->BelongsToCurrentThread());
1224 DVLOG(1) << "SetNetworkState: " << state;
1225 network_state_ = state;
1226 // Always notify to ensure client has the latest value.
1227 client_->networkStateChanged();
1230 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) {
1231 DCHECK(main_loop_->BelongsToCurrentThread());
1232 DVLOG(1) << "SetReadyState: " << state;
1234 if (state == WebMediaPlayer::ReadyStateHaveEnoughData &&
1236 network_state_ == WebMediaPlayer::NetworkStateLoading)
1237 SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
1239 ready_state_ = state;
1240 // Always notify to ensure client has the latest value.
1241 client_->readyStateChanged();
1244 blink::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() {
1245 return audio_source_provider_.get();
1248 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1249 DCHECK(main_loop_->BelongsToCurrentThread());
1250 incremented_externally_allocated_memory_ = true;
1251 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
1252 kPlayerExtraMemory);
1255 double WebMediaPlayerImpl::GetPipelineDuration() const {
1256 base::TimeDelta duration = pipeline_.GetMediaDuration();
1258 // Return positive infinity if the resource is unbounded.
1259 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-duration
1260 if (duration == media::kInfiniteDuration())
1261 return std::numeric_limits<double>::infinity();
1263 return duration.InSecondsF();
1266 void WebMediaPlayerImpl::OnDurationChange() {
1267 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
1270 client_->durationChanged();
1273 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) {
1274 DCHECK(main_loop_->BelongsToCurrentThread());
1275 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing);
1276 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged");
1278 media_log_->AddEvent(
1279 media_log_->CreateVideoSizeSetEvent(size.width(), size.height()));
1280 pipeline_metadata_.natural_size = size;
1282 client_->sizeChanged();
1285 void WebMediaPlayerImpl::FrameReady(
1286 const scoped_refptr<media::VideoFrame>& frame) {
1287 compositor_.UpdateCurrentFrame(frame);
1290 void WebMediaPlayerImpl::SetDecryptorReadyCB(
1291 const media::DecryptorReadyCB& decryptor_ready_cb) {
1292 DCHECK(main_loop_->BelongsToCurrentThread());
1294 // Cancels the previous decryptor request.
1295 if (decryptor_ready_cb.is_null()) {
1296 if (!decryptor_ready_cb_.is_null())
1297 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL);
1301 // TODO(xhwang): Support multiple decryptor notification request (e.g. from
1302 // video and audio). The current implementation is okay for the current
1303 // media pipeline since we initialize audio and video decoders in sequence.
1304 // But WebMediaPlayerImpl should not depend on media pipeline's implementation
1306 DCHECK(decryptor_ready_cb_.is_null());
1308 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink.
1309 DCHECK(!(proxy_decryptor_ && web_cdm_));
1311 if (proxy_decryptor_) {
1312 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor());
1317 decryptor_ready_cb.Run(web_cdm_->GetDecryptor());
1321 decryptor_ready_cb_ = decryptor_ready_cb;
1324 } // namespace content