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() {} | |
15 CastTransportSenderIPC::ClientCallbacks::~ClientCallbacks() {} | |
16 | |
14 CastTransportSenderIPC::CastTransportSenderIPC( | 17 CastTransportSenderIPC::CastTransportSenderIPC( |
15 const net::IPEndPoint& remote_end_point, | 18 const net::IPEndPoint& remote_end_point, |
16 const media::cast::CastTransportStatusCallback& status_cb, | 19 const media::cast::CastTransportStatusCallback& status_cb, |
17 const media::cast::BulkRawEventsCallback& raw_events_cb) | 20 const media::cast::BulkRawEventsCallback& raw_events_cb) |
18 : status_callback_(status_cb), raw_events_callback_(raw_events_cb) { | 21 : status_callback_(status_cb), raw_events_callback_(raw_events_cb) { |
19 if (CastIPCDispatcher::Get()) { | 22 if (CastIPCDispatcher::Get()) { |
20 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); | 23 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); |
21 } | 24 } |
22 Send(new CastHostMsg_New(channel_id_, remote_end_point)); | 25 Send(new CastHostMsg_New(channel_id_, remote_end_point)); |
23 } | 26 } |
24 | 27 |
25 CastTransportSenderIPC::~CastTransportSenderIPC() { | 28 CastTransportSenderIPC::~CastTransportSenderIPC() { |
26 Send(new CastHostMsg_Delete(channel_id_)); | 29 Send(new CastHostMsg_Delete(channel_id_)); |
27 if (CastIPCDispatcher::Get()) { | 30 if (CastIPCDispatcher::Get()) { |
28 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 31 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
29 } | 32 } |
30 } | 33 } |
31 | 34 |
32 void CastTransportSenderIPC::SetPacketReceiver( | |
33 const media::cast::PacketReceiverCallback& packet_callback) { | |
34 packet_callback_ = packet_callback; | |
35 } | |
36 | |
37 void CastTransportSenderIPC::InitializeAudio( | 35 void CastTransportSenderIPC::InitializeAudio( |
38 const media::cast::CastTransportRtpConfig& config) { | 36 const media::cast::CastTransportRtpConfig& config, |
37 const media::cast::RtcpCastMessageCallback& cast_message_cb, | |
38 const media::cast::RtcpRttCallback& rtt_cb) { | |
39 clients_[config.ssrc].cast_message_cb = cast_message_cb; | |
40 clients_[config.ssrc].rtt_cb = rtt_cb; | |
39 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); | 41 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); |
40 } | 42 } |
41 | 43 |
42 void CastTransportSenderIPC::InitializeVideo( | 44 void CastTransportSenderIPC::InitializeVideo( |
43 const media::cast::CastTransportRtpConfig& config) { | 45 const media::cast::CastTransportRtpConfig& config, |
46 const media::cast::RtcpCastMessageCallback& cast_message_cb, | |
47 const media::cast::RtcpRttCallback& rtt_cb) { | |
48 clients_[config.ssrc].cast_message_cb = cast_message_cb; | |
49 clients_[config.ssrc].rtt_cb = rtt_cb; | |
44 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); | 50 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); |
45 } | 51 } |
46 | 52 |
47 void CastTransportSenderIPC::InsertCodedAudioFrame( | 53 void CastTransportSenderIPC::InsertCodedAudioFrame( |
48 const media::cast::EncodedFrame& audio_frame) { | 54 const media::cast::EncodedFrame& audio_frame) { |
49 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, audio_frame)); | 55 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, audio_frame)); |
50 } | 56 } |
51 | 57 |
52 void CastTransportSenderIPC::InsertCodedVideoFrame( | 58 void CastTransportSenderIPC::InsertCodedVideoFrame( |
53 const media::cast::EncodedFrame& video_frame) { | 59 const media::cast::EncodedFrame& video_frame) { |
54 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, video_frame)); | 60 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, video_frame)); |
55 } | 61 } |
56 | 62 |
57 void CastTransportSenderIPC::SendRtcpFromRtpSender( | 63 void CastTransportSenderIPC::SendSenderReport( |
58 uint32 packet_type_flags, | 64 uint32 ssrc, |
59 uint32 ntp_seconds, | 65 base::TimeTicks current_time, |
60 uint32 ntp_fraction, | 66 uint32 current_time_as_rtp_timestamp) { |
61 uint32 rtp_timestamp, | 67 Send(new CastHostMsg_SendSenderReport(channel_id_, |
62 const media::cast::RtcpDlrrReportBlock& dlrr, | 68 ssrc, |
63 uint32 sending_ssrc, | 69 current_time, |
64 const std::string& c_name) { | 70 current_time_as_rtp_timestamp)); |
65 struct media::cast::SendRtcpFromRtpSenderData data; | |
66 data.packet_type_flags = packet_type_flags; | |
67 data.sending_ssrc = sending_ssrc; | |
68 data.c_name = c_name; | |
69 data.ntp_seconds = ntp_seconds; | |
70 data.ntp_fraction = ntp_fraction; | |
71 data.rtp_timestamp = rtp_timestamp; | |
72 Send(new CastHostMsg_SendRtcpFromRtpSender( | |
73 channel_id_, | |
74 data, | |
75 dlrr)); | |
76 } | 71 } |
77 | 72 |
78 void CastTransportSenderIPC::ResendPackets( | 73 void CastTransportSenderIPC::ResendPackets( |
79 bool is_audio, | 74 bool is_audio, |
80 const media::cast::MissingFramesAndPacketsMap& missing_packets, | 75 const media::cast::MissingFramesAndPacketsMap& missing_packets, |
81 bool cancel_rtx_if_not_in_list, | 76 bool cancel_rtx_if_not_in_list, |
82 base::TimeDelta dedupe_window) { | 77 base::TimeDelta dedupe_window) { |
83 Send(new CastHostMsg_ResendPackets(channel_id_, | 78 Send(new CastHostMsg_ResendPackets(channel_id_, |
84 is_audio, | 79 is_audio, |
85 missing_packets, | 80 missing_packets, |
86 cancel_rtx_if_not_in_list, | 81 cancel_rtx_if_not_in_list, |
87 dedupe_window)); | 82 dedupe_window)); |
88 } | 83 } |
89 | 84 |
90 void CastTransportSenderIPC::OnReceivedPacket( | |
91 const media::cast::Packet& packet) { | |
92 if (!packet_callback_.is_null()) { | |
93 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | |
94 scoped_ptr<media::cast::Packet> packet_copy( | |
95 new media::cast::Packet(packet)); | |
96 packet_callback_.Run(packet_copy.Pass()); | |
97 } else { | |
98 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | |
99 } | |
100 } | |
101 | |
102 void CastTransportSenderIPC::OnNotifyStatusChange( | 85 void CastTransportSenderIPC::OnNotifyStatusChange( |
103 media::cast::CastTransportStatus status) { | 86 media::cast::CastTransportStatus status) { |
104 status_callback_.Run(status); | 87 status_callback_.Run(status); |
105 } | 88 } |
106 | 89 |
107 void CastTransportSenderIPC::OnRawEvents( | 90 void CastTransportSenderIPC::OnRawEvents( |
108 const std::vector<media::cast::PacketEvent>& packet_events) { | 91 const std::vector<media::cast::PacketEvent>& packet_events, |
109 raw_events_callback_.Run(packet_events); | 92 const std::vector<media::cast::FrameEvent>& frame_events) { |
93 raw_events_callback_.Run(packet_events, frame_events); | |
94 } | |
95 | |
96 void CastTransportSenderIPC::OnRtt( | |
97 uint32 ssrc, | |
98 const media::cast::RtcpRttReport& rtt_report) { | |
99 if (clients_.find(ssrc) == clients_.end()) { | |
miu
2014/07/18 00:06:23
This code is doing 3 map look-ups. Consider just
Alpha Left Google
2014/07/18 01:14:30
Done.
| |
100 LOG(ERROR) << "Received RTT report from for unknown SSRC: " << ssrc; | |
101 return; | |
102 } | |
103 if (clients_[ssrc].rtt_cb.is_null()) | |
104 return; | |
105 clients_[ssrc].rtt_cb.Run( | |
106 rtt_report.rtt, | |
107 rtt_report.avg_rtt, | |
108 rtt_report.min_rtt, | |
109 rtt_report.max_rtt); | |
110 } | |
111 | |
112 void CastTransportSenderIPC::OnRtcpCastMessage( | |
113 uint32 ssrc, | |
114 const media::cast::RtcpCastMessage& cast_message) { | |
115 if (clients_.find(ssrc) == clients_.end()) { | |
miu
2014/07/18 00:06:23
ditto: Use an iterator.
Alpha Left Google
2014/07/18 01:14:30
Done.
| |
116 LOG(ERROR) << "Received cast message from for unknown SSRC: " << ssrc; | |
117 return; | |
118 } | |
119 if (clients_[ssrc].cast_message_cb.is_null()) | |
120 return; | |
121 clients_[ssrc].cast_message_cb.Run(cast_message); | |
110 } | 122 } |
111 | 123 |
112 void CastTransportSenderIPC::Send(IPC::Message* message) { | 124 void CastTransportSenderIPC::Send(IPC::Message* message) { |
113 if (CastIPCDispatcher::Get()) { | 125 if (CastIPCDispatcher::Get()) { |
114 CastIPCDispatcher::Get()->Send(message); | 126 CastIPCDispatcher::Get()->Send(message); |
115 } else { | 127 } else { |
116 delete message; | 128 delete message; |
117 } | 129 } |
118 } | 130 } |
OLD | NEW |