| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include "webrtc/base/array_view.h" | 13 #include "webrtc/base/array_view.h" |
| 14 #include "webrtc/call/flexfec_receive_stream_impl.h" | 14 #include "webrtc/call/flexfec_receive_stream_impl.h" |
| 15 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 15 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 16 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 18 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" | |
| 19 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 20 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 21 #include "webrtc/test/mock_transport.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 27 constexpr uint8_t kFlexfecPlType = 118; |
| 28 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
| 29 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; |
| 30 |
| 31 FlexfecReceiveStream::Config CreateDefaultConfig( |
| 32 Transport* rtcp_send_transport) { |
| 33 FlexfecReceiveStream::Config config(rtcp_send_transport); |
| 34 config.payload_type = kFlexfecPlType; |
| 35 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
| 36 config.protected_media_ssrcs = { |
| 37 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
| 38 EXPECT_TRUE(config.IsCompleteAndEnabled()); |
| 39 return config; |
| 40 } |
| 41 |
| 26 RtpPacketReceived ParsePacket(rtc::ArrayView<const uint8_t> packet) { | 42 RtpPacketReceived ParsePacket(rtc::ArrayView<const uint8_t> packet) { |
| 27 RtpPacketReceived parsed_packet(nullptr); | 43 RtpPacketReceived parsed_packet(nullptr); |
| 28 EXPECT_TRUE(parsed_packet.Parse(packet)); | 44 EXPECT_TRUE(parsed_packet.Parse(packet)); |
| 29 return parsed_packet; | 45 return parsed_packet; |
| 30 } | 46 } |
| 31 | 47 |
| 32 } // namespace | 48 } // namespace |
| 33 | 49 |
| 34 TEST(FlexfecReceiveStreamTest, ConstructDestruct) { | 50 TEST(FlexfecReceiveStreamConfigTest, IsCompleteAndEnabled) { |
| 35 FlexfecReceiveStream::Config config; | 51 MockTransport rtcp_send_transport; |
| 36 config.payload_type = 118; | 52 FlexfecReceiveStream::Config config(&rtcp_send_transport); |
| 37 config.remote_ssrc = 424223; | |
| 38 config.protected_media_ssrcs = {912512}; | |
| 39 MockRecoveredPacketReceiver recovered_packet_receiver; | |
| 40 | 53 |
| 41 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); | 54 config.local_ssrc = 18374743; |
| 55 config.rtcp_mode = RtcpMode::kCompound; |
| 56 config.transport_cc = true; |
| 57 config.rtp_header_extensions.emplace_back(TransportSequenceNumber::kUri, 7); |
| 58 EXPECT_FALSE(config.IsCompleteAndEnabled()); |
| 59 |
| 60 config.payload_type = 123; |
| 61 EXPECT_FALSE(config.IsCompleteAndEnabled()); |
| 62 |
| 63 config.remote_ssrc = 238423838; |
| 64 EXPECT_FALSE(config.IsCompleteAndEnabled()); |
| 65 |
| 66 config.protected_media_ssrcs.push_back(138989393); |
| 67 EXPECT_TRUE(config.IsCompleteAndEnabled()); |
| 68 |
| 69 config.protected_media_ssrcs.push_back(33423423); |
| 70 EXPECT_FALSE(config.IsCompleteAndEnabled()); |
| 42 } | 71 } |
| 43 | 72 |
| 44 TEST(FlexfecReceiveStreamTest, StartStop) { | 73 class FlexfecReceiveStreamTest : public ::testing::Test { |
| 45 FlexfecReceiveStream::Config config; | 74 protected: |
| 46 config.payload_type = 118; | 75 FlexfecReceiveStreamTest() |
| 47 config.remote_ssrc = 1652392; | 76 : config_(CreateDefaultConfig(&rtcp_send_transport_)), |
| 48 config.protected_media_ssrcs = {23300443}; | 77 receive_stream_(config_, &recovered_packet_receiver_) {} |
| 49 MockRecoveredPacketReceiver recovered_packet_receiver; | |
| 50 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); | |
| 51 | 78 |
| 52 receive_stream.Start(); | 79 FlexfecReceiveStream::Config config_; |
| 53 receive_stream.Stop(); | 80 MockRecoveredPacketReceiver recovered_packet_receiver_; |
| 81 MockTransport rtcp_send_transport_; |
| 82 |
| 83 FlexfecReceiveStreamImpl receive_stream_; |
| 84 }; |
| 85 |
| 86 TEST_F(FlexfecReceiveStreamTest, ConstructDestruct) {} |
| 87 |
| 88 TEST_F(FlexfecReceiveStreamTest, StartStop) { |
| 89 receive_stream_.Start(); |
| 90 receive_stream_.Stop(); |
| 54 } | 91 } |
| 55 | 92 |
| 56 // Create a FlexFEC packet that protects a single media packet and ensure | 93 // 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 | 94 // that the callback is called. Correctness of recovery is checked in the |
| 58 // FlexfecReceiver unit tests. | 95 // FlexfecReceiver unit tests. |
| 59 TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { | 96 TEST_F(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
| 60 constexpr uint8_t kFlexfecPlType = 118; | |
| 61 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; | 97 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
| 62 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; | 98 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
| 63 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; | |
| 64 constexpr uint8_t kMediaPlType = 107; | 99 constexpr uint8_t kMediaPlType = 107; |
| 65 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; | 100 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; |
| 66 constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; | 101 constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 67 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; | |
| 68 | 102 |
| 69 // This packet mask protects a single media packet, i.e., the FlexFEC payload | 103 // 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, | 104 // is a copy of that media packet. When inserted in the FlexFEC pipeline, |
| 71 // it will thus trivially recover the lost media packet. | 105 // it will thus trivially recover the lost media packet. |
| 72 constexpr uint8_t kKBit0 = 1 << 7; | 106 constexpr uint8_t kKBit0 = 1 << 7; |
| 73 constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; | 107 constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; |
| 74 constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; | 108 constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; |
| 75 constexpr uint8_t kSsrcCount = 1; | 109 constexpr uint8_t kSsrcCount = 1; |
| 76 constexpr uint8_t kReservedBits = 0x00; | 110 constexpr uint8_t kReservedBits = 0x00; |
| 77 constexpr uint8_t kPayloadBits = 0x00; | 111 constexpr uint8_t kPayloadBits = 0x00; |
| 78 // clang-format off | 112 // clang-format off |
| 79 constexpr uint8_t kFlexfecPacket[] = { | 113 constexpr uint8_t kFlexfecPacket[] = { |
| 80 // RTP header. | 114 // RTP header. |
| 81 0x80, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], | 115 0x80, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], |
| 82 kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], | 116 kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], |
| 83 kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], | 117 kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], |
| 84 // FlexFEC header. | 118 // FlexFEC header. |
| 85 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], | 119 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], |
| 86 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], | 120 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], |
| 87 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, | 121 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, |
| 88 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], | 122 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], |
| 89 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], | 123 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], |
| 90 // FEC payload. | 124 // FEC payload. |
| 91 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; | 125 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
| 92 // clang-format on | 126 // clang-format on |
| 93 | 127 |
| 94 FlexfecReceiveStream::Config config; | |
| 95 config.payload_type = kFlexfecPlType; | |
| 96 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); | |
| 97 config.protected_media_ssrcs = { | |
| 98 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; | |
| 99 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; | 128 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
| 100 FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); | 129 FlexfecReceiveStreamImpl receive_stream(config_, &recovered_packet_receiver); |
| 101 | 130 |
| 102 // Do not call back before being started. | 131 // Do not call back before being started. |
| 103 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); | 132 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
| 104 | 133 |
| 105 // Call back after being started. | 134 // Call back after being started. |
| 106 receive_stream.Start(); | 135 receive_stream.Start(); |
| 107 EXPECT_CALL( | 136 EXPECT_CALL( |
| 108 recovered_packet_receiver, | 137 recovered_packet_receiver, |
| 109 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); | 138 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); |
| 110 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); | 139 receive_stream.AddAndProcessReceivedPacket(ParsePacket(kFlexfecPacket)); |
| 111 } | 140 } |
| 112 | 141 |
| 113 } // namespace webrtc | 142 } // namespace webrtc |
| OLD | NEW |