| OLD | NEW |
| (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 #ifndef MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ |
| 6 #define MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "media/gpu/avda_state_provider.h" |
| 13 #include "media/gpu/media_gpu_export.h" |
| 14 |
| 15 namespace gpu { |
| 16 namespace gles2 { |
| 17 class GLStreamTextureImage; |
| 18 } |
| 19 } |
| 20 |
| 21 namespace gl { |
| 22 class ScopedJavaSurface; |
| 23 class SurfaceTexture; |
| 24 } |
| 25 |
| 26 namespace media { |
| 27 class AVDASharedState; |
| 28 class VideoCodecBridge; |
| 29 |
| 30 // AVDAPictureBufferManager is used by AVDA to associate its PictureBuffers with |
| 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>; |
| 40 |
| 41 AVDAPictureBufferManager(); |
| 42 virtual ~AVDAPictureBufferManager(); |
| 43 |
| 44 // Must be called before anything else. If |surface_view_id| is |kNoSurfaceID| |
| 45 // then a new SurfaceTexture will be returned. Otherwise, the corresponding |
| 46 // SurfaceView will be returned. |
| 47 gl::ScopedJavaSurface Initialize(AVDAStateProvider* state_provider, |
| 48 int surface_view_id); |
| 49 |
| 50 void Destroy(const PictureBufferMap& buffers); |
| 51 |
| 52 // Returns the GL texture target that the PictureBuffer textures use. |
| 53 uint32_t GetTextureTarget() const; |
| 54 |
| 55 // Returns the size to use when requesting picture buffers. |
| 56 gfx::Size GetPictureBufferSize() const; |
| 57 |
| 58 // Sets up |picture_buffer| so that its texture will refer to the image that |
| 59 // is represented by the decoded output buffer at codec_buffer_index. |
| 60 void UseCodecBufferForPictureBuffer(int32_t codec_buffer_index, |
| 61 const PictureBuffer& picture_buffer); |
| 62 |
| 63 // Assigns a picture buffer and attaches an image to its texture. |
| 64 void AssignOnePictureBuffer(const PictureBuffer& picture_buffer, |
| 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(); |
| 83 |
| 84 private: |
| 85 // 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. |
| 87 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer); |
| 88 |
| 89 gpu::gles2::TextureRef* GetTextureForPicture( |
| 90 const PictureBuffer& picture_buffer); |
| 91 |
| 92 // 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 |
| 94 // associated with |picture_buffer|. |
| 95 void SetImageForPicture( |
| 96 const PictureBuffer& picture_buffer, |
| 97 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image); |
| 98 |
| 99 scoped_refptr<AVDASharedState> shared_state_; |
| 100 |
| 101 AVDAStateProvider* state_provider_; |
| 102 |
| 103 // The SurfaceTexture to render to. Non-null after Initialize() if |
| 104 // we're not rendering to a SurfaceView. |
| 105 scoped_refptr<gl::SurfaceTexture> surface_texture_; |
| 106 |
| 107 class OnFrameAvailableHandler; |
| 108 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; |
| 109 |
| 110 VideoCodecBridge* media_codec_; |
| 111 |
| 112 // Picture buffer IDs that are out for display. Stored in order of frames as |
| 113 // they are returned from the decoder. |
| 114 std::vector<int32_t> pictures_out_for_display_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(AVDAPictureBufferManager); |
| 117 }; |
| 118 |
| 119 } // namespace media |
| 120 |
| 121 #endif // MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_ |
| OLD | NEW |