Index: chrome/renderer/media/cast_transport_sender_ipc.cc |
diff --git a/chrome/renderer/media/cast_transport_sender_ipc.cc b/chrome/renderer/media/cast_transport_sender_ipc.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63bb976efc81934fcd416e48d9062ab185335a71 |
--- /dev/null |
+++ b/chrome/renderer/media/cast_transport_sender_ipc.cc |
@@ -0,0 +1,195 @@ |
+// 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/renderer/media/cast_transport_sender_ipc.h" |
+ |
+namespace cast { |
+ |
+CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL; |
+ |
+CastIPCDispatcher::CastIPCDispatcher( |
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop) |
+ : channel_(NULL), |
+ io_message_loop_(io_message_loop) { |
+ DCHECK(!global_instance_); |
+ global_instance_ = this; |
+} |
+ |
+CastIPCDispatcher::~CastIPCDispatcher() { |
+ global_instance_ = NULL; |
+} |
+ |
+bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) { |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ bool handled = true; |
+ bool msg_is_good = true; |
+ IPC_BEGIN_MESSAGE_MAP_EX(CastIPCDispatcher, message, msg_is_good) |
+ IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) |
+ IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) |
+ IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics) |
+ IPC_MESSAGE_UNHANDLED(handled = false); |
+ IPC_END_MESSAGE_MAP_EX(); |
+ if (!msg_is_good) { |
+ LOG(ERROR) << "Failed to parse incoming message."; |
scherkus (not reviewing)
2014/02/07 00:11:06
avoid LOG(ERROR)
heck, there's nothing you can re
hubbe
2014/02/07 00:52:22
That's what I get for following documentation I gu
|
+ } |
+ return handled; |
+} |
+ |
+void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) { |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ channel_ = channel; |
+} |
+ |
+void CastIPCDispatcher::OnFilterRemoved() { |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ channel_ = NULL; |
+} |
+ |
+void CastIPCDispatcher::OnChannelClosing() { |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ channel_ = NULL; |
+} |
+ |
+ |
scherkus (not reviewing)
2014/02/07 00:11:06
remove extra bit o' whitespace
hubbe
2014/02/07 00:52:22
Done.
|
+void CastIPCDispatcher::OnReceivedPacket( |
+ int32 channel_id, |
+ const media::cast::transport::Packet& packet) { |
+ CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); |
+ if (ptr) { |
+ if (!ptr->packet_callback_.is_null()) { |
+ // TODO(hubbe): Perhaps an non-ownership-transferring cb would be better? |
+ scoped_ptr<media::cast::transport::Packet> packet_copy( |
+ new media::cast::transport::Packet(packet)); |
+ ptr->packet_callback_.Run(packet_copy.Pass()); |
+ } else { |
+ LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " |
+ << "no packet callback yet."; |
+ } |
+ } else { |
+ LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " |
+ << "on non-existing channel."; |
+ } |
+} |
+ |
+void CastIPCDispatcher::OnNotifyStatusChange( |
+ int32 channel_id, |
+ media::cast::transport::CastTransportStatus status) { |
+ CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); |
+ if (ptr) { |
+ ptr->status_callback_.Run(status); |
+ } else { |
+ LOG(ERROR) |
+ << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; |
+ } |
+} |
+ |
+void CastIPCDispatcher::OnRtpStatistics( |
+ int32 channel_id, |
+ bool audio, |
+ const media::cast::transport::RtcpSenderInfo& sender_info, |
+ base::TimeTicks time_sent, |
+ uint32 rtp_timestamp) { |
+ CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); |
+ if (ptr) { |
+ const media::cast::transport::CastTransportRtpStatistics& callback = |
+ audio ? ptr->audio_rtp_callback_ : ptr->video_rtp_callback_; |
+ callback.Run(sender_info, time_sent, rtp_timestamp); |
+ } else { |
+ LOG(ERROR) |
+ << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; |
+ } |
+} |
+ |
+CastTransportSenderIPC::CastTransportSenderIPC( |
+ const media::cast::transport::CastTransportConfig& config, |
+ const media::cast::transport::CastTransportStatusCallback& status_cb) |
+ : status_callback_(status_cb) { |
+ channel_id_ = CastIPCDispatcher::global_instance_->id_map_.Add(this); |
+ Send(new CastHostMsg_New(channel_id_, config)); |
+} |
+ |
+CastTransportSenderIPC::~CastTransportSenderIPC() { |
+ Send(new CastHostMsg_Delete(channel_id_)); |
+ if (CastIPCDispatcher::global_instance_) { |
+ CastIPCDispatcher::global_instance_->id_map_.Remove(channel_id_); |
scherkus (not reviewing)
2014/02/07 00:11:06
over indented
hubbe
2014/02/07 00:52:22
Done.
|
+ } |
+} |
+ |
+bool CastTransportSenderIPC::Send(IPC::Message *message) { |
scherkus (not reviewing)
2014/02/07 00:11:06
this method is bool, yet you ignore the result eve
hubbe
2014/02/07 00:52:22
Making it void.
|
+ if (CastIPCDispatcher::global_instance_ && |
+ CastIPCDispatcher::global_instance_->channel_) { |
+ DCHECK(CastIPCDispatcher::global_instance_->io_message_loop_-> |
+ BelongsToCurrentThread()); |
+ return CastIPCDispatcher::global_instance_->channel_->Send(message); |
+ } else { |
+ // TODO(Hubbe): Notify caller that send failed and close channel. |
+ delete message; |
+ return false; |
+ } |
+} |
+ |
+void CastTransportSenderIPC::SetPacketReceiver( |
+ const media::cast::transport::PacketReceiverCallback& packet_callback) { |
+ packet_callback_ = packet_callback; |
+} |
+ |
+void CastTransportSenderIPC::InsertCodedAudioFrame( |
+ const media::cast::transport::EncodedAudioFrame* audio_frame, |
+ const base::TimeTicks& recorded_time) { |
+ Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, |
+ *audio_frame, |
+ recorded_time)); |
+} |
+ |
+void CastTransportSenderIPC::InsertCodedVideoFrame( |
+ const media::cast::transport::EncodedVideoFrame* video_frame, |
+ const base::TimeTicks& capture_time) { |
+ Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, |
+ *video_frame, |
+ capture_time)); |
+} |
+ |
+void CastTransportSenderIPC::SendRtcpFromRtpSender( |
+ uint32 packet_type_flags, |
+ const media::cast::transport::RtcpSenderInfo& sender_info, |
+ const media::cast::transport::RtcpDlrrReportBlock& dlrr, |
+ const media::cast::transport::RtcpSenderLogMessage& sender_log, |
+ uint32 sending_ssrc, |
+ const std::string& c_name) { |
+ struct media::cast::transport::SendRtcpFromRtpSenderData data; |
+ data.packet_type_flags = packet_type_flags; |
+ data.sending_ssrc = sending_ssrc; |
+ data.c_name = data.c_name; |
+ Send(new CastHostMsg_SendRtcpFromRtpSender( |
+ channel_id_, |
+ data, |
+ sender_info, |
+ dlrr, |
+ sender_log)); |
+} |
+ |
+void CastTransportSenderIPC::ResendPackets( |
+ bool is_audio, |
+ const media::cast::MissingFramesAndPacketsMap& missing_packets) { |
+ Send(new CastHostMsg_ResendPackets(channel_id_, |
+ is_audio, |
+ missing_packets)); |
+} |
+ |
+void CastTransportSenderIPC::SubscribeAudioRtpStatsCallback( |
+ const media::cast::transport::CastTransportRtpStatistics& callback) { |
+ audio_rtp_callback_ = callback; |
+} |
+ |
+// Retrieves video RTP statistics. |
scherkus (not reviewing)
2014/02/07 00:11:06
nuke comment?
hubbe
2014/02/07 00:52:22
Done.
|
+void CastTransportSenderIPC::SubscribeVideoRtpStatsCallback( |
+ const media::cast::transport::CastTransportRtpStatistics& callback) { |
+ video_rtp_callback_ = callback; |
+} |
+ |
+ |
+ |
+ |
+ |
scherkus (not reviewing)
2014/02/07 00:11:06
nuke all this extra whitespace
hubbe
2014/02/07 00:52:22
Done.
|
+} // namespace cast |