OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <queue> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "chrome/gpu/arc_video_accelerator.h" |
| 16 #include "media/video/video_decode_accelerator.h" |
| 17 |
| 18 namespace chromeos { |
| 19 namespace arc { |
| 20 |
| 21 // This class is executed in Chromium's GPU process. It takes decoding requests |
| 22 // from ARC via IPC channels and translates and send those requests to an |
| 23 // implementation of the VideoDecodeAccelerator interface on Chromium. It also |
| 24 // returns the decoded frames back to the ARC side. |
| 25 class ArcGpuVideoDecodeAccelerator |
| 26 : public ArcVideoAccelerator, |
| 27 public media::VideoDecodeAccelerator::Client, |
| 28 public base::SupportsWeakPtr<ArcGpuVideoDecodeAccelerator> { |
| 29 public: |
| 30 ArcGpuVideoDecodeAccelerator(); |
| 31 ~ArcGpuVideoDecodeAccelerator() override; |
| 32 |
| 33 // Implementation of the ArcVideoAccelerator interface. |
| 34 bool Initialize(const Config& config, |
| 35 ArcVideoAccelerator::Client* client) override; |
| 36 void SetNumberOfOutputBuffers(size_t number) override; |
| 37 void BindSharedMemory(PortType port, |
| 38 uint32_t index, |
| 39 int ashmem_fd, |
| 40 off_t offset, |
| 41 size_t length) override; |
| 42 void BindDmabuf(PortType port, uint32_t index, int dmabuf_fd) override; |
| 43 void UseBuffer(PortType port, |
| 44 uint32_t index, |
| 45 const BufferMetadata& metadata) override; |
| 46 void Reset() override; |
| 47 |
| 48 // Implementation of the VideoDecodeAccelerator::Client interface. |
| 49 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, |
| 50 const gfx::Size& dimensions, |
| 51 uint32_t texture_target) override; |
| 52 void DismissPictureBuffer(int32_t picture_buffer) override; |
| 53 void PictureReady(const media::Picture& picture) override; |
| 54 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; |
| 55 void NotifyFlushDone() override; |
| 56 void NotifyResetDone() override; |
| 57 void NotifyError(media::VideoDecodeAccelerator::Error error) override; |
| 58 |
| 59 private: |
| 60 struct InputRecord { |
| 61 int32_t bitstream_buffer_id; |
| 62 uint32_t buffer_index; |
| 63 int64_t timestamp; |
| 64 |
| 65 InputRecord(int32_t bitstream_buffer_id, |
| 66 uint32_t buffer_index, |
| 67 int64_t timestamp); |
| 68 }; |
| 69 |
| 70 struct InputBufferInfo { |
| 71 // The file handle to access the buffer. It is owned by this class and |
| 72 // should be closed after use. |
| 73 base::ScopedFD handle; |
| 74 off_t offset = 0; |
| 75 size_t length = 0; |
| 76 }; |
| 77 |
| 78 // Helper function to Send the end-of-stream output buffer if |
| 79 // |pending_eos_output_buffer_| is true, or reuse the picture in ArcVDA. |
| 80 void SendEosIfNeededOrReusePicture(uint32_t index); |
| 81 |
| 82 // Helper function to validate |port| and |index|. |
| 83 bool ValidatePortAndIndex(PortType port, uint32_t index); |
| 84 |
| 85 // Sets InputRecord for the given |bitstream_buffer_id|. The |buffer_index| |
| 86 // is the index of the associated input buffer. The |timestamp| is the |
| 87 // time the video frame should be displayed. |
| 88 void SetInputRecord(int32_t bitstream_buffer_id, |
| 89 uint32_t buffer_index, |
| 90 int64_t timestamp); |
| 91 |
| 92 // Finds the InputRecord which matches to given |bitstream_buffer_id|. |
| 93 // Returns |nullptr| if it cannot be found. |
| 94 InputRecord* FindInputRecord(int32_t bitstream_buffer_id); |
| 95 |
| 96 // When true, an EOS output buffer need to be sent to |arc_client_| once an |
| 97 // output buffer is available. |
| 98 bool pending_eos_output_buffer_; |
| 99 scoped_ptr<media::VideoDecodeAccelerator> vda_; |
| 100 |
| 101 // It's safe to use the pointer here, the life cycle of the |arc_client_| |
| 102 // is longer than this ArcGpuVideoDecodeAccelerator. |
| 103 ArcVideoAccelerator::Client* arc_client_; |
| 104 |
| 105 // The callback called when reset completes. |
| 106 base::Closure reset_done_callback_; |
| 107 |
| 108 // The next ID for the bitstream buffer, started from 0. |
| 109 int32_t next_bitstream_buffer_id_; |
| 110 |
| 111 gfx::Size coded_size_; |
| 112 |
| 113 // The |picture_buffer_id|s for Picutres that were returned to us from VDA |
| 114 // via PictureReady() while flushing. We keep them until NotifyFlushDone(); |
| 115 // once it's called, we send one of the pending buffers from this queue (if |
| 116 // not empty), marked with an EOS flag, to |arc_client_|, and return the rest |
| 117 // to VDA for reuse. |
| 118 std::queue<int32_t> buffers_pending_eos_; |
| 119 std::list<InputRecord> input_records_; |
| 120 std::vector<InputBufferInfo> input_buffer_info_; |
| 121 |
| 122 // To keep those output buffers which have been bound by bindDmabuf() but not |
| 123 // be used yet. Will call VDA::ImportBufferForPicture() when those buffer are |
| 124 // used for the first time. |
| 125 std::vector<base::ScopedFD> pending_import_buffer_; |
| 126 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 127 base::ThreadChecker thread_checker_; |
| 128 size_t output_buffer_size_; |
| 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(ArcGpuVideoDecodeAccelerator); |
| 131 }; |
| 132 |
| 133 } // namespace arc |
| 134 } // namespace chromeos |
| 135 |
| 136 #endif // CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |