OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "media/cast/rtp_common/rtp_defines.h" | 8 #include "media/cast/rtp_common/rtp_defines.h" |
9 #include "media/cast/rtp_receiver/rtp_parser/rtp_parser.h" | 9 #include "media/cast/rtp_receiver/rtp_parser/rtp_parser.h" |
10 #include "media/cast/rtp_receiver/rtp_parser/test/rtp_packet_builder.h" | 10 #include "media/cast/rtp_receiver/rtp_parser/test/rtp_packet_builder.h" |
11 #include "media/cast/rtp_receiver/rtp_receiver.h" | 11 #include "media/cast/rtp_receiver/rtp_receiver.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 namespace cast { | 14 namespace cast { |
15 | 15 |
16 static const int kPacketLength = 1500; | 16 static const int kPacketLength = 1500; |
17 static const int kCastRtpLength = 7; | 17 static const int kCastRtpLength = 7; |
18 static const int kTestPayloadType = 127; | 18 static const int kTestPayloadType = 127; |
19 static const uint32 kTestSsrc = 1234; | 19 static const uint32 kTestSsrc = 1234; |
20 static const uint32 kTestTimestamp = 111111; | 20 static const uint32 kTestTimestamp = 111111; |
21 static const uint16 kTestSeqNum = 4321; | 21 static const uint16 kTestSeqNum = 4321; |
22 static const uint8 kRefFrameId = 17; | 22 static const uint8 kRefFrameId = 17; |
23 | 23 |
24 class RtpDataTest : public RtpData { | 24 class RtpDataTest : public RtpData { |
25 public: | 25 public: |
26 RtpDataTest() { | 26 RtpDataTest() { |
27 expected_header_.reset(new RtpCastHeader()); | 27 expected_header_.reset(new RtpCastHeader()); |
28 } | 28 } |
29 | 29 |
30 virtual ~RtpDataTest() {} | 30 ~RtpDataTest() {} |
31 | 31 |
32 void SetExpectedHeader(const RtpCastHeader& cast_header) { | 32 void SetExpectedHeader(const RtpCastHeader& cast_header) { |
33 memcpy(expected_header_.get(), &cast_header, sizeof(RtpCastHeader)); | 33 memcpy(expected_header_.get(), &cast_header, sizeof(RtpCastHeader)); |
34 } | 34 } |
35 | 35 |
36 virtual void OnReceivedPayloadData(const uint8* payloadData, | 36 void OnReceivedPayloadData(const uint8* payloadData, |
37 int payloadSize, | 37 int payloadSize, |
38 const RtpCastHeader* rtpHeader) OVERRIDE { | 38 const RtpCastHeader* rtpHeader) { |
39 VerifyCommonHeader(*rtpHeader); | 39 VerifyCommonHeader(*rtpHeader); |
40 VerifyCastHeader(*rtpHeader); | 40 VerifyCastHeader(*rtpHeader); |
41 // TODO(mikhal): Add data verification. | 41 // TODO(mikhal): Add data verification. |
42 } | 42 } |
43 | 43 |
44 void VerifyCommonHeader(const RtpCastHeader& parsed_header) { | 44 void VerifyCommonHeader(const RtpCastHeader& parsed_header) { |
45 EXPECT_EQ(expected_header_->packet_id == expected_header_->max_packet_id, | 45 EXPECT_EQ(expected_header_->packet_id == expected_header_->max_packet_id, |
46 parsed_header.webrtc.header.markerBit); | 46 parsed_header.webrtc.header.markerBit); |
47 EXPECT_EQ(kTestPayloadType, parsed_header.webrtc.header.payloadType); | 47 EXPECT_EQ(kTestPayloadType, parsed_header.webrtc.header.payloadType); |
48 EXPECT_EQ(kTestSsrc, parsed_header.webrtc.header.ssrc); | 48 EXPECT_EQ(kTestSsrc, parsed_header.webrtc.header.ssrc); |
(...skipping 13 matching lines...) Expand all Loading... |
62 }; | 62 }; |
63 | 63 |
64 class RtpParserTest : public ::testing::Test { | 64 class RtpParserTest : public ::testing::Test { |
65 protected: | 65 protected: |
66 RtpParserTest() { | 66 RtpParserTest() { |
67 PopulateConfig(); | 67 PopulateConfig(); |
68 rtp_data_.reset(new RtpDataTest()); | 68 rtp_data_.reset(new RtpDataTest()); |
69 rtp_parser_.reset(new RtpParser(rtp_data_.get(), config_)); | 69 rtp_parser_.reset(new RtpParser(rtp_data_.get(), config_)); |
70 } | 70 } |
71 | 71 |
72 virtual ~RtpParserTest() {} | 72 ~RtpParserTest() {} |
73 | 73 |
74 virtual void SetUp() { | 74 virtual void SetUp() { |
75 cast_header_.InitRTPVideoHeaderCast(); | 75 cast_header_.InitRTPVideoHeaderCast(); |
76 cast_header_.is_reference = true; | 76 cast_header_.is_reference = true; |
77 cast_header_.reference_frame_id = kRefFrameId; | 77 cast_header_.reference_frame_id = kRefFrameId; |
78 packet_builder_.SetSsrc(kTestSsrc); | 78 packet_builder_.SetSsrc(kTestSsrc); |
79 packet_builder_.SetReferenceFrameId(kRefFrameId, true); | 79 packet_builder_.SetReferenceFrameId(kRefFrameId, true); |
80 packet_builder_.SetSequenceNumber(kTestSeqNum); | 80 packet_builder_.SetSequenceNumber(kTestSeqNum); |
81 packet_builder_.SetTimestamp(kTestTimestamp); | 81 packet_builder_.SetTimestamp(kTestTimestamp); |
82 packet_builder_.SetPayloadType(kTestPayloadType); | 82 packet_builder_.SetPayloadType(kTestPayloadType); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 uint8 packet[kPacketLength]; | 192 uint8 packet[kPacketLength]; |
193 packet_builder_.BuildHeader(packet, kPacketLength); | 193 packet_builder_.BuildHeader(packet, kPacketLength); |
194 // Parse packet as is. | 194 // Parse packet as is. |
195 RtpCastHeader rtp_header; | 195 RtpCastHeader rtp_header; |
196 rtp_data_->SetExpectedHeader(cast_header_); | 196 rtp_data_->SetExpectedHeader(cast_header_); |
197 EXPECT_TRUE(rtp_parser_->ParsePacket(packet, kPacketLength, &rtp_header)); | 197 EXPECT_TRUE(rtp_parser_->ParsePacket(packet, kPacketLength, &rtp_header)); |
198 } | 198 } |
199 | 199 |
200 } // namespace cast | 200 } // namespace cast |
201 } // namespace media | 201 } // namespace media |
OLD | NEW |