| 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(const std::vector<int32_t>& picture_buffer_ids, | 158 void DismissPictures(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, start it immediately, otherwise mark | 165 // If we have no surfaces allocated, just allocate them and return. |
| 166 // ourselves as pending for surface set change. | 166 // Otherwise mark us 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 starting the flow to allocate a new set for the current | 170 // followed by allocating a new set for the new resolution/DPB size |
| 171 // resolution/DPB size, as provided by decoder. | 171 // as provided by decoder. Finally, try to resume decoding. |
| 172 bool FinishSurfaceSetChange(); | 172 void FinishSurfaceSetChangeIfNeeded(); |
| 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 // To be called if decoder_flushing_ is true. If not all pending frames are | 190 // If all pending frames are decoded and we are waiting to flush, perform it. |
| 191 // decoded, return false, requesting the caller to try again later. | 191 // This will send all pending pictures to client and notify the client that |
| 192 // Otherwise perform flush by sending all pending pictures to the client, | 192 // flush is complete and puts us in a state ready to resume. |
| 193 // notify it that flush is finished and return true, informing the caller | 193 void FinishFlushIfNeeded(); |
| 194 // that further progress can be made. | |
| 195 bool FinishFlush(); | |
| 196 | 194 |
| 197 // Reset flow when requested by client. | 195 // Reset flow when requested by client. |
| 198 // Drop all inputs, reset the decoder and mark us as pending for reset. | 196 // Drop all inputs and reset the decoder and mark us as pending for reset. |
| 199 void ResetTask(); | 197 void ResetTask(); |
| 200 // To be called if decoder_resetting_ is true. If not all pending frames are | 198 // If all pending frames are decoded and we are waiting to reset, perform it. |
| 201 // decoded, return false, requesting the caller to try again later. | 199 // This drops all pending outputs (client is not interested anymore), |
| 202 // Otherwise perform reset by dropping all pending outputs (client is not | 200 // notifies the client we are done and puts us in a state ready to resume. |
| 203 // interested anymore), notifying it that reset is finished, and return true, | 201 void FinishResetIfNeeded(); |
| 204 // informing the caller that further progress can be made. | |
| 205 bool FinishReset(); | |
| 206 | 202 |
| 207 // Allocate V4L2 buffers and assign them to |buffers| provided by the client | 203 // Process pending events if any. |
| 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. | |
| 225 void ProcessPendingEventsIfNeeded(); | 204 void ProcessPendingEventsIfNeeded(); |
| 226 | 205 |
| 227 // Performed on decoder_thread_ as a consequence of poll() on decoder_thread_ | 206 // Performed on decoder_thread_ as a consequence of poll() on decoder_thread_ |
| 228 // returning an event. | 207 // returning an event. |
| 229 void ServiceDeviceTask(); | 208 void ServiceDeviceTask(); |
| 230 | 209 |
| 231 // Schedule poll if we have any buffers queued and the poll thread | 210 // Schedule poll if we have any buffers queued and the poll thread |
| 232 // is not stopped (on surface set change). | 211 // is not stopped (on surface set change). |
| 233 void SchedulePollIfNeeded(); | 212 void SchedulePollIfNeeded(); |
| 234 | 213 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 struct PictureRecord; | 373 struct PictureRecord; |
| 395 // Pictures that are ready but not sent to PictureReady yet. | 374 // Pictures that are ready but not sent to PictureReady yet. |
| 396 std::queue<PictureRecord> pending_picture_ready_; | 375 std::queue<PictureRecord> pending_picture_ready_; |
| 397 | 376 |
| 398 // The number of pictures that are sent to PictureReady and will be cleared. | 377 // The number of pictures that are sent to PictureReady and will be cleared. |
| 399 int picture_clearing_count_; | 378 int picture_clearing_count_; |
| 400 | 379 |
| 401 // Make the GL context current callback. | 380 // Make the GL context current callback. |
| 402 base::Callback<bool(void)> make_context_current_; | 381 base::Callback<bool(void)> make_context_current_; |
| 403 | 382 |
| 383 // Used by the decoder thread to wait for AssignPictureBuffers to arrive |
| 384 // to avoid races with potential Reset requests. |
| 385 base::WaitableEvent pictures_assigned_; |
| 386 |
| 404 // EGL state | 387 // EGL state |
| 405 EGLDisplay egl_display_; | 388 EGLDisplay egl_display_; |
| 406 EGLContext egl_context_; | 389 EGLContext egl_context_; |
| 407 | 390 |
| 408 // The WeakPtrFactory for |weak_this_|. | 391 // The WeakPtrFactory for |weak_this_|. |
| 409 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; | 392 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; |
| 410 | 393 |
| 411 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); | 394 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); |
| 412 }; | 395 }; |
| 413 | 396 |
| 414 class V4L2H264Picture; | 397 class V4L2H264Picture; |
| 415 class V4L2VP8Picture; | 398 class V4L2VP8Picture; |
| 416 | 399 |
| 417 } // namespace content | 400 } // namespace content |
| 418 | 401 |
| 419 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 402 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |