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