File: test_video_decoder.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 4,588 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_video_decoder.h"

#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/video_decoder.h"
#include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
#include "ppapi/tests/testing_instance.h"

namespace {

// The maximum number of pictures that the client can pass in for
// min_picture_count, just as a sanity check on the argument.
// This should match the value of kMaximumPictureCount in
// video_decoder_resource.cc.
const uint32_t kMaximumPictureCount = 100;

}  // namespace

REGISTER_TEST_CASE(VideoDecoder);

bool TestVideoDecoder::Init() {
  const int width = 16;
  const int height = 16;
  const int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, width,
                             PP_GRAPHICS3DATTRIB_HEIGHT, height,
                             PP_GRAPHICS3DATTRIB_NONE};
  graphics_3d_ = pp::Graphics3D(instance_, attribs);
  return (pp::Module::Get()->GetBrowserInterface(PPB_VIDEODECODER_INTERFACE) &&
          CheckTestingInterface());
}

void TestVideoDecoder::RunTests(const std::string& filter) {
  RUN_CALLBACK_TEST(TestVideoDecoder, Create, filter);
}

std::string TestVideoDecoder::TestCreate() {
  // Test that Initialize fails with a bad Graphics3D resource.
  {
    pp::VideoDecoder video_decoder(instance_);
    ASSERT_FALSE(video_decoder.is_null());

    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
    pp::Graphics3D null_graphics_3d;
    callback.WaitForResult(
        video_decoder.Initialize(null_graphics_3d,
                                 PP_VIDEOPROFILE_VP8_ANY,
                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
                                 0,
                                 callback.GetCallback()));
    ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result());
  }
  // Test that Initialize fails with a bad profile enum value.
  {
    pp::VideoDecoder video_decoder(instance_);
    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
    const PP_VideoProfile kInvalidProfile = static_cast<PP_VideoProfile>(-1);
    callback.WaitForResult(
        video_decoder.Initialize(graphics_3d_,
                                 kInvalidProfile,
                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
                                 0,
                                 callback.GetCallback()));
    ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
  }
  // Test that Initialize succeeds if we can create a Graphics3D resources and
  // if we allow software fallback to VP8, which should always be supported.
  if (!graphics_3d_.is_null()) {
    pp::VideoDecoder video_decoder(instance_);
    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
    callback.WaitForResult(
        video_decoder.Initialize(graphics_3d_,
                                 PP_VIDEOPROFILE_VP8_ANY,
                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
                                 0,
                                 callback.GetCallback()));
    ASSERT_EQ(PP_OK, callback.result());
  }
  // Test that Initialize succeeds with a larger than normal number of requested
  // picture buffers, if we can create a Graphics3D resource and if we allow
  // software fallback to VP8, which should always be supported.
  if (!graphics_3d_.is_null()) {
    pp::VideoDecoder video_decoder(instance_);
    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
    callback.WaitForResult(
        video_decoder.Initialize(graphics_3d_,
                                 PP_VIDEOPROFILE_VP8_ANY,
                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
                                 kMaximumPictureCount,
                                 callback.GetCallback()));
    ASSERT_EQ(PP_OK, callback.result());
  }
  // Test that Initialize fails if we request an unreasonable number of picture
  // buffers.
  if (!graphics_3d_.is_null()) {
    pp::VideoDecoder video_decoder(instance_);
    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
    callback.WaitForResult(
        video_decoder.Initialize(graphics_3d_,
                                 PP_VIDEOPROFILE_VP8_ANY,
                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
                                 kMaximumPictureCount + 1,
                                 callback.GetCallback()));
    ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
  }

  PASS();
}