OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Destroy output buffers and release associated resources (textures, | 148 // Destroy output buffers and release associated resources (textures, |
149 // EGLImages). If |dismiss| is true, also dismissing the associated | 149 // EGLImages). If |dismiss| is true, also dismissing the associated |
150 // PictureBuffers. | 150 // PictureBuffers. |
151 bool DestroyOutputs(bool dismiss); | 151 bool DestroyOutputs(bool dismiss); |
152 | 152 |
153 // Used by DestroyOutputs. | 153 // Used by DestroyOutputs. |
154 bool DestroyOutputBuffers(); | 154 bool DestroyOutputBuffers(); |
155 | 155 |
156 // Dismiss all |picture_buffer_ids| via Client::DismissPictureBuffer() | 156 // Dismiss all |picture_buffer_ids| via Client::DismissPictureBuffer() |
157 // and signal |done| after finishing. | 157 // and signal |done| after finishing. |
158 void DismissPictures(std::vector<int32_t> picture_buffer_ids, | 158 void DismissPictures(const std::vector<int32_t>& picture_buffer_ids, |
159 base::WaitableEvent* done); | 159 base::WaitableEvent* done); |
160 | 160 |
161 // Task to finish initialization on decoder_thread_. | 161 // Task to finish initialization on decoder_thread_. |
162 void InitializeTask(); | 162 void InitializeTask(); |
163 | 163 |
164 // Surface set change (resolution change) flow. | 164 // Surface set change (resolution change) flow. |
165 // If we have no surfaces allocated, just allocate them and return. | 165 // If we have no surfaces allocated, start it immediately, otherwise mark |
166 // Otherwise mark us as pending for surface set change. | 166 // ourselves as pending for surface set change. |
167 void InitiateSurfaceSetChange(); | 167 void InitiateSurfaceSetChange(); |
168 // If a surface set change is pending and we are ready, stop the device, | 168 // If a surface set change is pending and we are ready, stop the device, |
169 // destroy outputs, releasing resources and dismissing pictures as required, | 169 // destroy outputs, releasing resources and dismissing pictures as required, |
170 // followed by allocating a new set for the new resolution/DPB size | 170 // followed by starting the flow to allocate a new set for the current |
171 // as provided by decoder. Finally, try to resume decoding. | 171 // resolution/DPB size, as provided by decoder. |
172 void FinishSurfaceSetChangeIfNeeded(); | 172 bool FinishSurfaceSetChange(); |
173 | 173 |
174 void NotifyError(Error error); | 174 void NotifyError(Error error); |
175 void DestroyTask(); | 175 void DestroyTask(); |
176 | 176 |
177 // Sets the state to kError and notifies client if needed. | 177 // Sets the state to kError and notifies client if needed. |
178 void SetErrorState(Error error); | 178 void SetErrorState(Error error); |
179 | 179 |
180 // Flush flow when requested by client. | 180 // Flush flow when requested by client. |
181 // When Flush() is called, it posts a FlushTask, which checks the input queue. | 181 // When Flush() is called, it posts a FlushTask, which checks the input queue. |
182 // If nothing is pending for decode on decoder_input_queue_, we call | 182 // If nothing is pending for decode on decoder_input_queue_, we call |
183 // InitiateFlush() directly. Otherwise, we push a dummy BitstreamBufferRef | 183 // InitiateFlush() directly. Otherwise, we push a dummy BitstreamBufferRef |
184 // onto the decoder_input_queue_ to schedule a flush. When we reach it later | 184 // onto the decoder_input_queue_ to schedule a flush. When we reach it later |
185 // on, we call InitiateFlush() to perform it at the correct time. | 185 // on, we call InitiateFlush() to perform it at the correct time. |
186 void FlushTask(); | 186 void FlushTask(); |
187 // Tell the decoder to flush all frames, reset it and mark us as scheduled | 187 // Tell the decoder to flush all frames, reset it and mark us as scheduled |
188 // for flush, so that we can finish it once all pending decodes are finished. | 188 // for flush, so that we can finish it once all pending decodes are finished. |
189 void InitiateFlush(); | 189 void InitiateFlush(); |
190 // If all pending frames are decoded and we are waiting to flush, perform it. | 190 // To be called if decoder_flushing_ is true. If not all pending frames are |
191 // This will send all pending pictures to client and notify the client that | 191 // decoded, return false, requesting the caller to try again later. |
192 // flush is complete and puts us in a state ready to resume. | 192 // Otherwise perform flush by sending all pending pictures to the client, |
193 void FinishFlushIfNeeded(); | 193 // notify it that flush is finished and return true, informing the caller |
| 194 // that further progress can be made. |
| 195 bool FinishFlush(); |
194 | 196 |
195 // Reset flow when requested by client. | 197 // Reset flow when requested by client. |
196 // Drop all inputs and reset the decoder and mark us as pending for reset. | 198 // Drop all inputs, reset the decoder and mark us as pending for reset. |
197 void ResetTask(); | 199 void ResetTask(); |
198 // If all pending frames are decoded and we are waiting to reset, perform it. | 200 // To be called if decoder_resetting_ is true. If not all pending frames are |
199 // This drops all pending outputs (client is not interested anymore), | 201 // decoded, return false, requesting the caller to try again later. |
200 // notifies the client we are done and puts us in a state ready to resume. | 202 // Otherwise perform reset by dropping all pending outputs (client is not |
201 void FinishResetIfNeeded(); | 203 // interested anymore), notifying it that reset is finished, and return true, |
| 204 // informing the caller that further progress can be made. |
| 205 bool FinishReset(); |
202 | 206 |
203 // Process pending events if any. | 207 // Allocate V4L2 buffers and assign them to |buffers| provided by the client |
| 208 // via AssignPictureBuffers() on decoder thread. |
| 209 void AssignPictureBuffersTask( |
| 210 const std::vector<media::PictureBuffer>& buffers); |
| 211 |
| 212 // Create EGLImages bound to textures in |buffers| for given |
| 213 // |output_format_fourcc| and |output_planes_count|. |
| 214 void CreateEGLImages(const std::vector<media::PictureBuffer>& buffers, |
| 215 uint32_t output_format_fourcc, |
| 216 size_t output_planes_count); |
| 217 |
| 218 // Assign |egl_images| to previously-allocated V4L2 buffers in |
| 219 // output_buffer_map_ and picture ids from |buffers| and finish the surface |
| 220 // change sequence. |
| 221 void AssignEGLImages(const std::vector<media::PictureBuffer>& buffers, |
| 222 const std::vector<EGLImageKHR>& egl_images); |
| 223 |
| 224 // Process pending events, if any. |
204 void ProcessPendingEventsIfNeeded(); | 225 void ProcessPendingEventsIfNeeded(); |
205 | 226 |
206 // Performed on decoder_thread_ as a consequence of poll() on decoder_thread_ | 227 // Performed on decoder_thread_ as a consequence of poll() on decoder_thread_ |
207 // returning an event. | 228 // returning an event. |
208 void ServiceDeviceTask(); | 229 void ServiceDeviceTask(); |
209 | 230 |
210 // Schedule poll if we have any buffers queued and the poll thread | 231 // Schedule poll if we have any buffers queued and the poll thread |
211 // is not stopped (on surface set change). | 232 // is not stopped (on surface set change). |
212 void SchedulePollIfNeeded(); | 233 void SchedulePollIfNeeded(); |
213 | 234 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 V4L2DecodeSurfaceByPictureBufferId surfaces_at_display_; | 391 V4L2DecodeSurfaceByPictureBufferId surfaces_at_display_; |
371 | 392 |
372 // Record for decoded pictures that can be sent to PictureReady. | 393 // Record for decoded pictures that can be sent to PictureReady. |
373 struct PictureRecord; | 394 struct PictureRecord; |
374 // Pictures that are ready but not sent to PictureReady yet. | 395 // Pictures that are ready but not sent to PictureReady yet. |
375 std::queue<PictureRecord> pending_picture_ready_; | 396 std::queue<PictureRecord> pending_picture_ready_; |
376 | 397 |
377 // The number of pictures that are sent to PictureReady and will be cleared. | 398 // The number of pictures that are sent to PictureReady and will be cleared. |
378 int picture_clearing_count_; | 399 int picture_clearing_count_; |
379 | 400 |
380 // Used by the decoder thread to wait for AssignPictureBuffers to arrive | |
381 // to avoid races with potential Reset requests. | |
382 base::WaitableEvent pictures_assigned_; | |
383 | |
384 // Make the GL context current callback. | 401 // Make the GL context current callback. |
385 base::Callback<bool(void)> make_context_current_; | 402 base::Callback<bool(void)> make_context_current_; |
386 | 403 |
387 // EGL state | 404 // EGL state |
388 EGLDisplay egl_display_; | 405 EGLDisplay egl_display_; |
389 EGLContext egl_context_; | 406 EGLContext egl_context_; |
390 | 407 |
391 // The WeakPtrFactory for |weak_this_|. | 408 // The WeakPtrFactory for |weak_this_|. |
392 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; | 409 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; |
393 | 410 |
394 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); | 411 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); |
395 }; | 412 }; |
396 | 413 |
397 class V4L2H264Picture; | 414 class V4L2H264Picture; |
398 class V4L2VP8Picture; | 415 class V4L2VP8Picture; |
399 | 416 |
400 } // namespace content | 417 } // namespace content |
401 | 418 |
402 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 419 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |