blob: 6fc898dcacd1409edb9f204344dbff582b06bbe2 [file] [log] [blame]
Rasmus Brandte90636a2018-03-01 10:39:361/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <memory>
12#include <vector>
13
14#include "api/video_codecs/sdp_video_format.h"
15#include "api/video_codecs/video_decoder.h"
16#include "api/video_codecs/video_decoder_factory.h"
17#include "api/video_codecs/video_encoder.h"
18#include "api/video_codecs/video_encoder_factory.h"
Rasmus Brandte90636a2018-03-01 10:39:3619#if defined(WEBRTC_ANDROID)
20#include "modules/video_coding/codecs/test/android_codec_factory_helper.h"
21#elif defined(WEBRTC_IOS)
22#include "modules/video_coding/codecs/test/objc_codec_factory_helper.h"
23#endif
24#include "test/gtest.h"
25#include "test/video_codec_settings.h"
26
27namespace webrtc {
28namespace test {
29
30namespace {
31
32int32_t InitEncoder(VideoCodecType codec_type, VideoEncoder* encoder) {
33 VideoCodec codec;
34 CodecSettings(codec_type, &codec);
35 codec.width = 640;
36 codec.height = 480;
37 codec.maxFramerate = 30;
38 RTC_CHECK(encoder);
39 return encoder->InitEncode(&codec, 1 /* number_of_cores */,
40 1200 /* max_payload_size */);
41}
42
43int32_t InitDecoder(VideoCodecType codec_type, VideoDecoder* decoder) {
44 VideoCodec codec;
45 CodecSettings(codec_type, &codec);
46 codec.width = 640;
47 codec.height = 480;
48 codec.maxFramerate = 30;
49 RTC_CHECK(decoder);
50 return decoder->InitDecode(&codec, 1 /* number_of_cores */);
51}
52
53} // namespace
54
55class VideoEncoderDecoderInstantiationTest
56 : public ::testing::Test,
57 public ::testing::WithParamInterface<::testing::tuple<int, int>> {
58 protected:
59 VideoEncoderDecoderInstantiationTest()
60 : vp8_format_("VP8"),
61 vp9_format_("VP9"),
62 h264cbp_format_("H264"),
63 num_encoders_(::testing::get<0>(GetParam())),
64 num_decoders_(::testing::get<1>(GetParam())) {
65#if defined(WEBRTC_ANDROID)
66 InitializeAndroidObjects();
67 encoder_factory_ = CreateAndroidEncoderFactory();
68 decoder_factory_ = CreateAndroidDecoderFactory();
69#elif defined(WEBRTC_IOS)
70 encoder_factory_ = CreateObjCEncoderFactory();
71 decoder_factory_ = CreateObjCDecoderFactory();
72#else
73 RTC_NOTREACHED() << "Only support Android and iOS.";
74#endif
75 }
76
77 ~VideoEncoderDecoderInstantiationTest() {
78 for (auto& encoder : encoders_) {
79 encoder->Release();
80 }
81 for (auto& decoder : decoders_) {
82 decoder->Release();
83 }
84 }
85
86 const SdpVideoFormat vp8_format_;
87 const SdpVideoFormat vp9_format_;
88 const SdpVideoFormat h264cbp_format_;
89 std::unique_ptr<VideoEncoderFactory> encoder_factory_;
90 std::unique_ptr<VideoDecoderFactory> decoder_factory_;
91
92 const int num_encoders_;
93 const int num_decoders_;
94 std::vector<std::unique_ptr<VideoEncoder>> encoders_;
95 std::vector<std::unique_ptr<VideoDecoder>> decoders_;
96};
97
Mirko Bonadeic84f6612019-01-31 11:20:5798INSTANTIATE_TEST_SUITE_P(MultipleEncoders,
99 VideoEncoderDecoderInstantiationTest,
100 ::testing::Combine(::testing::Range(1, 4),
101 ::testing::Range(1, 2)));
Rasmus Brandte90636a2018-03-01 10:39:36102
Mirko Bonadeic84f6612019-01-31 11:20:57103INSTANTIATE_TEST_SUITE_P(MultipleDecoders,
104 VideoEncoderDecoderInstantiationTest,
105 ::testing::Combine(::testing::Range(1, 2),
106 ::testing::Range(1, 9)));
Rasmus Brandte90636a2018-03-01 10:39:36107
Mirko Bonadeic84f6612019-01-31 11:20:57108INSTANTIATE_TEST_SUITE_P(MultipleEncodersDecoders,
109 VideoEncoderDecoderInstantiationTest,
110 ::testing::Combine(::testing::Range(1, 4),
111 ::testing::Range(1, 9)));
Rasmus Brandte90636a2018-03-01 10:39:36112
113// TODO(brandtr): Check that the factories actually support the codecs before
114// trying to instantiate. Currently, we will just crash with a Java exception
115// if the factory does not support the codec.
116TEST_P(VideoEncoderDecoderInstantiationTest, DISABLED_InstantiateVp8Codecs) {
117 for (int i = 0; i < num_encoders_; ++i) {
118 std::unique_ptr<VideoEncoder> encoder =
119 encoder_factory_->CreateVideoEncoder(vp8_format_);
120 EXPECT_EQ(0, InitEncoder(kVideoCodecVP8, encoder.get()));
121 encoders_.emplace_back(std::move(encoder));
122 }
123
124 for (int i = 0; i < num_decoders_; ++i) {
125 std::unique_ptr<VideoDecoder> decoder =
126 decoder_factory_->CreateVideoDecoder(vp8_format_);
127 EXPECT_EQ(0, InitDecoder(kVideoCodecVP8, decoder.get()));
128 decoders_.emplace_back(std::move(decoder));
129 }
130}
131
132TEST_P(VideoEncoderDecoderInstantiationTest,
133 DISABLED_InstantiateH264CBPCodecs) {
134 for (int i = 0; i < num_encoders_; ++i) {
135 std::unique_ptr<VideoEncoder> encoder =
136 encoder_factory_->CreateVideoEncoder(h264cbp_format_);
137 EXPECT_EQ(0, InitEncoder(kVideoCodecH264, encoder.get()));
138 encoders_.emplace_back(std::move(encoder));
139 }
140
141 for (int i = 0; i < num_decoders_; ++i) {
142 std::unique_ptr<VideoDecoder> decoder =
143 decoder_factory_->CreateVideoDecoder(h264cbp_format_);
144 EXPECT_EQ(0, InitDecoder(kVideoCodecH264, decoder.get()));
145 decoders_.emplace_back(std::move(decoder));
146 }
147}
148
149} // namespace test
150} // namespace webrtc