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 // media::JpegDecodeAccelerator implementation. | |
33 bool Initialize(Client* client) override; | |
34 void Decode(const media::BitstreamBuffer& bitstream_buffer, | |
35 const scoped_refptr<media::VideoFrame>& video_frame) override; | |
36 | |
37 private: | |
38 // Record for input/output buffers. | |
39 struct BufferRecord { | |
40 BufferRecord(); | |
41 ~BufferRecord(); | |
42 void* address; // mmap() address. | |
43 size_t length; // mmap() length. | |
44 | |
45 // Set true during QBUF and DQBUF. |adress| will be accessed by hardware. | |
wuchengli
2015/06/22 22:40:55
s/adress/address/
henryhsu
2015/06/23 10:08:17
Done.
| |
46 bool at_device; | |
47 }; | |
48 | |
49 // Job record. Jobs are processed in a FIFO order. This is separate from | |
50 // BufferRecord of input, because a BufferRecord of input may be returned | |
51 // before we dequeue the corresponding output buffer. It can't always be | |
52 // associated with a BufferRecord of output immediately either, because at | |
53 // the time of submission we may not have one available (and don't need one | |
54 // to submit input to the device). | |
55 struct JobRecord { | |
56 JobRecord(media::BitstreamBuffer bitstream_buffer, | |
57 scoped_refptr<media::VideoFrame> video_frame); | |
58 ~JobRecord(); | |
59 media::BitstreamBuffer bitstream_buffer; | |
wuchengli
2015/06/22 22:40:55
Document these three variables. Also mention |bits
henryhsu
2015/06/23 10:08:17
Done.
| |
60 scoped_refptr<media::VideoFrame> frame; | |
wuchengli
2015/06/22 22:40:55
s/frame/output_frame/ so it's more obvious what th
henryhsu
2015/06/23 10:08:17
Done.
| |
61 scoped_ptr<base::SharedMemory> shm; | |
wuchengli
2015/06/22 22:40:54
Document this is mapped from |bitstream_buffer|.
henryhsu
2015/06/23 10:08:17
Done.
| |
62 }; | |
63 | |
64 void Enqueue(); | |
65 void Dequeue(); | |
66 bool EnqueueInputRecord(); | |
67 bool EnqueueOutputRecord(); | |
68 bool CreateInputBuffers(); | |
69 bool CreateOutputBuffers(); | |
70 void DestroyInputBuffers(); | |
71 void DestroyOutputBuffers(); | |
72 // Check resolution and input buffer size to decide recreate buffers. | |
73 void CheckBufferAttributes(); | |
74 // Create input and output buffer if needed. | |
75 bool CreateBufferIfNecessary(); | |
wuchengli
2015/06/22 22:40:55
Document the return value -- False means an error
henryhsu
2015/06/23 10:08:17
Done.
| |
76 | |
77 void NotifyError(int32_t bitstream_buffer_id, Error error); | |
78 void PostNotifyError(int32_t bitstream_buffer_id, Error error); | |
79 | |
80 // Run on |decoder_thread_| to enqueue the coming frame. | |
81 void DecodeTask(scoped_ptr<JobRecord> job_record); | |
82 | |
83 // Run on |decoder_thread_| to dequeue last frame and enqueue next frame. | |
84 // This task is triggered by DevicePollTask. | |
85 void ServiceDeviceTask(); | |
86 | |
87 // Start/Stop |device_poll_thread_|. | |
88 void StartDevicePoll(); | |
89 bool StopDevicePoll(); | |
90 | |
91 // Run on |device_poll_thread_| to wait for device events. | |
92 void DevicePollTask(); | |
93 | |
94 // Run on |decoder_thread_| to destroy input and output buffers. | |
95 void DestroyTask(); | |
96 | |
97 const size_t kBufferCount = 2; | |
wuchengli
2015/06/22 22:40:55
Document this is the number of input buffers and o
henryhsu
2015/06/23 10:08:17
Done.
| |
98 | |
99 // Current image size used for checking the size is changed. | |
100 gfx::Size image_coded_size_; | |
101 | |
102 // Set true when input or output buffers have to re-allocate. | |
wuchengli
2015/06/22 22:40:55
s/re-allocate/be re-allocated/
henryhsu
2015/06/23 10:08:17
Done.
| |
103 bool recreate_input_buffers_pending_; | |
104 bool recreate_output_buffers_pending_; | |
105 | |
106 // ChildThread's task runner. | |
107 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | |
108 | |
109 // GPU IO task runner. | |
110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
111 | |
112 // The client of this class. | |
113 Client* client_; | |
114 | |
115 // The V4L2Device this class is operating upon. | |
116 scoped_refptr<V4L2Device> device_; | |
117 | |
118 // Thread to communicate with the device. | |
119 base::Thread decoder_thread_; | |
120 // Decode task runner. | |
121 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; | |
122 // Thread used to poll the V4L2 for events only. | |
123 base::Thread device_poll_thread_; | |
124 // Device poll task runner. | |
125 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; | |
126 | |
127 // All the below members are accessed from |decoder_thread_| only | |
wuchengli
2015/06/22 22:40:55
All the below members except |weak_factory_|
henryhsu
2015/06/23 10:08:17
Done.
| |
128 // (if it's running). | |
129 std::queue<linked_ptr<JobRecord> > input_jobs_; | |
130 std::queue<linked_ptr<JobRecord> > running_jobs_; | |
131 | |
132 // Input queue state. | |
133 bool input_streamon_; | |
134 // Number of input buffers enqueued to the device. | |
135 int input_buffer_queued_count_; | |
136 // Mapping of int index to an input buffer record. | |
137 std::vector<BufferRecord> input_buffer_map_; | |
138 // Indices of input buffers ready to use; LIFO since we don't care about | |
139 // ordering. | |
140 std::vector<int> free_input_buffers_; | |
141 | |
142 // Output queue state. | |
143 bool output_streamon_; | |
144 // Number of output buffers enqueued to the device. | |
145 int output_buffer_queued_count_; | |
146 // Mapping of int index to an output buffer record. | |
147 std::vector<BufferRecord> output_buffer_map_; | |
148 // Indices of output buffers ready to use; LIFO since we don't care about | |
149 // ordering. | |
150 std::vector<int> free_output_buffers_; | |
151 | |
152 // Weak factory for producing weak pointers on the decoder_thread_ | |
wuchengli
2015/06/22 22:40:55
s/decoder/child/
henryhsu
2015/06/23 10:08:17
Done.
| |
153 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); | |
156 }; | |
157 | |
158 } // namespace content | |
159 | |
160 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_ | |
OLD | NEW |