Chromium Code Reviews| Index: chrome/browser/media/cast_transport_host_filter.cc |
| diff --git a/chrome/browser/media/cast_transport_host_filter.cc b/chrome/browser/media/cast_transport_host_filter.cc |
| index 3f140734c2f728dcc3a414e4c29454de16f3a323..7feffd47f583263df9d5fd0612baeda6a5a82a13 100644 |
| --- a/chrome/browser/media/cast_transport_host_filter.cc |
| +++ b/chrome/browser/media/cast_transport_host_filter.cc |
| @@ -16,8 +16,49 @@ namespace { |
| // How often to send raw events. |
| const int kSendRawEventsIntervalSecs = 1; |
| +class TransportClient : public media::cast::CastTransportSender::Client { |
| + public: |
| + TransportClient( |
| + int32 channel_id, |
| + 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.
|
| + : channel_id_(channel_id), |
| + cast_transport_host_filter_(cast_transport_host_filter) {} |
| + |
| + 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.
|
| + void OnReceivedLoggingEvents( |
| + scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, |
| + scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) final; |
| + void OnReceivedPackets(scoped_ptr<media::cast::Packet> packet) final; |
| + |
| + private: |
| + int32 channel_id_; |
|
imcheng
2015/12/17 00:18:10
const int32 channel_id_;
xjz
2015/12/17 22:54:57
Done.
|
| + base::WeakPtr<cast::CastTransportHostFilter> cast_transport_host_filter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TransportClient); |
| +}; |
| + |
| +void TransportClient::OnStatusChange(media::cast::CastTransportStatus status) { |
| + cast_transport_host_filter_.get()->Send( |
| + new CastMsg_NotifyStatusChange(channel_id_, status)); |
| +} |
| + |
| +void TransportClient::OnReceivedLoggingEvents( |
| + scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, |
| + scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { |
| + if (frame_events->empty() && packet_events->empty()) |
| + return; |
| + cast_transport_host_filter_.get()->Send( |
| + new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events)); |
| } |
| +void TransportClient::OnReceivedPackets( |
| + scoped_ptr<media::cast::Packet> packet) { |
| + cast_transport_host_filter_.get()->Send( |
| + new CastMsg_ReceivedPacket(channel_id_, *packet)); |
| +} |
| + |
| +} // namespace |
| + |
| namespace cast { |
| CastTransportHostFilter::CastTransportHostFilter() |
| @@ -49,27 +90,6 @@ bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { |
| return handled; |
| } |
| -void CastTransportHostFilter::ReceivedPacket( |
| - int32 channel_id, |
| - scoped_ptr<media::cast::Packet> packet) { |
| - Send(new CastMsg_ReceivedPacket(channel_id, *packet)); |
| -} |
| - |
| -void CastTransportHostFilter::NotifyStatusChange( |
| - int32 channel_id, |
| - media::cast::CastTransportStatus status) { |
| - Send(new CastMsg_NotifyStatusChange(channel_id, status)); |
| -} |
| - |
| -void CastTransportHostFilter::SendRawEvents( |
| - int32 channel_id, |
| - scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, |
| - scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { |
| - if (frame_events->empty() && packet_events->empty()) |
| - return; |
| - Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events)); |
| -} |
| - |
| void CastTransportHostFilter::SendRtt(int32 channel_id, |
| uint32 ssrc, |
| base::TimeDelta rtt) { |
| @@ -102,24 +122,14 @@ void CastTransportHostFilter::OnNew( |
| id_map_.Remove(channel_id); |
| } |
| + scoped_ptr<media::cast::CastTransportSender::Client> client( |
| + 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
|
| + media::cast::CastTransportSender::CreateParams transport_params( |
| + g_browser_process->net_log(), &clock_, local_end_point, remote_end_point, |
| + client.Pass(), base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), |
| + make_scoped_ptr(options.DeepCopy()), base::ThreadTaskRunnerHandle::Get()); |
| scoped_ptr<media::cast::CastTransportSender> sender = |
| - media::cast::CastTransportSender::Create( |
| - g_browser_process->net_log(), |
| - &clock_, |
| - local_end_point, |
| - remote_end_point, |
| - make_scoped_ptr(options.DeepCopy()), |
| - base::Bind(&CastTransportHostFilter::NotifyStatusChange, |
| - weak_factory_.GetWeakPtr(), |
| - channel_id), |
| - base::Bind(&CastTransportHostFilter::SendRawEvents, |
| - weak_factory_.GetWeakPtr(), |
| - channel_id), |
| - base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), |
| - base::Bind(&CastTransportHostFilter::ReceivedPacket, |
| - weak_factory_.GetWeakPtr(), |
| - channel_id), |
| - base::ThreadTaskRunnerHandle::Get()); |
| + media::cast::CastTransportSender::Create(transport_params); |
| id_map_.AddWithID(sender.release(), channel_id); |
| } |