Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Side by Side Diff: media/gpu/v4l2_video_decode_accelerator.h

Issue 2191263002: V4L2VideoDecodeAccelerator: support external buffer import (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small refactor Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 VideoDecodeAccelerator 5 // This file contains an implementation of VideoDecodeAccelerator
6 // that utilizes hardware video decoders, which expose Video4Linux 2 API 6 // that utilizes hardware video decoders, which expose Video4Linux 2 API
7 // (http://linuxtv.org/downloads/v4l-dvb-apis/). 7 // (http://linuxtv.org/downloads/v4l-dvb-apis/).
8 8
9 #ifndef MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_ 9 #ifndef MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_
10 #define MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_ 10 #define MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_
11 11
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 14
15 #include <list>
15 #include <memory> 16 #include <memory>
16 #include <queue> 17 #include <queue>
17 #include <vector> 18 #include <vector>
18 19
19 #include "base/callback_forward.h" 20 #include "base/callback_forward.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/memory/linked_ptr.h" 22 #include "base/memory/linked_ptr.h"
22 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
23 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
24 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const GetGLContextCallback& get_gl_context_cb, 93 const GetGLContextCallback& get_gl_context_cb,
93 const MakeGLContextCurrentCallback& make_context_current_cb, 94 const MakeGLContextCurrentCallback& make_context_current_cb,
94 const scoped_refptr<V4L2Device>& device); 95 const scoped_refptr<V4L2Device>& device);
95 ~V4L2VideoDecodeAccelerator() override; 96 ~V4L2VideoDecodeAccelerator() override;
96 97
97 // VideoDecodeAccelerator implementation. 98 // VideoDecodeAccelerator implementation.
98 // Note: Initialize() and Destroy() are synchronous. 99 // Note: Initialize() and Destroy() are synchronous.
99 bool Initialize(const Config& config, Client* client) override; 100 bool Initialize(const Config& config, Client* client) override;
100 void Decode(const BitstreamBuffer& bitstream_buffer) override; 101 void Decode(const BitstreamBuffer& bitstream_buffer) override;
101 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override; 102 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override;
103 void ImportBufferForPicture(
104 int32_t picture_buffer_id,
105 const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handles) override;
102 void ReusePictureBuffer(int32_t picture_buffer_id) override; 106 void ReusePictureBuffer(int32_t picture_buffer_id) override;
103 void Flush() override; 107 void Flush() override;
104 void Reset() override; 108 void Reset() override;
105 void Destroy() override; 109 void Destroy() override;
106 bool TryToSetupDecodeOnSeparateThread( 110 bool TryToSetupDecodeOnSeparateThread(
107 const base::WeakPtr<Client>& decode_client, 111 const base::WeakPtr<Client>& decode_client,
108 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) 112 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner)
109 override; 113 override;
110 114
111 static VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(); 115 static VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 180
177 // Record for output buffers. 181 // Record for output buffers.
178 struct OutputRecord { 182 struct OutputRecord {
179 OutputRecord(); 183 OutputRecord();
180 OutputRecord(OutputRecord&&) = default; 184 OutputRecord(OutputRecord&&) = default;
181 ~OutputRecord(); 185 ~OutputRecord();
182 OutputRecordState state; 186 OutputRecordState state;
183 EGLImageKHR egl_image; // EGLImageKHR for the output buffer. 187 EGLImageKHR egl_image; // EGLImageKHR for the output buffer.
184 EGLSyncKHR egl_sync; // sync the compositor's use of the EGLImage. 188 EGLSyncKHR egl_sync; // sync the compositor's use of the EGLImage.
185 int32_t picture_id; // picture buffer id as returned to PictureReady(). 189 int32_t picture_id; // picture buffer id as returned to PictureReady().
190 GLuint texture_id;
186 bool cleared; // Whether the texture is cleared and safe to render 191 bool cleared; // Whether the texture is cleared and safe to render
187 // from. See TextureManager for details. 192 // from. See TextureManager for details.
188 // Exported fds for image processor to import. 193 // Input fds of the processor. Exported from the decoder.
189 std::vector<base::ScopedFD> fds; 194 std::vector<base::ScopedFD> processor_input_fds;
195 // Output fds of the processor. Used only when OutputMode is IMPORT.
196 std::vector<base::ScopedFD> processor_output_fds;
190 }; 197 };
191 198
192 // 199 //
193 // Decoding tasks, to be run on decode_thread_. 200 // Decoding tasks, to be run on decode_thread_.
194 // 201 //
195 202
196 // Enqueue a BitstreamBuffer to decode. This will enqueue a buffer to the 203 // Enqueue a BitstreamBuffer to decode. This will enqueue a buffer to the
197 // decoder_input_queue_, then queue a DecodeBufferTask() to actually decode 204 // decoder_input_queue_, then queue a DecodeBufferTask() to actually decode
198 // the buffer. 205 // the buffer.
199 void DecodeTask(const BitstreamBuffer& bitstream_buffer); 206 void DecodeTask(const BitstreamBuffer& bitstream_buffer);
(...skipping 15 matching lines...) Expand all
215 // non-error conditions; for example when pipeline is full and should be 222 // non-error conditions; for example when pipeline is full and should be
216 // retried later. 223 // retried later.
217 bool AppendToInputFrame(const void* data, size_t size); 224 bool AppendToInputFrame(const void* data, size_t size);
218 // Flush data for one decoded frame. 225 // Flush data for one decoded frame.
219 bool FlushInputFrame(); 226 bool FlushInputFrame();
220 227
221 // Allocate V4L2 buffers and assign them to |buffers| provided by the client 228 // Allocate V4L2 buffers and assign them to |buffers| provided by the client
222 // via AssignPictureBuffers() on decoder thread. 229 // via AssignPictureBuffers() on decoder thread.
223 void AssignPictureBuffersTask(const std::vector<PictureBuffer>& buffers); 230 void AssignPictureBuffersTask(const std::vector<PictureBuffer>& buffers);
224 231
225 // Create EGLImages bound to textures in |buffers| for given 232 // Use buffer backed by dmabuf file descriptors in |dmabuf_fds| for the
226 // |output_format_fourcc| and |output_planes_count|. 233 // OutputRecord associated with |picture_buffer_id|, taking ownership of the
227 void CreateEGLImages(const std::vector<media::PictureBuffer>& buffers, 234 // file descriptors. |stride| is the coded width of the buffer.
228 uint32_t output_format_fourcc, 235 void ImportBufferForPictureTask(int32_t picture_buffer_id,
229 size_t output_planes_count); 236 std::vector<base::ScopedFD> dmabuf_fds,
237 int32_t stride);
230 238
231 // Assign |egl_images| to previously-allocated V4L2 buffers in 239 // Create an EGLImage for the buffer associated with V4L2 |buffer_index| and
232 // output_buffer_map_ and picture ids from |buffers| and finish the resolution 240 // for |picture_buffer_id|, backed by dmabuf file descriptors in
233 // change sequence. 241 // |passed_dmabuf_fds|, taking ownership of them.
234 void AssignEGLImages(const std::vector<media::PictureBuffer>& buffers, 242 // The buffer should be bound to |texture_id| and is of |size| and format
235 const std::vector<EGLImageKHR>& egl_images); 243 // described by |fourcc|.
244 void CreateEGLImageFor(size_t buffer_index,
245 int32_t picture_buffer_id,
246 std::vector<base::ScopedFD> dmabuf_fds,
247 GLuint texture_id,
248 const gfx::Size& size,
249 uint32_t fourcc);
250
251 // Take the EGLImage |egl_image|, created for |picture_buffer_id|, and use it
252 // for OutputRecord at |buffer_index|. The buffer is backed by
253 // |passed_dmabuf_fds|, and the OutputRecord takes ownership of them.
254 void AssignEGLImage(size_t buffer_index,
255 int32_t picture_buffer_id,
256 EGLImageKHR egl_image,
257 std::vector<base::ScopedFD> dmabuf_fds);
236 258
237 // Service I/O on the V4L2 devices. This task should only be scheduled from 259 // Service I/O on the V4L2 devices. This task should only be scheduled from
238 // DevicePollTask(). If |event_pending| is true, one or more events 260 // DevicePollTask(). If |event_pending| is true, one or more events
239 // on file descriptor are pending. 261 // on file descriptor are pending.
240 void ServiceDeviceTask(bool event_pending); 262 void ServiceDeviceTask(bool event_pending);
241 // Handle the various device queues. 263 // Handle the various device queues.
242 void Enqueue(); 264 void Enqueue();
243 void Dequeue(); 265 void Dequeue();
244 266
245 // Return true if there is a resolution change event pending. 267 // Return true if there is a resolution change event pending.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 bool CreateInputBuffers(); 351 bool CreateInputBuffers();
330 bool CreateOutputBuffers(); 352 bool CreateOutputBuffers();
331 353
332 // Set input and output formats before starting decode. 354 // Set input and output formats before starting decode.
333 bool SetupFormats(); 355 bool SetupFormats();
334 // Return a usable input format of image processor. Return 0 if not found. 356 // Return a usable input format of image processor. Return 0 if not found.
335 uint32_t FindImageProcessorInputFormat(); 357 uint32_t FindImageProcessorInputFormat();
336 // Return a usable output format of image processor. Return 0 if not found. 358 // Return a usable output format of image processor. Return 0 if not found.
337 uint32_t FindImageProcessorOutputFormat(); 359 uint32_t FindImageProcessorOutputFormat();
338 360
361 bool CreateImageProcessor();
362 // Send a frame to the image processor to process. The index of decoder
363 // output buffer is |output_buffer_index| and its id is |bitstream_buffer_id|.
364 bool ProcessFrame(int32_t bitstream_buffer_id, int output_buffer_index);
365
339 // 366 //
340 // Methods run on child thread. 367 // Methods run on child thread.
341 // 368 //
342 369
343 // Destroy buffers. 370 // Destroy buffers.
344 void DestroyInputBuffers(); 371 void DestroyInputBuffers();
345 // In contrast to DestroyInputBuffers, which is called only from destructor, 372 // In contrast to DestroyInputBuffers, which is called only from destructor,
346 // we call DestroyOutputBuffers also during playback, on resolution change. 373 // we call DestroyOutputBuffers also during playback, on resolution change.
347 // Even if anything fails along the way, we still want to go on and clean 374 // Even if anything fails along the way, we still want to go on and clean
348 // up as much as possible, so return false if this happens, so that the 375 // up as much as possible, so return false if this happens, so that the
349 // caller can error out on resolution change. 376 // caller can error out on resolution change.
350 bool DestroyOutputBuffers(); 377 bool DestroyOutputBuffers();
378 bool DestroyEGLImages();
351 void ResolutionChangeDestroyBuffers(); 379 void ResolutionChangeDestroyBuffers();
352 380
353 // Send decoded pictures to PictureReady. 381 // Send decoded pictures to PictureReady.
354 void SendPictureReady(); 382 void SendPictureReady();
355 383
356 // Callback that indicates a picture has been cleared. 384 // Callback that indicates a picture has been cleared.
357 void PictureCleared(); 385 void PictureCleared();
358 386
359 // Image processor returns a processed frame. Its id is |bitstream_buffer_id| 387 // Image processor returns a processed frame. Its id is |bitstream_buffer_id|
360 // and stored in |output_buffer_index| buffer of image processor. 388 // and stored in |output_buffer_index| buffer of image processor.
(...skipping 29 matching lines...) Expand all
390 // Before decoder_thread_ has started, the decoder state is managed by 418 // Before decoder_thread_ has started, the decoder state is managed by
391 // the child (main) thread. After decoder_thread_ has started, the decoder 419 // the child (main) thread. After decoder_thread_ has started, the decoder
392 // thread should be the only one managing these. 420 // thread should be the only one managing these.
393 // 421 //
394 422
395 // This thread services tasks posted from the VDA API entry points by the 423 // This thread services tasks posted from the VDA API entry points by the
396 // child thread and device service callbacks posted from the device thread. 424 // child thread and device service callbacks posted from the device thread.
397 base::Thread decoder_thread_; 425 base::Thread decoder_thread_;
398 // Decoder state machine state. 426 // Decoder state machine state.
399 State decoder_state_; 427 State decoder_state_;
428
429 Config::OutputMode output_mode_;
430
400 // BitstreamBuffer we're presently reading. 431 // BitstreamBuffer we're presently reading.
401 std::unique_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_; 432 std::unique_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_;
402 // The V4L2Device this class is operating upon. 433 // The V4L2Device this class is operating upon.
403 scoped_refptr<V4L2Device> device_; 434 scoped_refptr<V4L2Device> device_;
404 // FlushTask() and ResetTask() should not affect buffers that have been 435 // FlushTask() and ResetTask() should not affect buffers that have been
405 // queued afterwards. For flushing or resetting the pipeline then, we will 436 // queued afterwards. For flushing or resetting the pipeline then, we will
406 // delay these buffers until after the flush or reset completes. 437 // delay these buffers until after the flush or reset completes.
407 int decoder_delay_bitstream_buffer_id_; 438 int decoder_delay_bitstream_buffer_id_;
408 // Input buffer we're presently filling. 439 // Input buffer we're presently filling.
409 int decoder_current_input_buffer_; 440 int decoder_current_input_buffer_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 std::vector<int> free_input_buffers_; 477 std::vector<int> free_input_buffers_;
447 // Mapping of int index to input buffer record. 478 // Mapping of int index to input buffer record.
448 std::vector<InputRecord> input_buffer_map_; 479 std::vector<InputRecord> input_buffer_map_;
449 480
450 // Output buffer state. 481 // Output buffer state.
451 bool output_streamon_; 482 bool output_streamon_;
452 // Output buffers enqueued to device. 483 // Output buffers enqueued to device.
453 int output_buffer_queued_count_; 484 int output_buffer_queued_count_;
454 // Output buffers ready to use, as a FIFO since we want oldest-first to hide 485 // Output buffers ready to use, as a FIFO since we want oldest-first to hide
455 // synchronization latency with GL. 486 // synchronization latency with GL.
456 std::queue<int> free_output_buffers_; 487 std::list<int> free_output_buffers_;
457 // Mapping of int index to output buffer record. 488 // Mapping of int index to output buffer record.
458 std::vector<OutputRecord> output_buffer_map_; 489 std::vector<OutputRecord> output_buffer_map_;
459 // Required size of DPB for decoding. 490 // Required size of DPB for decoding.
460 int output_dpb_size_; 491 int output_dpb_size_;
461 492
462 // Number of planes (i.e. separate memory buffers) for output. 493 // Number of planes (i.e. separate memory buffers) for output.
463 size_t output_planes_count_; 494 size_t output_planes_count_;
464 495
465 // Pictures that are ready but not sent to PictureReady yet. 496 // Pictures that are ready but not sent to PictureReady yet.
466 std::queue<PictureRecord> pending_picture_ready_; 497 std::queue<PictureRecord> pending_picture_ready_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 553
523 // The WeakPtrFactory for |weak_this_|. 554 // The WeakPtrFactory for |weak_this_|.
524 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; 555 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_;
525 556
526 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); 557 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator);
527 }; 558 };
528 559
529 } // namespace media 560 } // namespace media
530 561
531 #endif // MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_ 562 #endif // MEDIA_GPU_V4L2_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698