Commit 2a5280a3 authored by hubbe's avatar hubbe Committed by Commit bot

Cast: merge InsertCoded{Audio,Video}Frame into InsertFrame

Minor cleanup cl.

Review URL: https://codereview.chromium.org/519443002

Cr-Commit-Position: refs/heads/master@{#293367}
parent 2515b7dc
......@@ -31,10 +31,7 @@ bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete)
IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio)
IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo)
IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame,
OnInsertCodedAudioFrame)
IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame,
OnInsertCodedVideoFrame)
IPC_MESSAGE_HANDLER(CastHostMsg_InsertFrame, OnInsertFrame)
IPC_MESSAGE_HANDLER(CastHostMsg_SendSenderReport,
OnSendSenderReport)
IPC_MESSAGE_HANDLER(CastHostMsg_ResendFrameForKickstart,
......@@ -172,31 +169,17 @@ void CastTransportHostFilter::OnInitializeVideo(
}
}
void CastTransportHostFilter::OnInsertCodedAudioFrame(
void CastTransportHostFilter::OnInsertFrame(
int32 channel_id,
const media::cast::EncodedFrame& audio_frame) {
media::cast::CastTransportSender* sender =
id_map_.Lookup(channel_id);
if (sender) {
sender->InsertCodedAudioFrame(audio_frame);
} else {
DVLOG(1)
<< "CastTransportHostFilter::OnInsertCodedAudioFrame "
<< "on non-existing channel";
}
}
void CastTransportHostFilter::OnInsertCodedVideoFrame(
int32 channel_id,
const media::cast::EncodedFrame& video_frame) {
uint32 ssrc,
const media::cast::EncodedFrame& frame) {
media::cast::CastTransportSender* sender =
id_map_.Lookup(channel_id);
if (sender) {
sender->InsertCodedVideoFrame(video_frame);
sender->InsertFrame(ssrc, frame);
} else {
DVLOG(1)
<< "CastTransportHostFilter::OnInsertCodedVideoFrame "
<< "on non-existing channel";
<< "CastTransportHostFilter::OnInsertFrame on non-existing channel";
}
}
......
......@@ -54,12 +54,10 @@ class CastTransportHostFilter : public content::BrowserMessageFilter {
void OnInitializeVideo(
int32 channel_id,
const media::cast::CastTransportRtpConfig& config);
void OnInsertCodedAudioFrame(
void OnInsertFrame(
int32 channel_id,
const media::cast::EncodedFrame& audio_frame);
void OnInsertCodedVideoFrame(
int32 channel_id,
const media::cast::EncodedFrame& video_frame);
uint32 ssrc,
const media::cast::EncodedFrame& frame);
void OnSendSenderReport(
int32 channel_id,
uint32 ssrc,
......
......@@ -105,9 +105,8 @@ TEST_F(CastTransportHostFilterTest, SimpleMessages) {
const int kBytesPerSample = 2;
const int kChannels = 2;
audio_frame.data = std::string(kSamples * kBytesPerSample * kChannels, 'q');
CastHostMsg_InsertCodedAudioFrame insert_coded_audio_frame(
kChannelId, audio_frame);
FakeSend(insert_coded_audio_frame);
CastHostMsg_InsertFrame insert_audio_frame(1, kChannelId, audio_frame);
FakeSend(insert_audio_frame);
media::cast::EncodedFrame video_frame;
video_frame.dependency = media::cast::EncodedFrame::KEY;
......@@ -117,9 +116,8 @@ TEST_F(CastTransportHostFilterTest, SimpleMessages) {
// are generated.
const int kVideoDataSize = 4711;
video_frame.data = std::string(kVideoDataSize, 'p');
CastHostMsg_InsertCodedVideoFrame insert_coded_video_frame(
kChannelId, video_frame);
FakeSend(insert_coded_video_frame);
CastHostMsg_InsertFrame insert_video_frame(11, kChannelId, video_frame);
FakeSend(insert_video_frame);
CastHostMsg_SendSenderReport rtcp_msg(
kChannelId, 1, base::TimeTicks(), 2);
......
......@@ -123,15 +123,11 @@ IPC_MESSAGE_CONTROL2(
int32 /*channel_id*/,
media::cast::CastTransportRtpConfig /*config*/)
IPC_MESSAGE_CONTROL2(
CastHostMsg_InsertCodedAudioFrame,
int32 /* channel_id */,
media::cast::EncodedFrame /* audio_frame */)
IPC_MESSAGE_CONTROL2(
CastHostMsg_InsertCodedVideoFrame,
IPC_MESSAGE_CONTROL3(
CastHostMsg_InsertFrame,
int32 /* channel_id */,
media::cast::EncodedFrame /* video_frame */)
uint32 /* ssrc */,
media::cast::EncodedFrame /* audio/video frame */)
IPC_MESSAGE_CONTROL4(
CastHostMsg_SendSenderReport,
......
......@@ -50,14 +50,9 @@ void CastTransportSenderIPC::InitializeVideo(
Send(new CastHostMsg_InitializeVideo(channel_id_, config));
}
void CastTransportSenderIPC::InsertCodedAudioFrame(
const media::cast::EncodedFrame& audio_frame) {
Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, audio_frame));
}
void CastTransportSenderIPC::InsertCodedVideoFrame(
const media::cast::EncodedFrame& video_frame) {
Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, video_frame));
void CastTransportSenderIPC::InsertFrame(uint32 ssrc,
const media::cast::EncodedFrame& frame) {
Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame));
}
void CastTransportSenderIPC::SendSenderReport(
......
......@@ -36,10 +36,8 @@ class CastTransportSenderIPC
const media::cast::CastTransportRtpConfig& config,
const media::cast::RtcpCastMessageCallback& cast_message_cb,
const media::cast::RtcpRttCallback& rtt_cb) OVERRIDE;
virtual void InsertCodedAudioFrame(
const media::cast::EncodedFrame& audio_frame) OVERRIDE;
virtual void InsertCodedVideoFrame(
const media::cast::EncodedFrame& video_frame) OVERRIDE;
virtual void InsertFrame(uint32 ssrc,
const media::cast::EncodedFrame& frame) OVERRIDE;
virtual void SendSenderReport(
uint32 ssrc,
base::TimeTicks current_time,
......
......@@ -70,11 +70,9 @@ class CastTransportSender : public base::NonThreadSafe {
const RtcpCastMessageCallback& cast_message_cb,
const RtcpRttCallback& rtt_cb) = 0;
// The following two functions handle the encoded media frames (audio and
// video) to be processed.
// Frames will be encrypted, packetized and transmitted to the network.
virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) = 0;
virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) = 0;
// Encrypt, packetize and transmit |frame|. |ssrc| must refer to a
// a channel already established with InitializeAudio / InitializeVideo.
virtual void InsertFrame(uint32 ssrc, const EncodedFrame& frame) = 0;
// Sends a RTCP sender report to the receiver.
// |ssrc| is the SSRC for this report.
......
......@@ -178,16 +178,15 @@ void EncryptAndSendFrame(const EncodedFrame& frame,
}
} // namespace
void CastTransportSenderImpl::InsertCodedAudioFrame(
const EncodedFrame& audio_frame) {
DCHECK(audio_sender_) << "Audio sender uninitialized";
EncryptAndSendFrame(audio_frame, &audio_encryptor_, audio_sender_.get());
}
void CastTransportSenderImpl::InsertCodedVideoFrame(
const EncodedFrame& video_frame) {
DCHECK(video_sender_) << "Video sender uninitialized";
EncryptAndSendFrame(video_frame, &video_encryptor_, video_sender_.get());
void CastTransportSenderImpl::InsertFrame(uint32 ssrc,
const EncodedFrame& frame) {
if (audio_sender_ && ssrc == audio_sender_->ssrc()) {
EncryptAndSendFrame(frame, &audio_encryptor_, audio_sender_.get());
} else if (video_sender_ && ssrc == video_sender_->ssrc()) {
EncryptAndSendFrame(frame, &video_encryptor_, video_sender_.get());
} else {
NOTREACHED() << "Invalid InsertFrame call.";
}
}
void CastTransportSenderImpl::SendSenderReport(
......
......@@ -72,8 +72,7 @@ class CastTransportSenderImpl : public CastTransportSender {
virtual void InitializeVideo(const CastTransportRtpConfig& config,
const RtcpCastMessageCallback& cast_message_cb,
const RtcpRttCallback& rtt_cb) OVERRIDE;
virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) OVERRIDE;
virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) OVERRIDE;
virtual void InsertFrame(uint32 ssrc, const EncodedFrame& frame) OVERRIDE;
virtual void SendSenderReport(
uint32 ssrc,
......
......@@ -164,7 +164,7 @@ TEST_F(CastTransportSenderImplTest, NacksCancelRetransmits) {
fake_frame.dependency = EncodedFrame::KEY;
fake_frame.data.resize(5000, ' ');
transport_sender_->InsertCodedVideoFrame(fake_frame);
transport_sender_->InsertFrame(kVideoSsrc, fake_frame);
task_runner_->Sleep(base::TimeDelta::FromMilliseconds(10));
EXPECT_EQ(4, transport_.packets_sent());
......@@ -209,7 +209,7 @@ TEST_F(CastTransportSenderImplTest, CancelRetransmits) {
fake_frame.dependency = EncodedFrame::KEY;
fake_frame.data.resize(5000, ' ');
transport_sender_->InsertCodedVideoFrame(fake_frame);
transport_sender_->InsertFrame(kVideoSsrc, fake_frame);
task_runner_->Sleep(base::TimeDelta::FromMilliseconds(10));
EXPECT_EQ(4, transport_.packets_sent());
......@@ -248,7 +248,7 @@ TEST_F(CastTransportSenderImplTest, Kickstart) {
fake_frame.data.resize(5000, ' ');
transport_.SetPaused(true);
transport_sender_->InsertCodedVideoFrame(fake_frame);
transport_sender_->InsertFrame(kVideoSsrc, fake_frame);
transport_sender_->ResendFrameForKickstart(kVideoSsrc, 1);
transport_.SetPaused(false);
task_runner_->Sleep(base::TimeDelta::FromMilliseconds(10));
......@@ -285,11 +285,11 @@ TEST_F(CastTransportSenderImplTest, DedupRetransmissionWithAudio) {
fake_audio.reference_time = testing_clock_.NowTicks();
fake_audio.dependency = EncodedFrame::KEY;
fake_audio.data.resize(100, ' ');
transport_sender_->InsertCodedAudioFrame(fake_audio);
transport_sender_->InsertFrame(kAudioSsrc, fake_audio);
task_runner_->Sleep(base::TimeDelta::FromMilliseconds(2));
fake_audio.frame_id = 2;
fake_audio.reference_time = testing_clock_.NowTicks();
transport_sender_->InsertCodedAudioFrame(fake_audio);
transport_sender_->InsertFrame(kAudioSsrc, fake_audio);
task_runner_->Sleep(base::TimeDelta::FromMilliseconds(2));
EXPECT_EQ(2, transport_.packets_sent());
......@@ -308,7 +308,7 @@ TEST_F(CastTransportSenderImplTest, DedupRetransmissionWithAudio) {
fake_video.frame_id = 1;
fake_video.dependency = EncodedFrame::KEY;
fake_video.data.resize(5000, ' ');
transport_sender_->InsertCodedVideoFrame(fake_video);
transport_sender_->InsertFrame(kVideoSsrc, fake_video);
task_runner_->RunTasks();
EXPECT_EQ(6, transport_.packets_sent());
......
......@@ -138,7 +138,7 @@ void AudioSender::SendEncodedAudioFrame(
encoded_frame->new_playout_delay_ms =
target_playout_delay_.InMilliseconds();
}
transport_sender_->InsertCodedAudioFrame(*encoded_frame);
transport_sender_->InsertFrame(ssrc_, *encoded_frame);
}
void AudioSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) {
......
......@@ -211,7 +211,7 @@ void VideoSender::SendEncodedVideoFrame(
encoded_frame->new_playout_delay_ms =
target_playout_delay_.InMilliseconds();
}
transport_sender_->InsertCodedVideoFrame(*encoded_frame);
transport_sender_->InsertFrame(ssrc_, *encoded_frame);
}
void VideoSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) {
......
......@@ -112,6 +112,7 @@ class CastTransportSenderWrapper : public CastTransportSender {
const CastTransportRtpConfig& config,
const RtcpCastMessageCallback& cast_message_cb,
const RtcpRttCallback& rtt_cb) OVERRIDE {
audio_ssrc_ = config.ssrc;
transport_->InitializeAudio(config, cast_message_cb, rtt_cb);
}
......@@ -119,19 +120,18 @@ class CastTransportSenderWrapper : public CastTransportSender {
const CastTransportRtpConfig& config,
const RtcpCastMessageCallback& cast_message_cb,
const RtcpRttCallback& rtt_cb) OVERRIDE {
video_ssrc_ = config.ssrc;
transport_->InitializeVideo(config, cast_message_cb, rtt_cb);
}
virtual void InsertCodedAudioFrame(
const EncodedFrame& audio_frame) OVERRIDE {
*encoded_audio_bytes_ += audio_frame.data.size();
transport_->InsertCodedAudioFrame(audio_frame);
}
virtual void InsertCodedVideoFrame(
const EncodedFrame& video_frame) OVERRIDE {
*encoded_video_bytes_ += video_frame.data.size();
transport_->InsertCodedVideoFrame(video_frame);
virtual void InsertFrame(uint32 ssrc,
const EncodedFrame& frame) OVERRIDE {
if (ssrc == audio_ssrc_) {
*encoded_audio_bytes_ += frame.data.size();
} else if (ssrc == video_ssrc_) {
*encoded_video_bytes_ += frame.data.size();
}
transport_->InsertFrame(ssrc, frame);
}
virtual void SendSenderReport(
......@@ -160,6 +160,7 @@ class CastTransportSenderWrapper : public CastTransportSender {
private:
scoped_ptr<CastTransportSender> transport_;
uint32 audio_ssrc_, video_ssrc_;
uint64* encoded_video_bytes_;
uint64* encoded_audio_bytes_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment