blob: 42f4faed4a38662a9cb876b8fdc276cd755424c2 [file] [log] [blame]
pbosf1828e82015-07-28 08:20:59 -07001/*
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
kwibergb25345e2016-03-12 06:10:44 -080011#include <memory>
12
pbosf1828e82015-07-28 08:20:59 -070013#include "webrtc/test/call_test.h"
kwibergac9f8762016-09-30 22:29:43 -070014#include "webrtc/test/gtest.h"
pbosf1828e82015-07-28 08:20:59 -070015#include "webrtc/test/null_transport.h"
16
17namespace webrtc {
18
19class PacketInjectionTest : public test::CallTest {
20 protected:
21 enum class CodecType {
22 kVp8,
23 kH264,
24 };
25
26 PacketInjectionTest() : rtp_header_parser_(RtpHeaderParser::Create()) {}
27
28 void InjectIncorrectPacket(CodecType codec_type,
29 uint8_t packet_type,
30 const uint8_t* packet,
31 size_t length);
32
kwibergb25345e2016-03-12 06:10:44 -080033 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
pbosf1828e82015-07-28 08:20:59 -070034};
35
36void PacketInjectionTest::InjectIncorrectPacket(CodecType codec_type,
37 uint8_t payload_type,
38 const uint8_t* packet,
39 size_t length) {
solenberg4fbae2b2015-08-28 04:07:10 -070040 CreateSenderCall(Call::Config());
41 CreateReceiverCall(Call::Config());
pbosf1828e82015-07-28 08:20:59 -070042
solenberg4fbae2b2015-08-28 04:07:10 -070043 test::NullTransport null_transport;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010044 CreateSendConfig(1, 0, &null_transport);
solenberg4fbae2b2015-08-28 04:07:10 -070045 CreateMatchingReceiveConfigs(&null_transport);
stefanff483612015-12-21 03:14:00 -080046 video_receive_configs_[0].decoders[0].payload_type = payload_type;
pbosf1828e82015-07-28 08:20:59 -070047 switch (codec_type) {
48 case CodecType::kVp8:
stefanff483612015-12-21 03:14:00 -080049 video_receive_configs_[0].decoders[0].payload_name = "VP8";
pbosf1828e82015-07-28 08:20:59 -070050 break;
51 case CodecType::kH264:
stefanff483612015-12-21 03:14:00 -080052 video_receive_configs_[0].decoders[0].payload_name = "H264";
pbosf1828e82015-07-28 08:20:59 -070053 break;
54 }
Stefan Holmer9fea80f2016-01-07 17:43:18 +010055 CreateVideoStreams();
pbosf1828e82015-07-28 08:20:59 -070056
57 RTPHeader header;
58 EXPECT_TRUE(rtp_header_parser_->Parse(packet, length, &header));
Stefan Holmer9fea80f2016-01-07 17:43:18 +010059 EXPECT_EQ(kVideoSendSsrcs[0], header.ssrc)
pbosf1828e82015-07-28 08:20:59 -070060 << "Packet should have configured SSRC to not be dropped early.";
61 EXPECT_EQ(payload_type, header.payloadType);
62 Start();
63 EXPECT_EQ(PacketReceiver::DELIVERY_PACKET_ERROR,
64 receiver_call_->Receiver()->DeliverPacket(MediaType::VIDEO, packet,
stefan68786d22015-09-08 05:36:15 -070065 length, PacketTime()));
pbosf1828e82015-07-28 08:20:59 -070066 Stop();
67
68 DestroyStreams();
69}
70
71TEST_F(PacketInjectionTest, StapAPacketWithTruncatedNalUnits) {
72 const uint8_t kPacket[] = {0x80,
73 0xE5,
74 0xE6,
75 0x0,
76 0x0,
77 0xED,
78 0x23,
79 0x4,
80 0x00,
81 0xC0,
82 0xFF,
83 0xED,
84 0x58,
85 0xCB,
86 0xED,
87 0xDF};
88
89 InjectIncorrectPacket(CodecType::kH264, 101, kPacket, sizeof(kPacket));
90}
91
92} // namespace webrtc