| Index: ppapi/tests/test_video_decoder.cc
|
| diff --git a/ppapi/tests/test_video_decoder.cc b/ppapi/tests/test_video_decoder.cc
|
| index db0da55599e79c084729218e95001d4e54efa0d7..de28a64595a30f60bf10008e2b62d3da617dd746 100644
|
| --- a/ppapi/tests/test_video_decoder.cc
|
| +++ b/ppapi/tests/test_video_decoder.cc
|
| @@ -4,34 +4,116 @@
|
|
|
| #include "ppapi/tests/test_video_decoder.h"
|
|
|
| -#include "ppapi/c/dev/ppb_video_decoder_dev.h"
|
| +#include <vector>
|
| +
|
| +#include "ppapi/c/pp_errors.h"
|
| #include "ppapi/c/dev/ppb_testing_dev.h"
|
| -#include "ppapi/c/ppb_var.h"
|
| +#include "ppapi/tests/test_utils.h"
|
| #include "ppapi/tests/testing_instance.h"
|
|
|
| REGISTER_TEST_CASE(VideoDecoder);
|
|
|
| bool TestVideoDecoder::Init() {
|
| - video_decoder_interface_ = reinterpret_cast<PPB_VideoDecoder_Dev const*>(
|
| - pp::Module::Get()->GetBrowserInterface(PPB_VIDEODECODER_DEV_INTERFACE));
|
| - var_interface_ = reinterpret_cast<PPB_Var const*>(
|
| - pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE));
|
| - return video_decoder_interface_ && var_interface_ && InitTestingInterface();
|
| + return InitTestingInterface();
|
| }
|
|
|
| void TestVideoDecoder::RunTest() {
|
| - instance_->LogTest("Create", TestCreate());
|
| + instance_->LogTest("H264", TestH264());
|
| }
|
|
|
| void TestVideoDecoder::QuitMessageLoop() {
|
| testing_interface_->QuitMessageLoop(instance_->pp_instance());
|
| }
|
|
|
| -std::string TestVideoDecoder::TestCreate() {
|
| - PP_Resource decoder = video_decoder_interface_->Create(
|
| - instance_->pp_instance(), NULL, PP_MakeCompletionCallback(NULL, NULL));
|
| - if (decoder == 0) {
|
| - return "Error creating the decoder";
|
| +std::string TestVideoDecoder::TestH264() {
|
| + test_result_ = 0;
|
| + test_completed_ = false;
|
| + // Set-up the local video bitstream source.
|
| + video_bitstream_source_ = new LocalVideoBitstreamSource("test-25fps.264");
|
| + if (!video_bitstream_source_) {
|
| + return "Failed to create local video bitstream source";
|
| + }
|
| +
|
| + // Set up the display.
|
| + PP_Size surface_size = { 320, 240 };
|
| + GLES2Display* display = new GLES2Display(instance_, surface_size);
|
| + if (!display || !display->Initialize()) {
|
| + return "Failed to initialize GLES2Display";
|
| + }
|
| + display_interface_ = display;
|
| +
|
| + // Create and initialize the video decoding engine.
|
| + video_decoder_session_ = new VideoDecoderSession(
|
| + instance_, this, video_bitstream_source_, display_interface_);
|
| + PP_VideoConfigElement decoder_cfg[] = {
|
| + PP_VIDEOATTR_BITSTREAMFORMATKEY_FOURCC, PP_VIDEOCODECFOURCC_H264,
|
| + PP_VIDEOATTR_BITSTREAMFORMATKEY_WIDTH, 320,
|
| + PP_VIDEOATTR_BITSTREAMFORMATKEY_HEIGHT, 240,
|
| + // TODO(vmr): Correct colorformat once the CL lands.
|
| + PP_VIDEOATTR_COLORFORMAT_RGBA, 0,
|
| + PP_VIDEOATTR_DICTIONARY_TERMINATOR
|
| + };
|
| + if (!video_decoder_session_ ||
|
| + !video_decoder_session_->Initialize(
|
| + decoder_cfg,
|
| + cb_factory_.NewCallback(&TestVideoDecoder::OnInitializeCompleted))) {
|
| + return "Failed to initialize VideoDecoderSession";
|
| + }
|
| +
|
| + // Wait the test to complete. By assigning the TestCompletionCallback into
|
| + // pp::CompletionCallback we are registering completion callback which waits
|
| + // until the latter is initiated.
|
| + int32_t result = WaitForCompletion();
|
| + if (result) {
|
| + return "Test failed during the decoding process with result: " + result;
|
| }
|
| PASS();
|
| }
|
| +
|
| +// Wait for the completion of test.
|
| +int32_t TestVideoDecoder::WaitForCompletion() {
|
| + // TODO(vmr): Get rid of ugly busy-loop in platform independent,
|
| + // Pepper-compatible manner for synchronization.
|
| + while (!test_completed_);
|
| + return test_result_;
|
| +}
|
| +
|
| +void TestVideoDecoder::OnSessionCompleted(int32_t result) {
|
| + test_result_ = result;
|
| + test_completed_ = true;
|
| +}
|
| +
|
| +void TestVideoDecoder::OnInitializeCompleted(int32_t result) {
|
| + if (result != PP_OK) {
|
| + OnSessionCompleted(result);
|
| + }
|
| + video_decoder_session_->Run(
|
| + cb_factory_.NewCallback(&TestVideoDecoder::OnRunCompleted));
|
| +}
|
| +
|
| +void TestVideoDecoder::OnRunCompleted(int32_t result) {
|
| + if (result != PP_OK) {
|
| + OnSessionCompleted(result);
|
| + }
|
| + // No action needed, just let the session continue until it runs out.
|
| +}
|
| +
|
| +void TestVideoDecoder::OnStopCompleted(int32_t result) {
|
| + if (result != PP_OK) {
|
| + OnSessionCompleted(result);
|
| + }
|
| + video_decoder_session_->Teardown(
|
| + cb_factory_.NewCallback(&TestVideoDecoder::OnTeardownCompleted));
|
| +}
|
| +
|
| +void TestVideoDecoder::OnFlushCompleted(int32_t result) {
|
| + if (result != PP_OK) {
|
| + OnSessionCompleted(result);
|
| + }
|
| + // No action needed, just let the session continue.
|
| +}
|
| +
|
| +void TestVideoDecoder::OnTeardownCompleted(int32_t result) {
|
| + OnSessionCompleted(result);
|
| +}
|
| +
|
|
|