| 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 <memory> | |
| 10 #include <queue> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "chrome/gpu/arc_video_accelerator.h" | |
| 16 #include "gpu/command_buffer/service/gpu_preferences.h" | |
| 17 #include "media/video/video_decode_accelerator.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 namespace arc { | |
| 21 | |
| 22 // This class is executed in the GPU process. It takes decoding requests from | |
| 23 // ARC via IPC channels and translates and sends those requests to an | |
| 24 // implementation of media::VideoDecodeAccelerator. It also returns the decoded | |
| 25 // frames back to the ARC side. | |
| 26 class ArcGpuVideoDecodeAccelerator | |
| 27 : public ArcVideoAccelerator, | |
| 28 public media::VideoDecodeAccelerator::Client, | |
| 29 public base::SupportsWeakPtr<ArcGpuVideoDecodeAccelerator> { | |
| 30 public: | |
| 31 explicit ArcGpuVideoDecodeAccelerator( | |
| 32 const gpu::GpuPreferences& gpu_preferences); | |
| 33 ~ArcGpuVideoDecodeAccelerator() override; | |
| 34 | |
| 35 // Implementation of the ArcVideoAccelerator interface. | |
| 36 ArcVideoAccelerator::Result Initialize( | |
| 37 const Config& config, | |
| 38 ArcVideoAccelerator::Client* client) override; | |
| 39 void SetNumberOfOutputBuffers(size_t number) override; | |
| 40 void BindSharedMemory(PortType port, | |
| 41 uint32_t index, | |
| 42 base::ScopedFD ashmem_fd, | |
| 43 off_t offset, | |
| 44 size_t length) override; | |
| 45 void BindDmabuf(PortType port, | |
| 46 uint32_t index, | |
| 47 base::ScopedFD dmabuf_fd, | |
| 48 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& | |
| 49 dmabuf_planes) override; | |
| 50 void UseBuffer(PortType port, | |
| 51 uint32_t index, | |
| 52 const BufferMetadata& metadata) override; | |
| 53 void Reset() override; | |
| 54 void Flush() override; | |
| 55 | |
| 56 // Implementation of the VideoDecodeAccelerator::Client interface. | |
| 57 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, | |
| 58 media::VideoPixelFormat output_format, | |
| 59 uint32_t textures_per_buffer, | |
| 60 const gfx::Size& dimensions, | |
| 61 uint32_t texture_target) override; | |
| 62 void DismissPictureBuffer(int32_t picture_buffer) override; | |
| 63 void PictureReady(const media::Picture& picture) override; | |
| 64 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; | |
| 65 void NotifyFlushDone() override; | |
| 66 void NotifyResetDone() override; | |
| 67 void NotifyError(media::VideoDecodeAccelerator::Error error) override; | |
| 68 | |
| 69 private: | |
| 70 // Some information related to a bitstream buffer. The information is required | |
| 71 // when input or output buffers are returned back to the client. | |
| 72 struct InputRecord { | |
| 73 int32_t bitstream_buffer_id; | |
| 74 uint32_t buffer_index; | |
| 75 int64_t timestamp; | |
| 76 | |
| 77 InputRecord(int32_t bitstream_buffer_id, | |
| 78 uint32_t buffer_index, | |
| 79 int64_t timestamp); | |
| 80 }; | |
| 81 | |
| 82 // The information about the shared memory used as an input buffer. | |
| 83 struct InputBufferInfo { | |
| 84 // The file handle to access the buffer. It is owned by this class and | |
| 85 // should be closed after use. | |
| 86 base::ScopedFD handle; | |
| 87 | |
| 88 // The offset of the payload to the beginning of the shared memory. | |
| 89 off_t offset = 0; | |
| 90 | |
| 91 // The size of the payload in bytes. | |
| 92 size_t length = 0; | |
| 93 | |
| 94 InputBufferInfo(); | |
| 95 InputBufferInfo(InputBufferInfo&& other); | |
| 96 ~InputBufferInfo(); | |
| 97 }; | |
| 98 | |
| 99 // The information about the dmabuf used as an output buffer. | |
| 100 struct OutputBufferInfo { | |
| 101 base::ScopedFD handle; | |
| 102 std::vector<::arc::ArcVideoAcceleratorDmabufPlane> planes; | |
| 103 | |
| 104 OutputBufferInfo(); | |
| 105 OutputBufferInfo(OutputBufferInfo&& other); | |
| 106 ~OutputBufferInfo(); | |
| 107 }; | |
| 108 | |
| 109 // The helper method to simplify reporting of the status returned to UMA. | |
| 110 ArcVideoAccelerator::Result InitializeTask( | |
| 111 const Config& config, | |
| 112 ArcVideoAccelerator::Client* client); | |
| 113 | |
| 114 // Helper function to validate |port| and |index|. | |
| 115 bool ValidatePortAndIndex(PortType port, uint32_t index) const; | |
| 116 | |
| 117 // Return true if |dmabuf_planes| is valid for a dmabuf |fd|. | |
| 118 bool VerifyDmabuf(const base::ScopedFD& fd, | |
| 119 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& | |
| 120 dmabuf_planes) const; | |
| 121 | |
| 122 // Creates an InputRecord for the given |bitstream_buffer_id|. The | |
| 123 // |buffer_index| is the index of the associated input buffer. The |timestamp| | |
| 124 // is the time the video frame should be displayed. | |
| 125 void CreateInputRecord(int32_t bitstream_buffer_id, | |
| 126 uint32_t buffer_index, | |
| 127 int64_t timestamp); | |
| 128 | |
| 129 // Finds the InputRecord which matches to given |bitstream_buffer_id|. | |
| 130 // Returns |nullptr| if it cannot be found. | |
| 131 InputRecord* FindInputRecord(int32_t bitstream_buffer_id); | |
| 132 | |
| 133 // Notify the client when output format changes. | |
| 134 void NotifyOutputFormatChanged(); | |
| 135 | |
| 136 // Global counter that keeps track the number of active clients (i.e., how | |
| 137 // many VDAs in use by this class). | |
| 138 // Since this class only works on the same thread, it's safe to access | |
| 139 // |client_count_| without lock. | |
| 140 static int client_count_; | |
| 141 | |
| 142 std::unique_ptr<media::VideoDecodeAccelerator> vda_; | |
| 143 | |
| 144 // It's safe to use the pointer here, the life cycle of the |arc_client_| | |
| 145 // is longer than this ArcGpuVideoDecodeAccelerator. | |
| 146 ArcVideoAccelerator::Client* arc_client_; | |
| 147 | |
| 148 // The next ID for the bitstream buffer, started from 0. | |
| 149 int32_t next_bitstream_buffer_id_; | |
| 150 | |
| 151 gfx::Size coded_size_; | |
| 152 gfx::Rect visible_rect_; | |
| 153 media::VideoPixelFormat output_pixel_format_; | |
| 154 | |
| 155 // A list of most recent |kMaxNumberOfInputRecord| InputRecords. | |
| 156 // |kMaxNumberOfInputRecord| is defined in the cc file. | |
| 157 std::list<InputRecord> input_records_; | |
| 158 | |
| 159 // The details of the shared memory of each input buffers. | |
| 160 std::vector<InputBufferInfo> input_buffer_info_; | |
| 161 | |
| 162 // To keep those output buffers which have been bound by bindDmabuf() but | |
| 163 // haven't been passed to VDA yet. Will call VDA::ImportBufferForPicture() | |
| 164 // when those buffers are used for the first time. | |
| 165 std::vector<OutputBufferInfo> buffers_pending_import_; | |
| 166 | |
| 167 base::ThreadChecker thread_checker_; | |
| 168 size_t output_buffer_size_; | |
| 169 | |
| 170 // The minimal number of requested output buffers. | |
| 171 uint32_t requested_num_of_output_buffers_; | |
| 172 | |
| 173 gpu::GpuPreferences gpu_preferences_; | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(ArcGpuVideoDecodeAccelerator); | |
| 176 }; | |
| 177 | |
| 178 } // namespace arc | |
| 179 } // namespace chromeos | |
| 180 | |
| 181 #endif // CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_ | |
| OLD | NEW |