Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: chrome/browser/media/cast_transport_host_filter.cc

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ipc changes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/media/cast_transport_host_filter.h" 5 #include "chrome/browser/media/cast_transport_host_filter.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/net/chrome_net_log.h" 8 #include "chrome/browser/net/chrome_net_log.h"
9 #include "media/cast/net/cast_transport_sender.h" 9 #include "media/cast/net/cast_transport_sender.h"
10 10
(...skipping 15 matching lines...) Expand all
26 bool handled = true; 26 bool handled = true;
27 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message) 27 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message)
28 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew) 28 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew)
29 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete) 29 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete)
30 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio) 30 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio)
31 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo) 31 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo)
32 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame, 32 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame,
33 OnInsertCodedAudioFrame) 33 OnInsertCodedAudioFrame)
34 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame, 34 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame,
35 OnInsertCodedVideoFrame) 35 OnInsertCodedVideoFrame)
36 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpSender, 36 IPC_MESSAGE_HANDLER(CastHostMsg_SendSenderReport,
37 OnSendRtcpFromRtpSender) 37 OnSendSenderReport)
38 IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets, 38 IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets,
39 OnResendPackets) 39 OnResendPackets)
40 IPC_MESSAGE_UNHANDLED(handled = false); 40 IPC_MESSAGE_UNHANDLED(handled = false);
41 IPC_END_MESSAGE_MAP(); 41 IPC_END_MESSAGE_MAP();
42 return handled; 42 return handled;
43 } 43 }
44 44
45 void CastTransportHostFilter::NotifyStatusChange( 45 void CastTransportHostFilter::NotifyStatusChange(
46 int32 channel_id, 46 int32 channel_id,
47 media::cast::CastTransportStatus status) { 47 media::cast::CastTransportStatus status) {
48 Send(new CastMsg_NotifyStatusChange(channel_id, status)); 48 Send(new CastMsg_NotifyStatusChange(channel_id, status));
49 } 49 }
50 50
51 void CastTransportHostFilter::ReceivedPacket(
52 int32 channel_id,
53 scoped_ptr<media::cast::Packet> packet) {
54 Send(new CastMsg_ReceivedPacket(channel_id, *packet));
55 }
56
57 void CastTransportHostFilter::RawEvents( 51 void CastTransportHostFilter::RawEvents(
58 int32 channel_id, 52 int32 channel_id,
59 const std::vector<media::cast::PacketEvent>& packet_events) { 53 const std::vector<media::cast::PacketEvent>& packet_events,
54 const std::vector<media::cast::FrameEvent>& frame_events) {
60 if (!packet_events.empty()) 55 if (!packet_events.empty())
61 Send(new CastMsg_RawEvents(channel_id, packet_events)); 56 Send(new CastMsg_RawEvents(channel_id,
57 packet_events,
58 frame_events));
59 }
60
61 void CastTransportHostFilter::Rtt(int32 channel_id,
62 uint32 ssrc,
63 base::TimeDelta rtt,
64 base::TimeDelta avg_rtt,
65 base::TimeDelta min_rtt,
66 base::TimeDelta max_rtt) {
67 media::cast::RtcpRttReport report;
68 report.rtt = rtt;
69 report.avg_rtt = avg_rtt;
70 report.min_rtt = min_rtt;
71 report.max_rtt = max_rtt;
72 Send(new CastMsg_Rtt(channel_id, ssrc, report));
73 }
74
75 void CastTransportHostFilter::CastMessage(
76 int32 channel_id,
77 uint32 ssrc,
78 const media::cast::RtcpCastMessage& cast_message) {
79 Send(new CastMsg_RtcpCastMessage(channel_id, ssrc, cast_message));
62 } 80 }
63 81
64 void CastTransportHostFilter::OnNew( 82 void CastTransportHostFilter::OnNew(
65 int32 channel_id, 83 int32 channel_id,
66 const net::IPEndPoint& remote_end_point) { 84 const net::IPEndPoint& remote_end_point) {
67 if (id_map_.Lookup(channel_id)) { 85 if (id_map_.Lookup(channel_id)) {
68 id_map_.Remove(channel_id); 86 id_map_.Remove(channel_id);
69 } 87 }
70 88
71 scoped_ptr<media::cast::CastTransportSender> sender = 89 scoped_ptr<media::cast::CastTransportSender> sender =
72 media::cast::CastTransportSender::Create( 90 media::cast::CastTransportSender::Create(
73 g_browser_process->net_log(), 91 g_browser_process->net_log(),
74 &clock_, 92 &clock_,
75 remote_end_point, 93 remote_end_point,
76 base::Bind(&CastTransportHostFilter::NotifyStatusChange, 94 base::Bind(&CastTransportHostFilter::NotifyStatusChange,
77 base::Unretained(this), 95 base::Unretained(this),
78 channel_id), 96 channel_id),
79 base::Bind(&CastTransportHostFilter::RawEvents, 97 base::Bind(&CastTransportHostFilter::RawEvents,
80 base::Unretained(this), 98 base::Unretained(this),
81 channel_id), 99 channel_id),
82 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), 100 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
83 base::MessageLoopProxy::current()); 101 base::MessageLoopProxy::current());
84
85 sender->SetPacketReceiver(base::Bind(&CastTransportHostFilter::ReceivedPacket,
86 base::Unretained(this),
87 channel_id));
88
89 id_map_.AddWithID(sender.release(), channel_id); 102 id_map_.AddWithID(sender.release(), channel_id);
90 } 103 }
91 104
92 void CastTransportHostFilter::OnDelete(int32 channel_id) { 105 void CastTransportHostFilter::OnDelete(int32 channel_id) {
93 media::cast::CastTransportSender* sender = 106 media::cast::CastTransportSender* sender =
94 id_map_.Lookup(channel_id); 107 id_map_.Lookup(channel_id);
95 if (sender) { 108 if (sender) {
96 id_map_.Remove(channel_id); 109 id_map_.Remove(channel_id);
97 } else { 110 } else {
98 DVLOG(1) << "CastTransportHostFilter::Delete called " 111 DVLOG(1) << "CastTransportHostFilter::Delete called "
99 << "on non-existing channel"; 112 << "on non-existing channel";
100 } 113 }
101 } 114 }
102 115
103 void CastTransportHostFilter::OnInitializeAudio( 116 void CastTransportHostFilter::OnInitializeAudio(
104 int32 channel_id, 117 int32 channel_id,
105 const media::cast::CastTransportRtpConfig& config) { 118 const media::cast::CastTransportRtpConfig& config) {
106 media::cast::CastTransportSender* sender = 119 media::cast::CastTransportSender* sender =
107 id_map_.Lookup(channel_id); 120 id_map_.Lookup(channel_id);
108 if (sender) { 121 if (sender) {
109 sender->InitializeAudio(config); 122 sender->InitializeAudio(
123 config,
124 base::Bind(&CastTransportHostFilter::CastMessage,
miu 2014/07/18 00:06:22 The base::Unretained() makes me nervous. Can you
Alpha Left Google 2014/07/18 01:14:30 Changed it to WeakPtr.
125 base::Unretained(this),
126 channel_id, config.ssrc),
127 base::Bind(&CastTransportHostFilter::Rtt,
128 base::Unretained(this),
129 channel_id, config.ssrc));
110 } else { 130 } else {
111 DVLOG(1) 131 DVLOG(1)
112 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; 132 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel";
113 } 133 }
114 } 134 }
115 135
116 void CastTransportHostFilter::OnInitializeVideo( 136 void CastTransportHostFilter::OnInitializeVideo(
117 int32 channel_id, 137 int32 channel_id,
118 const media::cast::CastTransportRtpConfig& config) { 138 const media::cast::CastTransportRtpConfig& config) {
119 media::cast::CastTransportSender* sender = 139 media::cast::CastTransportSender* sender =
120 id_map_.Lookup(channel_id); 140 id_map_.Lookup(channel_id);
121 if (sender) { 141 if (sender) {
122 sender->InitializeVideo(config); 142 sender->InitializeVideo(
143 config,
144 base::Bind(&CastTransportHostFilter::CastMessage,
145 base::Unretained(this),
146 channel_id, config.ssrc),
147 base::Bind(&CastTransportHostFilter::Rtt,
148 base::Unretained(this),
149 channel_id, config.ssrc));
123 } else { 150 } else {
124 DVLOG(1) 151 DVLOG(1)
125 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; 152 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel";
126 } 153 }
127 } 154 }
128 155
129 void CastTransportHostFilter::OnInsertCodedAudioFrame( 156 void CastTransportHostFilter::OnInsertCodedAudioFrame(
130 int32 channel_id, 157 int32 channel_id,
131 const media::cast::EncodedFrame& audio_frame) { 158 const media::cast::EncodedFrame& audio_frame) {
132 media::cast::CastTransportSender* sender = 159 media::cast::CastTransportSender* sender =
(...skipping 14 matching lines...) Expand all
147 id_map_.Lookup(channel_id); 174 id_map_.Lookup(channel_id);
148 if (sender) { 175 if (sender) {
149 sender->InsertCodedVideoFrame(video_frame); 176 sender->InsertCodedVideoFrame(video_frame);
150 } else { 177 } else {
151 DVLOG(1) 178 DVLOG(1)
152 << "CastTransportHostFilter::OnInsertCodedVideoFrame " 179 << "CastTransportHostFilter::OnInsertCodedVideoFrame "
153 << "on non-existing channel"; 180 << "on non-existing channel";
154 } 181 }
155 } 182 }
156 183
157 void CastTransportHostFilter::OnSendRtcpFromRtpSender( 184 void CastTransportHostFilter::OnSendSenderReport(
158 int32 channel_id, 185 int32 channel_id,
159 const media::cast::SendRtcpFromRtpSenderData& data, 186 uint32 ssrc,
160 const media::cast::RtcpDlrrReportBlock& dlrr) { 187 base::TimeTicks current_time,
188 uint32 current_time_as_rtp_timestamp) {
161 media::cast::CastTransportSender* sender = 189 media::cast::CastTransportSender* sender =
162 id_map_.Lookup(channel_id); 190 id_map_.Lookup(channel_id);
163 if (sender) { 191 if (sender) {
164 sender->SendRtcpFromRtpSender(data.packet_type_flags, 192 sender->SendSenderReport(ssrc,
165 data.ntp_seconds, 193 current_time,
166 data.ntp_fraction, 194 current_time_as_rtp_timestamp);
167 data.rtp_timestamp,
168 dlrr,
169 data.sending_ssrc,
170 data.c_name);
171 } else { 195 } else {
172 DVLOG(1) 196 DVLOG(1)
173 << "CastTransportHostFilter::OnSendRtcpFromRtpSender " 197 << "CastTransportHostFilter::OnSendSenderReport "
174 << "on non-existing channel"; 198 << "on non-existing channel";
175 } 199 }
176 } 200 }
177 201
178 void CastTransportHostFilter::OnResendPackets( 202 void CastTransportHostFilter::OnResendPackets(
179 int32 channel_id, 203 int32 channel_id,
180 bool is_audio, 204 bool is_audio,
181 const media::cast::MissingFramesAndPacketsMap& missing_packets, 205 const media::cast::MissingFramesAndPacketsMap& missing_packets,
182 bool cancel_rtx_if_not_in_list, 206 bool cancel_rtx_if_not_in_list,
183 base::TimeDelta dedupe_window) { 207 base::TimeDelta dedupe_window) {
184 media::cast::CastTransportSender* sender = 208 media::cast::CastTransportSender* sender =
185 id_map_.Lookup(channel_id); 209 id_map_.Lookup(channel_id);
186 if (sender) { 210 if (sender) {
187 sender->ResendPackets( 211 sender->ResendPackets(
188 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); 212 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window);
189 } else { 213 } else {
190 DVLOG(1) 214 DVLOG(1)
191 << "CastTransportHostFilter::OnResendPackets on non-existing channel"; 215 << "CastTransportHostFilter::OnResendPackets on non-existing channel";
192 } 216 }
193 } 217 }
194 218
195 } // namespace cast 219 } // namespace cast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698