| 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 MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 class SharedMemoryRegion; | 38 class SharedMemoryRegion; |
| 39 | 39 |
| 40 // A VideoDecodeAccelerator implementation for Android. This class decodes the | 40 // A VideoDecodeAccelerator implementation for Android. This class decodes the |
| 41 // encded input stream using Android's MediaCodec. It handles the work of | 41 // encded input stream using Android's MediaCodec. It handles the work of |
| 42 // transferring data to and from MediaCodec, and delegates attaching MediaCodec | 42 // transferring data to and from MediaCodec, and delegates attaching MediaCodec |
| 43 // output buffers to PictureBuffers to AVDAPictureBufferManager. | 43 // output buffers to PictureBuffers to AVDAPictureBufferManager. |
| 44 class MEDIA_GPU_EXPORT AndroidVideoDecodeAccelerator | 44 class MEDIA_GPU_EXPORT AndroidVideoDecodeAccelerator |
| 45 : public VideoDecodeAccelerator, | 45 : public VideoDecodeAccelerator, |
| 46 public AVDAStateProvider { | 46 public AVDAStateProvider { |
| 47 public: | 47 public: |
| 48 static VideoDecodeAccelerator::Capabilities GetCapabilities( |
| 49 const gpu::GpuPreferences& gpu_preferences); |
| 50 |
| 48 AndroidVideoDecodeAccelerator( | 51 AndroidVideoDecodeAccelerator( |
| 49 const MakeGLContextCurrentCallback& make_context_current_cb, | 52 const MakeGLContextCurrentCallback& make_context_current_cb, |
| 50 const GetGLES2DecoderCallback& get_gles2_decoder_cb); | 53 const GetGLES2DecoderCallback& get_gles2_decoder_cb); |
| 51 | 54 |
| 52 ~AndroidVideoDecodeAccelerator() override; | 55 ~AndroidVideoDecodeAccelerator() override; |
| 53 | 56 |
| 54 // VideoDecodeAccelerator implementation: | 57 // VideoDecodeAccelerator implementation: |
| 55 bool Initialize(const Config& config, Client* client) override; | 58 bool Initialize(const Config& config, Client* client) override; |
| 56 void Decode(const BitstreamBuffer& bitstream_buffer) override; | 59 void Decode(const BitstreamBuffer& bitstream_buffer) override; |
| 57 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override; | 60 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override; |
| 58 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 61 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
| 59 void Flush() override; | 62 void Flush() override; |
| 60 void Reset() override; | 63 void Reset() override; |
| 61 void SetSurface(int32_t surface_id) override; | 64 void SetSurface(int32_t surface_id) override; |
| 62 void Destroy() override; | 65 void Destroy() override; |
| 63 bool TryToSetupDecodeOnSeparateThread( | 66 bool TryToSetupDecodeOnSeparateThread( |
| 64 const base::WeakPtr<Client>& decode_client, | 67 const base::WeakPtr<Client>& decode_client, |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 68 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
| 66 override; | 69 override; |
| 67 | 70 |
| 68 // AVDAStateProvider implementation: | 71 // AVDAStateProvider implementation: |
| 69 const gfx::Size& GetSize() const override; | 72 const gfx::Size& GetSize() const override; |
| 70 base::WeakPtr<gpu::gles2::GLES2Decoder> GetGlDecoder() const override; | 73 base::WeakPtr<gpu::gles2::GLES2Decoder> GetGlDecoder() const override; |
| 71 void PostError(const ::tracked_objects::Location& from_here, | 74 // Notifies the client about the error and sets |state_| to |ERROR|. |
| 72 VideoDecodeAccelerator::Error error) override; | 75 void NotifyError(Error error) override; |
| 73 | |
| 74 static VideoDecodeAccelerator::Capabilities GetCapabilities( | |
| 75 const gpu::GpuPreferences& gpu_preferences); | |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 friend class AVDAManager; | 78 friend class AVDAManager; |
| 79 | 79 |
| 80 // TODO(timav): evaluate the need for more states in the AVDA state machine. | 80 // TODO(timav): evaluate the need for more states in the AVDA state machine. |
| 81 enum State { | 81 enum State { |
| 82 NO_ERROR, | 82 NO_ERROR, |
| 83 ERROR, | 83 ERROR, |
| 84 // Set when we are asynchronously constructing the codec. Will transition | 84 // Set when we are asynchronously constructing the codec. Will transition |
| 85 // to NO_ERROR or ERROR depending on success. | 85 // to NO_ERROR or ERROR depending on success. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Notifies the client that the input buffer identifed by input_buffer_id has | 223 // Notifies the client that the input buffer identifed by input_buffer_id has |
| 224 // been processed. | 224 // been processed. |
| 225 void NotifyEndOfBitstreamBuffer(int input_buffer_id); | 225 void NotifyEndOfBitstreamBuffer(int input_buffer_id); |
| 226 | 226 |
| 227 // Notifies the client that the decoder was flushed. | 227 // Notifies the client that the decoder was flushed. |
| 228 void NotifyFlushDone(); | 228 void NotifyFlushDone(); |
| 229 | 229 |
| 230 // Notifies the client that the decoder was reset. | 230 // Notifies the client that the decoder was reset. |
| 231 void NotifyResetDone(); | 231 void NotifyResetDone(); |
| 232 | 232 |
| 233 // Notifies about decoding errors. | |
| 234 // Note: you probably don't want to call this directly. Use PostError or | |
| 235 // RETURN_ON_FAILURE, since we can defer error reporting to keep the pipeline | |
| 236 // from breaking. NotifyError will do so immediately, PostError may wait. | |
| 237 // |token| has to match |error_sequence_token_|, or else it's assumed to be | |
| 238 // from a post that's prior to a previous reset, and ignored. | |
| 239 void NotifyError(VideoDecodeAccelerator::Error error, int token); | |
| 240 | |
| 241 // Start or stop our work-polling timer based on whether we did any work, and | 233 // Start or stop our work-polling timer based on whether we did any work, and |
| 242 // how long it has been since we've done work. Calling this with true will | 234 // how long it has been since we've done work. Calling this with true will |
| 243 // start the timer. Calling it with false may stop the timer. | 235 // start the timer. Calling it with false may stop the timer. |
| 244 void ManageTimer(bool did_work); | 236 void ManageTimer(bool did_work); |
| 245 | 237 |
| 246 // Safely clear |media_codec_|. Do this instead of calling reset() / assign. | 238 // Safely clear |media_codec_|. Do this instead of calling reset() / assign. |
| 247 // Otherwise, the destructor can hang if mediaserver is in a bad state. This | 239 // Otherwise, the destructor can hang if mediaserver is in a bad state. This |
| 248 // will release immediately if safe, else post to a separate thread. Either | 240 // will release immediately if safe, else post to a separate thread. Either |
| 249 // way, |media_codec_| will be null upon return. | 241 // way, |media_codec_| will be null upon return. |
| 250 void ReleaseMediaCodec(); | 242 void ReleaseMediaCodec(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 scoped_refptr<CodecConfig> codec_config_; | 360 scoped_refptr<CodecConfig> codec_config_; |
| 369 | 361 |
| 370 // Index of the dequeued and filled buffer that we keep trying to enqueue. | 362 // Index of the dequeued and filled buffer that we keep trying to enqueue. |
| 371 // Such buffer appears in MEDIA_CODEC_NO_KEY processing. | 363 // Such buffer appears in MEDIA_CODEC_NO_KEY processing. |
| 372 int pending_input_buf_index_; | 364 int pending_input_buf_index_; |
| 373 | 365 |
| 374 // Monotonically increasing value that is used to prevent old, delayed errors | 366 // Monotonically increasing value that is used to prevent old, delayed errors |
| 375 // from being sent after a reset. | 367 // from being sent after a reset. |
| 376 int error_sequence_token_; | 368 int error_sequence_token_; |
| 377 | 369 |
| 378 // PostError will defer sending an error if and only if this is true. | |
| 379 bool defer_errors_; | |
| 380 | |
| 381 // True if and only if VDA initialization is deferred, and we have not yet | 370 // True if and only if VDA initialization is deferred, and we have not yet |
| 382 // called NotifyInitializationComplete. | 371 // called NotifyInitializationComplete. |
| 383 bool deferred_initialization_pending_; | 372 bool deferred_initialization_pending_; |
| 384 | 373 |
| 385 // Indicates if ResetCodecState() should be called upon the next call to | 374 // Indicates if ResetCodecState() should be called upon the next call to |
| 386 // Decode(). Allows us to avoid trashing the last few frames of a playback | 375 // Decode(). Allows us to avoid trashing the last few frames of a playback |
| 387 // when the EOS buffer is received. | 376 // when the EOS buffer is received. |
| 388 bool codec_needs_reset_; | 377 bool codec_needs_reset_; |
| 389 | 378 |
| 390 // True if surface creation and |picture_buffer_manager_| initialization has | 379 // True if surface creation and |picture_buffer_manager_| initialization has |
| (...skipping 13 matching lines...) Expand all Loading... |
| 404 | 393 |
| 405 // WeakPtrFactory for posting tasks back to |this|. | 394 // WeakPtrFactory for posting tasks back to |this|. |
| 406 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; | 395 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; |
| 407 | 396 |
| 408 friend class AndroidVideoDecodeAcceleratorTest; | 397 friend class AndroidVideoDecodeAcceleratorTest; |
| 409 }; | 398 }; |
| 410 | 399 |
| 411 } // namespace media | 400 } // namespace media |
| 412 | 401 |
| 413 #endif // MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 402 #endif // MEDIA_GPU_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |