Index: content/common/gpu/media/android_video_decode_accelerator.h |
diff --git a/content/common/gpu/media/android_video_decode_accelerator.h b/content/common/gpu/media/android_video_decode_accelerator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..646f7cf25e48618942bb6379e6067c7d1dc6f43d |
--- /dev/null |
+++ b/content/common/gpu/media/android_video_decode_accelerator.h |
@@ -0,0 +1,141 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
+#define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
+ |
+#include <dlfcn.h> |
+#include <map> |
+#include <queue> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/compiler_specific.h" |
+#include "base/threading/non_thread_safe.h" |
Ami GONE FROM CHROMIUM
2013/01/28 19:49:45
thread_checker.h, instead?
dwkang1
2013/02/04 14:08:26
Done.
|
+#include "content/common/content_export.h" |
+#include "media/base/android/media_codec_bridge.h" |
+#include "media/video/video_decode_accelerator.h" |
+ |
+class MessageLoop; |
+ |
+namespace content { |
+ |
+class SurfaceTextureBridge; |
+class Gles2ExternalTextureCopier; |
+ |
+// A VideoDecodeAccelerator implementation for Android. |
+// This class decodes the input encoded stream by using Android's MediaCodec |
+// class. http://developer.android.com/reference/android/media/MediaCodec.html |
+class CONTENT_EXPORT AndroidVideoDecodeAccelerator : |
+ public media::VideoDecodeAccelerator { |
+ public: |
+ // Does not take ownership of |client| which must outlive |*this|. |
+ AndroidVideoDecodeAccelerator( |
+ media::VideoDecodeAccelerator::Client* client, |
+ const base::Callback<bool(void)>& make_context_current); |
+ |
+ // media::VideoDecodeAccelerator implementation. |
+ bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
+ void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
+ virtual void AssignPictureBuffers( |
+ const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
+ void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
+ void Flush() OVERRIDE; |
+ void Reset() OVERRIDE; |
+ void Destroy() OVERRIDE; |
+ |
+ private: |
+ enum State { |
+ NO_ERROR, |
+ ERROR, |
+ }; |
+ |
+ static const base::TimeDelta kDecodePollDelay; |
+ |
+ virtual ~AndroidVideoDecodeAccelerator(); |
+ |
+ // Configures |media_codec_| with the given codec parameters from the client. |
+ void ConfigureMediaCodec(); |
+ |
+ // Sends the current picture on the surface to the client. |
+ void SendCurrentSurfaceToClient(int32 bitstream_id); |
+ |
+ // Does pending IO tasks if any. Once this is called, it polls |media_codec_| |
+ // until it finishes pending tasks. For the polling, |kDecodePollDelay| is |
+ // used. |
+ void DoIOTask(); |
+ |
+ // Feeds input data to |media_codec_|. This checks |
+ // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. |
+ void QueueInput(); |
+ |
+ // Dequeues output from |media_codec_| and feeds the decoded frame to the |
+ // client. |
+ void DequeueOutput(); |
+ |
+ // Notifies the client that initialize was completed. |
+ void NotifyInitializeDone(); |
+ |
+ // Notifies the client that the decoder was reset. |
+ void NotifyResetDone(); |
+ |
+ // Used to DCHECK that we are called on the correct thread. |
+ base::ThreadChecker thread_checker_; |
+ |
+ // To expose client callbacks from VideoDecodeAccelerator. |
+ Client* client_; |
+ |
+ // Callback to set the correct gl context. |
+ base::Callback<bool(void)> make_context_current_; |
+ |
+ // Codec type. Used when we configure media codec. |
+ media::MediaCodecBridge::Codec codec_; |
+ |
+ // The current state of this class. For now, this is used for setting error |
+ // state. |
+ State state_; |
+ |
+ // This map maintains the picture buffers passed the client for decoding. |
+ // The key is the picture buffer id. |
+ typedef std::map<int32, media::PictureBuffer> OutputBufferMap; |
+ OutputBufferMap output_picture_buffers_; |
+ |
+ // This keeps the free picture buffer ids which can be used for sending |
+ // decoded frames to the client. |
+ std::queue<int32> free_picture_ids_; |
+ |
+ // The low-level decoder which Android SDK provides. |
+ scoped_ptr<media::MediaCodecBridge> media_codec_; |
+ |
+ // A container of texture. Used to set a texture to |media_codec_|. |
+ scoped_refptr<SurfaceTextureBridge> surface_texture_; |
+ |
+ // The texture id which is set to |surface_texture_|. |
+ uint32 surface_texture_id_; |
+ |
+ // Set to true after requesting picture buffers to the client. |
+ bool picturebuffers_requested_; |
+ |
+ // Set to true when the polling against |media_codec_| is on. |
+ bool io_task_is_running_; |
+ |
+ // The resolution of the stream. |
+ gfx::Size size_; |
+ |
+ // Encoded bitstream buffers to be passed to media codec, queued until a input |
+ // buffer is available. |
+ typedef std::queue<media::BitstreamBuffer> BitstreamBufferList; |
+ BitstreamBufferList pending_bitstream_buffers_; |
+ |
+ // bitstream buffer ids that |media_codec_| is being processing. |
+ std::queue<int32> bitstream_buffer_ids_in_decoder_; |
+ |
+ // A helper which copies the given external texture |
+ // (GL_TEXTURE_EXTERNAL_OES) to the target texture (GL_TEXTURE_2D). |
+ scoped_ptr<Gles2ExternalTextureCopier> texture_copier_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |