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