Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains an implementation of VideoDecoderAccelerator | 5 // This file contains an implementation of VideoDecoderAccelerator |
| 6 // that utilizes hardware video decoder present on Intel CPUs. | 6 // that utilizes hardware video decoder present on Intel CPUs. |
| 7 | 7 |
| 8 #ifndef MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 8 #ifndef MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
| 9 #define MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 9 #define MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 private: | 86 private: |
| 87 class VaapiH264Accelerator; | 87 class VaapiH264Accelerator; |
| 88 class VaapiVP8Accelerator; | 88 class VaapiVP8Accelerator; |
| 89 class VaapiVP9Accelerator; | 89 class VaapiVP9Accelerator; |
| 90 | 90 |
| 91 // Notify the client that an error has occurred and decoding cannot continue. | 91 // Notify the client that an error has occurred and decoding cannot continue. |
| 92 void NotifyError(Error error); | 92 void NotifyError(Error error); |
| 93 | 93 |
| 94 // Map the received input buffer into this process' address space and | 94 // Map the received input buffer into this process' address space and |
| 95 // queue it for decode. | 95 // queue it for decode. |
| 96 void MapAndQueueNewInputBuffer(const BitstreamBuffer& bitstream_buffer); | 96 bool MapAndQueueNewInputBuffer(const BitstreamBuffer& bitstream_buffer); |
| 97 | 97 |
| 98 // Get a new input buffer from the queue and set it up in decoder. This will | 98 // Get a new input buffer from the queue and set it up in decoder. This will |
| 99 // sleep if no input buffers are available. Return true if a new buffer has | 99 // sleep if no input buffers are available. Return true if a new buffer has |
| 100 // been set up, false if an early exit has been requested (due to initiated | 100 // been set up, false if an early exit has been requested (due to initiated |
| 101 // reset/flush/destroy). | 101 // reset/flush/destroy). |
| 102 bool GetInputBuffer_Locked(); | 102 bool GetInputBuffer_Locked(); |
| 103 | 103 |
| 104 // Signal the client that the current buffer has been read and can be | 104 // Signal the client that the current buffer has been read and can be |
| 105 // returned. Will also release the mapping. | 105 // returned. Will also release the mapping. |
| 106 void ReturnCurrInputBuffer_Locked(); | 106 void ReturnCurrInputBuffer_Locked(); |
| 107 | 107 |
| 108 // Wait for more surfaces to become available. Return true once they do or | 108 // Wait for more surfaces to become available. Return true once they do or |
| 109 // false if an early exit has been requested (due to an initiated | 109 // false if an early exit has been requested (due to an initiated |
| 110 // reset/flush/destroy). | 110 // reset/flush/destroy). |
| 111 bool WaitForSurfaces_Locked(); | 111 bool WaitForSurfaces_Locked(); |
| 112 | 112 |
| 113 bool IsFlushPending_Locked(); | |
| 114 | |
| 113 // Continue decoding given input buffers and sleep waiting for input/output | 115 // Continue decoding given input buffers and sleep waiting for input/output |
| 114 // as needed. Will exit if a new set of surfaces or reset/flush/destroy | 116 // as needed. Will exit if a new set of surfaces or reset/flush/destroy |
| 115 // is requested. | 117 // is requested. |
| 116 void DecodeTask(); | 118 void DecodeTask(); |
| 117 | 119 |
| 118 // Scheduled after receiving a flush request and executed after the current | 120 // Scheduled after receiving a flush request and executed after the current |
| 119 // decoding task finishes decoding pending inputs. Makes the decoder return | 121 // decoding task finishes decoding pending inputs. Makes the decoder return |
| 120 // all remaining output pictures and puts it in an idle state, ready | 122 // all remaining output pictures and puts it in an idle state, ready |
| 121 // to resume if needed and schedules a FinishFlush. | 123 // to resume if needed and schedules a FinishFlush. |
| 122 void FlushTask(); | 124 void FlushTask(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 scoped_refptr<VaapiDecodeSurface> CreateSurface(); | 191 scoped_refptr<VaapiDecodeSurface> CreateSurface(); |
| 190 | 192 |
| 191 // VAVDA state. | 193 // VAVDA state. |
| 192 enum State { | 194 enum State { |
| 193 // Initialize() not called yet or failed. | 195 // Initialize() not called yet or failed. |
| 194 kUninitialized, | 196 kUninitialized, |
| 195 // DecodeTask running. | 197 // DecodeTask running. |
| 196 kDecoding, | 198 kDecoding, |
| 197 // Resetting, waiting for decoder to finish current task and cleanup. | 199 // Resetting, waiting for decoder to finish current task and cleanup. |
| 198 kResetting, | 200 kResetting, |
| 199 // Flushing, waiting for decoder to finish current task and cleanup. | |
| 200 kFlushing, | |
| 201 // Idle, decoder in state ready to start/resume decoding. | 201 // Idle, decoder in state ready to start/resume decoding. |
| 202 kIdle, | 202 kIdle, |
| 203 // Destroying, waiting for the decoder to finish current task. | 203 // Destroying, waiting for the decoder to finish current task. |
| 204 kDestroying, | 204 kDestroying, |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 // Protects input buffer and surface queues and state_. | 207 // Protects input buffer and surface queues and state_. |
| 208 base::Lock lock_; | 208 base::Lock lock_; |
| 209 State state_; | 209 State state_; |
| 210 Config::OutputMode output_mode_; | 210 Config::OutputMode output_mode_; |
| 211 | 211 |
| 212 // An input buffer awaiting consumption, provided by the client. | 212 // An input buffer awaiting consumption, provided by the client. |
| 213 struct InputBuffer { | 213 struct InputBuffer { |
| 214 InputBuffer(); | 214 InputBuffer(); |
|
Owen Lin
2017/01/19 07:39:16
Remove both ctor and dtor?
kcwu
2017/01/20 07:49:03
Done.
| |
| 215 ~InputBuffer(); | 215 ~InputBuffer(); |
| 216 | 216 |
| 217 int32_t id; | 217 // Indicates this is a dummy buffer for flush request. |
| 218 // If |dummy_flush| is true, |id| and |shm| are not used. | |
| 219 bool dummy_flush = false; | |
| 220 | |
| 221 int32_t id = 0; | |
| 218 std::unique_ptr<SharedMemoryRegion> shm; | 222 std::unique_ptr<SharedMemoryRegion> shm; |
|
Owen Lin
2017/01/19 07:39:16
Why not just use "shm == null" to indicate an empt
kcwu
2017/01/19 08:26:10
Do you mean "shm = null" to assign a default value
Owen Lin
2017/01/20 02:20:06
No, I mean we don't really need a new member dummy
kcwu
2017/01/20 07:49:03
Done.
| |
| 219 }; | 223 }; |
| 220 | 224 |
| 221 // Queue for available PictureBuffers (picture_buffer_ids). | 225 // Queue for available PictureBuffers (picture_buffer_ids). |
| 222 typedef std::queue<linked_ptr<InputBuffer>> InputBuffers; | 226 typedef std::queue<linked_ptr<InputBuffer>> InputBuffers; |
| 223 InputBuffers input_buffers_; | 227 InputBuffers input_buffers_; |
| 224 // Signalled when input buffers are queued onto the input_buffers_ queue. | 228 // Signalled when input buffers are queued onto the input_buffers_ queue. |
| 225 base::ConditionVariable input_ready_; | 229 base::ConditionVariable input_ready_; |
| 226 | 230 |
| 227 // Current input buffer at decoder. | 231 // Current input buffer at decoder. |
| 228 linked_ptr<InputBuffer> curr_input_buffer_; | 232 linked_ptr<InputBuffer> curr_input_buffer_; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 323 |
| 320 // The WeakPtrFactory for |weak_this_|. | 324 // The WeakPtrFactory for |weak_this_|. |
| 321 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; | 325 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; |
| 322 | 326 |
| 323 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 327 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
| 324 }; | 328 }; |
| 325 | 329 |
| 326 } // namespace media | 330 } // namespace media |
| 327 | 331 |
| 328 #endif // MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 332 #endif // MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |