Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/gpu/vaapi_video_decode_accelerator.h" | 5 #include "media/gpu/vaapi_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 private: | 261 private: |
| 262 scoped_refptr<VaapiDecodeSurface> VP9PictureToVaapiDecodeSurface( | 262 scoped_refptr<VaapiDecodeSurface> VP9PictureToVaapiDecodeSurface( |
| 263 const scoped_refptr<VP9Picture>& pic); | 263 const scoped_refptr<VP9Picture>& pic); |
| 264 | 264 |
| 265 VaapiWrapper* vaapi_wrapper_; | 265 VaapiWrapper* vaapi_wrapper_; |
| 266 VaapiVideoDecodeAccelerator* vaapi_dec_; | 266 VaapiVideoDecodeAccelerator* vaapi_dec_; |
| 267 | 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(VaapiVP9Accelerator); | 268 DISALLOW_COPY_AND_ASSIGN(VaapiVP9Accelerator); |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0) {} | 271 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() {} |
| 272 | 272 |
| 273 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() {} | 273 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() {} |
| 274 | 274 |
| 275 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { | 275 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { |
| 276 if (!task_runner_->BelongsToCurrentThread()) { | 276 if (!task_runner_->BelongsToCurrentThread()) { |
| 277 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 277 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 278 task_runner_->PostTask(FROM_HERE, | 278 task_runner_->PostTask(FROM_HERE, |
| 279 base::Bind(&VaapiVideoDecodeAccelerator::NotifyError, | 279 base::Bind(&VaapiVideoDecodeAccelerator::NotifyError, |
| 280 weak_this_, error)); | 280 weak_this_, error)); |
| 281 return; | 281 return; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 VaapiPicture* picture = PictureById(output_buffers_.front()); | 454 VaapiPicture* picture = PictureById(output_buffers_.front()); |
| 455 DCHECK(picture); | 455 DCHECK(picture); |
| 456 output_buffers_.pop(); | 456 output_buffers_.pop(); |
| 457 | 457 |
| 458 output_cb.Run(picture); | 458 output_cb.Run(picture); |
| 459 | 459 |
| 460 if (finish_flush_pending_ && pending_output_cbs_.empty()) | 460 if (finish_flush_pending_ && pending_output_cbs_.empty()) |
| 461 FinishFlush(); | 461 FinishFlush(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( | 464 bool VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
| 465 const BitstreamBuffer& bitstream_buffer) { | 465 const BitstreamBuffer& bitstream_buffer) { |
| 466 DCHECK(task_runner_->BelongsToCurrentThread()); | 466 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 467 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", | 467 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
| 468 bitstream_buffer.id()); | 468 bitstream_buffer.id()); |
| 469 | 469 |
| 470 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id() | 470 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id() |
| 471 << " size: " << (int)bitstream_buffer.size(); | 471 << " size: " << (int)bitstream_buffer.size(); |
| 472 | 472 |
| 473 std::unique_ptr<SharedMemoryRegion> shm( | 473 std::unique_ptr<SharedMemoryRegion> shm( |
| 474 new SharedMemoryRegion(bitstream_buffer, true)); | 474 new SharedMemoryRegion(bitstream_buffer, true)); |
| 475 | 475 |
| 476 // Skip empty buffers. | 476 // Skip empty buffers. |
|
Owen Lin
2017/01/19 07:39:16
Please see my comment below. Let's do the check in
| |
| 477 if (bitstream_buffer.size() == 0) { | 477 if (bitstream_buffer.size() == 0) { |
| 478 if (client_) | 478 if (client_) |
| 479 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer.id()); | 479 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer.id()); |
| 480 return; | 480 return true; |
| 481 } | 481 } |
| 482 | 482 |
| 483 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(), "Failed to map input buffer", | 483 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(), "Failed to map input buffer", |
| 484 UNREADABLE_INPUT, ); | 484 UNREADABLE_INPUT, false); |
| 485 | 485 |
| 486 base::AutoLock auto_lock(lock_); | 486 base::AutoLock auto_lock(lock_); |
| 487 | 487 |
| 488 if (IsFlushPending_Locked()) { | |
| 489 LOG(ERROR) << "Shouldn't enqueue more input before FlushDone"; | |
| 490 if (client_) | |
| 491 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer.id()); | |
| 492 NotifyError(PLATFORM_FAILURE); | |
| 493 return false; | |
| 494 } | |
| 495 | |
| 488 // Set up a new input buffer and queue it for later. | 496 // Set up a new input buffer and queue it for later. |
| 489 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); | 497 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); |
| 490 input_buffer->shm = std::move(shm); | 498 input_buffer->shm = std::move(shm); |
| 491 input_buffer->id = bitstream_buffer.id(); | 499 input_buffer->id = bitstream_buffer.id(); |
| 492 | 500 |
| 493 ++num_stream_bufs_at_decoder_; | 501 ++num_stream_bufs_at_decoder_; |
| 494 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder", | 502 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder", |
| 495 num_stream_bufs_at_decoder_); | 503 num_stream_bufs_at_decoder_); |
| 496 | 504 |
| 497 input_buffers_.push(input_buffer); | 505 input_buffers_.push(input_buffer); |
| 498 input_ready_.Signal(); | 506 input_ready_.Signal(); |
| 507 return true; | |
| 499 } | 508 } |
| 500 | 509 |
| 501 bool VaapiVideoDecodeAccelerator::GetInputBuffer_Locked() { | 510 bool VaapiVideoDecodeAccelerator::GetInputBuffer_Locked() { |
| 502 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 511 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 503 lock_.AssertAcquired(); | 512 lock_.AssertAcquired(); |
| 504 | 513 |
| 505 if (curr_input_buffer_.get()) | 514 if (curr_input_buffer_.get()) |
| 506 return true; | 515 return true; |
| 507 | 516 |
| 508 // Will only wait if it is expected that in current state new buffers will | 517 // Will only wait if it is expected that in current state new buffers will |
| 509 // be queued from the client via Decode(). The state can change during wait. | 518 // be queued from the client via Decode(). The state can change during wait. |
| 510 while (input_buffers_.empty() && (state_ == kDecoding || state_ == kIdle)) { | 519 while (input_buffers_.empty() && (state_ == kDecoding || state_ == kIdle)) { |
| 511 input_ready_.Wait(); | 520 input_ready_.Wait(); |
| 512 } | 521 } |
| 513 | 522 |
| 514 // We could have got woken up in a different state or never got to sleep | 523 // We could have got woken up in a different state or never got to sleep |
| 515 // due to current state; check for that. | 524 // due to current state; check for that. |
| 516 switch (state_) { | 525 switch (state_) { |
| 517 case kFlushing: | |
| 518 // Here we are only interested in finishing up decoding buffers that are | |
| 519 // already queued up. Otherwise will stop decoding. | |
| 520 if (input_buffers_.empty()) | |
| 521 return false; | |
| 522 // else fallthrough | |
| 523 case kDecoding: | 526 case kDecoding: |
| 524 case kIdle: | 527 case kIdle: |
| 525 DCHECK(!input_buffers_.empty()); | 528 DCHECK(!input_buffers_.empty()); |
| 526 | 529 |
| 527 curr_input_buffer_ = input_buffers_.front(); | 530 curr_input_buffer_ = input_buffers_.front(); |
| 528 input_buffers_.pop(); | 531 input_buffers_.pop(); |
| 529 | 532 |
| 530 DVLOG(4) << "New current bitstream buffer, id: " << curr_input_buffer_->id | 533 if (curr_input_buffer_->dummy_flush) { |
| 531 << " size: " << curr_input_buffer_->shm->size(); | 534 DVLOG(4) << "New flush buffer"; |
| 535 } else { | |
| 536 DVLOG(4) << "New current bitstream buffer, id: " | |
| 537 << curr_input_buffer_->id | |
| 538 << " size: " << curr_input_buffer_->shm->size(); | |
| 532 | 539 |
| 533 decoder_->SetStream( | 540 decoder_->SetStream( |
| 534 static_cast<uint8_t*>(curr_input_buffer_->shm->memory()), | 541 static_cast<uint8_t*>(curr_input_buffer_->shm->memory()), |
| 535 curr_input_buffer_->shm->size()); | 542 curr_input_buffer_->shm->size()); |
| 543 } | |
| 536 return true; | 544 return true; |
| 537 | 545 |
| 538 default: | 546 default: |
| 539 // We got woken up due to being destroyed/reset, ignore any already | 547 // We got woken up due to being destroyed/reset, ignore any already |
| 540 // queued inputs. | 548 // queued inputs. |
| 541 return false; | 549 return false; |
| 542 } | 550 } |
| 543 } | 551 } |
| 544 | 552 |
| 545 void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer_Locked() { | 553 void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer_Locked() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 558 num_stream_bufs_at_decoder_); | 566 num_stream_bufs_at_decoder_); |
| 559 } | 567 } |
| 560 | 568 |
| 561 // TODO(posciak): refactor the whole class to remove sleeping in wait for | 569 // TODO(posciak): refactor the whole class to remove sleeping in wait for |
| 562 // surfaces, and reschedule DecodeTask instead. | 570 // surfaces, and reschedule DecodeTask instead. |
| 563 bool VaapiVideoDecodeAccelerator::WaitForSurfaces_Locked() { | 571 bool VaapiVideoDecodeAccelerator::WaitForSurfaces_Locked() { |
| 564 lock_.AssertAcquired(); | 572 lock_.AssertAcquired(); |
| 565 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 573 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 566 | 574 |
| 567 while (available_va_surfaces_.empty() && | 575 while (available_va_surfaces_.empty() && |
| 568 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { | 576 (state_ == kDecoding || state_ == kIdle)) { |
| 569 surfaces_available_.Wait(); | 577 surfaces_available_.Wait(); |
| 570 } | 578 } |
| 571 | 579 |
| 572 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle) | 580 if (state_ != kDecoding && state_ != kIdle) |
| 573 return false; | 581 return false; |
| 574 | 582 |
| 575 return true; | 583 return true; |
| 576 } | 584 } |
| 577 | 585 |
| 586 bool VaapiVideoDecodeAccelerator::IsFlushPending_Locked() { | |
|
Owen Lin
2017/01/19 07:39:16
I am thinking maybe we can get rid of this functio
kcwu
2017/01/19 08:26:10
It's intentional to reject them since this is inva
Owen Lin
2017/01/20 02:20:06
Yes, I see your point and it makes totally sense.
| |
| 587 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 588 | |
| 589 if (finish_flush_pending_) | |
| 590 return true; | |
| 591 | |
| 592 if (curr_input_buffer_.get() && curr_input_buffer_->dummy_flush) | |
| 593 return true; | |
| 594 | |
| 595 // Checking last element of |input_buffers_| is enough because no more | |
| 596 // buffers will be queued after flush. | |
| 597 return !input_buffers_.empty() && input_buffers_.back()->dummy_flush; | |
| 598 } | |
| 599 | |
| 578 void VaapiVideoDecodeAccelerator::DecodeTask() { | 600 void VaapiVideoDecodeAccelerator::DecodeTask() { |
| 579 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 601 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 580 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); | 602 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); |
| 581 base::AutoLock auto_lock(lock_); | 603 base::AutoLock auto_lock(lock_); |
| 582 | 604 |
| 583 if (state_ != kDecoding) | 605 if (state_ != kDecoding) |
| 584 return; | 606 return; |
| 585 | 607 |
| 586 // Main decode task. | 608 // Main decode task. |
| 587 DVLOG(4) << "Decode task"; | 609 DVLOG(4) << "Decode task"; |
| 588 | 610 |
| 589 // Try to decode what stream data is (still) in the decoder until we run out | 611 // Try to decode what stream data is (still) in the decoder until we run out |
| 590 // of it. | 612 // of it. |
| 591 while (GetInputBuffer_Locked()) { | 613 while (GetInputBuffer_Locked()) { |
| 592 DCHECK(curr_input_buffer_.get()); | 614 DCHECK(curr_input_buffer_.get()); |
| 593 | 615 |
| 616 if (curr_input_buffer_->dummy_flush) { | |
| 617 FlushTask(); | |
| 618 break; | |
| 619 } | |
| 620 | |
| 594 AcceleratedVideoDecoder::DecodeResult res; | 621 AcceleratedVideoDecoder::DecodeResult res; |
| 595 { | 622 { |
| 596 // We are OK releasing the lock here, as decoder never calls our methods | 623 // We are OK releasing the lock here, as decoder never calls our methods |
| 597 // directly and we will reacquire the lock before looking at state again. | 624 // directly and we will reacquire the lock before looking at state again. |
| 598 // This is the main decode function of the decoder and while keeping | 625 // This is the main decode function of the decoder and while keeping |
| 599 // the lock for its duration would be fine, it would defeat the purpose | 626 // the lock for its duration would be fine, it would defeat the purpose |
| 600 // of having a separate decoder thread. | 627 // of having a separate decoder thread. |
| 601 base::AutoUnlock auto_unlock(lock_); | 628 base::AutoUnlock auto_unlock(lock_); |
| 602 res = decoder_->Decode(); | 629 res = decoder_->Decode(); |
| 603 } | 630 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 729 | 756 |
| 730 if (bitstream_buffer.id() < 0) { | 757 if (bitstream_buffer.id() < 0) { |
| 731 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) | 758 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) |
| 732 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); | 759 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); |
| 733 LOG(ERROR) << "Invalid bitstream_buffer, id: " << bitstream_buffer.id(); | 760 LOG(ERROR) << "Invalid bitstream_buffer, id: " << bitstream_buffer.id(); |
| 734 NotifyError(INVALID_ARGUMENT); | 761 NotifyError(INVALID_ARGUMENT); |
| 735 return; | 762 return; |
| 736 } | 763 } |
| 737 | 764 |
| 738 // We got a new input buffer from the client, map it and queue for later use. | 765 // We got a new input buffer from the client, map it and queue for later use. |
| 739 MapAndQueueNewInputBuffer(bitstream_buffer); | 766 if (!MapAndQueueNewInputBuffer(bitstream_buffer)) |
| 767 return; | |
| 740 | 768 |
| 741 base::AutoLock auto_lock(lock_); | 769 base::AutoLock auto_lock(lock_); |
| 742 switch (state_) { | 770 switch (state_) { |
| 743 case kIdle: | 771 case kIdle: |
| 744 state_ = kDecoding; | 772 state_ = kDecoding; |
| 745 decoder_thread_task_runner_->PostTask( | 773 decoder_thread_task_runner_->PostTask( |
| 746 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, | 774 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, |
| 747 base::Unretained(this))); | 775 base::Unretained(this))); |
| 748 break; | 776 break; |
| 749 | 777 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 RETURN_AND_NOTIFY_ON_FAILURE( | 845 RETURN_AND_NOTIFY_ON_FAILURE( |
| 818 picture->Allocate(output_format_), | 846 picture->Allocate(output_format_), |
| 819 "Failed to allocate memory for a VaapiPicture", PLATFORM_FAILURE, ); | 847 "Failed to allocate memory for a VaapiPicture", PLATFORM_FAILURE, ); |
| 820 output_buffers_.push(buffers[i].id()); | 848 output_buffers_.push(buffers[i].id()); |
| 821 } | 849 } |
| 822 | 850 |
| 823 available_va_surfaces_.push_back(va_surface_ids[i]); | 851 available_va_surfaces_.push_back(va_surface_ids[i]); |
| 824 surfaces_available_.Signal(); | 852 surfaces_available_.Signal(); |
| 825 } | 853 } |
| 826 | 854 |
| 827 // The resolution changing may happen while resetting or flushing. In this | 855 // Resume DecodeTask if it is still in decoding state. |
| 828 // case we do not change state and post DecodeTask(). | 856 if (state_ == kDecoding) { |
| 829 if (state_ != kResetting && state_ != kFlushing) { | |
| 830 state_ = kDecoding; | |
| 831 decoder_thread_task_runner_->PostTask( | 857 decoder_thread_task_runner_->PostTask( |
| 832 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, | 858 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, |
| 833 base::Unretained(this))); | 859 base::Unretained(this))); |
| 834 } | 860 } |
| 835 } | 861 } |
| 836 | 862 |
| 837 #if defined(USE_OZONE) | 863 #if defined(USE_OZONE) |
| 838 static void CloseGpuMemoryBufferHandle( | 864 static void CloseGpuMemoryBufferHandle( |
| 839 const gfx::GpuMemoryBufferHandle& handle) { | 865 const gfx::GpuMemoryBufferHandle& handle) { |
| 840 for (const auto& fd : handle.native_pixmap_handle.fds) { | 866 for (const auto& fd : handle.native_pixmap_handle.fds) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 | 927 |
| 902 --num_frames_at_client_; | 928 --num_frames_at_client_; |
| 903 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 929 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
| 904 | 930 |
| 905 output_buffers_.push(picture_buffer_id); | 931 output_buffers_.push(picture_buffer_id); |
| 906 TryOutputSurface(); | 932 TryOutputSurface(); |
| 907 } | 933 } |
| 908 | 934 |
| 909 void VaapiVideoDecodeAccelerator::FlushTask() { | 935 void VaapiVideoDecodeAccelerator::FlushTask() { |
| 910 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 936 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 937 DCHECK(input_buffers_.empty()) << "Input buffers should be empty because" | |
|
Owen Lin
2017/01/19 07:39:16
It looks like a comment instead of what we should
kcwu
2017/01/20 07:49:03
Code removed.
| |
| 938 << " the client cannot queue buffers before" | |
| 939 << " FlushDone"; | |
| 940 DCHECK(curr_input_buffer_.get() && curr_input_buffer_->dummy_flush); | |
| 941 | |
| 911 DVLOG(1) << "Flush task"; | 942 DVLOG(1) << "Flush task"; |
| 912 | 943 |
| 944 curr_input_buffer_.reset(); | |
| 945 | |
| 913 // First flush all the pictures that haven't been outputted, notifying the | 946 // First flush all the pictures that haven't been outputted, notifying the |
| 914 // client to output them. | 947 // client to output them. |
| 915 bool res = decoder_->Flush(); | 948 bool res = decoder_->Flush(); |
| 916 RETURN_AND_NOTIFY_ON_FAILURE(res, "Failed flushing the decoder.", | 949 RETURN_AND_NOTIFY_ON_FAILURE(res, "Failed flushing the decoder.", |
| 917 PLATFORM_FAILURE, ); | 950 PLATFORM_FAILURE, ); |
| 918 | 951 |
| 919 // Put the decoder in idle state, ready to resume. | 952 // Put the decoder in idle state, ready to resume. |
| 920 decoder_->Reset(); | 953 decoder_->Reset(); |
| 921 | 954 |
| 922 task_runner_->PostTask( | 955 task_runner_->PostTask( |
| 923 FROM_HERE, | 956 FROM_HERE, |
| 924 base::Bind(&VaapiVideoDecodeAccelerator::FinishFlush, weak_this_)); | 957 base::Bind(&VaapiVideoDecodeAccelerator::FinishFlush, weak_this_)); |
| 925 } | 958 } |
| 926 | 959 |
| 927 void VaapiVideoDecodeAccelerator::Flush() { | 960 void VaapiVideoDecodeAccelerator::Flush() { |
| 928 DCHECK(task_runner_->BelongsToCurrentThread()); | 961 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 929 DVLOG(1) << "Got flush request"; | 962 DVLOG(1) << "Got flush request"; |
| 930 | 963 |
| 931 base::AutoLock auto_lock(lock_); | 964 base::AutoLock auto_lock(lock_); |
| 932 state_ = kFlushing; | 965 if (IsFlushPending_Locked()) { |
| 933 // Queue a flush task after all existing decoding tasks to clean up. | 966 LOG(ERROR) << "Shouldn't Flush again before FlushDone"; |
| 934 decoder_thread_task_runner_->PostTask( | 967 NotifyError(PLATFORM_FAILURE); |
| 935 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::FlushTask, | 968 return; |
| 936 base::Unretained(this))); | 969 } |
| 970 | |
| 971 switch (state_) { | |
| 972 case kIdle: | |
| 973 state_ = kDecoding; | |
| 974 decoder_thread_task_runner_->PostTask( | |
| 975 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, | |
|
Owen Lin
2017/01/19 07:39:16
Can we extract the common part of this function an
kcwu
2017/01/19 08:26:10
Regarding to Flush() to use empty buffer, I don't
Owen Lin
2017/01/20 02:20:06
First, empty buffer is not invalid, we do accept e
kcwu
2017/01/20 07:49:03
Done.
| |
| 976 base::Unretained(this))); | |
| 977 break; | |
| 978 | |
| 979 case kDecoding: | |
| 980 // Decoder already running. | |
| 981 break; | |
| 982 | |
| 983 case kResetting: | |
| 984 // When resetting, allow accumulating bitstream buffers, so that | |
| 985 // the client can queue after-seek-buffers while we are finishing with | |
| 986 // the before-seek one. | |
| 987 break; | |
| 988 | |
| 989 default: | |
| 990 RETURN_AND_NOTIFY_ON_FAILURE( | |
| 991 false, "Decode request from client in invalid state: " << state_, | |
| 992 PLATFORM_FAILURE, ); | |
| 993 break; | |
| 994 } | |
| 995 | |
| 996 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); | |
| 997 input_buffer->dummy_flush = true; | |
| 998 input_buffers_.push(input_buffer); | |
| 937 | 999 |
| 938 input_ready_.Signal(); | 1000 input_ready_.Signal(); |
| 939 surfaces_available_.Signal(); | 1001 surfaces_available_.Signal(); |
| 940 } | 1002 } |
| 941 | 1003 |
| 942 void VaapiVideoDecodeAccelerator::FinishFlush() { | 1004 void VaapiVideoDecodeAccelerator::FinishFlush() { |
| 943 DCHECK(task_runner_->BelongsToCurrentThread()); | 1005 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 944 | 1006 |
| 945 finish_flush_pending_ = false; | 1007 finish_flush_pending_ = false; |
| 946 | 1008 |
| 947 base::AutoLock auto_lock(lock_); | 1009 base::AutoLock auto_lock(lock_); |
| 948 if (state_ != kFlushing) { | 1010 if (state_ != kDecoding) { |
| 949 DCHECK_EQ(state_, kDestroying); | 1011 DCHECK_EQ(state_, kDestroying); |
| 950 return; // We could've gotten destroyed already. | 1012 return; // We could've gotten destroyed already. |
| 951 } | 1013 } |
| 952 | 1014 |
| 953 // Still waiting for textures from client to finish outputting all pending | 1015 // Still waiting for textures from client to finish outputting all pending |
| 954 // frames. Try again later. | 1016 // frames. Try again later. |
| 955 if (!pending_output_cbs_.empty()) { | 1017 if (!pending_output_cbs_.empty()) { |
| 956 finish_flush_pending_ = true; | 1018 finish_flush_pending_ = true; |
| 957 return; | 1019 return; |
| 958 } | 1020 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 DCHECK(task_runner_->BelongsToCurrentThread()); | 1052 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 991 DVLOG(1) << "Got reset request"; | 1053 DVLOG(1) << "Got reset request"; |
| 992 | 1054 |
| 993 // This will make any new decode tasks exit early. | 1055 // This will make any new decode tasks exit early. |
| 994 base::AutoLock auto_lock(lock_); | 1056 base::AutoLock auto_lock(lock_); |
| 995 state_ = kResetting; | 1057 state_ = kResetting; |
| 996 finish_flush_pending_ = false; | 1058 finish_flush_pending_ = false; |
| 997 | 1059 |
| 998 // Drop all remaining input buffers, if present. | 1060 // Drop all remaining input buffers, if present. |
| 999 while (!input_buffers_.empty()) { | 1061 while (!input_buffers_.empty()) { |
| 1000 task_runner_->PostTask( | 1062 const auto& input_buffer = input_buffers_.front(); |
| 1001 FROM_HERE, base::Bind(&Client::NotifyEndOfBitstreamBuffer, client_, | 1063 if (!input_buffer->dummy_flush) |
| 1002 input_buffers_.front()->id)); | 1064 task_runner_->PostTask( |
| 1065 FROM_HERE, base::Bind(&Client::NotifyEndOfBitstreamBuffer, client_, | |
| 1066 input_buffer->id)); | |
| 1003 input_buffers_.pop(); | 1067 input_buffers_.pop(); |
| 1004 } | 1068 } |
| 1005 | 1069 |
| 1006 decoder_thread_task_runner_->PostTask( | 1070 decoder_thread_task_runner_->PostTask( |
| 1007 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::ResetTask, | 1071 FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::ResetTask, |
| 1008 base::Unretained(this))); | 1072 base::Unretained(this))); |
| 1009 | 1073 |
| 1010 input_ready_.Signal(); | 1074 input_ready_.Signal(); |
| 1011 surfaces_available_.Signal(); | 1075 surfaces_available_.Signal(); |
| 1012 } | 1076 } |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1880 return vaapi_pic->dec_surface(); | 1944 return vaapi_pic->dec_surface(); |
| 1881 } | 1945 } |
| 1882 | 1946 |
| 1883 // static | 1947 // static |
| 1884 VideoDecodeAccelerator::SupportedProfiles | 1948 VideoDecodeAccelerator::SupportedProfiles |
| 1885 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { | 1949 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { |
| 1886 return VaapiWrapper::GetSupportedDecodeProfiles(); | 1950 return VaapiWrapper::GetSupportedDecodeProfiles(); |
| 1887 } | 1951 } |
| 1888 | 1952 |
| 1889 } // namespace media | 1953 } // namespace media |
| OLD | NEW |