Skip to content

Commit 6bb8e0e

Browse files
rasmusbrandtCommit bot
authored and
Commit bot
committed
Add support for creating HW codecs in the VideoProcessor tests.
This CL adds the ability to _create_ HW codecs (Android and iOS) in the VideoProcessor integration tests. Since the VideoProcessor class is not thread safe yet, this CL does not add the ability to _use_ HW codecs in the tests. A follow-up CL is planned that will add this ability. This CL further adds a separate build target which is used to separate the "plot" versions of the integration tests from the "correctness" versions. The former will be run manually on devices, whereas the latter are used on the trybots/buildbots to find regressions in the SW codecs. The underlying test is the same, however. BUG=webrtc:6634 Review-Url: https://codereview.webrtc.org/2695653002 Cr-Commit-Position: refs/heads/master@{#16716}
1 parent 8dd4ec3 commit 6bb8e0e

13 files changed

+341
-58
lines changed

Diff for: resources/foreman_128x96.yuv.sha1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bf2fe75c6921c2be9c8cfd1cc00c6540133a2931

Diff for: resources/foreman_160x120.yuv.sha1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
315d8a7cc06fe15b68a6f2106d59d25b16270552

Diff for: resources/foreman_176x144.yuv.sha1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4a38b5629845646844350a4257a60554888509b9

Diff for: resources/foreman_320x240.yuv.sha1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bb838d60f2a0454af4ca63735d573069858ec004

Diff for: webrtc/modules/video_coding/BUILD.gn

+110-5
Original file line numberDiff line numberDiff line change
@@ -341,32 +341,137 @@ if (rtc_include_tests) {
341341
]
342342
}
343343

