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