brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 11 | #include "webrtc/base/array_view.h" |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 12 | #include "webrtc/base/basictypes.h" |
brandtr | 7250b39 | 2016-12-19 01:13:46 -0800 | [diff] [blame] | 13 | #include "webrtc/call/flexfec_receive_stream_impl.h" |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 14 | #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 15 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 16 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
| 18 | #include "webrtc/test/gmock.h" |
| 19 | #include "webrtc/test/gtest.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 23 | namespace { |
| 24 | |
| 25 | RtpPacketReceived ParsePacket(rtc::ArrayView<const uint8_t> packet) { |
| 26 | RtpPacketReceived parsed_packet(nullptr); |
| 27 | EXPECT_TRUE(parsed_packet.Parse(packet)); |
| 28 | return parsed_packet; |
| 29 | } |
| 30 | |
| 31 | } // namespace |
| 32 | |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 33 | TEST(FlexfecReceiveStreamTest, ConstructDestruct) { |
| 34 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 35 | config.payload_type = 118; |
| 36 | config.remote_ssrc = 424223; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 37 | config.protected_media_ssrcs = {912512}; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 38 | MockRecoveredPacketReceiver recovered_packet_receiver; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 39 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 40 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | TEST(FlexfecReceiveStreamTest, StartStop) { |
| 44 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 45 | config.payload_type = 118; |
| 46 | config.remote_ssrc = 1652392; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 47 | config.protected_media_ssrcs = {23300443}; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 48 | MockRecoveredPacketReceiver recovered_packet_receiver; |
| 49 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 50 | |
| 51 | receive_stream.Start(); |
| 52 | receive_stream.Stop(); |
| 53 | } |
| 54 | |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 55 | // Create a FlexFEC packet that protects a single media packet and ensure |
| 56 | // that the callback is called. Correctness of recovery is checked in the |
| 57 | // FlexfecReceiver unit tests. |
| 58 | TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
| 59 | constexpr uint8_t kFlexfecPlType = 118; |
| 60 | constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
| 61 | constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
| 62 | constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
| 63 | constexpr uint8_t kMediaPlType = 107; |
| 64 | constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; |
| 65 | constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 66 | constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; |
| 67 | |
| 68 | // This packet mask protects a single media packet, i.e., the FlexFEC payload |
| 69 | // is a copy of that media packet. When inserted in the FlexFEC pipeline, |
| 70 | // it will thus trivially recover the lost media packet. |
| 71 | constexpr uint8_t kKBit0 = 1 << 7; |
| 72 | constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; |
| 73 | constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; |
| 74 | constexpr uint8_t kSsrcCount = 1; |
| 75 | constexpr uint8_t kReservedBits = 0x00; |
| 76 | constexpr uint8_t kPayloadBits = 0x00; |
| 77 | // clang-format off |
| 78 | constexpr uint8_t kFlexfecPacket[] = { |
| 79 | // RTP header. |
| 80 | 0x80, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], |
| 81 | kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], |
| 82 | kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], |
| 83 | // FlexFEC header. |
| 84 | 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], |
| 85 | kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], |
| 86 | kSsrcCount, kReservedBits, kReservedBits, kReservedBits, |
| 87 | kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], |
| 88 | kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], |
| 89 | // FEC payload. |
| 90 | kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
| 91 | // clang-format on |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 92 | |
| 93 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 94 | config.payload_type = kFlexfecPlType; |
| 95 | config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 96 | config.protected_media_ssrcs = { |
| 97 | ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
| 98 | testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
brandtr | 7250b39 | 2016-12-19 01:13:46 -0800 | [diff] [blame] | 99 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 100 | |
| 101 | // Do not call back before being started. |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 102 | receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 103 | |
| 104 | // Call back after being started. |
| 105 | receive_stream.Start(); |
| 106 | EXPECT_CALL( |
| 107 | recovered_packet_receiver, |
| 108 | OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame^] | 109 | receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | } // namespace webrtc |