OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_BASE_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_BASE_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" | |
19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
20 #include "media/base/android/media_codec_bridge.h" | 19 #include "media/base/android/media_codec_bridge.h" |
21 #include "media/video/video_decode_accelerator.h" | 20 #include "media/video/video_decode_accelerator.h" |
22 | 21 |
23 namespace gfx { | 22 namespace gfx { |
24 class SurfaceTexture; | 23 class SurfaceTexture; |
25 } | 24 } |
26 | 25 |
27 namespace content { | 26 namespace content { |
28 // A VideoDecodeAccelerator implementation for Android. | 27 // A base class for VideoDecodeAccelerator implementations for Android. |
29 // This class decodes the input encoded stream by using Android's MediaCodec | 28 // This class decodes the input encoded stream by using Android's MediaCodec |
30 // class. http://developer.android.com/reference/android/media/MediaCodec.html | 29 // class. http://developer.android.com/reference/android/media/MediaCodec.html |
31 class CONTENT_EXPORT AndroidVideoDecodeAccelerator | 30 // It delegates attaching pictures to PictureBuffers to the client, but |
| 31 // otherwise handles the work of transferring data to / from MediaCodec. |
| 32 class CONTENT_EXPORT AndroidVideoDecodeAcceleratorBase |
32 : public media::VideoDecodeAccelerator { | 33 : public media::VideoDecodeAccelerator { |
33 public: | 34 public: |
34 // Does not take ownership of |client| which must outlive |*this|. | 35 AndroidVideoDecodeAcceleratorBase( |
35 AndroidVideoDecodeAccelerator( | |
36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, | 36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
37 const base::Callback<bool(void)>& make_context_current); | 37 const base::Callback<bool(void)>& make_context_current); |
38 | 38 |
39 // media::VideoDecodeAccelerator implementation. | 39 // media::VideoDecodeAccelerator implementation. |
| 40 // Does not take ownership of |client| which must outlive |*this|. |
40 bool Initialize(media::VideoCodecProfile profile, Client* client) override; | 41 bool Initialize(media::VideoCodecProfile profile, Client* client) override; |
41 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 42 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
42 void AssignPictureBuffers( | 43 void AssignPictureBuffers( |
43 const std::vector<media::PictureBuffer>& buffers) override; | 44 const std::vector<media::PictureBuffer>& buffers) override; |
44 void ReusePictureBuffer(int32 picture_buffer_id) override; | 45 void ReusePictureBuffer(int32 picture_buffer_id) override; |
45 void Flush() override; | 46 void Flush() override; |
46 void Reset() override; | 47 void Reset() override; |
47 void Destroy() override; | 48 void Destroy() override; |
48 bool CanDecodeOnIOThread() override; | 49 bool CanDecodeOnIOThread() override; |
49 | 50 |
50 static media::VideoDecodeAccelerator::SupportedProfiles | 51 static media::VideoDecodeAccelerator::SupportedProfiles |
51 GetSupportedProfiles(); | 52 GetSupportedProfiles(); |
52 | 53 |
| 54 protected: |
| 55 ~AndroidVideoDecodeAcceleratorBase() override; |
| 56 |
| 57 // Return the number of picture buffers that the implementation would like. |
| 58 // TODO(liberato): this isn't used much, and can probably be removed. |
| 59 virtual uint32 GetNumPictureBuffers() const = 0; |
| 60 |
| 61 // Return the GL texture target that the PictureBuffers will use. |
| 62 virtual uint32 GetTextureTarget() const = 0; |
| 63 |
| 64 // Use the provided PictureBuffer to hold the current surface. |
| 65 virtual void AssignCurrentSurfaceToPictureBuffer(int32 codec_buffer_index, |
| 66 const media::PictureBuffer&) = 0; |
| 67 |
| 68 // Misc getters for subclasses. |
| 69 Client* GetClient() const; |
| 70 const gfx::Size& GetSize() const; |
| 71 const base::ThreadChecker& ThreadChecker() const; |
| 72 gfx::SurfaceTexture* GetSurfaceTexture() const; |
| 73 uint32 GetSurfaceTextureId() const; |
| 74 gpu::gles2::GLES2Decoder* GetGlDecoder() const; |
| 75 media::VideoCodecBridge* GetMediaCodec(); |
| 76 |
| 77 // Helper function to report an error condition. Will post NotifyError(), |
| 78 // and transition to the error state. This is meant to be called from |
| 79 // the RETURN_ON_FAILURE macro. |
| 80 void PostError(const ::tracked_objects::Location& from_here, |
| 81 media::VideoDecodeAccelerator::Error error); |
| 82 |
53 private: | 83 private: |
54 enum State { | 84 enum State { |
55 NO_ERROR, | 85 NO_ERROR, |
56 ERROR, | 86 ERROR, |
57 }; | 87 }; |
58 | 88 |
59 static const base::TimeDelta kDecodePollDelay; | 89 static const base::TimeDelta kDecodePollDelay; |
60 | 90 |
61 ~AndroidVideoDecodeAccelerator() override; | |
62 | |
63 // Configures |media_codec_| with the given codec parameters from the client. | 91 // Configures |media_codec_| with the given codec parameters from the client. |
64 bool ConfigureMediaCodec(); | 92 bool ConfigureMediaCodec(); |
65 | 93 |
66 // Sends the current picture on the surface to the client. | 94 // Sends the current picture on the surface to the client. |
67 void SendCurrentSurfaceToClient(int32 bitstream_id); | 95 void SendCurrentSurfaceToClient(int32 codec_buffer_index, int32 bitstream_id); |
68 | 96 |
69 // Does pending IO tasks if any. Once this is called, it polls |media_codec_| | 97 // 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 | 98 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is |
71 // used. | 99 // used. |
72 void DoIOTask(); | 100 void DoIOTask(); |
73 | 101 |
74 // Feeds input data to |media_codec_|. This checks | 102 // Feeds input data to |media_codec_|. This checks |
75 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. | 103 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. |
76 void QueueInput(); | 104 void QueueInput(); |
77 | 105 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 PendingBitstreamBuffers; | 178 PendingBitstreamBuffers; |
151 PendingBitstreamBuffers pending_bitstream_buffers_; | 179 PendingBitstreamBuffers pending_bitstream_buffers_; |
152 | 180 |
153 // Keeps track of bitstream ids notified to the client with | 181 // Keeps track of bitstream ids notified to the client with |
154 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. | 182 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. |
155 std::list<int32> bitstreams_notified_in_advance_; | 183 std::list<int32> bitstreams_notified_in_advance_; |
156 | 184 |
157 // Owner of the GL context. Used to restore the context state. | 185 // Owner of the GL context. Used to restore the context state. |
158 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; | 186 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; |
159 | 187 |
160 // Used for copy the texture from |surface_texture_| to picture buffers. | |
161 scoped_ptr<gpu::CopyTextureCHROMIUMResourceManager> copier_; | |
162 | |
163 // Repeating timer responsible for draining pending IO to the codec. | 188 // Repeating timer responsible for draining pending IO to the codec. |
164 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_; | 189 base::RepeatingTimer<AndroidVideoDecodeAcceleratorBase> io_timer_; |
165 | 190 |
166 // WeakPtrFactory for posting tasks back to |this|. | 191 // WeakPtrFactory for posting tasks back to |this|. |
167 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; | 192 base::WeakPtrFactory<AndroidVideoDecodeAcceleratorBase> weak_this_factory_; |
168 | 193 |
169 friend class AndroidVideoDecodeAcceleratorTest; | 194 friend class AndroidVideoDecodeAcceleratorTest; |
170 }; | 195 }; |
171 | 196 |
172 } // namespace content | 197 } // namespace content |
173 | 198 |
174 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 199 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_BASE_H_ |
OLD | NEW |