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 20 matching lines...) Expand all Loading... | |
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 kExynosMfcDevice[] = "/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::MfcInputRecord::MfcInputRecord() |
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::MfcInputRecord::~MfcInputRecord() { |
159 } | 159 } |
160 | 160 |
161 ExynosVideoDecodeAccelerator::MfcOutputRecord::MfcOutputRecord() | 161 V4l2VideoDecodeAccelerator::MfcOutputRecord::MfcOutputRecord() |
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::MfcOutputRecord::~MfcOutputRecord() {} |
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_("ExynosDecoderThread"), |
Pawel Osciak
2014/01/07 04:16:27
s/ExynosDecoderThread/DecoderThread/
shivdasp
2014/01/07 04:31:14
Done.
| |
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 mfc_fd_(-1), |
204 mfc_input_streamon_(false), | 204 mfc_input_streamon_(false), |
205 mfc_input_buffer_queued_count_(0), | 205 mfc_input_buffer_queued_count_(0), |
206 mfc_output_streamon_(false), | 206 mfc_output_streamon_(false), |
207 mfc_output_buffer_queued_count_(0), | 207 mfc_output_buffer_queued_count_(0), |
208 mfc_output_buffer_pixelformat_(0), | 208 mfc_output_buffer_pixelformat_(0), |
209 mfc_output_dpb_size_(0), | 209 mfc_output_dpb_size_(0), |
210 picture_clearing_count_(0), | 210 picture_clearing_count_(0), |
211 device_poll_thread_("ExynosDevicePollThread"), | 211 device_poll_thread_("ExynosDevicePollThread"), |
Pawel Osciak
2014/01/07 04:16:27
DevicePollThread
shivdasp
2014/01/07 04:31:14
Done.
| |
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 (mfc_fd_ != -1) { |
226 DestroyMfcInputBuffers(); | 226 DestroyMfcInputBuffers(); |
227 DestroyMfcOutputBuffers(); | 227 DestroyMfcOutputBuffers(); |
228 close(mfc_fd_); | 228 close(mfc_fd_); |
229 mfc_fd_ = -1; | 229 mfc_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(mfc_input_buffer_map_.empty()); |
235 DCHECK(mfc_output_buffer_map_.empty()); | 235 DCHECK(mfc_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 28 matching lines...) Expand all Loading... | |
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 MFC device: " << kExynosMfcDevice; |
284 mfc_fd_ = HANDLE_EINTR(open(kExynosMfcDevice, | 284 mfc_fd_ = HANDLE_EINTR(open(kExynosMfcDevice, |
285 O_RDWR | O_NONBLOCK | O_CLOEXEC)); | 285 O_RDWR | O_NONBLOCK | O_CLOEXEC)); |
286 if (mfc_fd_ == -1) { | 286 if (mfc_fd_ == -1) { |
287 DPLOG(ERROR) << "Initialize(): could not open MFC device: " | 287 DPLOG(ERROR) << "Initialize(): could not open MFC device: " |
Pawel Osciak
2014/01/07 04:16:27
MFC -> decoder
| |
288 << kExynosMfcDevice; | 288 << kExynosMfcDevice; |
289 NOTIFY_ERROR(PLATFORM_FAILURE); | 289 NOTIFY_ERROR(PLATFORM_FAILURE); |
290 return false; | 290 return false; |
291 } | 291 } |
292 | 292 |
293 // Create the interrupt fd. | 293 // Create the interrupt fd. |
294 DCHECK_EQ(device_poll_interrupt_fd_, -1); | 294 DCHECK_EQ(device_poll_interrupt_fd_, -1); |
295 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 295 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
296 if (device_poll_interrupt_fd_ == -1) { | 296 if (device_poll_interrupt_fd_ == -1) { |
297 DPLOG(ERROR) << "Initialize(): eventfd() failed"; | 297 DPLOG(ERROR) << "Initialize(): eventfd() failed"; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 return false; | 341 return false; |
342 } | 342 } |
343 | 343 |
344 SetDecoderState(kInitialized); | 344 SetDecoderState(kInitialized); |
345 | 345 |
346 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 346 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
347 &Client::NotifyInitializeDone, client_)); | 347 &Client::NotifyInitializeDone, client_)); |
348 return true; | 348 return true; |
349 } | 349 } |
350 | 350 |
351 void ExynosVideoDecodeAccelerator::Decode( | 351 void V4l2VideoDecodeAccelerator::Decode( |
352 const media::BitstreamBuffer& bitstream_buffer) { | 352 const media::BitstreamBuffer& bitstream_buffer) { |
353 DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id() | 353 DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id() |
354 << ", size=" << bitstream_buffer.size(); | 354 << ", size=" << bitstream_buffer.size(); |
355 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 355 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
356 | 356 |
357 // DecodeTask() will take care of running a DecodeBufferTask(). | 357 // DecodeTask() will take care of running a DecodeBufferTask(). |
358 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 358 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
359 &ExynosVideoDecodeAccelerator::DecodeTask, base::Unretained(this), | 359 &V4l2VideoDecodeAccelerator::DecodeTask, base::Unretained(this), |
360 bitstream_buffer)); | 360 bitstream_buffer)); |
361 } | 361 } |
362 | 362 |
363 void ExynosVideoDecodeAccelerator::AssignPictureBuffers( | 363 void V4l2VideoDecodeAccelerator::AssignPictureBuffers( |
364 const std::vector<media::PictureBuffer>& buffers) { | 364 const std::vector<media::PictureBuffer>& buffers) { |
365 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); | 365 DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); |
366 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 366 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
367 | 367 |
368 if (buffers.size() != mfc_output_buffer_map_.size()) { | 368 if (buffers.size() != mfc_output_buffer_map_.size()) { |
369 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" | 369 DLOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" |
370 " buffers. (Got " << buffers.size() | 370 " buffers. (Got " << buffers.size() |
371 << ", requested " << mfc_output_buffer_map_.size() << ")"; | 371 << ", requested " << mfc_output_buffer_map_.size() << ")"; |
372 NOTIFY_ERROR(INVALID_ARGUMENT); | 372 NOTIFY_ERROR(INVALID_ARGUMENT); |
373 return; | 373 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 return; | 408 return; |
409 } | 409 } |
410 | 410 |
411 glBindTexture(GL_TEXTURE_EXTERNAL_OES, buffers[i].texture_id()); | 411 glBindTexture(GL_TEXTURE_EXTERNAL_OES, buffers[i].texture_id()); |
412 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | 412 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
413 picture_buffers_ref->picture_buffers.push_back( | 413 picture_buffers_ref->picture_buffers.push_back( |
414 PictureBufferArrayRef::PictureBufferRef(egl_image, buffers[i].id())); | 414 PictureBufferArrayRef::PictureBufferRef(egl_image, buffers[i].id())); |
415 } | 415 } |
416 decoder_thread_.message_loop()->PostTask( | 416 decoder_thread_.message_loop()->PostTask( |
417 FROM_HERE, | 417 FROM_HERE, |
418 base::Bind(&ExynosVideoDecodeAccelerator::AssignPictureBuffersTask, | 418 base::Bind(&V4l2VideoDecodeAccelerator::AssignPictureBuffersTask, |
419 base::Unretained(this), | 419 base::Unretained(this), |
420 base::Passed(&picture_buffers_ref))); | 420 base::Passed(&picture_buffers_ref))); |
421 } | 421 } |
422 | 422 |
423 void ExynosVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { | 423 void V4l2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { |
424 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; | 424 DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; |
425 // Must be run on child thread, as we'll insert a sync in the EGL context. | 425 // Must be run on child thread, as we'll insert a sync in the EGL context. |
426 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 426 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
427 | 427 |
428 if (!make_context_current_.Run()) { | 428 if (!make_context_current_.Run()) { |
429 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current"; | 429 DLOG(ERROR) << "ReusePictureBuffer(): could not make context current"; |
430 NOTIFY_ERROR(PLATFORM_FAILURE); | 430 NOTIFY_ERROR(PLATFORM_FAILURE); |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 EGLSyncKHR egl_sync = | 434 EGLSyncKHR egl_sync = |
435 eglCreateSyncKHR(egl_display_, EGL_SYNC_FENCE_KHR, NULL); | 435 eglCreateSyncKHR(egl_display_, EGL_SYNC_FENCE_KHR, NULL); |
436 if (egl_sync == EGL_NO_SYNC_KHR) { | 436 if (egl_sync == EGL_NO_SYNC_KHR) { |
437 DLOG(ERROR) << "ReusePictureBuffer(): eglCreateSyncKHR() failed"; | 437 DLOG(ERROR) << "ReusePictureBuffer(): eglCreateSyncKHR() failed"; |
438 NOTIFY_ERROR(PLATFORM_FAILURE); | 438 NOTIFY_ERROR(PLATFORM_FAILURE); |
439 return; | 439 return; |
440 } | 440 } |
441 | 441 |
442 scoped_ptr<EGLSyncKHRRef> egl_sync_ref(new EGLSyncKHRRef( | 442 scoped_ptr<EGLSyncKHRRef> egl_sync_ref(new EGLSyncKHRRef( |
443 egl_display_, egl_sync)); | 443 egl_display_, egl_sync)); |
444 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 444 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
445 &ExynosVideoDecodeAccelerator::ReusePictureBufferTask, | 445 &V4l2VideoDecodeAccelerator::ReusePictureBufferTask, |
446 base::Unretained(this), picture_buffer_id, base::Passed(&egl_sync_ref))); | 446 base::Unretained(this), picture_buffer_id, base::Passed(&egl_sync_ref))); |
447 } | 447 } |
448 | 448 |
449 void ExynosVideoDecodeAccelerator::Flush() { | 449 void V4l2VideoDecodeAccelerator::Flush() { |
450 DVLOG(3) << "Flush()"; | 450 DVLOG(3) << "Flush()"; |
451 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 451 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
452 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 452 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
453 &ExynosVideoDecodeAccelerator::FlushTask, base::Unretained(this))); | 453 &V4l2VideoDecodeAccelerator::FlushTask, base::Unretained(this))); |
454 } | 454 } |
455 | 455 |
456 void ExynosVideoDecodeAccelerator::Reset() { | 456 void V4l2VideoDecodeAccelerator::Reset() { |
457 DVLOG(3) << "Reset()"; | 457 DVLOG(3) << "Reset()"; |
458 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 458 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
459 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 459 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
460 &ExynosVideoDecodeAccelerator::ResetTask, base::Unretained(this))); | 460 &V4l2VideoDecodeAccelerator::ResetTask, base::Unretained(this))); |
461 } | 461 } |
462 | 462 |
463 void ExynosVideoDecodeAccelerator::Destroy() { | 463 void V4l2VideoDecodeAccelerator::Destroy() { |
464 DVLOG(3) << "Destroy()"; | 464 DVLOG(3) << "Destroy()"; |
465 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 465 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
466 | 466 |
467 // We're destroying; cancel all callbacks. | 467 // We're destroying; cancel all callbacks. |
468 client_ptr_factory_.InvalidateWeakPtrs(); | 468 client_ptr_factory_.InvalidateWeakPtrs(); |
469 | 469 |
470 // If the decoder thread is running, destroy using posted task. | 470 // If the decoder thread is running, destroy using posted task. |
471 if (decoder_thread_.IsRunning()) { | 471 if (decoder_thread_.IsRunning()) { |
472 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 472 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
473 &ExynosVideoDecodeAccelerator::DestroyTask, base::Unretained(this))); | 473 &V4l2VideoDecodeAccelerator::DestroyTask, base::Unretained(this))); |
474 // DestroyTask() will cause the decoder_thread_ to flush all tasks. | 474 // DestroyTask() will cause the decoder_thread_ to flush all tasks. |
475 decoder_thread_.Stop(); | 475 decoder_thread_.Stop(); |
476 } else { | 476 } else { |
477 // Otherwise, call the destroy task directly. | 477 // Otherwise, call the destroy task directly. |
478 DestroyTask(); | 478 DestroyTask(); |
479 } | 479 } |
480 | 480 |
481 // Set to kError state just in case. | 481 // Set to kError state just in case. |
482 SetDecoderState(kError); | 482 SetDecoderState(kError); |
483 | 483 |
484 delete this; | 484 delete this; |
485 } | 485 } |
486 | 486 |
487 bool ExynosVideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } | 487 bool V4l2VideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } |
488 | 488 |
489 void ExynosVideoDecodeAccelerator::DecodeTask( | 489 void V4l2VideoDecodeAccelerator::DecodeTask( |
490 const media::BitstreamBuffer& bitstream_buffer) { | 490 const media::BitstreamBuffer& bitstream_buffer) { |
491 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); | 491 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); |
492 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 492 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
493 DCHECK_NE(decoder_state_, kUninitialized); | 493 DCHECK_NE(decoder_state_, kUninitialized); |
494 TRACE_EVENT1("Video Decoder", "EVDA::DecodeTask", "input_id", | 494 TRACE_EVENT1("Video Decoder", "EVDA::DecodeTask", "input_id", |
495 bitstream_buffer.id()); | 495 bitstream_buffer.id()); |
496 | 496 |
497 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( | 497 scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( |
498 io_client_, io_message_loop_proxy_, | 498 io_client_, io_message_loop_proxy_, |
499 new base::SharedMemory(bitstream_buffer.handle(), true), | 499 new base::SharedMemory(bitstream_buffer.handle(), true), |
(...skipping 17 matching lines...) Expand all Loading... | |
517 DVLOG(2) << "DecodeTask(): early out: kError state"; | 517 DVLOG(2) << "DecodeTask(): early out: kError state"; |
518 return; | 518 return; |
519 } | 519 } |
520 | 520 |
521 decoder_input_queue_.push( | 521 decoder_input_queue_.push( |
522 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); | 522 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); |
523 decoder_decode_buffer_tasks_scheduled_++; | 523 decoder_decode_buffer_tasks_scheduled_++; |
524 DecodeBufferTask(); | 524 DecodeBufferTask(); |
525 } | 525 } |
526 | 526 |
527 void ExynosVideoDecodeAccelerator::DecodeBufferTask() { | 527 void V4l2VideoDecodeAccelerator::DecodeBufferTask() { |
528 DVLOG(3) << "DecodeBufferTask()"; | 528 DVLOG(3) << "DecodeBufferTask()"; |
529 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 529 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
530 DCHECK_NE(decoder_state_, kUninitialized); | 530 DCHECK_NE(decoder_state_, kUninitialized); |
531 TRACE_EVENT0("Video Decoder", "EVDA::DecodeBufferTask"); | 531 TRACE_EVENT0("Video Decoder", "EVDA::DecodeBufferTask"); |
532 | 532 |
533 decoder_decode_buffer_tasks_scheduled_--; | 533 decoder_decode_buffer_tasks_scheduled_--; |
534 | 534 |
535 if (decoder_state_ == kResetting) { | 535 if (decoder_state_ == kResetting) { |
536 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; | 536 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; |
537 return; | 537 return; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 // Our current bitstream buffer is done; return it. | 638 // Our current bitstream buffer is done; return it. |
639 int32 input_id = decoder_current_bitstream_buffer_->input_id; | 639 int32 input_id = decoder_current_bitstream_buffer_->input_id; |
640 DVLOG(3) << "DecodeBufferTask(): finished input_id=" << input_id; | 640 DVLOG(3) << "DecodeBufferTask(): finished input_id=" << input_id; |
641 // BitstreamBufferRef destructor calls NotifyEndOfBitstreamBuffer(). | 641 // BitstreamBufferRef destructor calls NotifyEndOfBitstreamBuffer(). |
642 decoder_current_bitstream_buffer_.reset(); | 642 decoder_current_bitstream_buffer_.reset(); |
643 } | 643 } |
644 ScheduleDecodeBufferTaskIfNeeded(); | 644 ScheduleDecodeBufferTaskIfNeeded(); |
645 } | 645 } |
646 } | 646 } |
647 | 647 |
648 bool ExynosVideoDecodeAccelerator::AdvanceFrameFragment( | 648 bool V4l2VideoDecodeAccelerator::AdvanceFrameFragment( |
649 const uint8* data, | 649 const uint8* data, |
650 size_t size, | 650 size_t size, |
651 size_t* endpos) { | 651 size_t* endpos) { |
652 if (video_profile_ >= media::H264PROFILE_MIN && | 652 if (video_profile_ >= media::H264PROFILE_MIN && |
653 video_profile_ <= media::H264PROFILE_MAX) { | 653 video_profile_ <= media::H264PROFILE_MAX) { |
654 // For H264, we need to feed HW one frame at a time. This is going to take | 654 // For H264, we need to feed HW one frame at a time. This is going to take |
655 // some parsing of our input stream. | 655 // some parsing of our input stream. |
656 decoder_h264_parser_->SetStream(data, size); | 656 decoder_h264_parser_->SetStream(data, size); |
657 content::H264NALU nalu; | 657 content::H264NALU nalu; |
658 content::H264Parser::Result result; | 658 content::H264Parser::Result result; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 DCHECK_GE(video_profile_, media::VP8PROFILE_MIN); | 718 DCHECK_GE(video_profile_, media::VP8PROFILE_MIN); |
719 DCHECK_LE(video_profile_, media::VP8PROFILE_MAX); | 719 DCHECK_LE(video_profile_, media::VP8PROFILE_MAX); |
720 // For VP8, we can just dump the entire buffer. No fragmentation needed, | 720 // For VP8, we can just dump the entire buffer. No fragmentation needed, |
721 // and we never return a partial frame. | 721 // and we never return a partial frame. |
722 *endpos = size; | 722 *endpos = size; |
723 decoder_partial_frame_pending_ = false; | 723 decoder_partial_frame_pending_ = false; |
724 return true; | 724 return true; |
725 } | 725 } |
726 } | 726 } |
727 | 727 |
728 void ExynosVideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { | 728 void V4l2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { |
729 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 729 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
730 | 730 |
731 // If we're behind on tasks, schedule another one. | 731 // If we're behind on tasks, schedule another one. |
732 int buffers_to_decode = decoder_input_queue_.size(); | 732 int buffers_to_decode = decoder_input_queue_.size(); |
733 if (decoder_current_bitstream_buffer_ != NULL) | 733 if (decoder_current_bitstream_buffer_ != NULL) |
734 buffers_to_decode++; | 734 buffers_to_decode++; |
735 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { | 735 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { |
736 decoder_decode_buffer_tasks_scheduled_++; | 736 decoder_decode_buffer_tasks_scheduled_++; |
737 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 737 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
738 &ExynosVideoDecodeAccelerator::DecodeBufferTask, | 738 &V4l2VideoDecodeAccelerator::DecodeBufferTask, |
739 base::Unretained(this))); | 739 base::Unretained(this))); |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial( | 743 bool V4l2VideoDecodeAccelerator::DecodeBufferInitial( |
744 const void* data, size_t size, size_t* endpos) { | 744 const void* data, size_t size, size_t* endpos) { |
745 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; | 745 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; |
746 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 746 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
747 DCHECK_NE(decoder_state_, kUninitialized); | 747 DCHECK_NE(decoder_state_, kUninitialized); |
748 DCHECK_NE(decoder_state_, kDecoding); | 748 DCHECK_NE(decoder_state_, kDecoding); |
749 DCHECK(!device_poll_thread_.IsRunning()); | 749 DCHECK(!device_poll_thread_.IsRunning()); |
750 // Initial decode. We haven't been able to get output stream format info yet. | 750 // Initial decode. We haven't been able to get output stream format info yet. |
751 // Get it, and start decoding. | 751 // Get it, and start decoding. |
752 | 752 |
753 // Copy in and send to HW. | 753 // Copy in and send to HW. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 | 794 |
795 // StartDevicePoll will raise the error if there is one. | 795 // StartDevicePoll will raise the error if there is one. |
796 if (!StartDevicePoll()) | 796 if (!StartDevicePoll()) |
797 return false; | 797 return false; |
798 | 798 |
799 decoder_state_ = kDecoding; | 799 decoder_state_ = kDecoding; |
800 ScheduleDecodeBufferTaskIfNeeded(); | 800 ScheduleDecodeBufferTaskIfNeeded(); |
801 return true; | 801 return true; |
802 } | 802 } |
803 | 803 |
804 bool ExynosVideoDecodeAccelerator::DecodeBufferContinue( | 804 bool V4l2VideoDecodeAccelerator::DecodeBufferContinue( |
805 const void* data, size_t size) { | 805 const void* data, size_t size) { |
806 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size; | 806 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size; |
807 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 807 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
808 DCHECK_EQ(decoder_state_, kDecoding); | 808 DCHECK_EQ(decoder_state_, kDecoding); |
809 | 809 |
810 // Both of these calls will set kError state if they fail. | 810 // Both of these calls will set kError state if they fail. |
811 // Only flush the frame if it's complete. | 811 // Only flush the frame if it's complete. |
812 return (AppendToInputFrame(data, size) && | 812 return (AppendToInputFrame(data, size) && |
813 (decoder_partial_frame_pending_ || FlushInputFrame())); | 813 (decoder_partial_frame_pending_ || FlushInputFrame())); |
814 } | 814 } |
815 | 815 |
816 bool ExynosVideoDecodeAccelerator::AppendToInputFrame( | 816 bool V4l2VideoDecodeAccelerator::AppendToInputFrame( |
817 const void* data, size_t size) { | 817 const void* data, size_t size) { |
818 DVLOG(3) << "AppendToInputFrame()"; | 818 DVLOG(3) << "AppendToInputFrame()"; |
819 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 819 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
820 DCHECK_NE(decoder_state_, kUninitialized); | 820 DCHECK_NE(decoder_state_, kUninitialized); |
821 DCHECK_NE(decoder_state_, kResetting); | 821 DCHECK_NE(decoder_state_, kResetting); |
822 DCHECK_NE(decoder_state_, kError); | 822 DCHECK_NE(decoder_state_, kError); |
823 // This routine can handle data == NULL and size == 0, which occurs when | 823 // This routine can handle data == NULL and size == 0, which occurs when |
824 // we queue an empty buffer for the purposes of flushing the pipe. | 824 // we queue an empty buffer for the purposes of flushing the pipe. |
825 | 825 |
826 // Flush if we're too big | 826 // Flush if we're too big |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 } | 873 } |
874 memcpy( | 874 memcpy( |
875 reinterpret_cast<uint8*>(input_record.address) + input_record.bytes_used, | 875 reinterpret_cast<uint8*>(input_record.address) + input_record.bytes_used, |
876 data, | 876 data, |
877 size); | 877 size); |
878 input_record.bytes_used += size; | 878 input_record.bytes_used += size; |
879 | 879 |
880 return true; | 880 return true; |
881 } | 881 } |
882 | 882 |
883 bool ExynosVideoDecodeAccelerator::FlushInputFrame() { | 883 bool V4l2VideoDecodeAccelerator::FlushInputFrame() { |
884 DVLOG(3) << "FlushInputFrame()"; | 884 DVLOG(3) << "FlushInputFrame()"; |
885 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 885 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
886 DCHECK_NE(decoder_state_, kUninitialized); | 886 DCHECK_NE(decoder_state_, kUninitialized); |
887 DCHECK_NE(decoder_state_, kResetting); | 887 DCHECK_NE(decoder_state_, kResetting); |
888 DCHECK_NE(decoder_state_, kError); | 888 DCHECK_NE(decoder_state_, kError); |
889 | 889 |
890 if (decoder_current_input_buffer_ == -1) | 890 if (decoder_current_input_buffer_ == -1) |
891 return true; | 891 return true; |
892 | 892 |
893 MfcInputRecord& input_record = | 893 MfcInputRecord& input_record = |
(...skipping 17 matching lines...) Expand all Loading... | |
911 mfc_input_ready_queue_.push(decoder_current_input_buffer_); | 911 mfc_input_ready_queue_.push(decoder_current_input_buffer_); |
912 decoder_current_input_buffer_ = -1; | 912 decoder_current_input_buffer_ = -1; |
913 DVLOG(3) << "FlushInputFrame(): submitting input_id=" | 913 DVLOG(3) << "FlushInputFrame(): submitting input_id=" |
914 << input_record.input_id; | 914 << input_record.input_id; |
915 // Kick the MFC once since there's new available input for it. | 915 // Kick the MFC once since there's new available input for it. |
916 EnqueueMfc(); | 916 EnqueueMfc(); |
917 | 917 |
918 return (decoder_state_ != kError); | 918 return (decoder_state_ != kError); |
919 } | 919 } |
920 | 920 |
921 void ExynosVideoDecodeAccelerator::AssignPictureBuffersTask( | 921 void V4l2VideoDecodeAccelerator::AssignPictureBuffersTask( |
922 scoped_ptr<PictureBufferArrayRef> pic_buffers) { | 922 scoped_ptr<PictureBufferArrayRef> pic_buffers) { |
923 DVLOG(3) << "AssignPictureBuffersTask()"; | 923 DVLOG(3) << "AssignPictureBuffersTask()"; |
924 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 924 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
925 DCHECK_NE(decoder_state_, kUninitialized); | 925 DCHECK_NE(decoder_state_, kUninitialized); |
926 TRACE_EVENT0("Video Decoder", "EVDA::AssignPictureBuffersTask"); | 926 TRACE_EVENT0("Video Decoder", "EVDA::AssignPictureBuffersTask"); |
927 | 927 |
928 // We run AssignPictureBuffersTask even if we're in kResetting. | 928 // We run AssignPictureBuffersTask even if we're in kResetting. |
929 if (decoder_state_ == kError) { | 929 if (decoder_state_ == kError) { |
930 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state"; | 930 DVLOG(2) << "AssignPictureBuffersTask(): early out: kError state"; |
931 return; | 931 return; |
(...skipping 19 matching lines...) Expand all Loading... | |
951 } | 951 } |
952 pic_buffers->picture_buffers.clear(); | 952 pic_buffers->picture_buffers.clear(); |
953 | 953 |
954 // We got buffers! Kick the MFC. | 954 // We got buffers! Kick the MFC. |
955 EnqueueMfc(); | 955 EnqueueMfc(); |
956 | 956 |
957 if (decoder_state_ == kChangingResolution) | 957 if (decoder_state_ == kChangingResolution) |
958 ResumeAfterResolutionChange(); | 958 ResumeAfterResolutionChange(); |
959 } | 959 } |
960 | 960 |
961 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool mfc_event_pending) { | 961 void V4l2VideoDecodeAccelerator::ServiceDeviceTask(bool mfc_event_pending) { |
962 DVLOG(3) << "ServiceDeviceTask()"; | 962 DVLOG(3) << "ServiceDeviceTask()"; |
963 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 963 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
964 DCHECK_NE(decoder_state_, kUninitialized); | 964 DCHECK_NE(decoder_state_, kUninitialized); |
965 DCHECK_NE(decoder_state_, kInitialized); | 965 DCHECK_NE(decoder_state_, kInitialized); |
966 DCHECK_NE(decoder_state_, kAfterReset); | 966 DCHECK_NE(decoder_state_, kAfterReset); |
967 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); | 967 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); |
968 | 968 |
969 if (decoder_state_ == kResetting) { | 969 if (decoder_state_ == kResetting) { |
970 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; | 970 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; |
971 return; | 971 return; |
(...skipping 22 matching lines...) Expand all Loading... | |
994 | 994 |
995 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(), | 995 // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(), |
996 // so either: | 996 // so either: |
997 // * device_poll_thread_ is running normally | 997 // * device_poll_thread_ is running normally |
998 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask() | 998 // * device_poll_thread_ scheduled us, but then a ResetTask() or DestroyTask() |
999 // shut it down, in which case we're either in kResetting or kError states | 999 // shut it down, in which case we're either in kResetting or kError states |
1000 // respectively, and we should have early-outed already. | 1000 // respectively, and we should have early-outed already. |
1001 DCHECK(device_poll_thread_.message_loop()); | 1001 DCHECK(device_poll_thread_.message_loop()); |
1002 // Queue the DevicePollTask() now. | 1002 // Queue the DevicePollTask() now. |
1003 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1003 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1004 &ExynosVideoDecodeAccelerator::DevicePollTask, | 1004 &V4l2VideoDecodeAccelerator::DevicePollTask, |
1005 base::Unretained(this), | 1005 base::Unretained(this), |
1006 poll_fds)); | 1006 poll_fds)); |
1007 | 1007 |
1008 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC[" | 1008 DVLOG(1) << "ServiceDeviceTask(): buffer counts: DEC[" |
1009 << decoder_input_queue_.size() << "->" | 1009 << decoder_input_queue_.size() << "->" |
1010 << mfc_input_ready_queue_.size() << "] => MFC[" | 1010 << mfc_input_ready_queue_.size() << "] => MFC[" |
1011 << mfc_free_input_buffers_.size() << "+" | 1011 << mfc_free_input_buffers_.size() << "+" |
1012 << mfc_input_buffer_queued_count_ << "/" | 1012 << mfc_input_buffer_queued_count_ << "/" |
1013 << mfc_input_buffer_map_.size() << "->" | 1013 << mfc_input_buffer_map_.size() << "->" |
1014 << mfc_free_output_buffers_.size() << "+" | 1014 << mfc_free_output_buffers_.size() << "+" |
1015 << mfc_output_buffer_queued_count_ << "/" | 1015 << mfc_output_buffer_queued_count_ << "/" |
1016 << mfc_output_buffer_map_.size() << "] => VDA[" | 1016 << mfc_output_buffer_map_.size() << "] => VDA[" |
1017 << decoder_frames_at_client_ << "]"; | 1017 << decoder_frames_at_client_ << "]"; |
1018 | 1018 |
1019 ScheduleDecodeBufferTaskIfNeeded(); | 1019 ScheduleDecodeBufferTaskIfNeeded(); |
1020 StartResolutionChangeIfNeeded(); | 1020 StartResolutionChangeIfNeeded(); |
1021 } | 1021 } |
1022 | 1022 |
1023 void ExynosVideoDecodeAccelerator::EnqueueMfc() { | 1023 void V4l2VideoDecodeAccelerator::EnqueueMfc() { |
1024 DVLOG(3) << "EnqueueMfc()"; | 1024 DVLOG(3) << "EnqueueMfc()"; |
1025 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1025 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1026 DCHECK_NE(decoder_state_, kUninitialized); | 1026 DCHECK_NE(decoder_state_, kUninitialized); |
1027 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); | 1027 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); |
1028 | 1028 |
1029 // Drain the pipe of completed decode buffers. | 1029 // Drain the pipe of completed decode buffers. |
1030 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; | 1030 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; |
1031 while (!mfc_input_ready_queue_.empty()) { | 1031 while (!mfc_input_ready_queue_.empty()) { |
1032 if (!EnqueueMfcInputRecord()) | 1032 if (!EnqueueMfcInputRecord()) |
1033 return; | 1033 return; |
(...skipping 24 matching lines...) Expand all Loading... | |
1058 return; | 1058 return; |
1059 // Start VIDIOC_STREAMON if we haven't yet. | 1059 // Start VIDIOC_STREAMON if we haven't yet. |
1060 if (!mfc_output_streamon_) { | 1060 if (!mfc_output_streamon_) { |
1061 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1061 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1062 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); | 1062 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); |
1063 mfc_output_streamon_ = true; | 1063 mfc_output_streamon_ = true; |
1064 } | 1064 } |
1065 } | 1065 } |
1066 } | 1066 } |
1067 | 1067 |
1068 void ExynosVideoDecodeAccelerator::DequeueMfcEvents() { | 1068 void V4l2VideoDecodeAccelerator::DequeueMfcEvents() { |
1069 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1069 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1070 DCHECK_NE(decoder_state_, kUninitialized); | 1070 DCHECK_NE(decoder_state_, kUninitialized); |
1071 DVLOG(3) << "DequeueMfcEvents()"; | 1071 DVLOG(3) << "DequeueMfcEvents()"; |
1072 | 1072 |
1073 struct v4l2_event ev; | 1073 struct v4l2_event ev; |
1074 memset(&ev, 0, sizeof(ev)); | 1074 memset(&ev, 0, sizeof(ev)); |
1075 | 1075 |
1076 while (ioctl(mfc_fd_, VIDIOC_DQEVENT, &ev) == 0) { | 1076 while (ioctl(mfc_fd_, VIDIOC_DQEVENT, &ev) == 0) { |
1077 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) { | 1077 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) { |
1078 DVLOG(3) << "DequeueMfcEvents(): got resolution change event."; | 1078 DVLOG(3) << "DequeueMfcEvents(): got resolution change event."; |
1079 DCHECK(!resolution_change_pending_); | 1079 DCHECK(!resolution_change_pending_); |
1080 resolution_change_pending_ = true; | 1080 resolution_change_pending_ = true; |
1081 } else { | 1081 } else { |
1082 DLOG(FATAL) << "DequeueMfcEvents(): got an event (" << ev.type | 1082 DLOG(FATAL) << "DequeueMfcEvents(): got an event (" << ev.type |
1083 << ") we haven't subscribed to."; | 1083 << ") we haven't subscribed to."; |
1084 } | 1084 } |
1085 } | 1085 } |
1086 } | 1086 } |
1087 | 1087 |
1088 void ExynosVideoDecodeAccelerator::DequeueMfc() { | 1088 void V4l2VideoDecodeAccelerator::DequeueMfc() { |
1089 DVLOG(3) << "DequeueMfc()"; | 1089 DVLOG(3) << "DequeueMfc()"; |
1090 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1090 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1091 DCHECK_NE(decoder_state_, kUninitialized); | 1091 DCHECK_NE(decoder_state_, kUninitialized); |
1092 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); | 1092 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); |
1093 | 1093 |
1094 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free | 1094 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free |
1095 // list. | 1095 // list. |
1096 struct v4l2_buffer dqbuf; | 1096 struct v4l2_buffer dqbuf; |
1097 struct v4l2_plane planes[2]; | 1097 struct v4l2_plane planes[2]; |
1098 while (mfc_input_buffer_queued_count_ > 0) { | 1098 while (mfc_input_buffer_queued_count_ > 0) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 SendPictureReady(); | 1161 SendPictureReady(); |
1162 output_record.cleared = true; | 1162 output_record.cleared = true; |
1163 decoder_frames_at_client_++; | 1163 decoder_frames_at_client_++; |
1164 } | 1164 } |
1165 mfc_output_buffer_queued_count_--; | 1165 mfc_output_buffer_queued_count_--; |
1166 } | 1166 } |
1167 | 1167 |
1168 NotifyFlushDoneIfNeeded(); | 1168 NotifyFlushDoneIfNeeded(); |
1169 } | 1169 } |
1170 | 1170 |
1171 bool ExynosVideoDecodeAccelerator::EnqueueMfcInputRecord() { | 1171 bool V4l2VideoDecodeAccelerator::EnqueueMfcInputRecord() { |
1172 DVLOG(3) << "EnqueueMfcInputRecord()"; | 1172 DVLOG(3) << "EnqueueMfcInputRecord()"; |
1173 DCHECK(!mfc_input_ready_queue_.empty()); | 1173 DCHECK(!mfc_input_ready_queue_.empty()); |
1174 | 1174 |
1175 // Enqueue a MFC input (VIDEO_OUTPUT) buffer. | 1175 // Enqueue a MFC input (VIDEO_OUTPUT) buffer. |
1176 const int buffer = mfc_input_ready_queue_.front(); | 1176 const int buffer = mfc_input_ready_queue_.front(); |
1177 MfcInputRecord& input_record = mfc_input_buffer_map_[buffer]; | 1177 MfcInputRecord& input_record = mfc_input_buffer_map_[buffer]; |
1178 DCHECK(!input_record.at_device); | 1178 DCHECK(!input_record.at_device); |
1179 struct v4l2_buffer qbuf; | 1179 struct v4l2_buffer qbuf; |
1180 struct v4l2_plane qbuf_plane; | 1180 struct v4l2_plane qbuf_plane; |
1181 memset(&qbuf, 0, sizeof(qbuf)); | 1181 memset(&qbuf, 0, sizeof(qbuf)); |
1182 memset(&qbuf_plane, 0, sizeof(qbuf_plane)); | 1182 memset(&qbuf_plane, 0, sizeof(qbuf_plane)); |
1183 qbuf.index = buffer; | 1183 qbuf.index = buffer; |
1184 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1184 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1185 qbuf.timestamp.tv_sec = input_record.input_id; | 1185 qbuf.timestamp.tv_sec = input_record.input_id; |
1186 qbuf.memory = V4L2_MEMORY_MMAP; | 1186 qbuf.memory = V4L2_MEMORY_MMAP; |
1187 qbuf.m.planes = &qbuf_plane; | 1187 qbuf.m.planes = &qbuf_plane; |
1188 qbuf.m.planes[0].bytesused = input_record.bytes_used; | 1188 qbuf.m.planes[0].bytesused = input_record.bytes_used; |
1189 qbuf.length = 1; | 1189 qbuf.length = 1; |
1190 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); | 1190 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); |
1191 mfc_input_ready_queue_.pop(); | 1191 mfc_input_ready_queue_.pop(); |
1192 input_record.at_device = true; | 1192 input_record.at_device = true; |
1193 mfc_input_buffer_queued_count_++; | 1193 mfc_input_buffer_queued_count_++; |
1194 DVLOG(3) << "EnqueueMfcInputRecord(): enqueued input_id=" | 1194 DVLOG(3) << "EnqueueMfcInputRecord(): enqueued input_id=" |
1195 << input_record.input_id; | 1195 << input_record.input_id; |
1196 return true; | 1196 return true; |
1197 } | 1197 } |
1198 | 1198 |
1199 bool ExynosVideoDecodeAccelerator::EnqueueMfcOutputRecord() { | 1199 bool V4l2VideoDecodeAccelerator::EnqueueMfcOutputRecord() { |
1200 DVLOG(3) << "EnqueueMfcOutputRecord()"; | 1200 DVLOG(3) << "EnqueueMfcOutputRecord()"; |
1201 DCHECK(!mfc_free_output_buffers_.empty()); | 1201 DCHECK(!mfc_free_output_buffers_.empty()); |
1202 | 1202 |
1203 // Enqueue a MFC output (VIDEO_CAPTURE) buffer. | 1203 // Enqueue a MFC output (VIDEO_CAPTURE) buffer. |
1204 const int buffer = mfc_free_output_buffers_.front(); | 1204 const int buffer = mfc_free_output_buffers_.front(); |
1205 MfcOutputRecord& output_record = mfc_output_buffer_map_[buffer]; | 1205 MfcOutputRecord& output_record = mfc_output_buffer_map_[buffer]; |
1206 DCHECK(!output_record.at_device); | 1206 DCHECK(!output_record.at_device); |
1207 DCHECK(!output_record.at_client); | 1207 DCHECK(!output_record.at_client); |
1208 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); | 1208 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); |
1209 DCHECK_NE(output_record.picture_id, -1); | 1209 DCHECK_NE(output_record.picture_id, -1); |
(...skipping 17 matching lines...) Expand all Loading... | |
1227 qbuf.memory = V4L2_MEMORY_MMAP; | 1227 qbuf.memory = V4L2_MEMORY_MMAP; |
1228 qbuf.m.planes = qbuf_planes; | 1228 qbuf.m.planes = qbuf_planes; |
1229 qbuf.length = arraysize(output_record.fds); | 1229 qbuf.length = arraysize(output_record.fds); |
1230 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); | 1230 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_QBUF, &qbuf); |
1231 mfc_free_output_buffers_.pop(); | 1231 mfc_free_output_buffers_.pop(); |
1232 output_record.at_device = true; | 1232 output_record.at_device = true; |
1233 mfc_output_buffer_queued_count_++; | 1233 mfc_output_buffer_queued_count_++; |
1234 return true; | 1234 return true; |
1235 } | 1235 } |
1236 | 1236 |
1237 void ExynosVideoDecodeAccelerator::ReusePictureBufferTask( | 1237 void V4l2VideoDecodeAccelerator::ReusePictureBufferTask( |
1238 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { | 1238 int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { |
1239 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" | 1239 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" |
1240 << picture_buffer_id; | 1240 << picture_buffer_id; |
1241 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1241 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1242 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); | 1242 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); |
1243 | 1243 |
1244 // We run ReusePictureBufferTask even if we're in kResetting. | 1244 // We run ReusePictureBufferTask even if we're in kResetting. |
1245 if (decoder_state_ == kError) { | 1245 if (decoder_state_ == kError) { |
1246 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; | 1246 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; |
1247 return; | 1247 return; |
(...skipping 26 matching lines...) Expand all Loading... | |
1274 output_record.at_client = false; | 1274 output_record.at_client = false; |
1275 output_record.egl_sync = egl_sync_ref->egl_sync; | 1275 output_record.egl_sync = egl_sync_ref->egl_sync; |
1276 mfc_free_output_buffers_.push(index); | 1276 mfc_free_output_buffers_.push(index); |
1277 decoder_frames_at_client_--; | 1277 decoder_frames_at_client_--; |
1278 // Take ownership of the EGLSync. | 1278 // Take ownership of the EGLSync. |
1279 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; | 1279 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; |
1280 // We got a buffer back, so kick the MFC. | 1280 // We got a buffer back, so kick the MFC. |
1281 EnqueueMfc(); | 1281 EnqueueMfc(); |
1282 } | 1282 } |
1283 | 1283 |
1284 void ExynosVideoDecodeAccelerator::FlushTask() { | 1284 void V4l2VideoDecodeAccelerator::FlushTask() { |
1285 DVLOG(3) << "FlushTask()"; | 1285 DVLOG(3) << "FlushTask()"; |
1286 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1286 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1287 TRACE_EVENT0("Video Decoder", "EVDA::FlushTask"); | 1287 TRACE_EVENT0("Video Decoder", "EVDA::FlushTask"); |
1288 | 1288 |
1289 // Flush outstanding buffers. | 1289 // Flush outstanding buffers. |
1290 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { | 1290 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { |
1291 // There's nothing in the pipe, so return done immediately. | 1291 // There's nothing in the pipe, so return done immediately. |
1292 DVLOG(3) << "FlushTask(): returning flush"; | 1292 DVLOG(3) << "FlushTask(): returning flush"; |
1293 child_message_loop_proxy_->PostTask( | 1293 child_message_loop_proxy_->PostTask( |
1294 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); | 1294 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); |
1295 return; | 1295 return; |
1296 } else if (decoder_state_ == kError) { | 1296 } else if (decoder_state_ == kError) { |
1297 DVLOG(2) << "FlushTask(): early out: kError state"; | 1297 DVLOG(2) << "FlushTask(): early out: kError state"; |
1298 return; | 1298 return; |
1299 } | 1299 } |
1300 | 1300 |
1301 // We don't support stacked flushing. | 1301 // We don't support stacked flushing. |
1302 DCHECK(!decoder_flushing_); | 1302 DCHECK(!decoder_flushing_); |
1303 | 1303 |
1304 // Queue up an empty buffer -- this triggers the flush. | 1304 // Queue up an empty buffer -- this triggers the flush. |
1305 decoder_input_queue_.push( | 1305 decoder_input_queue_.push( |
1306 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( | 1306 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( |
1307 io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId))); | 1307 io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId))); |
1308 decoder_flushing_ = true; | 1308 decoder_flushing_ = true; |
1309 SendPictureReady(); // Send all pending PictureReady. | 1309 SendPictureReady(); // Send all pending PictureReady. |
1310 | 1310 |
1311 ScheduleDecodeBufferTaskIfNeeded(); | 1311 ScheduleDecodeBufferTaskIfNeeded(); |
1312 } | 1312 } |
1313 | 1313 |
1314 void ExynosVideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { | 1314 void V4l2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { |
1315 if (!decoder_flushing_) | 1315 if (!decoder_flushing_) |
1316 return; | 1316 return; |
1317 | 1317 |
1318 // Pipeline is empty when: | 1318 // Pipeline is empty when: |
1319 // * Decoder input queue is empty of non-delayed buffers. | 1319 // * Decoder input queue is empty of non-delayed buffers. |
1320 // * There is no currently filling input buffer. | 1320 // * There is no currently filling input buffer. |
1321 // * MFC input holding queue is empty. | 1321 // * MFC input holding queue is empty. |
1322 // * All MFC input (VIDEO_OUTPUT) buffers are returned. | 1322 // * All MFC input (VIDEO_OUTPUT) buffers are returned. |
1323 if (!decoder_input_queue_.empty()) { | 1323 if (!decoder_input_queue_.empty()) { |
1324 if (decoder_input_queue_.front()->input_id != | 1324 if (decoder_input_queue_.front()->input_id != |
(...skipping 23 matching lines...) Expand all Loading... | |
1348 decoder_delay_bitstream_buffer_id_ = -1; | 1348 decoder_delay_bitstream_buffer_id_ = -1; |
1349 decoder_flushing_ = false; | 1349 decoder_flushing_ = false; |
1350 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; | 1350 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; |
1351 child_message_loop_proxy_->PostTask( | 1351 child_message_loop_proxy_->PostTask( |
1352 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); | 1352 FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); |
1353 | 1353 |
1354 // While we were flushing, we early-outed DecodeBufferTask()s. | 1354 // While we were flushing, we early-outed DecodeBufferTask()s. |
1355 ScheduleDecodeBufferTaskIfNeeded(); | 1355 ScheduleDecodeBufferTaskIfNeeded(); |
1356 } | 1356 } |
1357 | 1357 |
1358 void ExynosVideoDecodeAccelerator::ResetTask() { | 1358 void V4l2VideoDecodeAccelerator::ResetTask() { |
1359 DVLOG(3) << "ResetTask()"; | 1359 DVLOG(3) << "ResetTask()"; |
1360 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1360 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1361 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); | 1361 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); |
1362 | 1362 |
1363 if (decoder_state_ == kError) { | 1363 if (decoder_state_ == kError) { |
1364 DVLOG(2) << "ResetTask(): early out: kError state"; | 1364 DVLOG(2) << "ResetTask(): early out: kError state"; |
1365 return; | 1365 return; |
1366 } | 1366 } |
1367 | 1367 |
1368 // If we are in the middle of switching resolutions, postpone reset until | 1368 // If we are in the middle of switching resolutions, postpone reset until |
(...skipping 20 matching lines...) Expand all Loading... | |
1389 | 1389 |
1390 // If we were flushing, we'll never return any more BitstreamBuffers or | 1390 // If we were flushing, we'll never return any more BitstreamBuffers or |
1391 // PictureBuffers; they have all been dropped and returned by now. | 1391 // PictureBuffers; they have all been dropped and returned by now. |
1392 NotifyFlushDoneIfNeeded(); | 1392 NotifyFlushDoneIfNeeded(); |
1393 | 1393 |
1394 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening | 1394 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening |
1395 // jobs will early-out in the kResetting state. | 1395 // jobs will early-out in the kResetting state. |
1396 decoder_state_ = kResetting; | 1396 decoder_state_ = kResetting; |
1397 SendPictureReady(); // Send all pending PictureReady. | 1397 SendPictureReady(); // Send all pending PictureReady. |
1398 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1398 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1399 &ExynosVideoDecodeAccelerator::ResetDoneTask, base::Unretained(this))); | 1399 &V4l2VideoDecodeAccelerator::ResetDoneTask, base::Unretained(this))); |
1400 } | 1400 } |
1401 | 1401 |
1402 void ExynosVideoDecodeAccelerator::ResetDoneTask() { | 1402 void V4l2VideoDecodeAccelerator::ResetDoneTask() { |
1403 DVLOG(3) << "ResetDoneTask()"; | 1403 DVLOG(3) << "ResetDoneTask()"; |
1404 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1404 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1405 TRACE_EVENT0("Video Decoder", "EVDA::ResetDoneTask"); | 1405 TRACE_EVENT0("Video Decoder", "EVDA::ResetDoneTask"); |
1406 | 1406 |
1407 if (decoder_state_ == kError) { | 1407 if (decoder_state_ == kError) { |
1408 DVLOG(2) << "ResetDoneTask(): early out: kError state"; | 1408 DVLOG(2) << "ResetDoneTask(): early out: kError state"; |
1409 return; | 1409 return; |
1410 } | 1410 } |
1411 | 1411 |
1412 // We might have received a resolution change event while we were waiting | 1412 // We might have received a resolution change event while we were waiting |
(...skipping 13 matching lines...) Expand all Loading... | |
1426 decoder_state_ = kAfterReset; | 1426 decoder_state_ = kAfterReset; |
1427 decoder_partial_frame_pending_ = false; | 1427 decoder_partial_frame_pending_ = false; |
1428 decoder_delay_bitstream_buffer_id_ = -1; | 1428 decoder_delay_bitstream_buffer_id_ = -1; |
1429 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1429 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1430 &Client::NotifyResetDone, client_)); | 1430 &Client::NotifyResetDone, client_)); |
1431 | 1431 |
1432 // While we were resetting, we early-outed DecodeBufferTask()s. | 1432 // While we were resetting, we early-outed DecodeBufferTask()s. |
1433 ScheduleDecodeBufferTaskIfNeeded(); | 1433 ScheduleDecodeBufferTaskIfNeeded(); |
1434 } | 1434 } |
1435 | 1435 |
1436 void ExynosVideoDecodeAccelerator::DestroyTask() { | 1436 void V4l2VideoDecodeAccelerator::DestroyTask() { |
1437 DVLOG(3) << "DestroyTask()"; | 1437 DVLOG(3) << "DestroyTask()"; |
1438 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); | 1438 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); |
1439 | 1439 |
1440 // DestroyTask() should run regardless of decoder_state_. | 1440 // DestroyTask() should run regardless of decoder_state_. |
1441 | 1441 |
1442 // Stop streaming and the device_poll_thread_. | 1442 // Stop streaming and the device_poll_thread_. |
1443 StopDevicePoll(false); | 1443 StopDevicePoll(false); |
1444 | 1444 |
1445 decoder_current_bitstream_buffer_.reset(); | 1445 decoder_current_bitstream_buffer_.reset(); |
1446 decoder_current_input_buffer_ = -1; | 1446 decoder_current_input_buffer_ = -1; |
1447 decoder_decode_buffer_tasks_scheduled_ = 0; | 1447 decoder_decode_buffer_tasks_scheduled_ = 0; |
1448 decoder_frames_at_client_ = 0; | 1448 decoder_frames_at_client_ = 0; |
1449 while (!decoder_input_queue_.empty()) | 1449 while (!decoder_input_queue_.empty()) |
1450 decoder_input_queue_.pop(); | 1450 decoder_input_queue_.pop(); |
1451 decoder_flushing_ = false; | 1451 decoder_flushing_ = false; |
1452 | 1452 |
1453 // Set our state to kError. Just in case. | 1453 // Set our state to kError. Just in case. |
1454 decoder_state_ = kError; | 1454 decoder_state_ = kError; |
1455 } | 1455 } |
1456 | 1456 |
1457 bool ExynosVideoDecodeAccelerator::StartDevicePoll() { | 1457 bool V4l2VideoDecodeAccelerator::StartDevicePoll() { |
1458 DVLOG(3) << "StartDevicePoll()"; | 1458 DVLOG(3) << "StartDevicePoll()"; |
1459 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1459 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1460 DCHECK(!device_poll_thread_.IsRunning()); | 1460 DCHECK(!device_poll_thread_.IsRunning()); |
1461 | 1461 |
1462 // Start up the device poll thread and schedule its first DevicePollTask(). | 1462 // Start up the device poll thread and schedule its first DevicePollTask(). |
1463 if (!device_poll_thread_.Start()) { | 1463 if (!device_poll_thread_.Start()) { |
1464 DLOG(ERROR) << "StartDevicePoll(): Device thread failed to start"; | 1464 DLOG(ERROR) << "StartDevicePoll(): Device thread failed to start"; |
1465 NOTIFY_ERROR(PLATFORM_FAILURE); | 1465 NOTIFY_ERROR(PLATFORM_FAILURE); |
1466 return false; | 1466 return false; |
1467 } | 1467 } |
1468 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1468 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1469 &ExynosVideoDecodeAccelerator::DevicePollTask, | 1469 &V4l2VideoDecodeAccelerator::DevicePollTask, |
1470 base::Unretained(this), | 1470 base::Unretained(this), |
1471 0)); | 1471 0)); |
1472 | 1472 |
1473 return true; | 1473 return true; |
1474 } | 1474 } |
1475 | 1475 |
1476 bool ExynosVideoDecodeAccelerator::StopDevicePoll(bool keep_mfc_input_state) { | 1476 bool V4l2VideoDecodeAccelerator::StopDevicePoll(bool keep_mfc_input_state) { |
1477 DVLOG(3) << "StopDevicePoll()"; | 1477 DVLOG(3) << "StopDevicePoll()"; |
1478 if (decoder_thread_.IsRunning()) | 1478 if (decoder_thread_.IsRunning()) |
1479 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1479 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1480 | 1480 |
1481 // Signal the DevicePollTask() to stop, and stop the device poll thread. | 1481 // Signal the DevicePollTask() to stop, and stop the device poll thread. |
1482 if (!SetDevicePollInterrupt()) | 1482 if (!SetDevicePollInterrupt()) |
1483 return false; | 1483 return false; |
1484 device_poll_thread_.Stop(); | 1484 device_poll_thread_.Stop(); |
1485 // Clear the interrupt now, to be sure. | 1485 // Clear the interrupt now, to be sure. |
1486 if (!ClearDevicePollInterrupt()) | 1486 if (!ClearDevicePollInterrupt()) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1523 mfc_free_output_buffers_.push(i); | 1523 mfc_free_output_buffers_.push(i); |
1524 mfc_output_buffer_map_[i].at_device = false; | 1524 mfc_output_buffer_map_[i].at_device = false; |
1525 } | 1525 } |
1526 } | 1526 } |
1527 mfc_output_buffer_queued_count_ = 0; | 1527 mfc_output_buffer_queued_count_ = 0; |
1528 | 1528 |
1529 DVLOG(3) << "StopDevicePoll(): device poll stopped"; | 1529 DVLOG(3) << "StopDevicePoll(): device poll stopped"; |
1530 return true; | 1530 return true; |
1531 } | 1531 } |
1532 | 1532 |
1533 bool ExynosVideoDecodeAccelerator::SetDevicePollInterrupt() { | 1533 bool V4l2VideoDecodeAccelerator::SetDevicePollInterrupt() { |
1534 DVLOG(3) << "SetDevicePollInterrupt()"; | 1534 DVLOG(3) << "SetDevicePollInterrupt()"; |
1535 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1535 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1536 | 1536 |
1537 const uint64 buf = 1; | 1537 const uint64 buf = 1; |
1538 if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 1538 if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { |
1539 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; | 1539 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; |
1540 NOTIFY_ERROR(PLATFORM_FAILURE); | 1540 NOTIFY_ERROR(PLATFORM_FAILURE); |
1541 return false; | 1541 return false; |
1542 } | 1542 } |
1543 return true; | 1543 return true; |
1544 } | 1544 } |
1545 | 1545 |
1546 bool ExynosVideoDecodeAccelerator::ClearDevicePollInterrupt() { | 1546 bool V4l2VideoDecodeAccelerator::ClearDevicePollInterrupt() { |
1547 DVLOG(3) << "ClearDevicePollInterrupt()"; | 1547 DVLOG(3) << "ClearDevicePollInterrupt()"; |
1548 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1548 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1549 | 1549 |
1550 uint64 buf; | 1550 uint64 buf; |
1551 if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 1551 if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { |
1552 if (errno == EAGAIN) { | 1552 if (errno == EAGAIN) { |
1553 // No interrupt flag set, and we're reading nonblocking. Not an error. | 1553 // No interrupt flag set, and we're reading nonblocking. Not an error. |
1554 return true; | 1554 return true; |
1555 } else { | 1555 } else { |
1556 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; | 1556 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; |
1557 NOTIFY_ERROR(PLATFORM_FAILURE); | 1557 NOTIFY_ERROR(PLATFORM_FAILURE); |
1558 return false; | 1558 return false; |
1559 } | 1559 } |
1560 } | 1560 } |
1561 return true; | 1561 return true; |
1562 } | 1562 } |
1563 | 1563 |
1564 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() { | 1564 void V4l2VideoDecodeAccelerator::StartResolutionChangeIfNeeded() { |
1565 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1565 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1566 DCHECK_EQ(decoder_state_, kDecoding); | 1566 DCHECK_EQ(decoder_state_, kDecoding); |
1567 | 1567 |
1568 if (!resolution_change_pending_) | 1568 if (!resolution_change_pending_) |
1569 return; | 1569 return; |
1570 | 1570 |
1571 DVLOG(3) << "No more work, initiate resolution change"; | 1571 DVLOG(3) << "No more work, initiate resolution change"; |
1572 | 1572 |
1573 // Keep MFC input queue. | 1573 // Keep MFC input queue. |
1574 if (!StopDevicePoll(true)) | 1574 if (!StopDevicePoll(true)) |
1575 return; | 1575 return; |
1576 | 1576 |
1577 decoder_state_ = kChangingResolution; | 1577 decoder_state_ = kChangingResolution; |
1578 DCHECK(resolution_change_pending_); | 1578 DCHECK(resolution_change_pending_); |
1579 resolution_change_pending_ = false; | 1579 resolution_change_pending_ = false; |
1580 | 1580 |
1581 // Post a task to clean up buffers on child thread. This will also ensure | 1581 // Post a task to clean up buffers on child thread. This will also ensure |
1582 // that we won't accept ReusePictureBuffer() anymore after that. | 1582 // that we won't accept ReusePictureBuffer() anymore after that. |
1583 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1583 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1584 &ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers, | 1584 &V4l2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers, |
1585 weak_this_)); | 1585 weak_this_)); |
1586 } | 1586 } |
1587 | 1587 |
1588 void ExynosVideoDecodeAccelerator::FinishResolutionChange() { | 1588 void V4l2VideoDecodeAccelerator::FinishResolutionChange() { |
1589 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1589 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1590 DVLOG(3) << "FinishResolutionChange()"; | 1590 DVLOG(3) << "FinishResolutionChange()"; |
1591 | 1591 |
1592 if (decoder_state_ == kError) { | 1592 if (decoder_state_ == kError) { |
1593 DVLOG(2) << "FinishResolutionChange(): early out: kError state"; | 1593 DVLOG(2) << "FinishResolutionChange(): early out: kError state"; |
1594 return; | 1594 return; |
1595 } | 1595 } |
1596 | 1596 |
1597 struct v4l2_format format; | 1597 struct v4l2_format format; |
1598 bool again; | 1598 bool again; |
1599 bool ret = GetFormatInfo(&format, &again); | 1599 bool ret = GetFormatInfo(&format, &again); |
1600 if (!ret || again) { | 1600 if (!ret || again) { |
1601 DVLOG(3) << "Couldn't get format information after resolution change"; | 1601 DVLOG(3) << "Couldn't get format information after resolution change"; |
1602 NOTIFY_ERROR(PLATFORM_FAILURE); | 1602 NOTIFY_ERROR(PLATFORM_FAILURE); |
1603 return; | 1603 return; |
1604 } | 1604 } |
1605 | 1605 |
1606 if (!CreateBuffersForFormat(format)) { | 1606 if (!CreateBuffersForFormat(format)) { |
1607 DVLOG(3) << "Couldn't reallocate buffers after resolution change"; | 1607 DVLOG(3) << "Couldn't reallocate buffers after resolution change"; |
1608 NOTIFY_ERROR(PLATFORM_FAILURE); | 1608 NOTIFY_ERROR(PLATFORM_FAILURE); |
1609 return; | 1609 return; |
1610 } | 1610 } |
1611 | 1611 |
1612 // From here we stay in kChangingResolution and wait for | 1612 // From here we stay in kChangingResolution and wait for |
1613 // AssignPictureBuffers() before we can resume. | 1613 // AssignPictureBuffers() before we can resume. |
1614 } | 1614 } |
1615 | 1615 |
1616 void ExynosVideoDecodeAccelerator::ResumeAfterResolutionChange() { | 1616 void V4l2VideoDecodeAccelerator::ResumeAfterResolutionChange() { |
1617 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1617 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1618 DVLOG(3) << "ResumeAfterResolutionChange()"; | 1618 DVLOG(3) << "ResumeAfterResolutionChange()"; |
1619 | 1619 |
1620 decoder_state_ = kDecoding; | 1620 decoder_state_ = kDecoding; |
1621 | 1621 |
1622 if (resolution_change_reset_pending_) { | 1622 if (resolution_change_reset_pending_) { |
1623 resolution_change_reset_pending_ = false; | 1623 resolution_change_reset_pending_ = false; |
1624 ResetTask(); | 1624 ResetTask(); |
1625 return; | 1625 return; |
1626 } | 1626 } |
1627 | 1627 |
1628 if (!StartDevicePoll()) | 1628 if (!StartDevicePoll()) |
1629 return; | 1629 return; |
1630 | 1630 |
1631 EnqueueMfc(); | 1631 EnqueueMfc(); |
1632 ScheduleDecodeBufferTaskIfNeeded(); | 1632 ScheduleDecodeBufferTaskIfNeeded(); |
1633 } | 1633 } |
1634 | 1634 |
1635 void ExynosVideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) { | 1635 void V4l2VideoDecodeAccelerator::DevicePollTask(unsigned int poll_fds) { |
1636 DVLOG(3) << "DevicePollTask()"; | 1636 DVLOG(3) << "DevicePollTask()"; |
1637 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); | 1637 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); |
1638 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); | 1638 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); |
1639 | 1639 |
1640 // This routine just polls the set of device fds, and schedules a | 1640 // This routine just polls the set of device fds, and schedules a |
1641 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. | 1641 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. |
1642 // Other threads may notify this task to return early by writing to | 1642 // Other threads may notify this task to return early by writing to |
1643 // device_poll_interrupt_fd_. | 1643 // device_poll_interrupt_fd_. |
1644 struct pollfd pollfds[3]; | 1644 struct pollfd pollfds[3]; |
1645 nfds_t nfds; | 1645 nfds_t nfds; |
(...skipping 18 matching lines...) Expand all Loading... | |
1664 NOTIFY_ERROR(PLATFORM_FAILURE); | 1664 NOTIFY_ERROR(PLATFORM_FAILURE); |
1665 return; | 1665 return; |
1666 } | 1666 } |
1667 | 1667 |
1668 bool mfc_event_pending = (mfc_pollfd != -1 && | 1668 bool mfc_event_pending = (mfc_pollfd != -1 && |
1669 pollfds[mfc_pollfd].revents & POLLPRI); | 1669 pollfds[mfc_pollfd].revents & POLLPRI); |
1670 | 1670 |
1671 // All processing should happen on ServiceDeviceTask(), since we shouldn't | 1671 // All processing should happen on ServiceDeviceTask(), since we shouldn't |
1672 // touch decoder state from this thread. | 1672 // touch decoder state from this thread. |
1673 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1673 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1674 &ExynosVideoDecodeAccelerator::ServiceDeviceTask, | 1674 &V4l2VideoDecodeAccelerator::ServiceDeviceTask, |
1675 base::Unretained(this), mfc_event_pending)); | 1675 base::Unretained(this), mfc_event_pending)); |
1676 } | 1676 } |
1677 | 1677 |
1678 void ExynosVideoDecodeAccelerator::NotifyError(Error error) { | 1678 void V4l2VideoDecodeAccelerator::NotifyError(Error error) { |
1679 DVLOG(2) << "NotifyError()"; | 1679 DVLOG(2) << "NotifyError()"; |
1680 | 1680 |
1681 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { | 1681 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { |
1682 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1682 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1683 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error)); | 1683 &V4l2VideoDecodeAccelerator::NotifyError, weak_this_, error)); |
1684 return; | 1684 return; |
1685 } | 1685 } |
1686 | 1686 |
1687 if (client_) { | 1687 if (client_) { |
1688 client_->NotifyError(error); | 1688 client_->NotifyError(error); |
1689 client_ptr_factory_.InvalidateWeakPtrs(); | 1689 client_ptr_factory_.InvalidateWeakPtrs(); |
1690 } | 1690 } |
1691 } | 1691 } |
1692 | 1692 |
1693 void ExynosVideoDecodeAccelerator::SetDecoderState(State state) { | 1693 void V4l2VideoDecodeAccelerator::SetDecoderState(State state) { |
1694 DVLOG(3) << "SetDecoderState(): state=" << state; | 1694 DVLOG(3) << "SetDecoderState(): state=" << state; |
1695 | 1695 |
1696 // We can touch decoder_state_ only if this is the decoder thread or the | 1696 // We can touch decoder_state_ only if this is the decoder thread or the |
1697 // decoder thread isn't running. | 1697 // decoder thread isn't running. |
1698 if (decoder_thread_.message_loop() != NULL && | 1698 if (decoder_thread_.message_loop() != NULL && |
1699 decoder_thread_.message_loop() != base::MessageLoop::current()) { | 1699 decoder_thread_.message_loop() != base::MessageLoop::current()) { |
1700 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1700 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1701 &ExynosVideoDecodeAccelerator::SetDecoderState, | 1701 &V4l2VideoDecodeAccelerator::SetDecoderState, |
1702 base::Unretained(this), state)); | 1702 base::Unretained(this), state)); |
1703 } else { | 1703 } else { |
1704 decoder_state_ = state; | 1704 decoder_state_ = state; |
1705 } | 1705 } |
1706 } | 1706 } |
1707 | 1707 |
1708 bool ExynosVideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, | 1708 bool V4l2VideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, |
1709 bool* again) { | 1709 bool* again) { |
1710 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1710 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1711 | 1711 |
1712 *again = false; | 1712 *again = false; |
1713 memset(format, 0, sizeof(*format)); | 1713 memset(format, 0, sizeof(*format)); |
1714 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1714 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1715 if (HANDLE_EINTR(ioctl(mfc_fd_, VIDIOC_G_FMT, format)) != 0) { | 1715 if (HANDLE_EINTR(ioctl(mfc_fd_, VIDIOC_G_FMT, format)) != 0) { |
1716 if (errno == EINVAL) { | 1716 if (errno == EINVAL) { |
1717 // EINVAL means we haven't seen sufficient stream to decode the format. | 1717 // EINVAL means we haven't seen sufficient stream to decode the format. |
1718 *again = true; | 1718 *again = true; |
1719 return true; | 1719 return true; |
1720 } else { | 1720 } else { |
1721 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; | 1721 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; |
1722 NOTIFY_ERROR(PLATFORM_FAILURE); | 1722 NOTIFY_ERROR(PLATFORM_FAILURE); |
1723 return false; | 1723 return false; |
1724 } | 1724 } |
1725 } | 1725 } |
1726 | 1726 |
1727 return true; | 1727 return true; |
1728 } | 1728 } |
1729 | 1729 |
1730 bool ExynosVideoDecodeAccelerator::CreateBuffersForFormat( | 1730 bool V4l2VideoDecodeAccelerator::CreateBuffersForFormat( |
1731 const struct v4l2_format& format) { | 1731 const struct v4l2_format& format) { |
1732 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1732 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1733 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); | 1733 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); |
1734 frame_buffer_size_.SetSize( | 1734 frame_buffer_size_.SetSize( |
1735 format.fmt.pix_mp.width, format.fmt.pix_mp.height); | 1735 format.fmt.pix_mp.width, format.fmt.pix_mp.height); |
1736 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; | 1736 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; |
1737 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12M); | 1737 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12M); |
1738 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " | 1738 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " |
1739 << frame_buffer_size_.ToString(); | 1739 << frame_buffer_size_.ToString(); |
1740 | 1740 |
1741 if (!CreateMfcOutputBuffers()) | 1741 if (!CreateMfcOutputBuffers()) |
1742 return false; | 1742 return false; |
1743 | 1743 |
1744 return true; | 1744 return true; |
1745 } | 1745 } |
1746 | 1746 |
1747 bool ExynosVideoDecodeAccelerator::CreateMfcInputBuffers() { | 1747 bool V4l2VideoDecodeAccelerator::CreateMfcInputBuffers() { |
1748 DVLOG(3) << "CreateMfcInputBuffers()"; | 1748 DVLOG(3) << "CreateMfcInputBuffers()"; |
1749 // We always run this as we prepare to initialize. | 1749 // We always run this as we prepare to initialize. |
1750 DCHECK_EQ(decoder_state_, kUninitialized); | 1750 DCHECK_EQ(decoder_state_, kUninitialized); |
1751 DCHECK(!mfc_input_streamon_); | 1751 DCHECK(!mfc_input_streamon_); |
1752 DCHECK(mfc_input_buffer_map_.empty()); | 1752 DCHECK(mfc_input_buffer_map_.empty()); |
1753 | 1753 |
1754 __u32 pixelformat = 0; | 1754 __u32 pixelformat = 0; |
1755 if (video_profile_ >= media::H264PROFILE_MIN && | 1755 if (video_profile_ >= media::H264PROFILE_MIN && |
1756 video_profile_ <= media::H264PROFILE_MAX) { | 1756 video_profile_ <= media::H264PROFILE_MAX) { |
1757 pixelformat = V4L2_PIX_FMT_H264; | 1757 pixelformat = V4L2_PIX_FMT_H264; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1798 DPLOG(ERROR) << "CreateMfcInputBuffers(): mmap() failed"; | 1798 DPLOG(ERROR) << "CreateMfcInputBuffers(): mmap() failed"; |
1799 return false; | 1799 return false; |
1800 } | 1800 } |
1801 mfc_input_buffer_map_[i].address = address; | 1801 mfc_input_buffer_map_[i].address = address; |
1802 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; | 1802 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; |
1803 } | 1803 } |
1804 | 1804 |
1805 return true; | 1805 return true; |
1806 } | 1806 } |
1807 | 1807 |
1808 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() { | 1808 bool V4l2VideoDecodeAccelerator::CreateMfcOutputBuffers() { |
1809 DVLOG(3) << "CreateMfcOutputBuffers()"; | 1809 DVLOG(3) << "CreateMfcOutputBuffers()"; |
1810 DCHECK(decoder_state_ == kInitialized || | 1810 DCHECK(decoder_state_ == kInitialized || |
1811 decoder_state_ == kChangingResolution); | 1811 decoder_state_ == kChangingResolution); |
1812 DCHECK(!mfc_output_streamon_); | 1812 DCHECK(!mfc_output_streamon_); |
1813 DCHECK(mfc_output_buffer_map_.empty()); | 1813 DCHECK(mfc_output_buffer_map_.empty()); |
1814 | 1814 |
1815 // Number of MFC output buffers we need. | 1815 // Number of MFC output buffers we need. |
1816 struct v4l2_control ctrl; | 1816 struct v4l2_control ctrl; |
1817 memset(&ctrl, 0, sizeof(ctrl)); | 1817 memset(&ctrl, 0, sizeof(ctrl)); |
1818 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; | 1818 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1853 child_message_loop_proxy_->PostTask(FROM_HERE, | 1853 child_message_loop_proxy_->PostTask(FROM_HERE, |
1854 base::Bind(&Client::ProvidePictureBuffers, | 1854 base::Bind(&Client::ProvidePictureBuffers, |
1855 client_, | 1855 client_, |
1856 mfc_output_buffer_map_.size(), | 1856 mfc_output_buffer_map_.size(), |
1857 frame_buffer_size_, | 1857 frame_buffer_size_, |
1858 GL_TEXTURE_EXTERNAL_OES)); | 1858 GL_TEXTURE_EXTERNAL_OES)); |
1859 | 1859 |
1860 return true; | 1860 return true; |
1861 } | 1861 } |
1862 | 1862 |
1863 void ExynosVideoDecodeAccelerator::DestroyMfcInputBuffers() { | 1863 void V4l2VideoDecodeAccelerator::DestroyMfcInputBuffers() { |
1864 DVLOG(3) << "DestroyMfcInputBuffers()"; | 1864 DVLOG(3) << "DestroyMfcInputBuffers()"; |
1865 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1865 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1866 DCHECK(!mfc_input_streamon_); | 1866 DCHECK(!mfc_input_streamon_); |
1867 | 1867 |
1868 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { | 1868 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { |
1869 if (mfc_input_buffer_map_[i].address != NULL) { | 1869 if (mfc_input_buffer_map_[i].address != NULL) { |
1870 munmap(mfc_input_buffer_map_[i].address, | 1870 munmap(mfc_input_buffer_map_[i].address, |
1871 mfc_input_buffer_map_[i].length); | 1871 mfc_input_buffer_map_[i].length); |
1872 } | 1872 } |
1873 } | 1873 } |
1874 | 1874 |
1875 struct v4l2_requestbuffers reqbufs; | 1875 struct v4l2_requestbuffers reqbufs; |
1876 memset(&reqbufs, 0, sizeof(reqbufs)); | 1876 memset(&reqbufs, 0, sizeof(reqbufs)); |
1877 reqbufs.count = 0; | 1877 reqbufs.count = 0; |
1878 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1878 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1879 reqbufs.memory = V4L2_MEMORY_MMAP; | 1879 reqbufs.memory = V4L2_MEMORY_MMAP; |
1880 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) | 1880 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) |
1881 DPLOG(ERROR) << "DestroyMfcInputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; | 1881 DPLOG(ERROR) << "DestroyMfcInputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; |
1882 | 1882 |
1883 mfc_input_buffer_map_.clear(); | 1883 mfc_input_buffer_map_.clear(); |
1884 mfc_free_input_buffers_.clear(); | 1884 mfc_free_input_buffers_.clear(); |
1885 } | 1885 } |
1886 | 1886 |
1887 void ExynosVideoDecodeAccelerator::DestroyMfcOutputBuffers() { | 1887 void V4l2VideoDecodeAccelerator::DestroyMfcOutputBuffers() { |
1888 DVLOG(3) << "DestroyMfcOutputBuffers()"; | 1888 DVLOG(3) << "DestroyMfcOutputBuffers()"; |
1889 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1889 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1890 DCHECK(!mfc_output_streamon_); | 1890 DCHECK(!mfc_output_streamon_); |
1891 | 1891 |
1892 if (mfc_output_buffer_map_.size() != 0) { | 1892 if (mfc_output_buffer_map_.size() != 0) { |
1893 // TODO(sheu, posciak): Making the context current should not be required | 1893 // TODO(sheu, posciak): Making the context current should not be required |
1894 // anymore. Remove it and verify (crbug.com/327869). | 1894 // anymore. Remove it and verify (crbug.com/327869). |
1895 if (!make_context_current_.Run()) { | 1895 if (!make_context_current_.Run()) { |
1896 DLOG(ERROR) << "DestroyMfcOutputBuffers(): " | 1896 DLOG(ERROR) << "DestroyMfcOutputBuffers(): " |
1897 << "could not make context current"; | 1897 << "could not make context current"; |
(...skipping 27 matching lines...) Expand all Loading... | |
1925 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1925 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1926 reqbufs.memory = V4L2_MEMORY_MMAP; | 1926 reqbufs.memory = V4L2_MEMORY_MMAP; |
1927 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) | 1927 if (ioctl(mfc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) |
1928 DPLOG(ERROR) << "DestroyMfcOutputBuffers() ioctl() failed: VIDIOC_REQBUFS"; | 1928 DPLOG(ERROR) << "DestroyMfcOutputBuffers() ioctl() failed: VIDIOC_REQBUFS"; |
1929 | 1929 |
1930 mfc_output_buffer_map_.clear(); | 1930 mfc_output_buffer_map_.clear(); |
1931 while (!mfc_free_output_buffers_.empty()) | 1931 while (!mfc_free_output_buffers_.empty()) |
1932 mfc_free_output_buffers_.pop(); | 1932 mfc_free_output_buffers_.pop(); |
1933 } | 1933 } |
1934 | 1934 |
1935 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { | 1935 void V4l2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { |
1936 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1936 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
1937 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; | 1937 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; |
1938 | 1938 |
1939 DestroyMfcOutputBuffers(); | 1939 DestroyMfcOutputBuffers(); |
1940 | 1940 |
1941 // Finish resolution change on decoder thread. | 1941 // Finish resolution change on decoder thread. |
1942 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1942 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1943 &ExynosVideoDecodeAccelerator::FinishResolutionChange, | 1943 &V4l2VideoDecodeAccelerator::FinishResolutionChange, |
1944 base::Unretained(this))); | 1944 base::Unretained(this))); |
1945 } | 1945 } |
1946 | 1946 |
1947 void ExynosVideoDecodeAccelerator::SendPictureReady() { | 1947 void V4l2VideoDecodeAccelerator::SendPictureReady() { |
1948 DVLOG(3) << "SendPictureReady()"; | 1948 DVLOG(3) << "SendPictureReady()"; |
1949 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1949 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1950 bool resetting_or_flushing = | 1950 bool resetting_or_flushing = |
1951 (decoder_state_ == kResetting || decoder_flushing_); | 1951 (decoder_state_ == kResetting || decoder_flushing_); |
1952 while (pending_picture_ready_.size() > 0) { | 1952 while (pending_picture_ready_.size() > 0) { |
1953 bool cleared = pending_picture_ready_.front().cleared; | 1953 bool cleared = pending_picture_ready_.front().cleared; |
1954 const media::Picture& picture = pending_picture_ready_.front().picture; | 1954 const media::Picture& picture = pending_picture_ready_.front().picture; |
1955 if (cleared && picture_clearing_count_ == 0) { | 1955 if (cleared && picture_clearing_count_ == 0) { |
1956 // This picture is cleared. Post it to IO thread to reduce latency. This | 1956 // This picture is cleared. Post it to IO thread to reduce latency. This |
1957 // should be the case after all pictures are cleared at the beginning. | 1957 // should be the case after all pictures are cleared at the beginning. |
1958 io_message_loop_proxy_->PostTask( | 1958 io_message_loop_proxy_->PostTask( |
1959 FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); | 1959 FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); |
1960 pending_picture_ready_.pop(); | 1960 pending_picture_ready_.pop(); |
1961 } else if (!cleared || resetting_or_flushing) { | 1961 } else if (!cleared || resetting_or_flushing) { |
1962 DVLOG(3) << "SendPictureReady()" | 1962 DVLOG(3) << "SendPictureReady()" |
1963 << ". cleared=" << pending_picture_ready_.front().cleared | 1963 << ". cleared=" << pending_picture_ready_.front().cleared |
1964 << ", decoder_state_=" << decoder_state_ | 1964 << ", decoder_state_=" << decoder_state_ |
1965 << ", decoder_flushing_=" << decoder_flushing_ | 1965 << ", decoder_flushing_=" << decoder_flushing_ |
1966 << ", picture_clearing_count_=" << picture_clearing_count_; | 1966 << ", picture_clearing_count_=" << picture_clearing_count_; |
1967 // If the picture is not cleared, post it to the child thread because it | 1967 // If the picture is not cleared, post it to the child thread because it |
1968 // has to be cleared in the child thread. A picture only needs to be | 1968 // has to be cleared in the child thread. A picture only needs to be |
1969 // cleared once. If the decoder is resetting or flushing, send all | 1969 // cleared once. If the decoder is resetting or flushing, send all |
1970 // pictures to ensure PictureReady arrive before reset or flush done. | 1970 // pictures to ensure PictureReady arrive before reset or flush done. |
1971 child_message_loop_proxy_->PostTaskAndReply( | 1971 child_message_loop_proxy_->PostTaskAndReply( |
1972 FROM_HERE, | 1972 FROM_HERE, |
1973 base::Bind(&Client::PictureReady, client_, picture), | 1973 base::Bind(&Client::PictureReady, client_, picture), |
1974 // Unretained is safe. If Client::PictureReady gets to run, |this| is | 1974 // Unretained is safe. If Client::PictureReady gets to run, |this| is |
1975 // alive. Destroy() will wait the decode thread to finish. | 1975 // alive. Destroy() will wait the decode thread to finish. |
1976 base::Bind(&ExynosVideoDecodeAccelerator::PictureCleared, | 1976 base::Bind(&V4l2VideoDecodeAccelerator::PictureCleared, |
1977 base::Unretained(this))); | 1977 base::Unretained(this))); |
1978 picture_clearing_count_++; | 1978 picture_clearing_count_++; |
1979 pending_picture_ready_.pop(); | 1979 pending_picture_ready_.pop(); |
1980 } else { | 1980 } else { |
1981 // This picture is cleared. But some pictures are about to be cleared on | 1981 // This picture is cleared. But some pictures are about to be cleared on |
1982 // the child thread. To preserve the order, do not send this until those | 1982 // the child thread. To preserve the order, do not send this until those |
1983 // pictures are cleared. | 1983 // pictures are cleared. |
1984 break; | 1984 break; |
1985 } | 1985 } |
1986 } | 1986 } |
1987 } | 1987 } |
1988 | 1988 |
1989 void ExynosVideoDecodeAccelerator::PictureCleared() { | 1989 void V4l2VideoDecodeAccelerator::PictureCleared() { |
1990 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_; | 1990 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_; |
1991 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1991 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1992 DCHECK_GT(picture_clearing_count_, 0); | 1992 DCHECK_GT(picture_clearing_count_, 0); |
1993 picture_clearing_count_--; | 1993 picture_clearing_count_--; |
1994 SendPictureReady(); | 1994 SendPictureReady(); |
1995 } | 1995 } |
1996 | 1996 |
1997 } // namespace content | 1997 } // namespace content |
OLD | NEW |