Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: ppapi/proxy/video_encoder_resource_unittest.cc

Issue 905023005: Pepper: PPB_VideoEncoder implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix size_t->uint32_t conversion on Windows Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "base/memory/shared_memory.h"
6 #include "base/process/process.h"
7 #include "base/synchronization/waitable_event.h"
8 #include "ppapi/c/pp_codecs.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_video_encoder.h"
11 #include "ppapi/c/ppb_video_frame.h"
12 #include "ppapi/proxy/locking_resource_releaser.h"
13 #include "ppapi/proxy/plugin_message_filter.h"
14 #include "ppapi/proxy/ppapi_message_utils.h"
15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "ppapi/proxy/ppapi_proxy_test.h"
17 #include "ppapi/proxy/video_encoder_resource.h"
18 #include "ppapi/shared_impl/media_stream_buffer.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 class MockCompletionCallback {
30 public:
31 MockCompletionCallback() : called_(false), call_event_(false, false) {}
32
33 bool called() { return called_; }
34 int32_t result() { return result_; }
35
36 void WaitUntilCalled() { call_event_.Wait(); }
37
38 void Reset() {
39 called_ = false;
40 call_event_.Reset();
41 }
42
43 static void Callback(void* user_data, int32_t result) {
44 MockCompletionCallback* that =
45 reinterpret_cast<MockCompletionCallback*>(user_data);
46 that->call_event_.Signal();
47 that->called_ = true;
48 that->result_ = result;
49 }
50
51 private:
52 bool called_;
53 int32_t result_;
54 base::WaitableEvent call_event_;
55 };
56
57 class VideoEncoderResourceTest : public PluginProxyTest,
58 public MediaStreamBufferManager::Delegate {
59 public:
60 VideoEncoderResourceTest()
61 : encoder_iface_(thunk::GetPPB_VideoEncoder_0_1_Thunk()),
62 video_frames_manager_(this) {}
63 ~VideoEncoderResourceTest() override {}
64
65 const PPB_VideoEncoder_0_1* encoder_iface() const { return encoder_iface_; }
66
67 const uint32_t kBitstreamBufferSize = 4000;
68 const uint32_t kBitstreamBufferCount = 5;
69 const uint32_t kVideoFrameCount = 3;
70 const uint32_t kBitrate = 200000;
71
72 const PP_Size kFrameSize = PP_MakeSize(640, 480);
73
74 void SendReply(const ResourceMessageCallParams& params,
75 int32_t result,
76 const IPC::Message& nested_message) {
77 ResourceMessageReplyParams reply_params(params.pp_resource(),
78 params.sequence());
79 reply_params.set_result(result);
80 PluginMessageFilter::DispatchResourceReplyForTest(reply_params,
81 nested_message);
82 }
83
84 void SendReplyWithHandle(const ResourceMessageCallParams& params,
85 int32_t result,
86 const IPC::Message& nested_message,
87 const SerializedHandle& handle) {
88 ResourceMessageReplyParams reply_params(params.pp_resource(),
89 params.sequence());
90 reply_params.set_result(result);
91 reply_params.AppendHandle(handle);
92 PluginMessageFilter::DispatchResourceReplyForTest(reply_params,
93 nested_message);
94 }
95
96 void SendReplyWithHandles(const ResourceMessageCallParams& params,
97 int32_t result,
98 const IPC::Message& nested_message,
99 const std::vector<SerializedHandle>& handles) {
100 ResourceMessageReplyParams reply_params(params.pp_resource(),
101 params.sequence());
102 reply_params.set_result(result);
103 for (SerializedHandle handle : handles)
104 reply_params.AppendHandle(handle);
105 PluginMessageFilter::DispatchResourceReplyForTest(reply_params,
106 nested_message);
107 }
108
109 PP_Resource CreateEncoder() {
110 PP_Resource result = encoder_iface()->Create(pp_instance());
111 return result;
112 }
113
114 void CreateBitstreamSharedMemory(uint32_t buffer_size, uint32_t nb_buffers) {
115 shared_memory_bitstreams_.clear();
116 for (uint32_t i = 0; i < nb_buffers; ++i) {
117 scoped_ptr<base::SharedMemory> mem(new base::SharedMemory());
118 ASSERT_TRUE(mem->CreateAnonymous(buffer_size));
119 shared_memory_bitstreams_.push_back(mem.Pass());
120 }
121 }
122
123 void CreateVideoFramesSharedMemory(uint32_t frame_length,
124 uint32_t frame_count) {
125 scoped_ptr<base::SharedMemory> shared_memory_frames(
126 new base::SharedMemory());
127 uint32_t buffer_length =
128 frame_length + sizeof(ppapi::MediaStreamBuffer::Video);
129 ASSERT_TRUE(shared_memory_frames->CreateAnonymous(buffer_length *
130 frame_count));
131 ASSERT_TRUE(video_frames_manager_.SetBuffers(frame_count,
132 buffer_length,
133 shared_memory_frames.Pass(),
134 true));
135 for (int32_t i = 0; i < video_frames_manager_.number_of_buffers(); ++i) {
136 ppapi::MediaStreamBuffer::Video* buffer =
137 &(video_frames_manager_.GetBufferPointer(i)->video);
138 buffer->header.size = buffer_length;
139 buffer->header.type = ppapi::MediaStreamBuffer::TYPE_VIDEO;
140 buffer->format = PP_VIDEOFRAME_FORMAT_I420;
141 buffer->size = kFrameSize;
142 buffer->data_size = frame_length;
143 }
144 }
145
146 PP_Resource CreateAndInitializeEncoder() {
147 PP_Resource encoder = CreateEncoder();
148 PP_Size size = kFrameSize;
149 MockCompletionCallback cb;
150 int32_t result = encoder_iface()->Initialize(
151 encoder, PP_VIDEOFRAME_FORMAT_I420, &size, PP_VIDEOPROFILE_H264MAIN,
152 kBitrate, PP_HARDWAREACCELERATION_WITHFALLBACK,
153 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
154 &cb));
155 if (result != PP_OK_COMPLETIONPENDING)
156 return 0;
157 ResourceMessageCallParams params;
158 IPC::Message msg;
159 if (!sink().GetFirstResourceCallMatching(
160 PpapiHostMsg_VideoEncoder_Initialize::ID, &params, &msg))
161 return 0;
162 sink().ClearMessages();
163
164 SendInitializeReply(params, PP_OK, kVideoFrameCount, kFrameSize);
165 CreateBitstreamSharedMemory(kBitstreamBufferSize, kBitstreamBufferCount);
166 SendBitstreamBuffers(params, kBitstreamBufferSize);
167
168 if (!cb.called() || cb.result() != PP_OK)
169 return 0;
170
171 return encoder;
172 }
173
174 int32_t CallGetFramesRequired(PP_Resource pp_encoder) {
175 return encoder_iface()->GetFramesRequired(pp_encoder);
176 }
177
178 int32_t CallGetFrameCodedSize(PP_Resource pp_encoder, PP_Size* coded_size) {
179 return encoder_iface()->GetFrameCodedSize(pp_encoder, coded_size);
180 }
181
182 int32_t CallGetVideoFrame(PP_Resource pp_encoder,
183 PP_Resource* video_frame,
184 MockCompletionCallback* cb) {
185 return encoder_iface()->GetVideoFrame(
186 pp_encoder, video_frame, PP_MakeOptionalCompletionCallback(
187 &MockCompletionCallback::Callback, cb));
188 }
189
190 int32_t CallFirstGetVideoFrame(PP_Resource pp_encoder,
191 PP_Resource* video_frame,
192 MockCompletionCallback* cb) {
193 int32_t result = encoder_iface()->GetVideoFrame(
194 pp_encoder, video_frame, PP_MakeOptionalCompletionCallback(
195 &MockCompletionCallback::Callback, cb));
196 if (result != PP_OK_COMPLETIONPENDING)
197 return result;
198
199 ResourceMessageCallParams params;
200 CheckGetVideoFramesMsg(&params);
201
202 uint32_t frame_length = kFrameSize.width * kFrameSize.height * 2;
203 CreateVideoFramesSharedMemory(frame_length, kVideoFrameCount);
204 SendGetVideoFramesReply(params, kVideoFrameCount, frame_length, kFrameSize);
205
206 return result;
207 }
208
209 int32_t CallEncode(PP_Resource pp_encoder,
210 PP_Resource video_frame,
211 PP_Bool force_keyframe,
212 MockCompletionCallback* cb) {
213 return encoder_iface()->Encode(pp_encoder, video_frame, force_keyframe,
214 PP_MakeOptionalCompletionCallback(
215 &MockCompletionCallback::Callback, cb));
216 }
217
218 int32_t CallCompleteEncode(PP_Resource pp_encoder,
219 PP_Resource video_frame,
220 PP_Bool force_keyframe,
221 MockCompletionCallback* cb) {
222 int32_t result =
223 encoder_iface()->Encode(pp_encoder, video_frame, force_keyframe,
224 PP_MakeOptionalCompletionCallback(
225 &MockCompletionCallback::Callback, cb));
226 if (result != PP_OK_COMPLETIONPENDING)
227 return result;
228
229 ResourceMessageCallParams params;
230 uint32_t frame_id;
231 bool forced_keyframe;
232 if (!CheckEncodeMsg(&params, &frame_id, &forced_keyframe))
233 return PP_ERROR_FAILED;
234
235 SendEncodeReply(params, frame_id);
236
237 return result;
238 }
239
240 int32_t CallGetBitstreamBuffer(PP_Resource pp_encoder,
241 PP_BitstreamBuffer* bitstream_buffer,
242 MockCompletionCallback* cb) {
243 return encoder_iface()->GetBitstreamBuffer(
244 pp_encoder, bitstream_buffer,
245 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
246 cb));
247 }
248
249 void CallRecycleBitstreamBuffer(PP_Resource pp_encoder,
250 const PP_BitstreamBuffer& buffer) {
251 encoder_iface()->RecycleBitstreamBuffer(pp_encoder, &buffer);
252 }
253
254 void CallRequestEncodingParametersChange(PP_Resource pp_encoder,
255 uint32_t bitrate,
256 uint32_t framerate) {
257 encoder_iface()->RequestEncodingParametersChange(pp_encoder, bitrate,
258 framerate);
259 }
260
261 void CallClose(PP_Resource pp_encoder) {
262 encoder_iface()->Close(pp_encoder);
263 }
264
265 void SendGetSupportedProfilesReply(
266 const ResourceMessageCallParams& params,
267 const std::vector<PP_VideoProfileDescription>& profiles) {
268 SendReply(params, PP_OK,
269 PpapiPluginMsg_VideoEncoder_GetSupportedProfilesReply(profiles));
270 }
271
272 void SendInitializeReply(const ResourceMessageCallParams& params,
273 int32_t success,
274 uint32_t input_frame_count,
275 const PP_Size& input_coded_size) {
276 SendReply(params, success, PpapiPluginMsg_VideoEncoder_InitializeReply(
277 input_frame_count, input_coded_size));
278 }
279
280 void SendBitstreamBuffers(const ResourceMessageCallParams& params,
281 uint32_t buffer_length) {
282 std::vector<SerializedHandle> handles;
283 for (base::SharedMemory* mem : shared_memory_bitstreams_) {
284 ASSERT_EQ(mem->requested_size(), buffer_length);
285 base::SharedMemoryHandle handle;
286
287 ASSERT_TRUE(
288 mem->ShareToProcess(base::Process::Current().Handle(), &handle));
289 handles.push_back(SerializedHandle(handle, buffer_length));
290 }
291 SendReplyWithHandles(
292 params, PP_OK,
293 PpapiPluginMsg_VideoEncoder_BitstreamBuffers(buffer_length), handles);
294 }
295
296 void SendGetVideoFramesReply(const ResourceMessageCallParams& params,
297 uint32_t frame_count,
298 uint32_t frame_length,
299 const PP_Size& size) {
300 base::SharedMemoryHandle handle;
301 ASSERT_TRUE(video_frames_manager_.shm()->ShareToProcess(
302 base::Process::Current().Handle(), &handle));
303 SendReplyWithHandle(
304 params, PP_OK, PpapiPluginMsg_VideoEncoder_GetVideoFramesReply(
305 frame_count,
306 frame_length + sizeof(MediaStreamBuffer::Video),
307 size),
308 SerializedHandle(handle,
309 video_frames_manager_.shm()->requested_size()));
310 }
311
312 void SendEncodeReply(const ResourceMessageCallParams& params,
313 uint32_t frame_id) {
314 SendReply(params, PP_OK, PpapiPluginMsg_VideoEncoder_EncodeReply(frame_id));
315 }
316
317 void SendBitstreamBufferReady(const ResourceMessageCallParams& params,
318 uint32_t buffer_id,
319 uint32_t buffer_size,
320 bool keyframe) {
321 SendReply(params, PP_OK,
322 PpapiPluginMsg_VideoEncoder_BitstreamBufferReady(
323 buffer_id, buffer_size, PP_FromBool(keyframe)));
324 }
325
326 void SendNotifyError(const ResourceMessageCallParams& params, int32_t error) {
327 SendReply(params, PP_OK, PpapiPluginMsg_VideoEncoder_NotifyError(error));
328 }
329
330 bool CheckGetSupportedProfilesMsg(ResourceMessageCallParams* params) {
331 IPC::Message msg;
332 return sink().GetFirstResourceCallMatching(
333 PpapiHostMsg_VideoEncoder_GetSupportedProfiles::ID, params, &msg);
334 }
335
336 bool CheckInitializeMsg(ResourceMessageCallParams* params,
337 PP_VideoFrame_Format* input_format,
338 struct PP_Size* input_visible_size,
339 PP_VideoProfile* output_profile,
340 uint32_t* bitrate,
341 PP_HardwareAcceleration* acceleration) {
342 IPC::Message msg;
343 if (!sink().GetFirstResourceCallMatching(
344 PpapiHostMsg_VideoEncoder_Initialize::ID, params, &msg))
345 return false;
346 sink().ClearMessages();
347 return UnpackMessage<PpapiHostMsg_VideoEncoder_Initialize>(
348 msg, input_format, input_visible_size, output_profile, bitrate,
349 acceleration);
350 }
351
352 bool CheckGetVideoFramesMsg(ResourceMessageCallParams* params) {
353 IPC::Message msg;
354 if (!sink().GetFirstResourceCallMatching(
355 PpapiHostMsg_VideoEncoder_GetVideoFrames::ID, params, &msg))
356 return false;
357 sink().ClearMessages();
358 return true;
359 }
360
361 bool CheckEncodeMsg(ResourceMessageCallParams* params,
362 uint32_t* frame_id,
363 bool* keyframe) {
364 IPC::Message msg;
365 if (!sink().GetFirstResourceCallMatching(
366 PpapiHostMsg_VideoEncoder_Encode::ID, params, &msg))
367 return false;
368 sink().ClearMessages();
369 return UnpackMessage<PpapiHostMsg_VideoEncoder_Encode>(msg, frame_id,
370 keyframe);
371 }
372
373 bool CheckRecycleBitstreamBufferMsg(ResourceMessageCallParams* params,
374 uint32_t* buffer_id) {
375 IPC::Message msg;
376 if (!sink().GetFirstResourceCallMatching(
377 PpapiHostMsg_VideoEncoder_RecycleBitstreamBuffer::ID, params, &msg))
378 return false;
379 sink().ClearMessages();
380 return UnpackMessage<PpapiHostMsg_VideoEncoder_RecycleBitstreamBuffer>(
381 msg, buffer_id);
382 }
383
384 bool CheckRequestEncodingParametersChangeMsg(
385 ResourceMessageCallParams* params,
386 uint32_t* bitrate,
387 uint32_t* framerate) {
388 IPC::Message msg;
389 if (!sink().GetFirstResourceCallMatching(
390 PpapiHostMsg_VideoEncoder_RequestEncodingParametersChange::ID,
391 params, &msg))
392 return false;
393 sink().ClearMessages();
394 return UnpackMessage<
395 PpapiHostMsg_VideoEncoder_RequestEncodingParametersChange>(msg, bitrate,
396 framerate);
397 }
398
399 bool CheckIsVideoFrame(PP_Resource video_frame) {
400 return thunk::GetPPB_VideoFrame_0_1_Thunk()->IsVideoFrame(video_frame);
401 }
402
403 bool CheckIsVideoFrameValid(PP_Resource video_frame) {
404 PP_Size frame_size;
405 return thunk::GetPPB_VideoFrame_0_1_Thunk()->GetSize(
406 video_frame, &frame_size) == PP_TRUE;
407 }
408
409 private:
410 // MediaStreamBufferManager::Delegate:
411 void OnNewBufferEnqueued() override {}
412
413 const PPB_VideoEncoder_0_1* encoder_iface_;
414
415 ScopedVector<base::SharedMemory> shared_memory_bitstreams_;
416
417 MediaStreamBufferManager video_frames_manager_;
418 };
419
420 void* ForwardUserData(void* user_data,
421 uint32_t element_count,
422 uint32_t element_size) {
423 return user_data;
424 }
425
426 } // namespace
427
428 TEST_F(VideoEncoderResourceTest, GetSupportedProfiles) {
429 // Verifies that GetSupportedProfiles calls into the renderer and
430 // the we get the right results back.
431 {
432 LockingResourceReleaser encoder(CreateEncoder());
433 PP_VideoProfileDescription profiles[2];
434 PP_ArrayOutput output;
435 output.user_data = &profiles[0];
436 output.GetDataBuffer = ForwardUserData;
437 ResourceMessageCallParams params;
438 MockCompletionCallback cb;
439 int32_t result = encoder_iface()->GetSupportedProfiles(
440 encoder.get(), output, PP_MakeOptionalCompletionCallback(
441 &MockCompletionCallback::Callback, &cb));
442 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
443 ASSERT_TRUE(CheckGetSupportedProfilesMsg(&params));
444
445 std::vector<PP_VideoProfileDescription> profiles_response;
446 PP_VideoProfileDescription profile;
447 profile.profile = PP_VIDEOPROFILE_H264MAIN;
448 profile.max_resolution.width = 1920;
449 profile.max_resolution.height = 1080;
450 profile.max_framerate_numerator = 30;
451 profile.max_framerate_denominator = 1;
452 profile.acceleration = PP_HARDWAREACCELERATION_ONLY;
453 profiles_response.push_back(profile);
454 profile.profile = PP_VIDEOPROFILE_VP8_ANY;
455 profile.max_resolution.width = 1920;
456 profile.max_resolution.height = 1080;
457 profile.max_framerate_numerator = 30;
458 profile.max_framerate_denominator = 1;
459 profile.acceleration = PP_HARDWAREACCELERATION_NONE;
460 profiles_response.push_back(profile);
461
462 SendGetSupportedProfilesReply(params, profiles_response);
463 ASSERT_EQ(PP_OK, cb.result());
464
465 ASSERT_EQ(2U, profiles_response.size());
466 ASSERT_EQ(0, memcmp(&profiles[0], &profiles_response[0],
467 sizeof(PP_VideoProfileDescription) * 2));
468 }
469 }
470
471 TEST_F(VideoEncoderResourceTest, InitializeFailure) {
472 {
473 // Verify the initialize callback is called in case of failure.
474 LockingResourceReleaser encoder(CreateEncoder());
475 ResourceMessageCallParams params;
476 PP_Size size = kFrameSize;
477 MockCompletionCallback cb;
478 int32_t result = encoder_iface()->Initialize(
479 encoder.get(), PP_VIDEOFRAME_FORMAT_BGRA, &size,
480 PP_VIDEOPROFILE_H264MAIN, kBitrate,
481 PP_HARDWAREACCELERATION_WITHFALLBACK,
482 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
483 &cb));
484 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
485
486 PP_VideoFrame_Format input_format;
487 PP_Size input_visible_size;
488 PP_VideoProfile output_profile;
489 uint32_t bitrate;
490 PP_HardwareAcceleration acceleration;
491 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
492 &output_profile, &bitrate, &acceleration));
493 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_BGRA, input_format);
494 ASSERT_EQ(size.width, input_visible_size.width);
495 ASSERT_EQ(size.height, input_visible_size.height);
496 ASSERT_EQ(kBitrate, bitrate);
497 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
498 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
499
500 SendInitializeReply(params, PP_ERROR_NOTSUPPORTED, kVideoFrameCount,
501 kFrameSize);
502 ASSERT_TRUE(cb.called());
503 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, cb.result());
504 }
505 {
506 // Verify the initialize callback is called in case of error
507 // notification.
508 LockingResourceReleaser encoder(CreateEncoder());
509 ResourceMessageCallParams params;
510 PP_Size size = kFrameSize;
511 MockCompletionCallback cb;
512 int32_t result = encoder_iface()->Initialize(
513 encoder.get(), PP_VIDEOFRAME_FORMAT_BGRA, &size,
514 PP_VIDEOPROFILE_H264MAIN, kBitrate,
515 PP_HARDWAREACCELERATION_WITHFALLBACK,
516 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
517 &cb));
518 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
519
520 PP_VideoFrame_Format input_format;
521 PP_Size input_visible_size;
522 PP_VideoProfile output_profile;
523 uint32_t bitrate;
524 PP_HardwareAcceleration acceleration;
525 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
526 &output_profile, &bitrate, &acceleration));
527 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_BGRA, input_format);
528 ASSERT_EQ(kFrameSize.width, input_visible_size.width);
529 ASSERT_EQ(kFrameSize.height, input_visible_size.height);
530 ASSERT_EQ(kBitrate, bitrate);
531 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
532 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
533
534 ResourceMessageCallParams error_params(encoder.get(), 0);
535 SendNotifyError(error_params, PP_ERROR_FAILED);
536 ASSERT_TRUE(cb.called());
537 ASSERT_EQ(PP_ERROR_FAILED, cb.result());
538 }
539 {
540 // Verify that calling initialize twice fails the second time if
541 // we haven't received a response yet.
542 LockingResourceReleaser encoder(CreateEncoder());
543 ResourceMessageCallParams params;
544 PP_Size size = kFrameSize;
545 MockCompletionCallback cb;
546 int32_t result = encoder_iface()->Initialize(
547 encoder.get(), PP_VIDEOFRAME_FORMAT_BGRA, &size,
548 PP_VIDEOPROFILE_H264MAIN, kBitrate,
549 PP_HARDWAREACCELERATION_WITHFALLBACK,
550 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
551 &cb));
552 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
553
554 PP_VideoFrame_Format input_format;
555 PP_Size input_visible_size;
556 PP_VideoProfile output_profile;
557 uint32_t bitrate;
558 PP_HardwareAcceleration acceleration;
559 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
560 &output_profile, &bitrate, &acceleration));
561 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_BGRA, input_format);
562 ASSERT_EQ(size.width, input_visible_size.width);
563 ASSERT_EQ(size.height, input_visible_size.height);
564 ASSERT_EQ(kBitrate, bitrate);
565 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
566 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
567
568 result = encoder_iface()->Initialize(
569 encoder.get(), PP_VIDEOFRAME_FORMAT_BGRA, &size,
570 PP_VIDEOPROFILE_H264MAIN, kBitrate,
571 PP_HARDWAREACCELERATION_WITHFALLBACK,
572 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
573 &cb));
574 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
575
576 ResourceMessageCallParams error_params(encoder.get(), 0);
577 SendNotifyError(error_params, PP_ERROR_FAILED);
578 ASSERT_TRUE(cb.called());
579 ASSERT_EQ(PP_ERROR_FAILED, cb.result());
580 }
581 }
582
583 TEST_F(VideoEncoderResourceTest, InitializeSuccess) {
584 {
585 // Verify the initialize callback is called when initialization is
586 // successfull.
587 LockingResourceReleaser encoder(CreateEncoder());
588 ResourceMessageCallParams params;
589 PP_Size size = kFrameSize;
590 const uint32_t kBitrate = 420000;
591 MockCompletionCallback cb;
592 int32_t result = encoder_iface()->Initialize(
593 encoder.get(), PP_VIDEOFRAME_FORMAT_I420, &size,
594 PP_VIDEOPROFILE_H264MAIN, kBitrate,
595 PP_HARDWAREACCELERATION_WITHFALLBACK,
596 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
597 &cb));
598 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
599
600 PP_VideoFrame_Format input_format;
601 PP_Size input_visible_size;
602 PP_VideoProfile output_profile;
603 uint32_t bitrate;
604 PP_HardwareAcceleration acceleration;
605 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
606 &output_profile, &bitrate, &acceleration));
607 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_I420, input_format);
608 ASSERT_EQ(kFrameSize.width, input_visible_size.width);
609 ASSERT_EQ(kFrameSize.height, input_visible_size.height);
610 ASSERT_EQ(kBitrate, bitrate);
611 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
612 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
613
614 SendInitializeReply(params, PP_OK, kVideoFrameCount, kFrameSize);
615
616 ASSERT_TRUE(cb.called());
617 ASSERT_EQ(PP_OK, cb.result());
618 }
619 {
620 // Verify that calling initialize a second time, after it already
621 // succeeded, fails.
622 LockingResourceReleaser encoder(CreateEncoder());
623 ResourceMessageCallParams params;
624 PP_Size size = kFrameSize;
625 const uint32_t kBitrate = 420000;
626 MockCompletionCallback cb;
627 int32_t result = encoder_iface()->Initialize(
628 encoder.get(), PP_VIDEOFRAME_FORMAT_I420, &size,
629 PP_VIDEOPROFILE_H264MAIN, kBitrate,
630 PP_HARDWAREACCELERATION_WITHFALLBACK,
631 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
632 &cb));
633 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
634
635 PP_VideoFrame_Format input_format;
636 PP_Size input_visible_size;
637 PP_VideoProfile output_profile;
638 uint32_t bitrate;
639 PP_HardwareAcceleration acceleration;
640 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
641 &output_profile, &bitrate, &acceleration));
642 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_I420, input_format);
643 ASSERT_EQ(kFrameSize.width, input_visible_size.width);
644 ASSERT_EQ(kFrameSize.height, input_visible_size.height);
645 ASSERT_EQ(kBitrate, bitrate);
646 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
647 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
648
649 SendInitializeReply(params, PP_OK, kVideoFrameCount, kFrameSize);
650
651 ASSERT_TRUE(cb.called());
652 ASSERT_EQ(PP_OK, cb.result());
653
654 result = encoder_iface()->Initialize(
655 encoder.get(), PP_VIDEOFRAME_FORMAT_I420, &size,
656 PP_VIDEOPROFILE_H264MAIN, kBitrate,
657 PP_HARDWAREACCELERATION_WITHFALLBACK,
658 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
659 &cb));
660 ASSERT_EQ(PP_ERROR_FAILED, result);
661 }
662 {
663 // Verify the sending the bitstream buffers details makes them
664 // available through the API. the right values.
665 LockingResourceReleaser encoder(CreateEncoder());
666 ResourceMessageCallParams params;
667 PP_Size size = kFrameSize;
668 const uint32_t kBitrate = 420000;
669 MockCompletionCallback cb;
670 int32_t result = encoder_iface()->Initialize(
671 encoder.get(), PP_VIDEOFRAME_FORMAT_I420, &size,
672 PP_VIDEOPROFILE_H264MAIN, kBitrate,
673 PP_HARDWAREACCELERATION_WITHFALLBACK,
674 PP_MakeOptionalCompletionCallback(&MockCompletionCallback::Callback,
675 &cb));
676 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
677
678 PP_VideoFrame_Format input_format;
679 PP_Size input_visible_size;
680 PP_VideoProfile output_profile;
681 uint32_t bitrate;
682 PP_HardwareAcceleration acceleration;
683 ASSERT_TRUE(CheckInitializeMsg(&params, &input_format, &input_visible_size,
684 &output_profile, &bitrate, &acceleration));
685 ASSERT_EQ(PP_VIDEOFRAME_FORMAT_I420, input_format);
686 ASSERT_EQ(kFrameSize.width, input_visible_size.width);
687 ASSERT_EQ(kFrameSize.height, input_visible_size.height);
688 ASSERT_EQ(kBitrate, bitrate);
689 ASSERT_EQ(PP_VIDEOPROFILE_H264MAIN, output_profile);
690 ASSERT_EQ(PP_HARDWAREACCELERATION_WITHFALLBACK, acceleration);
691
692 SendInitializeReply(params, PP_OK, kVideoFrameCount, kFrameSize);
693
694 ASSERT_TRUE(cb.called());
695 ASSERT_EQ(PP_OK, cb.result());
696
697 PP_Size coded_size;
698 ASSERT_EQ(PP_OK, CallGetFrameCodedSize(encoder.get(), &coded_size));
699 ASSERT_EQ(kFrameSize.width, coded_size.width);
700 ASSERT_EQ(kFrameSize.height, coded_size.height);
701 ASSERT_EQ(static_cast<int32_t>(kVideoFrameCount),
702 CallGetFramesRequired(encoder.get()));
703 }
704 }
705
706 TEST_F(VideoEncoderResourceTest, Uninitialized) {
707 // Operations on uninitialized encoders should fail.
708 LockingResourceReleaser encoder(CreateEncoder());
709
710 ASSERT_EQ(PP_ERROR_FAILED, CallGetFramesRequired(encoder.get()));
711
712 PP_Size size;
713 ASSERT_EQ(PP_ERROR_FAILED, CallGetFrameCodedSize(encoder.get(), &size));
714
715 MockCompletionCallback uncalled_cb;
716 PP_Resource video_frame = 0;
717 ASSERT_EQ(PP_ERROR_FAILED,
718 CallGetVideoFrame(encoder.get(), &video_frame, &uncalled_cb));
719 ASSERT_FALSE(uncalled_cb.called());
720 ASSERT_EQ(0, video_frame);
721
722 ASSERT_EQ(PP_ERROR_FAILED,
723 CallEncode(encoder.get(), video_frame, PP_FALSE, &uncalled_cb));
724 ASSERT_FALSE(uncalled_cb.called());
725
726 PP_BitstreamBuffer bitstream_buffer;
727 ASSERT_EQ(
728 PP_ERROR_FAILED,
729 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer, &uncalled_cb));
730 ASSERT_FALSE(uncalled_cb.called());
731
732 ResourceMessageCallParams params;
733 uint32_t buffer_id;
734 CallRecycleBitstreamBuffer(encoder.get(), bitstream_buffer);
735 ASSERT_FALSE(CheckRecycleBitstreamBufferMsg(&params, &buffer_id));
736
737 uint32_t bitrate, framerate;
738 CallRequestEncodingParametersChange(encoder.get(), 0, 0);
739 ASSERT_FALSE(
740 CheckRequestEncodingParametersChangeMsg(&params, &bitrate, &framerate));
741 }
742
743 TEST_F(VideoEncoderResourceTest, InitializeAndGetVideoFrame) {
744 // Verify that we can pull the right number of video frames before
745 // the proxy makes us wait.
746 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
747 ResourceMessageCallParams params;
748 std::vector<PP_Resource> video_frames;
749 MockCompletionCallback get_frame_cb;
750
751 video_frames.resize(kVideoFrameCount + 1);
752
753 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
754 CallGetVideoFrame(encoder.get(), &video_frames[0], &get_frame_cb));
755 ASSERT_FALSE(get_frame_cb.called());
756 ASSERT_TRUE(CheckGetVideoFramesMsg(&params));
757
758 uint32_t frame_length = kFrameSize.width * kFrameSize.height * 2;
759 CreateVideoFramesSharedMemory(frame_length, kVideoFrameCount);
760 SendGetVideoFramesReply(params, kVideoFrameCount, frame_length, kFrameSize);
761
762 for (uint32_t i = 1; i < kVideoFrameCount; ++i) {
763 get_frame_cb.Reset();
764 ASSERT_EQ(
765 PP_OK_COMPLETIONPENDING,
766 CallGetVideoFrame(encoder.get(), &video_frames[i], &get_frame_cb));
767 ASSERT_TRUE(get_frame_cb.called());
768 ASSERT_EQ(PP_OK, get_frame_cb.result());
769 ASSERT_TRUE(CheckIsVideoFrame(video_frames[i]));
770 }
771
772 get_frame_cb.Reset();
773 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
774 CallGetVideoFrame(encoder.get(), &video_frames[kVideoFrameCount],
775 &get_frame_cb));
776 ASSERT_FALSE(get_frame_cb.called());
777
778 MockCompletionCallback get_frame_fail_cb;
779 ASSERT_EQ(PP_ERROR_INPROGRESS,
780 CallGetVideoFrame(encoder.get(), &video_frames[kVideoFrameCount],
781 &get_frame_fail_cb));
782 ASSERT_FALSE(get_frame_fail_cb.called());
783
784 // Unblock the GetVideoFrame callback by freeing up a frame.
785 MockCompletionCallback encode_cb;
786 ASSERT_EQ(
787 PP_OK_COMPLETIONPENDING,
788 CallCompleteEncode(encoder.get(), video_frames[0], PP_FALSE, &encode_cb));
789 ASSERT_TRUE(encode_cb.called());
790 ASSERT_EQ(PP_OK, encode_cb.result());
791 ASSERT_TRUE(get_frame_cb.called());
792
793 CallClose(encoder.get());
794 }
795
796 TEST_F(VideoEncoderResourceTest, Encode) {
797 // Check Encode() calls into the renderer.
798 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
799 PP_Resource video_frame;
800 MockCompletionCallback get_frame_cb;
801
802 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
803 CallFirstGetVideoFrame(encoder.get(), &video_frame, &get_frame_cb));
804 ASSERT_TRUE(get_frame_cb.called());
805 ASSERT_EQ(PP_OK, get_frame_cb.result());
806
807 MockCompletionCallback encode_cb;
808 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
809 CallEncode(encoder.get(), video_frame, PP_TRUE, &encode_cb));
810 ASSERT_FALSE(encode_cb.called());
811 ASSERT_FALSE(CheckIsVideoFrameValid(video_frame));
812
813 ResourceMessageCallParams params;
814 uint32_t frame_id;
815 bool force_frame;
816 ASSERT_TRUE(CheckEncodeMsg(&params, &frame_id, &force_frame));
817
818 SendEncodeReply(params, frame_id);
819
820 ASSERT_TRUE(encode_cb.called());
821 ASSERT_EQ(PP_OK, encode_cb.result());
822 }
823
824 TEST_F(VideoEncoderResourceTest, EncodeAndGetVideoFrame) {
825 // Check the encoding loop works well.
826 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
827 ResourceMessageCallParams params;
828 PP_Resource video_frame;
829 MockCompletionCallback get_frame_cb, encode_cb;
830
831 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
832 CallFirstGetVideoFrame(encoder.get(), &video_frame, &get_frame_cb));
833 ASSERT_TRUE(get_frame_cb.called());
834 ASSERT_EQ(PP_OK, get_frame_cb.result());
835
836 for (uint32_t i = 1; i < 20 * kVideoFrameCount; ++i) {
837 encode_cb.Reset();
838 ASSERT_EQ(
839 PP_OK_COMPLETIONPENDING,
840 CallCompleteEncode(encoder.get(), video_frame, PP_FALSE, &encode_cb));
841 ASSERT_TRUE(encode_cb.called());
842 ASSERT_EQ(PP_OK, encode_cb.result());
843
844 get_frame_cb.Reset();
845 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
846 CallGetVideoFrame(encoder.get(), &video_frame, &get_frame_cb));
847 ASSERT_TRUE(get_frame_cb.called());
848 ASSERT_EQ(PP_OK, get_frame_cb.result());
849 ASSERT_TRUE(CheckIsVideoFrame(video_frame));
850 }
851
852 ASSERT_EQ(
853 PP_OK_COMPLETIONPENDING,
854 CallCompleteEncode(encoder.get(), video_frame, PP_FALSE, &encode_cb));
855 ASSERT_TRUE(encode_cb.called());
856 ASSERT_EQ(PP_OK, encode_cb.result());
857 }
858
859 TEST_F(VideoEncoderResourceTest, GetBitstreamBuffer) {
860 {
861 // Verify that the GetBitstreamBuffer callback is fired whenever the
862 // renderer signals a buffer is available.
863 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
864
865 MockCompletionCallback get_bitstream_buffer_cb;
866 PP_BitstreamBuffer bitstream_buffer;
867 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
868 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
869 &get_bitstream_buffer_cb));
870 ASSERT_FALSE(get_bitstream_buffer_cb.called());
871
872 ResourceMessageCallParams buffer_params(encoder.get(), 0);
873 SendBitstreamBufferReady(buffer_params, 0, 10, true);
874
875 ASSERT_TRUE(get_bitstream_buffer_cb.called());
876 ASSERT_EQ(PP_OK, get_bitstream_buffer_cb.result());
877 ASSERT_EQ(10U, bitstream_buffer.size);
878 ASSERT_EQ(PP_TRUE, bitstream_buffer.key_frame);
879 }
880 {
881 // Verify that calling GetBitstreamBuffer a second time, while the
882 // first callback hasn't been fired fails.
883 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
884
885 MockCompletionCallback get_bitstream_buffer_cb;
886 PP_BitstreamBuffer bitstream_buffer;
887 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
888 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
889 &get_bitstream_buffer_cb));
890 ASSERT_FALSE(get_bitstream_buffer_cb.called());
891
892 ASSERT_EQ(PP_ERROR_INPROGRESS,
893 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
894 &get_bitstream_buffer_cb));
895 ASSERT_FALSE(get_bitstream_buffer_cb.called());
896
897 ResourceMessageCallParams buffer_params(encoder.get(), 0);
898 SendBitstreamBufferReady(buffer_params, 0, 10, true);
899 }
900 }
901
902 TEST_F(VideoEncoderResourceTest, RecycleBitstreamBuffer) {
903 // Verify that we signal the renderer that a bitstream buffer has been
904 // recycled.
905 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
906
907 MockCompletionCallback get_bitstream_buffer_cb;
908 PP_BitstreamBuffer bitstream_buffer;
909 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
910 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
911 &get_bitstream_buffer_cb));
912 ASSERT_FALSE(get_bitstream_buffer_cb.called());
913
914 ResourceMessageCallParams buffer_params(encoder.get(), 0);
915 SendBitstreamBufferReady(buffer_params, kBitstreamBufferCount - 1, 10, true);
916
917 ASSERT_TRUE(get_bitstream_buffer_cb.called());
918 ASSERT_EQ(PP_OK, get_bitstream_buffer_cb.result());
919
920 CallRecycleBitstreamBuffer(encoder.get(), bitstream_buffer);
921
922 ResourceMessageCallParams recycle_params;
923 uint32_t buffer_id;
924 ASSERT_TRUE(CheckRecycleBitstreamBufferMsg(&recycle_params, &buffer_id));
925 ASSERT_EQ(kBitstreamBufferCount - 1, buffer_id);
926 }
927
928 TEST_F(VideoEncoderResourceTest, RequestEncodingParametersChange) {
929 // Check encoding parameter changes are correctly sent to the
930 // renderer.
931 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
932
933 CallRequestEncodingParametersChange(encoder.get(), 1, 2);
934 ResourceMessageCallParams params;
935 uint32_t bitrate, framerate;
936 ASSERT_TRUE(
937 CheckRequestEncodingParametersChangeMsg(&params, &bitrate, &framerate));
938 ASSERT_EQ(1U, bitrate);
939 ASSERT_EQ(2U, framerate);
940 }
941
942 TEST_F(VideoEncoderResourceTest, NotifyError) {
943 {
944 // Check an error from the encoder aborts GetVideoFrame and
945 // GetBitstreamBuffer callbacks.
946 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
947
948 MockCompletionCallback get_frame_cb;
949 PP_Resource video_frame;
950 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
951 CallGetVideoFrame(encoder.get(), &video_frame, &get_frame_cb));
952 ASSERT_FALSE(get_frame_cb.called());
953
954 MockCompletionCallback get_bitstream_buffer_cb;
955 PP_BitstreamBuffer bitstream_buffer;
956 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
957 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
958 &get_bitstream_buffer_cb));
959
960 ResourceMessageCallParams error_params(encoder.get(), 0);
961 SendNotifyError(error_params, PP_ERROR_FAILED);
962
963 ASSERT_TRUE(get_frame_cb.called());
964 ASSERT_EQ(PP_ERROR_FAILED, get_frame_cb.result());
965 ASSERT_TRUE(get_bitstream_buffer_cb.called());
966 ASSERT_EQ(PP_ERROR_FAILED, get_bitstream_buffer_cb.result());
967 }
968 {
969 // Check an error from the encoder aborts Encode and GetBitstreamBuffer
970 // callbacks.
971 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
972
973 MockCompletionCallback get_frame_cb, encode_cb1, encode_cb2;
974 PP_Resource video_frame1, video_frame2;
975 ASSERT_EQ(
976 PP_OK_COMPLETIONPENDING,
977 CallFirstGetVideoFrame(encoder.get(), &video_frame1, &get_frame_cb));
978 ASSERT_TRUE(get_frame_cb.called());
979 ASSERT_EQ(PP_OK, get_frame_cb.result());
980
981 get_frame_cb.Reset();
982 ASSERT_EQ(
983 PP_OK_COMPLETIONPENDING,
984 CallFirstGetVideoFrame(encoder.get(), &video_frame2, &get_frame_cb));
985 ASSERT_TRUE(get_frame_cb.called());
986 ASSERT_EQ(PP_OK, get_frame_cb.result());
987
988 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
989 CallEncode(encoder.get(), video_frame1, PP_FALSE, &encode_cb1));
990 ASSERT_FALSE(encode_cb1.called());
991 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
992 CallEncode(encoder.get(), video_frame2, PP_FALSE, &encode_cb2));
993 ASSERT_FALSE(encode_cb2.called());
994
995 MockCompletionCallback get_bitstream_buffer_cb;
996 PP_BitstreamBuffer bitstream_buffer;
997 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
998 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
999 &get_bitstream_buffer_cb));
1000
1001 ResourceMessageCallParams error_params(encoder.get(), 0);
1002 SendNotifyError(error_params, PP_ERROR_FAILED);
1003
1004 ASSERT_TRUE(encode_cb1.called());
1005 ASSERT_EQ(PP_ERROR_FAILED, encode_cb1.result());
1006 ASSERT_TRUE(encode_cb2.called());
1007 ASSERT_EQ(PP_ERROR_FAILED, encode_cb2.result());
1008 ASSERT_TRUE(get_bitstream_buffer_cb.called());
1009 ASSERT_EQ(PP_ERROR_FAILED, get_bitstream_buffer_cb.result());
1010 }
1011 }
1012
1013 TEST_F(VideoEncoderResourceTest, Close) {
1014 {
1015 // Check closing the encoder aborts GetVideoFrame and
1016 // GetBitstreamBuffer callbacks.
1017 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
1018
1019 MockCompletionCallback get_frame_cb;
1020 PP_Resource video_frame;
1021 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
1022 CallGetVideoFrame(encoder.get(), &video_frame, &get_frame_cb));
1023 ASSERT_FALSE(get_frame_cb.called());
1024
1025 MockCompletionCallback get_bitstream_buffer_cb;
1026 PP_BitstreamBuffer bitstream_buffer;
1027 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
1028 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
1029 &get_bitstream_buffer_cb));
1030
1031 CallClose(encoder.get());
1032
1033 ASSERT_TRUE(get_frame_cb.called());
1034 ASSERT_EQ(PP_ERROR_ABORTED, get_frame_cb.result());
1035 ASSERT_TRUE(get_bitstream_buffer_cb.called());
1036 ASSERT_EQ(PP_ERROR_ABORTED, get_bitstream_buffer_cb.result());
1037 }
1038 {
1039 // Check closing the encoder aborts Encode and GetBitstreamBuffer
1040 // callbacks.
1041 LockingResourceReleaser encoder(CreateAndInitializeEncoder());
1042
1043 MockCompletionCallback get_frame_cb, encode_cb1, encode_cb2;
1044 PP_Resource video_frame1, video_frame2;
1045 ASSERT_EQ(
1046 PP_OK_COMPLETIONPENDING,
1047 CallFirstGetVideoFrame(encoder.get(), &video_frame1, &get_frame_cb));
1048 ASSERT_TRUE(get_frame_cb.called());
1049 ASSERT_EQ(PP_OK, get_frame_cb.result());
1050
1051 get_frame_cb.Reset();
1052 ASSERT_EQ(
1053 PP_OK_COMPLETIONPENDING,
1054 CallFirstGetVideoFrame(encoder.get(), &video_frame2, &get_frame_cb));
1055 ASSERT_TRUE(get_frame_cb.called());
1056 ASSERT_EQ(PP_OK, get_frame_cb.result());
1057
1058 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
1059 CallEncode(encoder.get(), video_frame1, PP_FALSE, &encode_cb1));
1060 ASSERT_FALSE(encode_cb1.called());
1061 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
1062 CallEncode(encoder.get(), video_frame2, PP_FALSE, &encode_cb2));
1063 ASSERT_FALSE(encode_cb2.called());
1064
1065 MockCompletionCallback get_bitstream_buffer_cb;
1066 PP_BitstreamBuffer bitstream_buffer;
1067 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
1068 CallGetBitstreamBuffer(encoder.get(), &bitstream_buffer,
1069 &get_bitstream_buffer_cb));
1070
1071 CallClose(encoder.get());
1072
1073 ASSERT_TRUE(encode_cb1.called());
1074 ASSERT_EQ(PP_ERROR_ABORTED, encode_cb1.result());
1075 ASSERT_TRUE(encode_cb2.called());
1076 ASSERT_EQ(PP_ERROR_ABORTED, encode_cb2.result());
1077 ASSERT_TRUE(get_bitstream_buffer_cb.called());
1078 ASSERT_EQ(PP_ERROR_ABORTED, get_bitstream_buffer_cb.result());
1079 }
1080 }
1081
1082 } // namespace proxy
1083 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698