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 15 matching lines...) Expand all Loading... | |
26 using ppapi::thunk::EnterResourceNoLock; | 26 using ppapi::thunk::EnterResourceNoLock; |
27 using ppapi::thunk::PPB_Buffer_API; | 27 using ppapi::thunk::PPB_Buffer_API; |
28 using ppapi::thunk::PPB_Context3D_API; | 28 using ppapi::thunk::PPB_Context3D_API; |
29 using ppapi::thunk::PPB_VideoDecoder_API; | 29 using ppapi::thunk::PPB_VideoDecoder_API; |
30 | 30 |
31 namespace webkit { | 31 namespace webkit { |
32 namespace ppapi { | 32 namespace ppapi { |
33 | 33 |
34 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) | 34 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) |
35 : Resource(instance), | 35 : Resource(instance), |
36 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 36 VideoDecoderImpl(true) { |
37 context3d_id_(0), | |
38 flush_callback_(PP_BlockUntilComplete()), | |
39 reset_callback_(PP_BlockUntilComplete()), | |
40 gles2_impl_(NULL) { | |
41 ppp_videodecoder_ = | 37 ppp_videodecoder_ = |
42 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> | 38 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> |
43 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 39 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
44 } | 40 } |
45 | 41 |
46 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 42 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
47 } | 43 } |
48 | 44 |
49 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 45 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
50 return this; | 46 return this; |
51 } | 47 } |
52 | 48 |
53 // static | 49 // static |
54 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, | 50 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, |
55 PP_Resource context3d_id, | 51 PP_Resource context3d_id, |
56 const PP_VideoConfigElement* config) { | 52 const PP_VideoConfigElement* config) { |
53 if (!context3d_id) | |
54 return NULL; | |
55 | |
56 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); | |
57 if (enter_context.failed()) | |
58 return NULL; | |
59 | |
57 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 60 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
58 new PPB_VideoDecoder_Impl(instance)); | 61 new PPB_VideoDecoder_Impl(instance)); |
59 if (decoder->Init(context3d_id, config)) | 62 if (decoder->Init(context3d_id, enter_context.object(), config)) |
60 return decoder->GetReference(); | 63 return decoder->GetReference(); |
61 return 0; | 64 return 0; |
62 } | 65 } |
63 | 66 |
64 bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, | 67 bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, |
68 PPB_Context3D_API* context3d, | |
65 const PP_VideoConfigElement* config) { | 69 const PP_VideoConfigElement* config) { |
66 if (!instance() || !context3d_id || !config) | 70 if(!instance() || |
71 !::ppapi::VideoDecoderImpl::Init(context3d_id, context3d, config)) | |
Ami GONE FROM CHROMIUM
2011/08/03 20:25:53
need braces now that if test is 2 lines.
vrk (LEFT CHROMIUM)
2011/08/03 22:05:22
Removed !instance() check, back to one-liner.
| |
67 return false; | 72 return false; |
68 | 73 |
69 EnterResourceNoLock<PPB_Context3D_API> enter(context3d_id, true); | 74 std::vector<int32> copied; |
70 if (enter.failed()) | 75 if (!CopyConfigsToVector(config, &copied)) |
71 return false; | 76 return false; |
72 PPB_Context3D_Impl* context3d = | |
73 static_cast<PPB_Context3D_Impl*>(enter.object()); | |
74 | 77 |
75 context3d_id_ = context3d_id; | 78 PPB_Context3D_Impl* context3d_impl = |
76 ResourceTracker::Get()->AddRefResource(context3d_id_); | 79 static_cast<PPB_Context3D_Impl*>(context3d); |
77 | 80 |
78 int command_buffer_route_id = | 81 int command_buffer_route_id = |
79 context3d->platform_context()->GetCommandBufferRouteId(); | 82 context3d_impl->platform_context()->GetCommandBufferRouteId(); |
80 if (command_buffer_route_id == 0) | 83 if (command_buffer_route_id == 0) |
81 return false; | 84 return false; |
82 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( | 85 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( |
83 this, command_buffer_route_id); | 86 this, command_buffer_route_id); |
84 | |
85 gles2_impl_ = context3d->gles2_impl(); | |
86 | |
87 if (!platform_video_decoder_) | 87 if (!platform_video_decoder_) |
88 return false; | 88 return false; |
89 | 89 |
90 std::vector<uint32> copied; | |
91 // TODO(fischman,vrk): this is completely broken in that it fails to account | |
92 // for the semantic distinction between keys and values; it is certainly | |
93 // possible for a value to show up as 0, and that shouldn't terminate the | |
94 // config vector. Only a *key* of 0 should do so. | |
95 // TODO(vrk): This is assuming PP_VideoAttributeDictionary and | |
96 // VideoAttributeKey have identical enum values. There is no compiler | |
97 // assert to guarantee this. We either need to add such asserts or | |
98 // merge PP_VideoAttributeDictionary and VideoAttributeKey. | |
99 for (const PP_VideoConfigElement* current = config; | |
100 *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR; ++current) { | |
101 copied.push_back(static_cast<uint32>(*current)); | |
102 } | |
103 | |
104 FlushCommandBuffer(); | 90 FlushCommandBuffer(); |
105 return platform_video_decoder_->Initialize(copied); | 91 return platform_video_decoder_->Initialize(copied); |
106 } | 92 } |
107 | 93 |
108 int32_t PPB_VideoDecoder_Impl::Decode( | 94 int32_t PPB_VideoDecoder_Impl::Decode( |
109 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 95 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
110 PP_CompletionCallback callback) { | 96 PP_CompletionCallback callback) { |
111 if (!platform_video_decoder_) | 97 if (!platform_video_decoder_) |
112 return PP_ERROR_BADRESOURCE; | 98 return PP_ERROR_BADRESOURCE; |
113 | 99 |
114 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); | 100 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); |
115 if (enter.failed()) | 101 if (enter.failed()) |
116 return PP_ERROR_FAILED; | 102 return PP_ERROR_FAILED; |
117 | 103 |
118 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 104 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
119 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 105 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
120 buffer->shared_memory()->handle(), | 106 buffer->shared_memory()->handle(), |
121 static_cast<size_t>(buffer->size())); | 107 static_cast<size_t>(buffer->size())); |
122 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( | 108 SetBitstreamBufferCallback(bitstream_buffer->id, callback); |
123 bitstream_buffer->id, callback)).second); | |
124 | 109 |
125 FlushCommandBuffer(); | 110 FlushCommandBuffer(); |
126 platform_video_decoder_->Decode(decode_buffer); | 111 platform_video_decoder_->Decode(decode_buffer); |
127 return PP_OK_COMPLETIONPENDING; | 112 return PP_OK_COMPLETIONPENDING; |
128 } | 113 } |
129 | 114 |
130 void PPB_VideoDecoder_Impl::AssignPictureBuffers( | 115 void PPB_VideoDecoder_Impl::AssignPictureBuffers( |
131 uint32_t no_of_buffers, | 116 uint32_t no_of_buffers, |
132 const PP_PictureBuffer_Dev* buffers) { | 117 const PP_PictureBuffer_Dev* buffers) { |
133 if (!platform_video_decoder_) | 118 if (!platform_video_decoder_) |
(...skipping 18 matching lines...) Expand all Loading... | |
152 return; | 137 return; |
153 | 138 |
154 FlushCommandBuffer(); | 139 FlushCommandBuffer(); |
155 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); | 140 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
156 } | 141 } |
157 | 142 |
158 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 143 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
159 if (!platform_video_decoder_) | 144 if (!platform_video_decoder_) |
160 return PP_ERROR_BADRESOURCE; | 145 return PP_ERROR_BADRESOURCE; |
161 | 146 |
162 // Store the callback to be called when Flush() is done. | 147 SetFlushCallback(callback); |
163 // TODO(fischman,vrk): consider implications of already-outstanding callback. | |
164 flush_callback_ = callback; | |
165 | 148 |
166 FlushCommandBuffer(); | 149 FlushCommandBuffer(); |
167 platform_video_decoder_->Flush(); | 150 platform_video_decoder_->Flush(); |
168 return PP_OK_COMPLETIONPENDING; | 151 return PP_OK_COMPLETIONPENDING; |
169 } | 152 } |
170 | 153 |
171 int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { | 154 int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { |
172 if (!platform_video_decoder_) | 155 if (!platform_video_decoder_) |
173 return PP_ERROR_BADRESOURCE; | 156 return PP_ERROR_BADRESOURCE; |
174 | 157 |
175 // Store the callback to be called when Reset() is done. | 158 SetResetCallback(callback); |
176 // TODO(fischman,vrk): consider implications of already-outstanding callback. | |
177 reset_callback_ = callback; | |
178 | 159 |
179 FlushCommandBuffer(); | 160 FlushCommandBuffer(); |
180 platform_video_decoder_->Reset(); | 161 platform_video_decoder_->Reset(); |
181 return PP_OK_COMPLETIONPENDING; | 162 return PP_OK_COMPLETIONPENDING; |
182 } | 163 } |
183 | 164 |
184 void PPB_VideoDecoder_Impl::Destroy() { | 165 void PPB_VideoDecoder_Impl::Destroy() { |
185 if (!platform_video_decoder_) | 166 if (!platform_video_decoder_) |
186 return; | 167 return; |
187 | 168 |
188 FlushCommandBuffer(); | 169 FlushCommandBuffer(); |
189 platform_video_decoder_->Destroy(); | 170 platform_video_decoder_->Destroy(); |
190 gles2_impl_ = NULL; | 171 ::ppapi::VideoDecoderImpl::Destroy(); |
191 if (context3d_id_) | |
192 ResourceTracker::Get()->UnrefResource(context3d_id_); | |
193 platform_video_decoder_ = NULL; | 172 platform_video_decoder_ = NULL; |
194 ppp_videodecoder_ = NULL; | 173 ppp_videodecoder_ = NULL; |
195 } | 174 } |
196 | 175 |
197 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 176 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
198 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { | 177 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { |
199 if (!ppp_videodecoder_) | 178 if (!ppp_videodecoder_) |
200 return; | 179 return; |
201 | 180 |
202 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); | 181 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 ScopedResourceId resource(this); | 222 ScopedResourceId resource(this); |
244 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and | 223 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and |
245 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler | 224 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler |
246 // assert to guarantee this. We either need to add such asserts or | 225 // assert to guarantee this. We either need to add such asserts or |
247 // merge these two enums. | 226 // merge these two enums. |
248 ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, | 227 ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, |
249 static_cast<PP_VideoDecodeError_Dev>(error)); | 228 static_cast<PP_VideoDecodeError_Dev>(error)); |
250 } | 229 } |
251 | 230 |
252 void PPB_VideoDecoder_Impl::NotifyResetDone() { | 231 void PPB_VideoDecoder_Impl::NotifyResetDone() { |
253 if (reset_callback_.func == NULL) | 232 RunResetCallback(PP_OK); |
254 return; | |
255 | |
256 // Call the callback that was stored to be called when Reset is done. | |
257 PP_RunAndClearCompletionCallback(&reset_callback_, PP_OK); | |
258 } | 233 } |
259 | 234 |
260 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( | 235 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( |
261 int32 bitstream_buffer_id) { | 236 int32 bitstream_buffer_id) { |
262 CallbackById::iterator it = | 237 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); |
263 bitstream_buffer_callbacks_.find(bitstream_buffer_id); | |
264 DCHECK(it != bitstream_buffer_callbacks_.end()); | |
265 PP_CompletionCallback cc = it->second; | |
266 bitstream_buffer_callbacks_.erase(it); | |
267 PP_RunCompletionCallback(&cc, PP_OK); | |
268 } | 238 } |
269 | 239 |
270 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 240 void PPB_VideoDecoder_Impl::NotifyFlushDone() { |
271 if (flush_callback_.func == NULL) | 241 RunFlushCallback(PP_OK); |
272 return; | |
273 | |
274 // Call the callback that was stored to be called when Flush is done. | |
275 PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); | |
276 } | 242 } |
277 | 243 |
278 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 244 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
279 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; | 245 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; |
280 } | 246 } |
281 | 247 |
282 void PPB_VideoDecoder_Impl::FlushCommandBuffer() { | |
283 // For the out-of-process case, |gles2_impl_| will be NULL in the renderer | |
284 // process. The VideoDecoder_Proxy is charged with the responsibility of | |
285 // doing this Flush() in the analogous places in the plugin process. | |
286 if (gles2_impl_) | |
287 gles2_impl_->Flush(); | |
288 } | |
289 | |
290 } // namespace ppapi | 248 } // namespace ppapi |
291 } // namespace webkit | 249 } // namespace webkit |
OLD | NEW |