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 #include "media/cast/transport/cast_transport_sender.h" | |
14 | 13 |
15 CastTransportSenderIPC::CastTransportSenderIPC( | 14 CastTransportSenderIPC::CastTransportSenderIPC( |
16 const net::IPEndPoint& remote_end_point, | 15 const net::IPEndPoint& remote_end_point, |
17 const media::cast::transport::CastTransportStatusCallback& status_cb, | 16 const media::cast::CastTransportStatusCallback& status_cb, |
18 const media::cast::transport::BulkRawEventsCallback& raw_events_cb) | 17 const media::cast::BulkRawEventsCallback& raw_events_cb) |
19 : status_callback_(status_cb), raw_events_callback_(raw_events_cb) { | 18 : status_callback_(status_cb), raw_events_callback_(raw_events_cb) { |
20 if (CastIPCDispatcher::Get()) { | 19 if (CastIPCDispatcher::Get()) { |
21 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); | 20 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); |
22 } | 21 } |
23 Send(new CastHostMsg_New(channel_id_, remote_end_point)); | 22 Send(new CastHostMsg_New(channel_id_, remote_end_point)); |
24 } | 23 } |
25 | 24 |
26 CastTransportSenderIPC::~CastTransportSenderIPC() { | 25 CastTransportSenderIPC::~CastTransportSenderIPC() { |
27 Send(new CastHostMsg_Delete(channel_id_)); | 26 Send(new CastHostMsg_Delete(channel_id_)); |
28 if (CastIPCDispatcher::Get()) { | 27 if (CastIPCDispatcher::Get()) { |
29 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 28 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
30 } | 29 } |
31 } | 30 } |
32 | 31 |
33 void CastTransportSenderIPC::SetPacketReceiver( | 32 void CastTransportSenderIPC::SetPacketReceiver( |
34 const media::cast::transport::PacketReceiverCallback& packet_callback) { | 33 const media::cast::PacketReceiverCallback& packet_callback) { |
35 packet_callback_ = packet_callback; | 34 packet_callback_ = packet_callback; |
36 } | 35 } |
37 | 36 |
38 void CastTransportSenderIPC::InitializeAudio( | 37 void CastTransportSenderIPC::InitializeAudio( |
39 const media::cast::transport::CastTransportRtpConfig& config) { | 38 const media::cast::CastTransportRtpConfig& config) { |
40 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); | 39 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); |
41 } | 40 } |
42 | 41 |
43 void CastTransportSenderIPC::InitializeVideo( | 42 void CastTransportSenderIPC::InitializeVideo( |
44 const media::cast::transport::CastTransportRtpConfig& config) { | 43 const media::cast::CastTransportRtpConfig& config) { |
45 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); | 44 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); |
46 } | 45 } |
47 | 46 |
48 void CastTransportSenderIPC::InsertCodedAudioFrame( | 47 void CastTransportSenderIPC::InsertCodedAudioFrame( |
49 const media::cast::transport::EncodedFrame& audio_frame) { | 48 const media::cast::EncodedFrame& audio_frame) { |
50 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, audio_frame)); | 49 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, audio_frame)); |
51 } | 50 } |
52 | 51 |
53 void CastTransportSenderIPC::InsertCodedVideoFrame( | 52 void CastTransportSenderIPC::InsertCodedVideoFrame( |
54 const media::cast::transport::EncodedFrame& video_frame) { | 53 const media::cast::EncodedFrame& video_frame) { |
55 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, video_frame)); | 54 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, video_frame)); |
56 } | 55 } |
57 | 56 |
58 void CastTransportSenderIPC::SendRtcpFromRtpSender( | 57 void CastTransportSenderIPC::SendRtcpFromRtpSender( |
59 uint32 packet_type_flags, | 58 uint32 packet_type_flags, |
60 uint32 ntp_seconds, | 59 uint32 ntp_seconds, |
61 uint32 ntp_fraction, | 60 uint32 ntp_fraction, |
62 uint32 rtp_timestamp, | 61 uint32 rtp_timestamp, |
63 const media::cast::transport::RtcpDlrrReportBlock& dlrr, | 62 const media::cast::RtcpDlrrReportBlock& dlrr, |
64 uint32 sending_ssrc, | 63 uint32 sending_ssrc, |
65 const std::string& c_name) { | 64 const std::string& c_name) { |
66 struct media::cast::transport::SendRtcpFromRtpSenderData data; | 65 struct media::cast::SendRtcpFromRtpSenderData data; |
67 data.packet_type_flags = packet_type_flags; | 66 data.packet_type_flags = packet_type_flags; |
68 data.sending_ssrc = sending_ssrc; | 67 data.sending_ssrc = sending_ssrc; |
69 data.c_name = c_name; | 68 data.c_name = c_name; |
70 data.ntp_seconds = ntp_seconds; | 69 data.ntp_seconds = ntp_seconds; |
71 data.ntp_fraction = ntp_fraction; | 70 data.ntp_fraction = ntp_fraction; |
72 data.rtp_timestamp = rtp_timestamp; | 71 data.rtp_timestamp = rtp_timestamp; |
73 Send(new CastHostMsg_SendRtcpFromRtpSender( | 72 Send(new CastHostMsg_SendRtcpFromRtpSender( |
74 channel_id_, | 73 channel_id_, |
75 data, | 74 data, |
76 dlrr)); | 75 dlrr)); |
77 } | 76 } |
78 | 77 |
79 void CastTransportSenderIPC::ResendPackets( | 78 void CastTransportSenderIPC::ResendPackets( |
80 bool is_audio, | 79 bool is_audio, |
81 const media::cast::MissingFramesAndPacketsMap& missing_packets, | 80 const media::cast::MissingFramesAndPacketsMap& missing_packets, |
82 bool cancel_rtx_if_not_in_list, | 81 bool cancel_rtx_if_not_in_list, |
83 base::TimeDelta dedupe_window) { | 82 base::TimeDelta dedupe_window) { |
84 Send(new CastHostMsg_ResendPackets(channel_id_, | 83 Send(new CastHostMsg_ResendPackets(channel_id_, |
85 is_audio, | 84 is_audio, |
86 missing_packets, | 85 missing_packets, |
87 cancel_rtx_if_not_in_list, | 86 cancel_rtx_if_not_in_list, |
88 dedupe_window)); | 87 dedupe_window)); |
89 } | 88 } |
90 | 89 |
91 void CastTransportSenderIPC::OnReceivedPacket( | 90 void CastTransportSenderIPC::OnReceivedPacket( |
92 const media::cast::Packet& packet) { | 91 const media::cast::Packet& packet) { |
93 if (!packet_callback_.is_null()) { | 92 if (!packet_callback_.is_null()) { |
94 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | 93 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? |
95 scoped_ptr<media::cast::transport::Packet> packet_copy( | 94 scoped_ptr<media::cast::Packet> packet_copy( |
96 new media::cast::transport::Packet(packet)); | 95 new media::cast::Packet(packet)); |
97 packet_callback_.Run(packet_copy.Pass()); | 96 packet_callback_.Run(packet_copy.Pass()); |
98 } else { | 97 } else { |
99 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | 98 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; |
100 } | 99 } |
101 } | 100 } |
102 | 101 |
103 void CastTransportSenderIPC::OnNotifyStatusChange( | 102 void CastTransportSenderIPC::OnNotifyStatusChange( |
104 media::cast::transport::CastTransportStatus status) { | 103 media::cast::CastTransportStatus status) { |
105 status_callback_.Run(status); | 104 status_callback_.Run(status); |
106 } | 105 } |
107 | 106 |
108 void CastTransportSenderIPC::OnRawEvents( | 107 void CastTransportSenderIPC::OnRawEvents( |
109 const std::vector<media::cast::PacketEvent>& packet_events) { | 108 const std::vector<media::cast::PacketEvent>& packet_events) { |
110 raw_events_callback_.Run(packet_events); | 109 raw_events_callback_.Run(packet_events); |
111 } | 110 } |
112 | 111 |
113 void CastTransportSenderIPC::Send(IPC::Message* message) { | 112 void CastTransportSenderIPC::Send(IPC::Message* message) { |
114 if (CastIPCDispatcher::Get()) { | 113 if (CastIPCDispatcher::Get()) { |
115 CastIPCDispatcher::Get()->Send(message); | 114 CastIPCDispatcher::Get()->Send(message); |
116 } else { | 115 } else { |
117 delete message; | 116 delete message; |
118 } | 117 } |
119 } | 118 } |
OLD | NEW |