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#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) {
39  CreateSenderCall(Call::Config());
40  CreateReceiverCall(Call::Config());
41
42  test::NullTransport null_transport;
43  CreateSendConfig(1, 0, &null_transport);
44  CreateMatchingReceiveConfigs(&null_transport);
45  video_receive_configs_[0].decoders[0].payload_type = payload_type;
46  switch (codec_type) {
47    case CodecType::kVp8:
48      video_receive_configs_[0].decoders[0].payload_name = "VP8";
49      break;
50    case CodecType::kH264:
51      video_receive_configs_[0].decoders[0].payload_name = "H264";
52      break;
53  }
54  CreateVideoStreams();
55
56  RTPHeader header;
57  EXPECT_TRUE(rtp_header_parser_->Parse(packet, length, &header));
58  EXPECT_EQ(kVideoSendSsrcs[0], header.ssrc)
59      << "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,
64                                                      length, PacketTime()));
65  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
92