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

Side by Side Diff: content/common/gpu/media/v4l2_jpeg_decode_accelerator.h

Issue 1125263005: MJPEG acceleration for V4L2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
(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. |address| 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
60 // Input image buffer.
61 media::BitstreamBuffer bitstream_buffer;
62 // Output frame buffer.
63 scoped_refptr<media::VideoFrame> out_frame;
64 // Memory mapped from |bitstream_buffer|.
65 scoped_ptr<base::SharedMemory> shm;
66 };
67
68 void EnqueueInput();
69 void EnqueueOutput();
70 void Dequeue();
71 bool EnqueueInputRecord();
72 bool EnqueueOutputRecord();
73 bool CreateInputBuffers();
74 bool CreateOutputBuffers();
75 void DestroyInputBuffers();
76 void DestroyOutputBuffers();
77
78 // Return the number of input/output buffers enqueued to the device.
79 int InputBufferQueuedCount();
80 int OutputBufferQueuedCount();
81
82 // Return true if input buffer should be re-created.
83 bool ShouldRecreateInputBuffers();
84 // Return true if output buffer should be re-created.
85 bool ShouldRecreateOutputBuffers();
86 // Create input and output buffer if needed. Return false means that an error
87 // has happened.
88 bool CreateBuffersIfNecessary();
89
90 void NotifyError(int32_t bitstream_buffer_id, Error error);
91 void PostNotifyError(int32_t bitstream_buffer_id, Error error);
92
93 // Run on |decoder_thread_| to enqueue the coming frame.
94 void DecodeTask(scoped_ptr<JobRecord> job_record);
95
96 // Run on |decoder_thread_| to dequeue last frame and enqueue next frame.
97 // This task is triggered by DevicePollTask.
98 void ServiceDeviceTask();
99
100 // Start/Stop |device_poll_thread_|.
101 void StartDevicePoll();
102 bool StopDevicePoll();
103
104 // Run on |device_poll_thread_| to wait for device events.
105 void DevicePollTask();
106
107 // Run on |decoder_thread_| to destroy input and output buffers.
108 void DestroyTask();
109
110 // The number of input buffers and output buffers.
111 const size_t kBufferCount = 2;
112
113 // Current image size used for checking the size is changed.
114 gfx::Size image_coded_size_;
115
116 // Set true when input or output buffers have to be re-allocated.
117 bool recreate_input_buffers_pending_;
118 bool recreate_output_buffers_pending_;
119
120 // ChildThread's task runner.
121 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_;
122
123 // GPU IO task runner.
124 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
125
126 // The client of this class.
127 Client* client_;
128
129 // The V4L2Device this class is operating upon.
130 scoped_refptr<V4L2Device> device_;
131
132 // Thread to communicate with the device.
133 base::Thread decoder_thread_;
134 // Decode task runner.
135 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_;
136 // Thread used to poll the V4L2 for events only.
137 base::Thread device_poll_thread_;
138 // Device poll task runner.
139 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_;
140
141 // All the below members except |weak_factory_| are accessed from
142 // |decoder_thread_| only (if it's running).
143 std::queue<linked_ptr<JobRecord> > input_jobs_;
144 std::queue<linked_ptr<JobRecord> > running_jobs_;
145
146 // Input queue state.
147 bool input_streamon_;
148 // Mapping of int index to an input buffer record.
149 std::vector<BufferRecord> input_buffer_map_;
150 // Indices of input buffers ready to use; LIFO since we don't care about
151 // ordering.
152 std::vector<int> free_input_buffers_;
153
154 // Output queue state.
155 bool output_streamon_;
156 // Mapping of int index to an output buffer record.
157 std::vector<BufferRecord> output_buffer_map_;
158 // Indices of output buffers ready to use; LIFO since we don't care about
159 // ordering.
160 std::vector<int> free_output_buffers_;
161
162 // Weak factory for producing weak pointers on the child thread.
163 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_;
164
165 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator);
166 };
167
168 } // namespace content
169
170 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698