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_ipc.h" | 5 #include "chrome/renderer/media/cast_transport_ipc.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "chrome/common/cast_messages.h" | 12 #include "chrome/common/cast_messages.h" |
| 13 #include "chrome/renderer/media/cast_ipc_dispatcher.h" | 13 #include "chrome/renderer/media/cast_ipc_dispatcher.h" |
| 14 #include "ipc/ipc_channel_proxy.h" | 14 #include "ipc/ipc_channel_proxy.h" |
| 15 #include "media/cast/cast_sender.h" | 15 #include "media/cast/cast_sender.h" |
| 16 | 16 |
| 17 CastTransportIPC::CastTransportIPC( | 17 CastTransportIPC::CastTransportIPC( |
| 18 const net::IPEndPoint& local_end_point, | 18 const net::IPEndPoint& local_end_point, |
| 19 const net::IPEndPoint& remote_end_point, | 19 const net::IPEndPoint& remote_end_point, |
| 20 std::unique_ptr<base::DictionaryValue> options, | 20 std::unique_ptr<base::DictionaryValue> options, |
| 21 const media::cast::PacketReceiverCallback& packet_callback, | 21 const media::cast::PacketReceiverCallback& packet_callback, |
| 22 const media::cast::CastTransportStatusCallback& status_cb, | 22 const media::cast::CastTransportStatusCallback& status_cb, |
| 23 const media::cast::BulkRawEventsCallback& raw_events_cb) | 23 const media::cast::BulkRawEventsCallback& raw_events_cb) |
| 24 : packet_callback_(packet_callback), | 24 : channel_id_(-1), |
| 25 packet_callback_(packet_callback), | |
| 25 status_callback_(status_cb), | 26 status_callback_(status_cb), |
| 26 raw_events_callback_(raw_events_cb) { | 27 raw_events_callback_(raw_events_cb) { |
| 27 if (CastIPCDispatcher::Get()) { | 28 if (CastIPCDispatcher::Get()) { |
|
miu
2016/11/21 20:21:50
Note: It's unfortunate that the original author of
| |
| 28 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); | 29 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); |
| 30 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point, | |
| 31 *options)); | |
| 29 } | 32 } |
| 30 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point, | |
| 31 *options)); | |
| 32 } | 33 } |
| 33 | 34 |
| 34 CastTransportIPC::~CastTransportIPC() { | 35 CastTransportIPC::~CastTransportIPC() { |
| 35 Send(new CastHostMsg_Delete(channel_id_)); | 36 if (channel_id_ != -1) { |
| 37 Send(new CastHostMsg_Delete(channel_id_)); | |
| 38 } | |
| 36 if (CastIPCDispatcher::Get()) { | 39 if (CastIPCDispatcher::Get()) { |
| 37 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 40 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
| 38 } | 41 } |
| 39 } | 42 } |
| 40 | 43 |
| 41 void CastTransportIPC::InitializeStream( | 44 void CastTransportIPC::InitializeStream( |
| 42 const media::cast::CastTransportRtpConfig& config, | 45 const media::cast::CastTransportRtpConfig& config, |
| 43 std::unique_ptr<media::cast::RtcpObserver> rtcp_observer) { | 46 std::unique_ptr<media::cast::RtcpObserver> rtcp_observer) { |
| 44 if (rtcp_observer) { | 47 if (rtcp_observer) { |
| 45 DCHECK(clients_.find(config.ssrc) == clients_.end()); | 48 DCHECK(clients_.find(config.ssrc) == clients_.end()); |
| 46 clients_[config.ssrc] = std::move(rtcp_observer); | 49 clients_[config.ssrc] = std::move(rtcp_observer); |
| 47 } | 50 } |
| 51 DCHECK(channel_id_ != -1); | |
| 48 Send(new CastHostMsg_InitializeStream(channel_id_, config)); | 52 Send(new CastHostMsg_InitializeStream(channel_id_, config)); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void CastTransportIPC::InsertFrame(uint32_t ssrc, | 55 void CastTransportIPC::InsertFrame(uint32_t ssrc, |
| 52 const media::cast::EncodedFrame& frame) { | 56 const media::cast::EncodedFrame& frame) { |
| 57 DCHECK(channel_id_ != -1); | |
| 53 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); | 58 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void CastTransportIPC::SendSenderReport( | 61 void CastTransportIPC::SendSenderReport( |
| 57 uint32_t ssrc, | 62 uint32_t ssrc, |
| 58 base::TimeTicks current_time, | 63 base::TimeTicks current_time, |
| 59 media::cast::RtpTimeTicks current_time_as_rtp_timestamp) { | 64 media::cast::RtpTimeTicks current_time_as_rtp_timestamp) { |
| 65 DCHECK(channel_id_ != -1); | |
| 60 Send(new CastHostMsg_SendSenderReport(channel_id_, ssrc, current_time, | 66 Send(new CastHostMsg_SendSenderReport(channel_id_, ssrc, current_time, |
| 61 current_time_as_rtp_timestamp)); | 67 current_time_as_rtp_timestamp)); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void CastTransportIPC::CancelSendingFrames( | 70 void CastTransportIPC::CancelSendingFrames( |
| 65 uint32_t ssrc, | 71 uint32_t ssrc, |
| 66 const std::vector<media::cast::FrameId>& frame_ids) { | 72 const std::vector<media::cast::FrameId>& frame_ids) { |
| 73 DCHECK(channel_id_ != -1); | |
| 67 Send(new CastHostMsg_CancelSendingFrames(channel_id_, ssrc, frame_ids)); | 74 Send(new CastHostMsg_CancelSendingFrames(channel_id_, ssrc, frame_ids)); |
| 68 } | 75 } |
| 69 | 76 |
| 70 void CastTransportIPC::ResendFrameForKickstart(uint32_t ssrc, | 77 void CastTransportIPC::ResendFrameForKickstart(uint32_t ssrc, |
| 71 media::cast::FrameId frame_id) { | 78 media::cast::FrameId frame_id) { |
| 79 DCHECK(channel_id_ != -1); | |
| 72 Send(new CastHostMsg_ResendFrameForKickstart(channel_id_, ssrc, frame_id)); | 80 Send(new CastHostMsg_ResendFrameForKickstart(channel_id_, ssrc, frame_id)); |
| 73 } | 81 } |
| 74 | 82 |
| 75 void CastTransportIPC::AddValidRtpReceiver(uint32_t rtp_sender_ssrc, | 83 void CastTransportIPC::AddValidRtpReceiver(uint32_t rtp_sender_ssrc, |
| 76 uint32_t rtp_receiver_ssrc) { | 84 uint32_t rtp_receiver_ssrc) { |
| 85 DCHECK(channel_id_ != -1); | |
| 77 Send(new CastHostMsg_AddValidRtpReceiver(channel_id_, rtp_sender_ssrc, | 86 Send(new CastHostMsg_AddValidRtpReceiver(channel_id_, rtp_sender_ssrc, |
| 78 rtp_receiver_ssrc)); | 87 rtp_receiver_ssrc)); |
| 79 } | 88 } |
| 80 | 89 |
| 81 void CastTransportIPC::InitializeRtpReceiverRtcpBuilder( | 90 void CastTransportIPC::InitializeRtpReceiverRtcpBuilder( |
| 82 uint32_t rtp_receiver_ssrc, | 91 uint32_t rtp_receiver_ssrc, |
| 83 const media::cast::RtcpTimeData& time_data) { | 92 const media::cast::RtcpTimeData& time_data) { |
| 93 DCHECK(channel_id_ != -1); | |
| 84 Send(new CastHostMsg_InitializeRtpReceiverRtcpBuilder( | 94 Send(new CastHostMsg_InitializeRtpReceiverRtcpBuilder( |
| 85 channel_id_, rtp_receiver_ssrc, time_data)); | 95 channel_id_, rtp_receiver_ssrc, time_data)); |
| 86 } | 96 } |
| 87 | 97 |
| 88 void CastTransportIPC::AddCastFeedback( | 98 void CastTransportIPC::AddCastFeedback( |
| 89 const media::cast::RtcpCastMessage& cast_message, | 99 const media::cast::RtcpCastMessage& cast_message, |
| 90 base::TimeDelta target_delay) { | 100 base::TimeDelta target_delay) { |
| 101 DCHECK(channel_id_ != -1); | |
| 91 Send( | 102 Send( |
| 92 new CastHostMsg_AddCastFeedback(channel_id_, cast_message, target_delay)); | 103 new CastHostMsg_AddCastFeedback(channel_id_, cast_message, target_delay)); |
| 93 } | 104 } |
| 94 | 105 |
| 95 void CastTransportIPC::AddPli(const media::cast::RtcpPliMessage& pli_message) { | 106 void CastTransportIPC::AddPli(const media::cast::RtcpPliMessage& pli_message) { |
| 107 DCHECK(channel_id_ != -1); | |
| 96 Send(new CastHostMsg_AddPli(channel_id_, pli_message)); | 108 Send(new CastHostMsg_AddPli(channel_id_, pli_message)); |
| 97 } | 109 } |
| 98 | 110 |
| 99 void CastTransportIPC::AddRtcpEvents( | 111 void CastTransportIPC::AddRtcpEvents( |
| 100 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) { | 112 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) { |
| 113 DCHECK(channel_id_ != -1); | |
| 101 Send(new CastHostMsg_AddRtcpEvents(channel_id_, rtcp_events)); | 114 Send(new CastHostMsg_AddRtcpEvents(channel_id_, rtcp_events)); |
| 102 } | 115 } |
| 103 | 116 |
| 104 void CastTransportIPC::AddRtpReceiverReport( | 117 void CastTransportIPC::AddRtpReceiverReport( |
| 105 const media::cast::RtcpReportBlock& rtp_receiver_report_block) { | 118 const media::cast::RtcpReportBlock& rtp_receiver_report_block) { |
| 119 DCHECK(channel_id_ != -1); | |
| 106 Send(new CastHostMsg_AddRtpReceiverReport(channel_id_, | 120 Send(new CastHostMsg_AddRtpReceiverReport(channel_id_, |
| 107 rtp_receiver_report_block)); | 121 rtp_receiver_report_block)); |
| 108 } | 122 } |
| 109 | 123 |
| 110 void CastTransportIPC::SendRtcpFromRtpReceiver() { | 124 void CastTransportIPC::SendRtcpFromRtpReceiver() { |
| 125 DCHECK(channel_id_ != -1); | |
| 111 Send(new CastHostMsg_SendRtcpFromRtpReceiver(channel_id_)); | 126 Send(new CastHostMsg_SendRtcpFromRtpReceiver(channel_id_)); |
| 112 } | 127 } |
| 113 | 128 |
| 114 void CastTransportIPC::OnNotifyStatusChange( | 129 void CastTransportIPC::OnNotifyStatusChange( |
| 115 media::cast::CastTransportStatus status) { | 130 media::cast::CastTransportStatus status) { |
| 116 status_callback_.Run(status); | 131 status_callback_.Run(status); |
| 117 } | 132 } |
| 118 | 133 |
| 119 void CastTransportIPC::OnRawEvents( | 134 void CastTransportIPC::OnRawEvents( |
| 120 const std::vector<media::cast::PacketEvent>& packet_events, | 135 const std::vector<media::cast::PacketEvent>& packet_events, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | 184 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? |
| 170 std::unique_ptr<media::cast::Packet> packet_copy( | 185 std::unique_ptr<media::cast::Packet> packet_copy( |
| 171 new media::cast::Packet(packet)); | 186 new media::cast::Packet(packet)); |
| 172 packet_callback_.Run(std::move(packet_copy)); | 187 packet_callback_.Run(std::move(packet_copy)); |
| 173 } else { | 188 } else { |
| 174 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | 189 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; |
| 175 } | 190 } |
| 176 } | 191 } |
| 177 | 192 |
| 178 void CastTransportIPC::Send(IPC::Message* message) { | 193 void CastTransportIPC::Send(IPC::Message* message) { |
| 179 if (CastIPCDispatcher::Get()) { | 194 if (CastIPCDispatcher::Get()) { |
|
miu
2016/11/21 20:21:50
Suggestion for simplifying: If you change this to
| |
| 180 CastIPCDispatcher::Get()->Send(message); | 195 CastIPCDispatcher::Get()->Send(message); |
| 181 } else { | 196 } else { |
| 182 delete message; | 197 delete message; |
| 183 } | 198 } |
| 184 } | 199 } |
| OLD | NEW |