File: test_video_encoder.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 4,100 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
111
112
113
114
115
// Copyright 2015 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_encoder.h"

#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/video_encoder.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(VideoEncoder);

bool TestVideoEncoder::Init() {
  video_encoder_interface_ = static_cast<const PPB_VideoEncoder_0_1*>(
      pp::Module::Get()->GetBrowserInterface(PPB_VIDEOENCODER_INTERFACE_0_1));
  return video_encoder_interface_ && CheckTestingInterface();
}

void TestVideoEncoder::RunTests(const std::string& filter) {
  RUN_CALLBACK_TEST(TestVideoEncoder, AvailableCodecs, filter);
  RUN_CALLBACK_TEST(TestVideoEncoder, IncorrectSizeFails, filter);
  RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP8, filter);
  RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9, filter);
}

std::string TestVideoEncoder::TestAvailableCodecs() {
  // Test that we get results for supported formats. We should at
  // least get the software supported formats.
  pp::VideoEncoder video_encoder(instance_);
  ASSERT_FALSE(video_encoder.is_null());

  TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> >
      callback(instance_->pp_instance(), false);
  callback.WaitForResult(
      video_encoder.GetSupportedProfiles(callback.GetCallback()));

  ASSERT_GE(callback.result(), 1U);

  const std::vector<PP_VideoProfileDescription> video_profiles =
      callback.output();
  ASSERT_GE(video_profiles.size(), 1U);

  bool found_vp8 = false, found_vp9 = false;
  for (uint32_t i = 0; i < video_profiles.size(); ++i) {
    const PP_VideoProfileDescription& description = video_profiles[i];
    if (description.hardware_accelerated == PP_FALSE) {
      ASSERT_GE(description.max_framerate_numerator /
                    description.max_framerate_denominator,
                30U);
      if (description.profile == PP_VIDEOPROFILE_VP8_ANY)
        found_vp8 = true;
      else if (description.profile == PP_VIDEOPROFILE_VP9_ANY)
        found_vp9 = true;
    }
  }
  ASSERT_TRUE(found_vp8);
  ASSERT_TRUE(found_vp9);

  PASS();
}

std::string TestVideoEncoder::TestIncorrectSizeFails() {
  // Test that initializing the encoder with incorrect size fails.
  pp::VideoEncoder video_encoder(instance_);
  ASSERT_FALSE(video_encoder.is_null());
  pp::Size video_size(0, 0);

  TestCompletionCallback callback(instance_->pp_instance(), false);
  callback.WaitForResult(video_encoder.Initialize(
      PP_VIDEOFRAME_FORMAT_I420, video_size, PP_VIDEOPROFILE_VP8_ANY, 1000000,
      PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));

  ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());

  PASS();
}

std::string TestVideoEncoder::TestInitializeVP8() {
  return TestInitializeCodec(PP_VIDEOPROFILE_VP8_ANY);
}

std::string TestVideoEncoder::TestInitializeVP9() {
  return TestInitializeCodec(PP_VIDEOPROFILE_VP9_ANY);
}

std::string TestVideoEncoder::TestInitializeCodec(PP_VideoProfile profile) {
  pp::VideoEncoder video_encoder(instance_);
  ASSERT_FALSE(video_encoder.is_null());
  pp::Size video_size(640, 480);

  TestCompletionCallback callback(instance_->pp_instance(), false);
  callback.WaitForResult(video_encoder.Initialize(
      PP_VIDEOFRAME_FORMAT_I420, video_size, profile, 1000000,
      PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));

  ASSERT_EQ(PP_OK, callback.result());

  pp::Size coded_size;
  ASSERT_EQ(PP_OK, video_encoder.GetFrameCodedSize(&coded_size));
  ASSERT_GE(coded_size.GetArea(), video_size.GetArea());
  ASSERT_GE(video_encoder.GetFramesRequired(), 1);

  TestCompletionCallbackWithOutput<pp::VideoFrame> get_video_frame(
      instance_->pp_instance(), false);
  get_video_frame.WaitForResult(
      video_encoder.GetVideoFrame(get_video_frame.GetCallback()));
  ASSERT_EQ(PP_OK, get_video_frame.result());

  pp::Size video_frame_size;
  ASSERT_TRUE(get_video_frame.output().GetSize(&video_frame_size));
  ASSERT_EQ(coded_size.GetArea(), video_frame_size.GetArea());

  PASS();
}