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

Side by Side Diff: content/common/gpu/media/android_video_decode_accelerator.h

Issue 1639963002: AndroidVideoDecodeAccelerator can now render to a SurfaceView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Frank's suggestion Created 4 years, 11 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 (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 to render to.
liberato (no reviews please) 2016/01/27 16:15:33 please make a note that it is required to use the
52 virtual void Initialize(AVDAStateProvider* provider) = 0; 53 // Returns the Java surface to configure MediaCodec with.
54 virtual gfx::ScopedJavaSurface Initialize(AVDAStateProvider* provider,
55 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 virtual bool PicturesAreOverlayable() { return false; }
94 }; 100 };
95 101
96 AndroidVideoDecodeAccelerator( 102 AndroidVideoDecodeAccelerator(
97 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, 103 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder,
98 const base::Callback<bool(void)>& make_context_current); 104 const base::Callback<bool(void)>& make_context_current);
99 105
100 ~AndroidVideoDecodeAccelerator() override; 106 ~AndroidVideoDecodeAccelerator() override;
101 107
102 // media::VideoDecodeAccelerator implementation: 108 // media::VideoDecodeAccelerator implementation:
103 bool Initialize(const Config& config, Client* client) override; 109 bool Initialize(const Config& config, Client* client) override;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 std::queue<int32_t> free_picture_ids_; 240 std::queue<int32_t> free_picture_ids_;
235 241
236 // Picture buffer ids which have been dismissed and not yet re-assigned. Used 242 // Picture buffer ids which have been dismissed and not yet re-assigned. Used
237 // to ignore ReusePictureBuffer calls that were in flight when the 243 // to ignore ReusePictureBuffer calls that were in flight when the
238 // DismissPictureBuffer call was made. 244 // DismissPictureBuffer call was made.
239 std::set<int32_t> dismissed_picture_ids_; 245 std::set<int32_t> dismissed_picture_ids_;
240 246
241 // The low-level decoder which Android SDK provides. 247 // The low-level decoder which Android SDK provides.
242 scoped_ptr<media::VideoCodecBridge> media_codec_; 248 scoped_ptr<media::VideoCodecBridge> media_codec_;
243 249
244 // A container of texture. Used to set a texture to |media_codec_|. 250 // The surface that MediaCodec is configured to output to. It's created by the
245 scoped_refptr<gfx::SurfaceTexture> surface_texture_; 251 // backing strategy.
252 gfx::ScopedJavaSurface surface_;
246 253
247 // Set to true after requesting picture buffers to the client. 254 // Set to true after requesting picture buffers to the client.
248 bool picturebuffers_requested_; 255 bool picturebuffers_requested_;
249 256
250 // The resolution of the stream. 257 // The resolution of the stream.
251 gfx::Size size_; 258 gfx::Size size_;
252 259
253 // Encoded bitstream buffers to be passed to media codec, queued until an 260 // Encoded bitstream buffers to be passed to media codec, queued until an
254 // input buffer is available, along with the time when they were first 261 // input buffer is available, along with the time when they were first
255 // enqueued. 262 // enqueued.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 309
303 // WeakPtrFactory for posting tasks back to |this|. 310 // WeakPtrFactory for posting tasks back to |this|.
304 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; 311 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_;
305 312
306 friend class AndroidVideoDecodeAcceleratorTest; 313 friend class AndroidVideoDecodeAcceleratorTest;
307 }; 314 };
308 315
309 } // namespace content 316 } // namespace content
310 317
311 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ 318 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698