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

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

Issue 1515023002: Simplify interface for media/cast: CastTransportSenderImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New interface and impl (no tests). Created 5 years 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
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 "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/common/cast_messages.h" 9 #include "chrome/common/cast_messages.h"
10 #include "components/net_log/chrome_net_log.h" 10 #include "components/net_log/chrome_net_log.h"
11 #include "content/public/browser/power_save_blocker.h" 11 #include "content/public/browser/power_save_blocker.h"
12 #include "media/cast/net/cast_transport_sender.h" 12 #include "media/cast/net/cast_transport_sender.h"
13 13
14 namespace { 14 namespace {
15 15
16 // How often to send raw events. 16 // How often to send raw events.
17 const int kSendRawEventsIntervalSecs = 1; 17 const int kSendRawEventsIntervalSecs = 1;
18 18
19 class TransportClient : public media::cast::CastTransportSender::Client {
20 public:
21 TransportClient(int32 channel_id,
22 cast::CastTransportHostFilter* cast_transport_host_filter)
23 : channel_id_(channel_id),
24 cast_transport_host_filter_(cast_transport_host_filter) {}
25
26 void OnStatusChange(media::cast::CastTransportStatus status) final;
27 void OnReceivedLoggingEvents(
28 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
29 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) final;
30 bool OnReceivedPackets(scoped_ptr<media::cast::Packet> packet) final;
31
32 private:
33 int32 channel_id_;
34 cast::CastTransportHostFilter* cast_transport_host_filter_;
35
36 DISALLOW_COPY_AND_ASSIGN(TransportClient);
37 };
38
39 void TransportClient::OnStatusChange(media::cast::CastTransportStatus status) {
40 DCHECK(cast_transport_host_filter_);
41 cast_transport_host_filter_->Send(
42 new CastMsg_NotifyStatusChange(channel_id_, status));
19 } 43 }
20 44
45 void TransportClient::OnReceivedLoggingEvents(
46 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
47 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) {
48 if (frame_events->empty() && packet_events->empty())
49 return;
50 DCHECK(cast_transport_host_filter_);
51 cast_transport_host_filter_->Send(
52 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events));
53 }
54
55 bool TransportClient::OnReceivedPackets(
56 scoped_ptr<media::cast::Packet> packet) {
57 DCHECK(cast_transport_host_filter_);
58 cast_transport_host_filter_->Send(
59 new CastMsg_ReceivedPacket(channel_id_, *packet));
60 return true;
61 }
62
63 } // namespace
64
21 namespace cast { 65 namespace cast {
22 66
23 CastTransportHostFilter::CastTransportHostFilter() 67 CastTransportHostFilter::CastTransportHostFilter()
24 : BrowserMessageFilter(CastMsgStart), 68 : BrowserMessageFilter(CastMsgStart),
25 weak_factory_(this) {} 69 weak_factory_(this) {}
26 70
27 CastTransportHostFilter::~CastTransportHostFilter() {} 71 CastTransportHostFilter::~CastTransportHostFilter() {}
28 72
29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { 73 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 74 bool handled = true;
(...skipping 11 matching lines...) Expand all
42 OnCancelSendingFrames) 86 OnCancelSendingFrames)
43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, 87 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc,
44 OnAddValidSsrc) 88 OnAddValidSsrc)
45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, 89 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver,
46 OnSendRtcpFromRtpReceiver) 90 OnSendRtcpFromRtpReceiver)
47 IPC_MESSAGE_UNHANDLED(handled = false); 91 IPC_MESSAGE_UNHANDLED(handled = false);
48 IPC_END_MESSAGE_MAP(); 92 IPC_END_MESSAGE_MAP();
49 return handled; 93 return handled;
50 } 94 }
51 95
52 void CastTransportHostFilter::ReceivedPacket(
53 int32 channel_id,
54 scoped_ptr<media::cast::Packet> packet) {
55 Send(new CastMsg_ReceivedPacket(channel_id, *packet));
56 }
57
58 void CastTransportHostFilter::NotifyStatusChange(
59 int32 channel_id,
60 media::cast::CastTransportStatus status) {
61 Send(new CastMsg_NotifyStatusChange(channel_id, status));
62 }
63
64 void CastTransportHostFilter::SendRawEvents(
65 int32 channel_id,
66 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
67 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) {
68 if (frame_events->empty() && packet_events->empty())
69 return;
70 Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events));
71 }
72
73 void CastTransportHostFilter::SendRtt(int32 channel_id, 96 void CastTransportHostFilter::SendRtt(int32 channel_id,
74 uint32 ssrc, 97 uint32 ssrc,
75 base::TimeDelta rtt) { 98 base::TimeDelta rtt) {
76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); 99 Send(new CastMsg_Rtt(channel_id, ssrc, rtt));
77 } 100 }
78 101
79 void CastTransportHostFilter::SendCastMessage( 102 void CastTransportHostFilter::SendCastMessage(
80 int32 channel_id, 103 int32 channel_id,
81 uint32 ssrc, 104 uint32 ssrc,
82 const media::cast::RtcpCastMessage& cast_message) { 105 const media::cast::RtcpCastMessage& cast_message) {
(...skipping 12 matching lines...) Expand all
95 content::PowerSaveBlocker::Create( 118 content::PowerSaveBlocker::Create(
96 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 119 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
97 content::PowerSaveBlocker::kReasonOther, 120 content::PowerSaveBlocker::kReasonOther,
98 "Cast is streaming content to a remote receiver").Pass(); 121 "Cast is streaming content to a remote receiver").Pass();
99 } 122 }
100 123
101 if (id_map_.Lookup(channel_id)) { 124 if (id_map_.Lookup(channel_id)) {
102 id_map_.Remove(channel_id); 125 id_map_.Remove(channel_id);
103 } 126 }
104 127
128 TransportClient client(channel_id, this);
Irfan 2015/12/15 22:23:13 I think we will want to make CastTransportHostFilt
xjz 2015/12/16 18:11:34 Done.
129 media::cast::CastTransportSender::CreateParams transport_params(
130 g_browser_process->net_log(), &clock_, local_end_point, remote_end_point,
131 &client, base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
132 make_scoped_ptr(options.DeepCopy()), base::ThreadTaskRunnerHandle::Get());
105 scoped_ptr<media::cast::CastTransportSender> sender = 133 scoped_ptr<media::cast::CastTransportSender> sender =
106 media::cast::CastTransportSender::Create( 134 media::cast::CastTransportSender::Create(transport_params);
107 g_browser_process->net_log(),
108 &clock_,
109 local_end_point,
110 remote_end_point,
111 make_scoped_ptr(options.DeepCopy()),
112 base::Bind(&CastTransportHostFilter::NotifyStatusChange,
113 weak_factory_.GetWeakPtr(),
114 channel_id),
115 base::Bind(&CastTransportHostFilter::SendRawEvents,
116 weak_factory_.GetWeakPtr(),
117 channel_id),
118 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
119 base::Bind(&CastTransportHostFilter::ReceivedPacket,
120 weak_factory_.GetWeakPtr(),
121 channel_id),
122 base::ThreadTaskRunnerHandle::Get());
123 id_map_.AddWithID(sender.release(), channel_id); 135 id_map_.AddWithID(sender.release(), channel_id);
124 } 136 }
125 137
126 void CastTransportHostFilter::OnDelete(int32 channel_id) { 138 void CastTransportHostFilter::OnDelete(int32 channel_id) {
127 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); 139 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id);
128 if (sender) { 140 if (sender) {
129 id_map_.Remove(channel_id); 141 id_map_.Remove(channel_id);
130 } else { 142 } else {
131 DVLOG(1) << "CastTransportHostFilter::Delete called " 143 DVLOG(1) << "CastTransportHostFilter::Delete called "
132 << "on non-existing channel"; 144 << "on non-existing channel";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 params.rtp_receiver_statistics.get()); 270 params.rtp_receiver_statistics.get());
259 } else { 271 } else {
260 DVLOG(1) 272 DVLOG(1)
261 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " 273 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver "
262 << "on non-existing channel"; 274 << "on non-existing channel";
263 } 275 }
264 } 276 }
265 277
266 278
267 } // namespace cast 279 } // namespace cast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698