Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 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/call/rtx_receive_stream.h" | |
| 12 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | |
| 13 #include "webrtc/test/gmock.h" | |
| 14 #include "webrtc/test/gtest.h" | |
| 15 | |
| 16 namespace webrtc { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 class MockRtpPacketSink : public RtpPacketSinkInterface { | |
| 21 public: | |
| 22 MOCK_METHOD1(OnRtpPacket, void(const RtpPacketReceived&)); | |
| 23 }; | |
| 24 | |
| 25 constexpr int kMediaPayloadType = 100; | |
| 26 constexpr int kRtxPayloadType = 98; | |
| 27 constexpr int kMediaSSRC = 0x3333333; | |
|
danilchap
2017/05/19 08:39:02
may be uint32_t for SSRC
nisse-webrtc
2017/05/19 10:59:14
Done.
| |
| 28 | |
|
danilchap
2017/05/19 08:39:03
might be helpful to add constants for the original
nisse-webrtc
2017/05/19 10:59:14
Added constant for the seqno.
| |
| 29 constexpr uint8_t kRtxPacket[] = { | |
| 30 0x80, // Version 2, | |
| 31 98, // Payload type | |
|
danilchap
2017/05/19 08:39:03
likely add dots at the end of the comments.
nisse-webrtc
2017/05/19 10:59:14
Done.
| |
| 32 0x12, 0x34, // Seqno, | |
| 33 0x11, 0x11, 0x11, 0x11, // Timestamp | |
| 34 0x22, 0x22, 0x22, 0x22, // SSRC | |
| 35 // RTX header | |
| 36 0x56, 0x57, // Orig seqno | |
| 37 // Payload | |
| 38 0xee, | |
| 39 }; | |
| 40 | |
| 41 std::map<int, int> PTMapping() { | |
|
danilchap
2017/05/19 08:39:03
it is easier to read if you do not abbreviate: so
nisse-webrtc
2017/05/19 10:59:14
Done.
| |
| 42 std::map<int, int> m; | |
|
danilchap
2017/05/19 08:39:02
I wonder if
return {{kRtxPayloadType, kMediaPayloa
| |
| 43 m[kRtxPayloadType] = kMediaPayloadType; | |
| 44 return m; | |
| 45 } | |
| 46 | |
| 47 template <typename T> | |
| 48 rtc::ArrayView<T> Truncate(rtc::ArrayView<T> a, size_t drop) { | |
| 49 return a.subview(0, a.size() - drop); | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 TEST(RtxReceiveStreamTest, RestoresPacketPayload) { | |
| 55 testing::StrictMock<MockRtpPacketSink> media_sink; | |
|
danilchap
2017/05/19 08:39:02
personally I prefer to add
using ::testing::_;
usi
nisse-webrtc
2017/05/19 10:59:14
Done for some of the symbols.
| |
| 56 RtxReceiveStream rtx_sink(&media_sink, PTMapping(), kMediaSSRC); | |
| 57 RtpPacketReceived rtx_packet; | |
| 58 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | |
| 59 | |
| 60 EXPECT_CALL(media_sink, | |
| 61 OnRtpPacket(testing::AllOf( | |
|
danilchap
2017/05/19 08:39:02
Alternative suggestion (not sure it is better thou
nisse-webrtc
2017/05/19 10:59:14
I've changed to this alternative. It provides clea
| |
| 62 testing::Truly([](const RtpPacketReceived& packet) { | |
| 63 return packet.SequenceNumber() == 0x5657; | |
| 64 }), | |
| 65 testing::Truly([](const RtpPacketReceived& packet) { | |
|
danilchap
2017/05/19 08:39:02
Or... yet another (again, not sure it is more read
| |
| 66 return packet.Ssrc() == kMediaSSRC; | |
| 67 }), | |
| 68 testing::Truly([](const RtpPacketReceived& packet) { | |
| 69 return packet.payload().size() == 1 && | |
| 70 packet.payload()[0] == 0xee; | |
| 71 })))); | |
| 72 rtx_sink.OnRtpPacket(rtx_packet); | |
| 73 } | |
| 74 | |
| 75 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) { | |
| 76 testing::StrictMock<MockRtpPacketSink> media_sink; | |
| 77 RtxReceiveStream rtx_sink(&media_sink, std::map<int, int>(), kMediaSSRC); | |
| 78 RtpPacketReceived rtx_packet; | |
| 79 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | |
| 80 rtx_sink.OnRtpPacket(rtx_packet); | |
| 81 } | |
| 82 | |
| 83 TEST(RtxReceiveStreamTest, IgnoresTruncatedPacket) { | |
| 84 testing::StrictMock<MockRtpPacketSink> media_sink; | |
| 85 RtxReceiveStream rtx_sink(&media_sink, PTMapping(), kMediaSSRC); | |
| 86 RtpPacketReceived rtx_packet; | |
| 87 EXPECT_TRUE( | |
| 88 rtx_packet.Parse(Truncate(rtc::ArrayView<const uint8_t>(kRtxPacket), 2))); | |
| 89 rtx_sink.OnRtpPacket(rtx_packet); | |
| 90 } | |
| 91 | |
| 92 } // namespace webrtc | |
| OLD | NEW |