OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 <GLES2/gl2.h> |
| 6 |
| 7 #include "base/memory/shared_memory.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/ppb_video_decoder.h" |
| 11 #include "ppapi/proxy/locking_resource_releaser.h" |
| 12 #include "ppapi/proxy/plugin_message_filter.h" |
| 13 #include "ppapi/proxy/ppapi_message_utils.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 16 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 17 #include "ppapi/proxy/video_decoder_constants.h" |
| 18 #include "ppapi/proxy/video_decoder_resource.h" |
| 19 #include "ppapi/shared_impl/proxy_lock.h" |
| 20 #include "ppapi/thunk/thunk.h" |
| 21 |
| 22 using ppapi::proxy::ResourceMessageTestSink; |
| 23 |
| 24 namespace ppapi { |
| 25 namespace proxy { |
| 26 |
| 27 namespace { |
| 28 |
| 29 const PP_Bool kAllowSoftwareFallback = PP_TRUE; |
| 30 const PP_Resource kGraphics3D = 7; |
| 31 const uint32_t kShmSize = 256; |
| 32 const size_t kDecodeBufferSize = 16; |
| 33 const uint32_t kDecodeId = 5; |
| 34 const uint32_t kTextureId1 = 1; |
| 35 const uint32_t kTextureId2 = 2; |
| 36 const uint32_t kNumRequestedTextures = 2; |
| 37 |
| 38 class MockCompletionCallback { |
| 39 public: |
| 40 MockCompletionCallback() : called_(false) {} |
| 41 |
| 42 bool called() { return called_; } |
| 43 int32_t result() { return result_; } |
| 44 |
| 45 void Reset() { called_ = false; } |
| 46 |
| 47 static void Callback(void* user_data, int32_t result) { |
| 48 MockCompletionCallback* that = |
| 49 reinterpret_cast<MockCompletionCallback*>(user_data); |
| 50 that->called_ = true; |
| 51 that->result_ = result; |
| 52 } |
| 53 |
| 54 private: |
| 55 bool called_; |
| 56 int32_t result_; |
| 57 }; |
| 58 |
| 59 class VideoDecoderResourceTest : public PluginProxyTest { |
| 60 public: |
| 61 VideoDecoderResourceTest() |
| 62 : decoder_iface_(thunk::GetPPB_VideoDecoder_0_1_Thunk()) {} |
| 63 |
| 64 const PPB_VideoDecoder_0_1* decoder_iface() const { return decoder_iface_; } |
| 65 |
| 66 void SendReply(const ResourceMessageCallParams& params, |
| 67 int32_t result, |
| 68 const IPC::Message& nested_message) { |
| 69 ResourceMessageReplyParams reply_params(params.pp_resource(), |
| 70 params.sequence()); |
| 71 reply_params.set_result(result); |
| 72 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| 73 nested_message); |
| 74 } |
| 75 |
| 76 void SendReplyWithHandle(const ResourceMessageCallParams& params, |
| 77 int32_t result, |
| 78 const IPC::Message& nested_message, |
| 79 const SerializedHandle& handle) { |
| 80 ResourceMessageReplyParams reply_params(params.pp_resource(), |
| 81 params.sequence()); |
| 82 reply_params.set_result(result); |
| 83 reply_params.AppendHandle(handle); |
| 84 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| 85 nested_message); |
| 86 } |
| 87 |
| 88 PP_Resource CreateDecoder() { |
| 89 PP_Resource result = decoder_iface()->Create(pp_instance()); |
| 90 if (result) { |
| 91 ProxyAutoLock lock; |
| 92 ppapi::Resource* resource = |
| 93 GetGlobals()->GetResourceTracker()->GetResource(result); |
| 94 proxy::VideoDecoderResource* decoder = |
| 95 static_cast<proxy::VideoDecoderResource*>(resource); |
| 96 decoder->SetForTest(); |
| 97 } |
| 98 |
| 99 return result; |
| 100 } |
| 101 |
| 102 PP_Resource CreateGraphics3d() { |
| 103 ProxyAutoLock lock; |
| 104 |
| 105 HostResource host_resource; |
| 106 host_resource.SetHostResource(pp_instance(), kGraphics3D); |
| 107 scoped_refptr<ppapi::proxy::Graphics3D> graphics_3d( |
| 108 new ppapi::proxy::Graphics3D(host_resource)); |
| 109 return graphics_3d->GetReference(); |
| 110 } |
| 111 |
| 112 PP_Resource CreateAndInitializeDecoder() { |
| 113 PP_Resource decoder = CreateDecoder(); |
| 114 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| 115 MockCompletionCallback cb; |
| 116 int32_t result = decoder_iface()->Initialize( |
| 117 decoder, |
| 118 graphics3d.get(), |
| 119 PP_VIDEOPROFILE_H264MAIN, |
| 120 PP_TRUE /* allow_software_fallback */, |
| 121 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
| 122 &cb)); |
| 123 if (result != PP_OK_COMPLETIONPENDING) |
| 124 return 0; |
| 125 ResourceMessageCallParams params; |
| 126 IPC::Message msg; |
| 127 if (!sink().GetFirstResourceCallMatching( |
| 128 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)) |
| 129 return 0; |
| 130 sink().ClearMessages(); |
| 131 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| 132 return decoder; |
| 133 } |
| 134 |
| 135 int32_t CallDecode(PP_Resource pp_decoder, |
| 136 MockCompletionCallback* cb, |
| 137 const PpapiHostMsg_VideoDecoder_GetShm* expected_shm_msg) { |
| 138 // Set up a handler in case the resource sends a sync message to create |
| 139 // shared memory. |
| 140 PpapiPluginMsg_VideoDecoder_GetShmReply shm_msg_reply(kShmSize); |
| 141 ResourceSyncCallHandler shm_msg_handler( |
| 142 &sink(), PpapiHostMsg_VideoDecoder_GetShm::ID, PP_OK, shm_msg_reply); |
| 143 sink().AddFilter(&shm_msg_handler); |
| 144 |
| 145 base::SharedMemory shm; |
| 146 if (expected_shm_msg) { |
| 147 shm.CreateAnonymous(kShmSize); |
| 148 base::SharedMemoryHandle shm_handle; |
| 149 shm.ShareToProcess(base::GetCurrentProcessHandle(), &shm_handle); |
| 150 SerializedHandle serialized_handle(shm_handle, kShmSize); |
| 151 shm_msg_handler.set_serialized_handle(&serialized_handle); |
| 152 } |
| 153 |
| 154 memset(decode_buffer_, 0x55, kDecodeBufferSize); |
| 155 int32_t result = |
| 156 decoder_iface()->Decode(pp_decoder, |
| 157 kDecodeId, |
| 158 kDecodeBufferSize, |
| 159 decode_buffer_, |
| 160 PP_MakeOptionalCompletionCallback( |
| 161 &MockCompletionCallback::Callback, cb)); |
| 162 |
| 163 if (expected_shm_msg) { |
| 164 uint32_t shm_id, shm_size, expected_shm_id, expected_shm_size; |
| 165 UnpackMessage<PpapiHostMsg_VideoDecoder_GetShm>( |
| 166 *expected_shm_msg, &expected_shm_id, &expected_shm_size); |
| 167 if (shm_msg_handler.last_handled_msg().type() == 0 || |
| 168 !UnpackMessage<PpapiHostMsg_VideoDecoder_GetShm>( |
| 169 shm_msg_handler.last_handled_msg(), &shm_id, &shm_size) || |
| 170 shm_id != expected_shm_id || |
| 171 shm_size != expected_shm_size) { |
| 172 // Signal that the expected shm message wasn't sent by failing. |
| 173 result = PP_ERROR_FAILED; |
| 174 } |
| 175 } |
| 176 |
| 177 sink().RemoveFilter(&shm_msg_handler); |
| 178 return result; |
| 179 } |
| 180 |
| 181 int32_t CallGetPicture(PP_Resource pp_decoder, |
| 182 PP_VideoPicture* picture, |
| 183 MockCompletionCallback* cb) { |
| 184 int32_t result = |
| 185 decoder_iface()->GetPicture(pp_decoder, |
| 186 picture, |
| 187 PP_MakeOptionalCompletionCallback( |
| 188 &MockCompletionCallback::Callback, cb)); |
| 189 return result; |
| 190 } |
| 191 |
| 192 void CallRecyclePicture(PP_Resource pp_decoder, |
| 193 const PP_VideoPicture& picture) { |
| 194 decoder_iface()->RecyclePicture(pp_decoder, &picture); |
| 195 } |
| 196 |
| 197 int32_t CallFlush(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| 198 int32_t result = |
| 199 decoder_iface()->Flush(pp_decoder, |
| 200 PP_MakeOptionalCompletionCallback( |
| 201 &MockCompletionCallback::Callback, cb)); |
| 202 return result; |
| 203 } |
| 204 |
| 205 int32_t CallReset(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| 206 int32_t result = |
| 207 decoder_iface()->Reset(pp_decoder, |
| 208 PP_MakeOptionalCompletionCallback( |
| 209 &MockCompletionCallback::Callback, cb)); |
| 210 return result; |
| 211 } |
| 212 |
| 213 void SendDecodeReply(const ResourceMessageCallParams& params, |
| 214 uint32_t shm_id) { |
| 215 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_DecodeReply(shm_id)); |
| 216 } |
| 217 |
| 218 void SendPictureReady(const ResourceMessageCallParams& params, |
| 219 uint32_t decode_count, |
| 220 uint32_t texture_id) { |
| 221 SendReply( |
| 222 params, |
| 223 PP_OK, |
| 224 PpapiPluginMsg_VideoDecoder_PictureReady(decode_count, texture_id)); |
| 225 } |
| 226 |
| 227 void SendFlushReply(const ResourceMessageCallParams& params) { |
| 228 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_FlushReply()); |
| 229 } |
| 230 |
| 231 void SendResetReply(const ResourceMessageCallParams& params) { |
| 232 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_ResetReply()); |
| 233 } |
| 234 |
| 235 void SendRequestTextures(const ResourceMessageCallParams& params) { |
| 236 SendReply(params, |
| 237 PP_OK, |
| 238 PpapiPluginMsg_VideoDecoder_RequestTextures( |
| 239 kNumRequestedTextures, PP_MakeSize(320, 240), GL_TEXTURE_2D)); |
| 240 } |
| 241 |
| 242 void SendNotifyError(const ResourceMessageCallParams& params, int32_t error) { |
| 243 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_NotifyError(error)); |
| 244 } |
| 245 |
| 246 bool CheckDecodeMsg(ResourceMessageCallParams* params, |
| 247 uint32_t* shm_id, |
| 248 uint32_t* size, |
| 249 int32_t* decode_id) { |
| 250 IPC::Message msg; |
| 251 if (!sink().GetFirstResourceCallMatching( |
| 252 PpapiHostMsg_VideoDecoder_Decode::ID, params, &msg)) |
| 253 return false; |
| 254 sink().ClearMessages(); |
| 255 return UnpackMessage<PpapiHostMsg_VideoDecoder_Decode>( |
| 256 msg, shm_id, size, decode_id); |
| 257 } |
| 258 |
| 259 bool CheckRecyclePictureMsg(ResourceMessageCallParams* params, |
| 260 uint32_t* texture_id) { |
| 261 IPC::Message msg; |
| 262 if (!sink().GetFirstResourceCallMatching( |
| 263 PpapiHostMsg_VideoDecoder_RecyclePicture::ID, params, &msg)) |
| 264 return false; |
| 265 sink().ClearMessages(); |
| 266 return UnpackMessage<PpapiHostMsg_VideoDecoder_RecyclePicture>(msg, |
| 267 texture_id); |
| 268 } |
| 269 |
| 270 bool CheckFlushMsg(ResourceMessageCallParams* params) { |
| 271 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Flush::ID); |
| 272 } |
| 273 |
| 274 bool CheckResetMsg(ResourceMessageCallParams* params) { |
| 275 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Reset::ID); |
| 276 } |
| 277 |
| 278 void ClearCallbacks(PP_Resource pp_decoder) { |
| 279 ResourceMessageCallParams params; |
| 280 MockCompletionCallback cb; |
| 281 |
| 282 // Reset to abort Decode and GetPicture callbacks. |
| 283 CallReset(pp_decoder, &cb); |
| 284 // Initialize params so we can reply to the Reset. |
| 285 CheckResetMsg(¶ms); |
| 286 // Run the Reset callback. |
| 287 SendResetReply(params); |
| 288 } |
| 289 |
| 290 private: |
| 291 bool CheckMsg(ResourceMessageCallParams* params, int id) { |
| 292 IPC::Message msg; |
| 293 if (!sink().GetFirstResourceCallMatching(id, params, &msg)) |
| 294 return false; |
| 295 sink().ClearMessages(); |
| 296 return true; |
| 297 } |
| 298 |
| 299 const PPB_VideoDecoder_0_1* decoder_iface_; |
| 300 |
| 301 char decode_buffer_[kDecodeBufferSize]; |
| 302 }; |
| 303 |
| 304 } // namespace |
| 305 |
| 306 TEST_F(VideoDecoderResourceTest, Initialize) { |
| 307 // Initialize with 0 graphics3d_context should fail. |
| 308 { |
| 309 LockingResourceReleaser decoder(CreateDecoder()); |
| 310 MockCompletionCallback cb; |
| 311 int32_t result = decoder_iface()->Initialize( |
| 312 decoder.get(), |
| 313 0 /* invalid 3d graphics */, |
| 314 PP_VIDEOPROFILE_H264MAIN, |
| 315 kAllowSoftwareFallback, |
| 316 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
| 317 &cb)); |
| 318 ASSERT_EQ(PP_ERROR_BADRESOURCE, result); |
| 319 } |
| 320 // Initialize with bad profile value should fail. |
| 321 { |
| 322 LockingResourceReleaser decoder(CreateDecoder()); |
| 323 MockCompletionCallback cb; |
| 324 int32_t result = decoder_iface()->Initialize( |
| 325 decoder.get(), |
| 326 1 /* non-zero resource */, |
| 327 static_cast<PP_VideoProfile>(-1), |
| 328 kAllowSoftwareFallback, |
| 329 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
| 330 &cb)); |
| 331 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
| 332 } |
| 333 // Initialize with valid graphics3d_context and profile should succeed. |
| 334 { |
| 335 LockingResourceReleaser decoder(CreateDecoder()); |
| 336 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| 337 MockCompletionCallback cb; |
| 338 int32_t result = decoder_iface()->Initialize( |
| 339 decoder.get(), |
| 340 graphics3d.get(), |
| 341 PP_VIDEOPROFILE_H264MAIN, |
| 342 kAllowSoftwareFallback, |
| 343 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
| 344 &cb)); |
| 345 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 346 ASSERT_TRUE(decoder_iface()->IsVideoDecoder(decoder.get())); |
| 347 |
| 348 // Another attempt while pending should fail. |
| 349 result = decoder_iface()->Initialize( |
| 350 decoder.get(), |
| 351 graphics3d.get(), |
| 352 PP_VIDEOPROFILE_H264MAIN, |
| 353 kAllowSoftwareFallback, |
| 354 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
| 355 &cb)); |
| 356 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| 357 |
| 358 // Check for host message and send a reply to complete initialization. |
| 359 ResourceMessageCallParams params; |
| 360 IPC::Message msg; |
| 361 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| 362 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)); |
| 363 sink().ClearMessages(); |
| 364 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| 365 ASSERT_TRUE(cb.called()); |
| 366 ASSERT_EQ(PP_OK, cb.result()); |
| 367 } |
| 368 } |
| 369 |
| 370 TEST_F(VideoDecoderResourceTest, Uninitialized) { |
| 371 // Operations on uninitialized decoders should fail. |
| 372 LockingResourceReleaser decoder(CreateDecoder()); |
| 373 MockCompletionCallback uncalled_cb; |
| 374 |
| 375 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb, NULL)); |
| 376 ASSERT_FALSE(uncalled_cb.called()); |
| 377 |
| 378 ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| 379 ASSERT_FALSE(uncalled_cb.called()); |
| 380 |
| 381 ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| 382 ASSERT_FALSE(uncalled_cb.called()); |
| 383 |
| 384 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 385 ASSERT_FALSE(uncalled_cb.called()); |
| 386 } |
| 387 |
| 388 // TODO(bbudge) Fix sync message testing on Windows 64 bit builds. The reply |
| 389 // message for GetShm isn't received, causing Decode to fail. |
| 390 // http://crbug.com/379260 |
| 391 #if !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 392 TEST_F(VideoDecoderResourceTest, DecodeAndGetPicture) { |
| 393 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 394 ResourceMessageCallParams params, params2; |
| 395 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| 396 |
| 397 uint32_t shm_id; |
| 398 uint32_t decode_size; |
| 399 int32_t decode_id; |
| 400 // Call Decode until we have the maximum pending, minus one. |
| 401 for (uint32_t i = 0; i < kMaximumPendingDecodes - 1; i++) { |
| 402 PpapiHostMsg_VideoDecoder_GetShm shm_msg(i, kDecodeBufferSize); |
| 403 ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &uncalled_cb, &shm_msg)); |
| 404 ASSERT_FALSE(uncalled_cb.called()); |
| 405 CheckDecodeMsg(¶ms, &shm_id, &decode_size, &decode_id); |
| 406 ASSERT_EQ(i, shm_id); |
| 407 ASSERT_EQ(kDecodeBufferSize, decode_size); |
| 408 // The resource generates uids internally, starting at 1. |
| 409 int32_t uid = i + 1; |
| 410 ASSERT_EQ(uid, decode_id); |
| 411 } |
| 412 // Once we've allocated the maximum number of buffers, we must wait. |
| 413 PpapiHostMsg_VideoDecoder_GetShm shm_msg(7U, kDecodeBufferSize); |
| 414 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 415 CallDecode(decoder.get(), &decode_cb, &shm_msg)); |
| 416 CheckDecodeMsg(¶ms, &shm_id, &decode_size, &decode_id); |
| 417 ASSERT_EQ(7U, shm_id); |
| 418 ASSERT_EQ(kDecodeBufferSize, decode_size); |
| 419 |
| 420 // Calling Decode when another Decode is pending should fail. |
| 421 ASSERT_EQ(PP_ERROR_INPROGRESS, CallDecode(decoder.get(), &uncalled_cb, NULL)); |
| 422 ASSERT_FALSE(uncalled_cb.called()); |
| 423 // Free up the first decode buffer. |
| 424 SendDecodeReply(params, 0U); |
| 425 // The decoder should run the pending callback. |
| 426 ASSERT_TRUE(decode_cb.called()); |
| 427 ASSERT_EQ(PP_OK, decode_cb.result()); |
| 428 decode_cb.Reset(); |
| 429 |
| 430 // Now try to get a picture. No picture ready message has been received yet. |
| 431 PP_VideoPicture picture; |
| 432 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 433 CallGetPicture(decoder.get(), &picture, &get_picture_cb)); |
| 434 ASSERT_FALSE(get_picture_cb.called()); |
| 435 // Calling GetPicture when another GetPicture is pending should fail. |
| 436 ASSERT_EQ(PP_ERROR_INPROGRESS, |
| 437 CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| 438 ASSERT_FALSE(uncalled_cb.called()); |
| 439 // Send 'request textures' message to initialize textures. |
| 440 SendRequestTextures(params); |
| 441 // Send a picture ready message for Decode call 1. The GetPicture callback |
| 442 // should complete. |
| 443 SendPictureReady(params, 1U, kTextureId1); |
| 444 ASSERT_TRUE(get_picture_cb.called()); |
| 445 ASSERT_EQ(PP_OK, get_picture_cb.result()); |
| 446 ASSERT_EQ(kDecodeId, picture.decode_id); |
| 447 get_picture_cb.Reset(); |
| 448 |
| 449 // Send a picture ready message for Decode call 2. Since there is no pending |
| 450 // GetPicture call, the picture should be queued. |
| 451 SendPictureReady(params, 2U, kTextureId2); |
| 452 // The next GetPicture should return synchronously. |
| 453 ASSERT_EQ(PP_OK, CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| 454 ASSERT_FALSE(uncalled_cb.called()); |
| 455 ASSERT_EQ(kDecodeId, picture.decode_id); |
| 456 } |
| 457 #endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 458 |
| 459 // TODO(bbudge) Fix sync message testing on Windows 64 bit builds. The reply |
| 460 // message for GetShm isn't received, causing Decode to fail. |
| 461 // http://crbug.com/379260 |
| 462 #if !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 463 TEST_F(VideoDecoderResourceTest, RecyclePicture) { |
| 464 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 465 ResourceMessageCallParams params; |
| 466 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| 467 |
| 468 // Get to a state where we have a picture to recycle. |
| 469 PpapiHostMsg_VideoDecoder_GetShm shm_msg(0U, kDecodeBufferSize); |
| 470 ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &decode_cb, &shm_msg)); |
| 471 uint32_t shm_id; |
| 472 uint32_t decode_size; |
| 473 int32_t decode_id; |
| 474 CheckDecodeMsg(¶ms, &shm_id, &decode_size, &decode_id); |
| 475 SendDecodeReply(params, 0U); |
| 476 // Send 'request textures' message to initialize textures. |
| 477 SendRequestTextures(params); |
| 478 // Call GetPicture and send 'picture ready' message to get a picture to |
| 479 // recycle. |
| 480 PP_VideoPicture picture; |
| 481 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 482 CallGetPicture(decoder.get(), &picture, &get_picture_cb)); |
| 483 SendPictureReady(params, 0U, kTextureId1); |
| 484 ASSERT_EQ(kTextureId1, picture.texture_id); |
| 485 |
| 486 CallRecyclePicture(decoder.get(), picture); |
| 487 uint32_t texture_id; |
| 488 ASSERT_TRUE(CheckRecyclePictureMsg(¶ms, &texture_id)); |
| 489 ASSERT_EQ(kTextureId1, texture_id); |
| 490 |
| 491 ClearCallbacks(decoder.get()); |
| 492 } |
| 493 #endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 494 |
| 495 TEST_F(VideoDecoderResourceTest, Flush) { |
| 496 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 497 ResourceMessageCallParams params, params2; |
| 498 MockCompletionCallback flush_cb, get_picture_cb, uncalled_cb; |
| 499 |
| 500 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallFlush(decoder.get(), &flush_cb)); |
| 501 ASSERT_FALSE(flush_cb.called()); |
| 502 ASSERT_TRUE(CheckFlushMsg(¶ms)); |
| 503 |
| 504 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb, NULL)); |
| 505 ASSERT_FALSE(uncalled_cb.called()); |
| 506 |
| 507 // Plugin can call GetPicture while Flush is pending. |
| 508 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 509 CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| 510 ASSERT_FALSE(get_picture_cb.called()); |
| 511 |
| 512 ASSERT_EQ(PP_ERROR_INPROGRESS, CallFlush(decoder.get(), &uncalled_cb)); |
| 513 ASSERT_FALSE(uncalled_cb.called()); |
| 514 |
| 515 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 516 ASSERT_FALSE(uncalled_cb.called()); |
| 517 |
| 518 // Plugin can call RecyclePicture while Flush is pending. |
| 519 PP_VideoPicture picture; |
| 520 picture.texture_id = kTextureId1; |
| 521 CallRecyclePicture(decoder.get(), picture); |
| 522 uint32_t texture_id; |
| 523 ASSERT_TRUE(CheckRecyclePictureMsg(¶ms2, &texture_id)); |
| 524 |
| 525 SendFlushReply(params); |
| 526 // Any pending GetPicture call is aborted. |
| 527 ASSERT_TRUE(get_picture_cb.called()); |
| 528 ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result()); |
| 529 ASSERT_TRUE(flush_cb.called()); |
| 530 ASSERT_EQ(PP_OK, flush_cb.result()); |
| 531 } |
| 532 |
| 533 // TODO(bbudge) Test Reset when we can run the message loop to get aborted |
| 534 // callbacks to run. |
| 535 |
| 536 // TODO(bbudge) Fix sync message testing on Windows 64 bit builds. The reply |
| 537 // message for GetShm isn't received, causing Decode to fail. |
| 538 // http://crbug.com/379260 |
| 539 #if !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 540 TEST_F(VideoDecoderResourceTest, NotifyError) { |
| 541 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 542 ResourceMessageCallParams params; |
| 543 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| 544 |
| 545 // Call Decode and GetPicture to have some pending requests. |
| 546 PpapiHostMsg_VideoDecoder_GetShm shm_msg(0U, kDecodeBufferSize); |
| 547 ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &decode_cb, &shm_msg)); |
| 548 ASSERT_FALSE(decode_cb.called()); |
| 549 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 550 CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| 551 ASSERT_FALSE(get_picture_cb.called()); |
| 552 |
| 553 // Send the decoder resource an unsolicited notify error message. We first |
| 554 // need to initialize 'params' so the message is routed to the decoder. |
| 555 uint32_t shm_id; |
| 556 uint32_t decode_size; |
| 557 int32_t decode_id; |
| 558 CheckDecodeMsg(¶ms, &shm_id, &decode_size, &decode_id); |
| 559 SendNotifyError(params, PP_ERROR_RESOURCE_FAILED); |
| 560 |
| 561 // Any pending message should be run with the reported error. |
| 562 ASSERT_TRUE(get_picture_cb.called()); |
| 563 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, get_picture_cb.result()); |
| 564 |
| 565 // All further calls return the reported error. |
| 566 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, |
| 567 CallDecode(decoder.get(), &uncalled_cb, NULL)); |
| 568 ASSERT_FALSE(uncalled_cb.called()); |
| 569 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, |
| 570 CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| 571 ASSERT_FALSE(uncalled_cb.called()); |
| 572 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| 573 ASSERT_FALSE(uncalled_cb.called()); |
| 574 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 575 ASSERT_FALSE(uncalled_cb.called()); |
| 576 } |
| 577 #endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
| 578 |
| 579 } // namespace proxy |
| 580 } // namespace ppapi |
OLD | NEW |