Commit 8b958fa4 authored by marcheu@chromium.org's avatar marcheu@chromium.org

VAVDA: Fix locking.

Ensure proper locking around all uses of curr_input_buffer_ and input_buffers_.

TEST=by hand
BUG=none

Change-Id: I4cc92a1b0be47ce95bc0def580a88ac3a9f7deec


Review URL: https://chromiumcodereview.appspot.com/10853005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149973 0039d316-1c4b-4281-b951-d872f2087c98
parent 045b9974
...@@ -129,13 +129,14 @@ void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( ...@@ -129,13 +129,14 @@ void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer(
RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()), RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()),
"Failed to map input buffer", UNREADABLE_INPUT,); "Failed to map input buffer", UNREADABLE_INPUT,);
base::AutoLock auto_lock(lock_);
// Set up a new input buffer and queue it for later. // Set up a new input buffer and queue it for later.
linked_ptr<InputBuffer> input_buffer(new InputBuffer()); linked_ptr<InputBuffer> input_buffer(new InputBuffer());
input_buffer->shm.reset(shm.release()); input_buffer->shm.reset(shm.release());
input_buffer->id = bitstream_buffer.id(); input_buffer->id = bitstream_buffer.id();
input_buffer->size = bitstream_buffer.size(); input_buffer->size = bitstream_buffer.size();
base::AutoLock auto_lock(lock_);
input_buffers_.push(input_buffer); input_buffers_.push(input_buffer);
input_ready_.Signal(); input_ready_.Signal();
} }
...@@ -157,10 +158,15 @@ void VaapiVideoDecodeAccelerator::InitialDecodeTask() { ...@@ -157,10 +158,15 @@ void VaapiVideoDecodeAccelerator::InitialDecodeTask() {
for (;;) { for (;;) {
if (!GetInputBuffer()) if (!GetInputBuffer())
return; return;
DCHECK(curr_input_buffer_.get());
VaapiH264Decoder::DecResult res = decoder_.DecodeInitial( int32 id = 0;
curr_input_buffer_->id); {
base::AutoLock auto_lock(lock_);
DCHECK(curr_input_buffer_.get());
id = curr_input_buffer_->id;
}
VaapiH264Decoder::DecResult res = decoder_.DecodeInitial(id);
switch (res) { switch (res) {
case VaapiH264Decoder::kReadyToDecode: case VaapiH264Decoder::kReadyToDecode:
if (state_ == kInitialized) { if (state_ == kInitialized) {
...@@ -247,11 +253,11 @@ bool VaapiVideoDecodeAccelerator::GetInputBuffer() { ...@@ -247,11 +253,11 @@ bool VaapiVideoDecodeAccelerator::GetInputBuffer() {
} }
} }
void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer() { void VaapiVideoDecodeAccelerator::ReturnCurrInputBufferLocked() {
lock_.AssertAcquired();
DCHECK_EQ(decoder_thread_.message_loop(), MessageLoop::current()); DCHECK_EQ(decoder_thread_.message_loop(), MessageLoop::current());
base::AutoLock auto_lock(lock_);
DCHECK(curr_input_buffer_.get()); DCHECK(curr_input_buffer_.get());
int32 id = curr_input_buffer_->id; int32 id = curr_input_buffer_->id;
curr_input_buffer_.reset(); curr_input_buffer_.reset();
DVLOG(4) << "End of input buffer " << id; DVLOG(4) << "End of input buffer " << id;
...@@ -259,6 +265,11 @@ void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer() { ...@@ -259,6 +265,11 @@ void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer() {
&Client::NotifyEndOfBitstreamBuffer, client_, id)); &Client::NotifyEndOfBitstreamBuffer, client_, id));
} }
void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer() {
base::AutoLock auto_lock(lock_);
ReturnCurrInputBufferLocked();
}
bool VaapiVideoDecodeAccelerator::GetOutputBuffers() { bool VaapiVideoDecodeAccelerator::GetOutputBuffers() {
DCHECK_EQ(decoder_thread_.message_loop(), MessageLoop::current()); DCHECK_EQ(decoder_thread_.message_loop(), MessageLoop::current());
...@@ -292,10 +303,15 @@ void VaapiVideoDecodeAccelerator::DecodeTask() { ...@@ -292,10 +303,15 @@ void VaapiVideoDecodeAccelerator::DecodeTask() {
if (!GetInputBuffer()) if (!GetInputBuffer())
// Early exit requested. // Early exit requested.
return; return;
DCHECK(curr_input_buffer_.get());
VaapiH264Decoder::DecResult res = int32 id = 0;
decoder_.DecodeOneFrame(curr_input_buffer_->id); {
base::AutoLock auto_lock(lock_);
DCHECK(curr_input_buffer_.get());
id = curr_input_buffer_->id;
}
VaapiH264Decoder::DecResult res = decoder_.DecodeOneFrame(id);
switch (res) { switch (res) {
case VaapiH264Decoder::kNeedMoreStreamData: case VaapiH264Decoder::kNeedMoreStreamData:
ReturnCurrInputBuffer(); ReturnCurrInputBuffer();
...@@ -454,9 +470,11 @@ void VaapiVideoDecodeAccelerator::ResetTask() { ...@@ -454,9 +470,11 @@ void VaapiVideoDecodeAccelerator::ResetTask() {
// to call Decode() after Reset() and before NotifyResetDone. // to call Decode() after Reset() and before NotifyResetDone.
decoder_.Reset(); decoder_.Reset();
base::AutoLock auto_lock(lock_);
// Return current input buffer, if present. // Return current input buffer, if present.
if (curr_input_buffer_.get()) if (curr_input_buffer_.get())
ReturnCurrInputBuffer(); ReturnCurrInputBufferLocked();
// And let client know that we are done with reset. // And let client know that we are done with reset.
message_loop_->PostTask(FROM_HERE, base::Bind( message_loop_->PostTask(FROM_HERE, base::Bind(
......
...@@ -77,6 +77,7 @@ class CONTENT_EXPORT VaapiVideoDecodeAccelerator : ...@@ -77,6 +77,7 @@ class CONTENT_EXPORT VaapiVideoDecodeAccelerator :
// Signal the client that the current buffer has been read and can be // Signal the client that the current buffer has been read and can be
// returned. Will also release the mapping. // returned. Will also release the mapping.
void ReturnCurrInputBufferLocked();
void ReturnCurrInputBuffer(); void ReturnCurrInputBuffer();
// Get and set up one or more output buffers in the decoder. This will sleep // Get and set up one or more output buffers in the decoder. This will sleep
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment