Chromium Code Reviews| Index: chrome/browser/media/cast_transport_host_filter.cc |
| diff --git a/chrome/browser/media/cast_transport_host_filter.cc b/chrome/browser/media/cast_transport_host_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..00262edf87fcc47009595c6346c5b156d39d6160 |
| --- /dev/null |
| +++ b/chrome/browser/media/cast_transport_host_filter.cc |
| @@ -0,0 +1,151 @@ |
| +// Copyright (c) 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 "chrome/browser/media/cast_transport_host_filter.h" |
| +#include "media/cast/transport/cast_transport_sender.h" |
| + |
| +namespace cast { |
| + |
| +CastTransportHostFilter::CastTransportHostFilter() { |
| +} |
| + |
| +CastTransportHostFilter::~CastTransportHostFilter() { |
| +} |
| + |
| +bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message, |
| + bool* message_was_ok) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP_EX(CastTransportHostFilter, message, *message_was_ok) |
| + IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew) |
| + IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete) |
| + IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame, |
| + OnInsertCodedAudioFrame) |
| + IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame, |
| + OnInsertCodedVideoFrame) |
| + IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpSender, |
| + OnSendRtcpFromRtpSender); |
| + IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets, |
| + OnResendPackets) |
| + IPC_MESSAGE_UNHANDLED(handled = false); |
| + IPC_END_MESSAGE_MAP_EX(); |
| + return handled; |
| +} |
| + |
| +void CastTransportHostFilter::NotifyStatusChange( |
| + int32 channel_id, |
| + media::cast::transport::CastTransportStatus status) { |
| + Send(new CastMsg_NotifyStatusChange(channel_id, status)); |
| +} |
| + |
| +void CastTransportHostFilter::ReceivedPacket( |
| + int32 channel_id, |
| + scoped_ptr<media::cast::transport::Packet> packet) { |
| + Send(new CastMsg_ReceivedPacket(channel_id, *packet)); |
| +} |
| + |
|
mikhal1
2014/02/05 00:53:05
nit: rm new line
hubbe
2014/02/05 01:11:44
Done.
|
| + |
| +void CastTransportHostFilter::OnNew( |
| + int32 channel_id, |
| + const media::cast::transport::CastTransportConfig& config) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + id_map_.Remove(channel_id); |
| + } |
| + |
| + sender = media::cast::transport::CastTransportSender:: |
| + CreateCastTransportSender( |
| + &clock_, |
| + config, |
| + base::Bind(&CastTransportHostFilter::NotifyStatusChange, |
| + base::Unretained(this), |
| + channel_id), |
| + base::MessageLoopProxy::current()); |
| + sender->SetPacketReceiver( |
| + base::Bind(&CastTransportHostFilter::ReceivedPacket, |
| + base::Unretained(this), |
| + channel_id)); |
| + |
| + id_map_.AddWithID(sender, channel_id); |
| +} |
| + |
| +void CastTransportHostFilter::OnDelete( |
| + int32 channel_id) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + id_map_.Remove(channel_id); |
| + } else { |
| + LOG(ERROR) << "CastTransportHostFilter::Delete called " |
| + << "on non-existing channel"; |
| + } |
| +} |
| + |
| +void CastTransportHostFilter::OnInsertCodedAudioFrame( |
| + int32 channel_id, |
| + const media::cast::transport::EncodedAudioFrame& audio_frame, |
| + base::TimeTicks recorded_time) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + sender->InsertCodedAudioFrame(&audio_frame, recorded_time); |
| + } else { |
| + LOG(ERROR) |
| + << "CastTransportHostFilter::OnInsertCodedAudioFrame " |
| + << "on non-existing channel"; |
| + } |
| +} |
| + |
| +void CastTransportHostFilter::OnInsertCodedVideoFrame( |
| + int32 channel_id, |
| + const media::cast::transport::EncodedVideoFrame& video_frame, |
| + base::TimeTicks capture_time) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + sender->InsertCodedVideoFrame(&video_frame, capture_time); |
| + } else { |
| + LOG(ERROR) |
| + << "CastTransportHostFilter::OnInsertCodedVideoFrame " |
| + << "on non-existing channel"; |
| + } |
| +} |
| + |
| +void CastTransportHostFilter::OnSendRtcpFromRtpSender( |
| + int32 channel_id, |
| + const media::cast::transport::SendRtcpFromRtpSenderData& data, |
| + const media::cast::transport::RtcpSenderInfo& sender_info, |
| + const media::cast::transport::RtcpDlrrReportBlock& dlrr, |
| + const media::cast::transport::RtcpSenderLogMessage& sender_log) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + sender->SendRtcpFromRtpSender(data.packet_type_flags, |
| + sender_info, |
| + dlrr, |
| + sender_log, |
| + data.sending_ssrc, |
| + data.c_name); |
| + } else { |
| + LOG(ERROR) |
| + << "CastTransportHostFilter::OnSendRtcpFromRtpSender " |
| + << "on non-existing channel"; |
| + } |
| +} |
| + |
| +void CastTransportHostFilter::OnResendPackets( |
| + int32 channel_id, |
| + bool is_audio, |
| + const media::cast::MissingFramesAndPacketsMap& missing_packets) { |
| + media::cast::transport::CastTransportSender *sender = |
| + id_map_.Lookup(channel_id); |
| + if (sender) { |
| + sender->ResendPackets(is_audio, missing_packets); |
| + } else { |
| + LOG(ERROR) |
| + << "CastTransportHostFilter::OnResendPackets on non-existing channel"; |
| + } |
| +} |
| + |
| +} // namespace cast |