OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 |
| 8 #include <dlfcn.h> |
| 9 #include <list> |
| 10 #include <map> |
| 11 #include <queue> |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "base/compiler_specific.h" |
| 16 #include "base/threading/thread_checker.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" |
| 20 #include "media/base/android/media_codec_bridge.h" |
| 21 #include "media/video/video_decode_accelerator.h" |
| 22 |
| 23 namespace content { |
| 24 |
| 25 class SurfaceTextureBridge; |
| 26 |
| 27 // A VideoDecodeAccelerator implementation for Android. |
| 28 // This class decodes the input encoded stream by using Android's MediaCodec |
| 29 // class. http://developer.android.com/reference/android/media/MediaCodec.html |
| 30 class CONTENT_EXPORT AndroidVideoDecodeAccelerator : |
| 31 public media::VideoDecodeAccelerator { |
| 32 public: |
| 33 // Does not take ownership of |client| which must outlive |*this|. |
| 34 AndroidVideoDecodeAccelerator( |
| 35 media::VideoDecodeAccelerator::Client* client, |
| 36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
| 37 const base::Callback<bool(void)>& make_context_current); |
| 38 |
| 39 // media::VideoDecodeAccelerator implementation. |
| 40 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
| 41 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
| 42 virtual void AssignPictureBuffers( |
| 43 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
| 44 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
| 45 virtual void Flush() OVERRIDE; |
| 46 virtual void Reset() OVERRIDE; |
| 47 virtual void Destroy() OVERRIDE; |
| 48 |
| 49 private: |
| 50 enum State { |
| 51 NO_ERROR, |
| 52 ERROR, |
| 53 }; |
| 54 |
| 55 static const base::TimeDelta kDecodePollDelay; |
| 56 |
| 57 virtual ~AndroidVideoDecodeAccelerator(); |
| 58 |
| 59 // Configures |media_codec_| with the given codec parameters from the client. |
| 60 void ConfigureMediaCodec(); |
| 61 |
| 62 // Sends the current picture on the surface to the client. |
| 63 void SendCurrentSurfaceToClient(int32 bitstream_id); |
| 64 |
| 65 // Does pending IO tasks if any. Once this is called, it polls |media_codec_| |
| 66 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is |
| 67 // used. |
| 68 void DoIOTask(); |
| 69 |
| 70 // Feeds input data to |media_codec_|. This checks |
| 71 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|. |
| 72 void QueueInput(); |
| 73 |
| 74 // Dequeues output from |media_codec_| and feeds the decoded frame to the |
| 75 // client. |
| 76 void DequeueOutput(); |
| 77 |
| 78 // Notifies the client that initialize was completed. |
| 79 void NotifyInitializeDone(); |
| 80 |
| 81 // Requests picture buffers from the client. |
| 82 void RequestPictureBuffers(); |
| 83 |
| 84 // Notifies the client about the availability of a picture. |
| 85 void NotifyPictureReady(const media::Picture& picture); |
| 86 |
| 87 // Notifies the client that the input buffer identifed by input_buffer_id has |
| 88 // been processed. |
| 89 void NotifyEndOfBitstreamBuffer(int input_buffer_id); |
| 90 |
| 91 // Notifies the client that the decoder was flushed. |
| 92 void NotifyFlushDone(); |
| 93 |
| 94 // Notifies the client that the decoder was reset. |
| 95 void NotifyResetDone(); |
| 96 |
| 97 // Notifies about decoding errors. |
| 98 void NotifyError(media::VideoDecodeAccelerator::Error error); |
| 99 |
| 100 // Used to DCHECK that we are called on the correct thread. |
| 101 base::ThreadChecker thread_checker_; |
| 102 |
| 103 // To expose client callbacks from VideoDecodeAccelerator. |
| 104 Client* client_; |
| 105 |
| 106 // Callback to set the correct gl context. |
| 107 base::Callback<bool(void)> make_context_current_; |
| 108 |
| 109 // Codec type. Used when we configure media codec. |
| 110 media::MediaCodecBridge::Codec codec_; |
| 111 |
| 112 // The current state of this class. For now, this is used only for setting |
| 113 // error state. |
| 114 State state_; |
| 115 |
| 116 // This map maintains the picture buffers passed to the client for decoding. |
| 117 // The key is the picture buffer id. |
| 118 typedef std::map<int32, media::PictureBuffer> OutputBufferMap; |
| 119 OutputBufferMap output_picture_buffers_; |
| 120 |
| 121 // This keeps the free picture buffer ids which can be used for sending |
| 122 // decoded frames to the client. |
| 123 std::queue<int32> free_picture_ids_; |
| 124 |
| 125 // The low-level decoder which Android SDK provides. |
| 126 scoped_ptr<media::MediaCodecBridge> media_codec_; |
| 127 |
| 128 // A container of texture. Used to set a texture to |media_codec_|. |
| 129 scoped_refptr<SurfaceTextureBridge> surface_texture_; |
| 130 |
| 131 // The texture id which is set to |surface_texture_|. |
| 132 uint32 surface_texture_id_; |
| 133 |
| 134 // Set to true after requesting picture buffers to the client. |
| 135 bool picturebuffers_requested_; |
| 136 |
| 137 // Set to true when DoIOTask is in the message loop. |
| 138 bool io_task_is_posted_; |
| 139 |
| 140 // Set to true when decoder outputs EOS (end of stream). |
| 141 bool decoder_met_eos_; |
| 142 |
| 143 // The resolution of the stream. |
| 144 gfx::Size size_; |
| 145 |
| 146 // Encoded bitstream buffers to be passed to media codec, queued until a input |
| 147 // buffer is available. |
| 148 typedef std::queue<media::BitstreamBuffer> BitstreamBufferList; |
| 149 BitstreamBufferList pending_bitstream_buffers_; |
| 150 |
| 151 // Indicates the number of bytes already passed to the decoder in the first |
| 152 // buffer in |pending_bitstream_buffers_|. |
| 153 size_t num_bytes_used_in_the_pending_buffer_; |
| 154 |
| 155 // Keeps track of bitstream ids notified to the client with |
| 156 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. |
| 157 std::list<int32> bitstreams_notified_in_advance_; |
| 158 |
| 159 // Owner of the GL context. Used to restore the context state. |
| 160 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_; |
| 161 |
| 162 // Used for copy the texture from |surface_texture_| to picture buffers. |
| 163 scoped_ptr<gpu::CopyTextureCHROMIUMResourceManager> copier_; |
| 164 }; |
| 165 |
| 166 } // namespace content |
| 167 |
| 168 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |