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

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

Issue 1313913003: Begin refactor of AVDA to support zero-copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed unit test. Created 5 years, 3 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) 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_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(int32 codec_buffer_index,
60 const media::PictureBuffer&) = 0;
61 };
62
35 AndroidVideoDecodeAccelerator( 63 AndroidVideoDecodeAccelerator(
36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, 64 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder,
37 const base::Callback<bool(void)>& make_context_current); 65 const base::Callback<bool(void)>& make_context_current,
66 scoped_ptr<BackingStrategy> strategy);
38 67
39 // media::VideoDecodeAccelerator implementation. 68 ~AndroidVideoDecodeAccelerator() override;
69
70 // Does not take ownership of |client| which must outlive |*this|.
40 bool Initialize(media::VideoCodecProfile profile, Client* client) override; 71 bool Initialize(media::VideoCodecProfile profile, Client* client) override;
41 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; 72 void Decode(const media::BitstreamBuffer& bitstream_buffer) override;
42 void AssignPictureBuffers( 73 void AssignPictureBuffers(
43 const std::vector<media::PictureBuffer>& buffers) override; 74 const std::vector<media::PictureBuffer>& buffers) override;
44 void ReusePictureBuffer(int32 picture_buffer_id) override; 75 void ReusePictureBuffer(int32 picture_buffer_id) override;
45 void Flush() override; 76 void Flush() override;
46 void Reset() override; 77 void Reset() override;
47 void Destroy() override; 78 void Destroy() override;
48 bool CanDecodeOnIOThread() override; 79 bool CanDecodeOnIOThread() override;
49 80
81 // AndroidVideoDecodeAccelerator::StateProvider
82 const gfx::Size& GetSize() const override;
83 const base::ThreadChecker& ThreadChecker() const override;
84 gfx::SurfaceTexture* GetSurfaceTexture() const override;
85 uint32 GetSurfaceTextureId() const override;
86 gpu::gles2::GLES2Decoder* GetGlDecoder() const override;
87 media::VideoCodecBridge* GetMediaCodec() override;
88 void PostError(const ::tracked_objects::Location& from_here,
89 media::VideoDecodeAccelerator::Error error) override;
90
50 static media::VideoDecodeAccelerator::SupportedProfiles 91 static media::VideoDecodeAccelerator::SupportedProfiles
51 GetSupportedProfiles(); 92 GetSupportedProfiles();
52 93
53 private: 94 private:
54 enum State { 95 enum State {
55 NO_ERROR, 96 NO_ERROR,
56 ERROR, 97 ERROR,
57 }; 98 };
58 99
59 static const base::TimeDelta kDecodePollDelay; 100 static const base::TimeDelta kDecodePollDelay;
60 101
61 ~AndroidVideoDecodeAccelerator() override;
62
63 // Configures |media_codec_| with the given codec parameters from the client. 102 // Configures |media_codec_| with the given codec parameters from the client.
64 bool ConfigureMediaCodec(); 103 bool ConfigureMediaCodec();
65 104
66 // Sends the current picture on the surface to the client. 105 // Sends the current picture on the surface to the client.
67 void SendCurrentSurfaceToClient(int32 bitstream_id); 106 void SendCurrentSurfaceToClient(int32 codec_buffer_index, int32 bitstream_id);
68 107
69 // Does pending IO tasks if any. Once this is called, it polls |media_codec_| 108 // 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 109 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is
71 // used. 110 // used.
72 void DoIOTask(); 111 void DoIOTask();
73 112
74 // Feeds input data to |media_codec_|. This checks 113 // Feeds input data to |media_codec_|. This checks
75 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. 114 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|.
76 void QueueInput(); 115 void QueueInput();
77 116
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // for multiple bitstream buffers that have the same presentation timestamp. 195 // for multiple bitstream buffers that have the same presentation timestamp.
157 std::map<base::TimeDelta, int32> bitstream_buffers_in_decoder_; 196 std::map<base::TimeDelta, int32> bitstream_buffers_in_decoder_;
158 197
159 // Keeps track of bitstream ids notified to the client with 198 // Keeps track of bitstream ids notified to the client with
160 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. 199 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream.
161 std::list<int32> bitstreams_notified_in_advance_; 200 std::list<int32> bitstreams_notified_in_advance_;
162 201
163 // Owner of the GL context. Used to restore the context state. 202 // Owner of the GL context. Used to restore the context state.
164 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; 203 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_;
165 204
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. 205 // Repeating timer responsible for draining pending IO to the codec.
170 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_; 206 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_;
171 207
208 // Backing strategy that we'll use to connect PictureBuffers to frames.
209 scoped_ptr<BackingStrategy> strategy_;
210
172 // WeakPtrFactory for posting tasks back to |this|. 211 // WeakPtrFactory for posting tasks back to |this|.
173 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; 212 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_;
174 213
175 friend class AndroidVideoDecodeAcceleratorTest; 214 friend class AndroidVideoDecodeAcceleratorTest;
176 }; 215 };
177 216
178 } // namespace content 217 } // namespace content
179 218
180 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ 219 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698