OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_video_decoder.h" | 10 #include "ppapi/c/ppb_video_decoder.h" |
11 #include "ppapi/proxy/locking_resource_releaser.h" | 11 #include "ppapi/proxy/locking_resource_releaser.h" |
12 #include "ppapi/proxy/plugin_message_filter.h" | 12 #include "ppapi/proxy/plugin_message_filter.h" |
13 #include "ppapi/proxy/ppapi_message_utils.h" | 13 #include "ppapi/proxy/ppapi_message_utils.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/proxy/ppapi_proxy_test.h" | 15 #include "ppapi/proxy/ppapi_proxy_test.h" |
16 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" | 16 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
17 #include "ppapi/proxy/video_decoder_constants.h" | 17 #include "ppapi/proxy/video_decoder_constants.h" |
18 #include "ppapi/proxy/video_decoder_resource.h" | 18 #include "ppapi/proxy/video_decoder_resource.h" |
19 #include "ppapi/shared_impl/proxy_lock.h" | 19 #include "ppapi/shared_impl/proxy_lock.h" |
20 #include "ppapi/thunk/thunk.h" | 20 #include "ppapi/thunk/thunk.h" |
21 | 21 |
22 using ppapi::proxy::ResourceMessageTestSink; | 22 using ppapi::proxy::ResourceMessageTestSink; |
23 | 23 |
24 namespace ppapi { | 24 namespace ppapi { |
25 namespace proxy { | 25 namespace proxy { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const PP_Bool kAllowSoftwareFallback = PP_TRUE; | |
30 const PP_Resource kGraphics3D = 7; | 29 const PP_Resource kGraphics3D = 7; |
31 const uint32_t kShmSize = 256; | 30 const uint32_t kShmSize = 256; |
32 const size_t kDecodeBufferSize = 16; | 31 const size_t kDecodeBufferSize = 16; |
33 const uint32_t kDecodeId = 5; | 32 const uint32_t kDecodeId = 5; |
34 const uint32_t kTextureId1 = 1; | 33 const uint32_t kTextureId1 = 1; |
35 const uint32_t kTextureId2 = 2; | 34 const uint32_t kTextureId2 = 2; |
36 const uint32_t kNumRequestedTextures = 2; | 35 const uint32_t kNumRequestedTextures = 2; |
37 | 36 |
38 class MockCompletionCallback { | 37 class MockCompletionCallback { |
39 public: | 38 public: |
(...skipping 12 matching lines...) Expand all Loading... |
52 } | 51 } |
53 | 52 |
54 private: | 53 private: |
55 bool called_; | 54 bool called_; |
56 int32_t result_; | 55 int32_t result_; |
57 }; | 56 }; |
58 | 57 |
59 class VideoDecoderResourceTest : public PluginProxyTest { | 58 class VideoDecoderResourceTest : public PluginProxyTest { |
60 public: | 59 public: |
61 VideoDecoderResourceTest() | 60 VideoDecoderResourceTest() |
62 : decoder_iface_(thunk::GetPPB_VideoDecoder_0_1_Thunk()) {} | 61 : decoder_iface_(thunk::GetPPB_VideoDecoder_0_2_Thunk()) {} |
63 | 62 |
64 const PPB_VideoDecoder_0_1* decoder_iface() const { return decoder_iface_; } | 63 const PPB_VideoDecoder_0_2* decoder_iface() const { return decoder_iface_; } |
65 | 64 |
66 void SendReply(const ResourceMessageCallParams& params, | 65 void SendReply(const ResourceMessageCallParams& params, |
67 int32_t result, | 66 int32_t result, |
68 const IPC::Message& nested_message) { | 67 const IPC::Message& nested_message) { |
69 ResourceMessageReplyParams reply_params(params.pp_resource(), | 68 ResourceMessageReplyParams reply_params(params.pp_resource(), |
70 params.sequence()); | 69 params.sequence()); |
71 reply_params.set_result(result); | 70 reply_params.set_result(result); |
72 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, | 71 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
73 nested_message); | 72 nested_message); |
74 } | 73 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 109 } |
111 | 110 |
112 PP_Resource CreateAndInitializeDecoder() { | 111 PP_Resource CreateAndInitializeDecoder() { |
113 PP_Resource decoder = CreateDecoder(); | 112 PP_Resource decoder = CreateDecoder(); |
114 LockingResourceReleaser graphics3d(CreateGraphics3d()); | 113 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
115 MockCompletionCallback cb; | 114 MockCompletionCallback cb; |
116 int32_t result = decoder_iface()->Initialize( | 115 int32_t result = decoder_iface()->Initialize( |
117 decoder, | 116 decoder, |
118 graphics3d.get(), | 117 graphics3d.get(), |
119 PP_VIDEOPROFILE_H264MAIN, | 118 PP_VIDEOPROFILE_H264MAIN, |
120 PP_TRUE /* allow_software_fallback */, | 119 PP_HARDWAREACCELERATION_WITHFALLBACK, |
121 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, | 120 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
122 &cb)); | 121 &cb)); |
123 if (result != PP_OK_COMPLETIONPENDING) | 122 if (result != PP_OK_COMPLETIONPENDING) |
124 return 0; | 123 return 0; |
125 ResourceMessageCallParams params; | 124 ResourceMessageCallParams params; |
126 IPC::Message msg; | 125 IPC::Message msg; |
127 if (!sink().GetFirstResourceCallMatching( | 126 if (!sink().GetFirstResourceCallMatching( |
128 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)) | 127 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)) |
129 return 0; | 128 return 0; |
130 sink().ClearMessages(); | 129 sink().ClearMessages(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 291 |
293 private: | 292 private: |
294 bool CheckMsg(ResourceMessageCallParams* params, int id) { | 293 bool CheckMsg(ResourceMessageCallParams* params, int id) { |
295 IPC::Message msg; | 294 IPC::Message msg; |
296 if (!sink().GetFirstResourceCallMatching(id, params, &msg)) | 295 if (!sink().GetFirstResourceCallMatching(id, params, &msg)) |
297 return false; | 296 return false; |
298 sink().ClearMessages(); | 297 sink().ClearMessages(); |
299 return true; | 298 return true; |
300 } | 299 } |
301 | 300 |
302 const PPB_VideoDecoder_0_1* decoder_iface_; | 301 const PPB_VideoDecoder_0_2* decoder_iface_; |
303 | 302 |
304 char decode_buffer_[kDecodeBufferSize]; | 303 char decode_buffer_[kDecodeBufferSize]; |
305 }; | 304 }; |
306 | 305 |
307 } // namespace | 306 } // namespace |
308 | 307 |
309 TEST_F(VideoDecoderResourceTest, Initialize) { | 308 TEST_F(VideoDecoderResourceTest, Initialize) { |
310 // Initialize with 0 graphics3d_context should fail. | 309 // Initialize with 0 graphics3d_context should fail. |
311 { | 310 { |
312 LockingResourceReleaser decoder(CreateDecoder()); | 311 LockingResourceReleaser decoder(CreateDecoder()); |
313 MockCompletionCallback cb; | 312 MockCompletionCallback cb; |
314 int32_t result = decoder_iface()->Initialize( | 313 int32_t result = decoder_iface()->Initialize( |
315 decoder.get(), | 314 decoder.get(), |
316 0 /* invalid 3d graphics */, | 315 0 /* invalid 3d graphics */, |
317 PP_VIDEOPROFILE_H264MAIN, | 316 PP_VIDEOPROFILE_H264MAIN, |
318 kAllowSoftwareFallback, | 317 PP_HARDWAREACCELERATION_WITHFALLBACK, |
319 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, | 318 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
320 &cb)); | 319 &cb)); |
321 ASSERT_EQ(PP_ERROR_BADRESOURCE, result); | 320 ASSERT_EQ(PP_ERROR_BADRESOURCE, result); |
322 } | 321 } |
323 // Initialize with bad profile value should fail. | 322 // Initialize with bad profile value should fail. |
324 { | 323 { |
325 LockingResourceReleaser decoder(CreateDecoder()); | 324 LockingResourceReleaser decoder(CreateDecoder()); |
326 MockCompletionCallback cb; | 325 MockCompletionCallback cb; |
327 int32_t result = decoder_iface()->Initialize( | 326 int32_t result = decoder_iface()->Initialize( |
328 decoder.get(), | 327 decoder.get(), |
329 1 /* non-zero resource */, | 328 1 /* non-zero resource */, |
330 static_cast<PP_VideoProfile>(-1), | 329 static_cast<PP_VideoProfile>(-1), |
331 kAllowSoftwareFallback, | 330 PP_HARDWAREACCELERATION_WITHFALLBACK, |
332 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, | 331 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
333 &cb)); | 332 &cb)); |
334 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 333 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
335 } | 334 } |
336 // Initialize with valid graphics3d_context and profile should succeed. | 335 // Initialize with valid graphics3d_context and profile should succeed. |
337 { | 336 { |
338 LockingResourceReleaser decoder(CreateDecoder()); | 337 LockingResourceReleaser decoder(CreateDecoder()); |
339 LockingResourceReleaser graphics3d(CreateGraphics3d()); | 338 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
340 MockCompletionCallback cb; | 339 MockCompletionCallback cb; |
341 int32_t result = decoder_iface()->Initialize( | 340 int32_t result = decoder_iface()->Initialize( |
342 decoder.get(), | 341 decoder.get(), |
343 graphics3d.get(), | 342 graphics3d.get(), |
344 PP_VIDEOPROFILE_H264MAIN, | 343 PP_VIDEOPROFILE_H264MAIN, |
345 kAllowSoftwareFallback, | 344 PP_HARDWAREACCELERATION_WITHFALLBACK, |
346 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, | 345 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
347 &cb)); | 346 &cb)); |
348 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 347 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
349 ASSERT_TRUE(decoder_iface()->IsVideoDecoder(decoder.get())); | 348 ASSERT_TRUE(decoder_iface()->IsVideoDecoder(decoder.get())); |
350 | 349 |
351 // Another attempt while pending should fail. | 350 // Another attempt while pending should fail. |
352 result = decoder_iface()->Initialize( | 351 result = decoder_iface()->Initialize( |
353 decoder.get(), | 352 decoder.get(), |
354 graphics3d.get(), | 353 graphics3d.get(), |
355 PP_VIDEOPROFILE_H264MAIN, | 354 PP_VIDEOPROFILE_H264MAIN, |
356 kAllowSoftwareFallback, | 355 PP_HARDWAREACCELERATION_WITHFALLBACK, |
357 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, | 356 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback, |
358 &cb)); | 357 &cb)); |
359 ASSERT_EQ(PP_ERROR_INPROGRESS, result); | 358 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
360 | 359 |
361 // Check for host message and send a reply to complete initialization. | 360 // Check for host message and send a reply to complete initialization. |
362 ResourceMessageCallParams params; | 361 ResourceMessageCallParams params; |
363 IPC::Message msg; | 362 IPC::Message msg; |
364 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 363 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
365 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)); | 364 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)); |
366 sink().ClearMessages(); | 365 sink().ClearMessages(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 ASSERT_FALSE(uncalled_cb.called()); | 573 ASSERT_FALSE(uncalled_cb.called()); |
575 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallFlush(decoder.get(), &uncalled_cb)); | 574 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
576 ASSERT_FALSE(uncalled_cb.called()); | 575 ASSERT_FALSE(uncalled_cb.called()); |
577 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallReset(decoder.get(), &uncalled_cb)); | 576 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
578 ASSERT_FALSE(uncalled_cb.called()); | 577 ASSERT_FALSE(uncalled_cb.called()); |
579 } | 578 } |
580 #endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) | 579 #endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS) |
581 | 580 |
582 } // namespace proxy | 581 } // namespace proxy |
583 } // namespace ppapi | 582 } // namespace ppapi |
OLD | NEW |