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