344-
rtc_source_set("video_coding_modules_tests") {
344+
rtc_source_set("video_coding_videoprocessor_integration_test") {
345345
testonly = true
346+
346347
sources = [
347-
"codecs/test/videoprocessor_integrationtest.cc",
348348
"codecs/test/videoprocessor_integrationtest.h",
349-
"codecs/vp8/test/vp8_impl_unittest.cc",
350349
]
350+
351351
deps = [
352352
":video_codecs_test_framework",
353353
":video_coding",
354354
":webrtc_h264",
355355
":webrtc_vp8",
356356
":webrtc_vp9",
357357
"../..:webrtc_common",
358+
"../../base:rtc_base_approved",
359+
"../../media:rtc_media",
360+
"../../test:test_support",
361+
"../../test:video_test_support",
362+
]
363+
364+
if (is_android) {
365+
sources += [
366+
"codecs/test/android_test_initializer.cc",
367+
"codecs/test/android_test_initializer.h",
368+
]
369+
370+
deps += [
371+
"../../base:rtc_base_approved",
372+
"../../sdk/android:libjingle_peerconnection_jni",
373+
"//base",
374+
]
375+
}
376+
377+
if (is_ios || is_mac) {
378+
deps += [
379+
"../../media:rtc_media_base",
380+
"../../sdk:webrtc_h264_video_toolbox",
381+
]
382+
}
383+
}
384+
385+
rtc_source_set("video_coding_modules_tests") {
386+
testonly = true
387+
388+
sources = [
389+
"codecs/test/videoprocessor_integrationtest.cc",
390+
"codecs/vp8/test/vp8_impl_unittest.cc",
391+
]
392+
393+
deps = [
394+
":video_coding_videoprocessor_integration_test",
395+
":webrtc_vp8",
358396
"../../api:video_frame_api",
359397
"../../base:rtc_base_approved",
360398
"../../common_video:common_video",
361-
"../../media:rtc_media_base",
362399
"../../test:test_support",
363400
"../../test:video_test_common",
364-
"../../test:video_test_support",
365401
"../video_capture",
366402
]
403+
367404
if (rtc_use_h264) {
368405
defines = [ "WEBRTC_VIDEOPROCESSOR_H264_TESTS" ]
369406
}
407+
408+
if (!build_with_chromium && is_clang) {
409+
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
410+
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
411+
}
412+
}
413+
414+
plot_videoprocessor_integrationtest_resources = [
415+
"//resources/foreman_128x96.yuv",
416+
"//resources/foreman_160x120.yuv",
417+
"//resources/foreman_176x144.yuv",
418+
"//resources/foreman_320x240.yuv",
419+
"//resources/foreman_cif.yuv",
420+
]
421+
422+
if (is_ios || is_mac) {
423+
bundle_data("plot_videoprocessor_integrationtest_bundle_data") {
424+
testonly = true
425+
sources = plot_videoprocessor_integrationtest_resources
426+
outputs = [
427+
"{{bundle_resources_dir}}/{{source_file_part}}",
428+
]
429+
}
430+
}
431+
432+
# This executable is meant for local codec perf testing and should not be run
433+
# on the trybots/buildbots, hence the existence of this special build target.
434+
rtc_test("plot_videoprocessor_integrationtest") {
435+
testonly = true
436+
437+
sources = [
438+
"codecs/test/plot_videoprocessor_integrationtest.cc",
439+
]
440+
441+
deps = [
442+
":video_coding_videoprocessor_integration_test",
443+
"../../test:test_main",
444+
"../../test:video_test_common",
445+
"../video_capture",
446+
]
447+
448+
data = plot_videoprocessor_integrationtest_resources
449+
450+
if (is_android) {
451+
deps += [
452+
"../../base:rtc_base_approved",
453+
454+
# TODO(brandtr): Figure out if the java dep below could be moved into
455+
# :video_coding_videoprocessor_integration_test, where it belongs.
456+
# When that is done, support for Android HW codecs can be added to the
457+
# modules_tests target as well.
458+
"../../sdk/android:libjingle_peerconnection_java",
459+
"../../sdk/android:libjingle_peerconnection_jni",
460+
"//base",
461+
"//testing/android/native_test:native_test_support",
462+
]
463+
464+
shard_timeout = 900
465+
}
466+
467+
if (is_ios || is_mac) {
468+
deps += [ ":plot_videoprocessor_integrationtest_bundle_data" ]
469+
}
470+
471+
# TODO(brandtr): Remove this define when the modules_tests target properly
472+
# loads the Java classes mentioned above.
473+
defines = [ "WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED" ]
474+
370475
if (!build_with_chromium && is_clang) {
371476
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
372477
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]

Diff for: webrtc/modules/video_coding/DEPS

+11
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ include_rules = [
88
"+webrtc/system_wrappers",
99
"+webrtc/tools",
1010
]
11+
12+
specific_include_rules = {
13+
"android_test_initializer\.cc": [
14+
"+base/android",
15+
"+webrtc/sdk",
16+
],
17+
"(.*test\.cc|.*test\.h)": [
18+
"+webrtc/media/engine",
19+
"+webrtc/sdk",
20+
],
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2017 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 <pthread.h>
12+
13+
#include "webrtc/base/ignore_wundef.h"
14+
#include "webrtc/modules/video_coding/codecs/test/android_test_initializer.h"
15+
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
16+
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
17+
18+
// Note: this dependency is dangerous since it reaches into Chromium's base.
19+
// There's a risk of e.g. macro clashes. This file may only be used in tests.
20+
// Since we use Chrome's build system for creating the gtest binary, this should
21+
// be fine.
22+
RTC_PUSH_IGNORING_WUNDEF()
23+
#include "base/android/jni_android.h"
24+
RTC_POP_IGNORING_WUNDEF()
25+
26+
#include "webrtc/base/checks.h"
27+
28+
namespace webrtc {
29+
30+
namespace {
31+
32+
static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
33+
34+
// There can only be one JNI_OnLoad in each binary. So since this is a GTEST
35+
// C++ runner binary, we want to initialize the same global objects we normally
36+
// do if this had been a Java binary.
37+
void EnsureInitializedOnce() {
38+
RTC_CHECK(::base::android::IsVMInitialized());
39+
JNIEnv* jni = ::base::android::AttachCurrentThread();
40+
JavaVM* jvm = NULL;
41+
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
42+
43+
jint ret = webrtc_jni::InitGlobalJniVariables(jvm);
44+
RTC_DCHECK_GE(ret, 0);
45+
46+
webrtc_jni::LoadGlobalClassReferenceHolder();
47+
}
48+
49+
} // namespace
50+
51+
void InitializeAndroidObjects() {
52+
RTC_CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce));
53+
}
54+
55+
} // namespace webrtc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2017 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+
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_ANDROID_TEST_INITIALIZER_H_
12+
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_ANDROID_TEST_INITIALIZER_H_
13+
14+
namespace webrtc {
15+
16+
void InitializeAndroidObjects();
17+
18+
} // namespace webrtc
19+
20+
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_ANDROID_TEST_INITIALIZER_H_

Diff for: webrtc/modules/video_coding/codecs/test/plot_videoprocessor_integrationtest.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const bool kDenoisingOn = false;
2121
const bool kFrameDropperOn = true;
2222
const bool kSpatialResizeOn = false;
2323
const VideoCodecType kVideoCodecType[] = {kVideoCodecVP8};
24+
const bool kHwCodec = false;
2425

2526
// Packet loss probability [0.0, 1.0].
2627
const float kPacketLoss = 0.0f;
@@ -52,7 +53,7 @@ class PlotVideoProcessorIntegrationTest
5253
rate_profile.num_frames = kNumFramesLong;
5354
// Codec/network settings.
5455
CodecConfigPars process_settings;
55-
SetCodecParameters(&process_settings, codec_type_, kPacketLoss,
56+
SetCodecParameters(&process_settings, codec_type_, kHwCodec, kPacketLoss,
5657
-1, // key_frame_interval
5758
1, // num_temporal_layers
5859
kErrorConcealmentOn, kDenoisingOn, kFrameDropperOn,
@@ -87,23 +88,23 @@ INSTANTIATE_TEST_CASE_P(
8788
::testing::ValuesIn(kFps),
8889
::testing::ValuesIn(kVideoCodecType)));
8990

90-
TEST_P(PlotVideoProcessorIntegrationTest, ProcessSQCif) {
91+
TEST_P(PlotVideoProcessorIntegrationTest, Process128x96) {
9192
RunTest(128, 96, "foreman_128x96");
9293
}
9394

94-
TEST_P(PlotVideoProcessorIntegrationTest, ProcessQQVga) {
95+
TEST_P(PlotVideoProcessorIntegrationTest, Process160x120) {
9596
RunTest(160, 120, "foreman_160x120");
9697
}
9798

98-
TEST_P(PlotVideoProcessorIntegrationTest, ProcessQCif) {
99+
TEST_P(PlotVideoProcessorIntegrationTest, Process176x144) {
99100
RunTest(176, 144, "foreman_176x144");
100101
}
101102

102-
TEST_P(PlotVideoProcessorIntegrationTest, ProcessQVga) {
103+
TEST_P(PlotVideoProcessorIntegrationTest, Process320x240) {
103104
RunTest(320, 240, "foreman_320x240");
104105
}
105106

106-
TEST_P(PlotVideoProcessorIntegrationTest, ProcessCif) {
107+
TEST_P(PlotVideoProcessorIntegrationTest, Process352x288) {
107108
RunTest(352, 288, "foreman_cif");
108109
}
109110

Diff for: webrtc/modules/video_coding/codecs/test/videoprocessor.cc

+14-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
374374
config_.codec_settings->height));
375375

376376
// Should be the same aspect ratio, no cropping needed.
377-
up_image->ScaleFrom(*image.video_frame_buffer());
377+
if (image.video_frame_buffer()->native_handle()) {
378+
up_image->ScaleFrom(*image.video_frame_buffer()->NativeToI420Buffer());
379+
} else {
380+
up_image->ScaleFrom(*image.video_frame_buffer());
381+
}
378382

379383
// TODO(mikhal): Extracting the buffer for now - need to update test.
380384
size_t length =
@@ -395,7 +399,15 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
395399
// TODO(mikhal): Add as a member function, so won't be allocated per frame.
396400
size_t length = CalcBufferSize(kI420, image.width(), image.height());
397401
std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
398-
int extracted_length = ExtractBuffer(image, length, image_buffer.get());
402+
int extracted_length;
403+
if (image.video_frame_buffer()->native_handle()) {
404+
extracted_length =
405+
ExtractBuffer(image.video_frame_buffer()->NativeToI420Buffer(),
406+
length, image_buffer.get());
407+
} else {
408+
extracted_length =
409+
ExtractBuffer(image.video_frame_buffer(), length, image_buffer.get());
410+
}
399411
RTC_DCHECK_GT(extracted_length, 0);
400412
memcpy(last_successful_frame_buffer_.get(), image_buffer.get(),
401413
extracted_length);

Diff for: webrtc/modules/video_coding/codecs/test/videoprocessor.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ class VideoProcessorImpl : public VideoProcessor {
205205
}
206206
int32_t Decoded(webrtc::VideoFrame& image,
207207
int64_t decode_time_ms) override {
208-
RTC_NOTREACHED();
209-
return -1;
208+
return Decoded(image);
210209
}
211-
void Decoded(VideoFrame& frame,
210+
void Decoded(webrtc::VideoFrame& image,
212211
rtc::Optional<int32_t> decode_time_ms,
213212
rtc::Optional<uint8_t> qp) override {
214-
RTC_NOTREACHED();
213+
Decoded(image,
214+
decode_time_ms ? static_cast<int32_t>(*decode_time_ms) : -1);
215215
}
216216

217217
private:

0 commit comments

Comments
 (0)