OLD | NEW |
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_AVDA_PICTURE_BUFFER_MANAGER_H_ | 5 #ifndef MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ |
6 #define MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_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/avda_state_provider.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 gpu { | 15 namespace gpu { |
16 namespace gles2 { | 16 namespace gles2 { |
17 class GLStreamTextureImage; | 17 class GLStreamTextureImage; |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 namespace gl { | 21 namespace gl { |
22 class ScopedJavaSurface; | 22 class ScopedJavaSurface; |
23 class SurfaceTexture; | 23 class SurfaceTexture; |
24 } | 24 } |
25 | 25 |
26 namespace media { | 26 namespace media { |
| 27 class AVDACodecImage; |
27 class AVDASharedState; | 28 class AVDASharedState; |
28 class VideoCodecBridge; | 29 class VideoCodecBridge; |
29 | 30 |
30 // AVDAPictureBufferManager is used by AVDA to associate its PictureBuffers with | 31 // AVDAPictureBufferManager is used by AVDA to associate its PictureBuffers with |
31 // MediaCodec output buffers. It attaches AVDACodecImages to the PictureBuffer | 32 // 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 // 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 // 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 // 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 // If the Surface is a SurfaceView, the release causes the frame to be displayed |
36 // immediately. | 37 // immediately. |
37 class MEDIA_GPU_EXPORT AVDAPictureBufferManager { | 38 class MEDIA_GPU_EXPORT AVDAPictureBufferManager { |
38 public: | 39 public: |
39 using PictureBufferMap = std::map<int32_t, PictureBuffer>; | 40 using PictureBufferMap = std::map<int32_t, PictureBuffer>; |
40 | 41 |
41 AVDAPictureBufferManager(); | 42 AVDAPictureBufferManager(AVDAStateProvider* state_provider); |
42 virtual ~AVDAPictureBufferManager(); | 43 virtual ~AVDAPictureBufferManager(); |
43 | 44 |
44 // Must be called before anything else. If |surface_view_id| is |kNoSurfaceID| | 45 // Must be called before anything else. If |surface_id| is |kNoSurfaceID| |
45 // then a new SurfaceTexture will be returned. Otherwise, the corresponding | 46 // then a new SurfaceTexture will be returned. Otherwise, the corresponding |
46 // SurfaceView will be returned. | 47 // SurfaceView will be returned. |
47 gl::ScopedJavaSurface Initialize(AVDAStateProvider* state_provider, | 48 gl::ScopedJavaSurface Initialize(int surface_id); |
48 int surface_view_id); | |
49 | 49 |
50 void Destroy(const PictureBufferMap& buffers); | 50 void Destroy(const PictureBufferMap& buffers); |
51 | 51 |
52 // Returns the GL texture target that the PictureBuffer textures use. | 52 // Returns the GL texture target that the PictureBuffer textures use. |
53 uint32_t GetTextureTarget() const; | 53 uint32_t GetTextureTarget() const; |
54 | 54 |
55 // Returns the size to use when requesting picture buffers. | 55 // Returns the size to use when requesting picture buffers. |
56 gfx::Size GetPictureBufferSize() const; | 56 gfx::Size GetPictureBufferSize() const; |
57 | 57 |
58 // Sets up |picture_buffer| so that its texture will refer to the image that | 58 // Sets up |picture_buffer| so that its texture will refer to the image that |
(...skipping 15 matching lines...) Expand all Loading... |
74 void MaybeRenderEarly(); | 74 void MaybeRenderEarly(); |
75 | 75 |
76 // Called when the MediaCodec instance changes. If |codec| is nullptr the | 76 // Called when the MediaCodec instance changes. If |codec| is nullptr the |
77 // MediaCodec is being destroyed. Previously provided codecs should no longer | 77 // MediaCodec is being destroyed. Previously provided codecs should no longer |
78 // be referenced. | 78 // be referenced. |
79 void CodecChanged(VideoCodecBridge* codec); | 79 void CodecChanged(VideoCodecBridge* codec); |
80 | 80 |
81 // Whether the pictures buffers are overlayable. | 81 // Whether the pictures buffers are overlayable. |
82 bool ArePicturesOverlayable(); | 82 bool ArePicturesOverlayable(); |
83 | 83 |
| 84 // Are there any unrendered picture buffers oustanding? |
| 85 bool ArePicturesOutstanding() const; |
| 86 |
84 private: | 87 private: |
85 // Release any codec buffer that is associated with the given picture buffer | 88 // Release any codec buffer that is associated with the given picture buffer |
86 // back to the codec. It is okay if there is no such buffer. | 89 // back to the codec. It is okay if there is no such buffer. |
87 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer); | 90 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer); |
88 | 91 |
89 gpu::gles2::TextureRef* GetTextureForPicture( | 92 gpu::gles2::TextureRef* GetTextureForPicture( |
90 const PictureBuffer& picture_buffer); | 93 const PictureBuffer& picture_buffer); |
91 | 94 |
92 // Sets up the texture references (as found by |picture_buffer|), for the | 95 // Sets up the texture references (as found by |picture_buffer|), for the |
93 // specified |image|. If |image| is null, clears any ref on the texture | 96 // specified |image|. If |image| is null, clears any ref on the texture |
94 // associated with |picture_buffer|. | 97 // associated with |picture_buffer|. |
95 void SetImageForPicture( | 98 void SetImageForPicture(const PictureBuffer& picture_buffer, |
96 const PictureBuffer& picture_buffer, | 99 gpu::gles2::GLStreamTextureImage* image); |
97 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image); | 100 |
| 101 AVDACodecImage* GetImageForPicture(int picture_buffer_id) const; |
98 | 102 |
99 scoped_refptr<AVDASharedState> shared_state_; | 103 scoped_refptr<AVDASharedState> shared_state_; |
100 | 104 |
101 AVDAStateProvider* state_provider_; | 105 AVDAStateProvider* const state_provider_; |
102 | 106 |
103 // The SurfaceTexture to render to. Non-null after Initialize() if | 107 // The SurfaceTexture to render to. Non-null after Initialize() if |
104 // we're not rendering to a SurfaceView. | 108 // we're not rendering to a SurfaceView. |
105 scoped_refptr<gl::SurfaceTexture> surface_texture_; | 109 scoped_refptr<gl::SurfaceTexture> surface_texture_; |
106 | 110 |
107 class OnFrameAvailableHandler; | |
108 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; | |
109 | |
110 VideoCodecBridge* media_codec_; | 111 VideoCodecBridge* media_codec_; |
111 | 112 |
112 // Picture buffer IDs that are out for display. Stored in order of frames as | 113 // Picture buffer IDs that are out for display. Stored in order of frames as |
113 // they are returned from the decoder. | 114 // they are returned from the decoder. |
114 std::vector<int32_t> pictures_out_for_display_; | 115 std::vector<int32_t> pictures_out_for_display_; |
115 | 116 |
| 117 // Maps a picture buffer id to a AVDACodecImage. |
| 118 std::map<int, AVDACodecImage*> codec_images_; |
| 119 |
116 DISALLOW_COPY_AND_ASSIGN(AVDAPictureBufferManager); | 120 DISALLOW_COPY_AND_ASSIGN(AVDAPictureBufferManager); |
117 }; | 121 }; |
118 | 122 |
119 } // namespace media | 123 } // namespace media |
120 | 124 |
121 #endif // MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ | 125 #endif // MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ |
OLD | NEW |