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 <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 18 #include "content/common/gpu/media/android_video_decode_accelerator_state_provid
er.h" |
19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
20 #include "media/base/android/media_codec_bridge.h" | 20 #include "media/base/android/media_codec_bridge.h" |
21 #include "media/video/video_decode_accelerator.h" | 21 #include "media/video/video_decode_accelerator.h" |
22 | 22 |
23 namespace gfx { | 23 namespace gfx { |
24 class SurfaceTexture; | 24 class SurfaceTexture; |
25 } | 25 } |
26 | 26 |
27 namespace content { | 27 namespace content { |
| 28 |
28 // A VideoDecodeAccelerator implementation for Android. | 29 // A VideoDecodeAccelerator implementation for Android. |
29 // This class decodes the input encoded stream by using Android's MediaCodec | 30 // This class decodes the input encoded stream by using Android's MediaCodec |
30 // class. http://developer.android.com/reference/android/media/MediaCodec.html | 31 // class. http://developer.android.com/reference/android/media/MediaCodec.html |
| 32 // It delegates attaching pictures to PictureBuffers to a BackingStrategy, but |
| 33 // otherwise handles the work of transferring data to / from MediaCodec. |
31 class CONTENT_EXPORT AndroidVideoDecodeAccelerator | 34 class CONTENT_EXPORT AndroidVideoDecodeAccelerator |
32 : public media::VideoDecodeAccelerator { | 35 : public media::VideoDecodeAccelerator, |
| 36 public AndroidVideoDecodeAcceleratorStateProvider { |
33 public: | 37 public: |
34 // Does not take ownership of |client| which must outlive |*this|. | 38 // A BackingStrategy is responsible for making a PictureBuffer's texture |
| 39 // contain the image that a MediaCodec decoder buffer tells it to. |
| 40 class BackingStrategy { |
| 41 public: |
| 42 virtual ~BackingStrategy() {} |
| 43 |
| 44 // Notify about the state provider. |
| 45 virtual void SetStateProvider( |
| 46 AndroidVideoDecodeAcceleratorStateProvider*) = 0; |
| 47 |
| 48 // Called before the AVDA does any Destroy() work. This will be |
| 49 // the last call that the BackingStrategy receives. |
| 50 virtual void Cleanup() = 0; |
| 51 |
| 52 // Return the number of picture buffers that we can support. |
| 53 virtual uint32 GetNumPictureBuffers() const = 0; |
| 54 |
| 55 // Return the GL texture target that the PictureBuffer textures use. |
| 56 virtual uint32 GetTextureTarget() const = 0; |
| 57 |
| 58 // Use the provided PictureBuffer to hold the current surface. |
| 59 virtual void AssignCurrentSurfaceToPictureBuffer( |
| 60 int32 codec_buffer_index, |
| 61 const media::PictureBuffer&) = 0; |
| 62 }; |
| 63 |
35 AndroidVideoDecodeAccelerator( | 64 AndroidVideoDecodeAccelerator( |
36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, | 65 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
37 const base::Callback<bool(void)>& make_context_current); | 66 const base::Callback<bool(void)>& make_context_current, |
| 67 scoped_ptr<BackingStrategy> strategy); |
38 | 68 |
39 // media::VideoDecodeAccelerator implementation. | 69 ~AndroidVideoDecodeAccelerator() override; |
| 70 |
| 71 // Does not take ownership of |client| which must outlive |*this|. |
40 bool Initialize(media::VideoCodecProfile profile, Client* client) override; | 72 bool Initialize(media::VideoCodecProfile profile, Client* client) override; |
41 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 73 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
42 void AssignPictureBuffers( | 74 void AssignPictureBuffers( |
43 const std::vector<media::PictureBuffer>& buffers) override; | 75 const std::vector<media::PictureBuffer>& buffers) override; |
44 void ReusePictureBuffer(int32 picture_buffer_id) override; | 76 void ReusePictureBuffer(int32 picture_buffer_id) override; |
45 void Flush() override; | 77 void Flush() override; |
46 void Reset() override; | 78 void Reset() override; |
47 void Destroy() override; | 79 void Destroy() override; |
48 bool CanDecodeOnIOThread() override; | 80 bool CanDecodeOnIOThread() override; |
49 | 81 |
| 82 // AndroidVideoDecodeStateProvider |
| 83 const gfx::Size& GetSize() const override; |
| 84 const base::ThreadChecker& ThreadChecker() const override; |
| 85 gfx::SurfaceTexture* GetSurfaceTexture() const override; |
| 86 uint32 GetSurfaceTextureId() const override; |
| 87 gpu::gles2::GLES2Decoder* GetGlDecoder() const override; |
| 88 media::VideoCodecBridge* GetMediaCodec() override; |
| 89 void PostError(const ::tracked_objects::Location& from_here, |
| 90 media::VideoDecodeAccelerator::Error error) override; |
| 91 |
50 static media::VideoDecodeAccelerator::SupportedProfiles | 92 static media::VideoDecodeAccelerator::SupportedProfiles |
51 GetSupportedProfiles(); | 93 GetSupportedProfiles(); |
52 | 94 |
53 private: | 95 private: |
54 enum State { | 96 enum State { |
55 NO_ERROR, | 97 NO_ERROR, |
56 ERROR, | 98 ERROR, |
57 }; | 99 }; |
58 | 100 |
59 static const base::TimeDelta kDecodePollDelay; | 101 static const base::TimeDelta kDecodePollDelay; |
60 | 102 |
61 ~AndroidVideoDecodeAccelerator() override; | |
62 | |
63 // Configures |media_codec_| with the given codec parameters from the client. | 103 // Configures |media_codec_| with the given codec parameters from the client. |
64 bool ConfigureMediaCodec(); | 104 bool ConfigureMediaCodec(); |
65 | 105 |
66 // Sends the current picture on the surface to the client. | 106 // Sends the current picture on the surface to the client. |
67 void SendCurrentSurfaceToClient(int32 bitstream_id); | 107 void SendCurrentSurfaceToClient(int32 codec_buffer_index, int32 bitstream_id); |
68 | 108 |
69 // Does pending IO tasks if any. Once this is called, it polls |media_codec_| | 109 // Does pending IO tasks if any. Once this is called, it polls |media_codec_| |
70 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is | 110 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is |
71 // used. | 111 // used. |
72 void DoIOTask(); | 112 void DoIOTask(); |
73 | 113 |
74 // Feeds input data to |media_codec_|. This checks | 114 // Feeds input data to |media_codec_|. This checks |
75 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. | 115 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. |
76 void QueueInput(); | 116 void QueueInput(); |
77 | 117 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // for multiple bitstream buffers that have the same presentation timestamp. | 196 // for multiple bitstream buffers that have the same presentation timestamp. |
157 std::map<base::TimeDelta, int32> bitstream_buffers_in_decoder_; | 197 std::map<base::TimeDelta, int32> bitstream_buffers_in_decoder_; |
158 | 198 |
159 // Keeps track of bitstream ids notified to the client with | 199 // Keeps track of bitstream ids notified to the client with |
160 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. | 200 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. |
161 std::list<int32> bitstreams_notified_in_advance_; | 201 std::list<int32> bitstreams_notified_in_advance_; |
162 | 202 |
163 // Owner of the GL context. Used to restore the context state. | 203 // Owner of the GL context. Used to restore the context state. |
164 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; | 204 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; |
165 | 205 |
166 // Used for copy the texture from |surface_texture_| to picture buffers. | |
167 scoped_ptr<gpu::CopyTextureCHROMIUMResourceManager> copier_; | |
168 | |
169 // Repeating timer responsible for draining pending IO to the codec. | 206 // Repeating timer responsible for draining pending IO to the codec. |
170 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_; | 207 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_; |
171 | 208 |
| 209 // Backing strategy that we'll use to connect PictureBuffers to frames. |
| 210 scoped_ptr<BackingStrategy> strategy_; |
| 211 |
172 // WeakPtrFactory for posting tasks back to |this|. | 212 // WeakPtrFactory for posting tasks back to |this|. |
173 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; | 213 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; |
174 | 214 |
175 friend class AndroidVideoDecodeAcceleratorTest; | 215 friend class AndroidVideoDecodeAcceleratorTest; |
176 }; | 216 }; |
177 | 217 |
178 } // namespace content | 218 } // namespace content |
179 | 219 |
180 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 220 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |