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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/android_video_decode_accelerator.cc
diff --git a/content/common/gpu/media/android_video_decode_accelerator.cc b/content/common/gpu/media/android_video_decode_accelerator.cc
index dfe0fc52895fcc9d70e0624f5b89132dfe6d6df7..6a9b5a4d2d2720c392d9c0cc148ac2893c9ed099 100644
--- a/content/common/gpu/media/android_video_decode_accelerator.cc
+++ b/content/common/gpu/media/android_video_decode_accelerator.cc
@@ -15,6 +15,7 @@
#include "base/metrics/histogram.h"
#include "base/trace_event/trace_event.h"
#include "content/common/gpu/gpu_channel.h"
+#include "content/common/gpu/gpu_surface_lookup.h"
#include "content/common/gpu/media/android_copying_backing_strategy.h"
#include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
@@ -220,11 +221,24 @@ bool AndroidVideoDecodeAccelerator::Initialize(const Config& config,
return false;
}
- strategy_->Initialize(this);
+ if (config.surface_id != VideoDecodeAccelerator::Config::kNullSurfaceID) {
+ DCHECK(UseDeferredRenderingStrategy());
+ surface_view_ =
+ GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(config.surface_id);
+ if (surface_view_.IsEmpty()) {
+ LOG(ERROR) << "Java surface was empty. surface_id: " << config.surface_id;
+ return false;
+ }
+ } else {
+ // Create a detached SurfaceTexture. The backing strategy is responsible
+ // for attaching it. Detaching it will silently fail to delete texture 0.
+ surface_texture_ = gfx::SurfaceTexture::Create(0);
+ surface_texture_->DetachFromGLContext();
+ on_frame_available_handler_ =
+ new OnFrameAvailableHandler(this, surface_texture_);
+ }
- surface_texture_ = strategy_->CreateSurfaceTexture();
- on_frame_available_handler_ =
- new OnFrameAvailableHandler(this, surface_texture_);
+ strategy_->Initialize(this, surface_texture_);
// For encrypted streams we postpone configuration until MediaCrypto is
// available.
@@ -578,11 +592,14 @@ void AndroidVideoDecodeAccelerator::SendDecodedFrameToClient(
// mechanism the strategy likes.
strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second);
+ // SurfaceView video frames must always be overlayable because that's the only
+ // way to display them.
+ const bool allow_overlay = !surface_view_.IsEmpty();
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyPictureReady,
weak_this_factory_.GetWeakPtr(),
media::Picture(picture_buffer_id, bitstream_id,
- gfx::Rect(size_), false)));
+ gfx::Rect(size_), allow_overlay)));
}
void AndroidVideoDecodeAccelerator::Decode(
@@ -678,10 +695,17 @@ void AndroidVideoDecodeAccelerator::Flush() {
bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(surface_texture_.get());
TRACE_EVENT0("media", "AVDA::ConfigureMediaCodec");
- gfx::ScopedJavaSurface surface(surface_texture_.get());
+ gfx::ScopedJavaSurface surface;
+ jobject surface_obj;
+ if (surface_texture_) {
liberato (no reviews please) 2016/01/26 21:48:45 it might be simpler to hide all of this inside the
+ surface = gfx::ScopedJavaSurface(surface_texture_.get());
+ surface_obj = surface.j_surface().obj();
+ } else {
+ DCHECK(!surface_view_.IsEmpty());
+ surface_obj = surface_view_.j_surface().obj();
+ }
jobject media_crypto = media_crypto_ ? media_crypto_->obj() : nullptr;
@@ -691,8 +715,8 @@ bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() {
// Pass a dummy 320x240 canvas size and let the codec signal the real size
// when it's known from the bitstream.
media_codec_.reset(media::VideoCodecBridge::CreateDecoder(
- codec_, needs_protected_surface_, gfx::Size(320, 240),
- surface.j_surface().obj(), media_crypto));
+ codec_, needs_protected_surface_, gfx::Size(320, 240), surface_obj,
+ media_crypto));
strategy_->CodecChanged(media_codec_.get(), output_picture_buffers_);
if (!media_codec_) {
LOG(ERROR) << "Failed to create MediaCodec instance.";

Powered by Google App Engine
This is Rietveld 408576698