OLD | NEW |
(Empty) | |
| 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 |
| 11 #include "webrtc/base/basictypes.h" |
| 12 #include "webrtc/call/flexfec_receive_stream.h" |
| 13 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 15 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
| 16 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" |
| 18 |
| 19 namespace webrtc { |
| 20 |
| 21 TEST(FlexfecReceiveStreamTest, ConfigToString) { |
| 22 FlexfecReceiveStream::Config config; |
| 23 config.flexfec_payload_type = 118; |
| 24 config.flexfec_ssrc = 12545412; |
| 25 config.protected_media_ssrcs = {89372, 262552}; |
| 26 |
| 27 EXPECT_EQ( |
| 28 "{flexfec_payload_type: 118, " |
| 29 "flexfec_ssrc: 12545412, " |
| 30 "protected_media_ssrcs: {89372, 262552}}", |
| 31 config.ToString()); |
| 32 } |
| 33 |
| 34 TEST(FlexfecReceiveStreamTest, ConstructDestruct) { |
| 35 FlexfecReceiveStream::Config config; |
| 36 config.flexfec_payload_type = 118; |
| 37 config.flexfec_ssrc = 424223; |
| 38 config.protected_media_ssrcs = {912512}; |
| 39 MockRecoveredPacketReceiver callback; |
| 40 |
| 41 internal::FlexfecReceiveStream receive_stream(config, &callback); |
| 42 } |
| 43 |
| 44 TEST(FlexfecReceiveStreamTest, StartStop) { |
| 45 FlexfecReceiveStream::Config config; |
| 46 config.flexfec_payload_type = 118; |
| 47 config.flexfec_ssrc = 1652392; |
| 48 config.protected_media_ssrcs = {23300443}; |
| 49 MockRecoveredPacketReceiver callback; |
| 50 internal::FlexfecReceiveStream receive_stream(config, &callback); |
| 51 |
| 52 receive_stream.Start(); |
| 53 receive_stream.Stop(); |
| 54 } |
| 55 |
| 56 TEST(FlexfecReceiveStreamTest, DoesNotProcessPacketWhenNoMediaSsrcGiven) { |
| 57 FlexfecReceiveStream::Config config; |
| 58 config.flexfec_payload_type = 118; |
| 59 config.flexfec_ssrc = 424223; |
| 60 config.protected_media_ssrcs = {}; |
| 61 MockRecoveredPacketReceiver callback; |
| 62 internal::FlexfecReceiveStream receive_stream(config, &callback); |
| 63 const uint8_t packet[] = {0x00, 0x11, 0x22, 0x33}; |
| 64 const size_t packet_length = sizeof(packet); |
| 65 |
| 66 EXPECT_FALSE( |
| 67 receive_stream.AddAndProcessReceivedPacket(packet, packet_length)); |
| 68 } |
| 69 |
| 70 // TODO(brandtr): Remove when we support multistream protection. |
| 71 TEST(FlexfecReceiveStreamTest, CannotProtectMultipleMediaStreams) { |
| 72 FlexfecReceiveStream::Config config; |
| 73 config.flexfec_payload_type = 118; |
| 74 config.flexfec_ssrc = 424223; |
| 75 config.protected_media_ssrcs = {123, 456}; |
| 76 MockRecoveredPacketReceiver callback; |
| 77 internal::FlexfecReceiveStream receive_stream(config, &callback); |
| 78 |
| 79 ASSERT_EQ(1U, receive_stream.config().protected_media_ssrcs.size()); |
| 80 EXPECT_EQ(config.protected_media_ssrcs[0], |
| 81 receive_stream.config().protected_media_ssrcs[0]); |
| 82 } |
| 83 |
| 84 // Create a FlexFEC packet that protects a single media packet and ensure |
| 85 // that the callback is called. Correctness of recovery is checked in the |
| 86 // FlexfecReceiver unit tests. |
| 87 TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
| 88 constexpr uint8_t kFlexfecPlType = 118; |
| 89 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
| 90 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
| 91 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
| 92 constexpr uint8_t kMediaPlType = 107; |
| 93 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; |
| 94 constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 95 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; |
| 96 |
| 97 // This packet mask protects a single media packet, i.e., the FlexFEC payload |
| 98 // is a copy of that media packet. When inserted in the FlexFEC pipeline, |
| 99 // it will thus trivially recover the lost media packet. |
| 100 constexpr uint8_t kKBit0 = 1 << 7; |
| 101 constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; |
| 102 constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; |
| 103 constexpr uint8_t kSsrcCount = 1; |
| 104 constexpr uint8_t kReservedBits = 0x00; |
| 105 constexpr uint8_t kPayloadBits = 0x00; |
| 106 // clang-format off |
| 107 constexpr uint8_t kFlexfecPacket[] = { |
| 108 // RTP header. |
| 109 0x80, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], |
| 110 kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], |
| 111 kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], |
| 112 // FlexFEC header. |
| 113 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], |
| 114 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], |
| 115 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, |
| 116 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], |
| 117 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], |
| 118 // FEC payload. |
| 119 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
| 120 // clang-format on |
| 121 constexpr size_t kFlexfecPacketLength = sizeof(kFlexfecPacket); |
| 122 |
| 123 FlexfecReceiveStream::Config config; |
| 124 config.flexfec_payload_type = kFlexfecPlType; |
| 125 config.flexfec_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
| 126 config.protected_media_ssrcs = { |
| 127 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
| 128 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
| 129 internal::FlexfecReceiveStream receive_stream(config, |
| 130 &recovered_packet_receiver); |
| 131 |
| 132 // Do not call back before being started. |
| 133 receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, |
| 134 kFlexfecPacketLength); |
| 135 |
| 136 // Call back after being started. |
| 137 receive_stream.Start(); |
| 138 EXPECT_CALL( |
| 139 recovered_packet_receiver, |
| 140 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); |
| 141 receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, |
| 142 kFlexfecPacketLength); |
| 143 } |
| 144 |
| 145 } // namespace webrtc |
OLD | NEW |