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 <cstdio> |
| 12 |
| 13 #include "webrtc/call/rtp_rtcp_demuxer_helper.h" |
| 14 |
| 15 #include "webrtc/base/arraysize.h" |
| 16 #include "webrtc/base/buffer.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 23 #include "webrtc/test/gtest.h" |
| 24 |
| 25 namespace webrtc { |
| 26 |
| 27 namespace { |
| 28 constexpr uint32_t kSsrc = 8374; |
| 29 } // namespace |
| 30 |
| 31 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_ByePacket) { |
| 32 webrtc::rtcp::Bye rtcp_packet; |
| 33 rtcp_packet.SetSenderSsrc(kSsrc); |
| 34 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 35 |
| 36 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 37 ASSERT_TRUE(ssrc); |
| 38 EXPECT_EQ(*ssrc, kSsrc); |
| 39 } |
| 40 |
| 41 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_PsfbPacket) { |
| 42 webrtc::rtcp::Pli rtcp_packet; // Psfb is abstract; use a subclass. |
| 43 rtcp_packet.SetSenderSsrc(kSsrc); |
| 44 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 45 |
| 46 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 47 ASSERT_TRUE(ssrc); |
| 48 EXPECT_EQ(*ssrc, kSsrc); |
| 49 } |
| 50 |
| 51 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_ReceiverReportPacket) { |
| 52 webrtc::rtcp::ReceiverReport rtcp_packet; |
| 53 rtcp_packet.SetSenderSsrc(kSsrc); |
| 54 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 55 |
| 56 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 57 ASSERT_TRUE(ssrc); |
| 58 EXPECT_EQ(*ssrc, kSsrc); |
| 59 } |
| 60 |
| 61 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_RtpfbPacket) { |
| 62 // Rtpfb is abstract; use a subclass. |
| 63 webrtc::rtcp::RapidResyncRequest rtcp_packet; |
| 64 rtcp_packet.SetSenderSsrc(kSsrc); |
| 65 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 66 |
| 67 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 68 ASSERT_TRUE(ssrc); |
| 69 EXPECT_EQ(*ssrc, kSsrc); |
| 70 } |
| 71 |
| 72 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_SenderReportPacket) { |
| 73 webrtc::rtcp::SenderReport rtcp_packet; |
| 74 rtcp_packet.SetSenderSsrc(kSsrc); |
| 75 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 76 |
| 77 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 78 ASSERT_TRUE(ssrc); |
| 79 EXPECT_EQ(*ssrc, kSsrc); |
| 80 } |
| 81 |
| 82 TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_BadRtcpPacket) { |
| 83 uint8_t garbage[100]; |
| 84 memset(&garbage[0], 0, arraysize(garbage)); |
| 85 |
| 86 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(garbage); |
| 87 EXPECT_FALSE(ssrc); |
| 88 } |
| 89 |
| 90 TEST(RtpRtcpDemuxerHelperTest, |
| 91 ParseRtcpPacketSenderSsrc_RtcpMessageWithoutSenderSsrc) { |
| 92 webrtc::rtcp::ExtendedJitterReport rtcp_packet; // Has no sender SSRC. |
| 93 rtc::Buffer raw_packet = rtcp_packet.Build(); |
| 94 |
| 95 rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
| 96 EXPECT_FALSE(ssrc); |
| 97 } |
| 98 |
| 99 } // namespace webrtc |
OLD | NEW |