blob: c25858f02cbf10c9021583401b4f36b9843020f6 [file] [log] [blame]
brandtr76648da2016-10-20 04:54:48 -07001/*
2 * Copyright (c) 2016 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
pbosc7c26a02017-01-02 08:42:32 -080011#include <stdint.h>
12
brandtrb29e6522016-12-21 06:37:18 -080013#include "webrtc/base/array_view.h"
brandtr7250b392016-12-19 01:13:46 -080014#include "webrtc/call/flexfec_receive_stream_impl.h"
brandtr76648da2016-10-20 04:54:48 -070015#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h"
16#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
brandtrb29e6522016-12-21 06:37:18 -080017#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
brandtr76648da2016-10-20 04:54:48 -070018#include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h"
19#include "webrtc/test/gmock.h"
20#include "webrtc/test/gtest.h"
21
22namespace webrtc {
23
brandtrb29e6522016-12-21 06:37:18 -080024namespace {
25
26RtpPacketReceived ParsePacket(rtc::ArrayView<const uint8_t> packet) {
27 RtpPacketReceived parsed_packet(nullptr);
28 EXPECT_TRUE(parsed_packet.Parse(packet));
29 return parsed_packet;
30}
31
32} // namespace
33
brandtr76648da2016-10-20 04:54:48 -070034TEST(FlexfecReceiveStreamTest, ConstructDestruct) {
35 FlexfecReceiveStream::Config config;
brandtr1cfbd602016-12-08 04:17:53 -080036 config.payload_type = 118;
37 config.remote_ssrc = 424223;
brandtr76648da2016-10-20 04:54:48 -070038 config.protected_media_ssrcs = {912512};
brandtrb29e6522016-12-21 06:37:18 -080039 MockRecoveredPacketReceiver recovered_packet_receiver;
brandtr76648da2016-10-20 04:54:48 -070040
brandtrb29e6522016-12-21 06:37:18 -080041 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver);
brandtr76648da2016-10-20 04:54:48 -070042}
43
44TEST(FlexfecReceiveStreamTest, StartStop) {
45 FlexfecReceiveStream::Config config;
brandtr1cfbd602016-12-08 04:17:53 -080046 config.payload_type = 118;
47 config.remote_ssrc = 1652392;
brandtr76648da2016-10-20 04:54:48 -070048 config.protected_media_ssrcs = {23300443};
brandtrb29e6522016-12-21 06:37:18 -080049 MockRecoveredPacketReceiver recovered_packet_receiver;
50 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver);
brandtr76648da2016-10-20 04:54:48 -070051
52 receive_stream.Start();
53 receive_stream.Stop();
54}
55
brandtr76648da2016-10-20 04:54:48 -070056// Create a FlexFEC packet that protects a single media packet and ensure
57// that the callback is called. Correctness of recovery is checked in the
58// FlexfecReceiver unit tests.
59TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) {
60 constexpr uint8_t kFlexfecPlType = 118;
61 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01};
62 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33};
63 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01};
64 constexpr uint8_t kMediaPlType = 107;
65 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02};
66 constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd};
67 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02};
68
69 // This packet mask protects a single media packet, i.e., the FlexFEC payload
70 // is a copy of that media packet. When inserted in the FlexFEC pipeline,
71 // it will thus trivially recover the lost media packet.
72 constexpr uint8_t kKBit0 = 1 << 7;
73 constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01};
74 constexpr uint8_t kPayloadLength[] = {0x00, 0x04};
75 constexpr uint8_t kSsrcCount = 1;
76 constexpr uint8_t kReservedBits = 0x00;
77 constexpr uint8_t kPayloadBits = 0x00;
78 // clang-format off
79 constexpr uint8_t kFlexfecPacket[] = {
80 // RTP header.
81 0x80, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1],
82 kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3],
83 kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3],
84 // FlexFEC header.
85 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1],
86 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3],
87 kSsrcCount, kReservedBits, kReservedBits, kReservedBits,
88 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3],
89 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1],
90 // FEC payload.
91 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits};
92 // clang-format on
brandtr76648da2016-10-20 04:54:48 -070093
94 FlexfecReceiveStream::Config config;
brandtr1cfbd602016-12-08 04:17:53 -080095 config.payload_type = kFlexfecPlType;
96 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc);
brandtr76648da2016-10-20 04:54:48 -070097 config.protected_media_ssrcs = {
98 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)};
99 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver;
brandtr7250b392016-12-19 01:13:46 -0800100 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver);
brandtr76648da2016-10-20 04:54:48 -0700101
102 // Do not call back before being started.
brandtrb29e6522016-12-21 06:37:18 -0800103 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket));
brandtr76648da2016-10-20 04:54:48 -0700104
105 // Call back after being started.
106 receive_stream.Start();
107 EXPECT_CALL(
108 recovered_packet_receiver,
109 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1]));
brandtrb29e6522016-12-21 06:37:18 -0800110 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket));
brandtr76648da2016-10-20 04:54:48 -0700111}
112
113} // namespace webrtc