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

Side by Side Diff: media/gpu/avda_picture_buffer_manager.h

Issue 2296513003: Delete AVDACopyingBackingStrategy and rename AVDADeferredRenderingBackingStrategy (Closed)
Patch Set: Created 4 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
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 MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ 5 #ifndef MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
6 #define MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ 6 #define MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "media/gpu/android_video_decode_accelerator.h" 12 #include "media/gpu/avda_state_provider.h"
13 #include "media/gpu/media_gpu_export.h" 13 #include "media/gpu/media_gpu_export.h"
14 14
15 namespace gl {
16 class GLImage;
17 }
18
19 namespace gpu { 15 namespace gpu {
20 namespace gles2 { 16 namespace gles2 {
21 class GLStreamTextureImage; 17 class GLStreamTextureImage;
22 class TextureRef;
23 } 18 }
24 } 19 }
25 20
21 namespace gl {
22 class ScopedJavaSurface;
23 class SurfaceTexture;
24 }
25
26 namespace media { 26 namespace media {
27 class AVDASharedState;
28 class VideoCodecBridge;
27 29
28 class AVDACodecImage; 30 // AVDAPictureBufferManager is used by AVDA to associate its PictureBuffers with
29 class AVDASharedState; 31 // MediaCodec output buffers. It attaches AVDACodecImages to the PictureBuffer
32 // textures so that when they're used to draw the AVDACodecImage can release the
33 // MediaCodec buffer to the backing Surface. If the Surface is a SurfaceTexture,
34 // the front buffer can then be used to draw without needing to copy the pixels.
35 // If the Surface is a SurfaceView, the release causes the frame to be displayed
36 // immediately.
37 class MEDIA_GPU_EXPORT AVDAPictureBufferManager {
38 public:
39 using PictureBufferMap = std::map<int32_t, PictureBuffer>;
30 40
31 // A BackingStrategy implementation that defers releasing codec buffers until 41 AVDAPictureBufferManager();
32 // a PictureBuffer's texture is used to draw, then draws using the surface 42 virtual ~AVDAPictureBufferManager();
33 // texture's front buffer rather than a copy. To do this, it uses a GLImage
34 // implementation to talk to MediaCodec.
35 class MEDIA_GPU_EXPORT AndroidDeferredRenderingBackingStrategy
36 : public AndroidVideoDecodeAccelerator::BackingStrategy {
37 public:
38 explicit AndroidDeferredRenderingBackingStrategy(
39 AVDAStateProvider* state_provider);
40 ~AndroidDeferredRenderingBackingStrategy() override;
41 43
42 // AndroidVideoDecodeAccelerator::BackingStrategy 44 // Must be called before anything else. If |surface_view_id| is |kNoSurfaceID|
43 gl::ScopedJavaSurface Initialize(int surface_view_id) override; 45 // then a new SurfaceTexture will be returned. Otherwise, the corresponding
44 void BeginCleanup( 46 // SurfaceView will be returned.
45 bool have_context, 47 gl::ScopedJavaSurface Initialize(AVDAStateProvider* state_provider,
46 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override; 48 int surface_view_id);
47 void EndCleanup() override; 49
48 scoped_refptr<gl::SurfaceTexture> GetSurfaceTexture() const override; 50 void Destroy(const PictureBufferMap& buffers);
49 uint32_t GetTextureTarget() const override; 51
50 gfx::Size GetPictureBufferSize() const override; 52 // Returns the GL texture target that the PictureBuffer textures use.
51 void UseCodecBufferForPictureBuffer( 53 uint32_t GetTextureTarget() const;
52 int32_t codec_buffer_index, 54
53 const PictureBuffer& picture_buffer) override; 55 // Returns the size to use when requesting picture buffers.
54 void AssignOnePictureBuffer(const PictureBuffer&, bool) override; 56 gfx::Size GetPictureBufferSize() const;
55 void ReuseOnePictureBuffer(const PictureBuffer& picture_buffer) override; 57
56 void MaybeRenderEarly() override; 58 // Sets up |picture_buffer| so that its texture will refer to the image that
57 void CodecChanged(VideoCodecBridge* codec) override; 59 // is represented by the decoded output buffer at codec_buffer_index.
58 void ReleaseCodecBuffers( 60 void UseCodecBufferForPictureBuffer(int32_t codec_buffer_index,
59 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override; 61 const PictureBuffer& picture_buffer);
60 void OnFrameAvailable() override; 62
61 bool ArePicturesOverlayable() override; 63 // Assigns a picture buffer and attaches an image to its texture.
62 void UpdatePictureBufferSize(PictureBuffer* picture_buffer, 64 void AssignOnePictureBuffer(const PictureBuffer& picture_buffer,
63 const gfx::Size& new_size) override; 65 bool have_context);
66
67 // Reuses a picture buffer to hold a new frame.
68 void ReuseOnePictureBuffer(const PictureBuffer& picture_buffer);
69
70 // Release MediaCodec buffers.
71 void ReleaseCodecBuffers(const PictureBufferMap& buffers);
72
73 // Attempts to free up codec output buffers by rendering early.
74 void MaybeRenderEarly();
75
76 // Called when the MediaCodec instance changes. If |codec| is nullptr the
77 // MediaCodec is being destroyed. Previously provided codecs should no longer
78 // be referenced.
79 void CodecChanged(VideoCodecBridge* codec);
80
81 // Whether the pictures buffers are overlayable.
82 bool ArePicturesOverlayable();
64 83
65 private: 84 private:
66 // Release any codec buffer that is associated with the given picture buffer 85 // Release any codec buffer that is associated with the given picture buffer
67 // back to the codec. It is okay if there is no such buffer. 86 // back to the codec. It is okay if there is no such buffer.
68 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer); 87 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer);
69 88
89 gpu::gles2::TextureRef* GetTextureForPicture(
90 const PictureBuffer& picture_buffer);
91
70 // Sets up the texture references (as found by |picture_buffer|), for the 92 // Sets up the texture references (as found by |picture_buffer|), for the
71 // specified |image|. If |image| is null, clears any ref on the texture 93 // specified |image|. If |image| is null, clears any ref on the texture
72 // associated with |picture_buffer|. 94 // associated with |picture_buffer|.
73 void SetImageForPicture( 95 void SetImageForPicture(
74 const PictureBuffer& picture_buffer, 96 const PictureBuffer& picture_buffer,
75 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image); 97 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image);
76 98
77 // Make a copy of the SurfaceTexture's front buffer and associate all given
78 // picture buffer textures with it. The picture buffer textures will not
79 // dependend on |this|, the SurfaceTexture, the MediaCodec or the VDA, so it's
80 // used to back the picture buffers when the VDA is being destroyed.
81 void CopySurfaceTextureToPictures(
82 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers);
83
84 // Return true if and only if CopySurfaceTextureToPictures is expected to work
85 // on this device.
86 bool ShouldCopyPictures() const;
87
88 scoped_refptr<AVDASharedState> shared_state_; 99 scoped_refptr<AVDASharedState> shared_state_;
89 100
90 AVDAStateProvider* state_provider_; 101 AVDAStateProvider* state_provider_;
91 102
92 // The SurfaceTexture to render to. Non-null after Initialize() if 103 // The SurfaceTexture to render to. Non-null after Initialize() if
93 // we're not rendering to a SurfaceView. 104 // we're not rendering to a SurfaceView.
94 scoped_refptr<gl::SurfaceTexture> surface_texture_; 105 scoped_refptr<gl::SurfaceTexture> surface_texture_;
95 106
107 class OnFrameAvailableHandler;
108 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_;
109
96 VideoCodecBridge* media_codec_; 110 VideoCodecBridge* media_codec_;
97 111
98 // Picture buffer IDs that are out for display. Stored in order of frames as 112 // Picture buffer IDs that are out for display. Stored in order of frames as
99 // they are returned from the decoder. 113 // they are returned from the decoder.
100 std::vector<int32_t> pictures_out_for_display_; 114 std::vector<int32_t> pictures_out_for_display_;
101 115
102 DISALLOW_COPY_AND_ASSIGN(AndroidDeferredRenderingBackingStrategy); 116 DISALLOW_COPY_AND_ASSIGN(AVDAPictureBufferManager);
103 }; 117 };
104 118
105 } // namespace media 119 } // namespace media
106 120
107 #endif // MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ 121 #endif // MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698