| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_video_decoder.h" | 5 #include "webkit/glue/plugins/pepper_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/dev/pp_video_dev.h" | 8 #include "ppapi/c/dev/pp_video_dev.h" |
| 9 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 9 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
| 10 #include "ppapi/c/pp_completion_callback.h" | 10 #include "ppapi/c/pp_completion_callback.h" |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "webkit/glue/plugins/pepper_common.h" |
| 12 #include "webkit/glue/plugins/pepper_file_ref.h" | 13 #include "webkit/glue/plugins/pepper_file_ref.h" |
| 13 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 14 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 14 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 15 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 15 | 16 |
| 16 namespace pepper { | 17 namespace pepper { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 bool GetConfig(PP_Instance instance_id, | 21 PP_Bool GetConfig(PP_Instance instance_id, |
| 21 PP_VideoCodecId_Dev codec, | 22 PP_VideoCodecId_Dev codec, |
| 22 PP_VideoConfig_Dev* configs, | 23 PP_VideoConfig_Dev* configs, |
| 23 int32_t config_size, | 24 int32_t config_size, |
| 24 int32_t *num_config) { | 25 int32_t *num_config) { |
| 25 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 26 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 26 *num_config = 0; | 27 *num_config = 0; |
| 27 if (!instance) | 28 if (!instance) |
| 28 return false; | 29 return PP_FALSE; |
| 29 | 30 |
| 30 // Get configs based on codec. | 31 // Get configs based on codec. |
| 31 | 32 |
| 32 if (configs) { | 33 if (configs) { |
| 33 // Fill in the array of configs. | 34 // Fill in the array of configs. |
| 34 } | 35 } |
| 35 | 36 |
| 36 // Update *num_config. | 37 // Update *num_config. |
| 37 | 38 |
| 38 return true; | 39 return PP_TRUE; |
| 39 } | 40 } |
| 40 | 41 |
| 41 PP_Resource Create(PP_Instance instance_id, | 42 PP_Resource Create(PP_Instance instance_id, |
| 42 const PP_VideoDecoderConfig_Dev* decoder_config) { | 43 const PP_VideoDecoderConfig_Dev* decoder_config) { |
| 43 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 44 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 44 if (!instance) | 45 if (!instance) |
| 45 return 0; | 46 return 0; |
| 46 | 47 |
| 47 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(instance)); | 48 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(instance)); |
| 48 | 49 |
| 49 if (!decoder->Init(*decoder_config)) | 50 if (!decoder->Init(*decoder_config)) |
| 50 return 0; | 51 return 0; |
| 51 | 52 |
| 52 return decoder->GetReference(); | 53 return decoder->GetReference(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool Decode(PP_Resource decoder_id, | 56 PP_Bool Decode(PP_Resource decoder_id, |
| 56 PP_VideoCompressedDataBuffer_Dev* input_buffer) { | 57 PP_VideoCompressedDataBuffer_Dev* input_buffer) { |
| 57 scoped_refptr<VideoDecoder> decoder( | 58 scoped_refptr<VideoDecoder> decoder( |
| 58 Resource::GetAs<VideoDecoder>(decoder_id)); | 59 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 59 if (!decoder) | 60 if (!decoder) |
| 60 return false; | 61 return PP_FALSE; |
| 61 | 62 |
| 62 decoder->Decode(*input_buffer); | 63 decoder->Decode(*input_buffer); |
| 63 return true; | 64 return PP_TRUE; |
| 64 } | 65 } |
| 65 | 66 |
| 66 int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { | 67 int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { |
| 67 scoped_refptr<VideoDecoder> decoder( | 68 scoped_refptr<VideoDecoder> decoder( |
| 68 Resource::GetAs<VideoDecoder>(decoder_id)); | 69 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 69 if (!decoder) | 70 if (!decoder) |
| 70 return PP_ERROR_BADRESOURCE; | 71 return PP_ERROR_BADRESOURCE; |
| 71 | 72 |
| 72 return decoder->Flush(callback); | 73 return decoder->Flush(callback); |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool ReturnUncompressedDataBuffer(PP_Resource decoder_id, | 76 PP_Bool ReturnUncompressedDataBuffer(PP_Resource decoder_id, |
| 76 PP_VideoUncompressedDataBuffer_Dev* buffer) { | 77 PP_VideoUncompressedDataBuffer_Dev* buffer) { |
| 77 scoped_refptr<VideoDecoder> decoder( | 78 scoped_refptr<VideoDecoder> decoder( |
| 78 Resource::GetAs<VideoDecoder>(decoder_id)); | 79 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 79 if (!decoder) | 80 if (!decoder) |
| 80 return false; | 81 return PP_FALSE; |
| 81 | 82 |
| 82 return decoder->ReturnUncompressedDataBuffer(*buffer); | 83 return BoolToPPBool(decoder->ReturnUncompressedDataBuffer(*buffer)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 const PPB_VideoDecoder_Dev ppb_videodecoder = { | 86 const PPB_VideoDecoder_Dev ppb_videodecoder = { |
| 86 &GetConfig, | 87 &GetConfig, |
| 87 &Create, | 88 &Create, |
| 88 &Decode, | 89 &Decode, |
| 89 &Flush, | 90 &Flush, |
| 90 &ReturnUncompressedDataBuffer | 91 &ReturnUncompressedDataBuffer |
| 91 }; | 92 }; |
| 92 | 93 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 bool VideoDecoder::ReturnUncompressedDataBuffer( | 133 bool VideoDecoder::ReturnUncompressedDataBuffer( |
| 133 PP_VideoUncompressedDataBuffer_Dev& buffer) { | 134 PP_VideoUncompressedDataBuffer_Dev& buffer) { |
| 134 if (!platform_video_decoder_.get()) | 135 if (!platform_video_decoder_.get()) |
| 135 return false; | 136 return false; |
| 136 | 137 |
| 137 return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); | 138 return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); |
| 138 } | 139 } |
| 139 | 140 |
| 140 } // namespace pepper | 141 } // namespace pepper |
| OLD | NEW |