blob: df19cf3d0cf7652474e9a6153a9f6730469a41e3 [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
skvlad11a9cbf2016-10-07 11:53:05 -070013#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
pbosf1828e82015-07-28 08:20:59 -070014#include "webrtc/test/call_test.h"
kwibergac9f8762016-09-30 22:29:43 -070015#include "webrtc/test/gtest.h"
pbosf1828e82015-07-28 08:20:59 -070016#include "webrtc/test/null_transport.h"
17
18namespace webrtc {
19
20class PacketInjectionTest : public test::CallTest {
21 protected:
22 enum class CodecType {
23 kVp8,
24 kH264,
25 };
26
27 PacketInjectionTest() : rtp_header_parser_(RtpHeaderParser::Create()) {}
28
29 void InjectIncorrectPacket(CodecType codec_type,
30 uint8_t packet_type,
31 const uint8_t* packet,
32 size_t length);
33
kwibergb25345e2016-03-12 06:10:44 -080034 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
pbosf1828e82015-07-28 08:20:59 -070035};
36
37void PacketInjectionTest::InjectIncorrectPacket(CodecType codec_type,
38 uint8_t payload_type,
39 const uint8_t* packet,
40 size_t length) {
skvlad11a9cbf2016-10-07 11:53:05 -070041 CreateSenderCall(Call::Config(&event_log_));
42 CreateReceiverCall(Call::Config(&event_log_));
pbosf1828e82015-07-28 08:20:59 -070043
solenberg4fbae2b2015-08-28 04:07:10 -070044 test::NullTransport null_transport;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010045 CreateSendConfig(1, 0, &null_transport);
solenberg4fbae2b2015-08-28 04:07:10 -070046 CreateMatchingReceiveConfigs(&null_transport);
stefanff483612015-12-21 03:14:00 -080047 video_receive_configs_[0].decoders[0].payload_type = payload_type;
pbosf1828e82015-07-28 08:20:59 -070048 switch (codec_type) {
49 case CodecType::kVp8:
stefanff483612015-12-21 03:14:00 -080050 video_receive_configs_[0].decoders[0].payload_name = "VP8";
pbosf1828e82015-07-28 08:20:59 -070051 break;
52 case CodecType::kH264:
stefanff483612015-12-21 03:14:00 -080053 video_receive_configs_[0].decoders[0].payload_name = "H264";
pbosf1828e82015-07-28 08:20:59 -070054 break;
55 }
Stefan Holmer9fea80f2016-01-07 17:43:18 +010056 CreateVideoStreams();
pbosf1828e82015-07-28 08:20:59 -070057
58 RTPHeader header;
59 EXPECT_TRUE(rtp_header_parser_->Parse(packet, length, &header));
Stefan Holmer9fea80f2016-01-07 17:43:18 +010060 EXPECT_EQ(kVideoSendSsrcs[0], header.ssrc)
pbosf1828e82015-07-28 08:20:59 -070061 << "Packet should have configured SSRC to not be dropped early.";
62 EXPECT_EQ(payload_type, header.payloadType);
63 Start();
64 EXPECT_EQ(PacketReceiver::DELIVERY_PACKET_ERROR,
65 receiver_call_->Receiver()->DeliverPacket(MediaType::VIDEO, packet,
stefan68786d22015-09-08 05:36:15 -070066 length, PacketTime()));
pbosf1828e82015-07-28 08:20:59 -070067 Stop();
68
69 DestroyStreams();
70}
71
72TEST_F(PacketInjectionTest, StapAPacketWithTruncatedNalUnits) {
73 const uint8_t kPacket[] = {0x80,
74 0xE5,
75 0xE6,
76 0x0,
77 0x0,
78 0xED,
79 0x23,
80 0x4,
81 0x00,
82 0xC0,
83 0xFF,
84 0xED,
85 0x58,
86 0xCB,
87 0xED,
88 0xDF};
89
90 InjectIncorrectPacket(CodecType::kH264, 101, kPacket, sizeof(kPacket));
91}
92
93} // namespace webrtc