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

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

Powered by Google App Engine
This is Rietveld 408576698