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

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: fix nit 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 void ResetQueues();
78
79 // Return the number of input/output buffers enqueued to the device.
80 size_t InputBufferQueuedCount();
81 size_t OutputBufferQueuedCount();
82
83 // Return true if input buffer should be re-created.
84 bool ShouldRecreateInputBuffers();
85 // Return true if output buffer should be re-created.
86 bool ShouldRecreateOutputBuffers();
87 // Create input and output buffer if needed. Return false means that an error
88 // has happened.
89 bool CreateBuffersIfNecessary();
90
91 void VideoFrameReady(int32_t bitstream_buffer_id);
92 void NotifyError(int32_t bitstream_buffer_id, Error error);
93 void PostNotifyError(int32_t bitstream_buffer_id, Error error);
94
95 // Run on |decoder_thread_| to enqueue the coming frame.
96 void DecodeTask(scoped_ptr<JobRecord> job_record);
97
98 // Run on |decoder_thread_| to dequeue last frame and enqueue next frame.
99 // This task is triggered by DevicePollTask.
100 void ServiceDeviceTask();
101
102 // Start/Stop |device_poll_thread_|.
103 void StartDevicePoll();
104 bool StopDevicePoll();
105
106 // Run on |device_poll_thread_| to wait for device events.
107 void DevicePollTask();
108
109 // Run on |decoder_thread_| to destroy input and output buffers.
110 void DestroyTask();
111
112 // The number of input buffers and output buffers.
113 const size_t kBufferCount = 2;
114
115 // Current image size used for checking the size is changed.
116 gfx::Size image_coded_size_;
117
118 // Set true when input or output buffers have to be re-allocated.
119 bool recreate_input_buffers_pending_;
120 bool recreate_output_buffers_pending_;
121
122 // ChildThread's task runner.
123 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_;
124
125 // GPU IO task runner.
126 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
127
128 // The client of this class.
129 Client* client_;
130
131 // The V4L2Device this class is operating upon.
132 scoped_refptr<V4L2Device> device_;
133
134 // Thread to communicate with the device.
135 base::Thread decoder_thread_;
136 // Decode task runner.
137 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_;
138 // Thread used to poll the V4L2 for events only.
139 base::Thread device_poll_thread_;
140 // Device poll task runner.
141 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_;
142
143 // All the below members except |weak_factory_| are accessed from
144 // |decoder_thread_| only (if it's running).
145 std::queue<linked_ptr<JobRecord>> input_jobs_;
146 std::queue<linked_ptr<JobRecord>> running_jobs_;
147
148 // Input queue state.
149 bool input_streamon_;
150 // Mapping of int index to an input buffer record.
151 std::vector<BufferRecord> input_buffer_map_;
152 // Indices of input buffers ready to use; LIFO since we don't care about
153 // ordering.
154 std::vector<int> free_input_buffers_;
155
156 // Output queue state.
157 bool output_streamon_;
158 // Mapping of int index to an output buffer record.
159 std::vector<BufferRecord> output_buffer_map_;
160 // Indices of output buffers ready to use; LIFO since we don't care about
161 // ordering.
162 std::vector<int> free_output_buffers_;
163
164 // Weak factory for producing weak pointers on the child thread.
165 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_;
166 // Point to |this| for use in posting tasks from the decoder thread back to
167 // the ChildThread.
168 base::WeakPtr<V4L2JpegDecodeAccelerator> weak_ptr_;
169
170 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator);
171 };
172
173 } // namespace content
174
175 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/v4l2_device.h ('k') | content/common/gpu/media/v4l2_jpeg_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698