diff options
author | hubbe <hubbe@chromium.org> | 2014-12-10 17:05:57 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-11 01:06:23 +0000 |
commit | 8029778b0e060e4a22c59fa40ca95e12c437c1f7 (patch) | |
tree | 1ee59bf03b03d4c0e803a1b79026a4d90d51bf6c /media/cast/receiver | |
parent | c571107b9edb9d666d7bcfa7d371ba366b4a4afb (diff) | |
download | chromium_src-8029778b0e060e4a22c59fa40ca95e12c437c1f7.zip chromium_src-8029778b0e060e4a22c59fa40ca95e12c437c1f7.tar.gz chromium_src-8029778b0e060e4a22c59fa40ca95e12c437c1f7.tar.bz2 |
Cast: Make receiver use cast_transport
Also, fix rtcp_builder to not be responsible for logging event redundancy.
Instead, we make the rtcp_event_subscriber do that.
Review URL: https://codereview.chromium.org/765643006
Cr-Commit-Position: refs/heads/master@{#307814}
Diffstat (limited to 'media/cast/receiver')
-rw-r--r-- | media/cast/receiver/cast_receiver_impl.cc | 28 | ||||
-rw-r--r-- | media/cast/receiver/cast_receiver_impl.h | 9 | ||||
-rw-r--r-- | media/cast/receiver/frame_receiver.cc | 37 | ||||
-rw-r--r-- | media/cast/receiver/frame_receiver.h | 9 | ||||
-rw-r--r-- | media/cast/receiver/frame_receiver_unittest.cc | 17 |
5 files changed, 43 insertions, 57 deletions
diff --git a/media/cast/receiver/cast_receiver_impl.cc b/media/cast/receiver/cast_receiver_impl.cc index 8265211..32b2c8c 100644 --- a/media/cast/receiver/cast_receiver_impl.cc +++ b/media/cast/receiver/cast_receiver_impl.cc @@ -20,25 +20,19 @@ scoped_ptr<CastReceiver> CastReceiver::Create( scoped_refptr<CastEnvironment> cast_environment, const FrameReceiverConfig& audio_config, const FrameReceiverConfig& video_config, - PacketSender* const packet_sender) { + CastTransportSender* const transport) { return scoped_ptr<CastReceiver>(new CastReceiverImpl( - cast_environment, audio_config, video_config, packet_sender)); + cast_environment, audio_config, video_config, transport)); } CastReceiverImpl::CastReceiverImpl( scoped_refptr<CastEnvironment> cast_environment, const FrameReceiverConfig& audio_config, const FrameReceiverConfig& video_config, - PacketSender* const packet_sender) + CastTransportSender* const transport) : cast_environment_(cast_environment), - pacer_(kTargetBurstSize, - kMaxBurstSize, - cast_environment->Clock(), - cast_environment->Logging(), - packet_sender, - cast_environment->GetTaskRunner(CastEnvironment::MAIN)), - audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, &pacer_), - video_receiver_(cast_environment, video_config, VIDEO_EVENT, &pacer_), + audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, transport), + video_receiver_(cast_environment, video_config, VIDEO_EVENT, transport), ssrc_of_audio_sender_(audio_config.incoming_ssrc), ssrc_of_video_sender_(video_config.incoming_ssrc), num_audio_channels_(audio_config.channels), @@ -48,14 +42,14 @@ CastReceiverImpl::CastReceiverImpl( CastReceiverImpl::~CastReceiverImpl() {} -void CastReceiverImpl::DispatchReceivedPacket(scoped_ptr<Packet> packet) { +void CastReceiverImpl::ReceivePacket(scoped_ptr<Packet> packet) { const uint8_t* const data = &packet->front(); const size_t length = packet->size(); uint32 ssrc_of_sender; if (Rtcp::IsRtcpPacket(data, length)) { ssrc_of_sender = Rtcp::GetSsrcOfSender(data, length); - } else if (!FrameReceiver::ParseSenderSsrc(data, length, &ssrc_of_sender)) { + } else if (!RtpParser::ParseSsrc(data, length, &ssrc_of_sender)) { VLOG(1) << "Invalid RTP packet."; return; } @@ -78,14 +72,6 @@ void CastReceiverImpl::DispatchReceivedPacket(scoped_ptr<Packet> packet) { base::Passed(&packet))); } -PacketReceiverCallback CastReceiverImpl::packet_receiver() { - return base::Bind(&CastReceiverImpl::DispatchReceivedPacket, - // TODO(miu): This code structure is dangerous, since the - // callback could be stored and then invoked after - // destruction of |this|. - base::Unretained(this)); -} - void CastReceiverImpl::RequestDecodedAudioFrame( const AudioFrameDecodedCallback& callback) { DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); diff --git a/media/cast/receiver/cast_receiver_impl.h b/media/cast/receiver/cast_receiver_impl.h index 5431393..bc1bf67 100644 --- a/media/cast/receiver/cast_receiver_impl.h +++ b/media/cast/receiver/cast_receiver_impl.h @@ -27,12 +27,12 @@ class CastReceiverImpl : public CastReceiver { CastReceiverImpl(scoped_refptr<CastEnvironment> cast_environment, const FrameReceiverConfig& audio_config, const FrameReceiverConfig& video_config, - PacketSender* const packet_sender); + CastTransportSender* const transport); ~CastReceiverImpl() override; // CastReceiver implementation. - PacketReceiverCallback packet_receiver() override; + void ReceivePacket(scoped_ptr<Packet> packet) override; void RequestDecodedAudioFrame( const AudioFrameDecodedCallback& callback) override; void RequestEncodedAudioFrame( @@ -43,10 +43,6 @@ class CastReceiverImpl : public CastReceiver { const ReceiveEncodedFrameCallback& callback) override; private: - // Forwards |packet| to a specific RTP frame receiver, or drops it if SSRC - // does not map to one of the receivers. - void DispatchReceivedPacket(scoped_ptr<Packet> packet); - // Feeds an EncodedFrame into |audio_decoder_|. RequestDecodedAudioFrame() // uses this as a callback for RequestEncodedAudioFrame(). void DecodeEncodedAudioFrame( @@ -88,7 +84,6 @@ class CastReceiverImpl : public CastReceiver { bool is_continuous); const scoped_refptr<CastEnvironment> cast_environment_; - PacedSender pacer_; FrameReceiver audio_receiver_; FrameReceiver video_receiver_; diff --git a/media/cast/receiver/frame_receiver.cc b/media/cast/receiver/frame_receiver.cc index 561e19f..c1155d0 100644 --- a/media/cast/receiver/frame_receiver.cc +++ b/media/cast/receiver/frame_receiver.cc @@ -23,8 +23,9 @@ FrameReceiver::FrameReceiver( const scoped_refptr<CastEnvironment>& cast_environment, const FrameReceiverConfig& config, EventMediaType event_media_type, - PacedPacketSender* const packet_sender) + CastTransportSender* const transport) : cast_environment_(cast_environment), + transport_(transport), packet_parser_(config.incoming_ssrc, config.rtp_payload_type), stats_(cast_environment->Clock()), event_media_type_(event_media_type), @@ -44,13 +45,14 @@ FrameReceiver::FrameReceiver( RtcpRttCallback(), RtcpLogMessageCallback(), cast_environment_->Clock(), - packet_sender, + NULL, config.feedback_ssrc, config.incoming_ssrc), is_waiting_for_consecutive_frame_(false), lip_sync_drift_(ClockDriftSmoother::GetDefaultTimeConstant()), rtcp_interval_(base::TimeDelta::FromMilliseconds(config.rtcp_interval)), weak_factory_(this) { + transport_->AddValidSsrc(config.incoming_ssrc); DCHECK_GT(config.rtp_max_delay_ms, 0); DCHECK_GT(config.max_frame_rate, 0); decryptor_.Initialize(config.aes_key, config.aes_iv_mask); @@ -100,15 +102,6 @@ bool FrameReceiver::ProcessPacket(scoped_ptr<Packet> packet) { return true; } -// static -bool FrameReceiver::ParseSenderSsrc(const uint8* packet, - size_t length, - uint32* ssrc) { - base::BigEndianReader big_endian_reader( - reinterpret_cast<const char*>(packet), length); - return big_endian_reader.Skip(8) && big_endian_reader.ReadU32(ssrc); -} - void FrameReceiver::ProcessParsedPacket(const RtpCastHeader& rtp_header, const uint8* payload_data, size_t payload_size) { @@ -177,10 +170,15 @@ void FrameReceiver::CastFeedback(const RtcpCastMessage& cast_message) { now, FRAME_ACK_SENT, event_media_type_, rtp_timestamp, cast_message.ack_frame_id); - ReceiverRtcpEventSubscriber::RtcpEventMultiMap rtcp_events; - event_subscriber_.GetRtcpEventsAndReset(&rtcp_events); - rtcp_.SendRtcpFromRtpReceiver(&cast_message, target_playout_delay_, - &rtcp_events, NULL); + ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events; + event_subscriber_.GetRtcpEventsWithRedundancy(&rtcp_events); + transport_->SendRtcpFromRtpReceiver(rtcp_.GetLocalSsrc(), + rtcp_.GetRemoteSsrc(), + rtcp_.ConvertToNTPAndSave(now), + &cast_message, + target_playout_delay_, + &rtcp_events, + NULL); } void FrameReceiver::EmitAvailableEncodedFrames() { @@ -336,8 +334,15 @@ void FrameReceiver::ScheduleNextRtcpReport() { void FrameReceiver::SendNextRtcpReport() { DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); + const base::TimeTicks now = cast_environment_->Clock()->NowTicks(); RtpReceiverStatistics stats = stats_.GetStatistics(); - rtcp_.SendRtcpFromRtpReceiver(NULL, base::TimeDelta(), NULL, &stats); + transport_->SendRtcpFromRtpReceiver(rtcp_.GetLocalSsrc(), + rtcp_.GetRemoteSsrc(), + rtcp_.ConvertToNTPAndSave(now), + NULL, + base::TimeDelta(), + NULL, + &stats); ScheduleNextRtcpReport(); } diff --git a/media/cast/receiver/frame_receiver.h b/media/cast/receiver/frame_receiver.h index 4d673f3..382b798 100644 --- a/media/cast/receiver/frame_receiver.h +++ b/media/cast/receiver/frame_receiver.h @@ -50,7 +50,7 @@ class FrameReceiver : public RtpPayloadFeedback, FrameReceiver(const scoped_refptr<CastEnvironment>& cast_environment, const FrameReceiverConfig& config, EventMediaType event_media_type, - PacedPacketSender* const packet_sender); + CastTransportSender* const transport); ~FrameReceiver() override; @@ -64,10 +64,6 @@ class FrameReceiver : public RtpPayloadFeedback, // out-of-order. Returns true if the parsing of the packet succeeded. bool ProcessPacket(scoped_ptr<Packet> packet); - // TODO(miu): This is the wrong place for this, but the (de)serialization - // implementation needs to be consolidated first. - static bool ParseSenderSsrc(const uint8* packet, size_t length, uint32* ssrc); - protected: friend class FrameReceiverTest; // Invokes ProcessParsedPacket(). @@ -115,6 +111,9 @@ class FrameReceiver : public RtpPayloadFeedback, const scoped_refptr<CastEnvironment> cast_environment_; + // Transport used to send data back. + CastTransportSender* const transport_; + // Deserializes a packet into a RtpHeader + payload bytes. RtpParser packet_parser_; diff --git a/media/cast/receiver/frame_receiver_unittest.cc b/media/cast/receiver/frame_receiver_unittest.cc index 24e1a0b..42bc4e3 100644 --- a/media/cast/receiver/frame_receiver_unittest.cc +++ b/media/cast/receiver/frame_receiver_unittest.cc @@ -12,7 +12,8 @@ #include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" #include "media/cast/logging/simple_event_subscriber.h" -#include "media/cast/net/pacing/mock_paced_packet_sender.h" +#include "media/cast/net/cast_transport_sender_impl.h" +#include "media/cast/net/mock_cast_transport_sender.h" #include "media/cast/net/rtcp/test_rtcp_packet_builder.h" #include "media/cast/receiver/frame_receiver.h" #include "media/cast/test/fake_single_thread_task_runner.h" @@ -136,7 +137,7 @@ class FrameReceiverTest : public ::testing::Test { RtpCastHeader rtp_header_; base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. base::TimeTicks start_time_; - MockPacedPacketSender mock_transport_; + MockCastTransportSender mock_transport_; scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; scoped_refptr<CastEnvironment> cast_environment_; FakeFrameClient frame_client_; @@ -171,8 +172,8 @@ TEST_F(FrameReceiverTest, ReceivesOneFrame) { SimpleEventSubscriber event_subscriber; cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); - EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) - .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _)) + .WillRepeatedly(testing::Return()); FeedLipSyncInfoIntoReceiver(); task_runner_->RunTasks(); @@ -212,8 +213,8 @@ TEST_F(FrameReceiverTest, ReceivesFramesSkippingWhenAppropriate) { SimpleEventSubscriber event_subscriber; cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); - EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) - .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _)) + .WillRepeatedly(testing::Return()); const uint32 rtp_advance_per_frame = config_.frequency / config_.max_frame_rate; @@ -315,8 +316,8 @@ TEST_F(FrameReceiverTest, ReceivesFramesRefusingToSkipAny) { SimpleEventSubscriber event_subscriber; cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); - EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) - .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _)) + .WillRepeatedly(testing::Return()); const uint32 rtp_advance_per_frame = config_.frequency / config_.max_frame_rate; |