Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 CastTransportSenderIPC::~CastTransportSenderIPC() { | 40 CastTransportSenderIPC::~CastTransportSenderIPC() { |
| 41 Send(new CastHostMsg_Delete(channel_id_)); | 41 Send(new CastHostMsg_Delete(channel_id_)); |
| 42 if (CastIPCDispatcher::Get()) { | 42 if (CastIPCDispatcher::Get()) { |
| 43 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 43 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CastTransportSenderIPC::InitializeAudio( | 47 void CastTransportSenderIPC::InitializeAudio( |
| 48 const media::cast::CastTransportRtpConfig& config, | 48 const media::cast::CastTransportRtpConfig& config, |
| 49 const media::cast::RtcpCastMessageCallback& cast_message_cb, | 49 const media::cast::RtcpCastMessageCallback& cast_message_cb, |
| 50 const media::cast::RtcpRttCallback& rtt_cb) { | 50 const media::cast::RtcpRttCallback& rtt_cb, |
| 51 const media::cast::RtcpPliCallback& pli_cb) { | |
| 51 clients_[config.ssrc].cast_message_cb = cast_message_cb; | 52 clients_[config.ssrc].cast_message_cb = cast_message_cb; |
| 52 clients_[config.ssrc].rtt_cb = rtt_cb; | 53 clients_[config.ssrc].rtt_cb = rtt_cb; |
| 54 clients_[config.ssrc].pli_cb = pli_cb; | |
| 53 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); | 55 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void CastTransportSenderIPC::InitializeVideo( | 58 void CastTransportSenderIPC::InitializeVideo( |
| 57 const media::cast::CastTransportRtpConfig& config, | 59 const media::cast::CastTransportRtpConfig& config, |
| 58 const media::cast::RtcpCastMessageCallback& cast_message_cb, | 60 const media::cast::RtcpCastMessageCallback& cast_message_cb, |
| 59 const media::cast::RtcpRttCallback& rtt_cb) { | 61 const media::cast::RtcpRttCallback& rtt_cb, |
| 62 const media::cast::RtcpPliCallback& pli_cb) { | |
| 60 clients_[config.ssrc].cast_message_cb = cast_message_cb; | 63 clients_[config.ssrc].cast_message_cb = cast_message_cb; |
| 61 clients_[config.ssrc].rtt_cb = rtt_cb; | 64 clients_[config.ssrc].rtt_cb = rtt_cb; |
| 65 clients_[config.ssrc].pli_cb = pli_cb; | |
| 62 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); | 66 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void CastTransportSenderIPC::InsertFrame( | 69 void CastTransportSenderIPC::InsertFrame( |
| 66 uint32_t ssrc, | 70 uint32_t ssrc, |
| 67 const media::cast::EncodedFrame& frame) { | 71 const media::cast::EncodedFrame& frame) { |
| 68 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); | 72 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void CastTransportSenderIPC::SendSenderReport( | 75 void CastTransportSenderIPC::SendSenderReport( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 95 | 99 |
| 96 void CastTransportSenderIPC::AddValidSsrc(uint32_t ssrc) { | 100 void CastTransportSenderIPC::AddValidSsrc(uint32_t ssrc) { |
| 97 Send(new CastHostMsg_AddValidSsrc(channel_id_, ssrc)); | 101 Send(new CastHostMsg_AddValidSsrc(channel_id_, ssrc)); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void CastTransportSenderIPC::SendRtcpFromRtpReceiver( | 104 void CastTransportSenderIPC::SendRtcpFromRtpReceiver( |
| 101 uint32_t ssrc, | 105 uint32_t ssrc, |
| 102 uint32_t sender_ssrc, | 106 uint32_t sender_ssrc, |
| 103 const media::cast::RtcpTimeData& time_data, | 107 const media::cast::RtcpTimeData& time_data, |
| 104 const media::cast::RtcpCastMessage* cast_message, | 108 const media::cast::RtcpCastMessage* cast_message, |
| 109 const media::cast::RtcpPliMessage* pli_message, | |
| 105 base::TimeDelta target_delay, | 110 base::TimeDelta target_delay, |
| 106 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, | 111 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
| 107 const media::cast::RtpReceiverStatistics* rtp_receiver_statistics) { | 112 const media::cast::RtpReceiverStatistics* rtp_receiver_statistics) { |
| 108 // To avoid copies, we put pointers to objects we don't really | 113 // To avoid copies, we put pointers to objects we don't really |
| 109 // own into scoped pointers and then very carefully extract them again | 114 // own into scoped pointers and then very carefully extract them again |
| 110 // before the scoped pointers go out of scope. | 115 // before the scoped pointers go out of scope. |
| 111 media::cast::SendRtcpFromRtpReceiver_Params params; | 116 media::cast::SendRtcpFromRtpReceiver_Params params; |
| 112 params.ssrc = ssrc; | 117 params.ssrc = ssrc; |
| 113 params.sender_ssrc = sender_ssrc; | 118 params.sender_ssrc = sender_ssrc; |
| 114 params.time_data = time_data; | 119 params.time_data = time_data; |
| 115 if (cast_message) { | 120 if (cast_message) { |
| 116 params.cast_message.reset( | 121 params.cast_message.reset( |
| 117 const_cast<media::cast::RtcpCastMessage*>(cast_message)); | 122 const_cast<media::cast::RtcpCastMessage*>(cast_message)); |
| 118 } | 123 } |
| 124 if (pli_message) { | |
| 125 params.pli_message.reset( | |
|
dcheng
2016/03/01 23:44:12
Maybe the parameters shouldn't be const?
xjz
2016/03/02 04:24:17
The const_cast is used here only for the purpose t
dcheng
2016/03/02 07:41:24
But what's the point of making it const? Either th
xjz
2016/03/16 00:25:50
Not applicable.
| |
| 126 const_cast<media::cast::RtcpPliMessage*>(pli_message)); | |
| 127 } | |
| 119 params.target_delay = target_delay; | 128 params.target_delay = target_delay; |
| 120 if (rtcp_events) { | 129 if (rtcp_events) { |
| 121 params.rtcp_events.reset( | 130 params.rtcp_events.reset( |
| 122 const_cast<media::cast::ReceiverRtcpEventSubscriber::RtcpEvents*>( | 131 const_cast<media::cast::ReceiverRtcpEventSubscriber::RtcpEvents*>( |
| 123 rtcp_events)); | 132 rtcp_events)); |
| 124 } | 133 } |
| 125 if (rtp_receiver_statistics) { | 134 if (rtp_receiver_statistics) { |
| 126 params.rtp_receiver_statistics.reset( | 135 params.rtp_receiver_statistics.reset( |
| 127 const_cast<media::cast::RtpReceiverStatistics*>( | 136 const_cast<media::cast::RtpReceiverStatistics*>( |
| 128 rtp_receiver_statistics)); | 137 rtp_receiver_statistics)); |
| 129 } | 138 } |
| 130 // Note, params contains scoped_ptr<>, but this still works because | 139 // Note, params contains scoped_ptr<>, but this still works because |
| 131 // CastHostMsg_SendRtcpFromRtpReceiver doesn't take ownership, it | 140 // CastHostMsg_SendRtcpFromRtpReceiver doesn't take ownership, it |
| 132 // serializes it and remember the serialized form instead. | 141 // serializes it and remember the serialized form instead. |
|
dcheng
2016/03/01 23:44:12
... so who frees this memory?
xjz
2016/03/02 04:24:17
It will be released below (line 146).
dcheng
2016/03/02 07:41:24
Reading the code, I understand how it works now: o
xjz
2016/03/16 00:25:50
Not applicable after refactor.
| |
| 133 Send(new CastHostMsg_SendRtcpFromRtpReceiver(channel_id_, params)); | 142 Send(new CastHostMsg_SendRtcpFromRtpReceiver(channel_id_, params)); |
| 134 | 143 |
| 135 ignore_result(params.rtp_receiver_statistics.release()); | 144 ignore_result(params.rtp_receiver_statistics.release()); |
| 136 ignore_result(params.cast_message.release()); | 145 ignore_result(params.cast_message.release()); |
| 146 ignore_result(params.pli_message.release()); | |
| 137 ignore_result(params.rtcp_events.release()); | 147 ignore_result(params.rtcp_events.release()); |
| 138 } | 148 } |
| 139 | 149 |
| 140 | 150 |
| 141 void CastTransportSenderIPC::OnNotifyStatusChange( | 151 void CastTransportSenderIPC::OnNotifyStatusChange( |
| 142 media::cast::CastTransportStatus status) { | 152 media::cast::CastTransportStatus status) { |
| 143 status_callback_.Run(status); | 153 status_callback_.Run(status); |
| 144 } | 154 } |
| 145 | 155 |
| 146 void CastTransportSenderIPC::OnRawEvents( | 156 void CastTransportSenderIPC::OnRawEvents( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 177 ClientMap::iterator it = clients_.find(ssrc); | 187 ClientMap::iterator it = clients_.find(ssrc); |
| 178 if (it == clients_.end()) { | 188 if (it == clients_.end()) { |
| 179 LOG(ERROR) << "Received cast message from for unknown SSRC: " << ssrc; | 189 LOG(ERROR) << "Received cast message from for unknown SSRC: " << ssrc; |
| 180 return; | 190 return; |
| 181 } | 191 } |
| 182 if (it->second.cast_message_cb.is_null()) | 192 if (it->second.cast_message_cb.is_null()) |
| 183 return; | 193 return; |
| 184 it->second.cast_message_cb.Run(cast_message); | 194 it->second.cast_message_cb.Run(cast_message); |
| 185 } | 195 } |
| 186 | 196 |
| 197 void CastTransportSenderIPC::OnReceivedPli(uint32_t ssrc) { | |
| 198 ClientMap::iterator it = clients_.find(ssrc); | |
| 199 if (it == clients_.end()) { | |
| 200 LOG(ERROR) << "Received picture loss indicator from for unknown SSRC: " | |
| 201 << ssrc; | |
| 202 return; | |
| 203 } | |
| 204 if (!it->second.pli_cb.is_null()) | |
| 205 it->second.pli_cb.Run(); | |
| 206 } | |
| 207 | |
| 187 void CastTransportSenderIPC::OnReceivedPacket( | 208 void CastTransportSenderIPC::OnReceivedPacket( |
| 188 const media::cast::Packet& packet) { | 209 const media::cast::Packet& packet) { |
| 189 if (!packet_callback_.is_null()) { | 210 if (!packet_callback_.is_null()) { |
| 190 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | 211 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? |
| 191 scoped_ptr<media::cast::Packet> packet_copy( | 212 scoped_ptr<media::cast::Packet> packet_copy( |
| 192 new media::cast::Packet(packet)); | 213 new media::cast::Packet(packet)); |
| 193 packet_callback_.Run(std::move(packet_copy)); | 214 packet_callback_.Run(std::move(packet_copy)); |
| 194 } else { | 215 } else { |
| 195 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | 216 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; |
| 196 } | 217 } |
| 197 } | 218 } |
| 198 | 219 |
| 199 void CastTransportSenderIPC::Send(IPC::Message* message) { | 220 void CastTransportSenderIPC::Send(IPC::Message* message) { |
| 200 if (CastIPCDispatcher::Get()) { | 221 if (CastIPCDispatcher::Get()) { |
| 201 CastIPCDispatcher::Get()->Send(message); | 222 CastIPCDispatcher::Get()->Send(message); |
| 202 } else { | 223 } else { |
| 203 delete message; | 224 delete message; |
| 204 } | 225 } |
| 205 } | 226 } |
| OLD | NEW |