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

Side by Side Diff: content/common/gpu/media/exynos_video_decode_accelerator.cc

Issue 23526070: Remove GSC usage from ExynosVideoDecodeAccelerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 7e4634ee Functional. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <linux/videodev2.h> 9 #include <linux/videodev2.h>
9 #include <poll.h> 10 #include <poll.h>
10 #include <sys/eventfd.h> 11 #include <sys/eventfd.h>
11 #include <sys/ioctl.h> 12 #include <sys/ioctl.h>
12 #include <sys/mman.h> 13 #include <sys/mman.h>
13 14
14 #include "base/bind.h" 15 #include "base/bind.h"
15 #include "base/debug/trace_event.h" 16 #include "base/debug/trace_event.h"
16 #include "base/memory/shared_memory.h" 17 #include "base/memory/shared_memory.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } while (0) 50 } while (0)
50 51
51 namespace { 52 namespace {
52 53
53 // TODO(posciak): remove once we update linux-headers. 54 // TODO(posciak): remove once we update linux-headers.
54 #ifndef V4L2_EVENT_RESOLUTION_CHANGE 55 #ifndef V4L2_EVENT_RESOLUTION_CHANGE
55 #define V4L2_EVENT_RESOLUTION_CHANGE 5 56 #define V4L2_EVENT_RESOLUTION_CHANGE 5
56 #endif 57 #endif
57 58
58 const char kExynosMfcDevice[] = "/dev/mfc-dec"; 59 const char kExynosMfcDevice[] = "/dev/mfc-dec";
59 const char kExynosGscDevice[] = "/dev/gsc1";
60 const char kMaliDriver[] = "libmali.so";
61 60
62 typedef EGLBoolean (*MaliEglImageGetBufferExtPhandleFunc)(EGLImageKHR, EGLint*,
63 void*);
64
65 void* libmali_handle = NULL;
66 MaliEglImageGetBufferExtPhandleFunc
67 mali_egl_image_get_buffer_ext_phandle = NULL;
68 } // anonymous namespace 61 } // anonymous namespace
69 62
70 struct ExynosVideoDecodeAccelerator::BitstreamBufferRef { 63 struct ExynosVideoDecodeAccelerator::BitstreamBufferRef {
71 BitstreamBufferRef( 64 BitstreamBufferRef(
72 base::WeakPtr<Client>& client, 65 base::WeakPtr<Client>& client,
73 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, 66 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy,
74 base::SharedMemory* shm, 67 base::SharedMemory* shm,
75 size_t size, 68 size_t size,
76 int32 input_id); 69 int32 input_id);
77 ~BitstreamBufferRef(); 70 ~BitstreamBufferRef();
78 const base::WeakPtr<Client> client; 71 const base::WeakPtr<Client> client;
79 const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy; 72 const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy;
80 const scoped_ptr<base::SharedMemory> shm; 73 const scoped_ptr<base::SharedMemory> shm;
81 const size_t size; 74 const size_t size;
82 off_t bytes_used; 75 off_t bytes_used;
83 const int32 input_id; 76 const int32 input_id;
84 }; 77 };
85 78
86 struct ExynosVideoDecodeAccelerator::PictureBufferArrayRef { 79 struct ExynosVideoDecodeAccelerator::PictureBufferArrayRef {
87 PictureBufferArrayRef(EGLDisplay egl_display, size_t count); 80 PictureBufferArrayRef(EGLDisplay egl_display);
88 ~PictureBufferArrayRef(); 81 ~PictureBufferArrayRef();
89 82
90 struct PictureBufferRef { 83 struct PictureBufferRef {
84 PictureBufferRef(EGLImageKHR egl_image, int32 picture_id)
85 : egl_image(egl_image), picture_id(picture_id) {}
91 EGLImageKHR egl_image; 86 EGLImageKHR egl_image;
92 int egl_image_fd; 87 int32 picture_id;
93 int32 client_id;
94 }; 88 };
95 89
96 EGLDisplay const egl_display; 90 EGLDisplay const egl_display;
97 std::vector<PictureBufferRef> picture_buffers; 91 std::vector<PictureBufferRef> picture_buffers;
98 }; 92 };
99 93
100 struct ExynosVideoDecodeAccelerator::EGLSyncKHRRef { 94 struct ExynosVideoDecodeAccelerator::EGLSyncKHRRef {
101 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync); 95 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync);
102 ~EGLSyncKHRRef(); 96 ~EGLSyncKHRRef();
103 EGLDisplay const egl_display; 97 EGLDisplay const egl_display;
(...skipping 13 matching lines...) Expand all
117 } 111 }
118 112
119 ExynosVideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() { 113 ExynosVideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() {
120 if (input_id >= 0) { 114 if (input_id >= 0) {
121 client_message_loop_proxy->PostTask(FROM_HERE, base::Bind( 115 client_message_loop_proxy->PostTask(FROM_HERE, base::Bind(
122 &Client::NotifyEndOfBitstreamBuffer, client, input_id)); 116 &Client::NotifyEndOfBitstreamBuffer, client, input_id));
123 } 117 }
124 } 118 }
125 119
126 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::PictureBufferArrayRef( 120 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::PictureBufferArrayRef(
127 EGLDisplay egl_display, size_t count) 121 EGLDisplay egl_display)
128 : egl_display(egl_display), 122 : egl_display(egl_display) {}
129 picture_buffers(count) { 123
124 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::~PictureBufferArrayRef() {
130 for (size_t i = 0; i < picture_buffers.size(); ++i) { 125 for (size_t i = 0; i < picture_buffers.size(); ++i) {
131 PictureBufferRef& buffer = picture_buffers[i]; 126 EGLImageKHR egl_image = picture_buffers[i].egl_image;
132 buffer.egl_image = EGL_NO_IMAGE_KHR; 127 if (egl_image != EGL_NO_IMAGE_KHR)
133 buffer.egl_image_fd = -1; 128 eglDestroyImageKHR(egl_display, egl_image);
134 buffer.client_id = -1;
135 } 129 }
136 } 130 }
137 131
138 ExynosVideoDecodeAccelerator::PictureBufferArrayRef::~PictureBufferArrayRef() {
139 for (size_t i = 0; i < picture_buffers.size(); ++i) {
140 PictureBufferRef& buffer = picture_buffers[i];
141 if (buffer.egl_image != EGL_NO_IMAGE_KHR)
142 eglDestroyImageKHR(egl_display, buffer.egl_image);
143 if (buffer.egl_image_fd != -1)
144 HANDLE_EINTR(close(buffer.egl_image_fd));
145 }
146 }
147
148 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::EGLSyncKHRRef( 132 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::EGLSyncKHRRef(
149 EGLDisplay egl_display, EGLSyncKHR egl_sync) 133 EGLDisplay egl_display, EGLSyncKHR egl_sync)
150 : egl_display(egl_display), 134 : egl_display(egl_display),
151 egl_sync(egl_sync) { 135 egl_sync(egl_sync) {
152 } 136 }
153 137
154 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::~EGLSyncKHRRef() { 138 ExynosVideoDecodeAccelerator::EGLSyncKHRRef::~EGLSyncKHRRef() {
155 if (egl_sync != EGL_NO_SYNC_KHR) 139 if (egl_sync != EGL_NO_SYNC_KHR)
156 eglDestroySyncKHR(egl_display, egl_sync); 140 eglDestroySyncKHR(egl_display, egl_sync);
157 } 141 }
158 142
159 ExynosVideoDecodeAccelerator::MfcInputRecord::MfcInputRecord() 143 ExynosVideoDecodeAccelerator::MfcInputRecord::MfcInputRecord()
160 : at_device(false), 144 : at_device(false),
161 address(NULL), 145 address(NULL),
162 length(0), 146 length(0),
163 bytes_used(0), 147 bytes_used(0),
164 input_id(-1) { 148 input_id(-1) {
165 } 149 }
166 150
167 ExynosVideoDecodeAccelerator::MfcInputRecord::~MfcInputRecord() { 151 ExynosVideoDecodeAccelerator::MfcInputRecord::~MfcInputRecord() {
168 } 152 }
169 153
170 ExynosVideoDecodeAccelerator::MfcOutputRecord::MfcOutputRecord() 154 ExynosVideoDecodeAccelerator::MfcOutputRecord::MfcOutputRecord()
171 : at_device(false), 155 : at_device(false),
172 input_id(-1) {
173 bytes_used[0] = 0;
174 bytes_used[1] = 0;
175 address[0] = NULL;
176 address[1] = NULL;
177 length[0] = 0;
178 length[1] = 0;
179 }
180
181 ExynosVideoDecodeAccelerator::MfcOutputRecord::~MfcOutputRecord() {
182 }
183
184 ExynosVideoDecodeAccelerator::GscInputRecord::GscInputRecord()
185 : at_device(false),
186 mfc_output(-1) {
187 }
188
189 ExynosVideoDecodeAccelerator::GscInputRecord::~GscInputRecord() {
190 }
191
192 ExynosVideoDecodeAccelerator::GscOutputRecord::GscOutputRecord()
193 : at_device(false),
194 at_client(false), 156 at_client(false),
195 fd(-1),
196 egl_image(EGL_NO_IMAGE_KHR), 157 egl_image(EGL_NO_IMAGE_KHR),
197 egl_sync(EGL_NO_SYNC_KHR), 158 egl_sync(EGL_NO_SYNC_KHR),
198 picture_id(-1) { 159 picture_id(-1) {
160 for (size_t i = 0; i < arraysize(fds); ++i)
161 fds[i] = -1;
199 } 162 }
200 163
201 ExynosVideoDecodeAccelerator::GscOutputRecord::~GscOutputRecord() { 164 ExynosVideoDecodeAccelerator::MfcOutputRecord::~MfcOutputRecord() {}
202 }
203 165
204 ExynosVideoDecodeAccelerator::ExynosVideoDecodeAccelerator( 166 ExynosVideoDecodeAccelerator::ExynosVideoDecodeAccelerator(
205 EGLDisplay egl_display, 167 EGLDisplay egl_display,
206 EGLContext egl_context, 168 EGLContext egl_context,
207 Client* client, 169 Client* client,
208 const base::WeakPtr<Client>& io_client, 170 const base::WeakPtr<Client>& io_client,
209 const base::Callback<bool(void)>& make_context_current, 171 const base::Callback<bool(void)>& make_context_current,
210 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) 172 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy)
211 : child_message_loop_proxy_(base::MessageLoopProxy::current()), 173 : child_message_loop_proxy_(base::MessageLoopProxy::current()),
212 io_message_loop_proxy_(io_message_loop_proxy), 174 io_message_loop_proxy_(io_message_loop_proxy),
(...skipping 11 matching lines...) Expand all
224 resolution_change_pending_(false), 186 resolution_change_pending_(false),
225 resolution_change_reset_pending_(false), 187 resolution_change_reset_pending_(false),
226 decoder_partial_frame_pending_(false), 188 decoder_partial_frame_pending_(false),
227 mfc_fd_(-1), 189 mfc_fd_(-1),
228 mfc_input_streamon_(false), 190 mfc_input_streamon_(false),
229 mfc_input_buffer_queued_count_(0), 191 mfc_input_buffer_queued_count_(0),
230 mfc_output_streamon_(false), 192 mfc_output_streamon_(false),
231 mfc_output_buffer_queued_count_(0), 193 mfc_output_buffer_queued_count_(0),
232 mfc_output_buffer_pixelformat_(0), 194 mfc_output_buffer_pixelformat_(0),
233 mfc_output_dpb_size_(0), 195 mfc_output_dpb_size_(0),
234 gsc_fd_(-1),
235 gsc_input_streamon_(false),
236 gsc_input_buffer_queued_count_(0),
237 gsc_output_streamon_(false),
238 gsc_output_buffer_queued_count_(0),
239 device_poll_thread_("ExynosDevicePollThread"), 196 device_poll_thread_("ExynosDevicePollThread"),
240 device_poll_interrupt_fd_(-1), 197 device_poll_interrupt_fd_(-1),
241 make_context_current_(make_context_current), 198 make_context_current_(make_context_current),
242 egl_display_(egl_display), 199 egl_display_(egl_display),
243 egl_context_(egl_context), 200 egl_context_(egl_context),
244 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {} 201 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {}
245 202
246 ExynosVideoDecodeAccelerator::~ExynosVideoDecodeAccelerator() { 203 ExynosVideoDecodeAccelerator::~ExynosVideoDecodeAccelerator() {
247 DCHECK(!decoder_thread_.IsRunning()); 204 DCHECK(!decoder_thread_.IsRunning());
248 DCHECK(!device_poll_thread_.IsRunning()); 205 DCHECK(!device_poll_thread_.IsRunning());
249 206
250 if (device_poll_interrupt_fd_ != -1) { 207 if (device_poll_interrupt_fd_ != -1) {
251 HANDLE_EINTR(close(device_poll_interrupt_fd_)); 208 HANDLE_EINTR(close(device_poll_interrupt_fd_));
252 device_poll_interrupt_fd_ = -1; 209 device_poll_interrupt_fd_ = -1;
253 } 210 }
254 if (gsc_fd_ != -1) {
255 DestroyGscInputBuffers();
256 DestroyGscOutputBuffers();
257 HANDLE_EINTR(close(gsc_fd_));
258 gsc_fd_ = -1;
259 }
260 if (mfc_fd_ != -1) { 211 if (mfc_fd_ != -1) {
261 DestroyMfcInputBuffers(); 212 DestroyMfcInputBuffers();
262 DestroyMfcOutputBuffers(); 213 DestroyMfcOutputBuffers();
263 HANDLE_EINTR(close(mfc_fd_)); 214 HANDLE_EINTR(close(mfc_fd_));
264 mfc_fd_ = -1; 215 mfc_fd_ = -1;
265 } 216 }
266 217
267 // These maps have members that should be manually destroyed, e.g. file 218 // These maps have members that should be manually destroyed, e.g. file
268 // descriptors, mmap() segments, etc. 219 // descriptors, mmap() segments, etc.
269 DCHECK(mfc_input_buffer_map_.empty()); 220 DCHECK(mfc_input_buffer_map_.empty());
270 DCHECK(mfc_output_buffer_map_.empty()); 221 DCHECK(mfc_output_buffer_map_.empty());
271 DCHECK(gsc_input_buffer_map_.empty());
272 DCHECK(gsc_output_buffer_map_.empty());
273 } 222 }
274 223
275 bool ExynosVideoDecodeAccelerator::Initialize( 224 bool ExynosVideoDecodeAccelerator::Initialize(
276 media::VideoCodecProfile profile) { 225 media::VideoCodecProfile profile) {
277 DVLOG(3) << "Initialize()"; 226 DVLOG(3) << "Initialize()";
278 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 227 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
279 DCHECK_EQ(decoder_state_, kUninitialized); 228 DCHECK_EQ(decoder_state_, kUninitialized);
280 229
281 switch (profile) { 230 switch (profile) {
282 case media::H264PROFILE_BASELINE: 231 case media::H264PROFILE_BASELINE:
283 DVLOG(2) << "Initialize(): profile H264PROFILE_BASELINE"; 232 DVLOG(2) << "Initialize(): profile H264PROFILE_BASELINE";
284 break; 233 break;
285 case media::H264PROFILE_MAIN: 234 case media::H264PROFILE_MAIN:
286 DVLOG(2) << "Initialize(): profile H264PROFILE_MAIN"; 235 DVLOG(2) << "Initialize(): profile H264PROFILE_MAIN";
287 break; 236 break;
288 case media::H264PROFILE_HIGH: 237 case media::H264PROFILE_HIGH:
289 DVLOG(2) << "Initialize(): profile H264PROFILE_HIGH"; 238 DVLOG(2) << "Initialize(): profile H264PROFILE_HIGH";
290 break; 239 break;
291 case media::VP8PROFILE_MAIN: 240 case media::VP8PROFILE_MAIN:
292 DVLOG(2) << "Initialize(): profile VP8PROFILE_MAIN"; 241 DVLOG(2) << "Initialize(): profile VP8PROFILE_MAIN";
293 break; 242 break;
294 default: 243 default:
295 DLOG(ERROR) << "Initialize(): unsupported profile=" << profile; 244 DLOG(ERROR) << "Initialize(): unsupported profile=" << profile;
296 return false; 245 return false;
297 }; 246 };
298 video_profile_ = profile; 247 video_profile_ = profile;
299 248
300 static bool sandbox_initialized = PostSandboxInitialization();
301 if (!sandbox_initialized) {
302 DLOG(ERROR) << "Initialize(): PostSandboxInitialization() failed";
303 NOTIFY_ERROR(PLATFORM_FAILURE);
304 return false;
305 }
306
307 if (egl_display_ == EGL_NO_DISPLAY) { 249 if (egl_display_ == EGL_NO_DISPLAY) {
308 DLOG(ERROR) << "Initialize(): could not get EGLDisplay"; 250 DLOG(ERROR) << "Initialize(): could not get EGLDisplay";
309 NOTIFY_ERROR(PLATFORM_FAILURE); 251 NOTIFY_ERROR(PLATFORM_FAILURE);
310 return false; 252 return false;
311 } 253 }
312 254
313 if (egl_context_ == EGL_NO_CONTEXT) { 255 if (egl_context_ == EGL_NO_CONTEXT) {
314 DLOG(ERROR) << "Initialize(): could not get EGLContext"; 256 DLOG(ERROR) << "Initialize(): could not get EGLContext";
315 NOTIFY_ERROR(PLATFORM_FAILURE); 257 NOTIFY_ERROR(PLATFORM_FAILURE);
316 return false; 258 return false;
(...skipping 15 matching lines...) Expand all
332 // Open the video devices. 274 // Open the video devices.
333 DVLOG(2) << "Initialize(): opening MFC device: " << kExynosMfcDevice; 275 DVLOG(2) << "Initialize(): opening MFC device: " << kExynosMfcDevice;
334 mfc_fd_ = HANDLE_EINTR(open(kExynosMfcDevice, 276 mfc_fd_ = HANDLE_EINTR(open(kExynosMfcDevice,
335 O_RDWR | O_NONBLOCK | O_CLOEXEC)); 277 O_RDWR | O_NONBLOCK | O_CLOEXEC));
336 if (mfc_fd_ == -1) { 278 if (mfc_fd_ == -1) {
337 DPLOG(ERROR) << "Initialize(): could not open MFC device: " 279 DPLOG(ERROR) << "Initialize(): could not open MFC device: "
338 << kExynosMfcDevice; 280 << kExynosMfcDevice;
339 NOTIFY_ERROR(PLATFORM_FAILURE); 281 NOTIFY_ERROR(PLATFORM_FAILURE);
340 return false; 282 return false;
341 } 283 }
342 DVLOG(2) << "Initialize(): opening GSC device: " << kExynosGscDevice;
343 gsc_fd_ = HANDLE_EINTR(open(kExynosGscDevice,
344 O_RDWR | O_NONBLOCK | O_CLOEXEC));
345 if (gsc_fd_ == -1) {
346 DPLOG(ERROR) << "Initialize(): could not open GSC device: "
347 << kExynosGscDevice;
348 NOTIFY_ERROR(PLATFORM_FAILURE);
349 return false;
350 }
351 284
352 // Create the interrupt fd. 285 // Create the interrupt fd.
353 DCHECK_EQ(device_poll_interrupt_fd_, -1); 286 DCHECK_EQ(device_poll_interrupt_fd_, -1);
354 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); 287 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
355 if (device_poll_interrupt_fd_ == -1) { 288 if (device_poll_interrupt_fd_ == -1) {
356 DPLOG(ERROR) << "Initialize(): eventfd() failed"; 289 DPLOG(ERROR) << "Initialize(): eventfd() failed";
357 NOTIFY_ERROR(PLATFORM_FAILURE); 290 NOTIFY_ERROR(PLATFORM_FAILURE);
358 return false; 291 return false;
359 } 292 }
360 293
361 // Capabilities check. 294 // Capabilities check.
362 struct v4l2_capability caps; 295 struct v4l2_capability caps;
363 const __u32 kCapsRequired = 296 const __u32 kCapsRequired =
364 V4L2_CAP_VIDEO_CAPTURE_MPLANE | 297 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
365 V4L2_CAP_VIDEO_OUTPUT_MPLANE | 298 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
366 V4L2_CAP_STREAMING; 299 V4L2_CAP_STREAMING;
367 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QUERYCAP, &caps); 300 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QUERYCAP, &caps);
368 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { 301 if ((caps.capabilities & kCapsRequired) != kCapsRequired) {
369 DLOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP" 302 DLOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP"
370 ", caps check failed: 0x" << std::hex << caps.capabilities; 303 ", caps check failed: 0x" << std::hex << caps.capabilities;
371 NOTIFY_ERROR(PLATFORM_FAILURE); 304 NOTIFY_ERROR(PLATFORM_FAILURE);
372 return false; 305 return false;
373 } 306 }
374 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_QUERYCAP, &caps);
375 if ((caps.capabilities & kCapsRequired) != kCapsRequired) {
376 DLOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP"
377 ", caps check failed: 0x" << std::hex << caps.capabilities;
378 NOTIFY_ERROR(PLATFORM_FAILURE);
379 return false;
380 }
381 307
382 if (!CreateMfcInputBuffers()) 308 if (!CreateMfcInputBuffers())
383 return false; 309 return false;
384 310
385 // MFC output format has to be setup before streaming starts. 311 // MFC output format has to be setup before streaming starts.
386 struct v4l2_format format; 312 struct v4l2_format format;
387 memset(&format, 0, sizeof(format)); 313 memset(&format, 0, sizeof(format));
388 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 314 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
389 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12MT_16X16; 315 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12M;
390 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format); 316 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format);
391 317
392 // Subscribe to the resolution change event. 318 // Subscribe to the resolution change event.
393 struct v4l2_event_subscription sub; 319 struct v4l2_event_subscription sub;
394 memset(&sub, 0, sizeof(sub)); 320 memset(&sub, 0, sizeof(sub));
395 sub.type = V4L2_EVENT_RESOLUTION_CHANGE; 321 sub.type = V4L2_EVENT_RESOLUTION_CHANGE;
396 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_SUBSCRIBE_EVENT, &sub); 322 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_SUBSCRIBE_EVENT, &sub);
397 323
398 // Initialize format-specific bits. 324 // Initialize format-specific bits.
399 if (video_profile_ >= media::H264PROFILE_MIN && 325 if (video_profile_ >= media::H264PROFILE_MIN &&
(...skipping 24 matching lines...) Expand all
424 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 350 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
425 &ExynosVideoDecodeAccelerator::DecodeTask, base::Unretained(this), 351 &ExynosVideoDecodeAccelerator::DecodeTask, base::Unretained(this),
426 bitstream_buffer)); 352 bitstream_buffer));
427 } 353 }
428 354
429 void ExynosVideoDecodeAccelerator::AssignPictureBuffers( 355 void ExynosVideoDecodeAccelerator::AssignPictureBuffers(
430 const std::vector<media::PictureBuffer>& buffers) { 356 const std::vector<media::PictureBuffer>& buffers) {
431 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); 357 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size();
432 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 358 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
433 359
434 if (buffers.size() != gsc_output_buffer_map_.size()) { 360 if (buffers.size() != mfc_output_buffer_map_.size()) {
435 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" 361 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture"
436 " buffers. (Got " << buffers.size() << ", requested " << 362 " buffers. (Got " << buffers.size()
437 gsc_output_buffer_map_.size() << ")"; 363 << ", requested " << mfc_output_buffer_map_.size() << ")";
438 NOTIFY_ERROR(INVALID_ARGUMENT); 364 NOTIFY_ERROR(INVALID_ARGUMENT);
439 return; 365 return;
440 } 366 }
441 367
442 if (!make_context_current_.Run()) { 368 if (!make_context_current_.Run()) {
443 DLOG(ERROR) << "AssignPictureBuffers(): could not make context current"; 369 DLOG(ERROR) << "AssignPictureBuffers(): could not make context current";
444 NOTIFY_ERROR(PLATFORM_FAILURE); 370 NOTIFY_ERROR(PLATFORM_FAILURE);
445 return; 371 return;
446 } 372 }
447 373
448 scoped_ptr<PictureBufferArrayRef> pic_buffers_ref( 374 scoped_ptr<PictureBufferArrayRef> picture_buffers_ref(
449 new PictureBufferArrayRef(egl_display_, buffers.size())); 375 new PictureBufferArrayRef(egl_display_));
450 376 gfx::ScopedTextureBinder bind_restore(GL_TEXTURE_EXTERNAL_OES, 0);
451 const static EGLint kImageAttrs[] = { 377 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) {
452 EGL_IMAGE_PRESERVED_KHR, 0,
453 EGL_NONE,
454 };
455 Display* x_display = base::MessagePumpForUI::GetDefaultXDisplay();
456 gfx::ScopedTextureBinder bind_restore(GL_TEXTURE_2D, 0);
457 for (size_t i = 0; i < pic_buffers_ref->picture_buffers.size(); ++i) {
458 DCHECK(buffers[i].size() == frame_buffer_size_); 378 DCHECK(buffers[i].size() == frame_buffer_size_);
459 PictureBufferArrayRef::PictureBufferRef& buffer = 379 MfcOutputRecord& output_record = mfc_output_buffer_map_[i];
460 pic_buffers_ref->picture_buffers[i]; 380 EGLint attrs[] = {
Pawel Osciak 2013/09/30 05:16:25 Can some of this not concerning output_record be e
sheu 2013/10/04 23:25:56 Done.
461 // Create the X pixmap and then create an EGLImageKHR from it, so we can 381 EGL_WIDTH, 0, EGL_HEIGHT, 0,
462 // get dma_buf backing. 382 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0,
463 Pixmap pixmap = XCreatePixmap(x_display, 383 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
464 RootWindow(x_display, 0), 384 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0,
465 frame_buffer_size_.width(), 385 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, };
466 frame_buffer_size_.height(), 386 attrs[1] = frame_buffer_size_.width();
467 32); 387 attrs[3] = frame_buffer_size_.height();
468 if (!pixmap) { 388 attrs[5] = DRM_FORMAT_NV12;
469 DLOG(ERROR) << "AssignPictureBuffers(): could not create X pixmap"; 389 attrs[7] = output_record.fds[0];
470 NOTIFY_ERROR(PLATFORM_FAILURE); 390 attrs[9] = 0;
471 return; 391 attrs[11] = frame_buffer_size_.width();
472 } 392 attrs[13] = output_record.fds[1];
473 glBindTexture(GL_TEXTURE_2D, buffers[i].texture_id()); 393 attrs[15] = 0;
394 attrs[17] = frame_buffer_size_.width();
474 EGLImageKHR egl_image = eglCreateImageKHR( 395 EGLImageKHR egl_image = eglCreateImageKHR(
475 egl_display_, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, 396 egl_display_, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs);
476 (EGLClientBuffer)pixmap, kImageAttrs);
477 // We can free the X pixmap immediately -- according to the
478 // EGL_KHR_image_base spec, the backing storage does not go away until the
479 // last referencing EGLImage is destroyed.
480 XFreePixmap(x_display, pixmap);
481 if (egl_image == EGL_NO_IMAGE_KHR) { 397 if (egl_image == EGL_NO_IMAGE_KHR) {
482 DLOG(ERROR) << "AssignPictureBuffers(): could not create EGLImageKHR"; 398 DLOG(ERROR) << "AssignPictureBuffers(): could not create EGLImageKHR";
483 NOTIFY_ERROR(PLATFORM_FAILURE); 399 NOTIFY_ERROR(PLATFORM_FAILURE);
484 return; 400 return;
485 } 401 }
486 buffer.egl_image = egl_image; 402
487 int fd; 403 glBindTexture(GL_TEXTURE_EXTERNAL_OES, buffers[i].texture_id());
488 if (!mali_egl_image_get_buffer_ext_phandle(buffer.egl_image, NULL, &fd)) { 404 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image);
489 DLOG(ERROR) << "AssignPictureBuffers(): " 405 picture_buffers_ref->picture_buffers.push_back(
490 << "could not get EGLImageKHR dmabuf fd"; 406 PictureBufferArrayRef::PictureBufferRef(egl_image, buffers[i].id()));
491 NOTIFY_ERROR(PLATFORM_FAILURE);
492 return;
493 }
494 buffer.egl_image_fd = fd;
495 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image);
496 buffer.client_id = buffers[i].id();
497 } 407 }
498 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 408 decoder_thread_.message_loop()->PostTask(
499 &ExynosVideoDecodeAccelerator::AssignPictureBuffersTask, 409 FROM_HERE,
500 base::Unretained(this), base::Passed(&pic_buffers_ref))); 410 base::Bind(&ExynosVideoDecodeAccelerator::AssignPictureBuffersTask,
411 base::Unretained(this),
412 base::Passed(&picture_buffers_ref)));
501 } 413 }
502 414
503 void ExynosVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { 415 void ExynosVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) {
504 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; 416 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id;
505 // Must be run on child thread, as we'll insert a sync in the EGL context. 417 // Must be run on child thread, as we'll insert a sync in the EGL context.
506 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 418 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
507 419
508 if (!make_context_current_.Run()) { 420 if (!make_context_current_.Run()) {
509 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current"; 421 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current";
510 NOTIFY_ERROR(PLATFORM_FAILURE); 422 NOTIFY_ERROR(PLATFORM_FAILURE);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 471 }
560 472
561 // Set to kError state just in case. 473 // Set to kError state just in case.
562 SetDecoderState(kError); 474 SetDecoderState(kError);
563 475
564 delete this; 476 delete this;
565 } 477 }
566 478
567 bool ExynosVideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } 479 bool ExynosVideoDecodeAccelerator::CanDecodeOnIOThread() { return true; }
568 480
569 // static
570 void ExynosVideoDecodeAccelerator::PreSandboxInitialization() {
571 DVLOG(3) << "PreSandboxInitialization()";
572 dlerror();
573
574 libmali_handle = dlopen(kMaliDriver, RTLD_LAZY | RTLD_LOCAL);
575 if (libmali_handle == NULL) {
576 DPLOG(ERROR) << "failed to dlopen() " << kMaliDriver << ": " << dlerror();
577 }
578 }
579
580 // static
581 bool ExynosVideoDecodeAccelerator::PostSandboxInitialization() {
582 DVLOG(3) << "PostSandboxInitialization()";
583 if (libmali_handle == NULL) {
584 DLOG(ERROR) << "PostSandboxInitialization(): no " << kMaliDriver
585 << " driver handle";
586 return false;
587 }
588
589 dlerror();
590 mali_egl_image_get_buffer_ext_phandle =
591 reinterpret_cast<MaliEglImageGetBufferExtPhandleFunc>(
592 dlsym(libmali_handle, "mali_egl_image_get_buffer_ext_phandle"));
593 if (mali_egl_image_get_buffer_ext_phandle == NULL) {
594 DPLOG(ERROR) << "PostSandboxInitialization(): failed to dlsym() "
595 << "mali_egl_image_get_buffer_ext_phandle: " << dlerror();
596 return false;
597 }
598
599 return true;
600 }
601
602 void ExynosVideoDecodeAccelerator::DecodeTask( 481 void ExynosVideoDecodeAccelerator::DecodeTask(
603 const media::BitstreamBuffer& bitstream_buffer) { 482 const media::BitstreamBuffer& bitstream_buffer) {
604 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); 483 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id();
605 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 484 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
606 DCHECK_NE(decoder_state_, kUninitialized); 485 DCHECK_NE(decoder_state_, kUninitialized);
607 TRACE_EVENT1("Video Decoder", "EVDA::DecodeTask", "input_id", 486 TRACE_EVENT1("Video Decoder", "EVDA::DecodeTask", "input_id",
608 bitstream_buffer.id()); 487 bitstream_buffer.id());
609 488
610 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( 489 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef(
611 io_client_, io_message_loop_proxy_, 490 io_client_, io_message_loop_proxy_,
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 916 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1038 DCHECK_NE(decoder_state_, kUninitialized); 917 DCHECK_NE(decoder_state_, kUninitialized);
1039 TRACE_EVENT0("Video Decoder", "EVDA::AssignPictureBuffersTask"); 918 TRACE_EVENT0("Video Decoder", "EVDA::AssignPictureBuffersTask");
1040 919
1041 // We run AssignPictureBuffersTask even if we're in kResetting. 920 // We run AssignPictureBuffersTask even if we're in kResetting.
1042 if (decoder_state_ == kError) { 921 if (decoder_state_ == kError) {
1043 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state"; 922 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state";
1044 return; 923 return;
1045 } 924 }
1046 925
1047 DCHECK_EQ(pic_buffers->picture_buffers.size(), gsc_output_buffer_map_.size()); 926 DCHECK_EQ(pic_buffers->picture_buffers.size(), mfc_output_buffer_map_.size());
1048 for (size_t i = 0; i < gsc_output_buffer_map_.size(); ++i) { 927 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) {
928 MfcOutputRecord& output_record = mfc_output_buffer_map_[i];
929 PictureBufferArrayRef::PictureBufferRef& buffer_ref =
930 pic_buffers->picture_buffers[i];
1049 // We should be blank right now. 931 // We should be blank right now.
1050 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; 932 DCHECK(!output_record.at_device);
1051 DCHECK_EQ(output_record.fd, -1); 933 DCHECK(!output_record.at_client);
1052 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR); 934 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR);
1053 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); 935 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR);
1054 DCHECK_EQ(output_record.picture_id, -1); 936 DCHECK_EQ(output_record.picture_id, -1);
1055 PictureBufferArrayRef::PictureBufferRef& buffer = 937 output_record.egl_image = buffer_ref.egl_image;
1056 pic_buffers->picture_buffers[i]; 938 output_record.picture_id = buffer_ref.picture_id;
1057 output_record.fd = buffer.egl_image_fd; 939 mfc_free_output_buffers_.push_back(i);
1058 output_record.egl_image = buffer.egl_image; 940 DVLOG(3) << "AssignPictureBuffersTask(): buffer[" << i
1059 output_record.picture_id = buffer.client_id; 941 << "]: picture_id=" << buffer_ref.picture_id;
942 }
943 pic_buffers->picture_buffers.clear();
1060 944
1061 // Take ownership of the EGLImage and fd. 945 // We got buffers! Kick the MFC.
1062 buffer.egl_image = EGL_NO_IMAGE_KHR; 946 EnqueueMfc();
1063 buffer.egl_image_fd = -1;
1064 // And add this buffer to the free list.
1065 gsc_free_output_buffers_.push_back(i);
1066 }
1067
1068 // We got buffers! Kick the GSC.
1069 EnqueueGsc();
1070 947
1071 if (decoder_state_ == kChangingResolution) 948 if (decoder_state_ == kChangingResolution)
1072 ResumeAfterResolutionChange(); 949 ResumeAfterResolutionChange();
1073 } 950 }
1074 951
1075 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool mfc_event_pending) { 952 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool mfc_event_pending) {
1076 DVLOG(3) << "ServiceDeviceTask()"; 953 DVLOG(3) << "ServiceDeviceTask()";
1077 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 954 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1078 DCHECK_NE(decoder_state_, kUninitialized); 955 DCHECK_NE(decoder_state_, kUninitialized);
1079 DCHECK_NE(decoder_state_, kInitialized); 956 DCHECK_NE(decoder_state_, kInitialized);
1080 DCHECK_NE(decoder_state_, kAfterReset); 957 DCHECK_NE(decoder_state_, kAfterReset);
1081 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); 958 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask");
1082 959
1083 if (decoder_state_ == kResetting) { 960 if (decoder_state_ == kResetting) {
1084 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; 961 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state";
1085 return; 962 return;
1086 } else if (decoder_state_ == kError) { 963 } else if (decoder_state_ == kError) {
1087 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; 964 DVLOG(2) << "ServiceDeviceTask(): early out: kError state";
1088 return; 965 return;
1089 } else if (decoder_state_ == kChangingResolution) { 966 } else if (decoder_state_ == kChangingResolution) {
1090 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state"; 967 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state";
1091 return; 968 return;
1092 } 969 }
1093 970
1094 if (mfc_event_pending) 971 if (mfc_event_pending)
1095 DequeueMfcEvents(); 972 DequeueMfcEvents();
1096 DequeueMfc(); 973 DequeueMfc();
1097 DequeueGsc();
1098 EnqueueMfc(); 974 EnqueueMfc();
1099 EnqueueGsc();
1100 975
1101 // Clear the interrupt fd. 976 // Clear the interrupt fd.
1102 if (!ClearDevicePollInterrupt()) 977 if (!ClearDevicePollInterrupt())
1103 return; 978 return;
1104 979
1105 unsigned int poll_fds = 0; 980 unsigned int poll_fds = 0;
1106 // Add MFC fd, if we should poll on it. 981 // Add MFC fd, if we should poll on it.
1107 // MFC can be polled as soon as either input or output buffers are queued. 982 // MFC can be polled as soon as either input or output buffers are queued.
1108 if (mfc_input_buffer_queued_count_ + mfc_output_buffer_queued_count_ > 0) 983 if (mfc_input_buffer_queued_count_ + mfc_output_buffer_queued_count_ > 0)
1109 poll_fds |= kPollMfc; 984 poll_fds |= kPollMfc;
1110 // Add GSC fd, if we should poll on it.
1111 // GSC has to wait until both input and output buffers are queued.
1112 if (gsc_input_buffer_queued_count_ > 0 && gsc_output_buffer_queued_count_ > 0)
1113 poll_fds |= kPollGsc;
1114 985
1115 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(), 986 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(),
1116 // so either: 987 // so either:
1117 // * device_poll_thread_ is running normally 988 // * device_poll_thread_ is running normally
1118 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask() 989 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask()
1119 // shut it down, in which case we're either in kResetting or kError states 990 // shut it down, in which case we're either in kResetting or kError states
1120 // respectively, and we should have early-outed already. 991 // respectively, and we should have early-outed already.
1121 DCHECK(device_poll_thread_.message_loop()); 992 DCHECK(device_poll_thread_.message_loop());
1122 // Queue the DevicePollTask() now. 993 // Queue the DevicePollTask() now.
1123 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 994 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
1124 &ExynosVideoDecodeAccelerator::DevicePollTask, 995 &ExynosVideoDecodeAccelerator::DevicePollTask,
1125 base::Unretained(this), 996 base::Unretained(this),
1126 poll_fds)); 997 poll_fds));
1127 998
1128 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC[" 999 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC["
1129 << decoder_input_queue_.size() << "->" 1000 << decoder_input_queue_.size() << "->"
1130 << mfc_input_ready_queue_.size() << "] => MFC[" 1001 << mfc_input_ready_queue_.size() << "] => MFC["
1131 << mfc_free_input_buffers_.size() << "+" 1002 << mfc_free_input_buffers_.size() << "+"
1132 << mfc_input_buffer_queued_count_ << "/" 1003 << mfc_input_buffer_queued_count_ << "/"
1133 << mfc_input_buffer_map_.size() << "->" 1004 << mfc_input_buffer_map_.size() << "->"
1134 << mfc_free_output_buffers_.size() << "+" 1005 << mfc_free_output_buffers_.size() << "+"
1135 << mfc_output_buffer_queued_count_ << "/" 1006 << mfc_output_buffer_queued_count_ << "/"
1136 << mfc_output_buffer_map_.size() << "] => " 1007 << mfc_output_buffer_map_.size() << "] => VDA["
1137 << mfc_output_gsc_input_queue_.size() << " => GSC["
1138 << gsc_free_input_buffers_.size() << "+"
1139 << gsc_input_buffer_queued_count_ << "/"
1140 << gsc_input_buffer_map_.size() << "->"
1141 << gsc_free_output_buffers_.size() << "+"
1142 << gsc_output_buffer_queued_count_ << "/"
1143 << gsc_output_buffer_map_.size() << "] => VDA["
1144 << decoder_frames_at_client_ << "]"; 1008 << decoder_frames_at_client_ << "]";
1145 1009
1146 ScheduleDecodeBufferTaskIfNeeded(); 1010 ScheduleDecodeBufferTaskIfNeeded();
1147 StartResolutionChangeIfNeeded(); 1011 StartResolutionChangeIfNeeded();
1148 } 1012 }
1149 1013
1150 void ExynosVideoDecodeAccelerator::EnqueueMfc() { 1014 void ExynosVideoDecodeAccelerator::EnqueueMfc() {
1151 DVLOG(3) << "EnqueueMfc()"; 1015 DVLOG(3) << "EnqueueMfc()";
1152 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1016 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1153 DCHECK_NE(decoder_state_, kUninitialized); 1017 DCHECK_NE(decoder_state_, kUninitialized);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 if (errno == EAGAIN) { 1126 if (errno == EAGAIN) {
1263 // EAGAIN if we're just out of buffers to dequeue. 1127 // EAGAIN if we're just out of buffers to dequeue.
1264 break; 1128 break;
1265 } 1129 }
1266 DPLOG(ERROR) << "DequeueMfc(): ioctl() failed: VIDIOC_DQBUF"; 1130 DPLOG(ERROR) << "DequeueMfc(): ioctl() failed: VIDIOC_DQBUF";
1267 NOTIFY_ERROR(PLATFORM_FAILURE); 1131 NOTIFY_ERROR(PLATFORM_FAILURE);
1268 return; 1132 return;
1269 } 1133 }
1270 MfcOutputRecord& output_record = mfc_output_buffer_map_[dqbuf.index]; 1134 MfcOutputRecord& output_record = mfc_output_buffer_map_[dqbuf.index];
1271 DCHECK(output_record.at_device); 1135 DCHECK(output_record.at_device);
1136 DCHECK(!output_record.at_client);
1137 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR);
1138 DCHECK_NE(output_record.picture_id, -1);
1272 output_record.at_device = false; 1139 output_record.at_device = false;
1273 output_record.bytes_used[0] = dqbuf.m.planes[0].bytesused; 1140 if (dqbuf.m.planes[0].bytesused + dqbuf.m.planes[1].bytesused == 0) {
1274 output_record.bytes_used[1] = dqbuf.m.planes[1].bytesused;
1275 if (output_record.bytes_used[0] + output_record.bytes_used[1] == 0) {
1276 // This is an empty output buffer returned as part of a flush. 1141 // This is an empty output buffer returned as part of a flush.
1277 mfc_free_output_buffers_.push_back(dqbuf.index); 1142 mfc_free_output_buffers_.push_back(dqbuf.index);
1278 output_record.input_id = -1;
1279 } else { 1143 } else {
1280 // This is an output buffer with contents to pass down the pipe. 1144 DCHECK(dqbuf.timestamp.tv_sec >= 0);
Pawel Osciak 2013/09/30 05:16:25 DCHECK_GE possible?
sheu 2013/10/04 23:25:56 Done.
1281 mfc_output_gsc_input_queue_.push_back(dqbuf.index); 1145 output_record.at_client = true;
1282 output_record.input_id = dqbuf.timestamp.tv_sec; 1146 DVLOG(3) << "DequeueMfc(): returning input_id=" << dqbuf.timestamp.tv_sec
1283 DCHECK(output_record.input_id >= 0); 1147 << " as picture_id=" << output_record.picture_id;
1284 DVLOG(3) << "DequeueMfc(): dequeued input_id=" << output_record.input_id; 1148 io_message_loop_proxy_->PostTask(
1285 // We don't count this output buffer dequeued yet, or add it to the free 1149 FROM_HERE,
1286 // list, as it has data GSC needs to process. 1150 base::Bind(&Client::PictureReady,
1287 1151 io_client_,
1288 // We have new frames in mfc_output_gsc_input_queue_. Kick the pipe. 1152 media::Picture(output_record.picture_id,
1289 SetDevicePollInterrupt(); 1153 dqbuf.timestamp.tv_sec)));
1154 decoder_frames_at_client_++;
1290 } 1155 }
1291 mfc_output_buffer_queued_count_--; 1156 mfc_output_buffer_queued_count_--;
1292 } 1157 }
1293 1158
1294 NotifyFlushDoneIfNeeded(); 1159 NotifyFlushDoneIfNeeded();
1295 } 1160 }
1296 1161
1297 void ExynosVideoDecodeAccelerator::EnqueueGsc() {
1298 DVLOG(3) << "EnqueueGsc()";
1299 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1300 DCHECK_NE(decoder_state_, kUninitialized);
1301 DCHECK_NE(decoder_state_, kInitialized);
1302 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueGsc");
1303
1304 // Drain the pipe of completed MFC output buffers.
1305 const int old_gsc_inputs_queued = gsc_input_buffer_queued_count_;
1306 while (!mfc_output_gsc_input_queue_.empty() &&
1307 !gsc_free_input_buffers_.empty()) {
1308 if (!EnqueueGscInputRecord())
1309 return;
1310 }
1311 if (old_gsc_inputs_queued == 0 && gsc_input_buffer_queued_count_ != 0) {
1312 // We just started up a previously empty queue.
1313 // Queue state changed; signal interrupt.
1314 if (!SetDevicePollInterrupt())
1315 return;
1316 // Start VIDIOC_STREAMON if we haven't yet.
1317 if (!gsc_input_streamon_) {
1318 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1319 IOCTL_OR_ERROR_RETURN(gsc_fd_, VIDIOC_STREAMON, &type);
1320 gsc_input_streamon_ = true;
1321 }
1322 }
1323
1324 if (gsc_input_buffer_queued_count_ != 0 &&
1325 gsc_output_buffer_queued_count_ == 0 &&
1326 !gsc_free_output_buffers_.empty()) {
1327 const int old_gsc_outputs_queued = gsc_output_buffer_queued_count_;
1328 if (!EnqueueGscOutputRecord())
1329 return;
1330 if (old_gsc_outputs_queued == 0 && gsc_output_buffer_queued_count_ != 0) {
1331 // We just started up a previously empty queue.
1332 // Queue state changed; signal interrupt.
1333 if (!SetDevicePollInterrupt())
1334 return;
1335 // Start VIDIOC_STREAMON if we haven't yet.
1336 if (!gsc_output_streamon_) {
1337 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1338 IOCTL_OR_ERROR_RETURN(gsc_fd_, VIDIOC_STREAMON, &type);
1339 gsc_output_streamon_ = true;
1340 }
1341 }
1342 }
1343 // Bug check: GSC is liable to race conditions if more than one buffer is
1344 // simultaneously queued.
1345 DCHECK_GE(1, gsc_output_buffer_queued_count_);
1346 }
1347
1348 void ExynosVideoDecodeAccelerator::DequeueGsc() {
1349 DVLOG(3) << "DequeueGsc()";
1350 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1351 DCHECK_NE(decoder_state_, kUninitialized);
1352 DCHECK_NE(decoder_state_, kInitialized);
1353 DCHECK_NE(decoder_state_, kAfterReset);
1354 TRACE_EVENT0("Video Decoder", "EVDA::DequeueGsc");
1355
1356 // Dequeue completed GSC input (VIDEO_OUTPUT) buffers, and recycle to the free
1357 // list. Also recycle the corresponding MFC output buffers at this time.
1358 struct v4l2_buffer dqbuf;
1359 struct v4l2_plane planes[2];
1360 while (gsc_input_buffer_queued_count_ > 0) {
1361 DCHECK(gsc_input_streamon_);
1362 memset(&dqbuf, 0, sizeof(dqbuf));
1363 memset(planes, 0, sizeof(planes));
1364 dqbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1365 dqbuf.memory = V4L2_MEMORY_DMABUF;
1366 dqbuf.m.planes = planes;
1367 dqbuf.length = 2;
1368 if (ioctl(gsc_fd_, VIDIOC_DQBUF, &dqbuf) != 0) {
1369 if (errno == EAGAIN) {
1370 // EAGAIN if we're just out of buffers to dequeue.
1371 break;
1372 }
1373 DPLOG(ERROR) << "DequeueGsc(): ioctl() failed: VIDIOC_DQBUF";
1374 NOTIFY_ERROR(PLATFORM_FAILURE);
1375 return;
1376 }
1377 GscInputRecord& input_record = gsc_input_buffer_map_[dqbuf.index];
1378 MfcOutputRecord& output_record =
1379 mfc_output_buffer_map_[input_record.mfc_output];
1380 DCHECK(input_record.at_device);
1381 gsc_free_input_buffers_.push_back(dqbuf.index);
1382 mfc_free_output_buffers_.push_back(input_record.mfc_output);
1383 input_record.at_device = false;
1384 input_record.mfc_output = -1;
1385 output_record.input_id = -1;
1386 gsc_input_buffer_queued_count_--;
1387 }
1388
1389 // Dequeue completed GSC output (VIDEO_CAPTURE) buffers, and send them off to
1390 // the client. Don't recycle to its free list yet -- we can't do that until
1391 // ReusePictureBuffer() returns it to us.
1392 while (gsc_output_buffer_queued_count_ > 0) {
1393 DCHECK(gsc_output_streamon_);
1394 memset(&dqbuf, 0, sizeof(dqbuf));
1395 memset(planes, 0, sizeof(planes));
1396 dqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1397 dqbuf.memory = V4L2_MEMORY_DMABUF;
1398 dqbuf.m.planes = planes;
1399 dqbuf.length = 1;
1400 if (ioctl(gsc_fd_, VIDIOC_DQBUF, &dqbuf) != 0) {
1401 if (errno == EAGAIN) {
1402 // EAGAIN if we're just out of buffers to dequeue.
1403 break;
1404 }
1405 DPLOG(ERROR) << "DequeueGsc(): ioctl() failed: VIDIOC_DQBUF";
1406 NOTIFY_ERROR(PLATFORM_FAILURE);
1407 return;
1408 }
1409 GscOutputRecord& output_record = gsc_output_buffer_map_[dqbuf.index];
1410 DCHECK(output_record.at_device);
1411 DCHECK(!output_record.at_client);
1412 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR);
1413 output_record.at_device = false;
1414 output_record.at_client = true;
1415 gsc_output_buffer_queued_count_--;
1416 DVLOG(3) << "DequeueGsc(): returning input_id=" << dqbuf.timestamp.tv_sec
1417 << " as picture_id=" << output_record.picture_id;
1418 io_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
1419 &Client::PictureReady, io_client_, media::Picture(
1420 output_record.picture_id, dqbuf.timestamp.tv_sec)));
1421 decoder_frames_at_client_++;
1422 }
1423
1424 NotifyFlushDoneIfNeeded();
1425 }
1426
1427 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() { 1162 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() {
1428 DVLOG(3) << "EnqueueMfcInputRecord()"; 1163 DVLOG(3) << "EnqueueMfcInputRecord()";
1429 DCHECK(!mfc_input_ready_queue_.empty()); 1164 DCHECK(!mfc_input_ready_queue_.empty());
1430 1165
1431 // Enqueue a MFC input (VIDEO_OUTPUT) buffer. 1166 // Enqueue a MFC input (VIDEO_OUTPUT) buffer.
1432 const int buffer = mfc_input_ready_queue_.back(); 1167 const int buffer = mfc_input_ready_queue_.back();
1433 MfcInputRecord& input_record = mfc_input_buffer_map_[buffer]; 1168 MfcInputRecord& input_record = mfc_input_buffer_map_[buffer];
1434 DCHECK(!input_record.at_device); 1169 DCHECK(!input_record.at_device);
1435 struct v4l2_buffer qbuf; 1170 struct v4l2_buffer qbuf;
1436 struct v4l2_plane qbuf_plane; 1171 struct v4l2_plane qbuf_plane;
(...skipping 13 matching lines...) Expand all
1450 DVLOG(3) << "EnqueueMfcInputRecord(): enqueued input_id=" 1185 DVLOG(3) << "EnqueueMfcInputRecord(): enqueued input_id="
1451 << input_record.input_id; 1186 << input_record.input_id;
1452 return true; 1187 return true;
1453 } 1188 }
1454 1189
1455 bool ExynosVideoDecodeAccelerator::EnqueueMfcOutputRecord() { 1190 bool ExynosVideoDecodeAccelerator::EnqueueMfcOutputRecord() {
1456 DVLOG(3) << "EnqueueMfcOutputRecord()"; 1191 DVLOG(3) << "EnqueueMfcOutputRecord()";
1457 DCHECK(!mfc_free_output_buffers_.empty()); 1192 DCHECK(!mfc_free_output_buffers_.empty());
1458 1193
1459 // Enqueue a MFC output (VIDEO_CAPTURE) buffer. 1194 // Enqueue a MFC output (VIDEO_CAPTURE) buffer.
1460 const int buffer = mfc_free_output_buffers_.back(); 1195 const int buffer = mfc_free_output_buffers_.front();
1461 MfcOutputRecord& output_record = mfc_output_buffer_map_[buffer]; 1196 MfcOutputRecord& output_record = mfc_output_buffer_map_[buffer];
1462 DCHECK(!output_record.at_device); 1197 DCHECK(!output_record.at_device);
1463 DCHECK_EQ(output_record.input_id, -1);
1464 struct v4l2_buffer qbuf;
1465 struct v4l2_plane qbuf_planes[2];
1466 memset(&qbuf, 0, sizeof(qbuf));
1467 memset(qbuf_planes, 0, sizeof(qbuf_planes));
1468 qbuf.index = buffer;
1469 qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1470 qbuf.memory = V4L2_MEMORY_MMAP;
1471 qbuf.m.planes = qbuf_planes;
1472 qbuf.length = 2;
1473 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf);
1474 mfc_free_output_buffers_.pop_back();
1475 output_record.at_device = true;
1476 mfc_output_buffer_queued_count_++;
1477 return true;
1478 }
1479
1480 bool ExynosVideoDecodeAccelerator::EnqueueGscInputRecord() {
1481 DVLOG(3) << "EnqueueGscInputRecord()";
1482 DCHECK(!gsc_free_input_buffers_.empty());
1483
1484 // Enqueue a GSC input (VIDEO_OUTPUT) buffer for a complete MFC output
1485 // (VIDEO_CAPTURE) buffer.
1486 const int mfc_buffer = mfc_output_gsc_input_queue_.front();
1487 const int gsc_buffer = gsc_free_input_buffers_.back();
1488 MfcOutputRecord& output_record = mfc_output_buffer_map_[mfc_buffer];
1489 DCHECK(!output_record.at_device);
1490 GscInputRecord& input_record = gsc_input_buffer_map_[gsc_buffer];
1491 DCHECK(!input_record.at_device);
1492 DCHECK_EQ(input_record.mfc_output, -1);
1493 struct v4l2_buffer qbuf;
1494 struct v4l2_plane qbuf_planes[2];
1495 memset(&qbuf, 0, sizeof(qbuf));
1496 memset(qbuf_planes, 0, sizeof(qbuf_planes));
1497 qbuf.index = gsc_buffer;
1498 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1499 qbuf.timestamp.tv_sec = output_record.input_id;
1500 qbuf.memory = V4L2_MEMORY_USERPTR;
1501 qbuf.m.planes = qbuf_planes;
1502 qbuf.m.planes[0].bytesused = output_record.bytes_used[0];
1503 qbuf.m.planes[0].length = mfc_output_buffer_size_[0];
1504 qbuf.m.planes[0].m.userptr = (unsigned long)output_record.address[0];
1505 qbuf.m.planes[1].bytesused = output_record.bytes_used[1];
1506 qbuf.m.planes[1].length = mfc_output_buffer_size_[1];
1507 qbuf.m.planes[1].m.userptr = (unsigned long)output_record.address[1];
1508 qbuf.length = 2;
1509 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_QBUF, &qbuf);
1510 mfc_output_gsc_input_queue_.pop_front();
1511 gsc_free_input_buffers_.pop_back();
1512 input_record.at_device = true;
1513 input_record.mfc_output = mfc_buffer;
1514 output_record.bytes_used[0] = 0;
1515 output_record.bytes_used[1] = 0;
1516 gsc_input_buffer_queued_count_++;
1517 DVLOG(3) << "EnqueueGscInputRecord(): enqueued input_id="
1518 << output_record.input_id;
1519 return true;
1520 }
1521
1522 bool ExynosVideoDecodeAccelerator::EnqueueGscOutputRecord() {
1523 DVLOG(3) << "EnqueueGscOutputRecord()";
1524 DCHECK(!gsc_free_output_buffers_.empty());
1525
1526 // Enqueue a GSC output (VIDEO_CAPTURE) buffer.
1527 const int buffer = gsc_free_output_buffers_.front();
1528 GscOutputRecord& output_record = gsc_output_buffer_map_[buffer];
1529 DCHECK(!output_record.at_device);
1530 DCHECK(!output_record.at_client); 1198 DCHECK(!output_record.at_client);
1199 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR);
1200 DCHECK_NE(output_record.picture_id, -1);
1531 if (output_record.egl_sync != EGL_NO_SYNC_KHR) { 1201 if (output_record.egl_sync != EGL_NO_SYNC_KHR) {
1532 TRACE_EVENT0( 1202 TRACE_EVENT0("Video Decoder",
1533 "Video Decoder", 1203 "EVDA::EnqueueMfcOutputRecord: eglClientWaitSyncKHR");
1534 "EVDA::EnqueueGscOutputRecord: eglClientWaitSyncKHR");
1535 // If we have to wait for completion, wait. Note that 1204 // If we have to wait for completion, wait. Note that
1536 // gsc_free_output_buffers_ is a FIFO queue, so we always wait on the 1205 // mfc_free_output_buffers_ is a FIFO queue, so we always wait on the
1537 // buffer that has been in the queue the longest. 1206 // buffer that has been in the queue the longest.
1538 eglClientWaitSyncKHR(egl_display_, output_record.egl_sync, 0, 1207 eglClientWaitSyncKHR(egl_display_, output_record.egl_sync, 0,
1539 EGL_FOREVER_KHR); 1208 EGL_FOREVER_KHR);
1540 eglDestroySyncKHR(egl_display_, output_record.egl_sync); 1209 eglDestroySyncKHR(egl_display_, output_record.egl_sync);
1541 output_record.egl_sync = EGL_NO_SYNC_KHR; 1210 output_record.egl_sync = EGL_NO_SYNC_KHR;
1542 } 1211 }
1543 struct v4l2_buffer qbuf; 1212 struct v4l2_buffer qbuf;
1544 struct v4l2_plane qbuf_plane; 1213 struct v4l2_plane qbuf_planes[arraysize(output_record.fds)];
1545 memset(&qbuf, 0, sizeof(qbuf)); 1214 memset(&qbuf, 0, sizeof(qbuf));
1546 memset(&qbuf_plane, 0, sizeof(qbuf_plane)); 1215 memset(qbuf_planes, 0, sizeof(qbuf_planes));
1547 qbuf.index = buffer; 1216 qbuf.index = buffer;
1548 qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1217 qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1549 qbuf.memory = V4L2_MEMORY_DMABUF; 1218 qbuf.memory = V4L2_MEMORY_MMAP;
1550 qbuf.m.planes = &qbuf_plane; 1219 qbuf.m.planes = qbuf_planes;
1551 qbuf.m.planes[0].m.fd = output_record.fd; 1220 qbuf.length = arraysize(output_record.fds);
1552 qbuf.length = 1; 1221 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf);
1553 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_QBUF, &qbuf); 1222 mfc_free_output_buffers_.pop_front();
1554 gsc_free_output_buffers_.pop_front();
1555 output_record.at_device = true; 1223 output_record.at_device = true;
1556 gsc_output_buffer_queued_count_++; 1224 mfc_output_buffer_queued_count_++;
1557 return true; 1225 return true;
1558 } 1226 }
1559 1227
1560 void ExynosVideoDecodeAccelerator::ReusePictureBufferTask( 1228 void ExynosVideoDecodeAccelerator::ReusePictureBufferTask(
1561 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { 1229 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) {
1562 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" 1230 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id="
1563 << picture_buffer_id; 1231 << picture_buffer_id;
1564 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1232 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1565 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); 1233 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask");
1566 1234
1567 // We run ReusePictureBufferTask even if we're in kResetting. 1235 // We run ReusePictureBufferTask even if we're in kResetting.
1568 if (decoder_state_ == kError) { 1236 if (decoder_state_ == kError) {
1569 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; 1237 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state";
1570 return; 1238 return;
1571 } 1239 }
1572 1240
1573 if (decoder_state_ == kChangingResolution) { 1241 if (decoder_state_ == kChangingResolution) {
1574 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution"; 1242 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution";
1575 return; 1243 return;
1576 } 1244 }
1577 1245
1578 size_t index; 1246 size_t index;
1579 for (index = 0; index < gsc_output_buffer_map_.size(); ++index) 1247 for (index = 0; index < mfc_output_buffer_map_.size(); ++index)
1580 if (gsc_output_buffer_map_[index].picture_id == picture_buffer_id) 1248 if (mfc_output_buffer_map_[index].picture_id == picture_buffer_id)
1581 break; 1249 break;
1582 1250
1583 if (index >= gsc_output_buffer_map_.size()) { 1251 if (index >= mfc_output_buffer_map_.size()) {
1584 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; 1252 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found";
1585 NOTIFY_ERROR(INVALID_ARGUMENT); 1253 NOTIFY_ERROR(INVALID_ARGUMENT);
1586 return; 1254 return;
1587 } 1255 }
1588 1256
1589 GscOutputRecord& output_record = gsc_output_buffer_map_[index]; 1257 MfcOutputRecord& output_record = mfc_output_buffer_map_[index];
1590 if (output_record.at_device || !output_record.at_client) { 1258 if (output_record.at_device || !output_record.at_client) {
1591 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not reusable"; 1259 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not reusable";
1592 NOTIFY_ERROR(INVALID_ARGUMENT); 1260 NOTIFY_ERROR(INVALID_ARGUMENT);
1593 return; 1261 return;
1594 } 1262 }
1595 1263
1596 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); 1264 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR);
1597 output_record.at_client = false; 1265 output_record.at_client = false;
1598 output_record.egl_sync = egl_sync_ref->egl_sync; 1266 output_record.egl_sync = egl_sync_ref->egl_sync;
1599 gsc_free_output_buffers_.push_back(index); 1267 mfc_free_output_buffers_.push_back(index);
1600 decoder_frames_at_client_--; 1268 decoder_frames_at_client_--;
1601 // Take ownership of the EGLSync. 1269 // Take ownership of the EGLSync.
1602 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; 1270 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR;
1603 // We got a buffer back, so kick the GSC. 1271 // We got a buffer back, so kick the MFC.
1604 EnqueueGsc(); 1272 EnqueueMfc();
1605 } 1273 }
1606 1274
1607 void ExynosVideoDecodeAccelerator::FlushTask() { 1275 void ExynosVideoDecodeAccelerator::FlushTask() {
1608 DVLOG(3) << "FlushTask()"; 1276 DVLOG(3) << "FlushTask()";
1609 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1277 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1610 TRACE_EVENT0("Video Decoder", "EVDA::FlushTask"); 1278 TRACE_EVENT0("Video Decoder", "EVDA::FlushTask");
1611 1279
1612 // Flush outstanding buffers. 1280 // Flush outstanding buffers.
1613 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { 1281 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) {
1614 // There's nothing in the pipe, so return done immediately. 1282 // There's nothing in the pipe, so return done immediately.
(...skipping 20 matching lines...) Expand all
1635 1303
1636 void ExynosVideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { 1304 void ExynosVideoDecodeAccelerator::NotifyFlushDoneIfNeeded() {
1637 if (!decoder_flushing_) 1305 if (!decoder_flushing_)
1638 return; 1306 return;
1639 1307
1640 // Pipeline is empty when: 1308 // Pipeline is empty when:
1641 // * Decoder input queue is empty of non-delayed buffers. 1309 // * Decoder input queue is empty of non-delayed buffers.
1642 // * There is no currently filling input buffer. 1310 // * There is no currently filling input buffer.
1643 // * MFC input holding queue is empty. 1311 // * MFC input holding queue is empty.
1644 // * All MFC input (VIDEO_OUTPUT) buffers are returned. 1312 // * All MFC input (VIDEO_OUTPUT) buffers are returned.
1645 // * MFC -> GSC holding queue is empty.
1646 // * All GSC input (VIDEO_OUTPUT) buffers are returned.
1647 if (!decoder_input_queue_.empty()) { 1313 if (!decoder_input_queue_.empty()) {
1648 if (decoder_input_queue_.front()->input_id != 1314 if (decoder_input_queue_.front()->input_id !=
1649 decoder_delay_bitstream_buffer_id_) 1315 decoder_delay_bitstream_buffer_id_)
1650 return; 1316 return;
1651 } 1317 }
1652 if (decoder_current_input_buffer_ != -1) 1318 if (decoder_current_input_buffer_ != -1)
1653 return; 1319 return;
1654 if ((mfc_input_ready_queue_.size() + 1320 if ((mfc_input_ready_queue_.size() + mfc_input_buffer_queued_count_) != 0)
1655 mfc_input_buffer_queued_count_ + mfc_output_gsc_input_queue_.size() +
1656 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ ) != 0)
1657 return; 1321 return;
1658 1322
1659 // TODO(posciak): crbug.com/270039. MFC requires a streamoff-streamon 1323 // TODO(posciak): crbug.com/270039. MFC requires a streamoff-streamon
1660 // sequence after flush to continue, even if we are not resetting. This would 1324 // sequence after flush to continue, even if we are not resetting. This would
1661 // make sense, because we don't really want to resume from a non-resume point 1325 // make sense, because we don't really want to resume from a non-resume point
1662 // (e.g. not from an IDR) if we are flushed. 1326 // (e.g. not from an IDR) if we are flushed.
1663 // MSE player however triggers a Flush() on chunk end, but never Reset(). One 1327 // MSE player however triggers a Flush() on chunk end, but never Reset(). One
1664 // could argue either way, or even say that Flush() is not needed/harmful when 1328 // could argue either way, or even say that Flush() is not needed/harmful when
1665 // transitioning to next chunk. 1329 // transitioning to next chunk.
1666 // For now, do the streamoff-streamon cycle to satisfy MFC and not freeze when 1330 // For now, do the streamoff-streamon cycle to satisfy MFC and not freeze when
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1475 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1812 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); 1476 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type);
1813 } 1477 }
1814 mfc_input_streamon_ = false; 1478 mfc_input_streamon_ = false;
1815 } 1479 }
1816 if (mfc_output_streamon_) { 1480 if (mfc_output_streamon_) {
1817 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1481 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1818 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); 1482 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type);
1819 } 1483 }
1820 mfc_output_streamon_ = false; 1484 mfc_output_streamon_ = false;
1821 if (gsc_input_streamon_) {
1822 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1823 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type);
1824 }
1825 gsc_input_streamon_ = false;
1826 if (gsc_output_streamon_) {
1827 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1828 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type);
1829 }
1830 gsc_output_streamon_ = false;
1831 1485
1832 // Reset all our accounting info. 1486 // Reset all our accounting info.
1833 if (!keep_mfc_input_state) { 1487 if (!keep_mfc_input_state) {
1834 mfc_input_ready_queue_.clear(); 1488 mfc_input_ready_queue_.clear();
1835 mfc_free_input_buffers_.clear(); 1489 mfc_free_input_buffers_.clear();
1836 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { 1490 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) {
1837 mfc_free_input_buffers_.push_back(i); 1491 mfc_free_input_buffers_.push_back(i);
1838 mfc_input_buffer_map_[i].at_device = false; 1492 mfc_input_buffer_map_[i].at_device = false;
1839 mfc_input_buffer_map_[i].bytes_used = 0; 1493 mfc_input_buffer_map_[i].bytes_used = 0;
1840 mfc_input_buffer_map_[i].input_id = -1; 1494 mfc_input_buffer_map_[i].input_id = -1;
1841 } 1495 }
1842 mfc_input_buffer_queued_count_ = 0; 1496 mfc_input_buffer_queued_count_ = 0;
1843 } 1497 }
1844 mfc_free_output_buffers_.clear(); 1498 mfc_free_output_buffers_.clear();
1845 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { 1499 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) {
1846 mfc_free_output_buffers_.push_back(i); 1500 MfcOutputRecord& output_record = mfc_output_buffer_map_[i];
1847 mfc_output_buffer_map_[i].at_device = false; 1501 // Only mark those free that aren't being held by the VDA client.
1848 mfc_output_buffer_map_[i].input_id = -1; 1502 if (!output_record.at_client) {
1503 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR);
1504 mfc_free_output_buffers_.push_back(i);
1505 mfc_output_buffer_map_[i].at_device = false;
1506 }
1849 } 1507 }
1850 mfc_output_buffer_queued_count_ = 0; 1508 mfc_output_buffer_queued_count_ = 0;
1851 mfc_output_gsc_input_queue_.clear();
1852 gsc_free_input_buffers_.clear();
1853 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) {
1854 gsc_free_input_buffers_.push_back(i);
1855 gsc_input_buffer_map_[i].at_device = false;
1856 gsc_input_buffer_map_[i].mfc_output = -1;
1857 }
1858 gsc_input_buffer_queued_count_ = 0;
1859 gsc_free_output_buffers_.clear();
1860 for (size_t i = 0; i < gsc_output_buffer_map_.size(); ++i) {
1861 // Only mark those free that aren't being held by the VDA.
1862 if (!gsc_output_buffer_map_[i].at_client) {
1863 gsc_free_output_buffers_.push_back(i);
1864 gsc_output_buffer_map_[i].at_device = false;
1865 }
1866 }
1867 gsc_output_buffer_queued_count_ = 0;
1868 1509
1869 DVLOG(3) << "StopDevicePoll(): device poll stopped"; 1510 DVLOG(3) << "StopDevicePoll(): device poll stopped";
1870 return true; 1511 return true;
1871 } 1512 }
1872 1513
1873 bool ExynosVideoDecodeAccelerator::SetDevicePollInterrupt() { 1514 bool ExynosVideoDecodeAccelerator::SetDevicePollInterrupt() {
1874 DVLOG(3) << "SetDevicePollInterrupt()"; 1515 DVLOG(3) << "SetDevicePollInterrupt()";
1875 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1516 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1876 1517
1877 const uint64 buf = 1; 1518 const uint64 buf = 1;
(...skipping 23 matching lines...) Expand all
1901 return true; 1542 return true;
1902 } 1543 }
1903 1544
1904 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() { 1545 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() {
1905 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1546 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1906 DCHECK_EQ(decoder_state_, kDecoding); 1547 DCHECK_EQ(decoder_state_, kDecoding);
1907 1548
1908 if (!resolution_change_pending_) 1549 if (!resolution_change_pending_)
1909 return; 1550 return;
1910 1551
1911 if (!mfc_output_gsc_input_queue_.empty() || 1552 DVLOG(3) << "No more work, initiate resolution change";
1912 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ > 0) {
1913 DVLOG(3) << "StartResolutionChangeIfNeeded(): waiting for GSC to finish.";
1914 return;
1915 }
1916
1917 DVLOG(3) << "No more work for GSC, initiate resolution change";
1918 1553
1919 // Keep MFC input queue. 1554 // Keep MFC input queue.
1920 if (!StopDevicePoll(true)) 1555 if (!StopDevicePoll(true))
1921 return; 1556 return;
1922 1557
1923 decoder_state_ = kChangingResolution; 1558 decoder_state_ = kChangingResolution;
1924 DCHECK(resolution_change_pending_); 1559 DCHECK(resolution_change_pending_);
1925 resolution_change_pending_ = false; 1560 resolution_change_pending_ = false;
1926 1561
1927 // Post a task to clean up buffers on child thread. This will also ensure 1562 // Post a task to clean up buffers on child thread. This will also ensure
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 if (resolution_change_reset_pending_) { 1603 if (resolution_change_reset_pending_) {
1969 resolution_change_reset_pending_ = false; 1604 resolution_change_reset_pending_ = false;
1970 ResetTask(); 1605 ResetTask();
1971 return; 1606 return;
1972 } 1607 }
1973 1608
1974 if (!StartDevicePoll()) 1609 if (!StartDevicePoll())
1975 return; 1610 return;
1976 1611
1977 EnqueueMfc(); 1612 EnqueueMfc();
1978 // Gsc will get enqueued in AssignPictureBuffersTask(). 1613 // Gsc will get enqueued in AssignPictureBuffersTask().
Pawel Osciak 2013/09/30 05:16:25 Not anymore.
sheu 2013/10/04 23:25:56 Done.
1979 ScheduleDecodeBufferTaskIfNeeded(); 1614 ScheduleDecodeBufferTaskIfNeeded();
1980 } 1615 }
1981 1616
1982 void ExynosVideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) { 1617 void ExynosVideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) {
1983 DVLOG(3) << "DevicePollTask()"; 1618 DVLOG(3) << "DevicePollTask()";
1984 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); 1619 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current());
1985 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); 1620 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask");
1986 1621
1987 // This routine just polls the set of device fds, and schedules a 1622 // This routine just polls the set of device fds, and schedules a
1988 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. 1623 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur.
1989 // Other threads may notify this task to return early by writing to 1624 // Other threads may notify this task to return early by writing to
1990 // device_poll_interrupt_fd_. 1625 // device_poll_interrupt_fd_.
1991 struct pollfd pollfds[3]; 1626 struct pollfd pollfds[3];
1992 nfds_t nfds; 1627 nfds_t nfds;
1993 int mfc_pollfd = -1; 1628 int mfc_pollfd = -1;
1994 1629
1995 // Add device_poll_interrupt_fd_; 1630 // Add device_poll_interrupt_fd_;
1996 pollfds[0].fd = device_poll_interrupt_fd_; 1631 pollfds[0].fd = device_poll_interrupt_fd_;
1997 pollfds[0].events = POLLIN | POLLERR; 1632 pollfds[0].events = POLLIN | POLLERR;
1998 nfds = 1; 1633 nfds = 1;
1999 1634
2000 if (poll_fds & kPollMfc) { 1635 if (poll_fds & kPollMfc) {
2001 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set"; 1636 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set";
2002 pollfds[nfds].fd = mfc_fd_; 1637 pollfds[nfds].fd = mfc_fd_;
2003 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI; 1638 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI;
2004 mfc_pollfd = nfds; 1639 mfc_pollfd = nfds;
2005 nfds++; 1640 nfds++;
2006 } 1641 }
2007 // Add GSC fd, if we should poll on it.
2008 // GSC has to wait until both input and output buffers are queued.
2009 if (poll_fds & kPollGsc) {
2010 DVLOG(3) << "DevicePollTask(): adding GSC to poll() set";
2011 pollfds[nfds].fd = gsc_fd_;
2012 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR;
2013 nfds++;
2014 }
2015 1642
2016 // Poll it! 1643 // Poll it!
2017 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { 1644 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) {
2018 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; 1645 DPLOG(ERROR) << "DevicePollTask(): poll() failed";
2019 NOTIFY_ERROR(PLATFORM_FAILURE); 1646 NOTIFY_ERROR(PLATFORM_FAILURE);
2020 return; 1647 return;
2021 } 1648 }
2022 1649
2023 bool mfc_event_pending = (mfc_pollfd != -1 && 1650 bool mfc_event_pending = (mfc_pollfd != -1 &&
2024 pollfds[mfc_pollfd].revents & POLLPRI); 1651 pollfds[mfc_pollfd].revents & POLLPRI);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 1711
2085 bool ExynosVideoDecodeAccelerator::CreateBuffersForFormat( 1712 bool ExynosVideoDecodeAccelerator::CreateBuffersForFormat(
2086 const struct v4l2_format& format) { 1713 const struct v4l2_format& format) {
2087 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1714 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
2088 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); 1715 CHECK_EQ(format.fmt.pix_mp.num_planes, 2);
2089 frame_buffer_size_.SetSize( 1716 frame_buffer_size_.SetSize(
2090 format.fmt.pix_mp.width, format.fmt.pix_mp.height); 1717 format.fmt.pix_mp.width, format.fmt.pix_mp.height);
2091 mfc_output_buffer_size_[0] = format.fmt.pix_mp.plane_fmt[0].sizeimage; 1718 mfc_output_buffer_size_[0] = format.fmt.pix_mp.plane_fmt[0].sizeimage;
2092 mfc_output_buffer_size_[1] = format.fmt.pix_mp.plane_fmt[1].sizeimage; 1719 mfc_output_buffer_size_[1] = format.fmt.pix_mp.plane_fmt[1].sizeimage;
2093 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; 1720 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat;
2094 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12MT_16X16); 1721 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12M);
2095 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " 1722 DVLOG(3) << "CreateBuffersForFormat(): new resolution: "
2096 << frame_buffer_size_.ToString(); 1723 << frame_buffer_size_.ToString();
2097 1724
2098 if (!CreateMfcOutputBuffers() || !CreateGscInputBuffers() || 1725 if (!CreateMfcOutputBuffers())
2099 !CreateGscOutputBuffers())
2100 return false; 1726 return false;
2101 1727
2102 return true; 1728 return true;
2103 } 1729 }
2104 1730
2105 bool ExynosVideoDecodeAccelerator::CreateMfcInputBuffers() { 1731 bool ExynosVideoDecodeAccelerator::CreateMfcInputBuffers() {
2106 DVLOG(3) << "CreateMfcInputBuffers()"; 1732 DVLOG(3) << "CreateMfcInputBuffers()";
2107 // We always run this as we prepare to initialize. 1733 // We always run this as we prepare to initialize.
2108 DCHECK_EQ(decoder_state_, kUninitialized); 1734 DCHECK_EQ(decoder_state_, kUninitialized);
2109 DCHECK(!mfc_input_streamon_); 1735 DCHECK(!mfc_input_streamon_);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 // Output format setup in Initialize(). 1806 // Output format setup in Initialize().
2181 1807
2182 // Allocate the output buffers. 1808 // Allocate the output buffers.
2183 struct v4l2_requestbuffers reqbufs; 1809 struct v4l2_requestbuffers reqbufs;
2184 memset(&reqbufs, 0, sizeof(reqbufs)); 1810 memset(&reqbufs, 0, sizeof(reqbufs));
2185 reqbufs.count = mfc_output_dpb_size_ + kDpbOutputBufferExtraCount; 1811 reqbufs.count = mfc_output_dpb_size_ + kDpbOutputBufferExtraCount;
2186 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1812 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2187 reqbufs.memory = V4L2_MEMORY_MMAP; 1813 reqbufs.memory = V4L2_MEMORY_MMAP;
2188 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_REQBUFS, &reqbufs); 1814 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_REQBUFS, &reqbufs);
2189 1815
2190 // Fill our free-buffers list, and create DMABUFs from them. 1816 // Create DMABUFs from output buffers.
2191 mfc_output_buffer_map_.resize(reqbufs.count); 1817 mfc_output_buffer_map_.resize(reqbufs.count);
2192 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { 1818 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) {
2193 mfc_free_output_buffers_.push_back(i); 1819 MfcOutputRecord& output_record = mfc_output_buffer_map_[i];
2194 1820 for (size_t j = 0; j < arraysize(output_record.fds); ++j) {
2195 // Query for the MEMORY_MMAP pointer. 1821 // Export the DMABUF fd so we can export it as a texture.
2196 struct v4l2_plane planes[2]; 1822 struct v4l2_exportbuffer expbuf;
2197 struct v4l2_buffer buffer; 1823 memset(&expbuf, 0, sizeof(expbuf));
2198 memset(&buffer, 0, sizeof(buffer)); 1824 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2199 memset(planes, 0, sizeof(planes)); 1825 expbuf.index = i;
2200 buffer.index = i; 1826 expbuf.plane = j;
2201 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1827 expbuf.flags = O_CLOEXEC;
2202 buffer.memory = V4L2_MEMORY_MMAP; 1828 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_EXPBUF, &expbuf);
2203 buffer.m.planes = planes; 1829 output_record.fds[j] = expbuf.fd;
2204 buffer.length = 2;
2205 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QUERYBUF, &buffer);
2206
2207 // Get their user memory for GSC input.
2208 for (int j = 0; j < 2; ++j) {
2209 void* address = mmap(NULL, buffer.m.planes[j].length,
2210 PROT_READ | PROT_WRITE, MAP_SHARED, mfc_fd_,
2211 buffer.m.planes[j].m.mem_offset);
2212 if (address == MAP_FAILED) {
2213 DPLOG(ERROR) << "CreateMfcInputBuffers(): mmap() failed";
2214 return false;
2215 }
2216 mfc_output_buffer_map_[i].address[j] = address;
2217 mfc_output_buffer_map_[i].length[j] = buffer.m.planes[j].length;
2218 } 1830 }
2219 } 1831 }
2220 1832
2221 return true; 1833 DVLOG(3) << "CreateMfcOutputBuffers(): ProvidePictureBuffers(): "
2222 } 1834 << "buffer_count=" << mfc_output_buffer_map_.size()
2223 1835 << ", width=" << frame_buffer_size_.width()
2224 bool ExynosVideoDecodeAccelerator::CreateGscInputBuffers() { 1836 << ", height=" << frame_buffer_size_.height();
2225 DVLOG(3) << "CreateGscInputBuffers()"; 1837 child_message_loop_proxy_->PostTask(
2226 DCHECK(decoder_state_ == kInitialized || 1838 FROM_HERE,
2227 decoder_state_ == kChangingResolution); 1839 base::Bind(
2228 DCHECK(!gsc_input_streamon_); 1840 &Client::ProvidePictureBuffers,
2229 DCHECK(gsc_input_buffer_map_.empty()); 1841 client_,
2230 1842 mfc_output_buffer_map_.size(),
2231 struct v4l2_format format; 1843 gfx::Size(frame_buffer_size_.width(), frame_buffer_size_.height()),
2232 memset(&format, 0, sizeof(format)); 1844 GL_TEXTURE_EXTERNAL_OES));
2233 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
2234 format.fmt.pix_mp.width = frame_buffer_size_.width();
2235 format.fmt.pix_mp.height = frame_buffer_size_.height();
2236 format.fmt.pix_mp.pixelformat = mfc_output_buffer_pixelformat_;
2237 format.fmt.pix_mp.plane_fmt[0].sizeimage = mfc_output_buffer_size_[0];
2238 format.fmt.pix_mp.plane_fmt[1].sizeimage = mfc_output_buffer_size_[1];
2239 // NV12MT_16X16 is a tiled format for which bytesperline doesn't make too much
2240 // sense. Convention seems to be to assume 8bpp for these tiled formats.
2241 format.fmt.pix_mp.plane_fmt[0].bytesperline = frame_buffer_size_.width();
2242 format.fmt.pix_mp.plane_fmt[1].bytesperline = frame_buffer_size_.width();
2243 format.fmt.pix_mp.num_planes = 2;
2244 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_FMT, &format);
2245
2246 struct v4l2_control control;
2247 memset(&control, 0, sizeof(control));
2248 control.id = V4L2_CID_ROTATE;
2249 control.value = 0;
2250 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_CTRL, &control);
2251
2252 memset(&control, 0, sizeof(control));
2253 control.id = V4L2_CID_HFLIP;
2254 control.value = 0;
2255 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_CTRL, &control);
2256
2257 memset(&control, 0, sizeof(control));
2258 control.id = V4L2_CID_VFLIP;
2259 control.value = 0;
2260 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_CTRL, &control);
2261
2262 memset(&control, 0, sizeof(control));
2263 control.id = V4L2_CID_GLOBAL_ALPHA;
2264 control.value = 255;
2265 if (HANDLE_EINTR(ioctl(gsc_fd_, VIDIOC_S_CTRL, &control)) != 0) {
2266 memset(&control, 0, sizeof(control));
2267 control.id = V4L2_CID_ALPHA_COMPONENT;
2268 control.value = 255;
2269 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_CTRL, &control);
2270 }
2271
2272 struct v4l2_requestbuffers reqbufs;
2273 memset(&reqbufs, 0, sizeof(reqbufs));
2274 reqbufs.count = kGscInputBufferCount;
2275 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
2276 reqbufs.memory = V4L2_MEMORY_USERPTR;
2277 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_REQBUFS, &reqbufs);
2278
2279 gsc_input_buffer_map_.resize(reqbufs.count);
2280 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) {
2281 gsc_free_input_buffers_.push_back(i);
2282 gsc_input_buffer_map_[i].mfc_output = -1;
2283 }
2284 1845
2285 return true; 1846 return true;
2286 } 1847 }
2287
2288 bool ExynosVideoDecodeAccelerator::CreateGscOutputBuffers() {
2289 DVLOG(3) << "CreateGscOutputBuffers()";
2290 DCHECK(decoder_state_ == kInitialized ||
2291 decoder_state_ == kChangingResolution);
2292 DCHECK(!gsc_output_streamon_);
2293 DCHECK(gsc_output_buffer_map_.empty());
2294
2295 // GSC outputs into the EGLImages we create from the textures we are
2296 // assigned. Assume RGBA8888 format.
2297 struct v4l2_format format;
2298 memset(&format, 0, sizeof(format));
2299 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2300 format.fmt.pix_mp.width = frame_buffer_size_.width();
2301 format.fmt.pix_mp.height = frame_buffer_size_.height();
2302 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_RGB32;
2303 format.fmt.pix_mp.plane_fmt[0].sizeimage =
2304 frame_buffer_size_.width() * frame_buffer_size_.height() * 4;
2305 format.fmt.pix_mp.plane_fmt[0].bytesperline = frame_buffer_size_.width() * 4;
2306 format.fmt.pix_mp.num_planes = 1;
2307 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_S_FMT, &format);
2308
2309 struct v4l2_requestbuffers reqbufs;
2310 memset(&reqbufs, 0, sizeof(reqbufs));
2311 reqbufs.count = mfc_output_dpb_size_ + kDpbOutputBufferExtraCount;
2312 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2313 reqbufs.memory = V4L2_MEMORY_DMABUF;
2314 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_REQBUFS, &reqbufs);
2315
2316 // We don't actually fill in the freelist or the map here. That happens once
2317 // we have actual usable buffers, after AssignPictureBuffers();
2318 gsc_output_buffer_map_.resize(reqbufs.count);
2319
2320 DVLOG(3) << "CreateGscOutputBuffers(): ProvidePictureBuffers(): "
2321 << "buffer_count=" << gsc_output_buffer_map_.size()
2322 << ", width=" << frame_buffer_size_.width()
2323 << ", height=" << frame_buffer_size_.height();
2324 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
2325 &Client::ProvidePictureBuffers, client_, gsc_output_buffer_map_.size(),
2326 gfx::Size(frame_buffer_size_.width(), frame_buffer_size_.height()),
2327 GL_TEXTURE_2D));
2328
2329 return true;
2330 }
2331 1848
2332 void ExynosVideoDecodeAccelerator::DestroyMfcInputBuffers() { 1849 void ExynosVideoDecodeAccelerator::DestroyMfcInputBuffers() {
2333 DVLOG(3) << "DestroyMfcInputBuffers()"; 1850 DVLOG(3) << "DestroyMfcInputBuffers()";
2334 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 1851 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
2335 DCHECK(!mfc_input_streamon_); 1852 DCHECK(!mfc_input_streamon_);
2336 1853
2337 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { 1854 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) {
2338 if (mfc_input_buffer_map_[i].address != NULL) { 1855 if (mfc_input_buffer_map_[i].address != NULL) {
2339 munmap(mfc_input_buffer_map_[i].address, 1856 munmap(mfc_input_buffer_map_[i].address,
2340 mfc_input_buffer_map_[i].length); 1857 mfc_input_buffer_map_[i].length);
(...skipping 10 matching lines...) Expand all
2351 1868
2352 mfc_input_buffer_map_.clear(); 1869 mfc_input_buffer_map_.clear();
2353 mfc_free_input_buffers_.clear(); 1870 mfc_free_input_buffers_.clear();
2354 } 1871 }
2355 1872
2356 void ExynosVideoDecodeAccelerator::DestroyMfcOutputBuffers() { 1873 void ExynosVideoDecodeAccelerator::DestroyMfcOutputBuffers() {
2357 DVLOG(3) << "DestroyMfcOutputBuffers()"; 1874 DVLOG(3) << "DestroyMfcOutputBuffers()";
2358 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 1875 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
2359 DCHECK(!mfc_output_streamon_); 1876 DCHECK(!mfc_output_streamon_);
2360 1877
2361 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { 1878 if (mfc_output_buffer_map_.size() != 0) {
2362 if (mfc_output_buffer_map_[i].address[0] != NULL) 1879 if (!make_context_current_.Run()) {
2363 munmap(mfc_output_buffer_map_[i].address[0], 1880 DLOG(ERROR) << "DestroyMfcOutputBuffers(): "
2364 mfc_output_buffer_map_[i].length[0]); 1881 << "could not make context current";
2365 if (mfc_output_buffer_map_[i].address[1] != NULL) 1882 } else {
2366 munmap(mfc_output_buffer_map_[i].address[1], 1883 size_t i = 0;
2367 mfc_output_buffer_map_[i].length[1]); 1884 do {
1885 MfcOutputRecord& output_record = mfc_output_buffer_map_[i];
1886 for (size_t j = 0; j < arraysize(output_record.fds); ++j) {
1887 if (output_record.fds[j] != -1)
1888 HANDLE_EINTR(close(output_record.fds[j]));
1889 if (output_record.egl_image != EGL_NO_IMAGE_KHR)
1890 eglDestroyImageKHR(egl_display_, output_record.egl_image);
1891 if (output_record.egl_sync != EGL_NO_SYNC_KHR)
1892 eglDestroySyncKHR(egl_display_, output_record.egl_sync);
1893 }
1894 i++;
1895 } while (i < mfc_output_buffer_map_.size());
1896 }
2368 } 1897 }
2369 1898
2370 struct v4l2_requestbuffers reqbufs; 1899 struct v4l2_requestbuffers reqbufs;
2371 memset(&reqbufs, 0, sizeof(reqbufs)); 1900 memset(&reqbufs, 0, sizeof(reqbufs));
2372 reqbufs.count = 0; 1901 reqbufs.count = 0;
2373 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1902 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2374 reqbufs.memory = V4L2_MEMORY_MMAP; 1903 reqbufs.memory = V4L2_MEMORY_MMAP;
2375 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) 1904 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0)
2376 DPLOG(ERROR) << "DestroyMfcOutputBuffers() ioctl() failed: VIDIOC_REQBUFS"; 1905 DPLOG(ERROR) << "DestroyMfcOutputBuffers() ioctl() failed: VIDIOC_REQBUFS";
2377 1906
2378 mfc_output_buffer_map_.clear(); 1907 mfc_output_buffer_map_.clear();
2379 mfc_free_output_buffers_.clear(); 1908 mfc_free_output_buffers_.clear();
2380 } 1909 }
2381 1910
2382 void ExynosVideoDecodeAccelerator::DestroyGscInputBuffers() {
2383 DVLOG(3) << "DestroyGscInputBuffers()";
2384 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
2385 DCHECK(!gsc_input_streamon_);
2386
2387 struct v4l2_requestbuffers reqbufs;
2388 memset(&reqbufs, 0, sizeof(reqbufs));
2389 reqbufs.count = 0;
2390 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
2391 reqbufs.memory = V4L2_MEMORY_DMABUF;
2392 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0)
2393 DPLOG(ERROR) << "DestroyGscInputBuffers(): ioctl() failed: VIDIOC_REQBUFS";
2394
2395 gsc_input_buffer_map_.clear();
2396 gsc_free_input_buffers_.clear();
2397 }
2398
2399 void ExynosVideoDecodeAccelerator::DestroyGscOutputBuffers() {
2400 DVLOG(3) << "DestroyGscOutputBuffers()";
2401 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
2402 DCHECK(!gsc_output_streamon_);
2403
2404 if (gsc_output_buffer_map_.size() != 0) {
2405 if (!make_context_current_.Run())
2406 DLOG(ERROR) << "DestroyGscOutputBuffers(): "
2407 << "could not make context current";
2408
2409 size_t i = 0;
2410 do {
2411 GscOutputRecord& output_record = gsc_output_buffer_map_[i];
2412 if (output_record.fd != -1)
2413 HANDLE_EINTR(close(output_record.fd));
2414 if (output_record.egl_image != EGL_NO_IMAGE_KHR)
2415 eglDestroyImageKHR(egl_display_, output_record.egl_image);
2416 if (output_record.egl_sync != EGL_NO_SYNC_KHR)
2417 eglDestroySyncKHR(egl_display_, output_record.egl_sync);
2418 if (client_) {
2419 DVLOG(1) << "DestroyGscOutputBuffers(): "
2420 << "dismissing PictureBuffer id=" << output_record.picture_id;
2421 client_->DismissPictureBuffer(output_record.picture_id);
2422 }
2423 ++i;
2424 } while (i < gsc_output_buffer_map_.size());
2425 }
2426
2427 struct v4l2_requestbuffers reqbufs;
2428 memset(&reqbufs, 0, sizeof(reqbufs));
2429 reqbufs.count = 0;
2430 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2431 reqbufs.memory = V4L2_MEMORY_DMABUF;
2432 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0)
2433 DPLOG(ERROR) << "DestroyGscOutputBuffers(): ioctl() failed: VIDIOC_REQBUFS";
2434
2435 gsc_output_buffer_map_.clear();
2436 gsc_free_output_buffers_.clear();
2437 }
2438
2439 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { 1911 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() {
2440 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); 1912 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
2441 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; 1913 DVLOG(3) << "ResolutionChangeDestroyBuffers()";
2442 1914
2443 DestroyGscInputBuffers();
2444 DestroyGscOutputBuffers();
2445 DestroyMfcOutputBuffers(); 1915 DestroyMfcOutputBuffers();
2446 1916
2447 // Finish resolution change on decoder thread. 1917 // Finish resolution change on decoder thread.
2448 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 1918 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
2449 &ExynosVideoDecodeAccelerator::FinishResolutionChange, 1919 &ExynosVideoDecodeAccelerator::FinishResolutionChange,
2450 base::Unretained(this))); 1920 base::Unretained(this)));
2451 } 1921 }
2452 1922
2453 } // namespace content 1923 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698