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

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

Issue 1313913003: Begin refactor of AVDA to support zero-copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cl feedback + rebased. Created 5 years, 3 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
(Empty)
1 // Copyright 2015 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 "content/common/gpu/media/android_copying_backing_strategy.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/trace_event/trace_event.h"
10 #include "content/common/gpu/media/avda_return_on_failure.h"
11 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
13 #include "media/base/limits.h"
14 #include "media/video/picture.h"
15 #include "ui/gl/android/surface_texture.h"
16 #include "ui/gl/gl_bindings.h"
17
18 namespace content {
19
20 // TODO(liberato): It is unclear if we have an issue with deadlock during
21 // playback if we lower this. Previously (crbug.com/176036), a deadlock
22 // could occur during preroll. More recent tests have shown some
23 // instability with kNumPictureBuffers==2 with similar symptoms
24 // during playback. crbug.com/:531588 .
25 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 };
26
27 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
28 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
29 0.0f, 0.0f, 0.0f, 1.0f};
30
31 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy()
32 : state_provider_(nullptr) {}
33
34 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {}
35
36 void AndroidCopyingBackingStrategy::SetStateProvider(
37 AndroidVideoDecodeAcceleratorStateProvider* state_provider) {
38 state_provider_ = state_provider;
39 }
40
41 void AndroidCopyingBackingStrategy::Cleanup() {
42 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
43 if (copier_)
44 copier_->Destroy();
45 }
46
47 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const {
48 return kNumPictureBuffers;
49 }
50
51 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const {
52 return GL_TEXTURE_2D;
53 }
54
55 void AndroidCopyingBackingStrategy::AssignCurrentSurfaceToPictureBuffer(
56 int32 codec_buf_index,
57 const media::PictureBuffer& picture_buffer) {
58 // Make sure that the decoder is available.
59 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(),
60 "Failed to get gles2 decoder instance.", ILLEGAL_STATE);
61
62 // Render the codec buffer into |surface_texture_|, and switch it to be
63 // the front buffer.
64 // This ignores the emitted ByteBuffer and instead relies on rendering to
65 // the codec's SurfaceTexture and then copying from that texture to the
66 // client's PictureBuffer's texture. This means that each picture's data
67 // is written three times: once to the ByteBuffer, once to the
68 // SurfaceTexture, and once to the client's texture. It would be nicer to
69 // either:
70 // 1) Render directly to the client's texture from MediaCodec (one write);
71 // or
72 // 2) Upload the ByteBuffer to the client's texture (two writes).
73 // Unfortunately neither is possible:
74 // 1) MediaCodec's use of SurfaceTexture is a singleton, and the texture
75 // written to can't change during the codec's lifetime. b/11990461
76 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific,
77 // opaque/non-standard format. It's not possible to negotiate the
78 // decoder to emit a specific colorspace, even using HW CSC. b/10706245
79 // So, we live with these two extra copies per picture :(
80 {
81 TRACE_EVENT0("media", "AVDA::ReleaseOutputBuffer");
82 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index,
83 true);
84 }
85
86 gfx::SurfaceTexture* surface_texture = state_provider_->GetSurfaceTexture();
87 {
88 TRACE_EVENT0("media", "AVDA::UpdateTexImage");
89 surface_texture->UpdateTexImage();
90 }
91
92 float transfrom_matrix[16];
93 surface_texture->GetTransformMatrix(transfrom_matrix);
94
95 uint32 picture_buffer_texture_id = picture_buffer.texture_id();
96
97 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
98 // needed because it takes 10s of milliseconds to initialize.
99 if (!copier_) {
100 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager());
101 copier_->Initialize(state_provider_->GetGlDecoder());
102 }
103
104 // Here, we copy |surface_texture_id_| to the picture buffer instead of
105 // setting new texture to |surface_texture_| by calling attachToGLContext()
106 // because:
107 // 1. Once we call detachFrameGLContext(), it deletes the texture previous
108 // attached.
109 // 2. SurfaceTexture requires us to apply a transform matrix when we show
110 // the texture.
111 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
112 // instead of using default matrix crbug.com/226218.
113 copier_->DoCopyTextureWithTransform(
114 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES,
115 state_provider_->GetSurfaceTextureId(), picture_buffer_texture_id,
116 state_provider_->GetSize().width(), state_provider_->GetSize().height(),
117 false, false, false, kIdentityMatrix);
118 }
119
120 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698