OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_ | |
7 | |
8 #include <queue> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/linked_ptr.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/single_thread_task_runner.h" | |
15 #include "base/threading/thread.h" | |
16 #include "content/common/content_export.h" | |
17 #include "content/common/gpu/media/v4l2_device.h" | |
18 #include "media/base/bitstream_buffer.h" | |
19 #include "media/base/video_frame.h" | |
20 #include "media/video/jpeg_decode_accelerator.h" | |
21 | |
22 namespace content { | |
23 | |
24 class CONTENT_EXPORT V4L2JpegDecodeAccelerator | |
25 : public media::JpegDecodeAccelerator { | |
26 public: | |
27 V4L2JpegDecodeAccelerator( | |
28 const scoped_refptr<V4L2Device>& device, | |
29 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
30 ~V4L2JpegDecodeAccelerator() override; | |
31 | |
32 // Note: Initialize() are synchronous. | |
wuchengli
2015/06/12 11:07:37
What do you mean it's synchronous? It posts a Star
Pawel Osciak
2015/06/16 07:13:22
I believe this is because returning true from here
henryhsu
2015/06/16 09:37:25
Modified comments.
| |
33 bool Initialize(Client* client) override; | |
Pawel Osciak
2015/06/16 07:13:22
Nit:
// media::JpegDecodeAccelerator implementatio
henryhsu
2015/06/16 09:37:24
Done.
| |
34 | |
35 void Decode(const media::BitstreamBuffer& bitstream_buffer, | |
36 const scoped_refptr<media::VideoFrame>& video_frame) override; | |
37 | |
38 private: | |
39 // Record for input buffers. | |
40 struct InputRecord { | |
41 InputRecord(); | |
42 ~InputRecord(); | |
43 void* address; // mmap() address. | |
44 size_t length; // mmap() length. | |
45 bool at_device; | |
wuchengli
2015/06/12 11:07:37
Explain what this means.
henryhsu
2015/06/16 09:37:24
Done.
| |
46 }; | |
47 | |
48 // Record for output buffers. | |
49 struct OutputRecord { | |
Pawel Osciak
2015/06/16 07:13:22
InputRecord and OutputRecord are identical. Could
henryhsu
2015/06/16 09:37:25
Done.
| |
50 OutputRecord(); | |
51 ~OutputRecord(); | |
52 void* address; // mmap() address. | |
53 size_t length; // mmap() length. | |
54 bool at_device; | |
wuchengli
2015/06/12 11:07:37
Explain what this means.
henryhsu
2015/06/16 09:37:24
Done.
| |
55 }; | |
56 | |
57 // Job record. Jobs are processed in a FIFO order. This is separate from | |
58 // InputRecord, because an InputRecord may be returned before we dequeue | |
59 // the corresponding output buffer. It can't always be associated with | |
60 // an OutputRecord immediately either, because at the time of submission we | |
61 // may not have one available (and don't need one to submit input to the | |
62 // device). | |
63 struct JobRecord { | |
64 JobRecord(media::BitstreamBuffer bitstream_buffer, | |
65 scoped_refptr<media::VideoFrame> video_frame); | |
66 ~JobRecord(); | |
67 media::BitstreamBuffer bitstream_buffer; | |
68 scoped_refptr<media::VideoFrame> frame; | |
69 }; | |
70 | |
71 enum { | |
72 // Arbitrarily tuned. | |
73 kInputBufferCount = 2, | |
Pawel Osciak
2015/06/16 07:13:22
We always want to have inputcount == outputcount,
henryhsu
2015/06/16 09:37:25
Done.
| |
74 kOutputBufferCount = 2, | |
75 }; | |
76 | |
77 enum { | |
78 kResetInputBuffer = 1 << 0, | |
79 kResetOutputBuffer = 1 << 1, | |
80 }; | |
81 | |
82 void Enqueue(); | |
83 void Dequeue(); | |
84 bool EnqueueInputRecord(); | |
85 bool EnqueueOutputRecord(); | |
86 bool CheckBufferAttributes(); | |
wuchengli
2015/06/12 11:07:37
Add documentation for this.
henryhsu
2015/06/16 09:37:24
Done.
| |
87 bool CreateInputBuffers(); | |
88 bool CreateOutputBuffers(); | |
89 void DestroyInputBuffers(); | |
90 void DestroyOutputBuffers(); | |
91 void ResetBuffers(); | |
wuchengli
2015/06/12 11:07:37
Add documentation for this.
henryhsu
2015/06/16 09:37:25
Done.
| |
92 | |
93 void NotifyError(int32_t bitstream_buffer_id, Error error); | |
94 void NotifyErrorFromDecoderThread(int32_t bitstream_buffer_id, Error error); | |
95 void DestroyTask(); | |
wuchengli
2015/06/12 11:07:37
Add documentation for this.
I think DestroyTask s
henryhsu
2015/06/16 09:37:25
Done.
| |
96 | |
97 void DecodeTask(scoped_ptr<JobRecord> job_record); | |
98 void ServiceDeviceTask(); | |
99 | |
100 // Attempt to start/stop device_poll_thread_. | |
wuchengli
2015/06/12 11:07:37
s/Attempt to//
henryhsu
2015/06/16 09:37:25
Done.
| |
101 void StartDevicePoll(); | |
102 bool StopDevicePoll(bool keep_input_queue); | |
103 | |
104 // Ran on device_poll_thread_ to wait for device events. | |
105 void DevicePollTask(); | |
106 | |
107 media::VideoFrame::Format output_format_; | |
wuchengli
2015/06/12 11:07:37
Add a blank line if there's comment. Same for all
henryhsu
2015/06/16 09:37:24
Done.
| |
108 // Record current image size for checking image size is changed or not. | |
wuchengli
2015/06/12 11:07:37
// Current image size used for checking if the siz
henryhsu
2015/06/16 09:37:24
Done.
| |
109 gfx::Size image_coded_size_; | |
110 // Set to true when input or output buffer have to re-allocate. | |
kcwu
2015/06/12 06:59:42
s/true/non-zero/
henryhsu
2015/06/16 09:37:25
Done.
| |
111 uint32_t reset_buffer_flag_; | |
wuchengli
2015/06/12 11:07:37
Two booleans is simpler than a bit mask. Just use
Pawel Osciak
2015/06/16 07:13:22
+1 to this.
henryhsu
2015/06/16 09:37:25
Done.
| |
112 | |
113 // ChildThread's task runner. | |
114 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | |
115 | |
116 // GPU IO task runner. | |
117 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
118 | |
119 // The client of this class. | |
120 Client* client_; | |
121 | |
122 // The V4L2Device this class is operating upon. | |
123 scoped_refptr<V4L2Device> device_; | |
124 | |
125 // Thread to communicate with the device on. | |
wuchengli
2015/06/12 11:07:37
I don't understand. Maybe you mean "Thread to comm
Pawel Osciak
2015/06/16 07:13:22
This sentence is grammatically correct actually. :
henryhsu
2015/06/16 09:37:24
Yes.
| |
126 base::Thread decoder_thread_; | |
127 // Decode task runner. | |
128 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; | |
129 // Thread used to poll the V4L2 for events only. | |
130 base::Thread device_poll_thread_; | |
131 // Device poll task runner. | |
132 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; | |
133 | |
134 // All the below members are to be accessed from decoder_thread_ only | |
wuchengli
2015/06/12 11:07:37
s/to be//
henryhsu
2015/06/16 09:37:25
Done.
| |
135 // (if it's running). | |
136 std::queue<linked_ptr<JobRecord> > input_queue_; | |
wuchengli
2015/06/12 11:07:37
The names of |input_queue_| and |running_jobs_| sh
Pawel Osciak
2015/06/16 07:13:22
How about job_input_queue_ as a compromise ? :)
henryhsu
2015/06/16 09:37:24
Done.
| |
137 std::queue<linked_ptr<JobRecord> > running_jobs_; | |
wuchengli
2015/06/15 07:55:28
I don't think you need to use linked_ptr for |inpu
Pawel Osciak
2015/06/16 07:13:22
JobRecord is base::Bound, so we'd have to make it
henryhsu
2015/06/16 09:37:25
As discussed, I prefer to keep linked_ptr here bec
| |
138 | |
139 // Input queue state. | |
140 bool input_streamon_; | |
141 // Number of input buffers enqueued to the device. | |
142 int input_buffer_queued_count_; | |
143 // Input buffers ready to use; LIFO since we don't care about ordering. | |
144 std::vector<int> free_input_buffers_; | |
145 // Mapping of int index to an input buffer record. | |
wuchengli
2015/06/12 11:07:37
This is not a map. Update the comment. s/input_buf
Pawel Osciak
2015/06/16 07:13:21
We use it as a map though. The position in the vec
henryhsu
2015/06/16 09:37:24
As Pawel said, I prefer to keep original name.
| |
146 std::vector<InputRecord> input_buffer_map_; | |
147 | |
148 // Output queue state. | |
149 bool output_streamon_; | |
150 // Number of output buffers enqueued to the device. | |
151 int output_buffer_queued_count_; | |
152 // Output buffers ready to use; LIFO since we don't care about ordering. | |
wuchengli
2015/06/12 11:07:37
Explain what the int stands for.
henryhsu
2015/06/16 09:37:25
Done.
| |
153 std::vector<int> free_output_buffers_; | |
154 // Mapping of int index to an output buffer record. | |
wuchengli
2015/06/12 11:07:37
This is not a map. s/output_buffer_map_/output_buf
Pawel Osciak
2015/06/16 07:13:22
Same as input_buffer_map_.
henryhsu
2015/06/16 09:37:25
same as input_buffer_map_.
| |
155 std::vector<OutputRecord> output_buffer_map_; | |
156 | |
157 // Weak factory for producing weak pointers on the decoder_thread_ | |
158 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> device_weak_factory_; | |
wuchengli
2015/06/12 11:07:37
s/device_weak_factory_/weak_factory_/. This is the
Pawel Osciak
2015/06/16 07:13:22
The weak this factory must be the last member of t
henryhsu
2015/06/16 09:37:24
Done.
henryhsu
2015/06/16 09:37:25
Done.
| |
159 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder | |
160 // thread back to the ChildThread. Because the decoder thread is a member of | |
161 // this class, any task running on the decoder thread is guaranteed that this | |
162 // object is still alive. As a result, tasks posted from ChildThread to | |
163 // decoder thread should use base::Unretained(this), and tasks posted from | |
164 // the decoder thread to the ChildThread should use |device_weak_|. | |
165 base::WeakPtr<V4L2JpegDecodeAccelerator> device_weak_; | |
kcwu
2015/06/12 06:59:42
Do we need to keep this? Just call device_weak_fac
wuchengli
2015/06/12 11:07:37
s/device_weak_/weak_this_/
henryhsu
2015/06/16 09:37:24
Done.
henryhsu
2015/06/16 09:37:24
deleted.
| |
166 | |
167 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); | |
168 }; | |
169 | |
170 } // namespace content | |
171 | |
172 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_ | |
OLD | NEW |