| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/plugins/ppapi/ppb_video_decoder_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 44 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 47 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
| 48 } | 48 } |
| 49 | 49 |
| 50 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 50 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
| 51 return this; | 51 return this; |
| 52 } | 52 } |
| 53 | 53 |
| 54 int32_t PPB_VideoDecoder_Impl::Initialize( | 54 // static |
| 55 PP_Resource context_id, | 55 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, |
| 56 const PP_VideoConfigElement* decoder_config, | 56 PP_Resource context3d_id, |
| 57 PP_CompletionCallback callback) { | 57 const PP_VideoConfigElement* config) { |
| 58 if (!callback.func) | 58 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
| 59 return PP_ERROR_BADARGUMENT; | 59 new PPB_VideoDecoder_Impl(instance)); |
| 60 if (decoder->Init(context3d_id, config)) |
| 61 return decoder->GetReference(); |
| 62 return 0; |
| 63 } |
| 60 | 64 |
| 61 if (!instance()) | 65 bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, |
| 62 return PP_ERROR_FAILED; | 66 const PP_VideoConfigElement* config) { |
| 67 if (!instance() || !context3d_id || !config) |
| 68 return false; |
| 63 | 69 |
| 64 EnterResourceNoLock<PPB_Context3D_API> enter(context_id, true); | 70 EnterResourceNoLock<PPB_Context3D_API> enter(context3d_id, true); |
| 65 if (enter.failed()) | 71 if (enter.failed()) |
| 66 return PP_ERROR_BADRESOURCE; | 72 return false; |
| 67 PPB_Context3D_Impl* context3d = | 73 PPB_Context3D_Impl* context3d = |
| 68 static_cast<PPB_Context3D_Impl*>(enter.object()); | 74 static_cast<PPB_Context3D_Impl*>(enter.object()); |
| 69 | 75 |
| 70 context3d_id_ = context_id; | 76 context3d_id_ = context3d_id; |
| 71 ResourceTracker::Get()->AddRefResource(context3d_id_); | 77 ResourceTracker::Get()->AddRefResource(context3d_id_); |
| 72 | 78 |
| 73 int command_buffer_route_id = | 79 int command_buffer_route_id = |
| 74 context3d->platform_context()->GetCommandBufferRouteId(); | 80 context3d->platform_context()->GetCommandBufferRouteId(); |
| 75 if (command_buffer_route_id == 0) | 81 if (command_buffer_route_id == 0) |
| 76 return PP_ERROR_FAILED; | 82 return false; |
| 77 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( | 83 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( |
| 78 this, command_buffer_route_id); | 84 this, command_buffer_route_id); |
| 79 | 85 |
| 80 gles2_impl_ = context3d->gles2_impl(); | 86 gles2_impl_ = context3d->gles2_impl(); |
| 81 | 87 |
| 82 if (!platform_video_decoder_) | 88 if (!platform_video_decoder_) |
| 83 return PP_ERROR_FAILED; | 89 return false; |
| 84 | 90 |
| 85 std::vector<uint32> copied; | 91 std::vector<uint32> copied; |
| 86 // TODO(fischman,vrk): this is completely broken in that it fails to account | 92 // TODO(fischman,vrk): this is completely broken in that it fails to account |
| 87 // for the semantic distinction between keys and values; it is certainly | 93 // for the semantic distinction between keys and values; it is certainly |
| 88 // possible for a value to show up as 0, and that shouldn't terminate the | 94 // possible for a value to show up as 0, and that shouldn't terminate the |
| 89 // config vector. Only a *key* of 0 should do so. | 95 // config vector. Only a *key* of 0 should do so. |
| 90 // TODO(vrk): This is assuming PP_VideoAttributeDictionary and | 96 // TODO(vrk): This is assuming PP_VideoAttributeDictionary and |
| 91 // VideoAttributeKey have identical enum values. There is no compiler | 97 // VideoAttributeKey have identical enum values. There is no compiler |
| 92 // assert to guarantee this. We either need to add such asserts or | 98 // assert to guarantee this. We either need to add such asserts or |
| 93 // merge PP_VideoAttributeDictionary and VideoAttributeKey. | 99 // merge PP_VideoAttributeDictionary and VideoAttributeKey. |
| 94 for (const PP_VideoConfigElement* current = decoder_config; | 100 for (const PP_VideoConfigElement* current = config; |
| 95 *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR; ++current) { | 101 *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR; ++current) { |
| 96 copied.push_back(static_cast<uint32>(*current)); | 102 copied.push_back(static_cast<uint32>(*current)); |
| 97 } | 103 } |
| 98 | 104 |
| 99 FlushCommandBuffer(); | 105 FlushCommandBuffer(); |
| 100 if (platform_video_decoder_->Initialize(copied)) { | 106 return platform_video_decoder_->Initialize(copied); |
| 101 initialization_callback_ = callback; | |
| 102 return PP_OK_COMPLETIONPENDING; | |
| 103 } else { | |
| 104 return PP_ERROR_FAILED; | |
| 105 } | |
| 106 } | 107 } |
| 107 | 108 |
| 108 int32_t PPB_VideoDecoder_Impl::Decode( | 109 int32_t PPB_VideoDecoder_Impl::Decode( |
| 109 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 110 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
| 110 PP_CompletionCallback callback) { | 111 PP_CompletionCallback callback) { |
| 111 if (!platform_video_decoder_) | 112 if (!platform_video_decoder_) |
| 112 return PP_ERROR_BADRESOURCE; | 113 return PP_ERROR_BADRESOURCE; |
| 113 | 114 |
| 114 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); | 115 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); |
| 115 if (enter.failed()) | 116 if (enter.failed()) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 270 |
| 270 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 271 void PPB_VideoDecoder_Impl::NotifyFlushDone() { |
| 271 if (flush_callback_.func == NULL) | 272 if (flush_callback_.func == NULL) |
| 272 return; | 273 return; |
| 273 | 274 |
| 274 // Call the callback that was stored to be called when Flush is done. | 275 // Call the callback that was stored to be called when Flush is done. |
| 275 PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); | 276 PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 279 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
| 279 if (initialization_callback_.func == NULL) | 280 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; |
| 280 return; | |
| 281 | |
| 282 PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); | |
| 283 } | 281 } |
| 284 | 282 |
| 285 void PPB_VideoDecoder_Impl::FlushCommandBuffer() { | 283 void PPB_VideoDecoder_Impl::FlushCommandBuffer() { |
| 286 // For the out-of-process case, |gles2_impl_| will be NULL in the renderer | 284 // For the out-of-process case, |gles2_impl_| will be NULL in the renderer |
| 287 // process. The VideoDecoder_Proxy is charged with the responsibility of | 285 // process. The VideoDecoder_Proxy is charged with the responsibility of |
| 288 // doing this Flush() in the analogous places in the plugin process. | 286 // doing this Flush() in the analogous places in the plugin process. |
| 289 if (gles2_impl_) | 287 if (gles2_impl_) |
| 290 gles2_impl_->Flush(); | 288 gles2_impl_->Flush(); |
| 291 } | 289 } |
| 292 | 290 |
| 293 } // namespace ppapi | 291 } // namespace ppapi |
| 294 } // namespace webkit | 292 } // namespace webkit |
| OLD | NEW |