| 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 |
| 93 // Attempts to free up codec output buffers by rendering early. |
| 94 virtual void MaybeRenderEarly() {} |
| 95 |
| 89 // Notify strategy that we have a new android MediaCodec instance. This | 96 // Notify strategy that we have a new android MediaCodec instance. This |
| 90 // happens when we're starting up or re-configuring mid-stream. Any | 97 // happens when we're starting up or re-configuring mid-stream. Any |
| 91 // previously provided codec should no longer be referenced. | 98 // previously provided codec should no longer be referenced. |
| 92 // For convenience, a container of PictureBuffers is provided in case | 99 virtual void CodecChanged(media::VideoCodecBridge* codec) = 0; |
| 93 // per-image cleanup is needed. | |
| 94 virtual void CodecChanged(media::VideoCodecBridge* codec, | |
| 95 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. |
| 99 virtual void OnFrameAvailable() = 0; | 103 virtual void OnFrameAvailable() = 0; |
| 100 | 104 |
| 101 // Whether the pictures produced by this backing strategy are overlayable. | 105 // Whether the pictures produced by this backing strategy are overlayable. |
| 102 virtual bool ArePicturesOverlayable() = 0; | 106 virtual bool ArePicturesOverlayable() = 0; |
| 103 | 107 |
| 104 // Size may have changed due to resolution change since the last time this | 108 // Size may have changed due to resolution change since the last time this |
| 105 // PictureBuffer was used. Update the size of the picture buffer to | 109 // PictureBuffer was used. Update the size of the picture buffer to |
| (...skipping 46 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 // Start the MediaCodec drain process by adding end_of_stream() buffer to the |
| 299 // encoded buffers queue. When we receive EOS from the output buffer the drain |
| 300 // process completes and we perform the action depending on the |drain_type|. |
| 301 void StartCodecDrain(DrainType drain_type); |
| 302 |
| 303 // Returns true if we are currently draining the codec and doing that as part |
| 304 // of Reset() or Destroy() VP8 workaround. (http://crbug.com/598963). We won't |
| 305 // display any frames and disable normal errors handling. |
| 306 bool IsDrainingForResetOrDestroy() const; |
| 307 |
| 308 // A helper method that performs the operation required after the drain |
| 309 // completion (usually when we receive EOS in the output). The operation |
| 310 // itself depends on the |drain_type_|. |
| 311 void OnDrainCompleted(); |
| 312 |
| 285 // Resets MediaCodec and buffers/containers used for storing output. These | 313 // 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 | 314 // 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 | 315 // (e.g. queued BitstreamBuffers) is not reset, as input following an EOS |
| 288 // is still valid and should be processed. | 316 // is still valid and should be processed. Upon competion calls |done_cb| that |
| 289 void ResetCodecState(); | 317 // can be a null callback. |
| 318 void ResetCodecState(const base::Closure& done_cb); |
| 290 | 319 |
| 291 // Return true if and only if we should use deferred rendering. | 320 // Return true if and only if we should use deferred rendering. |
| 292 static bool UseDeferredRenderingStrategy( | 321 static bool UseDeferredRenderingStrategy( |
| 293 const gpu::GpuPreferences& gpu_preferences); | 322 const gpu::GpuPreferences& gpu_preferences); |
| 294 | 323 |
| 295 // Used to DCHECK that we are called on the correct thread. | 324 // Used to DCHECK that we are called on the correct thread. |
| 296 base::ThreadChecker thread_checker_; | 325 base::ThreadChecker thread_checker_; |
| 297 | 326 |
| 298 // To expose client callbacks from VideoDecodeAccelerator. | 327 // To expose client callbacks from VideoDecodeAccelerator. |
| 299 Client* client_; | 328 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. | 374 // Backing strategy that we'll use to connect PictureBuffers to frames. |
| 346 scoped_ptr<BackingStrategy> strategy_; | 375 scoped_ptr<BackingStrategy> strategy_; |
| 347 | 376 |
| 348 // Helper class that manages asynchronous OnFrameAvailable callbacks. | 377 // Helper class that manages asynchronous OnFrameAvailable callbacks. |
| 349 class OnFrameAvailableHandler; | 378 class OnFrameAvailableHandler; |
| 350 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; | 379 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; |
| 351 | 380 |
| 352 // Time at which we last did useful work on io_timer_. | 381 // Time at which we last did useful work on io_timer_. |
| 353 base::TimeTicks most_recent_work_; | 382 base::TimeTicks most_recent_work_; |
| 354 | 383 |
| 384 // Type of a drain request. We need to distinguish between DRAIN_FOR_FLUSH |
| 385 // and other types, see IsDrainingForResetOrDestroy(). |
| 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 |