OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | |
6 | |
7 namespace cast { | |
8 | |
9 CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL; | |
10 | |
11 CastIPCDispatcher::CastIPCDispatcher( | |
12 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | |
13 : channel_(NULL), | |
14 io_message_loop_(io_message_loop) { | |
15 DCHECK(!global_instance_); | |
16 global_instance_ = this; | |
17 } | |
18 | |
19 CastIPCDispatcher::~CastIPCDispatcher() { | |
20 global_instance_ = NULL; | |
21 } | |
22 | |
23 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) { | |
24 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
25 bool handled = true; | |
26 bool msg_is_good = true; | |
27 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.
| |
28 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) | |
29 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) | |
30 IPC_MESSAGE_UNHANDLED(handled = false); | |
31 IPC_END_MESSAGE_MAP_EX(); | |
32 if (!msg_is_good) { | |
33 LOG(ERROR) << "Failed to parse incoming message."; | |
34 } | |
35 return handled; | |
36 } | |
37 | |
38 void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) { | |
39 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
40 channel_ = channel; | |
41 } | |
42 | |
43 void CastIPCDispatcher::OnFilterRemoved() { | |
44 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
45 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
| |
46 } | |
47 | |
48 void CastIPCDispatcher::OnChannelClosing() { | |
49 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
50 channel_ = NULL; | |
51 } | |
52 | |
53 | |
54 void CastIPCDispatcher::OnReceivedPacket( | |
55 int32 channel_id, | |
56 const media::cast::transport::Packet& packet) { | |
57 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
58 if (ptr) { | |
59 if (!ptr->packet_callback_.is_null()) { | |
60 // TODO(hubbe): Perhaps an non-ownership-transferring cb would be better? | |
61 scoped_ptr<media::cast::transport::Packet> packet_copy( | |
62 new media::cast::transport::Packet(packet)); | |
63 ptr->packet_callback_.Run(packet_copy.Pass()); | |
64 } else { | |
65 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
66 << "no packet callback yet."; | |
67 } | |
68 } else { | |
69 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
70 << "on non-existing channel."; | |
71 } | |
72 } | |
73 | |
74 void CastIPCDispatcher::OnNotifyStatusChange( | |
75 int32 channel_id, | |
76 media::cast::transport::CastTransportStatus status) { | |
77 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
78 if (ptr) { | |
79 ptr->status_callback_.Run(status); | |
80 } else { | |
81 LOG(ERROR) | |
82 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
83 } | |
84 } | |
85 | |
86 CastTransportSenderIPC::CastTransportSenderIPC( | |
87 const media::cast::transport::CastTransportConfig& config, | |
88 const media::cast::transport::CastTransportStatusCallback& status_cb) | |
89 : status_callback_(status_cb) { | |
90 channel_id_ = CastIPCDispatcher::global_instance_->id_map_.Add(this); | |
91 Send(new CastHostMsg_New(channel_id_, config)); | |
92 } | |
93 | |
94 CastTransportSenderIPC::~CastTransportSenderIPC() { | |
95 Send(new CastHostMsg_Delete(channel_id_)); | |
96 if ( CastIPCDispatcher::global_instance_) { | |
mikhal1
2014/02/05 00:53:05
nit:remove space after (
hubbe
2014/02/05 01:11:44
Done.
| |
97 CastIPCDispatcher::global_instance_->id_map_.Remove(channel_id_); | |
98 } | |
99 } | |
100 | |
101 bool CastTransportSenderIPC::Send(IPC::Message *message) { | |
102 if (CastIPCDispatcher::global_instance_ && | |
103 CastIPCDispatcher::global_instance_->channel_) { | |
104 DCHECK(CastIPCDispatcher::global_instance_->io_message_loop_-> | |
105 BelongsToCurrentThread()); | |
106 return CastIPCDispatcher::global_instance_->channel_->Send(message); | |
107 } else { | |
108 // TODO(Hubbe): Notify caller that send failed and close channel. | |
109 delete message; | |
110 return false; | |
111 } | |
112 } | |
113 | |
114 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
| |
115 const media::cast::transport::PacketReceiverCallback& packet_callback) { | |
116 packet_callback_ = packet_callback; | |
117 } | |
118 | |
119 void CastTransportSenderIPC::InsertCodedAudioFrame( | |
120 const media::cast::transport::EncodedAudioFrame* audio_frame, | |
121 const base::TimeTicks& recorded_time) { | |
122 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, | |
123 *audio_frame, | |
124 recorded_time)); | |
125 } | |
126 | |
127 void CastTransportSenderIPC::InsertCodedVideoFrame( | |
128 const media::cast::transport::EncodedVideoFrame* video_frame, | |
129 const base::TimeTicks& capture_time) { | |
130 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, | |
131 *video_frame, | |
132 capture_time)); | |
133 } | |
134 | |
135 void CastTransportSenderIPC::SendRtcpFromRtpSender( | |
136 uint32 packet_type_flags, | |
137 const media::cast::transport::RtcpSenderInfo& sender_info, | |
138 const media::cast::transport::RtcpDlrrReportBlock& dlrr, | |
139 const media::cast::transport::RtcpSenderLogMessage& sender_log, | |
140 uint32 sending_ssrc, | |
141 const std::string& c_name) { | |
142 struct media::cast::transport::SendRtcpFromRtpSenderData data; | |
143 data.packet_type_flags = packet_type_flags; | |
144 data.sending_ssrc = sending_ssrc; | |
145 data.c_name = data.c_name; | |
146 Send(new CastHostMsg_SendRtcpFromRtpSender( | |
147 channel_id_, | |
148 data, | |
149 sender_info, | |
150 dlrr, | |
151 sender_log)); | |
152 } | |
153 | |
154 void CastTransportSenderIPC::ResendPackets( | |
155 bool is_audio, | |
156 const media::cast::MissingFramesAndPacketsMap& missing_packets) { | |
157 Send(new CastHostMsg_ResendPackets(channel_id_, | |
158 is_audio, | |
159 missing_packets)); | |
160 } | |
161 | |
162 void CastTransportSenderIPC::RtpAudioStatistics( | |
163 const base::TimeTicks& now, | |
164 media::cast::transport::RtcpSenderInfo* sender_info) { | |
165 // TODO(hubbe): Not yet implemented | |
166 } | |
167 | |
168 // Retrieves video RTP statistics. | |
169 void CastTransportSenderIPC::RtpVideoStatistics( | |
170 const base::TimeTicks& now, | |
171 media::cast::transport::RtcpSenderInfo* sender_info) { | |
172 // TODO(hubbe): Not yet implemented | |
173 } | |
174 | |
175 | |
176 | |
177 | |
178 } // namespace cast | |
OLD | NEW |