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

Side by Side Diff: content/common/gpu/media/android_video_decode_accelerator.cc

Issue 1808983002: media: Add MediaDrmBridgeCdmContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 4 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/common/gpu/media/android_video_decode_accelerator.h" 5 #include "content/common/gpu/media/android_video_decode_accelerator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 20 matching lines...) Expand all
31 #include "media/base/limits.h" 31 #include "media/base/limits.h"
32 #include "media/base/media.h" 32 #include "media/base/media.h"
33 #include "media/base/timestamp_constants.h" 33 #include "media/base/timestamp_constants.h"
34 #include "media/base/video_decoder_config.h" 34 #include "media/base/video_decoder_config.h"
35 #include "media/video/picture.h" 35 #include "media/video/picture.h"
36 #include "ui/gl/android/scoped_java_surface.h" 36 #include "ui/gl/android/scoped_java_surface.h"
37 #include "ui/gl/android/surface_texture.h" 37 #include "ui/gl/android/surface_texture.h"
38 #include "ui/gl/gl_bindings.h" 38 #include "ui/gl/gl_bindings.h"
39 39
40 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 40 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
41 #include "media/base/media_keys.h"
42 #include "media/mojo/services/mojo_cdm_service.h" 41 #include "media/mojo/services/mojo_cdm_service.h"
43 #endif 42 #endif
44 43
45 #define POST_ERROR(error_code, error_message) \ 44 #define POST_ERROR(error_code, error_message) \
46 do { \ 45 do { \
47 DLOG(ERROR) << error_message; \ 46 DLOG(ERROR) << error_message; \
48 PostError(FROM_HERE, media::VideoDecodeAccelerator::error_code); \ 47 PostError(FROM_HERE, media::VideoDecodeAccelerator::error_code); \
49 } while (0) 48 } while (0)
50 49
51 namespace content { 50 namespace content {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 DVLOG(1) << __FUNCTION__ << ", using copy back strategy."; 277 DVLOG(1) << __FUNCTION__ << ", using copy back strategy.";
279 strategy_.reset(new AndroidCopyingBackingStrategy(this)); 278 strategy_.reset(new AndroidCopyingBackingStrategy(this));
280 } 279 }
281 } 280 }
282 281
283 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { 282 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() {
284 DCHECK(thread_checker_.CalledOnValidThread()); 283 DCHECK(thread_checker_.CalledOnValidThread());
285 g_avda_timer.Pointer()->StopTimer(this); 284 g_avda_timer.Pointer()->StopTimer(this);
286 285
287 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 286 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
288 if (cdm_) { 287 if (!cdm_)
289 DCHECK(cdm_registration_id_); 288 return;
290 static_cast<media::MediaDrmBridge*>(cdm_.get()) 289
291 ->UnregisterPlayer(cdm_registration_id_); 290 DCHECK(cdm_registration_id_);
292 } 291 static_cast<media::MediaDrmBridgeCdmContext*>(cdm_->GetCdmContext())
ddorwin 2016/03/21 21:40:25 It would be nice to only cast once. Also, we shoul
xhwang 2016/03/22 17:08:32 Done.
292 ->UnregisterPlayer(cdm_registration_id_);
293 #endif // defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 293 #endif // defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
294 } 294 }
295 295
296 bool AndroidVideoDecodeAccelerator::Initialize(const Config& config, 296 bool AndroidVideoDecodeAccelerator::Initialize(const Config& config,
297 Client* client) { 297 Client* client) {
298 DCHECK(!media_codec_); 298 DCHECK(!media_codec_);
299 DCHECK(thread_checker_.CalledOnValidThread()); 299 DCHECK(thread_checker_.CalledOnValidThread());
300 TRACE_EVENT0("media", "AVDA::Initialize"); 300 TRACE_EVENT0("media", "AVDA::Initialize");
301 301
302 DVLOG(1) << __FUNCTION__ << ": " << config.AsHumanReadableString(); 302 DVLOG(1) << __FUNCTION__ << ": " << config.AsHumanReadableString();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (is_encrypted_) 358 if (is_encrypted_)
359 return true; 359 return true;
360 360
361 return ConfigureMediaCodec(); 361 return ConfigureMediaCodec();
362 } 362 }
363 363
364 void AndroidVideoDecodeAccelerator::SetCdm(int cdm_id) { 364 void AndroidVideoDecodeAccelerator::SetCdm(int cdm_id) {
365 DVLOG(2) << __FUNCTION__ << ": " << cdm_id; 365 DVLOG(2) << __FUNCTION__ << ": " << cdm_id;
366 366
367 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 367 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
368 using media::MediaDrmBridge;
369
370 DCHECK(client_) << "SetCdm() must be called after Initialize()."; 368 DCHECK(client_) << "SetCdm() must be called after Initialize().";
371 369
372 if (cdm_) { 370 if (cdm_) {
373 NOTREACHED() << "We do not support resetting CDM."; 371 NOTREACHED() << "We do not support resetting CDM.";
374 NotifyCdmAttached(false); 372 NotifyCdmAttached(false);
375 return; 373 return;
376 } 374 }
377 375
378 cdm_ = media::MojoCdmService::LegacyGetCdm(cdm_id); 376 cdm_ = media::MojoCdmService::LegacyGetCdm(cdm_id);
379 DCHECK(cdm_); 377 DCHECK(cdm_);
380 378
381 // On Android platform the MediaKeys will be its subclass MediaDrmBridge. 379 // On Android platform the CdmContext must be a MediaDrmBridgeCdmContext.
382 MediaDrmBridge* drm_bridge = static_cast<MediaDrmBridge*>(cdm_.get()); 380 media::MediaDrmBridgeCdmContext* media_drm_bridge_cdm_context =
381 static_cast<media::MediaDrmBridgeCdmContext*>(cdm_->GetCdmContext());
383 382
384 // Register CDM callbacks. The callbacks registered will be posted back to 383 // Register CDM callbacks. The callbacks registered will be posted back to
385 // this thread via BindToCurrentLoop. 384 // this thread via BindToCurrentLoop.
386 385
387 // Since |this| holds a reference to the |cdm_|, by the time the CDM is 386 // Since |this| holds a reference to the |cdm_|, by the time the CDM is
388 // destructed, UnregisterPlayer() must have been called and |this| has been 387 // destructed, UnregisterPlayer() must have been called and |this| has been
389 // destructed as well. So the |cdm_unset_cb| will never have a chance to be 388 // destructed as well. So the |cdm_unset_cb| will never have a chance to be
390 // called. 389 // called.
391 // TODO(xhwang): Remove |cdm_unset_cb| after it's not used on all platforms. 390 // TODO(xhwang): Remove |cdm_unset_cb| after it's not used on all platforms.
392 cdm_registration_id_ = 391 cdm_registration_id_ = media_drm_bridge_cdm_context->RegisterPlayer(
393 drm_bridge->RegisterPlayer(media::BindToCurrentLoop(base::Bind( 392 media::BindToCurrentLoop(
394 &AndroidVideoDecodeAccelerator::OnKeyAdded, 393 base::Bind(&AndroidVideoDecodeAccelerator::OnKeyAdded,
395 weak_this_factory_.GetWeakPtr())), 394 weak_this_factory_.GetWeakPtr())),
396 base::Bind(&base::DoNothing)); 395 base::Bind(&base::DoNothing));
397 396
398 drm_bridge->SetMediaCryptoReadyCB(media::BindToCurrentLoop( 397 media_drm_bridge_cdm_context->SetMediaCryptoReadyCB(media::BindToCurrentLoop(
399 base::Bind(&AndroidVideoDecodeAccelerator::OnMediaCryptoReady, 398 base::Bind(&AndroidVideoDecodeAccelerator::OnMediaCryptoReady,
400 weak_this_factory_.GetWeakPtr()))); 399 weak_this_factory_.GetWeakPtr())));
401 400
402 // Postpone NotifyCdmAttached() call till we create the MediaCodec after 401 // Postpone NotifyCdmAttached() call till we create the MediaCodec after
403 // OnMediaCryptoReady(). 402 // OnMediaCryptoReady().
404 403
405 #else 404 #else
406 405
407 NOTIMPLEMENTED(); 406 NOTIMPLEMENTED();
408 NotifyCdmAttached(false); 407 NotifyCdmAttached(false);
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 media::VideoDecodeAccelerator::Error error) { 1063 media::VideoDecodeAccelerator::Error error) {
1065 base::MessageLoop::current()->PostDelayedTask( 1064 base::MessageLoop::current()->PostDelayedTask(
1066 from_here, 1065 from_here,
1067 base::Bind(&AndroidVideoDecodeAccelerator::NotifyError, 1066 base::Bind(&AndroidVideoDecodeAccelerator::NotifyError,
1068 weak_this_factory_.GetWeakPtr(), error, error_sequence_token_), 1067 weak_this_factory_.GetWeakPtr(), error, error_sequence_token_),
1069 (defer_errors_ ? ErrorPostingDelay() : base::TimeDelta())); 1068 (defer_errors_ ? ErrorPostingDelay() : base::TimeDelta()));
1070 state_ = ERROR; 1069 state_ = ERROR;
1071 } 1070 }
1072 1071
1073 void AndroidVideoDecodeAccelerator::OnMediaCryptoReady( 1072 void AndroidVideoDecodeAccelerator::OnMediaCryptoReady(
1074 media::MediaDrmBridge::JavaObjectPtr media_crypto, 1073 media::MediaDrmBridgeCdmContext::JavaObjectPtr media_crypto,
1075 bool needs_protected_surface) { 1074 bool needs_protected_surface) {
1076 DVLOG(1) << __FUNCTION__; 1075 DVLOG(1) << __FUNCTION__;
1077 1076
1078 if (!media_crypto) { 1077 if (!media_crypto) {
1079 LOG(ERROR) << "MediaCrypto is not available, can't play encrypted stream."; 1078 LOG(ERROR) << "MediaCrypto is not available, can't play encrypted stream.";
1080 NotifyCdmAttached(false); 1079 NotifyCdmAttached(false);
1081 return; 1080 return;
1082 } 1081 }
1083 1082
1084 DCHECK(!media_crypto->is_null()); 1083 DCHECK(!media_crypto->is_null());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: 1199 capabilities.flags = media::VideoDecodeAccelerator::Capabilities::
1201 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE | 1200 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE |
1202 media::VideoDecodeAccelerator::Capabilities:: 1201 media::VideoDecodeAccelerator::Capabilities::
1203 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; 1202 SUPPORTS_EXTERNAL_OUTPUT_SURFACE;
1204 } 1203 }
1205 1204
1206 return capabilities; 1205 return capabilities;
1207 } 1206 }
1208 1207
1209 } // namespace content 1208 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698