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 | |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame^] | 11 | #include <stdint.h> |
| 12 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 13 | #include "webrtc/base/array_view.h" |
brandtr | 7250b39 | 2016-12-19 01:13:46 -0800 | [diff] [blame] | 14 | #include "webrtc/call/flexfec_receive_stream_impl.h" |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 15 | #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 16 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 18 | #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
| 19 | #include "webrtc/test/gmock.h" |
| 20 | #include "webrtc/test/gtest.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | RtpPacketReceived 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 | |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 34 | TEST(FlexfecReceiveStreamTest, ConstructDestruct) { |
| 35 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 36 | config.payload_type = 118; |
| 37 | config.remote_ssrc = 424223; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 38 | config.protected_media_ssrcs = {912512}; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 39 | MockRecoveredPacketReceiver recovered_packet_receiver; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 40 | |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 41 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | TEST(FlexfecReceiveStreamTest, StartStop) { |
| 45 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 46 | config.payload_type = 118; |
| 47 | config.remote_ssrc = 1652392; |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 48 | config.protected_media_ssrcs = {23300443}; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 49 | MockRecoveredPacketReceiver recovered_packet_receiver; |
| 50 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 51 | |
| 52 | receive_stream.Start(); |
| 53 | receive_stream.Stop(); |
| 54 | } |
| 55 | |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 56 | // 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. |
| 59 | TEST(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 |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 93 | |
| 94 | FlexfecReceiveStream::Config config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 95 | config.payload_type = kFlexfecPlType; |
| 96 | config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 97 | config.protected_media_ssrcs = { |
| 98 | ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
| 99 | testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
brandtr | 7250b39 | 2016-12-19 01:13:46 -0800 | [diff] [blame] | 100 | FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 101 | |
| 102 | // Do not call back before being started. |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 103 | receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 104 | |
| 105 | // Call back after being started. |
| 106 | receive_stream.Start(); |
| 107 | EXPECT_CALL( |
| 108 | recovered_packet_receiver, |
| 109 | OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 110 | receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } // namespace webrtc |