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

Side by Side Diff: content/common/gpu/media/avda_codec_image.h

Issue 1963773003: Merge to M51: Various fixes to prevent playback hang on MotoX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ 5 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_
6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ 6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "content/common/gpu/media/avda_shared_state.h" 11 #include "content/common/gpu/media/avda_shared_state.h"
12 #include "gpu/command_buffer/service/gl_stream_texture_image.h" 12 #include "gpu/command_buffer/service/gl_stream_texture_image.h"
13 13
14 namespace ui { 14 namespace ui {
15 class ScopedMakeCurrent; 15 class ScopedMakeCurrent;
16 } 16 }
17 17
18 namespace content { 18 namespace content {
19 19
20 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as 20 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as
21 // needed in order to draw them. 21 // needed in order to draw them.
22 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage { 22 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage {
23 public: 23 public:
24 AVDACodecImage(const scoped_refptr<AVDASharedState>&, 24 AVDACodecImage(int picture_buffer_id,
25 const scoped_refptr<AVDASharedState>& shared_state,
25 media::VideoCodecBridge* codec, 26 media::VideoCodecBridge* codec,
26 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, 27 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder,
27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture); 28 const scoped_refptr<gfx::SurfaceTexture>& surface_texture);
28 29
29 protected:
30 ~AVDACodecImage() override;
31
32 public:
33 // gl::GLImage implementation 30 // gl::GLImage implementation
34 void Destroy(bool have_context) override; 31 void Destroy(bool have_context) override;
35 gfx::Size GetSize() override; 32 gfx::Size GetSize() override;
36 unsigned GetInternalFormat() override; 33 unsigned GetInternalFormat() override;
37 bool BindTexImage(unsigned target) override; 34 bool BindTexImage(unsigned target) override;
38 void ReleaseTexImage(unsigned target) override; 35 void ReleaseTexImage(unsigned target) override;
39 bool CopyTexImage(unsigned target) override; 36 bool CopyTexImage(unsigned target) override;
40 bool CopyTexSubImage(unsigned target, 37 bool CopyTexSubImage(unsigned target,
41 const gfx::Point& offset, 38 const gfx::Point& offset,
42 const gfx::Rect& rect) override; 39 const gfx::Rect& rect) override;
43 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 40 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
44 int z_order, 41 int z_order,
45 gfx::OverlayTransform transform, 42 gfx::OverlayTransform transform,
46 const gfx::Rect& bounds_rect, 43 const gfx::Rect& bounds_rect,
47 const gfx::RectF& crop_rect) override; 44 const gfx::RectF& crop_rect) override;
48 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 45 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
49 uint64_t process_tracing_id, 46 uint64_t process_tracing_id,
50 const std::string& dump_name) override; 47 const std::string& dump_name) override;
51 // gpu::gles2::GLStreamTextureMatrix implementation 48 // gpu::gles2::GLStreamTextureMatrix implementation
52 void GetTextureMatrix(float xform[16]) override; 49 void GetTextureMatrix(float xform[16]) override;
53 50
54 public: 51 enum class UpdateMode {
52 // Discards the codec buffer, no UpdateTexImage().
53 DISCARD_CODEC_BUFFER,
54
55 // Renders to back buffer, no UpdateTexImage(); can only be used with a
56 // valid |surface_texture_|.
57 RENDER_TO_BACK_BUFFER,
58
59 // Renders to the back buffer. When used with a SurfaceView, promotion to
60 // the front buffer is automatic. When using a |surface_texture_|,
61 // UpdateTexImage() is called to promote the back buffer into the front.
62 RENDER_TO_FRONT_BUFFER
63 };
64
65 // Releases the attached codec buffer (if not already released) indicated by
66 // |codec_buffer_index_| and updates the surface if specified by the given
67 // |update_mode|. See UpdateMode documentation for details.
68 void UpdateSurface(UpdateMode update_mode);
69
70 // Updates the MediaCodec for this image; clears |codec_buffer_index_|.
71 void CodecChanged(media::MediaCodecBridge* codec);
72
73 void set_texture(gpu::gles2::Texture* texture) { texture_ = texture; }
74
55 // Decoded buffer index that has the image for us to display. 75 // Decoded buffer index that has the image for us to display.
56 void SetMediaCodecBufferIndex(int buffer_index); 76 void set_media_codec_buffer_index(int buffer_index) {
57 77 codec_buffer_index_ = buffer_index;
58 // Return the codec buffer that we will return to the codec, or 78 }
59 // <0 if there is no such buffer.
60 int GetMediaCodecBufferIndex() const;
61 79
62 // Set the size of the current image. 80 // Set the size of the current image.
63 void SetSize(const gfx::Size& size); 81 void set_size(const gfx::Size& size) { size_ = size; }
64 82
65 void SetMediaCodec(media::MediaCodecBridge* codec); 83 // Indicates if the codec buffer has been released to the back buffer.
84 bool was_rendered_to_back_buffer() const {
85 return codec_buffer_index_ == kUpdateOnly;
86 }
66 87
67 void SetTexture(gpu::gles2::Texture* texture); 88 // Indicates if the codec buffer has been released to the front buffer.
89 bool was_rendered_to_front_buffer() const {
90 return codec_buffer_index_ == kRendered;
91 }
92
93 protected:
94 ~AVDACodecImage() override;
68 95
69 private: 96 private:
70 enum { kInvalidCodecBufferIndex = -1 };
71
72 // Make sure that the surface texture's front buffer is current. This will 97 // Make sure that the surface texture's front buffer is current. This will
73 // save / restore the current context. It will optionally restore the texture 98 // save / restore the current context. It will optionally restore the texture
74 // bindings in the surface texture's context, based on |mode|. This is 99 // bindings in the surface texture's context, based on |mode|. This is
75 // intended as a hint if we don't need to change contexts. If we do need to 100 // intended as a hint if we don't need to change contexts. If we do need to
76 // change contexts, then we'll always preserve the texture bindings in the 101 // change contexts, then we'll always preserve the texture bindings in the
77 // both contexts. In other words, the caller is telling us whether it's 102 // both contexts. In other words, the caller is telling us whether it's
78 // okay to change the binding in the current context. 103 // okay to change the binding in the current context.
79 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; 104 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings };
80 void UpdateSurfaceTexture(RestoreBindingsMode mode); 105 void UpdateSurfaceTexture(RestoreBindingsMode mode);
81 106
107 // Internal helper for UpdateSurface() that allows callers to specify the
108 // RestoreBindingsMode when a SurfaceTexture is already attached prior to
109 // calling this method.
110 void UpdateSurfaceInternal(UpdateMode update_mode,
111 RestoreBindingsMode attached_bindings_mode);
112
113 // Releases the attached codec buffer (if not already released) indicated by
114 // |codec_buffer_index_|. Never updates the actual surface. See UpdateMode
115 // documentation for details. For the purposes of this function the values
116 // RENDER_TO_FRONT_BUFFER and RENDER_TO_BACK_BUFFER do the same thing.
117 void ReleaseOutputBuffer(UpdateMode update_mode);
118
82 // Attach the surface texture to our GL context to whatever texture is bound 119 // Attach the surface texture to our GL context to whatever texture is bound
83 // on the active unit. 120 // on the active unit.
84 void AttachSurfaceTextureToContext(); 121 void AttachSurfaceTextureToContext();
85 122
86 // Make shared_state_->context() current if it isn't already. 123 // Make shared_state_->context() current if it isn't already.
87 scoped_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); 124 scoped_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded();
88 125
89 // Return whether or not the current context is in the same share group as
90 // |surface_texture_|'s client texture.
91 // TODO(liberato): is this needed?
92 bool IsCorrectShareGroup() const;
93
94 // Return whether there is a codec buffer that we haven't rendered yet. Will 126 // Return whether there is a codec buffer that we haven't rendered yet. Will
95 // return false also if there's no codec or we otherwise can't update. 127 // return false also if there's no codec or we otherwise can't update.
96 bool IsCodecBufferOutstanding() const; 128 bool IsCodecBufferOutstanding() const;
97 129
98 // Shared state between the AVDA and all AVDACodecImages. 130 // Shared state between the AVDA and all AVDACodecImages.
99 scoped_refptr<AVDASharedState> shared_state_; 131 scoped_refptr<AVDASharedState> shared_state_;
100 132
101 // The MediaCodec buffer index that we should render. Only valid if not equal 133 // The MediaCodec buffer index that we should render. Must be >= 0 or one of
102 // to |kInvalidCodecBufferIndex|. 134 // the enum values below.
135 enum { kUpdateOnly = -1, kRendered = -2, kInvalidCodecBufferIndex = -3 };
103 int codec_buffer_index_; 136 int codec_buffer_index_;
104 137
105 // Our image size. 138 // Our image size.
106 gfx::Size size_; 139 gfx::Size size_;
107 140
108 // May be null. 141 // May be null.
109 media::MediaCodecBridge* media_codec_; 142 media::MediaCodecBridge* media_codec_;
110 143
111 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; 144 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_;
112 145
113 // The SurfaceTexture to render to. This is null when rendering to a 146 // The SurfaceTexture to render to. This is null when rendering to a
114 // SurfaceView. 147 // SurfaceView.
115 const scoped_refptr<gfx::SurfaceTexture> surface_texture_; 148 const scoped_refptr<gfx::SurfaceTexture> surface_texture_;
116 149
117 // Should we detach |surface_texture_| from its GL context when we are 150 // Should we detach |surface_texture_| from its GL context when we are
118 // deleted? This happens when it's using our Texture's texture handle. 151 // deleted? This happens when it's using our Texture's texture handle.
119 bool detach_surface_texture_on_destruction_; 152 bool detach_surface_texture_on_destruction_;
120 153
121 // The texture that we're attached to. 154 // The texture that we're attached to.
122 gpu::gles2::Texture* texture_; 155 gpu::gles2::Texture* texture_;
123 156
124 // Texture matrix of the front buffer of the surface texture. 157 // Texture matrix of the front buffer of the surface texture.
125 float gl_matrix_[16]; 158 float gl_matrix_[16];
126 159
160 // The picture buffer id attached to this image.
161 int picture_buffer_id_;
162
127 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); 163 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage);
128 }; 164 };
129 165
130 } // namespace content 166 } // namespace content
131 167
132 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ 168 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/android_video_decode_accelerator.cc ('k') | content/common/gpu/media/avda_codec_image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698