| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/cast/net/rtp/rtp_packetizer.h" | 5 #include "media/cast/net/rtp/rtp_packetizer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| 11 #include "media/cast/net/pacing/paced_sender.h" | 11 #include "media/cast/net/pacing/paced_sender.h" |
| 12 #include "media/cast/net/rtp/packet_storage.h" | 12 #include "media/cast/net/rtp/packet_storage.h" |
| 13 #include "media/cast/net/rtp/rtp_parser.h" | 13 #include "media/cast/net/rtp/rtp_parser.h" |
| 14 #include "media/cast/test/fake_single_thread_task_runner.h" | 14 #include "media/cast/test/fake_single_thread_task_runner.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 namespace cast { | 18 namespace cast { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 static const int kPayload = 127; | 21 static const int kPayload = 127; |
| 22 static const uint32 kTimestampMs = 10; | 22 static const uint32_t kTimestampMs = 10; |
| 23 static const uint16 kSeqNum = 33; | 23 static const uint16_t kSeqNum = 33; |
| 24 static const int kMaxPacketLength = 1500; | 24 static const int kMaxPacketLength = 1500; |
| 25 static const int kSsrc = 0x12345; | 25 static const int kSsrc = 0x12345; |
| 26 static const unsigned int kFrameSize = 5000; | 26 static const unsigned int kFrameSize = 5000; |
| 27 } | 27 } |
| 28 | 28 |
| 29 class TestRtpPacketTransport : public PacketSender { | 29 class TestRtpPacketTransport : public PacketSender { |
| 30 public: | 30 public: |
| 31 explicit TestRtpPacketTransport(RtpPacketizerConfig config) | 31 explicit TestRtpPacketTransport(RtpPacketizerConfig config) |
| 32 : config_(config), | 32 : config_(config), |
| 33 sequence_number_(kSeqNum), | 33 sequence_number_(kSeqNum), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 60 if (rtp_header.packet_id != 0) { | 60 if (rtp_header.packet_id != 0) { |
| 61 EXPECT_EQ(rtp_header.num_extensions, 0) | 61 EXPECT_EQ(rtp_header.num_extensions, 0) |
| 62 << "Extensions only allowed on first packet of a frame"; | 62 << "Extensions only allowed on first packet of a frame"; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool SendPacket(PacketRef packet, const base::Closure& cb) final { | 66 bool SendPacket(PacketRef packet, const base::Closure& cb) final { |
| 67 ++packets_sent_; | 67 ++packets_sent_; |
| 68 RtpParser parser(kSsrc, kPayload); | 68 RtpParser parser(kSsrc, kPayload); |
| 69 RtpCastHeader rtp_header; | 69 RtpCastHeader rtp_header; |
| 70 const uint8* payload_data; | 70 const uint8_t* payload_data; |
| 71 size_t payload_size; | 71 size_t payload_size; |
| 72 parser.ParsePacket(&packet->data[0], packet->data.size(), &rtp_header, | 72 parser.ParsePacket(&packet->data[0], packet->data.size(), &rtp_header, |
| 73 &payload_data, &payload_size); | 73 &payload_data, &payload_size); |
| 74 VerifyRtpHeader(rtp_header); | 74 VerifyRtpHeader(rtp_header); |
| 75 ++sequence_number_; | 75 ++sequence_number_; |
| 76 ++expected_packet_id_; | 76 ++expected_packet_id_; |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 | 79 |
| 80 int64 GetBytesSent() final { return 0; } | 80 int64_t GetBytesSent() final { return 0; } |
| 81 | 81 |
| 82 size_t number_of_packets_received() const { return packets_sent_; } | 82 size_t number_of_packets_received() const { return packets_sent_; } |
| 83 | 83 |
| 84 void set_expected_number_of_packets(size_t expected_number_of_packets) { | 84 void set_expected_number_of_packets(size_t expected_number_of_packets) { |
| 85 expected_number_of_packets_ = expected_number_of_packets; | 85 expected_number_of_packets_ = expected_number_of_packets; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void set_rtp_timestamp(uint32 rtp_timestamp) { | 88 void set_rtp_timestamp(uint32_t rtp_timestamp) { |
| 89 expected_rtp_timestamp_ = rtp_timestamp; | 89 expected_rtp_timestamp_ = rtp_timestamp; |
| 90 } | 90 } |
| 91 | 91 |
| 92 RtpPacketizerConfig config_; | 92 RtpPacketizerConfig config_; |
| 93 uint32 sequence_number_; | 93 uint32_t sequence_number_; |
| 94 size_t packets_sent_; | 94 size_t packets_sent_; |
| 95 size_t number_of_packets_; | 95 size_t number_of_packets_; |
| 96 size_t expected_number_of_packets_; | 96 size_t expected_number_of_packets_; |
| 97 // Assuming packets arrive in sequence. | 97 // Assuming packets arrive in sequence. |
| 98 int expected_packet_id_; | 98 int expected_packet_id_; |
| 99 uint32 expected_frame_id_; | 99 uint32_t expected_frame_id_; |
| 100 uint32 expected_rtp_timestamp_; | 100 uint32_t expected_rtp_timestamp_; |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(TestRtpPacketTransport); | 103 DISALLOW_COPY_AND_ASSIGN(TestRtpPacketTransport); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class RtpPacketizerTest : public ::testing::Test { | 106 class RtpPacketizerTest : public ::testing::Test { |
| 107 protected: | 107 protected: |
| 108 RtpPacketizerTest() | 108 RtpPacketizerTest() |
| 109 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) { | 109 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) { |
| 110 config_.sequence_number = kSeqNum; | 110 config_.sequence_number = kSeqNum; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 video_frame_.reference_time = testing_clock_.NowTicks(); | 183 video_frame_.reference_time = testing_clock_.NowTicks(); |
| 184 rtp_packetizer_->SendFrameAsPackets(video_frame_); | 184 rtp_packetizer_->SendFrameAsPackets(video_frame_); |
| 185 RunTasks(33 + 1); | 185 RunTasks(33 + 1); |
| 186 EXPECT_EQ(expected_num_of_packets, rtp_packetizer_->send_packet_count()); | 186 EXPECT_EQ(expected_num_of_packets, rtp_packetizer_->send_packet_count()); |
| 187 EXPECT_EQ(kFrameSize, rtp_packetizer_->send_octet_count()); | 187 EXPECT_EQ(kFrameSize, rtp_packetizer_->send_octet_count()); |
| 188 EXPECT_EQ(expected_num_of_packets, transport_->number_of_packets_received()); | 188 EXPECT_EQ(expected_num_of_packets, transport_->number_of_packets_received()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace cast | 191 } // namespace cast |
| 192 } // namespace media | 192 } // namespace media |
| OLD | NEW |