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. | |
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; | |
60 scoped_refptr<media::VideoFrame> frame; | |
61 scoped_ptr<base::SharedMemory> shm; | |
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(); | |
76 | |
77 void NotifyError(int32_t bitstream_buffer_id, Error error); | |
78 void PostNotifyError(int32_t bitstream_buffer_id, Error error); | |
79 | |
80 void DecodeTask(scoped_ptr<JobRecord> job_record); | |
henryhsu
2015/06/16 09:53:50
I missed it. I'll add documentation for this in ne
| |
81 void ServiceDeviceTask(); | |
82 | |
83 // Start/Stop |device_poll_thread_|. | |
84 void StartDevicePoll(); | |
85 bool StopDevicePoll(); | |
86 | |
87 // Run on |device_poll_thread_| to wait for device events. | |
88 void DevicePollTask(); | |
89 | |
90 // Run on |decoder_thread_| to destroy input and output buffers. | |
91 void DestroyTask(); | |
92 | |
93 const size_t kBufferCount = 2; | |
94 | |
95 // Current image size used for checking the size is changed. | |
96 gfx::Size image_coded_size_; | |
97 | |
98 // Set true when input or output buffers have to re-allocate. | |
99 bool recreate_input_buffers_pending_; | |
100 bool recreate_output_buffers_pending_; | |
101 | |
102 // ChildThread's task runner. | |
103 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | |
104 | |
105 // GPU IO task runner. | |
106 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
107 | |
108 // The client of this class. | |
109 Client* client_; | |
110 | |
111 // The V4L2Device this class is operating upon. | |
112 scoped_refptr<V4L2Device> device_; | |
113 | |
114 // Thread to communicate with the device. | |
115 base::Thread decoder_thread_; | |
116 // Decode task runner. | |
117 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; | |
118 // Thread used to poll the V4L2 for events only. | |
119 base::Thread device_poll_thread_; | |
120 // Device poll task runner. | |
121 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; | |
122 | |
123 // All the below members are accessed from |decoder_thread_| only | |
124 // (if it's running). | |
125 std::queue<linked_ptr<JobRecord> > input_jobs_; | |
126 std::queue<linked_ptr<JobRecord> > running_jobs_; | |
127 | |
128 // Input queue state. | |
129 bool input_streamon_; | |
130 // Number of input buffers enqueued to the device. | |
131 int input_buffer_queued_count_; | |
132 // Mapping of int index to an input buffer record. | |
133 std::vector<BufferRecord> input_buffer_map_; | |
134 // Indices of input buffers ready to use; LIFO since we don't care about | |
135 // ordering. | |
136 std::vector<int> free_input_buffers_; | |
137 | |
138 // Output queue state. | |
139 bool output_streamon_; | |
140 // Number of output buffers enqueued to the device. | |
141 int output_buffer_queued_count_; | |
142 // Mapping of int index to an output buffer record. | |
143 std::vector<BufferRecord> output_buffer_map_; | |
144 // Indices of output buffers ready to use; LIFO since we don't care about | |
145 // ordering. | |
146 std::vector<int> free_output_buffers_; | |
147 | |
148 // Weak factory for producing weak pointers on the decoder_thread_ | |
149 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; | |
150 | |
151 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); | |
152 }; | |
153 | |
154 } // namespace content | |
155 | |
156 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_ | |
OLD | NEW |