OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <libdrm/drm_fourcc.h> | 8 #include <libdrm/drm_fourcc.h> |
9 #include <linux/videodev2.h> | 9 #include <linux/videodev2.h> |
10 #include <poll.h> | 10 #include <poll.h> |
11 #include <sys/eventfd.h> | 11 #include <sys/eventfd.h> |
12 #include <sys/ioctl.h> | 12 #include <sys/ioctl.h> |
13 #include <sys/mman.h> | 13 #include <sys/mman.h> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/debug/trace_event.h" | 16 #include "base/debug/trace_event.h" |
17 #include "base/memory/shared_memory.h" | 17 #include "base/memory/shared_memory.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/message_loop/message_loop_proxy.h" | 19 #include "base/message_loop/message_loop_proxy.h" |
20 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
21 #include "content/common/gpu/media/exynos_video_decode_accelerator.h" | |
22 #include "content/common/gpu/media/h264_parser.h" | 21 #include "content/common/gpu/media/h264_parser.h" |
22 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | |
23 #include "ui/gl/scoped_binders.h" | 23 #include "ui/gl/scoped_binders.h" |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 #define NOTIFY_ERROR(x) \ | 27 #define NOTIFY_ERROR(x) \ |
28 do { \ | 28 do { \ |
29 SetDecoderState(kError); \ | 29 SetDecoderState(kError); \ |
30 DLOG(ERROR) << "calling NotifyError(): " << x; \ | 30 DLOG(ERROR) << "calling NotifyError(): " << x; \ |
31 NotifyError(x); \ | 31 NotifyError(x); \ |
32 } while (0) | 32 } while (0) |
(...skipping 16 matching lines...) Expand all Loading... | |
49 } \ | 49 } \ |
50 } while (0) | 50 } while (0) |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // TODO(posciak): remove once we update linux-headers. | 54 // TODO(posciak): remove once we update linux-headers. |
55 #ifndef V4L2_EVENT_RESOLUTION_CHANGE | 55 #ifndef V4L2_EVENT_RESOLUTION_CHANGE |
56 #define V4L2_EVENT_RESOLUTION_CHANGE 5 | 56 #define V4L2_EVENT_RESOLUTION_CHANGE 5 |
57 #endif | 57 #endif |
58 | 58 |
59 const char kExynosMfcDevice[] = "/dev/mfc-dec"; | 59 const char kDevice[] = "/dev/mfc-dec"; |
60 | 60 |
61 } // anonymous namespace | 61 } // anonymous namespace |
62 | 62 |
63 struct ExynosVideoDecodeAccelerator::BitstreamBufferRef { | 63 struct V4L2VideoDecodeAccelerator::BitstreamBufferRef { |
64 BitstreamBufferRef( | 64 BitstreamBufferRef( |
65 base::WeakPtr<Client>& client, | 65 base::WeakPtr<Client>& client, |
66 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, | 66 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, |
67 base::SharedMemory* shm, | 67 base::SharedMemory* shm, |
68 size_t size, | 68 size_t size, |
69 int32 input_id); | 69 int32 input_id); |
70 ~BitstreamBufferRef(); | 70 ~BitstreamBufferRef(); |
71 const base::WeakPtr<Client> client; | 71 const base::WeakPtr<Client> client; |
72 const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy; | 72 const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy; |
73 const scoped_ptr<base::SharedMemory> shm; | 73 const scoped_ptr<base::SharedMemory> shm; |
74 const size_t size; | 74 const size_t size; |
75 off_t bytes_used; | 75 off_t bytes_used; |
76 const int32 input_id; | 76 const int32 input_id; |
77 }; | 77 }; |
78 | 78 |
79 struct ExynosVideoDecodeAccelerator::PictureBufferArrayRef { | 79 struct V4L2VideoDecodeAccelerator::PictureBufferArrayRef { |
80 PictureBufferArrayRef(EGLDisplay egl_display); | 80 PictureBufferArrayRef(EGLDisplay egl_display); |
81 ~PictureBufferArrayRef(); | 81 ~PictureBufferArrayRef(); |
82 | 82 |
83 struct PictureBufferRef { | 83 struct PictureBufferRef { |
84 PictureBufferRef(EGLImageKHR egl_image, int32 picture_id) | 84 PictureBufferRef(EGLImageKHR egl_image, int32 picture_id) |
85 : egl_image(egl_image), picture_id(picture_id) {} | 85 : egl_image(egl_image), picture_id(picture_id) {} |
86 EGLImageKHR egl_image; | 86 EGLImageKHR egl_image; |
87 int32 picture_id; | 87 int32 picture_id; |
88 }; | 88 }; |
89 | 89 |
90 EGLDisplay const egl_display; | 90 EGLDisplay const egl_display; |
91 std::vector<PictureBufferRef> picture_buffers; | 91 std::vector<PictureBufferRef> picture_buffers; |
92 }; | 92 }; |
93 | 93 |
94 struct ExynosVideoDecodeAccelerator::EGLSyncKHRRef { | 94 struct V4L2VideoDecodeAccelerator::EGLSyncKHRRef { |
95 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync); | 95 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync); |
96 ~EGLSyncKHRRef(); | 96 ~EGLSyncKHRRef(); |
97 EGLDisplay const egl_display; | 97 EGLDisplay const egl_display; |
98 EGLSyncKHR egl_sync; | 98 EGLSyncKHR egl_sync; |
99 }; | 99 }; |
100 | 100 |
101 struct ExynosVideoDecodeAccelerator::PictureRecord { | 101 struct V4L2VideoDecodeAccelerator::PictureRecord { |
102 PictureRecord(bool cleared, const media::Picture& picture); | 102 PictureRecord(bool cleared, const media::Picture& picture); |
103 ~PictureRecord(); | 103 ~PictureRecord(); |
104 bool cleared; // Whether the texture is cleared and safe to render from. | 104 bool cleared; // Whether the texture is cleared and safe to render from. |
105 media::Picture picture; // The decoded picture. | 105 media::Picture picture; // The decoded picture. |
106 }; | 106 }; |
107 | 107 |
108 ExynosVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( | 108 V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( |
109 base::WeakPtr<Client>& client, | 109 base::WeakPtr<Client>& client, |
110 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, | 110 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, |
111 base::SharedMemory* shm, size_t size, int32 input_id) | 111 base::SharedMemory* shm, size_t size, int32 input_id) |
112 : client(client), | 112 : client(client), |
113 client_message_loop_proxy(client_message_loop_proxy), | 113 client_message_loop_proxy(client_message_loop_proxy), |
114 shm(shm), | 114 shm(shm), |
115 size(size), | 115 size(size), |
116 bytes_used(0), | 116 bytes_used(0), |
117 input_id(input_id) { | 117 input_id(input_id) { |
118 } | 118 } |
119 | 119 |
120 ExynosVideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() { | 120 V4L2VideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() { |
121 if (input_id >= 0) { | 121 if (input_id >= 0) { |
122 client_message_loop_proxy->PostTask(FROM_HERE, base::Bind( | 122 client_message_loop_proxy->PostTask(FROM_HERE, base::Bind( |
123 &Client::NotifyEndOfBitstreamBuffer, client, input_id)); | 123 &Client::NotifyEndOfBitstreamBuffer, client, input_id)); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::PictureBufferArrayRef( | 127 V4L2VideoDecodeAccelerator::PictureBufferArrayRef::PictureBufferArrayRef( |
128 EGLDisplay egl_display) | 128 EGLDisplay egl_display) |
129 : egl_display(egl_display) {} | 129 : egl_display(egl_display) {} |
130 | 130 |
131 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::~PictureBufferArrayRef() { | 131 V4L2VideoDecodeAccelerator::PictureBufferArrayRef::~PictureBufferArrayRef() { |
132 for (size_t i = 0; i < picture_buffers.size(); ++i) { | 132 for (size_t i = 0; i < picture_buffers.size(); ++i) { |
133 EGLImageKHR egl_image = picture_buffers[i].egl_image; | 133 EGLImageKHR egl_image = picture_buffers[i].egl_image; |
134 if (egl_image != EGL_NO_IMAGE_KHR) | 134 if (egl_image != EGL_NO_IMAGE_KHR) |
135 eglDestroyImageKHR(egl_display, egl_image); | 135 eglDestroyImageKHR(egl_display, egl_image); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::EGLSyncKHRRef( | 139 V4L2VideoDecodeAccelerator::EGLSyncKHRRef::EGLSyncKHRRef( |
140 EGLDisplay egl_display, EGLSyncKHR egl_sync) | 140 EGLDisplay egl_display, EGLSyncKHR egl_sync) |
141 : egl_display(egl_display), | 141 : egl_display(egl_display), |
142 egl_sync(egl_sync) { | 142 egl_sync(egl_sync) { |
143 } | 143 } |
144 | 144 |
145 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::~EGLSyncKHRRef() { | 145 V4L2VideoDecodeAccelerator::EGLSyncKHRRef::~EGLSyncKHRRef() { |
146 if (egl_sync != EGL_NO_SYNC_KHR) | 146 if (egl_sync != EGL_NO_SYNC_KHR) |
147 eglDestroySyncKHR(egl_display, egl_sync); | 147 eglDestroySyncKHR(egl_display, egl_sync); |
148 } | 148 } |
149 | 149 |
150 ExynosVideoDecodeAccelerator::MfcInputRecord::MfcInputRecord() | 150 V4L2VideoDecodeAccelerator::InputRecord::InputRecord() |
151 : at_device(false), | 151 : at_device(false), |
152 address(NULL), | 152 address(NULL), |
153 length(0), | 153 length(0), |
154 bytes_used(0), | 154 bytes_used(0), |
155 input_id(-1) { | 155 input_id(-1) { |
156 } | 156 } |
157 | 157 |
158 ExynosVideoDecodeAccelerator::MfcInputRecord::~MfcInputRecord() { | 158 V4L2VideoDecodeAccelerator::InputRecord::~InputRecord() { |
159 } | 159 } |
160 | 160 |
161 ExynosVideoDecodeAccelerator::MfcOutputRecord::MfcOutputRecord() | 161 V4L2VideoDecodeAccelerator::OutputRecord::OutputRecord() |
162 : at_device(false), | 162 : at_device(false), |
163 at_client(false), | 163 at_client(false), |
164 egl_image(EGL_NO_IMAGE_KHR), | 164 egl_image(EGL_NO_IMAGE_KHR), |
165 egl_sync(EGL_NO_SYNC_KHR), | 165 egl_sync(EGL_NO_SYNC_KHR), |
166 picture_id(-1), | 166 picture_id(-1), |
167 cleared(false) { | 167 cleared(false) { |
168 for (size_t i = 0; i < arraysize(fds); ++i) | 168 for (size_t i = 0; i < arraysize(fds); ++i) |
169 fds[i] = -1; | 169 fds[i] = -1; |
170 } | 170 } |
171 | 171 |
172 ExynosVideoDecodeAccelerator::MfcOutputRecord::~MfcOutputRecord() {} | 172 V4L2VideoDecodeAccelerator::OutputRecord::~OutputRecord() {} |
173 | 173 |
174 ExynosVideoDecodeAccelerator::PictureRecord::PictureRecord( | 174 V4L2VideoDecodeAccelerator::PictureRecord::PictureRecord( |
175 bool cleared, | 175 bool cleared, |
176 const media::Picture& picture) | 176 const media::Picture& picture) |
177 : cleared(cleared), picture(picture) {} | 177 : cleared(cleared), picture(picture) {} |
178 | 178 |
179 ExynosVideoDecodeAccelerator::PictureRecord::~PictureRecord() {} | 179 V4L2VideoDecodeAccelerator::PictureRecord::~PictureRecord() {} |
180 | 180 |
181 ExynosVideoDecodeAccelerator::ExynosVideoDecodeAccelerator( | 181 V4L2VideoDecodeAccelerator::V4L2VideoDecodeAccelerator( |
182 EGLDisplay egl_display, | 182 EGLDisplay egl_display, |
183 Client* client, | 183 Client* client, |
184 const base::WeakPtr<Client>& io_client, | 184 const base::WeakPtr<Client>& io_client, |
185 const base::Callback<bool(void)>& make_context_current, | 185 const base::Callback<bool(void)>& make_context_current, |
186 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) | 186 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) |
187 : child_message_loop_proxy_(base::MessageLoopProxy::current()), | 187 : child_message_loop_proxy_(base::MessageLoopProxy::current()), |
188 io_message_loop_proxy_(io_message_loop_proxy), | 188 io_message_loop_proxy_(io_message_loop_proxy), |
189 weak_this_(base::AsWeakPtr(this)), | 189 weak_this_(base::AsWeakPtr(this)), |
190 client_ptr_factory_(client), | 190 client_ptr_factory_(client), |
191 client_(client_ptr_factory_.GetWeakPtr()), | 191 client_(client_ptr_factory_.GetWeakPtr()), |
192 io_client_(io_client), | 192 io_client_(io_client), |
193 decoder_thread_("ExynosDecoderThread"), | 193 decoder_thread_("DecoderThread"), |
194 decoder_state_(kUninitialized), | 194 decoder_state_(kUninitialized), |
195 decoder_delay_bitstream_buffer_id_(-1), | 195 decoder_delay_bitstream_buffer_id_(-1), |
196 decoder_current_input_buffer_(-1), | 196 decoder_current_input_buffer_(-1), |
197 decoder_decode_buffer_tasks_scheduled_(0), | 197 decoder_decode_buffer_tasks_scheduled_(0), |
198 decoder_frames_at_client_(0), | 198 decoder_frames_at_client_(0), |
199 decoder_flushing_(false), | 199 decoder_flushing_(false), |
200 resolution_change_pending_(false), | 200 resolution_change_pending_(false), |
201 resolution_change_reset_pending_(false), | 201 resolution_change_reset_pending_(false), |
202 decoder_partial_frame_pending_(false), | 202 decoder_partial_frame_pending_(false), |
203 mfc_fd_(-1), | 203 fd_(-1), |
204 mfc_input_streamon_(false), | 204 input_streamon_(false), |
205 mfc_input_buffer_queued_count_(0), | 205 input_buffer_queued_count_(0), |
206 mfc_output_streamon_(false), | 206 output_streamon_(false), |
207 mfc_output_buffer_queued_count_(0), | 207 output_buffer_queued_count_(0), |
208 mfc_output_buffer_pixelformat_(0), | 208 output_buffer_pixelformat_(0), |
209 mfc_output_dpb_size_(0), | 209 output_dpb_size_(0), |
210 picture_clearing_count_(0), | 210 picture_clearing_count_(0), |
211 device_poll_thread_("ExynosDevicePollThread"), | 211 device_poll_thread_("DevicePollThread"), |
212 device_poll_interrupt_fd_(-1), | 212 device_poll_interrupt_fd_(-1), |
213 make_context_current_(make_context_current), | 213 make_context_current_(make_context_current), |
214 egl_display_(egl_display), | 214 egl_display_(egl_display), |
215 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {} | 215 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {} |
216 | 216 |
217 ExynosVideoDecodeAccelerator::~ExynosVideoDecodeAccelerator() { | 217 V4L2VideoDecodeAccelerator::~V4L2VideoDecodeAccelerator() { |
218 DCHECK(!decoder_thread_.IsRunning()); | 218 DCHECK(!decoder_thread_.IsRunning()); |
219 DCHECK(!device_poll_thread_.IsRunning()); | 219 DCHECK(!device_poll_thread_.IsRunning()); |
220 | 220 |
221 if (device_poll_interrupt_fd_ != -1) { | 221 if (device_poll_interrupt_fd_ != -1) { |
222 close(device_poll_interrupt_fd_); | 222 close(device_poll_interrupt_fd_); |
223 device_poll_interrupt_fd_ = -1; | 223 device_poll_interrupt_fd_ = -1; |
224 } | 224 } |
225 if (mfc_fd_ != -1) { | 225 if (fd_ != -1) { |
226 DestroyMfcInputBuffers(); | 226 DestroyInputBuffers(); |
227 DestroyMfcOutputBuffers(); | 227 DestroyOutputBuffers(); |
228 close(mfc_fd_); | 228 close(fd_); |
229 mfc_fd_ = -1; | 229 fd_ = -1; |
230 } | 230 } |
231 | 231 |
232 // These maps have members that should be manually destroyed, e.g. file | 232 // These maps have members that should be manually destroyed, e.g. file |
233 // descriptors, mmap() segments, etc. | 233 // descriptors, mmap() segments, etc. |
234 DCHECK(mfc_input_buffer_map_.empty()); | 234 DCHECK(input_buffer_map_.empty()); |
235 DCHECK(mfc_output_buffer_map_.empty()); | 235 DCHECK(output_buffer_map_.empty()); |
236 } | 236 } |
237 | 237 |
238 bool ExynosVideoDecodeAccelerator::Initialize( | 238 bool V4L2VideoDecodeAccelerator::Initialize( |
239 media::VideoCodecProfile profile) { | 239 media::VideoCodecProfile profile) { |
240 DVLOG(3) << "Initialize()"; | 240 DVLOG(3) << "Initialize()"; |
241 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 241 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
242 DCHECK_EQ(decoder_state_, kUninitialized); | 242 DCHECK_EQ(decoder_state_, kUninitialized); |
243 | 243 |
244 switch (profile) { | 244 switch (profile) { |
245 case media::H264PROFILE_BASELINE: | 245 case media::H264PROFILE_BASELINE: |
246 DVLOG(2) << "Initialize(): profile H264PROFILE_BASELINE"; | 246 DVLOG(2) << "Initialize(): profile H264PROFILE_BASELINE"; |
247 break; | 247 break; |
248 case media::H264PROFILE_MAIN: | 248 case media::H264PROFILE_MAIN: |
(...skipping 24 matching lines...) Expand all Loading... | |
273 return false; | 273 return false; |
274 } | 274 } |
275 | 275 |
276 if (!gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync) { | 276 if (!gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync) { |
277 DLOG(ERROR) << "Initialize(): context does not have EGL_KHR_fence_sync"; | 277 DLOG(ERROR) << "Initialize(): context does not have EGL_KHR_fence_sync"; |
278 NOTIFY_ERROR(PLATFORM_FAILURE); | 278 NOTIFY_ERROR(PLATFORM_FAILURE); |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 // Open the video devices. | 282 // Open the video devices. |
283 DVLOG(2) << "Initialize(): opening MFC device: " << kExynosMfcDevice; | 283 DVLOG(2) << "Initialize(): opening device: " << kDevice; |
284 mfc_fd_ = HANDLE_EINTR(open(kExynosMfcDevice, | 284 fd_ = HANDLE_EINTR(open(kDevice, |
Pawel Osciak
2014/01/07 07:18:12
This and below might fit in one line now.
| |
285 O_RDWR | O_NONBLOCK | O_CLOEXEC)); | 285 O_RDWR | O_NONBLOCK | O_CLOEXEC)); |
286 if (mfc_fd_ == -1) { | 286 if (fd_ == -1) { |
287 DPLOG(ERROR) << "Initialize(): could not open MFC device: " | 287 DPLOG(ERROR) << "Initialize(): could not open device: " |
288 << kExynosMfcDevice; | 288 << kDevice; |
289 NOTIFY_ERROR(PLATFORM_FAILURE); | 289 NOTIFY_ERROR(PLATFORM_FAILURE); |
290 return false; | 290 return false; |
291 } | 291 } |
292 | 292 |
293 // Create the interrupt fd. | 293 // Create the interrupt fd. |
294 DCHECK_EQ(device_poll_interrupt_fd_, -1); | 294 DCHECK_EQ(device_poll_interrupt_fd_, -1); |
295 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 295 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
296 if (device_poll_interrupt_fd_ == -1) { | 296 if (device_poll_interrupt_fd_ == -1) { |
297 DPLOG(ERROR) << "Initialize(): eventfd() failed"; | 297 DPLOG(ERROR) << "Initialize(): eventfd() failed"; |
298 NOTIFY_ERROR(PLATFORM_FAILURE); | 298 NOTIFY_ERROR(PLATFORM_FAILURE); |
299 return false; | 299 return false; |
300 } | 300 } |
301 | 301 |
302 // Capabilities check. | 302 // Capabilities check. |
303 struct v4l2_capability caps; | 303 struct v4l2_capability caps; |
304 const __u32 kCapsRequired = | 304 const __u32 kCapsRequired = |
305 V4L2_CAP_VIDEO_CAPTURE_MPLANE | | 305 V4L2_CAP_VIDEO_CAPTURE_MPLANE | |
306 V4L2_CAP_VIDEO_OUTPUT_MPLANE | | 306 V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
307 V4L2_CAP_STREAMING; | 307 V4L2_CAP_STREAMING; |
308 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QUERYCAP, &caps); | 308 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_QUERYCAP, &caps); |
309 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { | 309 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { |
310 DLOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP" | 310 DLOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP" |
311 ", caps check failed: 0x" << std::hex << caps.capabilities; | 311 ", caps check failed: 0x" << std::hex << caps.capabilities; |
312 NOTIFY_ERROR(PLATFORM_FAILURE); | 312 NOTIFY_ERROR(PLATFORM_FAILURE); |
313 return false; | 313 return false; |
314 } | 314 } |
315 | 315 |
316 if (!CreateMfcInputBuffers()) | 316 if (!CreateInputBuffers()) |
317 return false; | 317 return false; |
318 | 318 |
319 // MFC output format has to be setup before streaming starts. | 319 // output format has to be setup before streaming starts. |
Pawel Osciak
2014/01/07 07:18:12
Capital letter.
| |
320 struct v4l2_format format; | 320 struct v4l2_format format; |
321 memset(&format, 0, sizeof(format)); | 321 memset(&format, 0, sizeof(format)); |
322 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 322 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
323 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12M; | 323 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12M; |
324 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format); | 324 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_S_FMT, &format); |
325 | 325 |
326 // Subscribe to the resolution change event. | 326 // Subscribe to the resolution change event. |
327 struct v4l2_event_subscription sub; | 327 struct v4l2_event_subscription sub; |
328 memset(&sub, 0, sizeof(sub)); | 328 memset(&sub, 0, sizeof(sub)); |
329 sub.type = V4L2_EVENT_RESOLUTION_CHANGE; | 329 sub.type = V4L2_EVENT_RESOLUTION_CHANGE; |
330 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_SUBSCRIBE_EVENT, &sub); | 330 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_SUBSCRIBE_EVENT, &sub); |
331 | 331 |
332 // Initialize format-specific bits. | 332 // Initialize format-specific bits. |
333 if (video_profile_ >= media::H264PROFILE_MIN && | 333 if (video_profile_ >= media::H264PROFILE_MIN && |
334 video_profile_ <= media::H264PROFILE_MAX) { | 334 video_profile_ <= media::H264PROFILE_MAX) { |
335 decoder_h264_parser_.reset(new content::H264Parser()); | 335 decoder_h264_parser_.reset(new content::H264Parser()); |
336 } | 336 } |
337 | 337 |
338 if (!decoder_thread_.Start()) { | 338 if (!decoder_thread_.Start()) { |
339 DLOG(ERROR) << "Initialize(): decoder thread failed to start"; | 339 DLOG(ERROR) << "Initialize(): decoder thread failed to start"; |
340 NOTIFY_ERROR(PLATFORM_FAILURE); | 340 NOTIFY_ERROR(PLATFORM_FAILURE); |
341 return false; | 341 return false; |
342 } | 342 } |
343 | 343 |
344 SetDecoderState(kInitialized); | 344 SetDecoderState(kInitialized); |
345 | 345 |
346 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 346 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
347 &Client::NotifyInitializeDone, client_)); | 347 &Client::NotifyInitializeDone, client_)); |
348 return true; | 348 return true; |
349 } | 349 } |
350 | 350 |
351 void ExynosVideoDecodeAccelerator::Decode( | 351 void V4L2VideoDecodeAccelerator::Decode( |
352 const media::BitstreamBuffer& bitstream_buffer) { | 352 const media::BitstreamBuffer& bitstream_buffer) { |
353 DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id() | 353 DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id() |
354 << ", size=" << bitstream_buffer.size(); | 354 << ", size=" << bitstream_buffer.size(); |
355 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 355 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
356 | 356 |
357 // DecodeTask() will take care of running a DecodeBufferTask(). | 357 // DecodeTask() will take care of running a DecodeBufferTask(). |
358 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 358 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
359 &ExynosVideoDecodeAccelerator::DecodeTask, base::Unretained(this), | 359 &V4L2VideoDecodeAccelerator::DecodeTask, base::Unretained(this), |
360 bitstream_buffer)); | 360 bitstream_buffer)); |
361 } | 361 } |
362 | 362 |
363 void ExynosVideoDecodeAccelerator::AssignPictureBuffers( | 363 void V4L2VideoDecodeAccelerator::AssignPictureBuffers( |
364 const std::vector<media::PictureBuffer>& buffers) { | 364 const std::vector<media::PictureBuffer>& buffers) { |
365 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); | 365 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); |
366 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 366 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
367 | 367 |
368 if (buffers.size() != mfc_output_buffer_map_.size()) { | 368 if (buffers.size() != output_buffer_map_.size()) { |
369 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" | 369 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" |
370 " buffers. (Got " << buffers.size() | 370 " buffers. (Got " << buffers.size() |
371 << ", requested " << mfc_output_buffer_map_.size() << ")"; | 371 << ", requested " << output_buffer_map_.size() << ")"; |
372 NOTIFY_ERROR(INVALID_ARGUMENT); | 372 NOTIFY_ERROR(INVALID_ARGUMENT); |
373 return; | 373 return; |
374 } | 374 } |
375 | 375 |
376 if (!make_context_current_.Run()) { | 376 if (!make_context_current_.Run()) { |
377 DLOG(ERROR) << "AssignPictureBuffers(): could not make context current"; | 377 DLOG(ERROR) << "AssignPictureBuffers(): could not make context current"; |
378 NOTIFY_ERROR(PLATFORM_FAILURE); | 378 NOTIFY_ERROR(PLATFORM_FAILURE); |
379 return; | 379 return; |
380 } | 380 } |
381 | 381 |
382 scoped_ptr<PictureBufferArrayRef> picture_buffers_ref( | 382 scoped_ptr<PictureBufferArrayRef> picture_buffers_ref( |
383 new PictureBufferArrayRef(egl_display_)); | 383 new PictureBufferArrayRef(egl_display_)); |
384 gfx::ScopedTextureBinder bind_restore(GL_TEXTURE_EXTERNAL_OES, 0); | 384 gfx::ScopedTextureBinder bind_restore(GL_TEXTURE_EXTERNAL_OES, 0); |
385 EGLint attrs[] = { | 385 EGLint attrs[] = { |
386 EGL_WIDTH, 0, EGL_HEIGHT, 0, | 386 EGL_WIDTH, 0, EGL_HEIGHT, 0, |
387 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0, | 387 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0, |
388 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0, | 388 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0, |
389 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0, | 389 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0, |
390 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, }; | 390 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, }; |
391 attrs[1] = frame_buffer_size_.width(); | 391 attrs[1] = frame_buffer_size_.width(); |
392 attrs[3] = frame_buffer_size_.height(); | 392 attrs[3] = frame_buffer_size_.height(); |
393 attrs[5] = DRM_FORMAT_NV12; | 393 attrs[5] = DRM_FORMAT_NV12; |
394 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { | 394 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { |
395 DCHECK(buffers[i].size() == frame_buffer_size_); | 395 DCHECK(buffers[i].size() == frame_buffer_size_); |
396 MfcOutputRecord& output_record = mfc_output_buffer_map_[i]; | 396 OutputRecord& output_record = output_buffer_map_[i]; |
397 attrs[7] = output_record.fds[0]; | 397 attrs[7] = output_record.fds[0]; |
398 attrs[9] = 0; | 398 attrs[9] = 0; |
399 attrs[11] = frame_buffer_size_.width(); | 399 attrs[11] = frame_buffer_size_.width(); |
400 attrs[13] = output_record.fds[1]; | 400 attrs[13] = output_record.fds[1]; |
401 attrs[15] = 0; | 401 attrs[15] = 0; |
402 attrs[17] = frame_buffer_size_.width(); | 402 attrs[17] = frame_buffer_size_.width(); |
403 EGLImageKHR egl_image = eglCreateImageKHR( | 403 EGLImageKHR egl_image = eglCreateImageKHR( |
404 egl_display_, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs); | 404 egl_display_, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs); |
405 if (egl_image == EGL_NO_IMAGE_KHR) { | 405 if (egl_image == EGL_NO_IMAGE_KHR) { |
406 DLOG(ERROR) << "AssignPictureBuffers(): could not create EGLImageKHR"; | 406 DLOG(ERROR) << "AssignPictureBuffers(): could not create EGLImageKHR"; |
407 NOTIFY_ERROR(PLATFORM_FAILURE); | 407 NOTIFY_ERROR(PLATFORM_FAILURE); |
408 return; | 408 return; |
409 } | 409 } |
410 | 410 |
411 glBindTexture(GL_TEXTURE_EXTERNAL_OES, buffers[i].texture_id()); | 411 glBindTexture(GL_TEXTURE_EXTERNAL_OES, buffers[i].texture_id()); |
412 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | 412 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
413 picture_buffers_ref->picture_buffers.push_back( | 413 picture_buffers_ref->picture_buffers.push_back( |
414 PictureBufferArrayRef::PictureBufferRef(egl_image, buffers[i].id())); | 414 PictureBufferArrayRef::PictureBufferRef(egl_image, buffers[i].id())); |
415 } | 415 } |
416 decoder_thread_.message_loop()->PostTask( | 416 decoder_thread_.message_loop()->PostTask( |
417 FROM_HERE, | 417 FROM_HERE, |
418 base::Bind(&ExynosVideoDecodeAccelerator::AssignPictureBuffersTask, | 418 base::Bind(&V4L2VideoDecodeAccelerator::AssignPictureBuffersTask, |
419 base::Unretained(this), | 419 base::Unretained(this), |
420 base::Passed(&picture_buffers_ref))); | 420 base::Passed(&picture_buffers_ref))); |
421 } | 421 } |
422 | 422 |
423 void ExynosVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { | 423 void V4L2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { |
424 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; | 424 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; |
425 // Must be run on child thread, as we'll insert a sync in the EGL context. | 425 // Must be run on child thread, as we'll insert a sync in the EGL context. |
426 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 426 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
427 | 427 |
428 if (!make_context_current_.Run()) { | 428 if (!make_context_current_.Run()) { |
429 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current"; | 429 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current"; |
430 NOTIFY_ERROR(PLATFORM_FAILURE); | 430 NOTIFY_ERROR(PLATFORM_FAILURE); |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 EGLSyncKHR egl_sync = | 434 EGLSyncKHR egl_sync = |
435 eglCreateSyncKHR(egl_display_, EGL_SYNC_FENCE_KHR, NULL); | 435 eglCreateSyncKHR(egl_display_, EGL_SYNC_FENCE_KHR, NULL); |
436 if (egl_sync == EGL_NO_SYNC_KHR) { | 436 if (egl_sync == EGL_NO_SYNC_KHR) { |
437 DLOG(ERROR) << "ReusePictureBuffer(): eglCreateSyncKHR() failed"; | 437 DLOG(ERROR) << "ReusePictureBuffer(): eglCreateSyncKHR() failed"; |
438 NOTIFY_ERROR(PLATFORM_FAILURE); | 438 NOTIFY_ERROR(PLATFORM_FAILURE); |
439 return; | 439 return; |
440 } | 440 } |
441 | 441 |
442 scoped_ptr<EGLSyncKHRRef> egl_sync_ref(new EGLSyncKHRRef( | 442 scoped_ptr<EGLSyncKHRRef> egl_sync_ref(new EGLSyncKHRRef( |
443 egl_display_, egl_sync)); | 443 egl_display_, egl_sync)); |
444 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 444 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
445 &ExynosVideoDecodeAccelerator::ReusePictureBufferTask, | 445 &V4L2VideoDecodeAccelerator::ReusePictureBufferTask, |
446 base::Unretained(this), picture_buffer_id, base::Passed(&egl_sync_ref))); | 446 base::Unretained(this), picture_buffer_id, base::Passed(&egl_sync_ref))); |
447 } | 447 } |
448 | 448 |
449 void ExynosVideoDecodeAccelerator::Flush() { | 449 void V4L2VideoDecodeAccelerator::Flush() { |
450 DVLOG(3) << "Flush()"; | 450 DVLOG(3) << "Flush()"; |
451 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 451 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
452 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 452 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
453 &ExynosVideoDecodeAccelerator::FlushTask, base::Unretained(this))); | 453 &V4L2VideoDecodeAccelerator::FlushTask, base::Unretained(this))); |
454 } | 454 } |
455 | 455 |
456 void ExynosVideoDecodeAccelerator::Reset() { | 456 void V4L2VideoDecodeAccelerator::Reset() { |
457 DVLOG(3) << "Reset()"; | 457 DVLOG(3) << "Reset()"; |
458 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 458 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
459 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 459 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
460 &ExynosVideoDecodeAccelerator::ResetTask, base::Unretained(this))); | 460 &V4L2VideoDecodeAccelerator::ResetTask, base::Unretained(this))); |
461 } | 461 } |
462 | 462 |
463 void ExynosVideoDecodeAccelerator::Destroy() { | 463 void V4L2VideoDecodeAccelerator::Destroy() { |
464 DVLOG(3) << "Destroy()"; | 464 DVLOG(3) << "Destroy()"; |
465 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 465 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
466 | 466 |
467 // We're destroying; cancel all callbacks. | 467 // We're destroying; cancel all callbacks. |
468 client_ptr_factory_.InvalidateWeakPtrs(); | 468 client_ptr_factory_.InvalidateWeakPtrs(); |
469 | 469 |
470 // If the decoder thread is running, destroy using posted task. | 470 // If the decoder thread is running, destroy using posted task. |
471 if (decoder_thread_.IsRunning()) { | 471 if (decoder_thread_.IsRunning()) { |
472 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 472 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
473 &ExynosVideoDecodeAccelerator::DestroyTask, base::Unretained(this))); | 473 &V4L2VideoDecodeAccelerator::DestroyTask, base::Unretained(this))); |
474 // DestroyTask() will cause the decoder_thread_ to flush all tasks. | 474 // DestroyTask() will cause the decoder_thread_ to flush all tasks. |
475 decoder_thread_.Stop(); | 475 decoder_thread_.Stop(); |
476 } else { | 476 } else { |
477 // Otherwise, call the destroy task directly. | 477 // Otherwise, call the destroy task directly. |
478 DestroyTask(); | 478 DestroyTask(); |
479 } | 479 } |
480 | 480 |
481 // Set to kError state just in case. | 481 // Set to kError state just in case. |
482 SetDecoderState(kError); | 482 SetDecoderState(kError); |
483 | 483 |
484 delete this; | 484 delete this; |
485 } | 485 } |
486 | 486 |
487 bool ExynosVideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } | 487 bool V4L2VideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } |
488 | 488 |
489 void ExynosVideoDecodeAccelerator::DecodeTask( | 489 void V4L2VideoDecodeAccelerator::DecodeTask( |
490 const media::BitstreamBuffer& bitstream_buffer) { | 490 const media::BitstreamBuffer& bitstream_buffer) { |
491 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); | 491 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); |
492 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 492 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
493 DCHECK_NE(decoder_state_, kUninitialized); | 493 DCHECK_NE(decoder_state_, kUninitialized); |
494 TRACE_EVENT1("Video Decoder", "EVDA::DecodeTask", "input_id", | 494 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id", |
495 bitstream_buffer.id()); | 495 bitstream_buffer.id()); |
496 | 496 |
497 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( | 497 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( |
498 io_client_, io_message_loop_proxy_, | 498 io_client_, io_message_loop_proxy_, |
499 new base::SharedMemory(bitstream_buffer.handle(), true), | 499 new base::SharedMemory(bitstream_buffer.handle(), true), |
500 bitstream_buffer.size(), bitstream_buffer.id())); | 500 bitstream_buffer.size(), bitstream_buffer.id())); |
501 if (!bitstream_record->shm->Map(bitstream_buffer.size())) { | 501 if (!bitstream_record->shm->Map(bitstream_buffer.size())) { |
502 DLOG(ERROR) << "Decode(): could not map bitstream_buffer"; | 502 DLOG(ERROR) << "Decode(): could not map bitstream_buffer"; |
503 NOTIFY_ERROR(UNREADABLE_INPUT); | 503 NOTIFY_ERROR(UNREADABLE_INPUT); |
504 return; | 504 return; |
(...skipping 12 matching lines...) Expand all Loading... | |
517 DVLOG(2) << "DecodeTask(): early out: kError state"; | 517 DVLOG(2) << "DecodeTask(): early out: kError state"; |
518 return; | 518 return; |
519 } | 519 } |
520 | 520 |
521 decoder_input_queue_.push( | 521 decoder_input_queue_.push( |
522 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); | 522 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); |
523 decoder_decode_buffer_tasks_scheduled_++; | 523 decoder_decode_buffer_tasks_scheduled_++; |
524 DecodeBufferTask(); | 524 DecodeBufferTask(); |
525 } | 525 } |
526 | 526 |
527 void ExynosVideoDecodeAccelerator::DecodeBufferTask() { | 527 void V4L2VideoDecodeAccelerator::DecodeBufferTask() { |
528 DVLOG(3) << "DecodeBufferTask()"; | 528 DVLOG(3) << "DecodeBufferTask()"; |
529 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 529 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
530 DCHECK_NE(decoder_state_, kUninitialized); | 530 DCHECK_NE(decoder_state_, kUninitialized); |
531 TRACE_EVENT0("Video Decoder", "EVDA::DecodeBufferTask"); | 531 TRACE_EVENT0("Video Decoder", "V4L2VDA::DecodeBufferTask"); |
532 | 532 |
533 decoder_decode_buffer_tasks_scheduled_--; | 533 decoder_decode_buffer_tasks_scheduled_--; |
534 | 534 |
535 if (decoder_state_ == kResetting) { | 535 if (decoder_state_ == kResetting) { |
536 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; | 536 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; |
537 return; | 537 return; |
538 } else if (decoder_state_ == kError) { | 538 } else if (decoder_state_ == kError) { |
539 DVLOG(2) << "DecodeBufferTask(): early out: kError state"; | 539 DVLOG(2) << "DecodeBufferTask(): early out: kError state"; |
540 return; | 540 return; |
541 } else if (decoder_state_ == kChangingResolution) { | 541 } else if (decoder_state_ == kChangingResolution) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 // This is a buffer queued from the client that has zero size. Skip. | 573 // This is a buffer queued from the client that has zero size. Skip. |
574 schedule_task = true; | 574 schedule_task = true; |
575 } else { | 575 } else { |
576 // This is a buffer of zero size, queued to flush the pipe. Flush. | 576 // This is a buffer of zero size, queued to flush the pipe. Flush. |
577 DCHECK_EQ(decoder_current_bitstream_buffer_->shm.get(), | 577 DCHECK_EQ(decoder_current_bitstream_buffer_->shm.get(), |
578 static_cast<base::SharedMemory*>(NULL)); | 578 static_cast<base::SharedMemory*>(NULL)); |
579 // Enqueue a buffer guaranteed to be empty. To do that, we flush the | 579 // Enqueue a buffer guaranteed to be empty. To do that, we flush the |
580 // current input, enqueue no data to the next frame, then flush that down. | 580 // current input, enqueue no data to the next frame, then flush that down. |
581 schedule_task = true; | 581 schedule_task = true; |
582 if (decoder_current_input_buffer_ != -1 && | 582 if (decoder_current_input_buffer_ != -1 && |
583 mfc_input_buffer_map_[decoder_current_input_buffer_].input_id != | 583 input_buffer_map_[decoder_current_input_buffer_].input_id != |
584 kFlushBufferId) | 584 kFlushBufferId) |
585 schedule_task = FlushInputFrame(); | 585 schedule_task = FlushInputFrame(); |
586 | 586 |
587 if (schedule_task && AppendToInputFrame(NULL, 0) && FlushInputFrame()) { | 587 if (schedule_task && AppendToInputFrame(NULL, 0) && FlushInputFrame()) { |
588 DVLOG(2) << "DecodeBufferTask(): enqueued flush buffer"; | 588 DVLOG(2) << "DecodeBufferTask(): enqueued flush buffer"; |
589 decoder_partial_frame_pending_ = false; | 589 decoder_partial_frame_pending_ = false; |
590 schedule_task = true; | 590 schedule_task = true; |
591 } else { | 591 } else { |
592 // If we failed to enqueue the empty buffer (due to pipeline | 592 // If we failed to enqueue the empty buffer (due to pipeline |
593 // backpressure), don't advance the bitstream buffer queue, and don't | 593 // backpressure), don't advance the bitstream buffer queue, and don't |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 // Our current bitstream buffer is done; return it. | 638 // Our current bitstream buffer is done; return it. |
639 int32 input_id = decoder_current_bitstream_buffer_->input_id; | 639 int32 input_id = decoder_current_bitstream_buffer_->input_id; |
640 DVLOG(3) << "DecodeBufferTask(): finished input_id=" << input_id; | 640 DVLOG(3) << "DecodeBufferTask(): finished input_id=" << input_id; |
641 // BitstreamBufferRef destructor calls NotifyEndOfBitstreamBuffer(). | 641 // BitstreamBufferRef destructor calls NotifyEndOfBitstreamBuffer(). |
642 decoder_current_bitstream_buffer_.reset(); | 642 decoder_current_bitstream_buffer_.reset(); |
643 } | 643 } |
644 ScheduleDecodeBufferTaskIfNeeded(); | 644 ScheduleDecodeBufferTaskIfNeeded(); |
645 } | 645 } |
646 } | 646 } |
647 | 647 |
648 bool ExynosVideoDecodeAccelerator::AdvanceFrameFragment( | 648 bool V4L2VideoDecodeAccelerator::AdvanceFrameFragment( |
649 const uint8* data, | 649 const uint8* data, |
650 size_t size, | 650 size_t size, |
651 size_t* endpos) { | 651 size_t* endpos) { |
652 if (video_profile_ >= media::H264PROFILE_MIN && | 652 if (video_profile_ >= media::H264PROFILE_MIN && |
653 video_profile_ <= media::H264PROFILE_MAX) { | 653 video_profile_ <= media::H264PROFILE_MAX) { |
654 // For H264, we need to feed HW one frame at a time. This is going to take | 654 // For H264, we need to feed HW one frame at a time. This is going to take |
655 // some parsing of our input stream. | 655 // some parsing of our input stream. |
656 decoder_h264_parser_->SetStream(data, size); | 656 decoder_h264_parser_->SetStream(data, size); |
657 content::H264NALU nalu; | 657 content::H264NALU nalu; |
658 content::H264Parser::Result result; | 658 content::H264Parser::Result result; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 DCHECK_GE(video_profile_, media::VP8PROFILE_MIN); | 718 DCHECK_GE(video_profile_, media::VP8PROFILE_MIN); |
719 DCHECK_LE(video_profile_, media::VP8PROFILE_MAX); | 719 DCHECK_LE(video_profile_, media::VP8PROFILE_MAX); |
720 // For VP8, we can just dump the entire buffer. No fragmentation needed, | 720 // For VP8, we can just dump the entire buffer. No fragmentation needed, |
721 // and we never return a partial frame. | 721 // and we never return a partial frame. |
722 *endpos = size; | 722 *endpos = size; |
723 decoder_partial_frame_pending_ = false; | 723 decoder_partial_frame_pending_ = false; |
724 return true; | 724 return true; |
725 } | 725 } |
726 } | 726 } |
727 | 727 |
728 void ExynosVideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { | 728 void V4L2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { |
729 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 729 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
730 | 730 |
731 // If we're behind on tasks, schedule another one. | 731 // If we're behind on tasks, schedule another one. |
732 int buffers_to_decode = decoder_input_queue_.size(); | 732 int buffers_to_decode = decoder_input_queue_.size(); |
733 if (decoder_current_bitstream_buffer_ != NULL) | 733 if (decoder_current_bitstream_buffer_ != NULL) |
734 buffers_to_decode++; | 734 buffers_to_decode++; |
735 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { | 735 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { |
736 decoder_decode_buffer_tasks_scheduled_++; | 736 decoder_decode_buffer_tasks_scheduled_++; |
737 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 737 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
738 &ExynosVideoDecodeAccelerator::DecodeBufferTask, | 738 &V4L2VideoDecodeAccelerator::DecodeBufferTask, |
739 base::Unretained(this))); | 739 base::Unretained(this))); |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial( | 743 bool V4L2VideoDecodeAccelerator::DecodeBufferInitial( |
744 const void* data, size_t size, size_t* endpos) { | 744 const void* data, size_t size, size_t* endpos) { |
745 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; | 745 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; |
746 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 746 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
747 DCHECK_NE(decoder_state_, kUninitialized); | 747 DCHECK_NE(decoder_state_, kUninitialized); |
748 DCHECK_NE(decoder_state_, kDecoding); | 748 DCHECK_NE(decoder_state_, kDecoding); |
749 DCHECK(!device_poll_thread_.IsRunning()); | 749 DCHECK(!device_poll_thread_.IsRunning()); |
750 // Initial decode. We haven't been able to get output stream format info yet. | 750 // Initial decode. We haven't been able to get output stream format info yet. |
751 // Get it, and start decoding. | 751 // Get it, and start decoding. |
752 | 752 |
753 // Copy in and send to HW. | 753 // Copy in and send to HW. |
754 if (!AppendToInputFrame(data, size)) | 754 if (!AppendToInputFrame(data, size)) |
755 return false; | 755 return false; |
756 | 756 |
757 // If we only have a partial frame, don't flush and process yet. | 757 // If we only have a partial frame, don't flush and process yet. |
758 if (decoder_partial_frame_pending_) | 758 if (decoder_partial_frame_pending_) |
759 return true; | 759 return true; |
760 | 760 |
761 if (!FlushInputFrame()) | 761 if (!FlushInputFrame()) |
762 return false; | 762 return false; |
763 | 763 |
764 // Recycle buffers. | 764 // Recycle buffers. |
765 DequeueMfc(); | 765 Dequeue(); |
766 | 766 |
767 // Check and see if we have format info yet. | 767 // Check and see if we have format info yet. |
768 struct v4l2_format format; | 768 struct v4l2_format format; |
769 bool again = false; | 769 bool again = false; |
770 if (!GetFormatInfo(&format, &again)) | 770 if (!GetFormatInfo(&format, &again)) |
771 return false; | 771 return false; |
772 | 772 |
773 if (again) { | 773 if (again) { |
774 // Need more stream to decode format, return true and schedule next buffer. | 774 // Need more stream to decode format, return true and schedule next buffer. |
775 *endpos = size; | 775 *endpos = size; |
776 return true; | 776 return true; |
777 } | 777 } |
778 | 778 |
779 // Run this initialization only on first startup. | 779 // Run this initialization only on first startup. |
780 if (decoder_state_ == kInitialized) { | 780 if (decoder_state_ == kInitialized) { |
781 DVLOG(3) << "DecodeBufferInitial(): running initialization"; | 781 DVLOG(3) << "DecodeBufferInitial(): running initialization"; |
782 // Success! Setup our parameters. | 782 // Success! Setup our parameters. |
783 if (!CreateBuffersForFormat(format)) | 783 if (!CreateBuffersForFormat(format)) |
784 return false; | 784 return false; |
785 | 785 |
786 // MFC expects to process the initial buffer once during stream init to | 786 // We expect to process the initial buffer once during stream init to |
787 // configure stream parameters, but will not consume the steam data on that | 787 // configure stream parameters, but will not consume the steam data on that |
788 // iteration. Subsequent iterations (including after reset) do not require | 788 // iteration. Subsequent iterations (including after reset) do not require |
789 // the stream init step. | 789 // the stream init step. |
790 *endpos = 0; | 790 *endpos = 0; |
791 } else { | 791 } else { |
792 *endpos = size; | 792 *endpos = size; |
793 } | 793 } |
794 | 794 |
795 // StartDevicePoll will raise the error if there is one. | 795 // StartDevicePoll will raise the error if there is one. |
796 if (!StartDevicePoll()) | 796 if (!StartDevicePoll()) |
797 return false; | 797 return false; |
798 | 798 |
799 decoder_state_ = kDecoding; | 799 decoder_state_ = kDecoding; |
800 ScheduleDecodeBufferTaskIfNeeded(); | 800 ScheduleDecodeBufferTaskIfNeeded(); |
801 return true; | 801 return true; |
802 } | 802 } |
803 | 803 |
804 bool ExynosVideoDecodeAccelerator::DecodeBufferContinue( | 804 bool V4L2VideoDecodeAccelerator::DecodeBufferContinue( |
805 const void* data, size_t size) { | 805 const void* data, size_t size) { |
806 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size; | 806 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size; |
807 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 807 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
808 DCHECK_EQ(decoder_state_, kDecoding); | 808 DCHECK_EQ(decoder_state_, kDecoding); |
809 | 809 |
810 // Both of these calls will set kError state if they fail. | 810 // Both of these calls will set kError state if they fail. |
811 // Only flush the frame if it's complete. | 811 // Only flush the frame if it's complete. |
812 return (AppendToInputFrame(data, size) && | 812 return (AppendToInputFrame(data, size) && |
813 (decoder_partial_frame_pending_ || FlushInputFrame())); | 813 (decoder_partial_frame_pending_ || FlushInputFrame())); |
814 } | 814 } |
815 | 815 |
816 bool ExynosVideoDecodeAccelerator::AppendToInputFrame( | 816 bool V4L2VideoDecodeAccelerator::AppendToInputFrame( |
817 const void* data, size_t size) { | 817 const void* data, size_t size) { |
818 DVLOG(3) << "AppendToInputFrame()"; | 818 DVLOG(3) << "AppendToInputFrame()"; |
819 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 819 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
820 DCHECK_NE(decoder_state_, kUninitialized); | 820 DCHECK_NE(decoder_state_, kUninitialized); |
821 DCHECK_NE(decoder_state_, kResetting); | 821 DCHECK_NE(decoder_state_, kResetting); |
822 DCHECK_NE(decoder_state_, kError); | 822 DCHECK_NE(decoder_state_, kError); |
823 // This routine can handle data == NULL and size == 0, which occurs when | 823 // This routine can handle data == NULL and size == 0, which occurs when |
824 // we queue an empty buffer for the purposes of flushing the pipe. | 824 // we queue an empty buffer for the purposes of flushing the pipe. |
825 | 825 |
826 // Flush if we're too big | 826 // Flush if we're too big |
827 if (decoder_current_input_buffer_ != -1) { | 827 if (decoder_current_input_buffer_ != -1) { |
828 MfcInputRecord& input_record = | 828 InputRecord& input_record = |
829 mfc_input_buffer_map_[decoder_current_input_buffer_]; | 829 input_buffer_map_[decoder_current_input_buffer_]; |
830 if (input_record.bytes_used + size > input_record.length) { | 830 if (input_record.bytes_used + size > input_record.length) { |
831 if (!FlushInputFrame()) | 831 if (!FlushInputFrame()) |
832 return false; | 832 return false; |
833 decoder_current_input_buffer_ = -1; | 833 decoder_current_input_buffer_ = -1; |
834 } | 834 } |
835 } | 835 } |
836 | 836 |
837 // Try to get an available input buffer | 837 // Try to get an available input buffer |
838 if (decoder_current_input_buffer_ == -1) { | 838 if (decoder_current_input_buffer_ == -1) { |
839 if (mfc_free_input_buffers_.empty()) { | 839 if (free_input_buffers_.empty()) { |
840 // See if we can get more free buffers from HW | 840 // See if we can get more free buffers from HW |
841 DequeueMfc(); | 841 Dequeue(); |
842 if (mfc_free_input_buffers_.empty()) { | 842 if (free_input_buffers_.empty()) { |
843 // Nope! | 843 // Nope! |
844 DVLOG(2) << "AppendToInputFrame(): stalled for input buffers"; | 844 DVLOG(2) << "AppendToInputFrame(): stalled for input buffers"; |
845 return false; | 845 return false; |
846 } | 846 } |
847 } | 847 } |
848 decoder_current_input_buffer_ = mfc_free_input_buffers_.back(); | 848 decoder_current_input_buffer_ = free_input_buffers_.back(); |
849 mfc_free_input_buffers_.pop_back(); | 849 free_input_buffers_.pop_back(); |
850 MfcInputRecord& input_record = | 850 InputRecord& input_record = |
851 mfc_input_buffer_map_[decoder_current_input_buffer_]; | 851 input_buffer_map_[decoder_current_input_buffer_]; |
852 DCHECK_EQ(input_record.bytes_used, 0); | 852 DCHECK_EQ(input_record.bytes_used, 0); |
853 DCHECK_EQ(input_record.input_id, -1); | 853 DCHECK_EQ(input_record.input_id, -1); |
854 DCHECK(decoder_current_bitstream_buffer_ != NULL); | 854 DCHECK(decoder_current_bitstream_buffer_ != NULL); |
855 input_record.input_id = decoder_current_bitstream_buffer_->input_id; | 855 input_record.input_id = decoder_current_bitstream_buffer_->input_id; |
856 } | 856 } |
857 | 857 |
858 DCHECK(data != NULL || size == 0); | 858 DCHECK(data != NULL || size == 0); |
859 if (size == 0) { | 859 if (size == 0) { |
860 // If we asked for an empty buffer, return now. We return only after | 860 // If we asked for an empty buffer, return now. We return only after |
861 // getting the next input buffer, since we might actually want an empty | 861 // getting the next input buffer, since we might actually want an empty |
862 // input buffer for flushing purposes. | 862 // input buffer for flushing purposes. |
863 return true; | 863 return true; |
864 } | 864 } |
865 | 865 |
866 // Copy in to the buffer. | 866 // Copy in to the buffer. |
867 MfcInputRecord& input_record = | 867 InputRecord& input_record = |
868 mfc_input_buffer_map_[decoder_current_input_buffer_]; | 868 input_buffer_map_[decoder_current_input_buffer_]; |
869 if (size > input_record.length - input_record.bytes_used) { | 869 if (size > input_record.length - input_record.bytes_used) { |
870 LOG(ERROR) << "AppendToInputFrame(): over-size frame, erroring"; | 870 LOG(ERROR) << "AppendToInputFrame(): over-size frame, erroring"; |
871 NOTIFY_ERROR(UNREADABLE_INPUT); | 871 NOTIFY_ERROR(UNREADABLE_INPUT); |
872 return false; | 872 return false; |
873 } | 873 } |
874 memcpy( | 874 memcpy( |
875 reinterpret_cast<uint8*>(input_record.address) + input_record.bytes_used, | 875 reinterpret_cast<uint8*>(input_record.address) + input_record.bytes_used, |
876 data, | 876 data, |
877 size); | 877 size); |
878 input_record.bytes_used += size; | 878 input_record.bytes_used += size; |
879 | 879 |
880 return true; | 880 return true; |
881 } | 881 } |
882 | 882 |
883 bool ExynosVideoDecodeAccelerator::FlushInputFrame() { | 883 bool V4L2VideoDecodeAccelerator::FlushInputFrame() { |
884 DVLOG(3) << "FlushInputFrame()"; | 884 DVLOG(3) << "FlushInputFrame()"; |
885 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 885 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
886 DCHECK_NE(decoder_state_, kUninitialized); | 886 DCHECK_NE(decoder_state_, kUninitialized); |
887 DCHECK_NE(decoder_state_, kResetting); | 887 DCHECK_NE(decoder_state_, kResetting); |
888 DCHECK_NE(decoder_state_, kError); | 888 DCHECK_NE(decoder_state_, kError); |
889 | 889 |
890 if (decoder_current_input_buffer_ == -1) | 890 if (decoder_current_input_buffer_ == -1) |
891 return true; | 891 return true; |
892 | 892 |
893 MfcInputRecord& input_record = | 893 InputRecord& input_record = |
894 mfc_input_buffer_map_[decoder_current_input_buffer_]; | 894 input_buffer_map_[decoder_current_input_buffer_]; |
895 DCHECK_NE(input_record.input_id, -1); | 895 DCHECK_NE(input_record.input_id, -1); |
896 DCHECK(input_record.input_id != kFlushBufferId || | 896 DCHECK(input_record.input_id != kFlushBufferId || |
897 input_record.bytes_used == 0); | 897 input_record.bytes_used == 0); |
898 // * if input_id >= 0, this input buffer was prompted by a bitstream buffer we | 898 // * if input_id >= 0, this input buffer was prompted by a bitstream buffer we |
899 // got from the client. We can skip it if it is empty. | 899 // got from the client. We can skip it if it is empty. |
900 // * if input_id < 0 (should be kFlushBufferId in this case), this input | 900 // * if input_id < 0 (should be kFlushBufferId in this case), this input |
901 // buffer was prompted by a flush buffer, and should be queued even when | 901 // buffer was prompted by a flush buffer, and should be queued even when |
902 // empty. | 902 // empty. |
903 if (input_record.input_id >= 0 && input_record.bytes_used == 0) { | 903 if (input_record.input_id >= 0 && input_record.bytes_used == 0) { |
904 input_record.input_id = -1; | 904 input_record.input_id = -1; |
905 mfc_free_input_buffers_.push_back(decoder_current_input_buffer_); | 905 free_input_buffers_.push_back(decoder_current_input_buffer_); |
906 decoder_current_input_buffer_ = -1; | 906 decoder_current_input_buffer_ = -1; |
907 return true; | 907 return true; |
908 } | 908 } |
909 | 909 |
910 // Queue it to MFC. | 910 // Queue it. |
911 mfc_input_ready_queue_.push(decoder_current_input_buffer_); | 911 input_ready_queue_.push(decoder_current_input_buffer_); |
912 decoder_current_input_buffer_ = -1; | 912 decoder_current_input_buffer_ = -1; |
913 DVLOG(3) << "FlushInputFrame(): submitting input_id=" | 913 DVLOG(3) << "FlushInputFrame(): submitting input_id=" |
914 << input_record.input_id; | 914 << input_record.input_id; |
915 // Kick the MFC once since there's new available input for it. | 915 // Enqueue since there's new available input for it. |
916 EnqueueMfc(); | 916 Enqueue(); |
917 | 917 |
918 return (decoder_state_ != kError); | 918 return (decoder_state_ != kError); |
919 } | 919 } |
920 | 920 |
921 void ExynosVideoDecodeAccelerator::AssignPictureBuffersTask( | 921 void V4L2VideoDecodeAccelerator::AssignPictureBuffersTask( |
922 scoped_ptr<PictureBufferArrayRef> pic_buffers) { | 922 scoped_ptr<PictureBufferArrayRef> pic_buffers) { |
923 DVLOG(3) << "AssignPictureBuffersTask()"; | 923 DVLOG(3) << "AssignPictureBuffersTask()"; |
924 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 924 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
925 DCHECK_NE(decoder_state_, kUninitialized); | 925 DCHECK_NE(decoder_state_, kUninitialized); |
926 TRACE_EVENT0("Video Decoder", "EVDA::AssignPictureBuffersTask"); | 926 TRACE_EVENT0("Video Decoder", "V4L2VDA::AssignPictureBuffersTask"); |
927 | 927 |
928 // We run AssignPictureBuffersTask even if we're in kResetting. | 928 // We run AssignPictureBuffersTask even if we're in kResetting. |
929 if (decoder_state_ == kError) { | 929 if (decoder_state_ == kError) { |
930 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state"; | 930 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state"; |
931 return; | 931 return; |
932 } | 932 } |
933 | 933 |
934 DCHECK_EQ(pic_buffers->picture_buffers.size(), mfc_output_buffer_map_.size()); | 934 DCHECK_EQ(pic_buffers->picture_buffers.size(), output_buffer_map_.size()); |
935 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { | 935 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { |
936 MfcOutputRecord& output_record = mfc_output_buffer_map_[i]; | 936 OutputRecord& output_record = output_buffer_map_[i]; |
937 PictureBufferArrayRef::PictureBufferRef& buffer_ref = | 937 PictureBufferArrayRef::PictureBufferRef& buffer_ref = |
938 pic_buffers->picture_buffers[i]; | 938 pic_buffers->picture_buffers[i]; |
939 // We should be blank right now. | 939 // We should be blank right now. |
940 DCHECK(!output_record.at_device); | 940 DCHECK(!output_record.at_device); |
941 DCHECK(!output_record.at_client); | 941 DCHECK(!output_record.at_client); |
942 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR); | 942 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR); |
943 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); | 943 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); |
944 DCHECK_EQ(output_record.picture_id, -1); | 944 DCHECK_EQ(output_record.picture_id, -1); |
945 DCHECK_EQ(output_record.cleared, false); | 945 DCHECK_EQ(output_record.cleared, false); |
946 output_record.egl_image = buffer_ref.egl_image; | 946 output_record.egl_image = buffer_ref.egl_image; |
947 output_record.picture_id = buffer_ref.picture_id; | 947 output_record.picture_id = buffer_ref.picture_id; |
948 mfc_free_output_buffers_.push(i); | 948 free_output_buffers_.push(i); |
949 DVLOG(3) << "AssignPictureBuffersTask(): buffer[" << i | 949 DVLOG(3) << "AssignPictureBuffersTask(): buffer[" << i |
950 << "]: picture_id=" << buffer_ref.picture_id; | 950 << "]: picture_id=" << buffer_ref.picture_id; |
951 } | 951 } |
952 pic_buffers->picture_buffers.clear(); | 952 pic_buffers->picture_buffers.clear(); |
953 | 953 |
954 // We got buffers! Kick the MFC. | 954 // We got buffers! Enqueue. |
955 EnqueueMfc(); | 955 Enqueue(); |
956 | 956 |
957 if (decoder_state_ == kChangingResolution) | 957 if (decoder_state_ == kChangingResolution) |
958 ResumeAfterResolutionChange(); | 958 ResumeAfterResolutionChange(); |
959 } | 959 } |
960 | 960 |
961 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool mfc_event_pending) { | 961 void V4L2VideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) { |
962 DVLOG(3) << "ServiceDeviceTask()"; | 962 DVLOG(3) << "ServiceDeviceTask()"; |
963 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 963 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
964 DCHECK_NE(decoder_state_, kUninitialized); | 964 DCHECK_NE(decoder_state_, kUninitialized); |
965 DCHECK_NE(decoder_state_, kInitialized); | 965 DCHECK_NE(decoder_state_, kInitialized); |
966 DCHECK_NE(decoder_state_, kAfterReset); | 966 DCHECK_NE(decoder_state_, kAfterReset); |
967 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); | 967 TRACE_EVENT0("Video Decoder", "V4L2VDA::ServiceDeviceTask"); |
968 | 968 |
969 if (decoder_state_ == kResetting) { | 969 if (decoder_state_ == kResetting) { |
970 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; | 970 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; |
971 return; | 971 return; |
972 } else if (decoder_state_ == kError) { | 972 } else if (decoder_state_ == kError) { |
973 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; | 973 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; |
974 return; | 974 return; |
975 } else if (decoder_state_ == kChangingResolution) { | 975 } else if (decoder_state_ == kChangingResolution) { |
976 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state"; | 976 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state"; |
977 return; | 977 return; |
978 } | 978 } |
979 | 979 |
980 if (mfc_event_pending) | 980 if (event_pending) |
981 DequeueMfcEvents(); | 981 DequeueEvents(); |
982 DequeueMfc(); | 982 Dequeue(); |
983 EnqueueMfc(); | 983 Enqueue(); |
984 | 984 |
985 // Clear the interrupt fd. | 985 // Clear the interrupt fd. |
986 if (!ClearDevicePollInterrupt()) | 986 if (!ClearDevicePollInterrupt()) |
987 return; | 987 return; |
988 | 988 |
989 unsigned int poll_fds = 0; | 989 unsigned int poll_fds = 0; |
990 // Add MFC fd, if we should poll on it. | 990 // Add fd, if we should poll on it. |
991 // MFC can be polled as soon as either input or output buffers are queued. | 991 // can be polled as soon as either input or output buffers are queued. |
992 if (mfc_input_buffer_queued_count_ + mfc_output_buffer_queued_count_ > 0) | 992 if (input_buffer_queued_count_ + output_buffer_queued_count_ > 0) |
993 poll_fds |= kPollMfc; | 993 poll_fds |= kPoll; |
994 | 994 |
995 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(), | 995 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(), |
996 // so either: | 996 // so either: |
997 // * device_poll_thread_ is running normally | 997 // * device_poll_thread_ is running normally |
998 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask() | 998 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask() |
999 // shut it down, in which case we're either in kResetting or kError states | 999 // shut it down, in which case we're either in kResetting or kError states |
1000 // respectively, and we should have early-outed already. | 1000 // respectively, and we should have early-outed already. |
1001 DCHECK(device_poll_thread_.message_loop()); | 1001 DCHECK(device_poll_thread_.message_loop()); |
1002 // Queue the DevicePollTask() now. | 1002 // Queue the DevicePollTask() now. |
1003 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1003 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1004 &ExynosVideoDecodeAccelerator::DevicePollTask, | 1004 &V4L2VideoDecodeAccelerator::DevicePollTask, |
1005 base::Unretained(this), | 1005 base::Unretained(this), |
1006 poll_fds)); | 1006 poll_fds)); |
1007 | 1007 |
1008 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC[" | 1008 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC[" |
1009 << decoder_input_queue_.size() << "->" | 1009 << decoder_input_queue_.size() << "->" |
1010 << mfc_input_ready_queue_.size() << "] => MFC[" | 1010 << input_ready_queue_.size() << "] => DEVICE[" |
1011 << mfc_free_input_buffers_.size() << "+" | 1011 << free_input_buffers_.size() << "+" |
1012 << mfc_input_buffer_queued_count_ << "/" | 1012 << input_buffer_queued_count_ << "/" |
1013 << mfc_input_buffer_map_.size() << "->" | 1013 << input_buffer_map_.size() << "->" |
1014 << mfc_free_output_buffers_.size() << "+" | 1014 << free_output_buffers_.size() << "+" |
1015 << mfc_output_buffer_queued_count_ << "/" | 1015 << output_buffer_queued_count_ << "/" |
1016 << mfc_output_buffer_map_.size() << "] => VDA[" | 1016 << output_buffer_map_.size() << "] => VDA[" |
1017 << decoder_frames_at_client_ << "]"; | 1017 << decoder_frames_at_client_ << "]"; |
1018 | 1018 |
1019 ScheduleDecodeBufferTaskIfNeeded(); | 1019 ScheduleDecodeBufferTaskIfNeeded(); |
1020 StartResolutionChangeIfNeeded(); | 1020 StartResolutionChangeIfNeeded(); |
1021 } | 1021 } |
1022 | 1022 |
1023 void ExynosVideoDecodeAccelerator::EnqueueMfc() { | 1023 void V4L2VideoDecodeAccelerator::Enqueue() { |
1024 DVLOG(3) << "EnqueueMfc()"; | 1024 DVLOG(3) << "Enqueue()"; |
1025 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1025 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1026 DCHECK_NE(decoder_state_, kUninitialized); | 1026 DCHECK_NE(decoder_state_, kUninitialized); |
1027 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); | 1027 TRACE_EVENT0("Video Decoder", "V4L2VDA::Enqueue"); |
1028 | 1028 |
1029 // Drain the pipe of completed decode buffers. | 1029 // Drain the pipe of completed decode buffers. |
1030 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; | 1030 const int old_inputs_queued = input_buffer_queued_count_; |
1031 while (!mfc_input_ready_queue_.empty()) { | 1031 while (!input_ready_queue_.empty()) { |
1032 if (!EnqueueMfcInputRecord()) | 1032 if (!EnqueueInputRecord()) |
1033 return; | 1033 return; |
1034 } | 1034 } |
1035 if (old_mfc_inputs_queued == 0 && mfc_input_buffer_queued_count_ != 0) { | 1035 if (old_inputs_queued == 0 && input_buffer_queued_count_ != 0) { |
1036 // We just started up a previously empty queue. | 1036 // We just started up a previously empty queue. |
1037 // Queue state changed; signal interrupt. | 1037 // Queue state changed; signal interrupt. |
1038 if (!SetDevicePollInterrupt()) | 1038 if (!SetDevicePollInterrupt()) |
1039 return; | 1039 return; |
1040 // Start VIDIOC_STREAMON if we haven't yet. | 1040 // Start VIDIOC_STREAMON if we haven't yet. |
1041 if (!mfc_input_streamon_) { | 1041 if (!input_streamon_) { |
1042 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1042 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1043 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); | 1043 IOCTL_OR_ERROR_RETURN(fd_, VIDIOC_STREAMON, &type); |
1044 mfc_input_streamon_ = true; | 1044 input_streamon_ = true; |
1045 } | 1045 } |
1046 } | 1046 } |
1047 | 1047 |
1048 // Enqueue all the MFC outputs we can. | 1048 // Enqueue all the outputs we can. |
1049 const int old_mfc_outputs_queued = mfc_output_buffer_queued_count_; | 1049 const int old_outputs_queued = output_buffer_queued_count_; |
1050 while (!mfc_free_output_buffers_.empty()) { | 1050 while (!free_output_buffers_.empty()) { |
1051 if (!EnqueueMfcOutputRecord()) | 1051 if (!EnqueueOutputRecord()) |
1052 return; | 1052 return; |
1053 } | 1053 } |
1054 if (old_mfc_outputs_queued == 0 && mfc_output_buffer_queued_count_ != 0) { | 1054 if (old_outputs_queued == 0 && output_buffer_queued_count_ != 0) { |
1055 // We just started up a previously empty queue. | 1055 // We just started up a previously empty queue. |
1056 // Queue state changed; signal interrupt. | 1056 // Queue state changed; signal interrupt. |
1057 if (!SetDevicePollInterrupt()) | 1057 if (!SetDevicePollInterrupt()) |
1058 return; | 1058 return; |
1059 // Start VIDIOC_STREAMON if we haven't yet. | 1059 // Start VIDIOC_STREAMON if we haven't yet. |
1060 if (!mfc_output_streamon_) { | 1060 if (!output_streamon_) { |
1061 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1061 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1062 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); | 1062 IOCTL_OR_ERROR_RETURN(fd_, VIDIOC_STREAMON, &type); |
1063 mfc_output_streamon_ = true; | 1063 output_streamon_ = true; |
1064 } | 1064 } |
1065 } | 1065 } |
1066 } | 1066 } |
1067 | 1067 |
1068 void ExynosVideoDecodeAccelerator::DequeueMfcEvents() { | 1068 void V4L2VideoDecodeAccelerator::DequeueEvents() { |
1069 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1069 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1070 DCHECK_NE(decoder_state_, kUninitialized); | 1070 DCHECK_NE(decoder_state_, kUninitialized); |
1071 DVLOG(3) << "DequeueMfcEvents()"; | 1071 DVLOG(3) << "DequeueEvents()"; |
1072 | 1072 |
1073 struct v4l2_event ev; | 1073 struct v4l2_event ev; |
1074 memset(&ev, 0, sizeof(ev)); | 1074 memset(&ev, 0, sizeof(ev)); |
1075 | 1075 |
1076 while (ioctl(mfc_fd_, VIDIOC_DQEVENT, &ev) == 0) { | 1076 while (ioctl(fd_, VIDIOC_DQEVENT, &ev) == 0) { |
1077 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) { | 1077 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) { |
1078 DVLOG(3) << "DequeueMfcEvents(): got resolution change event."; | 1078 DVLOG(3) << "DequeueEvents(): got resolution change event."; |
1079 DCHECK(!resolution_change_pending_); | 1079 DCHECK(!resolution_change_pending_); |
1080 resolution_change_pending_ = true; | 1080 resolution_change_pending_ = true; |
1081 } else { | 1081 } else { |
1082 DLOG(FATAL) << "DequeueMfcEvents(): got an event (" << ev.type | 1082 DLOG(FATAL) << "DequeueEvents(): got an event (" << ev.type |
1083 << ") we haven't subscribed to."; | 1083 << ") we haven't subscribed to."; |
1084 } | 1084 } |
1085 } | 1085 } |
1086 } | 1086 } |
1087 | 1087 |
1088 void ExynosVideoDecodeAccelerator::DequeueMfc() { | 1088 void V4L2VideoDecodeAccelerator::Dequeue() { |
1089 DVLOG(3) << "DequeueMfc()"; | 1089 DVLOG(3) << "Dequeue()"; |
1090 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1090 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1091 DCHECK_NE(decoder_state_, kUninitialized); | 1091 DCHECK_NE(decoder_state_, kUninitialized); |
1092 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); | 1092 TRACE_EVENT0("Video Decoder", "V4L2VDA::Dequeue"); |
1093 | 1093 |
1094 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free | 1094 // Dequeue completed input (VIDEO_OUTPUT) buffers, and recycle to the free |
1095 // list. | 1095 // list. |
1096 struct v4l2_buffer dqbuf; | 1096 struct v4l2_buffer dqbuf; |
1097 struct v4l2_plane planes[2]; | 1097 struct v4l2_plane planes[2]; |
1098 while (mfc_input_buffer_queued_count_ > 0) { | 1098 while (input_buffer_queued_count_ > 0) { |
1099 DCHECK(mfc_input_streamon_); | 1099 DCHECK(input_streamon_); |
1100 memset(&dqbuf, 0, sizeof(dqbuf)); | 1100 memset(&dqbuf, 0, sizeof(dqbuf)); |
1101 memset(planes, 0, sizeof(planes)); | 1101 memset(planes, 0, sizeof(planes)); |
1102 dqbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1102 dqbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1103 dqbuf.memory = V4L2_MEMORY_MMAP; | 1103 dqbuf.memory = V4L2_MEMORY_MMAP; |
1104 dqbuf.m.planes = planes; | 1104 dqbuf.m.planes = planes; |
1105 dqbuf.length = 1; | 1105 dqbuf.length = 1; |
1106 if (ioctl(mfc_fd_, VIDIOC_DQBUF, &dqbuf) != 0) { | 1106 if (ioctl(fd_, VIDIOC_DQBUF, &dqbuf) != 0) { |
1107 if (errno == EAGAIN) { | 1107 if (errno == EAGAIN) { |
1108 // EAGAIN if we're just out of buffers to dequeue. | 1108 // EAGAIN if we're just out of buffers to dequeue. |
1109 break; | 1109 break; |
1110 } | 1110 } |
1111 DPLOG(ERROR) << "DequeueMfc(): ioctl() failed: VIDIOC_DQBUF"; | 1111 DPLOG(ERROR) << "Dequeue(): ioctl() failed: VIDIOC_DQBUF"; |
1112 NOTIFY_ERROR(PLATFORM_FAILURE); | 1112 NOTIFY_ERROR(PLATFORM_FAILURE); |
1113 return; | 1113 return; |
1114 } | 1114 } |
1115 MfcInputRecord& input_record = mfc_input_buffer_map_[dqbuf.index]; | 1115 InputRecord& input_record = input_buffer_map_[dqbuf.index]; |
1116 DCHECK(input_record.at_device); | 1116 DCHECK(input_record.at_device); |
1117 mfc_free_input_buffers_.push_back(dqbuf.index); | 1117 free_input_buffers_.push_back(dqbuf.index); |
1118 input_record.at_device = false; | 1118 input_record.at_device = false; |
1119 input_record.bytes_used = 0; | 1119 input_record.bytes_used = 0; |
1120 input_record.input_id = -1; | 1120 input_record.input_id = -1; |
1121 mfc_input_buffer_queued_count_--; | 1121 input_buffer_queued_count_--; |
1122 } | 1122 } |
1123 | 1123 |
1124 // Dequeue completed MFC output (VIDEO_CAPTURE) buffers, and queue to the | 1124 // Dequeue completed output (VIDEO_CAPTURE) buffers, and queue to the |
1125 // completed queue. | 1125 // completed queue. |
1126 while (mfc_output_buffer_queued_count_ > 0) { | 1126 while (output_buffer_queued_count_ > 0) { |
1127 DCHECK(mfc_output_streamon_); | 1127 DCHECK(output_streamon_); |
1128 memset(&dqbuf, 0, sizeof(dqbuf)); | 1128 memset(&dqbuf, 0, sizeof(dqbuf)); |
1129 memset(planes, 0, sizeof(planes)); | 1129 memset(planes, 0, sizeof(planes)); |
1130 dqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1130 dqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1131 dqbuf.memory = V4L2_MEMORY_MMAP; | 1131 dqbuf.memory = V4L2_MEMORY_MMAP; |
1132 dqbuf.m.planes = planes; | 1132 dqbuf.m.planes = planes; |
1133 dqbuf.length = 2; | 1133 dqbuf.length = 2; |
1134 if (ioctl(mfc_fd_, VIDIOC_DQBUF, &dqbuf) != 0) { | 1134 if (ioctl(fd_, VIDIOC_DQBUF, &dqbuf) != 0) { |
1135 if (errno == EAGAIN) { | 1135 if (errno == EAGAIN) { |
1136 // EAGAIN if we're just out of buffers to dequeue. | 1136 // EAGAIN if we're just out of buffers to dequeue. |
1137 break; | 1137 break; |
1138 } | 1138 } |
1139 DPLOG(ERROR) << "DequeueMfc(): ioctl() failed: VIDIOC_DQBUF"; | 1139 DPLOG(ERROR) << "Dequeue(): ioctl() failed: VIDIOC_DQBUF"; |
1140 NOTIFY_ERROR(PLATFORM_FAILURE); | 1140 NOTIFY_ERROR(PLATFORM_FAILURE); |
1141 return; | 1141 return; |
1142 } | 1142 } |
1143 MfcOutputRecord& output_record = mfc_output_buffer_map_[dqbuf.index]; | 1143 OutputRecord& output_record = output_buffer_map_[dqbuf.index]; |
1144 DCHECK(output_record.at_device); | 1144 DCHECK(output_record.at_device); |
1145 DCHECK(!output_record.at_client); | 1145 DCHECK(!output_record.at_client); |
1146 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); | 1146 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); |
1147 DCHECK_NE(output_record.picture_id, -1); | 1147 DCHECK_NE(output_record.picture_id, -1); |
1148 output_record.at_device = false; | 1148 output_record.at_device = false; |
1149 if (dqbuf.m.planes[0].bytesused + dqbuf.m.planes[1].bytesused == 0) { | 1149 if (dqbuf.m.planes[0].bytesused + dqbuf.m.planes[1].bytesused == 0) { |
1150 // This is an empty output buffer returned as part of a flush. | 1150 // This is an empty output buffer returned as part of a flush. |
1151 mfc_free_output_buffers_.push(dqbuf.index); | 1151 free_output_buffers_.push(dqbuf.index); |
1152 } else { | 1152 } else { |
1153 DCHECK_GE(dqbuf.timestamp.tv_sec, 0); | 1153 DCHECK_GE(dqbuf.timestamp.tv_sec, 0); |
1154 output_record.at_client = true; | 1154 output_record.at_client = true; |
1155 DVLOG(3) << "DequeueMfc(): returning input_id=" << dqbuf.timestamp.tv_sec | 1155 DVLOG(3) << "Dequeue(): returning input_id=" << dqbuf.timestamp.tv_sec |
1156 << " as picture_id=" << output_record.picture_id; | 1156 << " as picture_id=" << output_record.picture_id; |
1157 const media::Picture& picture = | 1157 const media::Picture& picture = |
1158 media::Picture(output_record.picture_id, dqbuf.timestamp.tv_sec); | 1158 media::Picture(output_record.picture_id, dqbuf.timestamp.tv_sec); |
1159 pending_picture_ready_.push( | 1159 pending_picture_ready_.push( |
1160 PictureRecord(output_record.cleared, picture)); | 1160 PictureRecord(output_record.cleared, picture)); |
1161 SendPictureReady(); | 1161 SendPictureReady(); |
1162 output_record.cleared = true; | 1162 output_record.cleared = true; |
1163 decoder_frames_at_client_++; | 1163 decoder_frames_at_client_++; |
1164 } | 1164 } |
1165 mfc_output_buffer_queued_count_--; | 1165 output_buffer_queued_count_--; |
1166 } | 1166 } |
1167 | 1167 |
1168 NotifyFlushDoneIfNeeded(); | 1168 NotifyFlushDoneIfNeeded(); |
1169 } | 1169 } |
1170 | 1170 |
1171 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() { | 1171 bool V4L2VideoDecodeAccelerator::EnqueueInputRecord() { |
1172 DVLOG(3) << "EnqueueMfcInputRecord()"; | 1172 DVLOG(3) << "EnqueueInputRecord()"; |
1173 DCHECK(!mfc_input_ready_queue_.empty()); | 1173 DCHECK(!input_ready_queue_.empty()); |
1174 | 1174 |
1175 // Enqueue a MFC input (VIDEO_OUTPUT) buffer. | 1175 // Enqueue a input (VIDEO_OUTPUT) buffer. |
Pawel Osciak
2014/01/07 07:18:12
s/a/an/
| |
1176 const int buffer = mfc_input_ready_queue_.front(); | 1176 const int buffer = input_ready_queue_.front(); |
1177 MfcInputRecord& input_record = mfc_input_buffer_map_[buffer]; | 1177 InputRecord& input_record = input_buffer_map_[buffer]; |
1178 DCHECK(!input_record.at_device); | 1178 DCHECK(!input_record.at_device); |
1179 struct v4l2_buffer qbuf; | 1179 struct v4l2_buffer qbuf; |
1180 struct v4l2_plane qbuf_plane; | 1180 struct v4l2_plane qbuf_plane; |
1181 memset(&qbuf, 0, sizeof(qbuf)); | 1181 memset(&qbuf, 0, sizeof(qbuf)); |
1182 memset(&qbuf_plane, 0, sizeof(qbuf_plane)); | 1182 memset(&qbuf_plane, 0, sizeof(qbuf_plane)); |
1183 qbuf.index = buffer; | 1183 qbuf.index = buffer; |
1184 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1184 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1185 qbuf.timestamp.tv_sec = input_record.input_id; | 1185 qbuf.timestamp.tv_sec = input_record.input_id; |
1186 qbuf.memory = V4L2_MEMORY_MMAP; | 1186 qbuf.memory = V4L2_MEMORY_MMAP; |
1187 qbuf.m.planes = &qbuf_plane; | 1187 qbuf.m.planes = &qbuf_plane; |
1188 qbuf.m.planes[0].bytesused = input_record.bytes_used; | 1188 qbuf.m.planes[0].bytesused = input_record.bytes_used; |
1189 qbuf.length = 1; | 1189 qbuf.length = 1; |
1190 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); | 1190 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_QBUF, &qbuf); |
1191 mfc_input_ready_queue_.pop(); | 1191 input_ready_queue_.pop(); |
1192 input_record.at_device = true; | 1192 input_record.at_device = true; |
1193 mfc_input_buffer_queued_count_++; | 1193 input_buffer_queued_count_++; |
1194 DVLOG(3) << "EnqueueMfcInputRecord(): enqueued input_id=" | 1194 DVLOG(3) << "EnqueueInputRecord(): enqueued input_id=" |
1195 << input_record.input_id; | 1195 << input_record.input_id; |
1196 return true; | 1196 return true; |
1197 } | 1197 } |
1198 | 1198 |
1199 bool ExynosVideoDecodeAccelerator::EnqueueMfcOutputRecord() { | 1199 bool V4L2VideoDecodeAccelerator::EnqueueOutputRecord() { |
1200 DVLOG(3) << "EnqueueMfcOutputRecord()"; | 1200 DVLOG(3) << "EnqueueOutputRecord()"; |
1201 DCHECK(!mfc_free_output_buffers_.empty()); | 1201 DCHECK(!free_output_buffers_.empty()); |
1202 | 1202 |
1203 // Enqueue a MFC output (VIDEO_CAPTURE) buffer. | 1203 // Enqueue a output (VIDEO_CAPTURE) buffer. |
Pawel Osciak
2014/01/07 07:18:12
s/a/an/
| |
1204 const int buffer = mfc_free_output_buffers_.front(); | 1204 const int buffer = free_output_buffers_.front(); |
1205 MfcOutputRecord& output_record = mfc_output_buffer_map_[buffer]; | 1205 OutputRecord& output_record = output_buffer_map_[buffer]; |
1206 DCHECK(!output_record.at_device); | 1206 DCHECK(!output_record.at_device); |
1207 DCHECK(!output_record.at_client); | 1207 DCHECK(!output_record.at_client); |
1208 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); | 1208 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); |
1209 DCHECK_NE(output_record.picture_id, -1); | 1209 DCHECK_NE(output_record.picture_id, -1); |
1210 if (output_record.egl_sync != EGL_NO_SYNC_KHR) { | 1210 if (output_record.egl_sync != EGL_NO_SYNC_KHR) { |
1211 TRACE_EVENT0("Video Decoder", | 1211 TRACE_EVENT0("Video Decoder", |
1212 "EVDA::EnqueueMfcOutputRecord: eglClientWaitSyncKHR"); | 1212 "V4L2VDA::EnqueueOutputRecord: eglClientWaitSyncKHR"); |
1213 // If we have to wait for completion, wait. Note that | 1213 // If we have to wait for completion, wait. Note that |
1214 // mfc_free_output_buffers_ is a FIFO queue, so we always wait on the | 1214 // free_output_buffers_ is a FIFO queue, so we always wait on the |
1215 // buffer that has been in the queue the longest. | 1215 // buffer that has been in the queue the longest. |
1216 eglClientWaitSyncKHR(egl_display_, output_record.egl_sync, 0, | 1216 eglClientWaitSyncKHR(egl_display_, output_record.egl_sync, 0, |
1217 EGL_FOREVER_KHR); | 1217 EGL_FOREVER_KHR); |
1218 eglDestroySyncKHR(egl_display_, output_record.egl_sync); | 1218 eglDestroySyncKHR(egl_display_, output_record.egl_sync); |
1219 output_record.egl_sync = EGL_NO_SYNC_KHR; | 1219 output_record.egl_sync = EGL_NO_SYNC_KHR; |
1220 } | 1220 } |
1221 struct v4l2_buffer qbuf; | 1221 struct v4l2_buffer qbuf; |
1222 struct v4l2_plane qbuf_planes[arraysize(output_record.fds)]; | 1222 struct v4l2_plane qbuf_planes[arraysize(output_record.fds)]; |
1223 memset(&qbuf, 0, sizeof(qbuf)); | 1223 memset(&qbuf, 0, sizeof(qbuf)); |
1224 memset(qbuf_planes, 0, sizeof(qbuf_planes)); | 1224 memset(qbuf_planes, 0, sizeof(qbuf_planes)); |
1225 qbuf.index = buffer; | 1225 qbuf.index = buffer; |
1226 qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1226 qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1227 qbuf.memory = V4L2_MEMORY_MMAP; | 1227 qbuf.memory = V4L2_MEMORY_MMAP; |
1228 qbuf.m.planes = qbuf_planes; | 1228 qbuf.m.planes = qbuf_planes; |
1229 qbuf.length = arraysize(output_record.fds); | 1229 qbuf.length = arraysize(output_record.fds); |
1230 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); | 1230 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_QBUF, &qbuf); |
1231 mfc_free_output_buffers_.pop(); | 1231 free_output_buffers_.pop(); |
1232 output_record.at_device = true; | 1232 output_record.at_device = true; |
1233 mfc_output_buffer_queued_count_++; | 1233 output_buffer_queued_count_++; |
1234 return true; | 1234 return true; |
1235 } | 1235 } |
1236 | 1236 |
1237 void ExynosVideoDecodeAccelerator::ReusePictureBufferTask( | 1237 void V4L2VideoDecodeAccelerator::ReusePictureBufferTask( |
1238 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { | 1238 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { |
1239 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" | 1239 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" |
1240 << picture_buffer_id; | 1240 << picture_buffer_id; |
1241 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1241 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1242 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); | 1242 TRACE_EVENT0("Video Decoder", "V4L2VDA::ReusePictureBufferTask"); |
1243 | 1243 |
1244 // We run ReusePictureBufferTask even if we're in kResetting. | 1244 // We run ReusePictureBufferTask even if we're in kResetting. |
1245 if (decoder_state_ == kError) { | 1245 if (decoder_state_ == kError) { |
1246 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; | 1246 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; |
1247 return; | 1247 return; |
1248 } | 1248 } |
1249 | 1249 |
1250 if (decoder_state_ == kChangingResolution) { | 1250 if (decoder_state_ == kChangingResolution) { |
1251 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution"; | 1251 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution"; |
1252 return; | 1252 return; |
1253 } | 1253 } |
1254 | 1254 |
1255 size_t index; | 1255 size_t index; |
1256 for (index = 0; index < mfc_output_buffer_map_.size(); ++index) | 1256 for (index = 0; index < output_buffer_map_.size(); ++index) |
1257 if (mfc_output_buffer_map_[index].picture_id == picture_buffer_id) | 1257 if (output_buffer_map_[index].picture_id == picture_buffer_id) |
1258 break; | 1258 break; |
1259 | 1259 |
1260 if (index >= mfc_output_buffer_map_.size()) { | 1260 if (index >= output_buffer_map_.size()) { |
1261 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; | 1261 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; |
1262 NOTIFY_ERROR(INVALID_ARGUMENT); | 1262 NOTIFY_ERROR(INVALID_ARGUMENT); |
1263 return; | 1263 return; |
1264 } | 1264 } |
1265 | 1265 |
1266 MfcOutputRecord& output_record = mfc_output_buffer_map_[index]; | 1266 OutputRecord& output_record = output_buffer_map_[index]; |
1267 if (output_record.at_device || !output_record.at_client) { | 1267 if (output_record.at_device || !output_record.at_client) { |
1268 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not reusable"; | 1268 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not reusable"; |
1269 NOTIFY_ERROR(INVALID_ARGUMENT); | 1269 NOTIFY_ERROR(INVALID_ARGUMENT); |
1270 return; | 1270 return; |
1271 } | 1271 } |
1272 | 1272 |
1273 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); | 1273 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); |
1274 output_record.at_client = false; | 1274 output_record.at_client = false; |
1275 output_record.egl_sync = egl_sync_ref->egl_sync; | 1275 output_record.egl_sync = egl_sync_ref->egl_sync; |
1276 mfc_free_output_buffers_.push(index); | 1276 free_output_buffers_.push(index); |
1277 decoder_frames_at_client_--; | 1277 decoder_frames_at_client_--; |
1278 // Take ownership of the EGLSync. | 1278 // Take ownership of the EGLSync. |
1279 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; | 1279 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; |
1280 // We got a buffer back, so kick the MFC. | 1280 // We got a buffer back, so enqueue it back. |
1281 EnqueueMfc(); | 1281 Enqueue(); |
1282 } | 1282 } |
1283 | 1283 |
1284 void ExynosVideoDecodeAccelerator::FlushTask() { | 1284 void V4L2VideoDecodeAccelerator::FlushTask() { |
1285 DVLOG(3) << "FlushTask()"; | 1285 DVLOG(3) << "FlushTask()"; |
1286 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1286 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1287 TRACE_EVENT0("Video Decoder", "EVDA::FlushTask"); | 1287 TRACE_EVENT0("Video Decoder", "V4L2VDA::FlushTask"); |
1288 | 1288 |
1289 // Flush outstanding buffers. | 1289 // Flush outstanding buffers. |
1290 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { | 1290 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { |
1291 // There's nothing in the pipe, so return done immediately. | 1291 // There's nothing in the pipe, so return done immediately. |
1292 DVLOG(3) << "FlushTask(): returning flush"; | 1292 DVLOG(3) << "FlushTask(): returning flush"; |
1293 child_message_loop_proxy_->PostTask( | 1293 child_message_loop_proxy_->PostTask( |
1294 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); | 1294 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); |
1295 return; | 1295 return; |
1296 } else if (decoder_state_ == kError) { | 1296 } else if (decoder_state_ == kError) { |
1297 DVLOG(2) << "FlushTask(): early out: kError state"; | 1297 DVLOG(2) << "FlushTask(): early out: kError state"; |
1298 return; | 1298 return; |
1299 } | 1299 } |
1300 | 1300 |
1301 // We don't support stacked flushing. | 1301 // We don't support stacked flushing. |
1302 DCHECK(!decoder_flushing_); | 1302 DCHECK(!decoder_flushing_); |
1303 | 1303 |
1304 // Queue up an empty buffer -- this triggers the flush. | 1304 // Queue up an empty buffer -- this triggers the flush. |
1305 decoder_input_queue_.push( | 1305 decoder_input_queue_.push( |
1306 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( | 1306 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( |
1307 io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId))); | 1307 io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId))); |
1308 decoder_flushing_ = true; | 1308 decoder_flushing_ = true; |
1309 SendPictureReady(); // Send all pending PictureReady. | 1309 SendPictureReady(); // Send all pending PictureReady. |
1310 | 1310 |
1311 ScheduleDecodeBufferTaskIfNeeded(); | 1311 ScheduleDecodeBufferTaskIfNeeded(); |
1312 } | 1312 } |
1313 | 1313 |
1314 void ExynosVideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { | 1314 void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { |
1315 if (!decoder_flushing_) | 1315 if (!decoder_flushing_) |
1316 return; | 1316 return; |
1317 | 1317 |
1318 // Pipeline is empty when: | 1318 // Pipeline is empty when: |
1319 // * Decoder input queue is empty of non-delayed buffers. | 1319 // * Decoder input queue is empty of non-delayed buffers. |
1320 // * There is no currently filling input buffer. | 1320 // * There is no currently filling input buffer. |
1321 // * MFC input holding queue is empty. | 1321 // * input holding queue is empty. |
1322 // * All MFC input (VIDEO_OUTPUT) buffers are returned. | 1322 // * All input (VIDEO_OUTPUT) buffers are returned. |
1323 if (!decoder_input_queue_.empty()) { | 1323 if (!decoder_input_queue_.empty()) { |
1324 if (decoder_input_queue_.front()->input_id != | 1324 if (decoder_input_queue_.front()->input_id != |
1325 decoder_delay_bitstream_buffer_id_) | 1325 decoder_delay_bitstream_buffer_id_) |
1326 return; | 1326 return; |
1327 } | 1327 } |
1328 if (decoder_current_input_buffer_ != -1) | 1328 if (decoder_current_input_buffer_ != -1) |
1329 return; | 1329 return; |
1330 if ((mfc_input_ready_queue_.size() + mfc_input_buffer_queued_count_) != 0) | 1330 if ((input_ready_queue_.size() + input_buffer_queued_count_) != 0) |
1331 return; | 1331 return; |
1332 | 1332 |
1333 // TODO(posciak): crbug.com/270039. MFC requires a streamoff-streamon | 1333 // TODO(posciak): crbug.com/270039. Exynos requires a streamoff-streamon |
1334 // sequence after flush to continue, even if we are not resetting. This would | 1334 // sequence after flush to continue, even if we are not resetting. This would |
1335 // make sense, because we don't really want to resume from a non-resume point | 1335 // make sense, because we don't really want to resume from a non-resume point |
1336 // (e.g. not from an IDR) if we are flushed. | 1336 // (e.g. not from an IDR) if we are flushed. |
1337 // MSE player however triggers a Flush() on chunk end, but never Reset(). One | 1337 // MSE player however triggers a Flush() on chunk end, but never Reset(). One |
1338 // could argue either way, or even say that Flush() is not needed/harmful when | 1338 // could argue either way, or even say that Flush() is not needed/harmful when |
1339 // transitioning to next chunk. | 1339 // transitioning to next chunk. |
1340 // For now, do the streamoff-streamon cycle to satisfy MFC and not freeze when | 1340 // For now, do the streamoff-streamon cycle to satisfy Exynos and not freeze |
1341 // doing MSE. This should be harmless otherwise. | 1341 // when doing MSE. This should be harmless otherwise. |
1342 if (!StopDevicePoll(false)) | 1342 if (!StopDevicePoll(false)) |
1343 return; | 1343 return; |
1344 | 1344 |
1345 if (!StartDevicePoll()) | 1345 if (!StartDevicePoll()) |
1346 return; | 1346 return; |
1347 | 1347 |
1348 decoder_delay_bitstream_buffer_id_ = -1; | 1348 decoder_delay_bitstream_buffer_id_ = -1; |
1349 decoder_flushing_ = false; | 1349 decoder_flushing_ = false; |
1350 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; | 1350 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; |
1351 child_message_loop_proxy_->PostTask( | 1351 child_message_loop_proxy_->PostTask( |
1352 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); | 1352 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); |
1353 | 1353 |
1354 // While we were flushing, we early-outed DecodeBufferTask()s. | 1354 // While we were flushing, we early-outed DecodeBufferTask()s. |
1355 ScheduleDecodeBufferTaskIfNeeded(); | 1355 ScheduleDecodeBufferTaskIfNeeded(); |
1356 } | 1356 } |
1357 | 1357 |
1358 void ExynosVideoDecodeAccelerator::ResetTask() { | 1358 void V4L2VideoDecodeAccelerator::ResetTask() { |
1359 DVLOG(3) << "ResetTask()"; | 1359 DVLOG(3) << "ResetTask()"; |
1360 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1360 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1361 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); | 1361 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetTask"); |
1362 | 1362 |
1363 if (decoder_state_ == kError) { | 1363 if (decoder_state_ == kError) { |
1364 DVLOG(2) << "ResetTask(): early out: kError state"; | 1364 DVLOG(2) << "ResetTask(): early out: kError state"; |
1365 return; | 1365 return; |
1366 } | 1366 } |
1367 | 1367 |
1368 // If we are in the middle of switching resolutions, postpone reset until | 1368 // If we are in the middle of switching resolutions, postpone reset until |
1369 // it's done. We don't have to worry about timing of this wrt to decoding, | 1369 // it's done. We don't have to worry about timing of this wrt to decoding, |
1370 // because MFC input pipe is already stopped if we are changing resolution. | 1370 // because input pipe is already stopped if we are changing resolution. |
1371 // We will come back here after we are done with the resolution change. | 1371 // We will come back here after we are done with the resolution change. |
1372 DCHECK(!resolution_change_reset_pending_); | 1372 DCHECK(!resolution_change_reset_pending_); |
1373 if (resolution_change_pending_ || decoder_state_ == kChangingResolution) { | 1373 if (resolution_change_pending_ || decoder_state_ == kChangingResolution) { |
1374 resolution_change_reset_pending_ = true; | 1374 resolution_change_reset_pending_ = true; |
1375 return; | 1375 return; |
1376 } | 1376 } |
1377 | 1377 |
1378 // We stop streaming and clear buffer tracking info (not preserving | 1378 // We stop streaming and clear buffer tracking info (not preserving |
Pawel Osciak
2014/01/07 07:18:12
Wrap line please.
| |
1379 // MFC inputs). | 1379 // inputs). |
1380 // StopDevicePoll() unconditionally does _not_ destroy buffers, however. | 1380 // StopDevicePoll() unconditionally does _not_ destroy buffers, however. |
1381 if (!StopDevicePoll(false)) | 1381 if (!StopDevicePoll(false)) |
1382 return; | 1382 return; |
1383 | 1383 |
1384 decoder_current_bitstream_buffer_.reset(); | 1384 decoder_current_bitstream_buffer_.reset(); |
1385 while (!decoder_input_queue_.empty()) | 1385 while (!decoder_input_queue_.empty()) |
1386 decoder_input_queue_.pop(); | 1386 decoder_input_queue_.pop(); |
1387 | 1387 |
1388 decoder_current_input_buffer_ = -1; | 1388 decoder_current_input_buffer_ = -1; |
1389 | 1389 |
1390 // If we were flushing, we'll never return any more BitstreamBuffers or | 1390 // If we were flushing, we'll never return any more BitstreamBuffers or |
1391 // PictureBuffers; they have all been dropped and returned by now. | 1391 // PictureBuffers; they have all been dropped and returned by now. |
1392 NotifyFlushDoneIfNeeded(); | 1392 NotifyFlushDoneIfNeeded(); |
1393 | 1393 |
1394 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening | 1394 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening |
1395 // jobs will early-out in the kResetting state. | 1395 // jobs will early-out in the kResetting state. |
1396 decoder_state_ = kResetting; | 1396 decoder_state_ = kResetting; |
1397 SendPictureReady(); // Send all pending PictureReady. | 1397 SendPictureReady(); // Send all pending PictureReady. |
1398 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1398 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1399 &ExynosVideoDecodeAccelerator::ResetDoneTask, base::Unretained(this))); | 1399 &V4L2VideoDecodeAccelerator::ResetDoneTask, base::Unretained(this))); |
1400 } | 1400 } |
1401 | 1401 |
1402 void ExynosVideoDecodeAccelerator::ResetDoneTask() { | 1402 void V4L2VideoDecodeAccelerator::ResetDoneTask() { |
1403 DVLOG(3) << "ResetDoneTask()"; | 1403 DVLOG(3) << "ResetDoneTask()"; |
1404 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1404 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1405 TRACE_EVENT0("Video Decoder", "EVDA::ResetDoneTask"); | 1405 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetDoneTask"); |
1406 | 1406 |
1407 if (decoder_state_ == kError) { | 1407 if (decoder_state_ == kError) { |
1408 DVLOG(2) << "ResetDoneTask(): early out: kError state"; | 1408 DVLOG(2) << "ResetDoneTask(): early out: kError state"; |
1409 return; | 1409 return; |
1410 } | 1410 } |
1411 | 1411 |
1412 // We might have received a resolution change event while we were waiting | 1412 // We might have received a resolution change event while we were waiting |
1413 // for the reset to finish. The codec will not post another event if the | 1413 // for the reset to finish. The codec will not post another event if the |
1414 // resolution after reset remains the same as the one to which were just | 1414 // resolution after reset remains the same as the one to which were just |
1415 // about to switch, so preserve the event across reset so we can address | 1415 // about to switch, so preserve the event across reset so we can address |
(...skipping 10 matching lines...) Expand all Loading... | |
1426 decoder_state_ = kAfterReset; | 1426 decoder_state_ = kAfterReset; |
1427 decoder_partial_frame_pending_ = false; | 1427 decoder_partial_frame_pending_ = false; |
1428 decoder_delay_bitstream_buffer_id_ = -1; | 1428 decoder_delay_bitstream_buffer_id_ = -1; |
1429 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1429 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1430 &Client::NotifyResetDone, client_)); | 1430 &Client::NotifyResetDone, client_)); |
1431 | 1431 |
1432 // While we were resetting, we early-outed DecodeBufferTask()s. | 1432 // While we were resetting, we early-outed DecodeBufferTask()s. |
1433 ScheduleDecodeBufferTaskIfNeeded(); | 1433 ScheduleDecodeBufferTaskIfNeeded(); |
1434 } | 1434 } |
1435 | 1435 |
1436 void ExynosVideoDecodeAccelerator::DestroyTask() { | 1436 void V4L2VideoDecodeAccelerator::DestroyTask() { |
1437 DVLOG(3) << "DestroyTask()"; | 1437 DVLOG(3) << "DestroyTask()"; |
1438 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); | 1438 TRACE_EVENT0("Video Decoder", "V4L2VDA::DestroyTask"); |
1439 | 1439 |
1440 // DestroyTask() should run regardless of decoder_state_. | 1440 // DestroyTask() should run regardless of decoder_state_. |
1441 | 1441 |
1442 // Stop streaming and the device_poll_thread_. | 1442 // Stop streaming and the device_poll_thread_. |
1443 StopDevicePoll(false); | 1443 StopDevicePoll(false); |
1444 | 1444 |
1445 decoder_current_bitstream_buffer_.reset(); | 1445 decoder_current_bitstream_buffer_.reset(); |
1446 decoder_current_input_buffer_ = -1; | 1446 decoder_current_input_buffer_ = -1; |
1447 decoder_decode_buffer_tasks_scheduled_ = 0; | 1447 decoder_decode_buffer_tasks_scheduled_ = 0; |
1448 decoder_frames_at_client_ = 0; | 1448 decoder_frames_at_client_ = 0; |
1449 while (!decoder_input_queue_.empty()) | 1449 while (!decoder_input_queue_.empty()) |
1450 decoder_input_queue_.pop(); | 1450 decoder_input_queue_.pop(); |
1451 decoder_flushing_ = false; | 1451 decoder_flushing_ = false; |
1452 | 1452 |
1453 // Set our state to kError. Just in case. | 1453 // Set our state to kError. Just in case. |
1454 decoder_state_ = kError; | 1454 decoder_state_ = kError; |
1455 } | 1455 } |
1456 | 1456 |
1457 bool ExynosVideoDecodeAccelerator::StartDevicePoll() { | 1457 bool V4L2VideoDecodeAccelerator::StartDevicePoll() { |
1458 DVLOG(3) << "StartDevicePoll()"; | 1458 DVLOG(3) << "StartDevicePoll()"; |
1459 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1459 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1460 DCHECK(!device_poll_thread_.IsRunning()); | 1460 DCHECK(!device_poll_thread_.IsRunning()); |
1461 | 1461 |
1462 // Start up the device poll thread and schedule its first DevicePollTask(). | 1462 // Start up the device poll thread and schedule its first DevicePollTask(). |
1463 if (!device_poll_thread_.Start()) { | 1463 if (!device_poll_thread_.Start()) { |
1464 DLOG(ERROR) << "StartDevicePoll(): Device thread failed to start"; | 1464 DLOG(ERROR) << "StartDevicePoll(): Device thread failed to start"; |
1465 NOTIFY_ERROR(PLATFORM_FAILURE); | 1465 NOTIFY_ERROR(PLATFORM_FAILURE); |
1466 return false; | 1466 return false; |
1467 } | 1467 } |
1468 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1468 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1469 &ExynosVideoDecodeAccelerator::DevicePollTask, | 1469 &V4L2VideoDecodeAccelerator::DevicePollTask, |
1470 base::Unretained(this), | 1470 base::Unretained(this), |
1471 0)); | 1471 0)); |
1472 | 1472 |
1473 return true; | 1473 return true; |
1474 } | 1474 } |
1475 | 1475 |
1476 bool ExynosVideoDecodeAccelerator::StopDevicePoll(bool keep_mfc_input_state) { | 1476 bool V4L2VideoDecodeAccelerator::StopDevicePoll(bool keep_input_state) { |
1477 DVLOG(3) << "StopDevicePoll()"; | 1477 DVLOG(3) << "StopDevicePoll()"; |
1478 if (decoder_thread_.IsRunning()) | 1478 if (decoder_thread_.IsRunning()) |
1479 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1479 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1480 | 1480 |
1481 // Signal the DevicePollTask() to stop, and stop the device poll thread. | 1481 // Signal the DevicePollTask() to stop, and stop the device poll thread. |
1482 if (!SetDevicePollInterrupt()) | 1482 if (!SetDevicePollInterrupt()) |
1483 return false; | 1483 return false; |
1484 device_poll_thread_.Stop(); | 1484 device_poll_thread_.Stop(); |
1485 // Clear the interrupt now, to be sure. | 1485 // Clear the interrupt now, to be sure. |
1486 if (!ClearDevicePollInterrupt()) | 1486 if (!ClearDevicePollInterrupt()) |
1487 return false; | 1487 return false; |
1488 | 1488 |
1489 // Stop streaming. | 1489 // Stop streaming. |
1490 if (!keep_mfc_input_state) { | 1490 if (!keep_input_state) { |
1491 if (mfc_input_streamon_) { | 1491 if (input_streamon_) { |
1492 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1492 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1493 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); | 1493 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_STREAMOFF, &type); |
1494 } | 1494 } |
1495 mfc_input_streamon_ = false; | 1495 input_streamon_ = false; |
1496 } | 1496 } |
1497 if (mfc_output_streamon_) { | 1497 if (output_streamon_) { |
1498 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1498 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1499 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); | 1499 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_STREAMOFF, &type); |
1500 } | 1500 } |
1501 mfc_output_streamon_ = false; | 1501 output_streamon_ = false; |
1502 | 1502 |
1503 // Reset all our accounting info. | 1503 // Reset all our accounting info. |
1504 if (!keep_mfc_input_state) { | 1504 if (!keep_input_state) { |
1505 while (!mfc_input_ready_queue_.empty()) | 1505 while (!input_ready_queue_.empty()) |
1506 mfc_input_ready_queue_.pop(); | 1506 input_ready_queue_.pop(); |
1507 mfc_free_input_buffers_.clear(); | 1507 free_input_buffers_.clear(); |
1508 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { | 1508 for (size_t i = 0; i < input_buffer_map_.size(); ++i) { |
1509 mfc_free_input_buffers_.push_back(i); | 1509 free_input_buffers_.push_back(i); |
1510 mfc_input_buffer_map_[i].at_device = false; | 1510 input_buffer_map_[i].at_device = false; |
1511 mfc_input_buffer_map_[i].bytes_used = 0; | 1511 input_buffer_map_[i].bytes_used = 0; |
1512 mfc_input_buffer_map_[i].input_id = -1; | 1512 input_buffer_map_[i].input_id = -1; |
1513 } | 1513 } |
1514 mfc_input_buffer_queued_count_ = 0; | 1514 input_buffer_queued_count_ = 0; |
1515 } | 1515 } |
1516 while (!mfc_free_output_buffers_.empty()) | 1516 while (!free_output_buffers_.empty()) |
1517 mfc_free_output_buffers_.pop(); | 1517 free_output_buffers_.pop(); |
1518 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { | 1518 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { |
1519 MfcOutputRecord& output_record = mfc_output_buffer_map_[i]; | 1519 OutputRecord& output_record = output_buffer_map_[i]; |
1520 // Only mark those free that aren't being held by the VDA client. | 1520 // Only mark those free that aren't being held by the VDA client. |
1521 if (!output_record.at_client) { | 1521 if (!output_record.at_client) { |
1522 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); | 1522 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); |
1523 mfc_free_output_buffers_.push(i); | 1523 free_output_buffers_.push(i); |
1524 mfc_output_buffer_map_[i].at_device = false; | 1524 output_buffer_map_[i].at_device = false; |
1525 } | 1525 } |
1526 } | 1526 } |
1527 mfc_output_buffer_queued_count_ = 0; | 1527 output_buffer_queued_count_ = 0; |
1528 | 1528 |
1529 DVLOG(3) << "StopDevicePoll(): device poll stopped"; | 1529 DVLOG(3) << "StopDevicePoll(): device poll stopped"; |
1530 return true; | 1530 return true; |
1531 } | 1531 } |
1532 | 1532 |
1533 bool ExynosVideoDecodeAccelerator::SetDevicePollInterrupt() { | 1533 bool V4L2VideoDecodeAccelerator::SetDevicePollInterrupt() { |
1534 DVLOG(3) << "SetDevicePollInterrupt()"; | 1534 DVLOG(3) << "SetDevicePollInterrupt()"; |
1535 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1535 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1536 | 1536 |
1537 const uint64 buf = 1; | 1537 const uint64 buf = 1; |
1538 if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 1538 if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { |
1539 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; | 1539 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; |
1540 NOTIFY_ERROR(PLATFORM_FAILURE); | 1540 NOTIFY_ERROR(PLATFORM_FAILURE); |
1541 return false; | 1541 return false; |
1542 } | 1542 } |
1543 return true; | 1543 return true; |
1544 } | 1544 } |
1545 | 1545 |
1546 bool ExynosVideoDecodeAccelerator::ClearDevicePollInterrupt() { | 1546 bool V4L2VideoDecodeAccelerator::ClearDevicePollInterrupt() { |
1547 DVLOG(3) << "ClearDevicePollInterrupt()"; | 1547 DVLOG(3) << "ClearDevicePollInterrupt()"; |
1548 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1548 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1549 | 1549 |
1550 uint64 buf; | 1550 uint64 buf; |
1551 if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 1551 if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { |
1552 if (errno == EAGAIN) { | 1552 if (errno == EAGAIN) { |
1553 // No interrupt flag set, and we're reading nonblocking. Not an error. | 1553 // No interrupt flag set, and we're reading nonblocking. Not an error. |
1554 return true; | 1554 return true; |
1555 } else { | 1555 } else { |
1556 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; | 1556 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; |
1557 NOTIFY_ERROR(PLATFORM_FAILURE); | 1557 NOTIFY_ERROR(PLATFORM_FAILURE); |
1558 return false; | 1558 return false; |
1559 } | 1559 } |
1560 } | 1560 } |
1561 return true; | 1561 return true; |
1562 } | 1562 } |
1563 | 1563 |
1564 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() { | 1564 void V4L2VideoDecodeAccelerator::StartResolutionChangeIfNeeded() { |
1565 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1565 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1566 DCHECK_EQ(decoder_state_, kDecoding); | 1566 DCHECK_EQ(decoder_state_, kDecoding); |
1567 | 1567 |
1568 if (!resolution_change_pending_) | 1568 if (!resolution_change_pending_) |
1569 return; | 1569 return; |
1570 | 1570 |
1571 DVLOG(3) << "No more work, initiate resolution change"; | 1571 DVLOG(3) << "No more work, initiate resolution change"; |
1572 | 1572 |
1573 // Keep MFC input queue. | 1573 // Keep input queue. |
1574 if (!StopDevicePoll(true)) | 1574 if (!StopDevicePoll(true)) |
1575 return; | 1575 return; |
1576 | 1576 |
1577 decoder_state_ = kChangingResolution; | 1577 decoder_state_ = kChangingResolution; |
1578 DCHECK(resolution_change_pending_); | 1578 DCHECK(resolution_change_pending_); |
1579 resolution_change_pending_ = false; | 1579 resolution_change_pending_ = false; |
1580 | 1580 |
1581 // Post a task to clean up buffers on child thread. This will also ensure | 1581 // Post a task to clean up buffers on child thread. This will also ensure |
1582 // that we won't accept ReusePictureBuffer() anymore after that. | 1582 // that we won't accept ReusePictureBuffer() anymore after that. |
1583 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1583 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1584 &ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers, | 1584 &V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers, |
1585 weak_this_)); | 1585 weak_this_)); |
1586 } | 1586 } |
1587 | 1587 |
1588 void ExynosVideoDecodeAccelerator::FinishResolutionChange() { | 1588 void V4L2VideoDecodeAccelerator::FinishResolutionChange() { |
1589 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1589 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1590 DVLOG(3) << "FinishResolutionChange()"; | 1590 DVLOG(3) << "FinishResolutionChange()"; |
1591 | 1591 |
1592 if (decoder_state_ == kError) { | 1592 if (decoder_state_ == kError) { |
1593 DVLOG(2) << "FinishResolutionChange(): early out: kError state"; | 1593 DVLOG(2) << "FinishResolutionChange(): early out: kError state"; |
1594 return; | 1594 return; |
1595 } | 1595 } |
1596 | 1596 |
1597 struct v4l2_format format; | 1597 struct v4l2_format format; |
1598 bool again; | 1598 bool again; |
1599 bool ret = GetFormatInfo(&format, &again); | 1599 bool ret = GetFormatInfo(&format, &again); |
1600 if (!ret || again) { | 1600 if (!ret || again) { |
1601 DVLOG(3) << "Couldn't get format information after resolution change"; | 1601 DVLOG(3) << "Couldn't get format information after resolution change"; |
1602 NOTIFY_ERROR(PLATFORM_FAILURE); | 1602 NOTIFY_ERROR(PLATFORM_FAILURE); |
1603 return; | 1603 return; |
1604 } | 1604 } |
1605 | 1605 |
1606 if (!CreateBuffersForFormat(format)) { | 1606 if (!CreateBuffersForFormat(format)) { |
1607 DVLOG(3) << "Couldn't reallocate buffers after resolution change"; | 1607 DVLOG(3) << "Couldn't reallocate buffers after resolution change"; |
1608 NOTIFY_ERROR(PLATFORM_FAILURE); | 1608 NOTIFY_ERROR(PLATFORM_FAILURE); |
1609 return; | 1609 return; |
1610 } | 1610 } |
1611 | 1611 |
1612 // From here we stay in kChangingResolution and wait for | 1612 // From here we stay in kChangingResolution and wait for |
1613 // AssignPictureBuffers() before we can resume. | 1613 // AssignPictureBuffers() before we can resume. |
1614 } | 1614 } |
1615 | 1615 |
1616 void ExynosVideoDecodeAccelerator::ResumeAfterResolutionChange() { | 1616 void V4L2VideoDecodeAccelerator::ResumeAfterResolutionChange() { |
1617 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1617 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1618 DVLOG(3) << "ResumeAfterResolutionChange()"; | 1618 DVLOG(3) << "ResumeAfterResolutionChange()"; |
1619 | 1619 |
1620 decoder_state_ = kDecoding; | 1620 decoder_state_ = kDecoding; |
1621 | 1621 |
1622 if (resolution_change_reset_pending_) { | 1622 if (resolution_change_reset_pending_) { |
1623 resolution_change_reset_pending_ = false; | 1623 resolution_change_reset_pending_ = false; |
1624 ResetTask(); | 1624 ResetTask(); |
1625 return; | 1625 return; |
1626 } | 1626 } |
1627 | 1627 |
1628 if (!StartDevicePoll()) | 1628 if (!StartDevicePoll()) |
1629 return; | 1629 return; |
1630 | 1630 |
1631 EnqueueMfc(); | 1631 Enqueue(); |
1632 ScheduleDecodeBufferTaskIfNeeded(); | 1632 ScheduleDecodeBufferTaskIfNeeded(); |
1633 } | 1633 } |
1634 | 1634 |
1635 void ExynosVideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) { | 1635 void V4L2VideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) { |
1636 DVLOG(3) << "DevicePollTask()"; | 1636 DVLOG(3) << "DevicePollTask()"; |
1637 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); | 1637 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); |
1638 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); | 1638 TRACE_EVENT0("Video Decoder", "V4L2VDA::DevicePollTask"); |
1639 | 1639 |
1640 // This routine just polls the set of device fds, and schedules a | 1640 // This routine just polls the set of device fds, and schedules a |
1641 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. | 1641 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. |
1642 // Other threads may notify this task to return early by writing to | 1642 // Other threads may notify this task to return early by writing to |
1643 // device_poll_interrupt_fd_. | 1643 // device_poll_interrupt_fd_. |
1644 struct pollfd pollfds[3]; | 1644 struct pollfd pollfds[3]; |
1645 nfds_t nfds; | 1645 nfds_t nfds; |
1646 int mfc_pollfd = -1; | 1646 int pollfd = -1; |
1647 | 1647 |
1648 // Add device_poll_interrupt_fd_; | 1648 // Add device_poll_interrupt_fd_; |
1649 pollfds[0].fd = device_poll_interrupt_fd_; | 1649 pollfds[0].fd = device_poll_interrupt_fd_; |
1650 pollfds[0].events = POLLIN | POLLERR; | 1650 pollfds[0].events = POLLIN | POLLERR; |
1651 nfds = 1; | 1651 nfds = 1; |
1652 | 1652 |
1653 if (poll_fds & kPollMfc) { | 1653 if (poll_fds & kPoll) { |
1654 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set"; | 1654 DVLOG(3) << "DevicePollTask(): adding device fd to poll() set"; |
1655 pollfds[nfds].fd = mfc_fd_; | 1655 pollfds[nfds].fd = fd_; |
1656 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI; | 1656 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI; |
1657 mfc_pollfd = nfds; | 1657 pollfd = nfds; |
1658 nfds++; | 1658 nfds++; |
1659 } | 1659 } |
1660 | 1660 |
1661 // Poll it! | 1661 // Poll it! |
1662 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { | 1662 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { |
1663 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; | 1663 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; |
1664 NOTIFY_ERROR(PLATFORM_FAILURE); | 1664 NOTIFY_ERROR(PLATFORM_FAILURE); |
1665 return; | 1665 return; |
1666 } | 1666 } |
1667 | 1667 |
1668 bool mfc_event_pending = (mfc_pollfd != -1 && | 1668 bool event_pending = (pollfd != -1 && |
Pawel Osciak
2014/01/07 07:18:12
Line wrap please.
| |
1669 pollfds[mfc_pollfd].revents & POLLPRI); | 1669 pollfds[pollfd].revents & POLLPRI); |
1670 | 1670 |
1671 // All processing should happen on ServiceDeviceTask(), since we shouldn't | 1671 // All processing should happen on ServiceDeviceTask(), since we shouldn't |
1672 // touch decoder state from this thread. | 1672 // touch decoder state from this thread. |
1673 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1673 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1674 &ExynosVideoDecodeAccelerator::ServiceDeviceTask, | 1674 &V4L2VideoDecodeAccelerator::ServiceDeviceTask, |
1675 base::Unretained(this), mfc_event_pending)); | 1675 base::Unretained(this), event_pending)); |
1676 } | 1676 } |
1677 | 1677 |
1678 void ExynosVideoDecodeAccelerator::NotifyError(Error error) { | 1678 void V4L2VideoDecodeAccelerator::NotifyError(Error error) { |
1679 DVLOG(2) << "NotifyError()"; | 1679 DVLOG(2) << "NotifyError()"; |
1680 | 1680 |
1681 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { | 1681 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { |
1682 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1682 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1683 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error)); | 1683 &V4L2VideoDecodeAccelerator::NotifyError, weak_this_, error)); |
1684 return; | 1684 return; |
1685 } | 1685 } |
1686 | 1686 |
1687 if (client_) { | 1687 if (client_) { |
1688 client_->NotifyError(error); | 1688 client_->NotifyError(error); |
1689 client_ptr_factory_.InvalidateWeakPtrs(); | 1689 client_ptr_factory_.InvalidateWeakPtrs(); |
1690 } | 1690 } |
1691 } | 1691 } |
1692 | 1692 |
1693 void ExynosVideoDecodeAccelerator::SetDecoderState(State state) { | 1693 void V4L2VideoDecodeAccelerator::SetDecoderState(State state) { |
1694 DVLOG(3) << "SetDecoderState(): state=" << state; | 1694 DVLOG(3) << "SetDecoderState(): state=" << state; |
1695 | 1695 |
1696 // We can touch decoder_state_ only if this is the decoder thread or the | 1696 // We can touch decoder_state_ only if this is the decoder thread or the |
1697 // decoder thread isn't running. | 1697 // decoder thread isn't running. |
1698 if (decoder_thread_.message_loop() != NULL && | 1698 if (decoder_thread_.message_loop() != NULL && |
1699 decoder_thread_.message_loop() != base::MessageLoop::current()) { | 1699 decoder_thread_.message_loop() != base::MessageLoop::current()) { |
1700 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1700 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1701 &ExynosVideoDecodeAccelerator::SetDecoderState, | 1701 &V4L2VideoDecodeAccelerator::SetDecoderState, |
1702 base::Unretained(this), state)); | 1702 base::Unretained(this), state)); |
1703 } else { | 1703 } else { |
1704 decoder_state_ = state; | 1704 decoder_state_ = state; |
1705 } | 1705 } |
1706 } | 1706 } |
1707 | 1707 |
1708 bool ExynosVideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, | 1708 bool V4L2VideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, |
1709 bool* again) { | 1709 bool* again) { |
1710 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1710 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1711 | 1711 |
1712 *again = false; | 1712 *again = false; |
1713 memset(format, 0, sizeof(*format)); | 1713 memset(format, 0, sizeof(*format)); |
1714 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1714 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1715 if (HANDLE_EINTR(ioctl(mfc_fd_, VIDIOC_G_FMT, format)) != 0) { | 1715 if (HANDLE_EINTR(ioctl(fd_, VIDIOC_G_FMT, format)) != 0) { |
1716 if (errno == EINVAL) { | 1716 if (errno == EINVAL) { |
1717 // EINVAL means we haven't seen sufficient stream to decode the format. | 1717 // EINVAL means we haven't seen sufficient stream to decode the format. |
1718 *again = true; | 1718 *again = true; |
1719 return true; | 1719 return true; |
1720 } else { | 1720 } else { |
1721 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; | 1721 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; |
1722 NOTIFY_ERROR(PLATFORM_FAILURE); | 1722 NOTIFY_ERROR(PLATFORM_FAILURE); |
1723 return false; | 1723 return false; |
1724 } | 1724 } |
1725 } | 1725 } |
1726 | 1726 |
1727 return true; | 1727 return true; |
1728 } | 1728 } |
1729 | 1729 |
1730 bool ExynosVideoDecodeAccelerator::CreateBuffersForFormat( | 1730 bool V4L2VideoDecodeAccelerator::CreateBuffersForFormat( |
1731 const struct v4l2_format& format) { | 1731 const struct v4l2_format& format) { |
1732 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1732 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1733 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); | 1733 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); |
1734 frame_buffer_size_.SetSize( | 1734 frame_buffer_size_.SetSize( |
1735 format.fmt.pix_mp.width, format.fmt.pix_mp.height); | 1735 format.fmt.pix_mp.width, format.fmt.pix_mp.height); |
1736 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; | 1736 output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; |
1737 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12M); | 1737 DCHECK_EQ(output_buffer_pixelformat_, V4L2_PIX_FMT_NV12M); |
1738 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " | 1738 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " |
1739 << frame_buffer_size_.ToString(); | 1739 << frame_buffer_size_.ToString(); |
1740 | 1740 |
1741 if (!CreateMfcOutputBuffers()) | 1741 if (!CreateOutputBuffers()) |
1742 return false; | 1742 return false; |
1743 | 1743 |
1744 return true; | 1744 return true; |
1745 } | 1745 } |
1746 | 1746 |
1747 bool ExynosVideoDecodeAccelerator::CreateMfcInputBuffers() { | 1747 bool V4L2VideoDecodeAccelerator::CreateInputBuffers() { |
1748 DVLOG(3) << "CreateMfcInputBuffers()"; | 1748 DVLOG(3) << "CreateInputBuffers()"; |
1749 // We always run this as we prepare to initialize. | 1749 // We always run this as we prepare to initialize. |
1750 DCHECK_EQ(decoder_state_, kUninitialized); | 1750 DCHECK_EQ(decoder_state_, kUninitialized); |
1751 DCHECK(!mfc_input_streamon_); | 1751 DCHECK(!input_streamon_); |
1752 DCHECK(mfc_input_buffer_map_.empty()); | 1752 DCHECK(input_buffer_map_.empty()); |
1753 | 1753 |
1754 __u32 pixelformat = 0; | 1754 __u32 pixelformat = 0; |
1755 if (video_profile_ >= media::H264PROFILE_MIN && | 1755 if (video_profile_ >= media::H264PROFILE_MIN && |
1756 video_profile_ <= media::H264PROFILE_MAX) { | 1756 video_profile_ <= media::H264PROFILE_MAX) { |
1757 pixelformat = V4L2_PIX_FMT_H264; | 1757 pixelformat = V4L2_PIX_FMT_H264; |
1758 } else if (video_profile_ >= media::VP8PROFILE_MIN && | 1758 } else if (video_profile_ >= media::VP8PROFILE_MIN && |
1759 video_profile_ <= media::VP8PROFILE_MAX) { | 1759 video_profile_ <= media::VP8PROFILE_MAX) { |
1760 pixelformat = V4L2_PIX_FMT_VP8; | 1760 pixelformat = V4L2_PIX_FMT_VP8; |
1761 } else { | 1761 } else { |
1762 NOTREACHED(); | 1762 NOTREACHED(); |
1763 } | 1763 } |
1764 | 1764 |
1765 struct v4l2_format format; | 1765 struct v4l2_format format; |
1766 memset(&format, 0, sizeof(format)); | 1766 memset(&format, 0, sizeof(format)); |
1767 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1767 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1768 format.fmt.pix_mp.pixelformat = pixelformat; | 1768 format.fmt.pix_mp.pixelformat = pixelformat; |
1769 format.fmt.pix_mp.plane_fmt[0].sizeimage = kMfcInputBufferMaxSize; | 1769 format.fmt.pix_mp.plane_fmt[0].sizeimage = kInputBufferMaxSize; |
1770 format.fmt.pix_mp.num_planes = 1; | 1770 format.fmt.pix_mp.num_planes = 1; |
1771 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format); | 1771 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_S_FMT, &format); |
1772 | 1772 |
1773 struct v4l2_requestbuffers reqbufs; | 1773 struct v4l2_requestbuffers reqbufs; |
1774 memset(&reqbufs, 0, sizeof(reqbufs)); | 1774 memset(&reqbufs, 0, sizeof(reqbufs)); |
1775 reqbufs.count = kMfcInputBufferCount; | 1775 reqbufs.count = kInputBufferCount; |
1776 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1776 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1777 reqbufs.memory = V4L2_MEMORY_MMAP; | 1777 reqbufs.memory = V4L2_MEMORY_MMAP; |
1778 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_REQBUFS, &reqbufs); | 1778 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_REQBUFS, &reqbufs); |
1779 mfc_input_buffer_map_.resize(reqbufs.count); | 1779 input_buffer_map_.resize(reqbufs.count); |
1780 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { | 1780 for (size_t i = 0; i < input_buffer_map_.size(); ++i) { |
1781 mfc_free_input_buffers_.push_back(i); | 1781 free_input_buffers_.push_back(i); |
1782 | 1782 |
1783 // Query for the MEMORY_MMAP pointer. | 1783 // Query for the MEMORY_MMAP pointer. |
1784 struct v4l2_plane planes[1]; | 1784 struct v4l2_plane planes[1]; |
1785 struct v4l2_buffer buffer; | 1785 struct v4l2_buffer buffer; |
1786 memset(&buffer, 0, sizeof(buffer)); | 1786 memset(&buffer, 0, sizeof(buffer)); |
1787 memset(planes, 0, sizeof(planes)); | 1787 memset(planes, 0, sizeof(planes)); |
1788 buffer.index = i; | 1788 buffer.index = i; |
1789 buffer.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1789 buffer.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1790 buffer.memory = V4L2_MEMORY_MMAP; | 1790 buffer.memory = V4L2_MEMORY_MMAP; |
1791 buffer.m.planes = planes; | 1791 buffer.m.planes = planes; |
1792 buffer.length = 1; | 1792 buffer.length = 1; |
1793 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QUERYBUF, &buffer); | 1793 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_QUERYBUF, &buffer); |
1794 void* address = mmap(NULL, buffer.m.planes[0].length, | 1794 void* address = mmap(NULL, buffer.m.planes[0].length, |
1795 PROT_READ | PROT_WRITE, MAP_SHARED, mfc_fd_, | 1795 PROT_READ | PROT_WRITE, MAP_SHARED, fd_, |
1796 buffer.m.planes[0].m.mem_offset); | 1796 buffer.m.planes[0].m.mem_offset); |
1797 if (address == MAP_FAILED) { | 1797 if (address == MAP_FAILED) { |
1798 DPLOG(ERROR) << "CreateMfcInputBuffers(): mmap() failed"; | 1798 DPLOG(ERROR) << "CreateInputBuffers(): mmap() failed"; |
1799 return false; | 1799 return false; |
1800 } | 1800 } |
1801 mfc_input_buffer_map_[i].address = address; | 1801 input_buffer_map_[i].address = address; |
1802 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; | 1802 input_buffer_map_[i].length = buffer.m.planes[0].length; |
1803 } | 1803 } |
1804 | 1804 |
1805 return true; | 1805 return true; |
1806 } | 1806 } |
1807 | 1807 |
1808 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() { | 1808 bool V4L2VideoDecodeAccelerator::CreateOutputBuffers() { |
1809 DVLOG(3) << "CreateMfcOutputBuffers()"; | 1809 DVLOG(3) << "CreateOutputBuffers()"; |
1810 DCHECK(decoder_state_ == kInitialized || | 1810 DCHECK(decoder_state_ == kInitialized || |
1811 decoder_state_ == kChangingResolution); | 1811 decoder_state_ == kChangingResolution); |
1812 DCHECK(!mfc_output_streamon_); | 1812 DCHECK(!output_streamon_); |
1813 DCHECK(mfc_output_buffer_map_.empty()); | 1813 DCHECK(output_buffer_map_.empty()); |
1814 | 1814 |
1815 // Number of MFC output buffers we need. | 1815 // Number of output buffers we need. |
1816 struct v4l2_control ctrl; | 1816 struct v4l2_control ctrl; |
1817 memset(&ctrl, 0, sizeof(ctrl)); | 1817 memset(&ctrl, 0, sizeof(ctrl)); |
1818 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; | 1818 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; |
1819 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_G_CTRL, &ctrl); | 1819 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_G_CTRL, &ctrl); |
1820 mfc_output_dpb_size_ = ctrl.value; | 1820 output_dpb_size_ = ctrl.value; |
1821 | 1821 |
1822 // Output format setup in Initialize(). | 1822 // Output format setup in Initialize(). |
1823 | 1823 |
1824 // Allocate the output buffers. | 1824 // Allocate the output buffers. |
1825 struct v4l2_requestbuffers reqbufs; | 1825 struct v4l2_requestbuffers reqbufs; |
1826 memset(&reqbufs, 0, sizeof(reqbufs)); | 1826 memset(&reqbufs, 0, sizeof(reqbufs)); |
1827 reqbufs.count = mfc_output_dpb_size_ + kDpbOutputBufferExtraCount; | 1827 reqbufs.count = output_dpb_size_ + kDpbOutputBufferExtraCount; |
1828 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1828 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1829 reqbufs.memory = V4L2_MEMORY_MMAP; | 1829 reqbufs.memory = V4L2_MEMORY_MMAP; |
1830 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_REQBUFS, &reqbufs); | 1830 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_REQBUFS, &reqbufs); |
1831 | 1831 |
1832 // Create DMABUFs from output buffers. | 1832 // Create DMABUFs from output buffers. |
1833 mfc_output_buffer_map_.resize(reqbufs.count); | 1833 output_buffer_map_.resize(reqbufs.count); |
1834 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { | 1834 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { |
1835 MfcOutputRecord& output_record = mfc_output_buffer_map_[i]; | 1835 OutputRecord& output_record = output_buffer_map_[i]; |
1836 for (size_t j = 0; j < arraysize(output_record.fds); ++j) { | 1836 for (size_t j = 0; j < arraysize(output_record.fds); ++j) { |
1837 // Export the DMABUF fd so we can export it as a texture. | 1837 // Export the DMABUF fd so we can export it as a texture. |
1838 struct v4l2_exportbuffer expbuf; | 1838 struct v4l2_exportbuffer expbuf; |
1839 memset(&expbuf, 0, sizeof(expbuf)); | 1839 memset(&expbuf, 0, sizeof(expbuf)); |
1840 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1840 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1841 expbuf.index = i; | 1841 expbuf.index = i; |
1842 expbuf.plane = j; | 1842 expbuf.plane = j; |
1843 expbuf.flags = O_CLOEXEC; | 1843 expbuf.flags = O_CLOEXEC; |
1844 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_EXPBUF, &expbuf); | 1844 IOCTL_OR_ERROR_RETURN_FALSE(fd_, VIDIOC_EXPBUF, &expbuf); |
1845 output_record.fds[j] = expbuf.fd; | 1845 output_record.fds[j] = expbuf.fd; |
1846 } | 1846 } |
1847 } | 1847 } |
1848 | 1848 |
1849 DVLOG(3) << "CreateMfcOutputBuffers(): ProvidePictureBuffers(): " | 1849 DVLOG(3) << "CreateOutputBuffers(): ProvidePictureBuffers(): " |
1850 << "buffer_count=" << mfc_output_buffer_map_.size() | 1850 << "buffer_count=" << output_buffer_map_.size() |
1851 << ", width=" << frame_buffer_size_.width() | 1851 << ", width=" << frame_buffer_size_.width() |
1852 << ", height=" << frame_buffer_size_.height(); | 1852 << ", height=" << frame_buffer_size_.height(); |
1853 child_message_loop_proxy_->PostTask(FROM_HERE, | 1853 child_message_loop_proxy_->PostTask(FROM_HERE, |
1854 base::Bind(&Client::ProvidePictureBuffers, | 1854 base::Bind(&Client::ProvidePictureBuffers, |
1855 client_, | 1855 client_, |
1856 mfc_output_buffer_map_.size(), | 1856 output_buffer_map_.size(), |
1857 frame_buffer_size_, | 1857 frame_buffer_size_, |
1858 GL_TEXTURE_EXTERNAL_OES)); | 1858 GL_TEXTURE_EXTERNAL_OES)); |
1859 | 1859 |
1860 return true; | 1860 return true; |
1861 } | 1861 } |
1862 | 1862 |
1863 void ExynosVideoDecodeAccelerator::DestroyMfcInputBuffers() { | 1863 void V4L2VideoDecodeAccelerator::DestroyInputBuffers() { |
1864 DVLOG(3) << "DestroyMfcInputBuffers()"; | 1864 DVLOG(3) << "DestroyInputBuffers()"; |
1865 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1865 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1866 DCHECK(!mfc_input_streamon_); | 1866 DCHECK(!input_streamon_); |
1867 | 1867 |
1868 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { | 1868 for (size_t i = 0; i < input_buffer_map_.size(); ++i) { |
1869 if (mfc_input_buffer_map_[i].address != NULL) { | 1869 if (input_buffer_map_[i].address != NULL) { |
1870 munmap(mfc_input_buffer_map_[i].address, | 1870 munmap(input_buffer_map_[i].address, |
1871 mfc_input_buffer_map_[i].length); | 1871 input_buffer_map_[i].length); |
1872 } | 1872 } |
1873 } | 1873 } |
1874 | 1874 |
1875 struct v4l2_requestbuffers reqbufs; | 1875 struct v4l2_requestbuffers reqbufs; |
1876 memset(&reqbufs, 0, sizeof(reqbufs)); | 1876 memset(&reqbufs, 0, sizeof(reqbufs)); |
1877 reqbufs.count = 0; | 1877 reqbufs.count = 0; |
1878 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1878 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1879 reqbufs.memory = V4L2_MEMORY_MMAP; | 1879 reqbufs.memory = V4L2_MEMORY_MMAP; |
1880 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) | 1880 if (ioctl(fd_, VIDIOC_REQBUFS, &reqbufs) != 0) |
1881 DPLOG(ERROR) << "DestroyMfcInputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; | 1881 DPLOG(ERROR) << "DestroyInputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; |
1882 | 1882 |
1883 mfc_input_buffer_map_.clear(); | 1883 input_buffer_map_.clear(); |
1884 mfc_free_input_buffers_.clear(); | 1884 free_input_buffers_.clear(); |
1885 } | 1885 } |
1886 | 1886 |
1887 void ExynosVideoDecodeAccelerator::DestroyMfcOutputBuffers() { | 1887 void V4L2VideoDecodeAccelerator::DestroyOutputBuffers() { |
1888 DVLOG(3) << "DestroyMfcOutputBuffers()"; | 1888 DVLOG(3) << "DestroyOutputBuffers()"; |
1889 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1889 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1890 DCHECK(!mfc_output_streamon_); | 1890 DCHECK(!output_streamon_); |
1891 | 1891 |
1892 if (mfc_output_buffer_map_.size() != 0) { | 1892 if (output_buffer_map_.size() != 0) { |
1893 // TODO(sheu, posciak): Making the context current should not be required | 1893 // TODO(sheu, posciak): Making the context current should not be required |
1894 // anymore. Remove it and verify (crbug.com/327869). | 1894 // anymore. Remove it and verify (crbug.com/327869). |
1895 if (!make_context_current_.Run()) { | 1895 if (!make_context_current_.Run()) { |
1896 DLOG(ERROR) << "DestroyMfcOutputBuffers(): " | 1896 DLOG(ERROR) << "DestroyOutputBuffers(): " |
1897 << "could not make context current"; | 1897 << "could not make context current"; |
1898 } else { | 1898 } else { |
1899 size_t i = 0; | 1899 size_t i = 0; |
1900 do { | 1900 do { |
1901 MfcOutputRecord& output_record = mfc_output_buffer_map_[i]; | 1901 OutputRecord& output_record = output_buffer_map_[i]; |
1902 for (size_t j = 0; j < arraysize(output_record.fds); ++j) { | 1902 for (size_t j = 0; j < arraysize(output_record.fds); ++j) { |
1903 if (output_record.fds[j] != -1) | 1903 if (output_record.fds[j] != -1) |
1904 close(output_record.fds[j]); | 1904 close(output_record.fds[j]); |
1905 if (output_record.egl_image != EGL_NO_IMAGE_KHR) | 1905 if (output_record.egl_image != EGL_NO_IMAGE_KHR) |
1906 eglDestroyImageKHR(egl_display_, output_record.egl_image); | 1906 eglDestroyImageKHR(egl_display_, output_record.egl_image); |
1907 if (output_record.egl_sync != EGL_NO_SYNC_KHR) | 1907 if (output_record.egl_sync != EGL_NO_SYNC_KHR) |
1908 eglDestroySyncKHR(egl_display_, output_record.egl_sync); | 1908 eglDestroySyncKHR(egl_display_, output_record.egl_sync); |
1909 } | 1909 } |
1910 DVLOG(1) << "DestroyMfcOutputBuffers(): dismissing PictureBuffer id=" | 1910 DVLOG(1) << "DestroyOutputBuffers(): dismissing PictureBuffer id=" |
1911 << output_record.picture_id; | 1911 << output_record.picture_id; |
1912 child_message_loop_proxy_->PostTask( | 1912 child_message_loop_proxy_->PostTask( |
1913 FROM_HERE, | 1913 FROM_HERE, |
1914 base::Bind(&Client::DismissPictureBuffer, | 1914 base::Bind(&Client::DismissPictureBuffer, |
1915 client_, | 1915 client_, |
1916 output_record.picture_id)); | 1916 output_record.picture_id)); |
1917 i++; | 1917 i++; |
1918 } while (i < mfc_output_buffer_map_.size()); | 1918 } while (i < output_buffer_map_.size()); |
1919 } | 1919 } |
1920 } | 1920 } |
1921 | 1921 |
1922 struct v4l2_requestbuffers reqbufs; | 1922 struct v4l2_requestbuffers reqbufs; |
1923 memset(&reqbufs, 0, sizeof(reqbufs)); | 1923 memset(&reqbufs, 0, sizeof(reqbufs)); |
1924 reqbufs.count = 0; | 1924 reqbufs.count = 0; |
1925 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1925 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1926 reqbufs.memory = V4L2_MEMORY_MMAP; | 1926 reqbufs.memory = V4L2_MEMORY_MMAP; |
1927 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) | 1927 if (ioctl(fd_, VIDIOC_REQBUFS, &reqbufs) != 0) |
1928 DPLOG(ERROR) << "DestroyMfcOutputBuffers() ioctl() failed: VIDIOC_REQBUFS"; | 1928 DPLOG(ERROR) << "DestroyOutputBuffers() ioctl() failed: VIDIOC_REQBUFS"; |
1929 | 1929 |
1930 mfc_output_buffer_map_.clear(); | 1930 output_buffer_map_.clear(); |
1931 while (!mfc_free_output_buffers_.empty()) | 1931 while (!free_output_buffers_.empty()) |
1932 mfc_free_output_buffers_.pop(); | 1932 free_output_buffers_.pop(); |
1933 } | 1933 } |
1934 | 1934 |
1935 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { | 1935 void V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { |
1936 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1936 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1937 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; | 1937 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; |
1938 | 1938 |
1939 DestroyMfcOutputBuffers(); | 1939 DestroyOutputBuffers(); |
1940 | 1940 |
1941 // Finish resolution change on decoder thread. | 1941 // Finish resolution change on decoder thread. |
1942 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1942 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1943 &ExynosVideoDecodeAccelerator::FinishResolutionChange, | 1943 &V4L2VideoDecodeAccelerator::FinishResolutionChange, |
1944 base::Unretained(this))); | 1944 base::Unretained(this))); |
1945 } | 1945 } |
1946 | 1946 |
1947 void ExynosVideoDecodeAccelerator::SendPictureReady() { | 1947 void V4L2VideoDecodeAccelerator::SendPictureReady() { |
1948 DVLOG(3) << "SendPictureReady()"; | 1948 DVLOG(3) << "SendPictureReady()"; |
1949 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1949 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1950 bool resetting_or_flushing = | 1950 bool resetting_or_flushing = |
1951 (decoder_state_ == kResetting || decoder_flushing_); | 1951 (decoder_state_ == kResetting || decoder_flushing_); |
1952 while (pending_picture_ready_.size() > 0) { | 1952 while (pending_picture_ready_.size() > 0) { |
1953 bool cleared = pending_picture_ready_.front().cleared; | 1953 bool cleared = pending_picture_ready_.front().cleared; |
1954 const media::Picture& picture = pending_picture_ready_.front().picture; | 1954 const media::Picture& picture = pending_picture_ready_.front().picture; |
1955 if (cleared && picture_clearing_count_ == 0) { | 1955 if (cleared && picture_clearing_count_ == 0) { |
1956 // This picture is cleared. Post it to IO thread to reduce latency. This | 1956 // This picture is cleared. Post it to IO thread to reduce latency. This |
1957 // should be the case after all pictures are cleared at the beginning. | 1957 // should be the case after all pictures are cleared at the beginning. |
1958 io_message_loop_proxy_->PostTask( | 1958 io_message_loop_proxy_->PostTask( |
1959 FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); | 1959 FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); |
1960 pending_picture_ready_.pop(); | 1960 pending_picture_ready_.pop(); |
1961 } else if (!cleared || resetting_or_flushing) { | 1961 } else if (!cleared || resetting_or_flushing) { |
1962 DVLOG(3) << "SendPictureReady()" | 1962 DVLOG(3) << "SendPictureReady()" |
1963 << ". cleared=" << pending_picture_ready_.front().cleared | 1963 << ". cleared=" << pending_picture_ready_.front().cleared |
1964 << ", decoder_state_=" << decoder_state_ | 1964 << ", decoder_state_=" << decoder_state_ |
1965 << ", decoder_flushing_=" << decoder_flushing_ | 1965 << ", decoder_flushing_=" << decoder_flushing_ |
1966 << ", picture_clearing_count_=" << picture_clearing_count_; | 1966 << ", picture_clearing_count_=" << picture_clearing_count_; |
1967 // If the picture is not cleared, post it to the child thread because it | 1967 // If the picture is not cleared, post it to the child thread because it |
1968 // has to be cleared in the child thread. A picture only needs to be | 1968 // has to be cleared in the child thread. A picture only needs to be |
1969 // cleared once. If the decoder is resetting or flushing, send all | 1969 // cleared once. If the decoder is resetting or flushing, send all |
1970 // pictures to ensure PictureReady arrive before reset or flush done. | 1970 // pictures to ensure PictureReady arrive before reset or flush done. |
1971 child_message_loop_proxy_->PostTaskAndReply( | 1971 child_message_loop_proxy_->PostTaskAndReply( |
1972 FROM_HERE, | 1972 FROM_HERE, |
1973 base::Bind(&Client::PictureReady, client_, picture), | 1973 base::Bind(&Client::PictureReady, client_, picture), |
1974 // Unretained is safe. If Client::PictureReady gets to run, |this| is | 1974 // Unretained is safe. If Client::PictureReady gets to run, |this| is |
1975 // alive. Destroy() will wait the decode thread to finish. | 1975 // alive. Destroy() will wait the decode thread to finish. |
1976 base::Bind(&ExynosVideoDecodeAccelerator::PictureCleared, | 1976 base::Bind(&V4L2VideoDecodeAccelerator::PictureCleared, |
1977 base::Unretained(this))); | 1977 base::Unretained(this))); |
1978 picture_clearing_count_++; | 1978 picture_clearing_count_++; |
1979 pending_picture_ready_.pop(); | 1979 pending_picture_ready_.pop(); |
1980 } else { | 1980 } else { |
1981 // This picture is cleared. But some pictures are about to be cleared on | 1981 // This picture is cleared. But some pictures are about to be cleared on |
1982 // the child thread. To preserve the order, do not send this until those | 1982 // the child thread. To preserve the order, do not send this until those |
1983 // pictures are cleared. | 1983 // pictures are cleared. |
1984 break; | 1984 break; |
1985 } | 1985 } |
1986 } | 1986 } |
1987 } | 1987 } |
1988 | 1988 |
1989 void ExynosVideoDecodeAccelerator::PictureCleared() { | 1989 void V4L2VideoDecodeAccelerator::PictureCleared() { |
1990 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_; | 1990 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_; |
1991 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1991 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1992 DCHECK_GT(picture_clearing_count_, 0); | 1992 DCHECK_GT(picture_clearing_count_, 0); |
1993 picture_clearing_count_--; | 1993 picture_clearing_count_--; |
1994 SendPictureReady(); | 1994 SendPictureReady(); |
1995 } | 1995 } |
1996 | 1996 |
1997 } // namespace content | 1997 } // namespace content |
OLD | NEW |