Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 1 | /* |
| 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 Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 19 | #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 | |
| 27 | namespace webrtc { |
| 28 | namespace test { |
| 29 | |
| 30 | namespace { |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 31 | const VideoEncoder::Capabilities kCapabilities(false); |
Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 32 | |
| 33 | int32_t InitEncoder(VideoCodecType codec_type, VideoEncoder* encoder) { |
| 34 | VideoCodec codec; |
| 35 | CodecSettings(codec_type, &codec); |
| 36 | codec.width = 640; |
| 37 | codec.height = 480; |
| 38 | codec.maxFramerate = 30; |
| 39 | RTC_CHECK(encoder); |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 40 | return encoder->InitEncode( |
| 41 | &codec, VideoEncoder::Settings(kCapabilities, 1 /* number_of_cores */, |
| 42 | 1200 /* max_payload_size */)); |
Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | int32_t InitDecoder(VideoCodecType codec_type, VideoDecoder* decoder) { |
| 46 | VideoCodec codec; |
| 47 | CodecSettings(codec_type, &codec); |
| 48 | codec.width = 640; |
| 49 | codec.height = 480; |
| 50 | codec.maxFramerate = 30; |
| 51 | RTC_CHECK(decoder); |
| 52 | return decoder->InitDecode(&codec, 1 /* number_of_cores */); |
| 53 | } |
| 54 | |
| 55 | } // namespace |
| 56 | |
| 57 | class VideoEncoderDecoderInstantiationTest |
| 58 | : public ::testing::Test, |
| 59 | public ::testing::WithParamInterface<::testing::tuple<int, int>> { |
| 60 | protected: |
| 61 | VideoEncoderDecoderInstantiationTest() |
| 62 | : vp8_format_("VP8"), |
| 63 | vp9_format_("VP9"), |
| 64 | h264cbp_format_("H264"), |
| 65 | num_encoders_(::testing::get<0>(GetParam())), |
| 66 | num_decoders_(::testing::get<1>(GetParam())) { |
| 67 | #if defined(WEBRTC_ANDROID) |
| 68 | InitializeAndroidObjects(); |
| 69 | encoder_factory_ = CreateAndroidEncoderFactory(); |
| 70 | decoder_factory_ = CreateAndroidDecoderFactory(); |
| 71 | #elif defined(WEBRTC_IOS) |
| 72 | encoder_factory_ = CreateObjCEncoderFactory(); |
| 73 | decoder_factory_ = CreateObjCDecoderFactory(); |
| 74 | #else |
| 75 | RTC_NOTREACHED() << "Only support Android and iOS."; |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | ~VideoEncoderDecoderInstantiationTest() { |
| 80 | for (auto& encoder : encoders_) { |
| 81 | encoder->Release(); |
| 82 | } |
| 83 | for (auto& decoder : decoders_) { |
| 84 | decoder->Release(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | const SdpVideoFormat vp8_format_; |
| 89 | const SdpVideoFormat vp9_format_; |
| 90 | const SdpVideoFormat h264cbp_format_; |
| 91 | std::unique_ptr<VideoEncoderFactory> encoder_factory_; |
| 92 | std::unique_ptr<VideoDecoderFactory> decoder_factory_; |
| 93 | |
| 94 | const int num_encoders_; |
| 95 | const int num_decoders_; |
| 96 | std::vector<std::unique_ptr<VideoEncoder>> encoders_; |
| 97 | std::vector<std::unique_ptr<VideoDecoder>> decoders_; |
| 98 | }; |
| 99 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 100 | INSTANTIATE_TEST_SUITE_P(MultipleEncoders, |
| 101 | VideoEncoderDecoderInstantiationTest, |
| 102 | ::testing::Combine(::testing::Range(1, 4), |
| 103 | ::testing::Range(1, 2))); |
Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 104 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 105 | INSTANTIATE_TEST_SUITE_P(MultipleDecoders, |
| 106 | VideoEncoderDecoderInstantiationTest, |
| 107 | ::testing::Combine(::testing::Range(1, 2), |
| 108 | ::testing::Range(1, 9))); |
Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 109 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 110 | INSTANTIATE_TEST_SUITE_P(MultipleEncodersDecoders, |
| 111 | VideoEncoderDecoderInstantiationTest, |
| 112 | ::testing::Combine(::testing::Range(1, 4), |
| 113 | ::testing::Range(1, 9))); |
Rasmus Brandt | e90636a | 2018-03-01 10:39:36 | [diff] [blame] | 114 | |
| 115 | // TODO(brandtr): Check that the factories actually support the codecs before |
| 116 | // trying to instantiate. Currently, we will just crash with a Java exception |
| 117 | // if the factory does not support the codec. |
| 118 | TEST_P(VideoEncoderDecoderInstantiationTest, DISABLED_InstantiateVp8Codecs) { |
| 119 | for (int i = 0; i < num_encoders_; ++i) { |
| 120 | std::unique_ptr<VideoEncoder> encoder = |
| 121 | encoder_factory_->CreateVideoEncoder(vp8_format_); |
| 122 | EXPECT_EQ(0, InitEncoder(kVideoCodecVP8, encoder.get())); |
| 123 | encoders_.emplace_back(std::move(encoder)); |
| 124 | } |
| 125 | |
| 126 | for (int i = 0; i < num_decoders_; ++i) { |
| 127 | std::unique_ptr<VideoDecoder> decoder = |
| 128 | decoder_factory_->CreateVideoDecoder(vp8_format_); |
| 129 | EXPECT_EQ(0, InitDecoder(kVideoCodecVP8, decoder.get())); |
| 130 | decoders_.emplace_back(std::move(decoder)); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | TEST_P(VideoEncoderDecoderInstantiationTest, |
| 135 | DISABLED_InstantiateH264CBPCodecs) { |
| 136 | for (int i = 0; i < num_encoders_; ++i) { |
| 137 | std::unique_ptr<VideoEncoder> encoder = |
| 138 | encoder_factory_->CreateVideoEncoder(h264cbp_format_); |
| 139 | EXPECT_EQ(0, InitEncoder(kVideoCodecH264, encoder.get())); |
| 140 | encoders_.emplace_back(std::move(encoder)); |
| 141 | } |
| 142 | |
| 143 | for (int i = 0; i < num_decoders_; ++i) { |
| 144 | std::unique_ptr<VideoDecoder> decoder = |
| 145 | decoder_factory_->CreateVideoDecoder(h264cbp_format_); |
| 146 | EXPECT_EQ(0, InitDecoder(kVideoCodecH264, decoder.get())); |
| 147 | decoders_.emplace_back(std::move(decoder)); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | } // namespace test |
| 152 | } // namespace webrtc |