Commit d527cdd8 authored by piman@chromium.org's avatar piman@chromium.org

Gracefully handle multiple Flush/Reset/Decode with same id

The DCHECKs don't trigger in release, and in any case it's a bit rude to have
the renderer crash on a plugin that did the wrong thing, so send an error
instead.

BUG=None
TEST=Pepper Flash


Review URL: http://codereview.chromium.org/7628025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96649 0039d316-1c4b-4281-b951-d872f2087c98
parent ae3ac175
......@@ -96,7 +96,8 @@ int32_t VideoDecoder::Decode(
if (enter_buffer.failed())
return PP_ERROR_BADRESOURCE;
SetBitstreamBufferCallback(bitstream_buffer->id, callback);
if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback))
return PP_ERROR_BADARGUMENT;
Buffer* ppb_buffer =
static_cast<Buffer*>(enter_buffer.object());
......@@ -127,7 +128,8 @@ void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) {
}
int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
SetFlushCallback(callback);
if (!SetFlushCallback(callback))
return PP_ERROR_INPROGRESS;
FlushCommandBuffer();
GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Flush(
......@@ -136,7 +138,8 @@ int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
}
int32_t VideoDecoder::Reset(PP_CompletionCallback callback) {
SetResetCallback(callback);
if (!SetResetCallback(callback))
return PP_ERROR_INPROGRESS;
FlushCommandBuffer();
GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset(
......
......@@ -44,22 +44,26 @@ void VideoDecoderImpl::Destroy() {
UnrefResource(context3d_id_);
}
void VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) {
bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) {
CHECK(callback.func);
DCHECK(!flush_callback_.func);
if (flush_callback_.func)
return false;
flush_callback_ = callback;
return true;
}
void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) {
bool VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) {
CHECK(callback.func);
DCHECK(!reset_callback_.func);
if (reset_callback_.func)
return false;
reset_callback_ = callback;
return true;
}
void VideoDecoderImpl::SetBitstreamBufferCallback(
bool VideoDecoderImpl::SetBitstreamBufferCallback(
int32 bitstream_buffer_id, PP_CompletionCallback callback) {
CHECK(bitstream_buffer_callbacks_.insert(
std::make_pair(bitstream_buffer_id, callback)).second);
return bitstream_buffer_callbacks_.insert(
std::make_pair(bitstream_buffer_id, callback)).second;
}
void VideoDecoderImpl::RunFlushCallback(int32 result) {
......
......@@ -44,9 +44,9 @@ class VideoDecoderImpl : public thunk::PPB_VideoDecoder_API {
std::vector<PP_VideoConfigElement>* out_configs);
protected:
void SetFlushCallback(PP_CompletionCallback callback);
void SetResetCallback(PP_CompletionCallback callback);
void SetBitstreamBufferCallback(
bool SetFlushCallback(PP_CompletionCallback callback);
bool SetResetCallback(PP_CompletionCallback callback);
bool SetBitstreamBufferCallback(
int32 bitstream_buffer_id, PP_CompletionCallback callback);
void RunFlushCallback(int32 result);
......
......@@ -104,7 +104,8 @@ int32_t PPB_VideoDecoder_Impl::Decode(
bitstream_buffer->id,
buffer->shared_memory()->handle(),
static_cast<size_t>(bitstream_buffer->size));
SetBitstreamBufferCallback(bitstream_buffer->id, callback);
if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback))
return PP_ERROR_BADARGUMENT;
FlushCommandBuffer();
platform_video_decoder_->Decode(decode_buffer);
......@@ -143,7 +144,8 @@ int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) {
if (!platform_video_decoder_)
return PP_ERROR_BADRESOURCE;
SetFlushCallback(callback);
if (!SetFlushCallback(callback))
return PP_ERROR_INPROGRESS;
FlushCommandBuffer();
platform_video_decoder_->Flush();
......@@ -154,7 +156,8 @@ int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) {
if (!platform_video_decoder_)
return PP_ERROR_BADRESOURCE;
SetResetCallback(callback);
if (!SetResetCallback(callback))
return PP_ERROR_INPROGRESS;
FlushCommandBuffer();
platform_video_decoder_->Reset();
......
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