OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/plugins/pepper_video_decoder.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/ppapi/c/pp_completion_callback.h" |
| 9 #include "third_party/ppapi/c/pp_errors.h" |
| 10 #include "third_party/ppapi/c/pp_video.h" |
| 11 #include "third_party/ppapi/c/ppb_video_decoder.h" |
| 12 #include "webkit/glue/plugins/pepper_file_ref.h" |
| 13 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 14 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 15 |
| 16 namespace pepper { |
| 17 |
| 18 namespace { |
| 19 |
| 20 bool GetConfig(PP_Instance instance_id, |
| 21 PP_VideoCodecId codec, |
| 22 PP_VideoConfig* configs, |
| 23 int32_t config_size, |
| 24 int32_t *num_config) { |
| 25 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 26 *num_config = 0; |
| 27 if (!instance) |
| 28 return false; |
| 29 |
| 30 // Get configs based on codec. |
| 31 |
| 32 if (configs) { |
| 33 // Fill in the array of configs. |
| 34 } |
| 35 |
| 36 // Update *num_config. |
| 37 |
| 38 return true; |
| 39 } |
| 40 |
| 41 PP_Resource Create(PP_Instance instance_id, |
| 42 const PP_VideoDecoderConfig* decoder_config) { |
| 43 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 44 if (!instance) |
| 45 return 0; |
| 46 |
| 47 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(instance)); |
| 48 |
| 49 if (!decoder->Init(*decoder_config)) |
| 50 return 0; |
| 51 |
| 52 return decoder->GetReference(); |
| 53 } |
| 54 |
| 55 bool Decode(PP_Resource decoder_id, |
| 56 PP_VideoCompressedDataBuffer* input_buffer) { |
| 57 scoped_refptr<VideoDecoder> decoder( |
| 58 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 59 if (!decoder) |
| 60 return false; |
| 61 |
| 62 decoder->Decode(*input_buffer); |
| 63 return true; |
| 64 } |
| 65 |
| 66 int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { |
| 67 scoped_refptr<VideoDecoder> decoder( |
| 68 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 69 if (!decoder) |
| 70 return PP_ERROR_BADRESOURCE; |
| 71 |
| 72 return decoder->Flush(callback); |
| 73 } |
| 74 |
| 75 bool ReturnUncompressedDataBuffer(PP_Resource decoder_id, |
| 76 PP_VideoUncompressedDataBuffer* buffer) { |
| 77 scoped_refptr<VideoDecoder> decoder( |
| 78 Resource::GetAs<VideoDecoder>(decoder_id)); |
| 79 if (!decoder) |
| 80 return false; |
| 81 |
| 82 return decoder->ReturnUncompressedDataBuffer(*buffer); |
| 83 } |
| 84 |
| 85 const PPB_VideoDecoder ppb_videodecoder = { |
| 86 &GetConfig, |
| 87 &Create, |
| 88 &Decode, |
| 89 &Flush, |
| 90 &ReturnUncompressedDataBuffer |
| 91 }; |
| 92 |
| 93 } // namespace |
| 94 |
| 95 VideoDecoder::VideoDecoder(PluginInstance* instance) |
| 96 : Resource(instance->module()), |
| 97 instance_(instance) { |
| 98 } |
| 99 |
| 100 VideoDecoder::~VideoDecoder() { |
| 101 } |
| 102 |
| 103 // static |
| 104 const PPB_VideoDecoder* VideoDecoder::GetInterface() { |
| 105 return &ppb_videodecoder; |
| 106 } |
| 107 |
| 108 bool VideoDecoder::Init(const PP_VideoDecoderConfig& decoder_config) { |
| 109 if (!instance()) |
| 110 return false; |
| 111 |
| 112 platform_video_decoder_.reset( |
| 113 instance()->delegate()->CreateVideoDecoder(decoder_config)); |
| 114 |
| 115 return platform_video_decoder_.get()? true : false; |
| 116 } |
| 117 |
| 118 bool VideoDecoder::Decode(PP_VideoCompressedDataBuffer& input_buffer) { |
| 119 if (!platform_video_decoder_.get()) |
| 120 return false; |
| 121 |
| 122 return platform_video_decoder_->Decode(input_buffer); |
| 123 } |
| 124 |
| 125 int32_t VideoDecoder::Flush(PP_CompletionCallback& callback) { |
| 126 if (!platform_video_decoder_.get()) |
| 127 return PP_ERROR_FAILED; |
| 128 |
| 129 return platform_video_decoder_->Flush(callback); |
| 130 } |
| 131 |
| 132 bool VideoDecoder::ReturnUncompressedDataBuffer( |
| 133 PP_VideoUncompressedDataBuffer& buffer) { |
| 134 if (!platform_video_decoder_.get()) |
| 135 return false; |
| 136 |
| 137 return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); |
| 138 } |
| 139 |
| 140 } // namespace pepper |
OLD | NEW |