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