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

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

Issue 1639963002: AndroidVideoDecodeAccelerator can now render to a SurfaceView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "content/common/gpu/gpu_channel.h" 17 #include "content/common/gpu/gpu_channel.h"
18 #include "content/common/gpu/gpu_surface_lookup.h"
18 #include "content/common/gpu/media/android_copying_backing_strategy.h" 19 #include "content/common/gpu/media/android_copying_backing_strategy.h"
19 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h " 20 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h "
20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
21 #include "media/base/bind_to_current_loop.h" 22 #include "media/base/bind_to_current_loop.h"
22 #include "media/base/bitstream_buffer.h" 23 #include "media/base/bitstream_buffer.h"
23 #include "media/base/limits.h" 24 #include "media/base/limits.h"
24 #include "media/base/media_switches.h" 25 #include "media/base/media_switches.h"
25 #include "media/base/timestamp_constants.h" 26 #include "media/base/timestamp_constants.h"
26 #include "media/base/video_decoder_config.h" 27 #include "media/base/video_decoder_config.h"
27 #include "media/video/picture.h" 28 #include "media/video/picture.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (!make_context_current_.Run()) { 214 if (!make_context_current_.Run()) {
214 LOG(ERROR) << "Failed to make this decoder's GL context current."; 215 LOG(ERROR) << "Failed to make this decoder's GL context current.";
215 return false; 216 return false;
216 } 217 }
217 218
218 if (!gl_decoder_) { 219 if (!gl_decoder_) {
219 LOG(ERROR) << "Failed to get gles2 decoder instance."; 220 LOG(ERROR) << "Failed to get gles2 decoder instance.";
220 return false; 221 return false;
221 } 222 }
222 223
223 strategy_->Initialize(this); 224 if (config.surface_id != VideoDecodeAccelerator::Config::kNullSurfaceID) {
225 DCHECK(UseDeferredRenderingStrategy());
226 surface_view_ =
227 GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(config.surface_id);
228 if (surface_view_.IsEmpty()) {
229 LOG(ERROR) << "Java surface was empty. surface_id: " << config.surface_id;
230 return false;
231 }
232 } else {
233 // Create a detached SurfaceTexture. The backing strategy is responsible
234 // for attaching it. Detaching it will silently fail to delete texture 0.
235 surface_texture_ = gfx::SurfaceTexture::Create(0);
236 surface_texture_->DetachFromGLContext();
237 on_frame_available_handler_ =
238 new OnFrameAvailableHandler(this, surface_texture_);
239 }
224 240
225 surface_texture_ = strategy_->CreateSurfaceTexture(); 241 strategy_->Initialize(this, surface_texture_);
226 on_frame_available_handler_ =
227 new OnFrameAvailableHandler(this, surface_texture_);
228 242
229 // For encrypted streams we postpone configuration until MediaCrypto is 243 // For encrypted streams we postpone configuration until MediaCrypto is
230 // available. 244 // available.
231 if (is_encrypted_) 245 if (is_encrypted_)
232 return true; 246 return true;
233 247
234 return ConfigureMediaCodec(); 248 return ConfigureMediaCodec();
235 } 249 }
236 250
237 void AndroidVideoDecodeAccelerator::SetCdm(int cdm_id) { 251 void AndroidVideoDecodeAccelerator::SetCdm(int cdm_id) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (i == output_picture_buffers_.end()) { 585 if (i == output_picture_buffers_.end()) {
572 POST_ERROR(PLATFORM_FAILURE, 586 POST_ERROR(PLATFORM_FAILURE,
573 "Can't find PictureBuffer id: " << picture_buffer_id); 587 "Can't find PictureBuffer id: " << picture_buffer_id);
574 return; 588 return;
575 } 589 }
576 590
577 // Connect the PictureBuffer to the decoded frame, via whatever 591 // Connect the PictureBuffer to the decoded frame, via whatever
578 // mechanism the strategy likes. 592 // mechanism the strategy likes.
579 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); 593 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second);
580 594
595 // SurfaceView video frames must always be overlayable because that's the only
596 // way to display them.
597 const bool allow_overlay = !surface_view_.IsEmpty();
581 base::MessageLoop::current()->PostTask( 598 base::MessageLoop::current()->PostTask(
582 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyPictureReady, 599 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyPictureReady,
583 weak_this_factory_.GetWeakPtr(), 600 weak_this_factory_.GetWeakPtr(),
584 media::Picture(picture_buffer_id, bitstream_id, 601 media::Picture(picture_buffer_id, bitstream_id,
585 gfx::Rect(size_), false))); 602 gfx::Rect(size_), allow_overlay)));
586 } 603 }
587 604
588 void AndroidVideoDecodeAccelerator::Decode( 605 void AndroidVideoDecodeAccelerator::Decode(
589 const media::BitstreamBuffer& bitstream_buffer) { 606 const media::BitstreamBuffer& bitstream_buffer) {
590 DCHECK(thread_checker_.CalledOnValidThread()); 607 DCHECK(thread_checker_.CalledOnValidThread());
591 if (bitstream_buffer.id() != -1 && bitstream_buffer.size() == 0) { 608 if (bitstream_buffer.id() != -1 && bitstream_buffer.size() == 0) {
592 base::MessageLoop::current()->PostTask( 609 base::MessageLoop::current()->PostTask(
593 FROM_HERE, 610 FROM_HERE,
594 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer, 611 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer,
595 weak_this_factory_.GetWeakPtr(), bitstream_buffer.id())); 612 weak_this_factory_.GetWeakPtr(), bitstream_buffer.id()));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 688 }
672 689
673 void AndroidVideoDecodeAccelerator::Flush() { 690 void AndroidVideoDecodeAccelerator::Flush() {
674 DCHECK(thread_checker_.CalledOnValidThread()); 691 DCHECK(thread_checker_.CalledOnValidThread());
675 692
676 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); 693 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0));
677 } 694 }
678 695
679 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { 696 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() {
680 DCHECK(thread_checker_.CalledOnValidThread()); 697 DCHECK(thread_checker_.CalledOnValidThread());
681 DCHECK(surface_texture_.get());
682 TRACE_EVENT0("media", "AVDA::ConfigureMediaCodec"); 698 TRACE_EVENT0("media", "AVDA::ConfigureMediaCodec");
683 699
684 gfx::ScopedJavaSurface surface(surface_texture_.get()); 700 gfx::ScopedJavaSurface surface;
701 jobject surface_obj;
702 if (surface_texture_) {
liberato (no reviews please) 2016/01/26 21:48:45 it might be simpler to hide all of this inside the
703 surface = gfx::ScopedJavaSurface(surface_texture_.get());
704 surface_obj = surface.j_surface().obj();
705 } else {
706 DCHECK(!surface_view_.IsEmpty());
707 surface_obj = surface_view_.j_surface().obj();
708 }
685 709
686 jobject media_crypto = media_crypto_ ? media_crypto_->obj() : nullptr; 710 jobject media_crypto = media_crypto_ ? media_crypto_->obj() : nullptr;
687 711
688 // |needs_protected_surface_| implies encrypted stream. 712 // |needs_protected_surface_| implies encrypted stream.
689 DCHECK(!needs_protected_surface_ || media_crypto); 713 DCHECK(!needs_protected_surface_ || media_crypto);
690 714
691 // Pass a dummy 320x240 canvas size and let the codec signal the real size 715 // Pass a dummy 320x240 canvas size and let the codec signal the real size
692 // when it's known from the bitstream. 716 // when it's known from the bitstream.
693 media_codec_.reset(media::VideoCodecBridge::CreateDecoder( 717 media_codec_.reset(media::VideoCodecBridge::CreateDecoder(
694 codec_, needs_protected_surface_, gfx::Size(320, 240), 718 codec_, needs_protected_surface_, gfx::Size(320, 240), surface_obj,
695 surface.j_surface().obj(), media_crypto)); 719 media_crypto));
696 strategy_->CodecChanged(media_codec_.get(), output_picture_buffers_); 720 strategy_->CodecChanged(media_codec_.get(), output_picture_buffers_);
697 if (!media_codec_) { 721 if (!media_codec_) {
698 LOG(ERROR) << "Failed to create MediaCodec instance."; 722 LOG(ERROR) << "Failed to create MediaCodec instance.";
699 return false; 723 return false;
700 } 724 }
701 725
702 ManageTimer(true); 726 ManageTimer(true);
703 return true; 727 return true;
704 } 728 }
705 729
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 987
964 if (UseDeferredRenderingStrategy()) { 988 if (UseDeferredRenderingStrategy()) {
965 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: 989 capabilities.flags = media::VideoDecodeAccelerator::Capabilities::
966 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE; 990 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE;
967 } 991 }
968 992
969 return capabilities; 993 return capabilities;
970 } 994 }
971 995
972 } // namespace content 996 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698