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

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: 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(
22 int32 channel_id,
23 base::WeakPtr<cast::CastTransportHostFilter> cast_transport_host_filter)
Irfan 2015/12/16 22:37:04 If you use WeakPtr, I think you will want to valid
imcheng 2015/12/17 00:18:10 +1 on raw pointer. Looks like this class is ultima
xjz 2015/12/17 22:54:57 Done. Use raw pointer.
24 : channel_id_(channel_id),
25 cast_transport_host_filter_(cast_transport_host_filter) {}
26
27 void OnStatusChange(media::cast::CastTransportStatus status) final;
imcheng 2015/12/17 00:18:10 nit on naming: I would probably name these OnStatu
xjz 2015/12/17 22:54:57 Done.
28 void OnReceivedLoggingEvents(
29 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
30 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) final;
31 void OnReceivedPackets(scoped_ptr<media::cast::Packet> packet) final;
32
33 private:
34 int32 channel_id_;
imcheng 2015/12/17 00:18:10 const int32 channel_id_;
xjz 2015/12/17 22:54:57 Done.
35 base::WeakPtr<cast::CastTransportHostFilter> cast_transport_host_filter_;
36
37 DISALLOW_COPY_AND_ASSIGN(TransportClient);
38 };
39
40 void TransportClient::OnStatusChange(media::cast::CastTransportStatus status) {
41 cast_transport_host_filter_.get()->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 cast_transport_host_filter_.get()->Send(
51 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events));
52 }
53
54 void TransportClient::OnReceivedPackets(
55 scoped_ptr<media::cast::Packet> packet) {
56 cast_transport_host_filter_.get()->Send(
57 new CastMsg_ReceivedPacket(channel_id_, *packet));
58 }
59
60 } // namespace
61
21 namespace cast { 62 namespace cast {
22 63
23 CastTransportHostFilter::CastTransportHostFilter() 64 CastTransportHostFilter::CastTransportHostFilter()
24 : BrowserMessageFilter(CastMsgStart), 65 : BrowserMessageFilter(CastMsgStart),
25 weak_factory_(this) {} 66 weak_factory_(this) {}
26 67
27 CastTransportHostFilter::~CastTransportHostFilter() {} 68 CastTransportHostFilter::~CastTransportHostFilter() {}
28 69
29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { 70 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 71 bool handled = true;
(...skipping 11 matching lines...) Expand all
42 OnCancelSendingFrames) 83 OnCancelSendingFrames)
43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, 84 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc,
44 OnAddValidSsrc) 85 OnAddValidSsrc)
45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, 86 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver,
46 OnSendRtcpFromRtpReceiver) 87 OnSendRtcpFromRtpReceiver)
47 IPC_MESSAGE_UNHANDLED(handled = false); 88 IPC_MESSAGE_UNHANDLED(handled = false);
48 IPC_END_MESSAGE_MAP(); 89 IPC_END_MESSAGE_MAP();
49 return handled; 90 return handled;
50 } 91 }
51 92
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, 93 void CastTransportHostFilter::SendRtt(int32 channel_id,
74 uint32 ssrc, 94 uint32 ssrc,
75 base::TimeDelta rtt) { 95 base::TimeDelta rtt) {
76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); 96 Send(new CastMsg_Rtt(channel_id, ssrc, rtt));
77 } 97 }
78 98
79 void CastTransportHostFilter::SendCastMessage( 99 void CastTransportHostFilter::SendCastMessage(
80 int32 channel_id, 100 int32 channel_id,
81 uint32 ssrc, 101 uint32 ssrc,
82 const media::cast::RtcpCastMessage& cast_message) { 102 const media::cast::RtcpCastMessage& cast_message) {
(...skipping 12 matching lines...) Expand all
95 content::PowerSaveBlocker::Create( 115 content::PowerSaveBlocker::Create(
96 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 116 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
97 content::PowerSaveBlocker::kReasonOther, 117 content::PowerSaveBlocker::kReasonOther,
98 "Cast is streaming content to a remote receiver").Pass(); 118 "Cast is streaming content to a remote receiver").Pass();
99 } 119 }
100 120
101 if (id_map_.Lookup(channel_id)) { 121 if (id_map_.Lookup(channel_id)) {
102 id_map_.Remove(channel_id); 122 id_map_.Remove(channel_id);
103 } 123 }
104 124
125 scoped_ptr<media::cast::CastTransportSender::Client> client(
126 new TransportClient(channel_id, weak_factory_.GetWeakPtr()));
Irfan 2015/12/16 22:37:04 I think what we want to do is pass a raw pointer t
xjz 2015/12/17 22:54:57 This is correct but might not be good as commented
127 media::cast::CastTransportSender::CreateParams transport_params(
128 g_browser_process->net_log(), &clock_, local_end_point, remote_end_point,
129 client.Pass(), base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
130 make_scoped_ptr(options.DeepCopy()), base::ThreadTaskRunnerHandle::Get());
105 scoped_ptr<media::cast::CastTransportSender> sender = 131 scoped_ptr<media::cast::CastTransportSender> sender =
106 media::cast::CastTransportSender::Create( 132 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); 133 id_map_.AddWithID(sender.release(), channel_id);
124 } 134 }
125 135
126 void CastTransportHostFilter::OnDelete(int32 channel_id) { 136 void CastTransportHostFilter::OnDelete(int32 channel_id) {
127 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); 137 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id);
128 if (sender) { 138 if (sender) {
129 id_map_.Remove(channel_id); 139 id_map_.Remove(channel_id);
130 } else { 140 } else {
131 DVLOG(1) << "CastTransportHostFilter::Delete called " 141 DVLOG(1) << "CastTransportHostFilter::Delete called "
132 << "on non-existing channel"; 142 << "on non-existing channel";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 params.rtp_receiver_statistics.get()); 268 params.rtp_receiver_statistics.get());
259 } else { 269 } else {
260 DVLOG(1) 270 DVLOG(1)
261 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " 271 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver "
262 << "on non-existing channel"; 272 << "on non-existing channel";
263 } 273 }
264 } 274 }
265 275
266 276
267 } // namespace cast 277 } // namespace cast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698