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

Side by Side Diff: chrome/gpu/arc_gpu_video_decode_accelerator.h

Issue 1549473002: Add ArcGpuVideoDecodeAccelerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add out-of-line ctor/dtor Created 4 years, 8 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
« no previous file with comments | « chrome/gpu/BUILD.gn ('k') | chrome/gpu/arc_gpu_video_decode_accelerator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "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 ArcGpuVideoDecodeAccelerator();
32 ~ArcGpuVideoDecodeAccelerator() override;
33
34 // Implementation of the ArcVideoAccelerator interface.
35 bool Initialize(const Config& config,
36 ArcVideoAccelerator::Client* client) override;
37 void SetNumberOfOutputBuffers(size_t number) override;
38 void BindSharedMemory(PortType port,
39 uint32_t index,
40 base::ScopedFD ashmem_fd,
41 off_t offset,
42 size_t length) override;
43 void BindDmabuf(PortType port,
44 uint32_t index,
45 base::ScopedFD dmabuf_fd) override;
46 void UseBuffer(PortType port,
47 uint32_t index,
48 const BufferMetadata& metadata) override;
49 void Reset() override;
50
51 // Implementation of the VideoDecodeAccelerator::Client interface.
52 void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
53 uint32_t textures_per_buffer,
54 const gfx::Size& dimensions,
55 uint32_t texture_target) override;
56 void DismissPictureBuffer(int32_t picture_buffer) override;
57 void PictureReady(const media::Picture& picture) override;
58 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override;
59 void NotifyFlushDone() override;
60 void NotifyResetDone() override;
61 void NotifyError(media::VideoDecodeAccelerator::Error error) override;
62
63 private:
64 // Some information related to a bitstream buffer. The information is required
65 // when input or output buffers are returned back to the client.
66 struct InputRecord {
67 int32_t bitstream_buffer_id;
68 uint32_t buffer_index;
69 int64_t timestamp;
70
71 InputRecord(int32_t bitstream_buffer_id,
72 uint32_t buffer_index,
73 int64_t timestamp);
74 };
75
76 // The information about the shared memory used as an input buffer.
77 struct InputBufferInfo {
78 // The file handle to access the buffer. It is owned by this class and
79 // should be closed after use.
80 base::ScopedFD handle;
81 off_t offset;
82 size_t length;
83
84 InputBufferInfo();
85 InputBufferInfo(InputBufferInfo&& other);
86 ~InputBufferInfo();
87 };
88
89 // Helper function to Send the end-of-stream output buffer if
90 // |pending_eos_output_buffer_| is true, or reuse the picture in ArcVDA.
91 void SendEosIfNeededOrReusePicture(uint32_t index);
92
93 // Helper function to validate |port| and |index|.
94 bool ValidatePortAndIndex(PortType port, uint32_t index);
95
96 // Creates an InputRecord for the given |bitstream_buffer_id|. The
97 // |buffer_index| is the index of the associated input buffer. The |timestamp|
98 // is the time the video frame should be displayed.
99 void CreateInputRecord(int32_t bitstream_buffer_id,
100 uint32_t buffer_index,
101 int64_t timestamp);
102
103 // Finds the InputRecord which matches to given |bitstream_buffer_id|.
104 // Returns |nullptr| if it cannot be found.
105 InputRecord* FindInputRecord(int32_t bitstream_buffer_id);
106
107 // When true, an EOS output buffer need to be sent to |arc_client_| once an
108 // output buffer is available.
109 bool pending_eos_output_buffer_;
110
111 scoped_ptr<media::VideoDecodeAccelerator> vda_;
112
113 // It's safe to use the pointer here, the life cycle of the |arc_client_|
114 // is longer than this ArcGpuVideoDecodeAccelerator.
115 ArcVideoAccelerator::Client* arc_client_;
116
117 // The next ID for the bitstream buffer, started from 0.
118 int32_t next_bitstream_buffer_id_;
119
120 gfx::Size coded_size_;
121
122 // The |picture_buffer_id|s for Pictures that were returned to us from VDA
123 // via PictureReady() while flushing. We keep them until NotifyFlushDone();
124 // once it's called, we send one of the pending buffers from this queue (if
125 // not empty), marked with an EOS flag, to |arc_client_|, and return the rest
126 // to VDA for reuse.
127 std::queue<int32_t> buffers_pending_eos_;
128
129 // A list of most recent |kMaxNumberOfInputRecord| InputRecords.
130 // |kMaxNumberOfInputRecord| is defined in the cc file.
131 std::list<InputRecord> input_records_;
132
133 // The details of the shared memory of each input buffers.
134 std::vector<InputBufferInfo> input_buffer_info_;
135
136 // To keep those output buffers which have been bound by bindDmabuf() but not
137 // be used yet. Will call VDA::ImportBufferForPicture() when those buffers are
138 // used for the first time.
139 std::vector<base::ScopedFD> buffers_pending_import_;
140
141 base::ThreadChecker thread_checker_;
142 size_t output_buffer_size_;
143
144 gpu::GpuPreferences gpu_preferences_;
145
146 DISALLOW_COPY_AND_ASSIGN(ArcGpuVideoDecodeAccelerator);
147 };
148
149 } // namespace arc
150 } // namespace chromeos
151
152 #endif // CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW
« no previous file with comments | « chrome/gpu/BUILD.gn ('k') | chrome/gpu/arc_gpu_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698