| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <queue> | 12 #include <queue> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/common/gpu/media/avda_state_provider.h" | 20 #include "content/common/gpu/media/avda_state_provider.h" |
| 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 22 #include "media/base/android/media_drm_bridge.h" | 22 #include "media/base/android/media_drm_bridge.h" |
| 23 #include "media/base/android/sdk_media_codec_bridge.h" | 23 #include "media/base/android/sdk_media_codec_bridge.h" |
| 24 #include "media/base/media_keys.h" | 24 #include "media/base/media_keys.h" |
| 25 #include "media/video/video_decode_accelerator.h" | 25 #include "media/video/video_decode_accelerator.h" |
| 26 #include "ui/gl/android/scoped_java_surface.h" |
| 26 | 27 |
| 27 namespace gfx { | 28 namespace gfx { |
| 28 class SurfaceTexture; | 29 class SurfaceTexture; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 // A VideoDecodeAccelerator implementation for Android. | 34 // A VideoDecodeAccelerator implementation for Android. |
| 34 // This class decodes the input encoded stream by using Android's MediaCodec | 35 // This class decodes the input encoded stream by using Android's MediaCodec |
| 35 // class. http://developer.android.com/reference/android/media/MediaCodec.html | 36 // class. http://developer.android.com/reference/android/media/MediaCodec.html |
| 36 // It delegates attaching pictures to PictureBuffers to a BackingStrategy, but | 37 // It delegates attaching pictures to PictureBuffers to a BackingStrategy, but |
| 37 // otherwise handles the work of transferring data to / from MediaCodec. | 38 // otherwise handles the work of transferring data to / from MediaCodec. |
| 38 class CONTENT_EXPORT AndroidVideoDecodeAccelerator | 39 class CONTENT_EXPORT AndroidVideoDecodeAccelerator |
| 39 : public media::VideoDecodeAccelerator, | 40 : public media::VideoDecodeAccelerator, |
| 40 public AVDAStateProvider { | 41 public AVDAStateProvider { |
| 41 public: | 42 public: |
| 42 typedef std::map<int32_t, media::PictureBuffer> OutputBufferMap; | 43 typedef std::map<int32_t, media::PictureBuffer> OutputBufferMap; |
| 43 | 44 |
| 44 // A BackingStrategy is responsible for making a PictureBuffer's texture | 45 // A BackingStrategy is responsible for making a PictureBuffer's texture |
| 45 // contain the image that a MediaCodec decoder buffer tells it to. | 46 // contain the image that a MediaCodec decoder buffer tells it to. |
| 46 class BackingStrategy { | 47 class BackingStrategy { |
| 47 public: | 48 public: |
| 48 virtual ~BackingStrategy() {} | 49 virtual ~BackingStrategy() {} |
| 49 | 50 |
| 50 // Called after the state provider is given, but before any other | 51 // Must be called before anything else. If surface_view_id is not equal to |
| 51 // calls to the BackingStrategy. | 52 // |kNoSurfaceID| it refers to a SurfaceView that the strategy must render |
| 52 virtual void Initialize(AVDAStateProvider* provider) = 0; | 53 // to. |
| 54 // Returns the Java surface to configure MediaCodec with. |
| 55 virtual gfx::ScopedJavaSurface Initialize(int surface_view_id) = 0; |
| 53 | 56 |
| 54 // Called before the AVDA does any Destroy() work. This will be | 57 // Called before the AVDA does any Destroy() work. This will be |
| 55 // the last call that the BackingStrategy receives. | 58 // the last call that the BackingStrategy receives. |
| 56 virtual void Cleanup(bool have_context, | 59 virtual void Cleanup(bool have_context, |
| 57 const OutputBufferMap& buffer_map) = 0; | 60 const OutputBufferMap& buffer_map) = 0; |
| 58 | 61 |
| 62 // This returns the SurfaceTexture created by Initialize, or nullptr if |
| 63 // the strategy was initialized with a SurfaceView. |
| 64 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture() const = 0; |
| 65 |
| 59 // Return the GL texture target that the PictureBuffer textures use. | 66 // Return the GL texture target that the PictureBuffer textures use. |
| 60 virtual uint32_t GetTextureTarget() const = 0; | 67 virtual uint32_t GetTextureTarget() const = 0; |
| 61 | 68 |
| 62 // Create and return a surface texture for the MediaCodec to use. | |
| 63 virtual scoped_refptr<gfx::SurfaceTexture> CreateSurfaceTexture() = 0; | |
| 64 | |
| 65 // Make the provided PictureBuffer draw the image that is represented by | 69 // Make the provided PictureBuffer draw the image that is represented by |
| 66 // the decoded output buffer at codec_buffer_index. | 70 // the decoded output buffer at codec_buffer_index. |
| 67 virtual void UseCodecBufferForPictureBuffer( | 71 virtual void UseCodecBufferForPictureBuffer( |
| 68 int32_t codec_buffer_index, | 72 int32_t codec_buffer_index, |
| 69 const media::PictureBuffer& picture_buffer) = 0; | 73 const media::PictureBuffer& picture_buffer) = 0; |
| 70 | 74 |
| 71 // Notify strategy that a picture buffer has been assigned. | 75 // Notify strategy that a picture buffer has been assigned. |
| 72 virtual void AssignOnePictureBuffer( | 76 virtual void AssignOnePictureBuffer( |
| 73 const media::PictureBuffer& picture_buffer) {} | 77 const media::PictureBuffer& picture_buffer) {} |
| 74 | 78 |
| 75 // Notify strategy that a picture buffer has been reused. | 79 // Notify strategy that a picture buffer has been reused. |
| 76 virtual void ReuseOnePictureBuffer( | 80 virtual void ReuseOnePictureBuffer( |
| 77 const media::PictureBuffer& picture_buffer) {} | 81 const media::PictureBuffer& picture_buffer) {} |
| 78 | 82 |
| 79 // Notify strategy that we are about to dismiss a picture buffer. | 83 // Notify strategy that we are about to dismiss a picture buffer. |
| 80 virtual void DismissOnePictureBuffer( | 84 virtual void DismissOnePictureBuffer( |
| 81 const media::PictureBuffer& picture_buffer) {} | 85 const media::PictureBuffer& picture_buffer) {} |
| 82 | 86 |
| 83 // Notify strategy that we have a new android MediaCodec instance. This | 87 // Notify strategy that we have a new android MediaCodec instance. This |
| 84 // happens when we're starting up or re-configuring mid-stream. Any | 88 // happens when we're starting up or re-configuring mid-stream. Any |
| 85 // previously provided codec should no longer be referenced. | 89 // previously provided codec should no longer be referenced. |
| 86 // For convenience, a container of PictureBuffers is provided in case | 90 // For convenience, a container of PictureBuffers is provided in case |
| 87 // per-image cleanup is needed. | 91 // per-image cleanup is needed. |
| 88 virtual void CodecChanged(media::VideoCodecBridge* codec, | 92 virtual void CodecChanged(media::VideoCodecBridge* codec, |
| 89 const OutputBufferMap& buffer_map) = 0; | 93 const OutputBufferMap& buffer_map) = 0; |
| 90 | 94 |
| 91 // Notify the strategy that a frame is available. This callback can happen | 95 // Notify the strategy that a frame is available. This callback can happen |
| 92 // on any thread at any time. | 96 // on any thread at any time. |
| 93 virtual void OnFrameAvailable() = 0; | 97 virtual void OnFrameAvailable() = 0; |
| 98 |
| 99 // Whether the pictures produced by this backing strategy are overlayable. |
| 100 virtual bool ArePicturesOverlayable() = 0; |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 AndroidVideoDecodeAccelerator( | 103 AndroidVideoDecodeAccelerator( |
| 97 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, | 104 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
| 98 const base::Callback<bool(void)>& make_context_current); | 105 const base::Callback<bool(void)>& make_context_current); |
| 99 | 106 |
| 100 ~AndroidVideoDecodeAccelerator() override; | 107 ~AndroidVideoDecodeAccelerator() override; |
| 101 | 108 |
| 102 // media::VideoDecodeAccelerator implementation: | 109 // media::VideoDecodeAccelerator implementation: |
| 103 bool Initialize(const Config& config, Client* client) override; | 110 bool Initialize(const Config& config, Client* client) override; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 std::queue<int32_t> free_picture_ids_; | 246 std::queue<int32_t> free_picture_ids_; |
| 240 | 247 |
| 241 // Picture buffer ids which have been dismissed and not yet re-assigned. Used | 248 // Picture buffer ids which have been dismissed and not yet re-assigned. Used |
| 242 // to ignore ReusePictureBuffer calls that were in flight when the | 249 // to ignore ReusePictureBuffer calls that were in flight when the |
| 243 // DismissPictureBuffer call was made. | 250 // DismissPictureBuffer call was made. |
| 244 std::set<int32_t> dismissed_picture_ids_; | 251 std::set<int32_t> dismissed_picture_ids_; |
| 245 | 252 |
| 246 // The low-level decoder which Android SDK provides. | 253 // The low-level decoder which Android SDK provides. |
| 247 scoped_ptr<media::VideoCodecBridge> media_codec_; | 254 scoped_ptr<media::VideoCodecBridge> media_codec_; |
| 248 | 255 |
| 249 // A container of texture. Used to set a texture to |media_codec_|. | 256 // The surface that MediaCodec is configured to output to. It's created by the |
| 250 scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 257 // backing strategy. |
| 258 gfx::ScopedJavaSurface surface_; |
| 251 | 259 |
| 252 // Set to true after requesting picture buffers to the client. | 260 // Set to true after requesting picture buffers to the client. |
| 253 bool picturebuffers_requested_; | 261 bool picturebuffers_requested_; |
| 254 | 262 |
| 255 // The resolution of the stream. | 263 // The resolution of the stream. |
| 256 gfx::Size size_; | 264 gfx::Size size_; |
| 257 | 265 |
| 258 // Encoded bitstream buffers to be passed to media codec, queued until an | 266 // Encoded bitstream buffers to be passed to media codec, queued until an |
| 259 // input buffer is available, along with the time when they were first | 267 // input buffer is available, along with the time when they were first |
| 260 // enqueued. | 268 // enqueued. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 322 |
| 315 // WeakPtrFactory for posting tasks back to |this|. | 323 // WeakPtrFactory for posting tasks back to |this|. |
| 316 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; | 324 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; |
| 317 | 325 |
| 318 friend class AndroidVideoDecodeAcceleratorTest; | 326 friend class AndroidVideoDecodeAcceleratorTest; |
| 319 }; | 327 }; |
| 320 | 328 |
| 321 } // namespace content | 329 } // namespace content |
| 322 | 330 |
| 323 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 331 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |