| Index: media/gpu/avda_picture_buffer_manager.h
|
| diff --git a/media/gpu/android_deferred_rendering_backing_strategy.h b/media/gpu/avda_picture_buffer_manager.h
|
| similarity index 35%
|
| rename from media/gpu/android_deferred_rendering_backing_strategy.h
|
| rename to media/gpu/avda_picture_buffer_manager.h
|
| index 948ff952285db7c6b7f93528b71af0c7f5718be8..3c156fd30df4a219fd72eb9cc56ddb3918ac20cc 100644
|
| --- a/media/gpu/android_deferred_rendering_backing_strategy.h
|
| +++ b/media/gpu/avda_picture_buffer_manager.h
|
| @@ -2,71 +2,93 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_
|
| -#define MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_
|
| +#ifndef MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
|
| +#define MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
|
|
|
| #include <stdint.h>
|
| #include <vector>
|
|
|
| #include "base/macros.h"
|
| -#include "media/gpu/android_video_decode_accelerator.h"
|
| +#include "media/gpu/avda_state_provider.h"
|
| #include "media/gpu/media_gpu_export.h"
|
|
|
| -namespace gl {
|
| -class GLImage;
|
| -}
|
| -
|
| namespace gpu {
|
| namespace gles2 {
|
| class GLStreamTextureImage;
|
| -class TextureRef;
|
| }
|
| }
|
|
|
| +namespace gl {
|
| +class ScopedJavaSurface;
|
| +class SurfaceTexture;
|
| +}
|
| +
|
| namespace media {
|
| -
|
| -class AVDACodecImage;
|
| class AVDASharedState;
|
| +class VideoCodecBridge;
|
|
|
| -// A BackingStrategy implementation that defers releasing codec buffers until
|
| -// a PictureBuffer's texture is used to draw, then draws using the surface
|
| -// texture's front buffer rather than a copy. To do this, it uses a GLImage
|
| -// implementation to talk to MediaCodec.
|
| -class MEDIA_GPU_EXPORT AndroidDeferredRenderingBackingStrategy
|
| - : public AndroidVideoDecodeAccelerator::BackingStrategy {
|
| +// AVDAPictureBufferManager is used by AVDA to associate its PictureBuffers with
|
| +// MediaCodec output buffers. It attaches AVDACodecImages to the PictureBuffer
|
| +// textures so that when they're used to draw the AVDACodecImage can release the
|
| +// MediaCodec buffer to the backing Surface. If the Surface is a SurfaceTexture,
|
| +// the front buffer can then be used to draw without needing to copy the pixels.
|
| +// If the Surface is a SurfaceView, the release causes the frame to be displayed
|
| +// immediately.
|
| +class MEDIA_GPU_EXPORT AVDAPictureBufferManager {
|
| public:
|
| - explicit AndroidDeferredRenderingBackingStrategy(
|
| - AVDAStateProvider* state_provider);
|
| - ~AndroidDeferredRenderingBackingStrategy() override;
|
| -
|
| - // AndroidVideoDecodeAccelerator::BackingStrategy
|
| - gl::ScopedJavaSurface Initialize(int surface_view_id) override;
|
| - void BeginCleanup(
|
| - bool have_context,
|
| - const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override;
|
| - void EndCleanup() override;
|
| - scoped_refptr<gl::SurfaceTexture> GetSurfaceTexture() const override;
|
| - uint32_t GetTextureTarget() const override;
|
| - gfx::Size GetPictureBufferSize() const override;
|
| - void UseCodecBufferForPictureBuffer(
|
| - int32_t codec_buffer_index,
|
| - const PictureBuffer& picture_buffer) override;
|
| - void AssignOnePictureBuffer(const PictureBuffer&, bool) override;
|
| - void ReuseOnePictureBuffer(const PictureBuffer& picture_buffer) override;
|
| - void MaybeRenderEarly() override;
|
| - void CodecChanged(VideoCodecBridge* codec) override;
|
| - void ReleaseCodecBuffers(
|
| - const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override;
|
| - void OnFrameAvailable() override;
|
| - bool ArePicturesOverlayable() override;
|
| - void UpdatePictureBufferSize(PictureBuffer* picture_buffer,
|
| - const gfx::Size& new_size) override;
|
| + using PictureBufferMap = std::map<int32_t, PictureBuffer>;
|
| +
|
| + AVDAPictureBufferManager();
|
| + virtual ~AVDAPictureBufferManager();
|
| +
|
| + // Must be called before anything else. If |surface_view_id| is |kNoSurfaceID|
|
| + // then a new SurfaceTexture will be returned. Otherwise, the corresponding
|
| + // SurfaceView will be returned.
|
| + gl::ScopedJavaSurface Initialize(AVDAStateProvider* state_provider,
|
| + int surface_view_id);
|
| +
|
| + void Destroy(const PictureBufferMap& buffers);
|
| +
|
| + // Returns the GL texture target that the PictureBuffer textures use.
|
| + uint32_t GetTextureTarget() const;
|
| +
|
| + // Returns the size to use when requesting picture buffers.
|
| + gfx::Size GetPictureBufferSize() const;
|
| +
|
| + // Sets up |picture_buffer| so that its texture will refer to the image that
|
| + // is represented by the decoded output buffer at codec_buffer_index.
|
| + void UseCodecBufferForPictureBuffer(int32_t codec_buffer_index,
|
| + const PictureBuffer& picture_buffer);
|
| +
|
| + // Assigns a picture buffer and attaches an image to its texture.
|
| + void AssignOnePictureBuffer(const PictureBuffer& picture_buffer,
|
| + bool have_context);
|
| +
|
| + // Reuses a picture buffer to hold a new frame.
|
| + void ReuseOnePictureBuffer(const PictureBuffer& picture_buffer);
|
| +
|
| + // Release MediaCodec buffers.
|
| + void ReleaseCodecBuffers(const PictureBufferMap& buffers);
|
| +
|
| + // Attempts to free up codec output buffers by rendering early.
|
| + void MaybeRenderEarly();
|
| +
|
| + // Called when the MediaCodec instance changes. If |codec| is nullptr the
|
| + // MediaCodec is being destroyed. Previously provided codecs should no longer
|
| + // be referenced.
|
| + void CodecChanged(VideoCodecBridge* codec);
|
| +
|
| + // Whether the pictures buffers are overlayable.
|
| + bool ArePicturesOverlayable();
|
|
|
| private:
|
| // Release any codec buffer that is associated with the given picture buffer
|
| // back to the codec. It is okay if there is no such buffer.
|
| void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer);
|
|
|
| + gpu::gles2::TextureRef* GetTextureForPicture(
|
| + const PictureBuffer& picture_buffer);
|
| +
|
| // Sets up the texture references (as found by |picture_buffer|), for the
|
| // specified |image|. If |image| is null, clears any ref on the texture
|
| // associated with |picture_buffer|.
|
| @@ -74,17 +96,6 @@ class MEDIA_GPU_EXPORT AndroidDeferredRenderingBackingStrategy
|
| const PictureBuffer& picture_buffer,
|
| const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image);
|
|
|
| - // Make a copy of the SurfaceTexture's front buffer and associate all given
|
| - // picture buffer textures with it. The picture buffer textures will not
|
| - // dependend on |this|, the SurfaceTexture, the MediaCodec or the VDA, so it's
|
| - // used to back the picture buffers when the VDA is being destroyed.
|
| - void CopySurfaceTextureToPictures(
|
| - const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers);
|
| -
|
| - // Return true if and only if CopySurfaceTextureToPictures is expected to work
|
| - // on this device.
|
| - bool ShouldCopyPictures() const;
|
| -
|
| scoped_refptr<AVDASharedState> shared_state_;
|
|
|
| AVDAStateProvider* state_provider_;
|
| @@ -93,15 +104,18 @@ class MEDIA_GPU_EXPORT AndroidDeferredRenderingBackingStrategy
|
| // we're not rendering to a SurfaceView.
|
| scoped_refptr<gl::SurfaceTexture> surface_texture_;
|
|
|
| + class OnFrameAvailableHandler;
|
| + scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_;
|
| +
|
| VideoCodecBridge* media_codec_;
|
|
|
| // Picture buffer IDs that are out for display. Stored in order of frames as
|
| // they are returned from the decoder.
|
| std::vector<int32_t> pictures_out_for_display_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(AndroidDeferredRenderingBackingStrategy);
|
| + DISALLOW_COPY_AND_ASSIGN(AVDAPictureBufferManager);
|
| };
|
|
|
| } // namespace media
|
|
|
| -#endif // MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_
|
| +#endif // MEDIA_GPU_AVDA_PICTURE_BUFFER_MANAGER_H_
|
|
|