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