OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/shared_impl/video_decoder_impl.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 11 #include "ppapi/thunk/ppb_context_3d_api.h" |
| 12 #include "ppapi/thunk/enter.h" |
| 13 |
| 14 using ppapi::thunk::PPB_Context3D_API; |
| 15 |
| 16 namespace ppapi { |
| 17 |
| 18 VideoDecoderImpl::VideoDecoderImpl() |
| 19 : flush_callback_(PP_MakeCompletionCallback(NULL, NULL)), |
| 20 reset_callback_(PP_MakeCompletionCallback(NULL, NULL)), |
| 21 context3d_id_(0), |
| 22 gles2_impl_(NULL) { |
| 23 } |
| 24 |
| 25 thunk::PPB_VideoDecoder_API* VideoDecoderImpl::AsPPB_VideoDecoder_API() { |
| 26 return this; |
| 27 } |
| 28 |
| 29 VideoDecoderImpl::~VideoDecoderImpl() { |
| 30 } |
| 31 |
| 32 bool VideoDecoderImpl::Init(PP_Resource context3d_id, |
| 33 PPB_Context3D_API* context3d, |
| 34 const PP_VideoConfigElement* decoder_config) { |
| 35 if (!context3d || !decoder_config || !context3d_id) |
| 36 return false; |
| 37 |
| 38 DCHECK(!gles2_impl_ && !context3d_id_); |
| 39 gles2_impl_ = context3d->GetGLES2Impl(); |
| 40 AddRefResource(context3d_id); |
| 41 context3d_id_ = context3d_id; |
| 42 return true; |
| 43 } |
| 44 |
| 45 void VideoDecoderImpl::Destroy() { |
| 46 context3d_id_ = 0; |
| 47 gles2_impl_ = NULL; |
| 48 UnrefResource(context3d_id_); |
| 49 } |
| 50 |
| 51 void VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { |
| 52 CHECK(callback.func); |
| 53 DCHECK(!flush_callback_.func); |
| 54 flush_callback_ = callback; |
| 55 } |
| 56 |
| 57 void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) { |
| 58 CHECK(callback.func); |
| 59 DCHECK(!reset_callback_.func); |
| 60 reset_callback_ = callback; |
| 61 } |
| 62 |
| 63 void VideoDecoderImpl::SetBitstreamBufferCallback( |
| 64 int32 bitstream_buffer_id, PP_CompletionCallback callback) { |
| 65 CHECK(bitstream_buffer_callbacks_.insert( |
| 66 std::make_pair(bitstream_buffer_id, callback)).second); |
| 67 } |
| 68 |
| 69 void VideoDecoderImpl::RunFlushCallback(int32 result) { |
| 70 DCHECK(flush_callback_.func); |
| 71 PP_RunAndClearCompletionCallback(&flush_callback_, result); |
| 72 } |
| 73 |
| 74 void VideoDecoderImpl::RunResetCallback(int32 result) { |
| 75 DCHECK(reset_callback_.func); |
| 76 PP_RunAndClearCompletionCallback(&reset_callback_, result); |
| 77 } |
| 78 |
| 79 void VideoDecoderImpl::RunBitstreamBufferCallback( |
| 80 int32 bitstream_buffer_id, int32 result) { |
| 81 CallbackById::iterator it = |
| 82 bitstream_buffer_callbacks_.find(bitstream_buffer_id); |
| 83 DCHECK(it != bitstream_buffer_callbacks_.end()); |
| 84 PP_CompletionCallback cc = it->second; |
| 85 bitstream_buffer_callbacks_.erase(it); |
| 86 PP_RunCompletionCallback(&cc, PP_OK); |
| 87 } |
| 88 |
| 89 void VideoDecoderImpl::FlushCommandBuffer() { |
| 90 if (gles2_impl_) |
| 91 gles2_impl_->Flush(); |
| 92 } |
| 93 |
| 94 bool VideoDecoderImpl::CopyConfigsToVector( |
| 95 const PP_VideoConfigElement* configs_to_copy, |
| 96 std::vector<PP_VideoConfigElement>* out_configs) { |
| 97 // TODO(fischman/vrk): This is still broken. We need to get rid of the silly |
| 98 // PP_VideoConfigElement vector in favor of a struct (see TODO in |
| 99 // ppb_video_decoder_dev.h). |
| 100 const PP_VideoConfigElement* current = configs_to_copy; |
| 101 while (current && *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) { |
| 102 out_configs->push_back(*current); |
| 103 out_configs->push_back(*(current + 1)); |
| 104 current += 2; |
| 105 } |
| 106 return true; |
| 107 } |
| 108 |
| 109 } // namespace ppapi |
OLD | NEW |