diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-08 14:30:41 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-12 13:49:54 +0200 |
commit | ab0a50979b9eb4dfa3320eff7e187e41efedf7a9 (patch) | |
tree | 498dfb8a97ff3361a9f7486863a52bb4e26bb898 /chromium/media/cast/net | |
parent | 4ce69f7403811819800e7c5ae1318b2647e778d1 (diff) |
Update Chromium to beta version 37.0.2062.68
Change-Id: I188e3b5aff1bec75566014291b654eb19f5bc8ca
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'chromium/media/cast/net')
22 files changed, 0 insertions, 1782 deletions
diff --git a/chromium/media/cast/net/cast_net_defines.h b/chromium/media/cast/net/cast_net_defines.h deleted file mode 100644 index a9f1629a91a..00000000000 --- a/chromium/media/cast/net/cast_net_defines.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_NET_CAST_NET_DEFINES_H_ -#define MEDIA_CAST_NET_CAST_NET_DEFINES_H_ - -#include "base/basictypes.h" - -namespace media { -namespace cast { - -class FrameIdWrapHelper { - public: - FrameIdWrapHelper() - : first_(true), - frame_id_wrap_count_(0), - range_(kLowRange) {} - - uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) { - if (first_) { - first_ = false; - if (over_the_wire_frame_id == 0xff) { - // Special case for startup. - return kStartFrameId; - } - } - - uint32 wrap_count = frame_id_wrap_count_; - switch (range_) { - case kLowRange: - if (over_the_wire_frame_id > kLowRangeThreshold && - over_the_wire_frame_id < kHighRangeThreshold) { - range_ = kMiddleRange; - } - if (over_the_wire_frame_id > kHighRangeThreshold) { - // Wrap count was incremented in High->Low transition, but this frame - // is 'old', actually from before the wrap count got incremented. - --wrap_count; - } - break; - case kMiddleRange: - if (over_the_wire_frame_id > kHighRangeThreshold) { - range_ = kHighRange; - } - break; - case kHighRange: - if (over_the_wire_frame_id < kLowRangeThreshold) { - // Wrap-around detected. - range_ = kLowRange; - ++frame_id_wrap_count_; - // Frame triggering wrap-around so wrap count should be incremented as - // as well to match |frame_id_wrap_count_|. - ++wrap_count; - } - break; - } - return (wrap_count << 8) + over_the_wire_frame_id; - } - - private: - enum Range { - kLowRange, - kMiddleRange, - kHighRange, - }; - - static const uint8 kLowRangeThreshold = 0x0f; - static const uint8 kHighRangeThreshold = 0xf0; - static const uint32 kStartFrameId = GG_UINT32_C(0xffffffff); - - bool first_; - uint32 frame_id_wrap_count_; - Range range_; -}; - - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_CAST_NET_DEFINES_H_ diff --git a/chromium/media/cast/net/frame_id_wrap_helper_test.cc b/chromium/media/cast/net/frame_id_wrap_helper_test.cc deleted file mode 100644 index f6b89b01d22..00000000000 --- a/chromium/media/cast/net/frame_id_wrap_helper_test.cc +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <gtest/gtest.h> -#include "media/cast/net/cast_net_defines.h" - -namespace media { -namespace cast { - -class FrameIdWrapHelperTest : public ::testing::Test { - protected: - FrameIdWrapHelperTest() {} - virtual ~FrameIdWrapHelperTest() {} - - FrameIdWrapHelper frame_id_wrap_helper_; -}; - -TEST_F(FrameIdWrapHelperTest, FirstFrame) { - EXPECT_EQ(kStartFrameId, frame_id_wrap_helper_.MapTo32bitsFrameId(255u)); -} - -TEST_F(FrameIdWrapHelperTest, Rollover) { - uint32 new_frame_id = 0u; - for (int i = 0; i <= 256; ++i) { - new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId( - static_cast<uint8>(i)); - } - EXPECT_EQ(256u, new_frame_id); -} - -TEST_F(FrameIdWrapHelperTest, OutOfOrder) { - uint32 new_frame_id = 0u; - for (int i = 0; i < 255; ++i) { - new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId( - static_cast<uint8>(i)); - } - EXPECT_EQ(254u, new_frame_id); - new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(0u); - EXPECT_EQ(256u, new_frame_id); - new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(255u); - EXPECT_EQ(255u, new_frame_id); - new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(1u); - EXPECT_EQ(257u, new_frame_id); -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/pacing/mock_paced_packet_sender.cc b/chromium/media/cast/net/pacing/mock_paced_packet_sender.cc deleted file mode 100644 index 6caf8f6390e..00000000000 --- a/chromium/media/cast/net/pacing/mock_paced_packet_sender.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/pacing/mock_paced_packet_sender.h" - -namespace media { -namespace cast { - -MockPacedPacketSender::MockPacedPacketSender() { -} - -MockPacedPacketSender::~MockPacedPacketSender() { -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/pacing/mock_paced_packet_sender.h b/chromium/media/cast/net/pacing/mock_paced_packet_sender.h deleted file mode 100644 index 9933516f14c..00000000000 --- a/chromium/media/cast/net/pacing/mock_paced_packet_sender.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_NET_PACING_MOCK_PACED_PACKET_SENDER_H_ -#define MEDIA_CAST_NET_PACING_MOCK_PACED_PACKET_SENDER_H_ - -#include "media/cast/net/pacing/paced_sender.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace media { -namespace cast { - -class MockPacedPacketSender : public PacedPacketSender { - public: - MockPacedPacketSender(); - virtual ~MockPacedPacketSender(); - - MOCK_METHOD1(SendPackets, bool(const PacketList& packets)); - MOCK_METHOD1(ResendPackets, bool(const PacketList& packets)); - MOCK_METHOD1(SendRtcpPacket, bool(const Packet& packet)); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_PACING_MOCK_PACED_PACKET_SENDER_H_ diff --git a/chromium/media/cast/net/pacing/paced_sender.cc b/chromium/media/cast/net/pacing/paced_sender.cc deleted file mode 100644 index 8a07380df0d..00000000000 --- a/chromium/media/cast/net/pacing/paced_sender.cc +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/pacing/paced_sender.h" - -#include "base/bind.h" -#include "base/message_loop/message_loop.h" - -namespace media { -namespace cast { - -static const int64 kPacingIntervalMs = 10; -// Each frame will be split into no more than kPacingMaxBurstsPerFrame -// bursts of packets. -static const size_t kPacingMaxBurstsPerFrame = 3; - -PacedSender::PacedSender(scoped_refptr<CastEnvironment> cast_environment, - PacketSender* transport) - : cast_environment_(cast_environment), - burst_size_(1), - packets_sent_in_burst_(0), - transport_(transport), - weak_factory_(this) { - ScheduleNextSend(); -} - -PacedSender::~PacedSender() {} - -bool PacedSender::SendPackets(const PacketList& packets) { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - cast_environment_->Logging()->InsertPacketListEvent(kPacketSentToPacer, - packets); - return SendPacketsToTransport(packets, &packet_list_); -} - -bool PacedSender::ResendPackets(const PacketList& packets) { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - cast_environment_->Logging()->InsertPacketListEvent(kPacketRetransmited, - packets); - return SendPacketsToTransport(packets, &resend_packet_list_); -} - -bool PacedSender::SendPacketsToTransport(const PacketList& packets, - PacketList* packets_not_sent) { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - UpdateBurstSize(packets.size()); - - if (!packets_not_sent->empty()) { - packets_not_sent->insert(packets_not_sent->end(), - packets.begin(), packets.end()); - return true; - } - PacketList packets_to_send; - PacketList::const_iterator first_to_store_it = packets.begin(); - - size_t max_packets_to_send_now = burst_size_ - packets_sent_in_burst_; - if (max_packets_to_send_now > 0) { - size_t packets_to_send_now = std::min(max_packets_to_send_now, - packets.size()); - - std::advance(first_to_store_it, packets_to_send_now); - packets_to_send.insert(packets_to_send.begin(), - packets.begin(), first_to_store_it); - } - packets_not_sent->insert(packets_not_sent->end(), - first_to_store_it, packets.end()); - packets_sent_in_burst_ += packets_to_send.size(); - if (packets_to_send.empty()) return true; - - cast_environment_->Logging()->InsertPacketListEvent(kPacketSentToNetwork, - packets); - return transport_->SendPackets(packets_to_send); -} - -bool PacedSender::SendRtcpPacket(const Packet& packet) { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - // We pass the RTCP packets straight through. - return transport_->SendPacket(packet); -} - -void PacedSender::ScheduleNextSend() { - base::TimeDelta time_to_next = time_last_process_ - - cast_environment_->Clock()->NowTicks() + - base::TimeDelta::FromMilliseconds(kPacingIntervalMs); - - time_to_next = std::max(time_to_next, base::TimeDelta()); - - cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, - base::Bind(&PacedSender::SendNextPacketBurst, weak_factory_.GetWeakPtr()), - time_to_next); -} - -void PacedSender::SendNextPacketBurst() { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - SendStoredPackets(); - time_last_process_ = cast_environment_->Clock()->NowTicks(); - ScheduleNextSend(); -} - -void PacedSender::SendStoredPackets() { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - if (packet_list_.empty() && resend_packet_list_.empty()) return; - - size_t packets_to_send = burst_size_; - PacketList packets_to_resend; - - // Send our re-send packets first. - if (!resend_packet_list_.empty()) { - PacketList::iterator it = resend_packet_list_.begin(); - size_t packets_to_send_now = std::min(packets_to_send, - resend_packet_list_.size()); - std::advance(it, packets_to_send_now); - packets_to_resend.insert(packets_to_resend.begin(), - resend_packet_list_.begin(), it); - resend_packet_list_.erase(resend_packet_list_.begin(), it); - packets_to_send -= packets_to_resend.size(); - } - if (!packet_list_.empty() && packets_to_send > 0) { - PacketList::iterator it = packet_list_.begin(); - size_t packets_to_send_now = std::min(packets_to_send, - packet_list_.size()); - - std::advance(it, packets_to_send_now); - packets_to_resend.insert(packets_to_resend.end(), - packet_list_.begin(), it); - packet_list_.erase(packet_list_.begin(), it); - - if (packet_list_.empty()) { - burst_size_ = 1; // Reset burst size after we sent the last stored packet - packets_sent_in_burst_ = 0; - } - } - transport_->SendPackets(packets_to_resend); -} - -void PacedSender::UpdateBurstSize(size_t packets_to_send) { - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - packets_to_send = std::max(packets_to_send, - resend_packet_list_.size() + packet_list_.size()); - - packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. - burst_size_ = std::max(packets_to_send / kPacingMaxBurstsPerFrame, - burst_size_); -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/pacing/paced_sender.gyp b/chromium/media/cast/net/pacing/paced_sender.gyp deleted file mode 100644 index 1947dd4ec40..00000000000 --- a/chromium/media/cast/net/pacing/paced_sender.gyp +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'cast_paced_sender', - 'type': 'static_library', - 'include_dirs': [ - '<(DEPTH)/', - ], - 'sources': [ - 'paced_sender.h', - 'paced_sender.cc', - ], - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - ], - }, - ], # targets -} diff --git a/chromium/media/cast/net/pacing/paced_sender.h b/chromium/media/cast/net/pacing/paced_sender.h deleted file mode 100644 index 89283257134..00000000000 --- a/chromium/media/cast/net/pacing/paced_sender.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_NET_PACING_PACED_SENDER_H_ -#define MEDIA_CAST_NET_PACING_PACED_SENDER_H_ - -#include <list> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/threading/non_thread_safe.h" -#include "base/time/default_tick_clock.h" -#include "base/time/tick_clock.h" -#include "base/time/time.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_environment.h" - -namespace media { -namespace cast { - -// We have this pure virtual class to enable mocking. -class PacedPacketSender { - public: - // Inform the pacer / sender of the total number of packets. - virtual bool SendPackets(const PacketList& packets) = 0; - - virtual bool ResendPackets(const PacketList& packets) = 0; - - virtual bool SendRtcpPacket(const Packet& packet) = 0; - - virtual ~PacedPacketSender() {} -}; - -class PacedSender : public PacedPacketSender, - public base::NonThreadSafe, - public base::SupportsWeakPtr<PacedSender> { - public: - PacedSender(scoped_refptr<CastEnvironment> cast_environment, - PacketSender* transport); - virtual ~PacedSender(); - - virtual bool SendPackets(const PacketList& packets) OVERRIDE; - - virtual bool ResendPackets(const PacketList& packets) OVERRIDE; - - virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE; - - protected: - // Schedule a delayed task on the main cast thread when it's time to send the - // next packet burst. - void ScheduleNextSend(); - - // Process any pending packets in the queue(s). - void SendNextPacketBurst(); - - private: - bool SendPacketsToTransport(const PacketList& packets, - PacketList* packets_not_sent); - void SendStoredPackets(); - void UpdateBurstSize(size_t num_of_packets); - - scoped_refptr<CastEnvironment> cast_environment_; - size_t burst_size_; - size_t packets_sent_in_burst_; - base::TimeTicks time_last_process_; - // Note: We can't combine the |packet_list_| and the |resend_packet_list_| - // since then we might get reordering of the retransmitted packets. - PacketList packet_list_; - PacketList resend_packet_list_; - PacketSender* transport_; - - base::WeakPtrFactory<PacedSender> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(PacedSender); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ diff --git a/chromium/media/cast/net/pacing/paced_sender_unittest.cc b/chromium/media/cast/net/pacing/paced_sender_unittest.cc deleted file mode 100644 index 15b81362f69..00000000000 --- a/chromium/media/cast/net/pacing/paced_sender_unittest.cc +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/test/simple_test_tick_clock.h" -#include "media/cast/net/pacing/paced_sender.h" -#include "media/cast/test/fake_task_runner.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace media { -namespace cast { - -using testing::_; - -static const uint8 kValue = 123; -static const size_t kSize1 = 100; -static const size_t kSize2 = 101; -static const size_t kSize3 = 102; -static const size_t kSize4 = 103; -static const size_t kNackSize = 104; -static const int64 kStartMillisecond = GG_INT64_C(12345678900000); - -class TestPacketSender : public PacketSender { - public: - virtual bool SendPackets(const PacketList& packets) OVERRIDE { - PacketList::const_iterator it = packets.begin(); - for (; it != packets.end(); ++it) { - EXPECT_FALSE(expected_packet_size_.empty()); - size_t expected_packet_size = expected_packet_size_.front(); - expected_packet_size_.pop_front(); - EXPECT_EQ(expected_packet_size, it->size()); - } - return true; - } - - virtual bool SendPacket(const Packet& packet) OVERRIDE { - return true; - } - - void AddExpectedSize(int expected_packet_size, int repeat_count) { - for (int i = 0; i < repeat_count; ++i) { - expected_packet_size_.push_back(expected_packet_size); - } - } - - private: - std::list<int> expected_packet_size_; -}; - -class PacedSenderTest : public ::testing::Test { - protected: - PacedSenderTest() { - testing_clock_.Advance( - base::TimeDelta::FromMilliseconds(kStartMillisecond)); - } - - virtual ~PacedSenderTest() {} - - virtual void SetUp() { - task_runner_ = new test::FakeTaskRunner(&testing_clock_); - cast_environment_ = new CastEnvironment(&testing_clock_, task_runner_, - task_runner_, task_runner_, task_runner_, task_runner_, - GetDefaultCastLoggingConfig()); - paced_sender_.reset(new PacedSender(cast_environment_, &mock_transport_)); - } - - PacketList CreatePacketList(size_t packet_size, int num_of_packets_in_frame) { - PacketList packets; - for (int i = 0; i < num_of_packets_in_frame; ++i) { - packets.push_back(Packet(packet_size, kValue)); - } - return packets; - } - - base::SimpleTestTickClock testing_clock_; - TestPacketSender mock_transport_; - scoped_refptr<test::FakeTaskRunner> task_runner_; - scoped_ptr<PacedSender> paced_sender_; - scoped_refptr<CastEnvironment> cast_environment_; -}; - -TEST_F(PacedSenderTest, PassThroughRtcp) { - mock_transport_.AddExpectedSize(kSize1, 1); - PacketList packets = CreatePacketList(kSize1, 1); - - EXPECT_TRUE(paced_sender_->SendPackets(packets)); - EXPECT_TRUE(paced_sender_->ResendPackets(packets)); - - mock_transport_.AddExpectedSize(kSize2, 1); - EXPECT_TRUE(paced_sender_->SendRtcpPacket(Packet(kSize2, kValue))); -} - -TEST_F(PacedSenderTest, BasicPace) { - int num_of_packets = 9; - PacketList packets = CreatePacketList(kSize1, num_of_packets); - - mock_transport_.AddExpectedSize(kSize1, 3); - EXPECT_TRUE(paced_sender_->SendPackets(packets)); - - // Check that we get the next burst. - mock_transport_.AddExpectedSize(kSize1, 3); - - base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // If we call process too early make sure we don't send any packets. - timeout = base::TimeDelta::FromMilliseconds(5); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // Check that we get the next burst. - mock_transport_.AddExpectedSize(kSize1, 3); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // Check that we don't get any more packets. - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); -} - -TEST_F(PacedSenderTest, PaceWithNack) { - // Testing what happen when we get multiple NACK requests for a fully lost - // frames just as we sent the first packets in a frame. - int num_of_packets_in_frame = 9; - int num_of_packets_in_nack = 9; - - PacketList first_frame_packets = - CreatePacketList(kSize1, num_of_packets_in_frame); - - PacketList second_frame_packets = - CreatePacketList(kSize2, num_of_packets_in_frame); - - PacketList nack_packets = - CreatePacketList(kNackSize, num_of_packets_in_nack); - - // Check that the first burst of the frame go out on the wire. - mock_transport_.AddExpectedSize(kSize1, 3); - EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets)); - - // Add first NACK request. - EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets)); - - // Check that we get the first NACK burst. - mock_transport_.AddExpectedSize(kNackSize, 5); - base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // Add second NACK request. - EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets)); - - // Check that we get the next NACK burst. - mock_transport_.AddExpectedSize(kNackSize, 7); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // End of NACK plus a packet from the oldest frame. - mock_transport_.AddExpectedSize(kNackSize, 6); - mock_transport_.AddExpectedSize(kSize1, 1); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // Add second frame. - // Make sure we don't delay the second frame due to the previous packets. - EXPECT_TRUE(paced_sender_->SendPackets(second_frame_packets)); - - // Last packets of frame 1 and the first packets of frame 2. - mock_transport_.AddExpectedSize(kSize1, 5); - mock_transport_.AddExpectedSize(kSize2, 2); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // Last packets of frame 2. - mock_transport_.AddExpectedSize(kSize2, 7); - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); - - // No more packets. - testing_clock_.Advance(timeout); - task_runner_->RunTasks(); -} - -TEST_F(PacedSenderTest, PaceWith60fps) { - // Testing what happen when we get multiple NACK requests for a fully lost - // frames just as we sent the first packets in a frame. - int num_of_packets_in_frame = 9; - - PacketList first_frame_packets = - CreatePacketList(kSize1, num_of_packets_in_frame); - - PacketList second_frame_packets = - CreatePacketList(kSize2, num_of_packets_in_frame); - - PacketList third_frame_packets = - CreatePacketList(kSize3, num_of_packets_in_frame); - - PacketList fourth_frame_packets = - CreatePacketList(kSize4, num_of_packets_in_frame); - - base::TimeDelta timeout_10ms = base::TimeDelta::FromMilliseconds(10); - - // Check that the first burst of the frame go out on the wire. - mock_transport_.AddExpectedSize(kSize1, 3); - EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets)); - - mock_transport_.AddExpectedSize(kSize1, 3); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(6)); - - // Add second frame, after 16 ms. - EXPECT_TRUE(paced_sender_->SendPackets(second_frame_packets)); - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(4)); - - mock_transport_.AddExpectedSize(kSize1, 3); - mock_transport_.AddExpectedSize(kSize2, 1); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - mock_transport_.AddExpectedSize(kSize2, 4); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(3)); - - // Add third frame, after 33 ms. - EXPECT_TRUE(paced_sender_->SendPackets(third_frame_packets)); - mock_transport_.AddExpectedSize(kSize2, 4); - mock_transport_.AddExpectedSize(kSize3, 1); - - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(7)); - task_runner_->RunTasks(); - - // Add fourth frame, after 50 ms. - EXPECT_TRUE(paced_sender_->SendPackets(fourth_frame_packets)); - - mock_transport_.AddExpectedSize(kSize3, 6); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - mock_transport_.AddExpectedSize(kSize3, 2); - mock_transport_.AddExpectedSize(kSize4, 4); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - mock_transport_.AddExpectedSize(kSize4, 5); - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); - - testing_clock_.Advance(timeout_10ms); - task_runner_->RunTasks(); -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/mock_rtp_sender.h b/chromium/media/cast/net/rtp_sender/mock_rtp_sender.h deleted file mode 100644 index 2c3f19f2ae9..00000000000 --- a/chromium/media/cast/net/rtp_sender/mock_rtp_sender.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_RTP_SENDER_MOCK_RTP_SENDER_H_ -#define MEDIA_CAST_RTP_SENDER_MOCK_RTP_SENDER_H_ - -#include <vector> - -#include "media/cast/net/rtp_sender/rtp_sender.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace media { -namespace cast { - -class MockRtpSender : public RtpSender { - public: - MOCK_METHOD2(IncomingEncodedVideoFrame, - bool(const EncodedVideoFrame& frame, int64 capture_time)); - - MOCK_METHOD2(IncomingEncodedAudioFrame, - bool(const EncodedAudioFrame& frame, int64 recorded_time)); - - MOCK_METHOD3(ResendPacket, - bool(bool is_audio, uint32 frame_id, uint16 packet_id)); - - MOCK_METHOD0(RtpStatistics, void()); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_RTP_SENDER_MOCK_RTP_SENDER_H_ - diff --git a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.cc b/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.cc deleted file mode 100644 index 3bd8f900665..00000000000 --- a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.cc +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/packet_storage/packet_storage.h" - -#include <string> - -#include "base/logging.h" -#include "media/cast/cast_defines.h" - -namespace media { -namespace cast { - -// Limit the max time delay to avoid frame id wrap around; 256 / 60 fps. -const int kMaxAllowedTimeStoredMs = 4000; - -typedef PacketMap::iterator PacketMapIterator; -typedef TimeToPacketMap::iterator TimeToPacketIterator; - -class StoredPacket { - public: - StoredPacket() { - packet_.reserve(kIpPacketSize); - } - - void Save(const Packet* packet) { - DCHECK_LT(packet->size(), kIpPacketSize) << "Invalid argument"; - packet_.clear(); - packet_.insert(packet_.begin(), packet->begin(), packet->end()); - } - - void GetCopy(PacketList* packets) { - packets->push_back(Packet(packet_.begin(), packet_.end())); - } - - private: - Packet packet_; -}; - -PacketStorage::PacketStorage(base::TickClock* clock, - int max_time_stored_ms) - : clock_(clock) { - max_time_stored_ = base::TimeDelta::FromMilliseconds(max_time_stored_ms); - DCHECK_LE(max_time_stored_ms, kMaxAllowedTimeStoredMs) << "Invalid argument"; -} - -PacketStorage::~PacketStorage() { - time_to_packet_map_.clear(); - - PacketMapIterator store_it = stored_packets_.begin(); - for (; store_it != stored_packets_.end(); - store_it = stored_packets_.begin()) { - stored_packets_.erase(store_it); - } - while (!free_packets_.empty()) { - free_packets_.pop_front(); - } -} - -void PacketStorage::CleanupOldPackets(base::TimeTicks now) { - TimeToPacketIterator time_it = time_to_packet_map_.begin(); - - // Check max size. - while (time_to_packet_map_.size() >= kMaxStoredPackets) { - PacketMapIterator store_it = stored_packets_.find(time_it->second); - - // We should always find the packet. - DCHECK(store_it != stored_packets_.end()) << "Invalid state"; - time_to_packet_map_.erase(time_it); - // Save the pointer. - linked_ptr<StoredPacket> storted_packet = store_it->second; - stored_packets_.erase(store_it); - // Add this packet to the free list for later re-use. - free_packets_.push_back(storted_packet); - time_it = time_to_packet_map_.begin(); - } - - // Time out old packets. - while (time_it != time_to_packet_map_.end()) { - if (now < time_it->first + max_time_stored_) { - break; - } - // Packet too old. - PacketMapIterator store_it = stored_packets_.find(time_it->second); - - // We should always find the packet. - DCHECK(store_it != stored_packets_.end()) << "Invalid state"; - time_to_packet_map_.erase(time_it); - // Save the pointer. - linked_ptr<StoredPacket> storted_packet = store_it->second; - stored_packets_.erase(store_it); - // Add this packet to the free list for later re-use. - free_packets_.push_back(storted_packet); - time_it = time_to_packet_map_.begin(); - } -} - -void PacketStorage::StorePacket(uint32 frame_id, uint16 packet_id, - const Packet* packet) { - base::TimeTicks now = clock_->NowTicks(); - CleanupOldPackets(now); - - // Internally we only use the 8 LSB of the frame id. - uint32 index = ((0xff & frame_id) << 16) + packet_id; - PacketMapIterator it = stored_packets_.find(index); - if (it != stored_packets_.end()) { - // We have already saved this. - DCHECK(false) << "Invalid state"; - return; - } - linked_ptr<StoredPacket> stored_packet; - if (free_packets_.empty()) { - // No previous allocated packets allocate one. - stored_packet.reset(new StoredPacket()); - } else { - // Re-use previous allocated packet. - stored_packet = free_packets_.front(); - free_packets_.pop_front(); - } - stored_packet->Save(packet); - stored_packets_[index] = stored_packet; - time_to_packet_map_.insert(std::make_pair(now, index)); -} - -PacketList PacketStorage::GetPackets( - const MissingFramesAndPacketsMap& missing_frames_and_packets) { - PacketList packets_to_resend; - - // Iterate over all frames in the list. - for (MissingFramesAndPacketsMap::const_iterator it = - missing_frames_and_packets.begin(); - it != missing_frames_and_packets.end(); ++it) { - uint8 frame_id = it->first; - const PacketIdSet& packets_set = it->second; - bool success = false; - - if (packets_set.empty()) { - VLOG(1) << "Missing all packets in frame " << static_cast<int>(frame_id); - - uint16 packet_id = 0; - do { - // Get packet from storage. - success = GetPacket(frame_id, packet_id, &packets_to_resend); - ++packet_id; - } while (success); - } else { - // Iterate over all of the packets in the frame. - for (PacketIdSet::const_iterator set_it = packets_set.begin(); - set_it != packets_set.end(); ++set_it) { - GetPacket(frame_id, *set_it, &packets_to_resend); - } - } - } - return packets_to_resend; -} - -bool PacketStorage::GetPacket(uint8 frame_id, - uint16 packet_id, - PacketList* packets) { - // Internally we only use the 8 LSB of the frame id. - uint32 index = (static_cast<uint32>(frame_id) << 16) + packet_id; - PacketMapIterator it = stored_packets_.find(index); - if (it == stored_packets_.end()) { - return false; - } - it->second->GetCopy(packets); - VLOG(1) << "Resend " << static_cast<int>(frame_id) - << ":" << packet_id; - return true; -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.gyp b/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.gyp deleted file mode 100644 index f691d9e9b69..00000000000 --- a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.gyp +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'packet_storage', - 'type': 'static_library', - 'include_dirs': [ - '<(DEPTH)/', - ], - 'sources': [ - 'packet_storage.h', - 'packet_storage.cc', - ], # source - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - ], - }, - ], -} - diff --git a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.h b/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.h deleted file mode 100644 index 34933ef5f6d..00000000000 --- a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_ -#define MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_ - -#include <list> -#include <map> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/linked_ptr.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/tick_clock.h" -#include "base/time/time.h" -#include "media/cast/cast_config.h" - -namespace media { -namespace cast { - -class StoredPacket; -typedef std::map<uint32, linked_ptr<StoredPacket> > PacketMap; -typedef std::multimap<base::TimeTicks, uint32> TimeToPacketMap; - -class PacketStorage { - public: - static const int kMaxStoredPackets = 1000; - - PacketStorage(base::TickClock* clock, int max_time_stored_ms); - virtual ~PacketStorage(); - - void StorePacket(uint32 frame_id, uint16 packet_id, const Packet* packet); - - // Copies all missing packets into the packet list. - PacketList GetPackets( - const MissingFramesAndPacketsMap& missing_frames_and_packets); - - // Copies packet into the packet list. - bool GetPacket(uint8 frame_id, uint16 packet_id, PacketList* packets); - - private: - void CleanupOldPackets(base::TimeTicks now); - - base::TickClock* const clock_; // Not owned by this class. - base::TimeDelta max_time_stored_; - PacketMap stored_packets_; - TimeToPacketMap time_to_packet_map_; - std::list<linked_ptr<StoredPacket> > free_packets_; -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_ diff --git a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage_unittest.cc b/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage_unittest.cc deleted file mode 100644 index 049d3ae29b6..00000000000 --- a/chromium/media/cast/net/rtp_sender/packet_storage/packet_storage_unittest.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/packet_storage/packet_storage.h" - -#include <vector> - -#include "base/test/simple_test_tick_clock.h" -#include "base/time/time.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace media { -namespace cast { - -static const int kMaxDeltaStoredMs = 500; -static const base::TimeDelta kDeltaBetweenFrames = - base::TimeDelta::FromMilliseconds(33); - -static const int64 kStartMillisecond = GG_INT64_C(12345678900000); - -class PacketStorageTest : public ::testing::Test { - protected: - PacketStorageTest() : packet_storage_(&testing_clock_, kMaxDeltaStoredMs) { - testing_clock_.Advance( - base::TimeDelta::FromMilliseconds(kStartMillisecond)); - } - - base::SimpleTestTickClock testing_clock_; - PacketStorage packet_storage_; -}; - -TEST_F(PacketStorageTest, TimeOut) { - Packet test_123(100, 123); // 100 insertions of the value 123. - PacketList packets; - for (uint32 frame_id = 0; frame_id < 30; ++frame_id) { - for (uint16 packet_id = 0; packet_id < 10; ++packet_id) { - packet_storage_.StorePacket(frame_id, packet_id, &test_123); - } - testing_clock_.Advance(kDeltaBetweenFrames); - } - - // All packets belonging to the first 14 frames is expected to be expired. - for (uint32 frame_id = 0; frame_id < 14; ++frame_id) { - for (uint16 packet_id = 0; packet_id < 10; ++packet_id) { - Packet packet; - EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets)); - } - } - // All packets belonging to the next 15 frames is expected to be valid. - for (uint32 frame_id = 14; frame_id < 30; ++frame_id) { - for (uint16 packet_id = 0; packet_id < 10; ++packet_id) { - EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets)); - EXPECT_TRUE(packets.front() == test_123); - } - } -} - -TEST_F(PacketStorageTest, MaxNumberOfPackets) { - Packet test_123(100, 123); // 100 insertions of the value 123. - PacketList packets; - - uint32 frame_id = 0; - for (uint16 packet_id = 0; packet_id <= PacketStorage::kMaxStoredPackets; - ++packet_id) { - packet_storage_.StorePacket(frame_id, packet_id, &test_123); - } - Packet packet; - uint16 packet_id = 0; - EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets)); - - ++packet_id; - for (; packet_id <= PacketStorage::kMaxStoredPackets; ++packet_id) { - EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets)); - EXPECT_TRUE(packets.back() == test_123); - } -} - -TEST_F(PacketStorageTest, PacketContent) { - Packet test_123(100, 123); // 100 insertions of the value 123. - Packet test_234(200, 234); // 200 insertions of the value 234. - PacketList packets; - - for (uint32 frame_id = 0; frame_id < 10; ++frame_id) { - for (uint16 packet_id = 0; packet_id < 10; ++packet_id) { - // Every other packet. - if (packet_id % 2 == 0) { - packet_storage_.StorePacket(frame_id, packet_id, &test_123); - } else { - packet_storage_.StorePacket(frame_id, packet_id, &test_234); - } - } - testing_clock_.Advance(kDeltaBetweenFrames); - } - for (uint32 frame_id = 0; frame_id < 10; ++frame_id) { - for (uint16 packet_id = 0; packet_id < 10; ++packet_id) { - EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets)); - // Every other packet. - if (packet_id % 2 == 0) { - EXPECT_TRUE(packets.back() == test_123); - } else { - EXPECT_TRUE(packets.back() == test_234); - } - } - } -} - -} // namespace cast -} // namespace media - diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.cc b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.cc deleted file mode 100644 index 8a50f8a8aad..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.cc +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h" - -#include "base/logging.h" -#include "media/cast/cast_defines.h" -#include "media/cast/net/pacing/paced_sender.h" -#include "net/base/big_endian.h" - -namespace media { -namespace cast { - -static const uint16 kCommonRtpHeaderLength = 12; -static const uint16 kCastRtpHeaderLength = 7; -static const uint8 kCastKeyFrameBitMask = 0x80; -static const uint8 kCastReferenceFrameIdBitMask = 0x40; - -RtpPacketizer::RtpPacketizer(PacedPacketSender* transport, - PacketStorage* packet_storage, - RtpPacketizerConfig rtp_packetizer_config) - : config_(rtp_packetizer_config), - transport_(transport), - packet_storage_(packet_storage), - sequence_number_(config_.sequence_number), - rtp_timestamp_(config_.rtp_timestamp), - packet_id_(0), - send_packets_count_(0), - send_octet_count_(0) { - DCHECK(transport) << "Invalid argument"; -} - -RtpPacketizer::~RtpPacketizer() {} - -void RtpPacketizer::IncomingEncodedVideoFrame( - const EncodedVideoFrame* video_frame, - const base::TimeTicks& capture_time) { - DCHECK(!config_.audio) << "Invalid state"; - if (config_.audio) return; - - // Timestamp is in 90 KHz for video. - rtp_timestamp_ = GetVideoRtpTimestamp(capture_time); - time_last_sent_rtp_timestamp_ = capture_time; - - Cast(video_frame->key_frame, - video_frame->frame_id, - video_frame->last_referenced_frame_id, - rtp_timestamp_, - video_frame->data); -} - -void RtpPacketizer::IncomingEncodedAudioFrame( - const EncodedAudioFrame* audio_frame, - const base::TimeTicks& recorded_time) { - DCHECK(config_.audio) << "Invalid state"; - if (!config_.audio) return; - - rtp_timestamp_ += audio_frame->samples; // Timestamp is in samples for audio. - time_last_sent_rtp_timestamp_ = recorded_time; - Cast(true, audio_frame->frame_id, 0, rtp_timestamp_, audio_frame->data); -} - -uint16 RtpPacketizer::NextSequenceNumber() { - ++sequence_number_; - return sequence_number_ - 1; -} - -bool RtpPacketizer::LastSentTimestamp(base::TimeTicks* time_sent, - uint32* rtp_timestamp) const { - if (time_last_sent_rtp_timestamp_.is_null()) return false; - - *time_sent = time_last_sent_rtp_timestamp_; - *rtp_timestamp = rtp_timestamp_; - return true; -} - -// TODO(mikhal): Switch to pass data with a const_ref. -void RtpPacketizer::Cast(bool is_key, - uint32 frame_id, - uint32 reference_frame_id, - uint32 timestamp, - const std::string& data) { - uint16 rtp_header_length = kCommonRtpHeaderLength + kCastRtpHeaderLength; - uint16 max_length = config_.max_payload_length - rtp_header_length - 1; - - // Split the payload evenly (round number up). - size_t num_packets = (data.size() + max_length) / max_length; - size_t payload_length = (data.size() + num_packets) / num_packets; - DCHECK_LE(payload_length, max_length) << "Invalid argument"; - - PacketList packets; - - size_t remaining_size = data.size(); - std::string::const_iterator data_iter = data.begin(); - while (remaining_size > 0) { - Packet packet; - - if (remaining_size < payload_length) { - payload_length = remaining_size; - } - remaining_size -= payload_length; - BuildCommonRTPheader(&packet, remaining_size == 0, timestamp); - - // Build Cast header. - packet.push_back( - (is_key ? kCastKeyFrameBitMask : 0) | kCastReferenceFrameIdBitMask); - packet.push_back(frame_id); - size_t start_size = packet.size(); - packet.resize(start_size + 4); - net::BigEndianWriter big_endian_writer(&(packet[start_size]), 4); - big_endian_writer.WriteU16(packet_id_); - big_endian_writer.WriteU16(static_cast<uint16>(num_packets - 1)); - packet.push_back(static_cast<uint8>(reference_frame_id)); - - // Copy payload data. - packet.insert(packet.end(), data_iter, data_iter + payload_length); - - // Store packet. - packet_storage_->StorePacket(frame_id, packet_id_, &packet); - ++packet_id_; - data_iter += payload_length; - - // Update stats. - ++send_packets_count_; - send_octet_count_ += payload_length; - packets.push_back(packet); - } - DCHECK(packet_id_ == num_packets) << "Invalid state"; - - // Send to network. - transport_->SendPackets(packets); - - // Prepare for next frame. - packet_id_ = 0; -} - -void RtpPacketizer::BuildCommonRTPheader( - Packet* packet, bool marker_bit, uint32 time_stamp) { - packet->push_back(0x80); - packet->push_back(static_cast<uint8>(config_.payload_type) | - (marker_bit ? kRtpMarkerBitMask : 0)); - size_t start_size = packet->size(); - packet->resize(start_size + 10); - net::BigEndianWriter big_endian_writer(&((*packet)[start_size]), 10); - big_endian_writer.WriteU16(sequence_number_); - big_endian_writer.WriteU32(time_stamp); - big_endian_writer.WriteU32(config_.ssrc); - ++sequence_number_; -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.gyp b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.gyp deleted file mode 100644 index d75d8a66911..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.gyp +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'cast_rtp_packetizer', - 'type': 'static_library', - 'include_dirs': [ - '<(DEPTH)/', - '<(DEPTH)/third_party/', - '<(DEPTH)/third_party/webrtc/', - ], - 'sources': [ - 'rtp_packetizer.cc', - 'rtp_packetizer.h', - 'rtp_packetizer_config.cc', - 'rtp_packetizer_config.h', - ], # source - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - '<(DEPTH)/net/net.gyp:net', - ], - }, - ], -} diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h deleted file mode 100644 index 9f9be5fe163..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_H_ -#define MEDIA_CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_H_ - -#include <cmath> -#include <list> -#include <map> - -#include "base/time/time.h" -#include "media/cast/net/rtp_sender/packet_storage/packet_storage.h" -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h" - -namespace media { -namespace cast { - -class PacedPacketSender; - -// This object is only called from the main cast thread. -// This class break encoded audio and video frames into packets and add an RTP -// header to each packet. -class RtpPacketizer { - public: - RtpPacketizer(PacedPacketSender* transport, - PacketStorage* packet_storage, - RtpPacketizerConfig rtp_packetizer_config); - ~RtpPacketizer(); - - // The video_frame objects ownership is handled by the main cast thread. - void IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, - const base::TimeTicks& capture_time); - - // The audio_frame objects ownership is handled by the main cast thread. - void IncomingEncodedAudioFrame(const EncodedAudioFrame* audio_frame, - const base::TimeTicks& recorded_time); - - bool LastSentTimestamp(base::TimeTicks* time_sent, - uint32* rtp_timestamp) const; - - // Return the next sequence number, and increment by one. Enables unique - // incremental sequence numbers for every packet (including retransmissions). - uint16 NextSequenceNumber(); - - int send_packets_count() { return send_packets_count_; } - - size_t send_octet_count() { return send_octet_count_; } - - private: - void Cast(bool is_key, uint32 frame_id, uint32 reference_frame_id, - uint32 timestamp, const std::string& data); - - void BuildCommonRTPheader(std::vector<uint8>* packet, bool marker_bit, - uint32 time_stamp); - - RtpPacketizerConfig config_; - PacedPacketSender* transport_; - PacketStorage* packet_storage_; - - base::TimeTicks time_last_sent_rtp_timestamp_; - uint16 sequence_number_; - uint32 rtp_timestamp_; - uint16 packet_id_; - - int send_packets_count_; - size_t send_octet_count_; -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_H_ diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.cc b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.cc deleted file mode 100644 index 5fe3a92b61b..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h" - -namespace media { -namespace cast { - -RtpPacketizerConfig::RtpPacketizerConfig() - : ssrc(0), - max_payload_length(kIpPacketSize - 28), // Default is IP-v4/UDP. - audio(false), - frequency(8000), - payload_type(-1), - sequence_number(0), - rtp_timestamp(0) { -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h deleted file mode 100644 index 1a2549e66b2..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_CONFIG_H_ -#define CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_CONFIG_H_ - -#include "media/cast/cast_config.h" -#include "media/cast/rtp_receiver/rtp_receiver_defines.h" - -namespace media { -namespace cast { - -struct RtpPacketizerConfig { - RtpPacketizerConfig(); - - // General. - bool audio; - int payload_type; - uint16 max_payload_length; - uint16 sequence_number; - uint32 rtp_timestamp; - int frequency; - - // SSRC. - unsigned int ssrc; - - // Video. - VideoCodec video_codec; - - // Audio. - uint8 channels; - AudioCodec audio_codec; -}; - -} // namespace cast -} // namespace media - -#endif // CAST_NET_RTP_SENDER_RTP_PACKETIZER_RTP_PACKETIZER_CONFIG_H_ diff --git a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_unittest.cc b/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_unittest.cc deleted file mode 100644 index defdecf7584..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_unittest.cc +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h" - -#include "base/memory/scoped_ptr.h" -#include "base/test/simple_test_tick_clock.h" -#include "media/cast/cast_config.h" -#include "media/cast/net/pacing/paced_sender.h" -#include "media/cast/net/rtp_sender/packet_storage/packet_storage.h" -#include "media/cast/net/rtp_sender/rtp_packetizer/test/rtp_header_parser.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace media { -namespace cast { - -static const int kPayload = 127; -static const uint32 kTimestampMs = 10; -static const uint16 kSeqNum = 33; -static const int kMaxPacketLength = 1500; -static const int kSsrc = 0x12345; -static const unsigned int kFrameSize = 5000; -static const int kMaxPacketStorageTimeMs = 300; - -class TestRtpPacketTransport : public PacedPacketSender { - public: - explicit TestRtpPacketTransport(RtpPacketizerConfig config) - : config_(config), - sequence_number_(kSeqNum), - packets_sent_(0), - expected_number_of_packets_(0), - expected_packet_id_(0), - expected_frame_id_(0) {} - - void VerifyRtpHeader(const RtpCastTestHeader& rtp_header) { - VerifyCommonRtpHeader(rtp_header); - VerifyCastRtpHeader(rtp_header); - } - - void VerifyCommonRtpHeader(const RtpCastTestHeader& rtp_header) { - EXPECT_EQ(expected_number_of_packets_ == packets_sent_, - rtp_header.marker); - EXPECT_EQ(kPayload, rtp_header.payload_type); - EXPECT_EQ(sequence_number_, rtp_header.sequence_number); - EXPECT_EQ(kTimestampMs * 90, rtp_header.rtp_timestamp); - EXPECT_EQ(config_.ssrc, rtp_header.ssrc); - EXPECT_EQ(0, rtp_header.num_csrcs); - } - - void VerifyCastRtpHeader(const RtpCastTestHeader& rtp_header) { - EXPECT_FALSE(rtp_header.is_key_frame); - EXPECT_EQ(expected_frame_id_, rtp_header.frame_id); - EXPECT_EQ(expected_packet_id_, rtp_header.packet_id); - EXPECT_EQ(expected_number_of_packets_ - 1, rtp_header.max_packet_id); - EXPECT_TRUE(rtp_header.is_reference); - EXPECT_EQ(expected_frame_id_ - 1u, rtp_header.reference_frame_id); - } - - virtual bool SendPackets(const PacketList& packets) OVERRIDE { - EXPECT_EQ(expected_number_of_packets_, static_cast<int>(packets.size())); - PacketList::const_iterator it = packets.begin(); - for (; it != packets.end(); ++it) { - ++packets_sent_; - RtpHeaderParser parser(it->data(), it->size()); - RtpCastTestHeader rtp_header; - parser.Parse(&rtp_header); - VerifyRtpHeader(rtp_header); - ++sequence_number_; - ++expected_packet_id_; - } - return true; - } - - virtual bool ResendPackets(const PacketList& packets) OVERRIDE { - EXPECT_TRUE(false); - return false; - } - - virtual bool SendRtcpPacket(const std::vector<uint8>& packet) OVERRIDE { - EXPECT_TRUE(false); - return false; - } - - void SetExpectedNumberOfPackets(int num) { - expected_number_of_packets_ = num; - } - - RtpPacketizerConfig config_; - uint32 sequence_number_; - int packets_sent_; - int expected_number_of_packets_; - // Assuming packets arrive in sequence. - int expected_packet_id_; - uint32 expected_frame_id_; -}; - -class RtpPacketizerTest : public ::testing::Test { - protected: - RtpPacketizerTest() - :video_frame_(), - packet_storage_(&testing_clock_, kMaxPacketStorageTimeMs) { - config_.sequence_number = kSeqNum; - config_.ssrc = kSsrc; - config_.payload_type = kPayload; - config_.max_payload_length = kMaxPacketLength; - transport_.reset(new TestRtpPacketTransport(config_)); - rtp_packetizer_.reset( - new RtpPacketizer(transport_.get(), &packet_storage_, config_)); - } - - virtual ~RtpPacketizerTest() {} - - virtual void SetUp() { - video_frame_.key_frame = false; - video_frame_.frame_id = 0; - video_frame_.last_referenced_frame_id = kStartFrameId; - video_frame_.data.assign(kFrameSize, 123); - } - - base::SimpleTestTickClock testing_clock_; - scoped_ptr<RtpPacketizer> rtp_packetizer_; - RtpPacketizerConfig config_; - scoped_ptr<TestRtpPacketTransport> transport_; - EncodedVideoFrame video_frame_; - PacketStorage packet_storage_; -}; - -TEST_F(RtpPacketizerTest, SendStandardPackets) { - int expected_num_of_packets = kFrameSize / kMaxPacketLength + 1; - transport_->SetExpectedNumberOfPackets(expected_num_of_packets); - - base::TimeTicks time; - time += base::TimeDelta::FromMilliseconds(kTimestampMs); - rtp_packetizer_->IncomingEncodedVideoFrame(&video_frame_, time); -} - -TEST_F(RtpPacketizerTest, Stats) { - EXPECT_FALSE(rtp_packetizer_->send_packets_count()); - EXPECT_FALSE(rtp_packetizer_->send_octet_count()); - // Insert packets at varying lengths. - int expected_num_of_packets = kFrameSize / kMaxPacketLength + 1; - transport_->SetExpectedNumberOfPackets(expected_num_of_packets); - - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kTimestampMs)); - rtp_packetizer_->IncomingEncodedVideoFrame(&video_frame_, - testing_clock_.NowTicks()); - EXPECT_EQ(expected_num_of_packets, rtp_packetizer_->send_packets_count()); - EXPECT_EQ(kFrameSize, rtp_packetizer_->send_octet_count()); -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/rtp_sender.cc b/chromium/media/cast/net/rtp_sender/rtp_sender.cc deleted file mode 100644 index 2b017bc1784..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_sender.cc +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/net/rtp_sender/rtp_sender.h" - -#include "base/logging.h" -#include "base/rand_util.h" -#include "media/cast/cast_defines.h" -#include "media/cast/net/pacing/paced_sender.h" -#include "media/cast/rtcp/rtcp_defines.h" -#include "net/base/big_endian.h" - -namespace media { -namespace cast { - -RtpSender::RtpSender(scoped_refptr<CastEnvironment> cast_environment, - const AudioSenderConfig* audio_config, - const VideoSenderConfig* video_config, - PacedPacketSender* transport) - : cast_environment_(cast_environment), - config_(), - transport_(transport) { - // Store generic cast config and create packetizer config. - DCHECK(audio_config || video_config) << "Invalid argument"; - if (audio_config) { - storage_.reset(new PacketStorage(cast_environment->Clock(), - audio_config->rtp_history_ms)); - config_.audio = true; - config_.ssrc = audio_config->sender_ssrc; - config_.payload_type = audio_config->rtp_payload_type; - config_.frequency = audio_config->frequency; - config_.audio_codec = audio_config->codec; - } else { - storage_.reset(new PacketStorage(cast_environment->Clock(), - video_config->rtp_history_ms)); - config_.audio = false; - config_.ssrc = video_config->sender_ssrc; - config_.payload_type = video_config->rtp_payload_type; - config_.frequency = kVideoFrequency; - config_.video_codec = video_config->codec; - } - // Randomly set start values. - config_.sequence_number = base::RandInt(0, 65535); - config_.rtp_timestamp = base::RandInt(0, 65535); - config_.rtp_timestamp += base::RandInt(0, 65535) << 16; - packetizer_.reset(new RtpPacketizer(transport, storage_.get(), config_)); -} - -RtpSender::~RtpSender() {} - -void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, - const base::TimeTicks& capture_time) { - packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); -} - -void RtpSender::IncomingEncodedAudioFrame(const EncodedAudioFrame* audio_frame, - const base::TimeTicks& recorded_time) { - packetizer_->IncomingEncodedAudioFrame(audio_frame, recorded_time); -} - -void RtpSender::ResendPackets( - const MissingFramesAndPacketsMap& missing_frames_and_packets) { - // Iterate over all frames in the list. - for (MissingFramesAndPacketsMap::const_iterator it = - missing_frames_and_packets.begin(); - it != missing_frames_and_packets.end(); ++it) { - PacketList packets_to_resend; - uint8 frame_id = it->first; - const PacketIdSet& packets_set = it->second; - bool success = false; - - if (packets_set.empty()) { - VLOG(1) << "Missing all packets in frame " << static_cast<int>(frame_id); - - uint16 packet_id = 0; - do { - // Get packet from storage. - success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); - - // Resend packet to the network. - if (success) { - VLOG(1) << "Resend " << static_cast<int>(frame_id) - << ":" << packet_id; - // Set a unique incremental sequence number for every packet. - Packet& packet = packets_to_resend.back(); - UpdateSequenceNumber(&packet); - // Set the size as correspond to each frame. - ++packet_id; - } - } while (success); - } else { - // Iterate over all of the packets in the frame. - for (PacketIdSet::const_iterator set_it = packets_set.begin(); - set_it != packets_set.end(); ++set_it) { - uint16 packet_id = *set_it; - success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); - - // Resend packet to the network. - if (success) { - VLOG(1) << "Resend " << static_cast<int>(frame_id) - << ":" << packet_id; - Packet& packet = packets_to_resend.back(); - UpdateSequenceNumber(&packet); - } - } - } - transport_->ResendPackets(packets_to_resend); - } -} - -void RtpSender::UpdateSequenceNumber(Packet* packet) { - uint16 new_sequence_number = packetizer_->NextSequenceNumber(); - int index = 2; - (*packet)[index] = (static_cast<uint8>(new_sequence_number)); - (*packet)[index + 1] =(static_cast<uint8>(new_sequence_number >> 8)); -} - -void RtpSender::RtpStatistics(const base::TimeTicks& now, - RtcpSenderInfo* sender_info) { - // The timestamp of this Rtcp packet should be estimated as the timestamp of - // the frame being captured at this moment. We are calculating that - // timestamp as the last frame's timestamp + the time since the last frame - // was captured. - uint32 ntp_seconds = 0; - uint32 ntp_fraction = 0; - ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); - sender_info->ntp_seconds = ntp_seconds; - sender_info->ntp_fraction = ntp_fraction; - - base::TimeTicks time_sent; - uint32 rtp_timestamp; - if (packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp)) { - base::TimeDelta time_since_last_send = now - time_sent; - sender_info->rtp_timestamp = rtp_timestamp + - time_since_last_send.InMilliseconds() * (config_.frequency / 1000); - } else { - sender_info->rtp_timestamp = 0; - } - sender_info->send_packet_count = packetizer_->send_packets_count(); - sender_info->send_octet_count = packetizer_->send_octet_count(); -} - -} // namespace cast -} // namespace media diff --git a/chromium/media/cast/net/rtp_sender/rtp_sender.gyp b/chromium/media/cast/net/rtp_sender/rtp_sender.gyp deleted file mode 100644 index f689b99b149..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_sender.gyp +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'cast_rtp_sender', - 'type': 'static_library', - 'include_dirs': [ - '<(DEPTH)/', - '<(DEPTH)/third_party/', - '<(DEPTH)/third_party/webrtc/', - ], - 'sources': [ - 'rtp_sender.cc', - 'rtp_sender.h', - ], # source - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - 'packet_storage/packet_storage.gyp:*', - 'rtp_packetizer/rtp_packetizer.gyp:*', - ], - }, - ], -} diff --git a/chromium/media/cast/net/rtp_sender/rtp_sender.h b/chromium/media/cast/net/rtp_sender/rtp_sender.h deleted file mode 100644 index 038165992db..00000000000 --- a/chromium/media/cast/net/rtp_sender/rtp_sender.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file contains the interface to the cast RTP sender. - -#ifndef MEDIA_CAST_NET_RTP_SENDER_RTP_SENDER_H_ -#define MEDIA_CAST_NET_RTP_SENDER_RTP_SENDER_H_ - -#include <map> -#include <set> - -#include "base/memory/scoped_ptr.h" -#include "base/time/tick_clock.h" -#include "base/time/time.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_environment.h" -#include "media/cast/net/rtp_sender/packet_storage/packet_storage.h" -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer.h" -#include "media/cast/net/rtp_sender/rtp_packetizer/rtp_packetizer_config.h" - -namespace media { -namespace cast { - -class PacedPacketSender; -struct RtcpSenderInfo; - -// This object is only called from the main cast thread. -// This class handles splitting encoded audio and video frames into packets and -// add an RTP header to each packet. The sent packets are stored until they are -// acknowledged by the remote peer or timed out. -class RtpSender { - public: - RtpSender(scoped_refptr<CastEnvironment> cast_environment, - const AudioSenderConfig* audio_config, - const VideoSenderConfig* video_config, - PacedPacketSender* transport); - - ~RtpSender(); - - // The video_frame objects ownership is handled by the main cast thread. - void IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, - const base::TimeTicks& capture_time); - - // The audio_frame objects ownership is handled by the main cast thread. - void IncomingEncodedAudioFrame(const EncodedAudioFrame* audio_frame, - const base::TimeTicks& recorded_time); - - void ResendPackets(const MissingFramesAndPacketsMap& missing_packets); - - void RtpStatistics(const base::TimeTicks& now, RtcpSenderInfo* sender_info); - - private: - void UpdateSequenceNumber(std::vector<uint8>* packet); - - scoped_refptr<CastEnvironment> cast_environment_; - RtpPacketizerConfig config_; - scoped_ptr<RtpPacketizer> packetizer_; - scoped_ptr<PacketStorage> storage_; - PacedPacketSender* transport_; -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_NET_RTP_SENDER_RTP_SENDER_H_ |