1 /*
2 * Copyright (c) 2015 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
12 #include "modules/video_coding/codecs/h264/h264_encoder_impl.h"
13
14 #include "api/video_codecs/video_encoder.h"
15 #include "test/gtest.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 const int kMaxPayloadSize = 1024;
22 const int kNumCores = 1;
23
24 const VideoEncoder::Capabilities kCapabilities(false);
25 const VideoEncoder::Settings kSettings(kCapabilities,
26 kNumCores,
27 kMaxPayloadSize);
28
SetDefaultSettings(VideoCodec * codec_settings)29 void SetDefaultSettings(VideoCodec* codec_settings) {
30 codec_settings->codecType = kVideoCodecH264;
31 codec_settings->maxFramerate = 60;
32 codec_settings->width = 640;
33 codec_settings->height = 480;
34 // If frame dropping is false, we get a warning that bitrate can't
35 // be controlled for RC_QUALITY_MODE; RC_BITRATE_MODE and RC_TIMESTAMP_MODE
36 codec_settings->SetFrameDropEnabled(true);
37 codec_settings->startBitrate = 2000;
38 codec_settings->maxBitrate = 4000;
39 }
40
TEST(H264EncoderImplTest,CanInitializeWithDefaultParameters)41 TEST(H264EncoderImplTest, CanInitializeWithDefaultParameters) {
42 H264EncoderImpl encoder(cricket::VideoCodec("H264"));
43 VideoCodec codec_settings;
44 SetDefaultSettings(&codec_settings);
45 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
46 encoder.InitEncode(&codec_settings, kSettings));
47 EXPECT_EQ(H264PacketizationMode::NonInterleaved,
48 encoder.PacketizationModeForTesting());
49 }
50
TEST(H264EncoderImplTest,CanInitializeWithNonInterleavedModeExplicitly)51 TEST(H264EncoderImplTest, CanInitializeWithNonInterleavedModeExplicitly) {
52 cricket::VideoCodec codec("H264");
53 codec.SetParam(cricket::kH264FmtpPacketizationMode, "1");
54 H264EncoderImpl encoder(codec);
55 VideoCodec codec_settings;
56 SetDefaultSettings(&codec_settings);
57 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
58 encoder.InitEncode(&codec_settings, kSettings));
59 EXPECT_EQ(H264PacketizationMode::NonInterleaved,
60 encoder.PacketizationModeForTesting());
61 }
62
TEST(H264EncoderImplTest,CanInitializeWithSingleNalUnitModeExplicitly)63 TEST(H264EncoderImplTest, CanInitializeWithSingleNalUnitModeExplicitly) {
64 cricket::VideoCodec codec("H264");
65 codec.SetParam(cricket::kH264FmtpPacketizationMode, "0");
66 H264EncoderImpl encoder(codec);
67 VideoCodec codec_settings;
68 SetDefaultSettings(&codec_settings);
69 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
70 encoder.InitEncode(&codec_settings, kSettings));
71 EXPECT_EQ(H264PacketizationMode::SingleNalUnit,
72 encoder.PacketizationModeForTesting());
73 }
74
TEST(H264EncoderImplTest,CanInitializeWithRemovedParameter)75 TEST(H264EncoderImplTest, CanInitializeWithRemovedParameter) {
76 cricket::VideoCodec codec("H264");
77 codec.RemoveParam(cricket::kH264FmtpPacketizationMode);
78 H264EncoderImpl encoder(codec);
79 VideoCodec codec_settings;
80 SetDefaultSettings(&codec_settings);
81 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
82 encoder.InitEncode(&codec_settings, kSettings));
83 EXPECT_EQ(H264PacketizationMode::SingleNalUnit,
84 encoder.PacketizationModeForTesting());
85 }
86
87 } // anonymous namespace
88
89 } // namespace webrtc
90