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 <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <poll.h> | 9 #include <poll.h> |
10 #include <sys/eventfd.h> | 10 #include <sys/eventfd.h> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 std::vector<PictureBufferRef> picture_buffers; | 97 std::vector<PictureBufferRef> picture_buffers; |
98 }; | 98 }; |
99 | 99 |
100 struct ExynosVideoDecodeAccelerator::EGLSyncKHRRef { | 100 struct ExynosVideoDecodeAccelerator::EGLSyncKHRRef { |
101 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync); | 101 EGLSyncKHRRef(EGLDisplay egl_display, EGLSyncKHR egl_sync); |
102 ~EGLSyncKHRRef(); | 102 ~EGLSyncKHRRef(); |
103 EGLDisplay const egl_display; | 103 EGLDisplay const egl_display; |
104 EGLSyncKHR egl_sync; | 104 EGLSyncKHR egl_sync; |
105 }; | 105 }; |
106 | 106 |
| 107 struct ExynosVideoDecodeAccelerator::PictureRecord { |
| 108 PictureRecord(bool cleared, const media::Picture& picture); |
| 109 ~PictureRecord(); |
| 110 bool cleared; // whether the texture has been cleared |
| 111 media::Picture picture; // the decoded picture |
| 112 }; |
| 113 |
107 ExynosVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( | 114 ExynosVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( |
108 base::WeakPtr<Client>& client, | 115 base::WeakPtr<Client>& client, |
109 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, | 116 scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, |
110 base::SharedMemory* shm, size_t size, int32 input_id) | 117 base::SharedMemory* shm, size_t size, int32 input_id) |
111 : client(client), | 118 : client(client), |
112 client_message_loop_proxy(client_message_loop_proxy), | 119 client_message_loop_proxy(client_message_loop_proxy), |
113 shm(shm), | 120 shm(shm), |
114 size(size), | 121 size(size), |
115 bytes_used(0), | 122 bytes_used(0), |
116 input_id(input_id) { | 123 input_id(input_id) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 195 |
189 ExynosVideoDecodeAccelerator::GscInputRecord::~GscInputRecord() { | 196 ExynosVideoDecodeAccelerator::GscInputRecord::~GscInputRecord() { |
190 } | 197 } |
191 | 198 |
192 ExynosVideoDecodeAccelerator::GscOutputRecord::GscOutputRecord() | 199 ExynosVideoDecodeAccelerator::GscOutputRecord::GscOutputRecord() |
193 : at_device(false), | 200 : at_device(false), |
194 at_client(false), | 201 at_client(false), |
195 fd(-1), | 202 fd(-1), |
196 egl_image(EGL_NO_IMAGE_KHR), | 203 egl_image(EGL_NO_IMAGE_KHR), |
197 egl_sync(EGL_NO_SYNC_KHR), | 204 egl_sync(EGL_NO_SYNC_KHR), |
198 picture_id(-1) { | 205 picture_id(-1), |
| 206 cleared(false) {} |
| 207 |
| 208 ExynosVideoDecodeAccelerator::GscOutputRecord::~GscOutputRecord() { |
199 } | 209 } |
200 | 210 |
201 ExynosVideoDecodeAccelerator::GscOutputRecord::~GscOutputRecord() { | 211 ExynosVideoDecodeAccelerator::PictureRecord::PictureRecord( |
| 212 bool cleared, const media::Picture& picture) |
| 213 : cleared(cleared), picture(picture) { |
| 214 } |
| 215 |
| 216 ExynosVideoDecodeAccelerator::PictureRecord::~PictureRecord() { |
202 } | 217 } |
203 | 218 |
204 ExynosVideoDecodeAccelerator::ExynosVideoDecodeAccelerator( | 219 ExynosVideoDecodeAccelerator::ExynosVideoDecodeAccelerator( |
205 EGLDisplay egl_display, | 220 EGLDisplay egl_display, |
206 EGLContext egl_context, | 221 EGLContext egl_context, |
207 Client* client, | 222 Client* client, |
208 const base::WeakPtr<Client>& io_client, | 223 const base::WeakPtr<Client>& io_client, |
209 const base::Callback<bool(void)>& make_context_current, | 224 const base::Callback<bool(void)>& make_context_current, |
210 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) | 225 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) |
211 : child_message_loop_proxy_(base::MessageLoopProxy::current()), | 226 : child_message_loop_proxy_(base::MessageLoopProxy::current()), |
(...skipping 17 matching lines...) Expand all Loading... |
229 mfc_input_buffer_queued_count_(0), | 244 mfc_input_buffer_queued_count_(0), |
230 mfc_output_streamon_(false), | 245 mfc_output_streamon_(false), |
231 mfc_output_buffer_queued_count_(0), | 246 mfc_output_buffer_queued_count_(0), |
232 mfc_output_buffer_pixelformat_(0), | 247 mfc_output_buffer_pixelformat_(0), |
233 mfc_output_dpb_size_(0), | 248 mfc_output_dpb_size_(0), |
234 gsc_fd_(-1), | 249 gsc_fd_(-1), |
235 gsc_input_streamon_(false), | 250 gsc_input_streamon_(false), |
236 gsc_input_buffer_queued_count_(0), | 251 gsc_input_buffer_queued_count_(0), |
237 gsc_output_streamon_(false), | 252 gsc_output_streamon_(false), |
238 gsc_output_buffer_queued_count_(0), | 253 gsc_output_buffer_queued_count_(0), |
| 254 picture_clearing_count_(0), |
239 device_poll_thread_("ExynosDevicePollThread"), | 255 device_poll_thread_("ExynosDevicePollThread"), |
240 device_poll_interrupt_fd_(-1), | 256 device_poll_interrupt_fd_(-1), |
241 make_context_current_(make_context_current), | 257 make_context_current_(make_context_current), |
242 egl_display_(egl_display), | 258 egl_display_(egl_display), |
243 egl_context_(egl_context), | 259 egl_context_(egl_context), |
244 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {} | 260 video_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN) {} |
245 | 261 |
246 ExynosVideoDecodeAccelerator::~ExynosVideoDecodeAccelerator() { | 262 ExynosVideoDecodeAccelerator::~ExynosVideoDecodeAccelerator() { |
247 DCHECK(!decoder_thread_.IsRunning()); | 263 DCHECK(!decoder_thread_.IsRunning()); |
248 DCHECK(!device_poll_thread_.IsRunning()); | 264 DCHECK(!device_poll_thread_.IsRunning()); |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 } | 1061 } |
1046 | 1062 |
1047 DCHECK_EQ(pic_buffers->picture_buffers.size(), gsc_output_buffer_map_.size()); | 1063 DCHECK_EQ(pic_buffers->picture_buffers.size(), gsc_output_buffer_map_.size()); |
1048 for (size_t i = 0; i < gsc_output_buffer_map_.size(); ++i) { | 1064 for (size_t i = 0; i < gsc_output_buffer_map_.size(); ++i) { |
1049 // We should be blank right now. | 1065 // We should be blank right now. |
1050 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; | 1066 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; |
1051 DCHECK_EQ(output_record.fd, -1); | 1067 DCHECK_EQ(output_record.fd, -1); |
1052 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR); | 1068 DCHECK_EQ(output_record.egl_image, EGL_NO_IMAGE_KHR); |
1053 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); | 1069 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); |
1054 DCHECK_EQ(output_record.picture_id, -1); | 1070 DCHECK_EQ(output_record.picture_id, -1); |
| 1071 DCHECK_EQ(output_record.cleared, false); |
1055 PictureBufferArrayRef::PictureBufferRef& buffer = | 1072 PictureBufferArrayRef::PictureBufferRef& buffer = |
1056 pic_buffers->picture_buffers[i]; | 1073 pic_buffers->picture_buffers[i]; |
1057 output_record.fd = buffer.egl_image_fd; | 1074 output_record.fd = buffer.egl_image_fd; |
1058 output_record.egl_image = buffer.egl_image; | 1075 output_record.egl_image = buffer.egl_image; |
1059 output_record.picture_id = buffer.client_id; | 1076 output_record.picture_id = buffer.client_id; |
1060 | 1077 |
1061 // Take ownership of the EGLImage and fd. | 1078 // Take ownership of the EGLImage and fd. |
1062 buffer.egl_image = EGL_NO_IMAGE_KHR; | 1079 buffer.egl_image = EGL_NO_IMAGE_KHR; |
1063 buffer.egl_image_fd = -1; | 1080 buffer.egl_image_fd = -1; |
1064 // And add this buffer to the free list. | 1081 // And add this buffer to the free list. |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 } | 1425 } |
1409 GscOutputRecord& output_record = gsc_output_buffer_map_[dqbuf.index]; | 1426 GscOutputRecord& output_record = gsc_output_buffer_map_[dqbuf.index]; |
1410 DCHECK(output_record.at_device); | 1427 DCHECK(output_record.at_device); |
1411 DCHECK(!output_record.at_client); | 1428 DCHECK(!output_record.at_client); |
1412 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); | 1429 DCHECK_EQ(output_record.egl_sync, EGL_NO_SYNC_KHR); |
1413 output_record.at_device = false; | 1430 output_record.at_device = false; |
1414 output_record.at_client = true; | 1431 output_record.at_client = true; |
1415 gsc_output_buffer_queued_count_--; | 1432 gsc_output_buffer_queued_count_--; |
1416 DVLOG(3) << "DequeueGsc(): returning input_id=" << dqbuf.timestamp.tv_sec | 1433 DVLOG(3) << "DequeueGsc(): returning input_id=" << dqbuf.timestamp.tv_sec |
1417 << " as picture_id=" << output_record.picture_id; | 1434 << " as picture_id=" << output_record.picture_id; |
1418 io_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1435 const media::Picture& picture = |
1419 &Client::PictureReady, io_client_, media::Picture( | 1436 media::Picture(output_record.picture_id, dqbuf.timestamp.tv_sec); |
1420 output_record.picture_id, dqbuf.timestamp.tv_sec))); | 1437 pending_picture_ready_.push(PictureRecord(output_record.cleared, picture)); |
| 1438 SendPictureReady(); |
| 1439 output_record.cleared = true; |
1421 decoder_frames_at_client_++; | 1440 decoder_frames_at_client_++; |
1422 } | 1441 } |
1423 | 1442 |
1424 NotifyFlushDoneIfNeeded(); | 1443 NotifyFlushDoneIfNeeded(); |
1425 } | 1444 } |
1426 | 1445 |
1427 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() { | 1446 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() { |
1428 DVLOG(3) << "EnqueueMfcInputRecord()"; | 1447 DVLOG(3) << "EnqueueMfcInputRecord()"; |
1429 DCHECK(!mfc_input_ready_queue_.empty()); | 1448 DCHECK(!mfc_input_ready_queue_.empty()); |
1430 | 1449 |
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 DestroyGscInputBuffers(); | 2462 DestroyGscInputBuffers(); |
2444 DestroyGscOutputBuffers(); | 2463 DestroyGscOutputBuffers(); |
2445 DestroyMfcOutputBuffers(); | 2464 DestroyMfcOutputBuffers(); |
2446 | 2465 |
2447 // Finish resolution change on decoder thread. | 2466 // Finish resolution change on decoder thread. |
2448 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 2467 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
2449 &ExynosVideoDecodeAccelerator::FinishResolutionChange, | 2468 &ExynosVideoDecodeAccelerator::FinishResolutionChange, |
2450 base::Unretained(this))); | 2469 base::Unretained(this))); |
2451 } | 2470 } |
2452 | 2471 |
| 2472 void ExynosVideoDecodeAccelerator::SendPictureReady() { |
| 2473 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
| 2474 while (pending_picture_ready_.size() > 0) { |
| 2475 const media::Picture& picture = pending_picture_ready_.front().picture; |
| 2476 if (!pending_picture_ready_.front().cleared) { |
| 2477 // If the picture is not cleared, post it to the child thread because it |
| 2478 // has to be cleared in the child thread. |
| 2479 child_message_loop_proxy_->PostTaskAndReply( |
| 2480 FROM_HERE, |
| 2481 base::Bind(&Client::PictureReady, client_, picture), |
| 2482 base::Bind(&ExynosVideoDecodeAccelerator::PictureCleared, |
| 2483 weak_this_)); |
| 2484 picture_clearing_count_++; |
| 2485 pending_picture_ready_.pop(); |
| 2486 } else if (picture_clearing_count_ == 0) { |
| 2487 // This picture is cleared. Post it to IO thread to reduce latency. |
| 2488 io_message_loop_proxy_->PostTask( |
| 2489 FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); |
| 2490 pending_picture_ready_.pop(); |
| 2491 } else { |
| 2492 // This picture is cleared. But some pictures are about to be cleared on |
| 2493 // the child thread. To preserve the order, do not send this until those |
| 2494 // pictures are cleared. |
| 2495 break; |
| 2496 } |
| 2497 } |
| 2498 } |
| 2499 |
| 2500 void ExynosVideoDecodeAccelerator::PictureCleared() { |
| 2501 DVLOG(3) << "PictureCleared()"; |
| 2502 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
| 2503 DCHECK_GT(picture_clearing_count_, 0); |
| 2504 picture_clearing_count_--; |
| 2505 SendPictureReady(); |
| 2506 } |
| 2507 |
2453 } // namespace content | 2508 } // namespace content |
OLD | NEW |