Chromium Code Reviews| 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..7a77279099d8f28e7ddf409920d0033dddfad6de |
| --- /dev/null |
| +++ b/chrome/renderer/media/cast_transport_sender_ipc.cc |
| @@ -0,0 +1,178 @@ |
| +// 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) |
|
mikhal1
2014/02/05 00:53:05
Can will msg_is_good update?
hubbe
2014/02/05 01:11:44
Yes, I think so.
|
| + IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) |
| + IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) |
| + IPC_MESSAGE_UNHANDLED(handled = false); |
| + IPC_END_MESSAGE_MAP_EX(); |
| + if (!msg_is_good) { |
| + LOG(ERROR) << "Failed to parse incoming message."; |
| + } |
| + 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; |
|
mikhal1
2014/02/05 00:53:05
What's the difference between removing a filter an
hubbe
2014/02/05 01:11:44
Not much. Although, filter removal will never happ
|
| +} |
| + |
| +void CastIPCDispatcher::OnChannelClosing() { |
| + DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| + channel_ = NULL; |
| +} |
| + |
| + |
| +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."; |
| + } |
| +} |
| + |
| +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_) { |
|
mikhal1
2014/02/05 00:53:05
nit:remove space after (
hubbe
2014/02/05 01:11:44
Done.
|
| + CastIPCDispatcher::global_instance_->id_map_.Remove(channel_id_); |
| + } |
| +} |
| + |
| +bool CastTransportSenderIPC::Send(IPC::Message *message) { |
| + 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( |
|
mikhal1
2014/02/05 00:53:05
Consider renaming the function
hubbe
2014/02/05 01:11:44
I could, but not in this CL, as I would have to ch
|
| + 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::RtpAudioStatistics( |
| + const base::TimeTicks& now, |
| + media::cast::transport::RtcpSenderInfo* sender_info) { |
| + // TODO(hubbe): Not yet implemented |
| +} |
| + |
| +// Retrieves video RTP statistics. |
| +void CastTransportSenderIPC::RtpVideoStatistics( |
| + const base::TimeTicks& now, |
| + media::cast::transport::RtcpSenderInfo* sender_info) { |
| + // TODO(hubbe): Not yet implemented |
| +} |
| + |
| + |
| + |
| + |
| +} // namespace cast |