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
13 #include "absl/memory/memory.h"
14 #include "media/base/media_constants.h"
15 #include "sdk/android/generated_native_unittests_jni/CodecsWrapperTestHelper_jni.h"
16 #include "sdk/android/native_api/codecs/wrapper.h"
17 #include "sdk/android/src/jni/video_encoder_wrapper.h"
18 #include "test/gtest.h"
19
20 namespace webrtc {
21 namespace test {
22 namespace {
TEST(JavaCodecsWrapperTest,JavaToNativeVideoCodecInfo)23 TEST(JavaCodecsWrapperTest, JavaToNativeVideoCodecInfo) {
24 JNIEnv* env = AttachCurrentThreadIfNeeded();
25 ScopedJavaLocalRef<jobject> j_video_codec_info =
26 jni::Java_CodecsWrapperTestHelper_createTestVideoCodecInfo(env);
27
28 const SdpVideoFormat video_format =
29 JavaToNativeVideoCodecInfo(env, j_video_codec_info.obj());
30
31 EXPECT_EQ(cricket::kH264CodecName, video_format.name);
32 const auto it =
33 video_format.parameters.find(cricket::kH264FmtpProfileLevelId);
34 ASSERT_NE(it, video_format.parameters.end());
35 EXPECT_EQ(cricket::kH264ProfileLevelConstrainedBaseline, it->second);
36 }
37
TEST(JavaCodecsWrapperTest,JavaToNativeResolutionBitrateLimits)38 TEST(JavaCodecsWrapperTest, JavaToNativeResolutionBitrateLimits) {
39 JNIEnv* env = AttachCurrentThreadIfNeeded();
40 ScopedJavaLocalRef<jobject> j_fake_encoder =
41 jni::Java_CodecsWrapperTestHelper_createFakeVideoEncoder(env);
42
43 auto encoder = jni::JavaToNativeVideoEncoder(env, j_fake_encoder);
44 ASSERT_TRUE(encoder);
45
46 // Check that the bitrate limits correctly passed from Java to native.
47 const std::vector<VideoEncoder::ResolutionBitrateLimits> bitrate_limits =
48 encoder->GetEncoderInfo().resolution_bitrate_limits;
49 ASSERT_EQ(bitrate_limits.size(), 1u);
50 EXPECT_EQ(bitrate_limits[0].frame_size_pixels, 640 * 360);
51 EXPECT_EQ(bitrate_limits[0].min_start_bitrate_bps, 300000);
52 EXPECT_EQ(bitrate_limits[0].min_bitrate_bps, 200000);
53 EXPECT_EQ(bitrate_limits[0].max_bitrate_bps, 1000000);
54 }
55 } // namespace
56 } // namespace test
57 } // namespace webrtc
58