| 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 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 // Notify strategy that a picture buffer has been assigned. | 81 // Notify strategy that a picture buffer has been assigned. |
| 82 virtual void AssignOnePictureBuffer( | 82 virtual void AssignOnePictureBuffer( |
| 83 const media::PictureBuffer& picture_buffer, | 83 const media::PictureBuffer& picture_buffer, |
| 84 bool have_context) {} | 84 bool have_context) {} |
| 85 | 85 |
| 86 // Notify strategy that a picture buffer has been reused. | 86 // Notify strategy that a picture buffer has been reused. |
| 87 virtual void ReuseOnePictureBuffer( | 87 virtual void ReuseOnePictureBuffer( |
| 88 const media::PictureBuffer& picture_buffer) {} | 88 const media::PictureBuffer& picture_buffer) {} |
| 89 | 89 |
| 90 // Release MediaCodec buffers. |
| 91 virtual void ReleaseCodecBuffers( |
| 92 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) {} |
| 93 |
| 90 // Notify strategy that we have a new android MediaCodec instance. This | 94 // Notify strategy that we have a new android MediaCodec instance. This |
| 91 // happens when we're starting up or re-configuring mid-stream. Any | 95 // happens when we're starting up or re-configuring mid-stream. Any |
| 92 // previously provided codec should no longer be referenced. | 96 // previously provided codec should no longer be referenced. |
| 93 // For convenience, a container of PictureBuffers is provided in case | 97 // For convenience, a container of PictureBuffers is provided in case |
| 94 // per-image cleanup is needed. | 98 // per-image cleanup is needed. |
| 95 virtual void CodecChanged(media::VideoCodecBridge* codec, | 99 virtual void CodecChanged(media::VideoCodecBridge* codec, |
| 96 const OutputBufferMap& buffer_map) = 0; | 100 const OutputBufferMap& buffer_map) = 0; |
| 97 | 101 |
| 98 // Notify the strategy that a frame is available. This callback can happen | 102 // Notify the strategy that a frame is available. This callback can happen |
| 99 // on any thread at any time. | 103 // on any thread at any time. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 157 |
| 154 // TODO(timav): evaluate the need for more states in the AVDA state machine. | 158 // TODO(timav): evaluate the need for more states in the AVDA state machine. |
| 155 enum State { | 159 enum State { |
| 156 NO_ERROR, | 160 NO_ERROR, |
| 157 ERROR, | 161 ERROR, |
| 158 // Set when we are asynchronously constructing the codec. Will transition | 162 // Set when we are asynchronously constructing the codec. Will transition |
| 159 // to NO_ERROR or ERROR depending on success. | 163 // to NO_ERROR or ERROR depending on success. |
| 160 WAITING_FOR_CODEC, | 164 WAITING_FOR_CODEC, |
| 161 // Set when we have a codec, but it doesn't yet have a key. | 165 // Set when we have a codec, but it doesn't yet have a key. |
| 162 WAITING_FOR_KEY, | 166 WAITING_FOR_KEY, |
| 163 WAITING_FOR_EOS, | 167 }; |
| 168 |
| 169 enum DrainType { |
| 170 DRAIN_TYPE_NONE, |
| 171 DRAIN_FOR_FLUSH, |
| 172 DRAIN_FOR_RESET, |
| 173 DRAIN_FOR_DESTROY, |
| 164 }; | 174 }; |
| 165 | 175 |
| 166 // Configuration info for MediaCodec. | 176 // Configuration info for MediaCodec. |
| 167 // This is used to shuttle configuration info between threads without needing | 177 // This is used to shuttle configuration info between threads without needing |
| 168 // to worry about the lifetime of the AVDA instance. All of these should not | 178 // to worry about the lifetime of the AVDA instance. All of these should not |
| 169 // be modified while |state_| is WAITING_FOR_CODEC. | 179 // be modified while |state_| is WAITING_FOR_CODEC. |
| 170 class CodecConfig : public base::RefCountedThreadSafe<CodecConfig> { | 180 class CodecConfig : public base::RefCountedThreadSafe<CodecConfig> { |
| 171 public: | 181 public: |
| 172 CodecConfig(); | 182 CodecConfig(); |
| 173 | 183 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 190 gfx::Size initial_expected_coded_size_; | 200 gfx::Size initial_expected_coded_size_; |
| 191 | 201 |
| 192 protected: | 202 protected: |
| 193 friend class base::RefCountedThreadSafe<CodecConfig>; | 203 friend class base::RefCountedThreadSafe<CodecConfig>; |
| 194 virtual ~CodecConfig(); | 204 virtual ~CodecConfig(); |
| 195 | 205 |
| 196 private: | 206 private: |
| 197 DISALLOW_COPY_AND_ASSIGN(CodecConfig); | 207 DISALLOW_COPY_AND_ASSIGN(CodecConfig); |
| 198 }; | 208 }; |
| 199 | 209 |
| 210 // A part of destruction process that is sometimes postponed after the drain. |
| 211 void ActualDestroy(); |
| 212 |
| 200 // Configures |media_codec_| with the given codec parameters from the client. | 213 // Configures |media_codec_| with the given codec parameters from the client. |
| 201 // This configuration will (probably) not be complete before this call | 214 // This configuration will (probably) not be complete before this call |
| 202 // returns. Multiple calls before completion will be ignored. |state_| | 215 // returns. Multiple calls before completion will be ignored. |state_| |
| 203 // must be NO_ERROR or WAITING_FOR_CODEC. Note that, once you call this, | 216 // must be NO_ERROR or WAITING_FOR_CODEC. Note that, once you call this, |
| 204 // you should be careful to avoid modifying members of |codec_config_| until | 217 // you should be careful to avoid modifying members of |codec_config_| until |
| 205 // |state_| is no longer WAITING_FOR_CODEC. | 218 // |state_| is no longer WAITING_FOR_CODEC. |
| 206 void ConfigureMediaCodecAsynchronously(); | 219 void ConfigureMediaCodecAsynchronously(); |
| 207 | 220 |
| 208 // Like ConfigureMediaCodecAsynchronously, but synchronous. Returns true if | 221 // Like ConfigureMediaCodecAsynchronously, but synchronous. Returns true if |
| 209 // and only if |media_codec_| is non-null. Since all configuration is done | 222 // and only if |media_codec_| is non-null. Since all configuration is done |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // from breaking. NotifyError will do so immediately, PostError may wait. | 289 // from breaking. NotifyError will do so immediately, PostError may wait. |
| 277 // |token| has to match |error_sequence_token_|, or else it's assumed to be | 290 // |token| has to match |error_sequence_token_|, or else it's assumed to be |
| 278 // from a post that's prior to a previous reset, and ignored. | 291 // from a post that's prior to a previous reset, and ignored. |
| 279 void NotifyError(media::VideoDecodeAccelerator::Error error, int token); | 292 void NotifyError(media::VideoDecodeAccelerator::Error error, int token); |
| 280 | 293 |
| 281 // Start or stop our work-polling timer based on whether we did any work, and | 294 // Start or stop our work-polling timer based on whether we did any work, and |
| 282 // how long it has been since we've done work. Calling this with true will | 295 // how long it has been since we've done work. Calling this with true will |
| 283 // start the timer. Calling it with false may stop the timer. | 296 // start the timer. Calling it with false may stop the timer. |
| 284 void ManageTimer(bool did_work); | 297 void ManageTimer(bool did_work); |
| 285 | 298 |
| 299 // Start the MediaCodec drain process by adding end_of_stream() buffer to the |
| 300 // encoded buffers queue. When we receive EOS from the output buffer the drain |
| 301 // process completes and we perform the action depending on the |drain_type|. |
| 302 void StartCodecDrain(DrainType drain_type); |
| 303 |
| 304 // Returns true if we are currently draining the codec and doing that as part |
| 305 // of Reset() or Destroy() VP8 workaround. (http://598963). We won't display |
| 306 // any frames and disable normal errors handling. |
| 307 bool IsDrainingForResetOrDestroy() const; |
| 308 |
| 309 // A helper method that performs the operation required after the drain |
| 310 // completion (usually when we receive EOS in the output). The operation |
| 311 // itself depends on the |drain_type_|. |
| 312 void OnDrainCompleted(); |
| 313 |
| 286 // Resets MediaCodec and buffers/containers used for storing output. These | 314 // Resets MediaCodec and buffers/containers used for storing output. These |
| 287 // components need to be reset upon EOS to decode a later stream. Input state | 315 // components need to be reset upon EOS to decode a later stream. Input state |
| 288 // (e.g. queued BitstreamBuffers) is not reset, as input following an EOS | 316 // (e.g. queued BitstreamBuffers) is not reset, as input following an EOS |
| 289 // is still valid and should be processed. | 317 // is still valid and should be processed. Upon competion calls |done_cb| that |
| 290 void ResetCodecState(); | 318 // can be a null callback. |
| 319 void ResetCodecState(base::Closure done_cb); |
| 291 | 320 |
| 292 // Return true if and only if we should use deferred rendering. | 321 // Return true if and only if we should use deferred rendering. |
| 293 static bool UseDeferredRenderingStrategy( | 322 static bool UseDeferredRenderingStrategy( |
| 294 const gpu::GpuPreferences& gpu_preferences); | 323 const gpu::GpuPreferences& gpu_preferences); |
| 295 | 324 |
| 296 // Used to DCHECK that we are called on the correct thread. | 325 // Used to DCHECK that we are called on the correct thread. |
| 297 base::ThreadChecker thread_checker_; | 326 base::ThreadChecker thread_checker_; |
| 298 | 327 |
| 299 // To expose client callbacks from VideoDecodeAccelerator. | 328 // To expose client callbacks from VideoDecodeAccelerator. |
| 300 Client* client_; | 329 Client* client_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // Backing strategy that we'll use to connect PictureBuffers to frames. | 375 // Backing strategy that we'll use to connect PictureBuffers to frames. |
| 347 std::unique_ptr<BackingStrategy> strategy_; | 376 std::unique_ptr<BackingStrategy> strategy_; |
| 348 | 377 |
| 349 // Helper class that manages asynchronous OnFrameAvailable callbacks. | 378 // Helper class that manages asynchronous OnFrameAvailable callbacks. |
| 350 class OnFrameAvailableHandler; | 379 class OnFrameAvailableHandler; |
| 351 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; | 380 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; |
| 352 | 381 |
| 353 // Time at which we last did useful work on io_timer_. | 382 // Time at which we last did useful work on io_timer_. |
| 354 base::TimeTicks most_recent_work_; | 383 base::TimeTicks most_recent_work_; |
| 355 | 384 |
| 385 // Type of a drain request. We need to distinguish between DRAIN_FOR_FLUSH |
| 386 // and other types, see IsDrainingForResetOrDestroy(). |
| 387 DrainType drain_type_; |
| 388 |
| 356 // CDM related stuff. | 389 // CDM related stuff. |
| 357 | 390 |
| 358 // Holds a ref-count to the CDM to avoid using the CDM after it's destroyed. | 391 // Holds a ref-count to the CDM to avoid using the CDM after it's destroyed. |
| 359 scoped_refptr<media::MediaKeys> cdm_for_reference_holding_only_; | 392 scoped_refptr<media::MediaKeys> cdm_for_reference_holding_only_; |
| 360 | 393 |
| 361 media::MediaDrmBridgeCdmContext* media_drm_bridge_cdm_context_; | 394 media::MediaDrmBridgeCdmContext* media_drm_bridge_cdm_context_; |
| 362 | 395 |
| 363 // MediaDrmBridge requires registration/unregistration of the player, this | 396 // MediaDrmBridge requires registration/unregistration of the player, this |
| 364 // registration id is used for this. | 397 // registration id is used for this. |
| 365 int cdm_registration_id_; | 398 int cdm_registration_id_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 385 | 418 |
| 386 // WeakPtrFactory for posting tasks back to |this|. | 419 // WeakPtrFactory for posting tasks back to |this|. |
| 387 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; | 420 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_; |
| 388 | 421 |
| 389 friend class AndroidVideoDecodeAcceleratorTest; | 422 friend class AndroidVideoDecodeAcceleratorTest; |
| 390 }; | 423 }; |
| 391 | 424 |
| 392 } // namespace content | 425 } // namespace content |
| 393 | 426 |
| 394 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ | 427 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |