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

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: add gn build. 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 (c) 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/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h"
11 #include "content/common/gpu/gpu_channel.h"
12 #include "content/common/gpu/media/avda_return_on_failure.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
14 #include "media/base/bitstream_buffer.h"
15 #include "media/base/limits.h"
16 #include "media/base/video_decoder_config.h"
17 #include "media/video/picture.h"
18 #include "ui/gl/android/surface_texture.h"
19 #include "ui/gl/gl_bindings.h"
20
21 namespace content {
22
23 // TODO(dwkang): We only need kMaxVideoFrames to pass media stack's prerolling
24 // phase, but 1 is added due to crbug.com/176036. This should be tuned when we
25 // have actual use case.
sandersd (OOO until July 31) 2015/09/10 20:28:20 We should probably update all of the copies of thi
liberato (no reviews please) 2015/09/14 17:41:28 i saw weirdness when prototyping the zero copy cod
26 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 };
27
28 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy()
29 : state_provider_(nullptr) {}
30
31 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {}
32
33 void AndroidCopyingBackingStrategy::SetStateProvider(
34 AndroidVideoDecodeAcceleratorStateProvider* state_provider) {
35 state_provider_ = state_provider;
36 }
37
38 void AndroidCopyingBackingStrategy::Cleanup() {
39 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
40 if (copier_)
41 copier_->Destroy();
42 }
43
44 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const {
45 return kNumPictureBuffers;
46 }
47
48 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const {
49 return GL_TEXTURE_2D;
50 }
51
52 void AndroidCopyingBackingStrategy::AssignCurrentSurfaceToPictureBuffer(
53 int32 codec_buf_index,
54 const media::PictureBuffer& picture_buffer) {
55 // Make sure that the decoder is available.
56 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(),
57 "Failed to get gles2 decoder instance.", ILLEGAL_STATE);
58
59 // Render the codec buffer into |surface_texture_|, and switch it to be
60 // the front buffer.
61 // This ignores the emitted ByteBuffer and instead relies on rendering to
62 // the codec's SurfaceTexture and then copying from that texture to the
63 // client's PictureBuffer's texture. This means that each picture's data
64 // is written three times: once to the ByteBuffer, once to the
65 // SurfaceTexture, and once to the client's texture. It would be nicer to
66 // either:
67 // 1) Render directly to the client's texture from MediaCodec (one write);
68 // or
69 // 2) Upload the ByteBuffer to the client's texture (two writes).
70 // Unfortunately neither is possible:
71 // 1) MediaCodec's use of SurfaceTexture is a singleton, and the texture
72 // written to can't change during the codec's lifetime. b/11990461
73 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific,
74 // opaque/non-standard format. It's not possible to negotiate the
75 // decoder to emit a specific colorspace, even using HW CSC. b/10706245
76 // So, we live with these two extra copies per picture :(
77 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index, true);
78
79 gfx::SurfaceTexture* surface_texture = state_provider_->GetSurfaceTexture();
80 surface_texture->UpdateTexImage();
81
82 float transfrom_matrix[16];
83 surface_texture->GetTransformMatrix(transfrom_matrix);
84
85 uint32 picture_buffer_texture_id = picture_buffer.texture_id();
86
87 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
88 // needed because it takes 10s of milliseconds to initialize.
89 if (!copier_) {
90 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager());
91 copier_->Initialize(state_provider_->GetGlDecoder());
92 }
93
94 // Here, we copy |surface_texture_id_| to the picture buffer instead of
95 // setting new texture to |surface_texture_| by calling attachToGLContext()
96 // because:
97 // 1. Once we call detachFrameGLContext(), it deletes the texture previous
98 // attached.
99 // 2. SurfaceTexture requires us to apply a transform matrix when we show
100 // the texture.
101 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
102 // instead of using default matrix crbug.com/226218.
103 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
qinmin 2015/09/11 17:29:51 should this be using the transform_matrix instead?
liberato (no reviews please) 2015/09/14 17:41:28 great question. i want to preserve current behavi
watk 2015/09/14 18:15:19 qinmin@ said the xoom has non identity, but I don'
104 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
105 0.0f, 0.0f, 0.0f, 1.0f};
106 copier_->DoCopyTextureWithTransform(
107 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES,
108 state_provider_->GetSurfaceTextureId(), picture_buffer_texture_id,
109 state_provider_->GetSize().width(), state_provider_->GetSize().height(),
110 false, false, false, default_matrix);
111 }
112
113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698