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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/debug/trace_event.h" | 6 #include "base/debug/trace_event.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 } while (0) | 37 } while (0) |
38 | 38 |
39 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0), size(0) { | 39 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0), size(0) { |
40 } | 40 } |
41 | 41 |
42 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() { | 42 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() { |
43 } | 43 } |
44 | 44 |
45 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { | 45 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { |
46 if (message_loop_ != base::MessageLoop::current()) { | 46 if (message_loop_ != base::MessageLoop::current()) { |
47 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
48 message_loop_->PostTask(FROM_HERE, base::Bind( | 47 message_loop_->PostTask(FROM_HERE, base::Bind( |
49 &VaapiVideoDecodeAccelerator::NotifyError, weak_this_, error)); | 48 &VaapiVideoDecodeAccelerator::NotifyError, weak_this_, error)); |
50 return; | 49 return; |
51 } | 50 } |
52 | 51 |
53 // Post Cleanup() as a task so we don't recursively acquire lock_. | 52 // Post Cleanup() as a task so we don't recursively acquire lock_. |
54 message_loop_->PostTask(FROM_HERE, base::Bind( | 53 message_loop_->PostTask(FROM_HERE, base::Bind( |
55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); | 54 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); |
56 | 55 |
57 DVLOG(1) << "Notifying of error " << error; | 56 DVLOG(1) << "Notifying of error " << error; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; | 234 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; |
236 return NULL; | 235 return NULL; |
237 } | 236 } |
238 | 237 |
239 return it->second.get(); | 238 return it->second.get(); |
240 } | 239 } |
241 | 240 |
242 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 241 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
243 Display* x_display, GLXContext glx_context, | 242 Display* x_display, GLXContext glx_context, |
244 Client* client, | 243 Client* client, |
245 const base::Callback<bool(void)>& make_context_current) | 244 const base::Callback<bool(void)>& make_context_current, |
245 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); | |
246 : x_display_(x_display), | 246 : x_display_(x_display), |
247 glx_context_(glx_context), | 247 glx_context_(glx_context), |
248 make_context_current_(make_context_current), | 248 make_context_current_(make_context_current), |
249 state_(kUninitialized), | 249 state_(kUninitialized), |
250 input_ready_(&lock_), | 250 input_ready_(&lock_), |
251 surfaces_available_(&lock_), | 251 surfaces_available_(&lock_), |
252 message_loop_(base::MessageLoop::current()), | 252 message_loop_(base::MessageLoop::current()), |
253 io_message_loop_(io_message_loop), | |
253 weak_this_(base::AsWeakPtr(this)), | 254 weak_this_(base::AsWeakPtr(this)), |
254 client_ptr_factory_(client), | 255 client_ptr_factory_(client), |
255 client_(client_ptr_factory_.GetWeakPtr()), | 256 client_(client_ptr_factory_.GetWeakPtr()), |
256 decoder_thread_("VaapiDecoderThread"), | 257 decoder_thread_("VaapiDecoderThread"), |
257 num_frames_at_client_(0), | 258 num_frames_at_client_(0), |
258 num_stream_bufs_at_decoder_(0), | 259 num_stream_bufs_at_decoder_(0), |
259 finish_flush_pending_(false), | 260 finish_flush_pending_(false), |
260 awaiting_va_surfaces_recycle_(false), | 261 awaiting_va_surfaces_recycle_(false), |
261 requested_num_pics_(0) { | 262 requested_num_pics_(0) { |
262 DCHECK(client); | 263 DCHECK(client); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 output_buffers_.pop(); | 405 output_buffers_.pop(); |
405 | 406 |
406 output_cb.Run(tfp_picture); | 407 output_cb.Run(tfp_picture); |
407 | 408 |
408 if (finish_flush_pending_ && pending_output_cbs_.empty()) | 409 if (finish_flush_pending_ && pending_output_cbs_.empty()) |
409 FinishFlush(); | 410 FinishFlush(); |
410 } | 411 } |
411 | 412 |
412 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( | 413 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
413 const media::BitstreamBuffer& bitstream_buffer) { | 414 const media::BitstreamBuffer& bitstream_buffer) { |
414 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 415 DCHECK_EQ(io_message_loop_, base::MessageLoop::current()); |
415 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", | 416 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
416 bitstream_buffer.id()); | 417 bitstream_buffer.id()); |
417 | 418 |
418 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id() | 419 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id() |
419 << " size: " << (int)bitstream_buffer.size(); | 420 << " size: " << (int)bitstream_buffer.size(); |
420 | 421 |
421 scoped_ptr<base::SharedMemory> shm( | 422 scoped_ptr<base::SharedMemory> shm( |
422 new base::SharedMemory(bitstream_buffer.handle(), true)); | 423 new base::SharedMemory(bitstream_buffer.handle(), true)); |
423 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()), | 424 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()), |
piman
2013/08/27 04:01:20
The Map() can take a long time. Can you move it to
wuchengli
2013/08/27 12:32:24
I reverted this and let CanDecodeOnIOThread return
| |
424 "Failed to map input buffer", UNREADABLE_INPUT,); | 425 "Failed to map input buffer", UNREADABLE_INPUT,); |
425 | 426 |
426 base::AutoLock auto_lock(lock_); | 427 base::AutoLock auto_lock(lock_); |
piman
2013/08/27 04:01:20
What else takes this lock? Can it be held for a lo
wuchengli
2013/08/27 12:32:24
I reverted this and let CanDecodeOnIOThread return
| |
427 | 428 |
428 // Set up a new input buffer and queue it for later. | 429 // Set up a new input buffer and queue it for later. |
429 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); | 430 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); |
430 input_buffer->shm.reset(shm.release()); | 431 input_buffer->shm.reset(shm.release()); |
431 input_buffer->id = bitstream_buffer.id(); | 432 input_buffer->id = bitstream_buffer.id(); |
432 input_buffer->size = bitstream_buffer.size(); | 433 input_buffer->size = bitstream_buffer.size(); |
433 | 434 |
434 ++num_stream_bufs_at_decoder_; | 435 ++num_stream_bufs_at_decoder_; |
435 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder", | 436 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder", |
436 num_stream_bufs_at_decoder_); | 437 num_stream_bufs_at_decoder_); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " | 640 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " |
640 << requested_pic_size_.ToString(); | 641 << requested_pic_size_.ToString(); |
641 | 642 |
642 message_loop_->PostTask(FROM_HERE, base::Bind( | 643 message_loop_->PostTask(FROM_HERE, base::Bind( |
643 &Client::ProvidePictureBuffers, client_, | 644 &Client::ProvidePictureBuffers, client_, |
644 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); | 645 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); |
645 } | 646 } |
646 | 647 |
647 void VaapiVideoDecodeAccelerator::Decode( | 648 void VaapiVideoDecodeAccelerator::Decode( |
648 const media::BitstreamBuffer& bitstream_buffer) { | 649 const media::BitstreamBuffer& bitstream_buffer) { |
649 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 650 DCHECK_EQ(io_message_loop_, base::MessageLoop::current()); |
650 | 651 |
651 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", | 652 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", |
652 bitstream_buffer.id()); | 653 bitstream_buffer.id()); |
653 | 654 |
654 // We got a new input buffer from the client, map it and queue for later use. | 655 // We got a new input buffer from the client, map it and queue for later use. |
655 MapAndQueueNewInputBuffer(bitstream_buffer); | 656 MapAndQueueNewInputBuffer(bitstream_buffer); |
656 | 657 |
657 base::AutoLock auto_lock(lock_); | 658 base::AutoLock auto_lock(lock_); |
658 switch (state_) { | 659 switch (state_) { |
659 case kIdle: | 660 case kIdle: |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 state_ = kUninitialized; | 926 state_ = kUninitialized; |
926 } | 927 } |
927 | 928 |
928 void VaapiVideoDecodeAccelerator::Destroy() { | 929 void VaapiVideoDecodeAccelerator::Destroy() { |
929 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 930 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
930 Cleanup(); | 931 Cleanup(); |
931 delete this; | 932 delete this; |
932 } | 933 } |
933 | 934 |
934 } // namespace content | 935 } // namespace content |
OLD | NEW |