OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | 5 #include "chrome/renderer/media/cast_transport_sender_ipc.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "chrome/common/cast_messages.h" | 9 #include "chrome/common/cast_messages.h" |
10 #include "chrome/renderer/media/cast_ipc_dispatcher.h" | 10 #include "chrome/renderer/media/cast_ipc_dispatcher.h" |
11 #include "ipc/ipc_channel_proxy.h" | 11 #include "ipc/ipc_channel_proxy.h" |
12 #include "media/cast/cast_sender.h" | 12 #include "media/cast/cast_sender.h" |
13 | 13 |
14 CastTransportSenderIPC::ClientCallbacks::ClientCallbacks() {} | 14 CastTransportSenderIPC::ClientCallbacks::ClientCallbacks() {} |
15 CastTransportSenderIPC::ClientCallbacks::~ClientCallbacks() {} | 15 CastTransportSenderIPC::ClientCallbacks::~ClientCallbacks() {} |
16 | 16 |
17 CastTransportSenderIPC::CastTransportSenderIPC( | 17 CastTransportSenderIPC::CastTransportSenderIPC( |
18 const net::IPEndPoint& local_end_point, | |
18 const net::IPEndPoint& remote_end_point, | 19 const net::IPEndPoint& remote_end_point, |
19 scoped_ptr<base::DictionaryValue> options, | 20 scoped_ptr<base::DictionaryValue> options, |
21 const media::cast::PacketReceiverCallback& packet_callback, | |
20 const media::cast::CastTransportStatusCallback& status_cb, | 22 const media::cast::CastTransportStatusCallback& status_cb, |
21 const media::cast::BulkRawEventsCallback& raw_events_cb) | 23 const media::cast::BulkRawEventsCallback& raw_events_cb) |
22 : status_callback_(status_cb), raw_events_callback_(raw_events_cb) { | 24 : packet_callback_(packet_callback) , |
25 status_callback_(status_cb), | |
26 raw_events_callback_(raw_events_cb) { | |
23 if (CastIPCDispatcher::Get()) { | 27 if (CastIPCDispatcher::Get()) { |
24 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); | 28 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); |
25 } | 29 } |
26 Send(new CastHostMsg_New(channel_id_, remote_end_point, *options)); | 30 Send(new CastHostMsg_New(channel_id_, |
31 local_end_point, | |
32 remote_end_point, | |
33 *options)); | |
27 } | 34 } |
28 | 35 |
29 CastTransportSenderIPC::~CastTransportSenderIPC() { | 36 CastTransportSenderIPC::~CastTransportSenderIPC() { |
30 Send(new CastHostMsg_Delete(channel_id_)); | 37 Send(new CastHostMsg_Delete(channel_id_)); |
31 if (CastIPCDispatcher::Get()) { | 38 if (CastIPCDispatcher::Get()) { |
32 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 39 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
33 } | 40 } |
34 } | 41 } |
35 | 42 |
36 void CastTransportSenderIPC::InitializeAudio( | 43 void CastTransportSenderIPC::InitializeAudio( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 frame_ids)); | 80 frame_ids)); |
74 } | 81 } |
75 | 82 |
76 void CastTransportSenderIPC::ResendFrameForKickstart( | 83 void CastTransportSenderIPC::ResendFrameForKickstart( |
77 uint32 ssrc, uint32 frame_id) { | 84 uint32 ssrc, uint32 frame_id) { |
78 Send(new CastHostMsg_ResendFrameForKickstart(channel_id_, | 85 Send(new CastHostMsg_ResendFrameForKickstart(channel_id_, |
79 ssrc, | 86 ssrc, |
80 frame_id)); | 87 frame_id)); |
81 } | 88 } |
82 | 89 |
90 void CastTransportSenderIPC::AddValidSsrc(uint32 ssrc) { | |
91 Send(new CastHostMsg_AddValidSsrc(channel_id_, ssrc)); | |
92 } | |
93 | |
94 | |
95 void CastTransportSenderIPC::SendRtcpFromRtpReceiver( | |
96 uint32 ssrc, | |
97 uint32 sender_ssrc, | |
98 const media::cast::RtcpTimeData& time_data, | |
99 const media::cast::RtcpCastMessage* cast_message, | |
100 base::TimeDelta target_delay, | |
101 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents* | |
102 rtcp_events, | |
103 const media::cast::RtpReceiverStatistics* rtp_receiver_statistics) { | |
104 // To avoid copies, we put pointers to objects we don't really | |
105 // own into scoped pointers and then very carefully extract them again | |
106 // before the scoped pointers go out of scope. | |
107 media::cast::SendRtcpFromRtpReceiver_Params params; | |
108 params.ssrc = ssrc; | |
109 params.sender_ssrc = sender_ssrc; | |
110 params.time_data = time_data; | |
111 if (cast_message) { | |
112 params.cast_message.reset( | |
113 const_cast<media::cast::RtcpCastMessage*>(cast_message)); | |
114 } | |
115 params.target_delay = target_delay; | |
116 if (rtcp_events) { | |
117 params.rtcp_events.reset( | |
118 const_cast< | |
miu
2014/12/04 04:18:53
Line 118 and 119 can be one LOC.
hubbe
2014/12/05 23:57:20
Done.
| |
119 media::cast::ReceiverRtcpEventSubscriber::RtcpEvents*>( | |
120 rtcp_events)); | |
121 } | |
122 if (rtp_receiver_statistics) { | |
123 params.rtp_receiver_statistics.reset( | |
124 const_cast<media::cast::RtpReceiverStatistics*>( | |
125 rtp_receiver_statistics)); | |
126 } | |
127 // Note, params contains scoped_ptr<>, but this still works because | |
128 // CastHostMsg_SendRtcpFromRtpReceiver doesn't take ownership, it | |
129 // serializes it and remember the serialized form instead. | |
130 Send(new CastHostMsg_SendRtcpFromRtpReceiver(channel_id_, params)); | |
131 | |
132 (void)params.rtp_receiver_statistics.release(); | |
133 (void)params.cast_message.release(); | |
134 (void)params.rtcp_events.release(); | |
135 } | |
136 | |
137 | |
83 void CastTransportSenderIPC::OnNotifyStatusChange( | 138 void CastTransportSenderIPC::OnNotifyStatusChange( |
84 media::cast::CastTransportStatus status) { | 139 media::cast::CastTransportStatus status) { |
85 status_callback_.Run(status); | 140 status_callback_.Run(status); |
86 } | 141 } |
87 | 142 |
88 void CastTransportSenderIPC::OnRawEvents( | 143 void CastTransportSenderIPC::OnRawEvents( |
89 const std::vector<media::cast::PacketEvent>& packet_events, | 144 const std::vector<media::cast::PacketEvent>& packet_events, |
90 const std::vector<media::cast::FrameEvent>& frame_events) { | 145 const std::vector<media::cast::FrameEvent>& frame_events) { |
91 raw_events_callback_.Run(packet_events, frame_events); | 146 raw_events_callback_.Run(packet_events, frame_events); |
92 } | 147 } |
(...skipping 14 matching lines...) Expand all Loading... | |
107 ClientMap::iterator it = clients_.find(ssrc); | 162 ClientMap::iterator it = clients_.find(ssrc); |
108 if (it == clients_.end()) { | 163 if (it == clients_.end()) { |
109 LOG(ERROR) << "Received cast message from for unknown SSRC: " << ssrc; | 164 LOG(ERROR) << "Received cast message from for unknown SSRC: " << ssrc; |
110 return; | 165 return; |
111 } | 166 } |
112 if (it->second.cast_message_cb.is_null()) | 167 if (it->second.cast_message_cb.is_null()) |
113 return; | 168 return; |
114 it->second.cast_message_cb.Run(cast_message); | 169 it->second.cast_message_cb.Run(cast_message); |
115 } | 170 } |
116 | 171 |
172 void CastTransportSenderIPC::OnReceivedPacket( | |
173 const media::cast::Packet& packet) { | |
174 if (!packet_callback_.is_null()) { | |
175 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | |
176 scoped_ptr<media::cast::Packet> packet_copy( | |
177 new media::cast::Packet(packet)); | |
178 packet_callback_.Run(packet_copy.Pass()); | |
179 } else { | |
180 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | |
181 } | |
182 } | |
183 | |
117 void CastTransportSenderIPC::Send(IPC::Message* message) { | 184 void CastTransportSenderIPC::Send(IPC::Message* message) { |
118 if (CastIPCDispatcher::Get()) { | 185 if (CastIPCDispatcher::Get()) { |
119 CastIPCDispatcher::Get()->Send(message); | 186 CastIPCDispatcher::Get()->Send(message); |
120 } else { | 187 } else { |
121 delete message; | 188 delete message; |
122 } | 189 } |
123 } | 190 } |
OLD | NEW |