blob: 277cd3e4df21de2041cc273e99fdc1125247e2f3 [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
11#include "testing/gtest/include/gtest/gtest.h"
12
13#include "webrtc/test/call_test.h"
14#include "webrtc/test/null_transport.h"
15
16namespace webrtc {
17
18class PacketInjectionTest : public test::CallTest {
19 protected:
20 enum class CodecType {
21 kVp8,
22 kH264,
23 };
24
25 PacketInjectionTest() : rtp_header_parser_(RtpHeaderParser::Create()) {}
26
27 void InjectIncorrectPacket(CodecType codec_type,
28 uint8_t packet_type,
29 const uint8_t* packet,
30 size_t length);
31
32 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
33};
34
35void PacketInjectionTest::InjectIncorrectPacket(CodecType codec_type,
36 uint8_t payload_type,
37 const uint8_t* packet,
38 size_t length) {
solenberg4fbae2b2015-08-28 04:07:10 -070039 CreateSenderCall(Call::Config());
40 CreateReceiverCall(Call::Config());
pbosf1828e82015-07-28 08:20:59 -070041
solenberg4fbae2b2015-08-28 04:07:10 -070042 test::NullTransport null_transport;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010043 CreateSendConfig(1, 0, &null_transport);
solenberg4fbae2b2015-08-28 04:07:10 -070044 CreateMatchingReceiveConfigs(&null_transport);
stefanff483612015-12-21 03:14:00 -080045 video_receive_configs_[0].decoders[0].payload_type = payload_type;
pbosf1828e82015-07-28 08:20:59 -070046 switch (codec_type) {
47 case CodecType::kVp8:
stefanff483612015-12-21 03:14:00 -080048 video_receive_configs_[0].decoders[0].payload_name = "VP8";
pbosf1828e82015-07-28 08:20:59 -070049 break;
50 case CodecType::kH264:
stefanff483612015-12-21 03:14:00 -080051 video_receive_configs_[0].decoders[0].payload_name = "H264";
pbosf1828e82015-07-28 08:20:59 -070052 break;
53 }
Stefan Holmer9fea80f2016-01-07 17:43:18 +010054 CreateVideoStreams();
pbosf1828e82015-07-28 08:20:59 -070055
56 RTPHeader header;
57 EXPECT_TRUE(rtp_header_parser_->Parse(packet, length, &header));
Stefan Holmer9fea80f2016-01-07 17:43:18 +010058 EXPECT_EQ(kVideoSendSsrcs[0], header.ssrc)
pbosf1828e82015-07-28 08:20:59 -070059 << "Packet should have configured SSRC to not be dropped early.";
60 EXPECT_EQ(payload_type, header.payloadType);
61 Start();
62 EXPECT_EQ(PacketReceiver::DELIVERY_PACKET_ERROR,
63 receiver_call_->Receiver()->DeliverPacket(MediaType::VIDEO, packet,
stefan68786d22015-09-08 05:36:15 -070064 length, PacketTime()));
pbosf1828e82015-07-28 08:20:59 -070065 Stop();
66
67 DestroyStreams();
68}
69
70TEST_F(PacketInjectionTest, StapAPacketWithTruncatedNalUnits) {
71 const uint8_t kPacket[] = {0x80,
72 0xE5,
73 0xE6,
74 0x0,
75 0x0,
76 0xED,
77 0x23,
78 0x4,
79 0x00,
80 0xC0,
81 0xFF,
82 0xED,
83 0x58,
84 0xCB,
85 0xED,
86 0xDF};
87
88 InjectIncorrectPacket(CodecType::kH264, 101, kPacket, sizeof(kPacket));
89}
90
91} // namespace webrtc