OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_session_delegate.h" | 5 #include "chrome/renderer/media/cast_session_delegate.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "chrome/renderer/media/cast_threads.h" | 10 #include "chrome/renderer/media/cast_threads.h" |
11 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | 11 #include "chrome/renderer/media/cast_transport_sender_ipc.h" |
12 #include "content/public/renderer/p2p_socket_client.h" | 12 #include "content/public/renderer/p2p_socket_client.h" |
13 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
14 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
15 #include "media/cast/cast_environment.h" | 15 #include "media/cast/cast_environment.h" |
16 #include "media/cast/cast_sender.h" | 16 #include "media/cast/cast_sender.h" |
17 #include "media/cast/logging/encoding_event_subscriber.h" | 17 #include "media/cast/logging/encoding_event_subscriber.h" |
18 #include "media/cast/logging/log_serializer.h" | |
18 #include "media/cast/logging/logging_defines.h" | 19 #include "media/cast/logging/logging_defines.h" |
19 #include "media/cast/transport/cast_transport_config.h" | 20 #include "media/cast/transport/cast_transport_config.h" |
20 #include "media/cast/transport/cast_transport_sender.h" | 21 #include "media/cast/transport/cast_transport_sender.h" |
21 | 22 |
22 using media::cast::AudioSenderConfig; | 23 using media::cast::AudioSenderConfig; |
23 using media::cast::CastEnvironment; | 24 using media::cast::CastEnvironment; |
24 using media::cast::CastSender; | 25 using media::cast::CastSender; |
25 using media::cast::VideoSenderConfig; | 26 using media::cast::VideoSenderConfig; |
26 | 27 |
27 static base::LazyInstance<CastThreads> g_cast_threads = | 28 static base::LazyInstance<CastThreads> g_cast_threads = |
28 LAZY_INSTANCE_INITIALIZER; | 29 LAZY_INSTANCE_INITIALIZER; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
33 // Allow 10MB for serialized video / audio event logs. | |
34 const int kMaxSerializedBytes = 9000000; | |
35 | |
32 // Allow about 9MB for video event logs. Assume serialized log data for | 36 // Allow about 9MB for video event logs. Assume serialized log data for |
33 // each frame will take up to 150 bytes. | 37 // each frame will take up to 150 bytes. |
34 const int kMaxVideoEventEntries = 9000000 / 150; | 38 const int kMaxVideoEventEntries = kMaxSerializedBytes / 150; |
35 | 39 |
36 // Allow about 9MB for audio event logs. Assume serialized log data for | 40 // Allow about 9MB for audio event logs. Assume serialized log data for |
37 // each frame will take up to 75 bytes. | 41 // each frame will take up to 75 bytes. |
38 const int kMaxAudioEventEntries = 9000000 / 75; | 42 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75; |
39 | 43 |
40 } // namespace | 44 } // namespace |
41 | 45 |
42 CastSessionDelegate::CastSessionDelegate() | 46 CastSessionDelegate::CastSessionDelegate() |
43 : transport_configured_(false), | 47 : transport_configured_(false), |
44 io_message_loop_proxy_( | 48 io_message_loop_proxy_( |
45 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 49 content::RenderThread::Get()->GetIOMessageLoopProxy()) { |
46 DCHECK(io_message_loop_proxy_); | 50 DCHECK(io_message_loop_proxy_); |
47 } | 51 } |
48 | 52 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 void CastSessionDelegate::StartUDP( | 105 void CastSessionDelegate::StartUDP( |
102 const net::IPEndPoint& local_endpoint, | 106 const net::IPEndPoint& local_endpoint, |
103 const net::IPEndPoint& remote_endpoint) { | 107 const net::IPEndPoint& remote_endpoint) { |
104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 108 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
105 transport_configured_ = true; | 109 transport_configured_ = true; |
106 local_endpoint_ = local_endpoint; | 110 local_endpoint_ = local_endpoint; |
107 remote_endpoint_ = remote_endpoint; | 111 remote_endpoint_ = remote_endpoint; |
108 StartSendingInternal(); | 112 StartSendingInternal(); |
109 } | 113 } |
110 | 114 |
115 void CastSessionDelegate::ToggleLogging(bool is_audio, | |
116 bool enable) { | |
117 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | |
118 if (enable) { | |
119 if (is_audio) { | |
120 if (audio_event_subscriber_.get()) | |
121 return; | |
122 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | |
123 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); | |
124 cast_environment_->Logging()->AddRawEventSubscriber( | |
125 audio_event_subscriber_.get()); | |
126 } else { | |
127 if (video_event_subscriber_.get()) | |
128 return; | |
129 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | |
130 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); | |
131 cast_environment_->Logging()->AddRawEventSubscriber( | |
132 video_event_subscriber_.get()); | |
133 } | |
134 } else { | |
135 if (is_audio) { | |
136 if (!audio_event_subscriber_.get()) | |
137 return; | |
138 cast_environment_->Logging()->RemoveRawEventSubscriber( | |
139 audio_event_subscriber_.get()); | |
140 audio_event_subscriber_.reset(); | |
141 } else { | |
142 if (!video_event_subscriber_.get()) | |
143 return; | |
144 cast_environment_->Logging()->RemoveRawEventSubscriber( | |
145 video_event_subscriber_.get()); | |
146 video_event_subscriber_.reset(); | |
147 } | |
148 } | |
149 } | |
150 | |
111 void CastSessionDelegate::GetEventLogsAndReset( | 151 void CastSessionDelegate::GetEventLogsAndReset( |
112 const EventLogsCallback& callback) { | 152 bool is_audio, const EventLogsCallback& callback) { |
113 if (!cast_sender_.get()) | 153 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
114 return; | |
115 | 154 |
116 // TODO(imcheng): Get data from event subscribers. | 155 media::cast::EncodingEventSubscriber* subscriber = is_audio ? |
117 scoped_ptr<std::string> result(new std::string); | 156 audio_event_subscriber_.get() : video_event_subscriber_.get(); |
118 callback.Run(result.Pass()); | 157 if (!subscriber) { |
158 VLOG(2) << "Logging is currently disabled."; | |
159 callback.Run(make_scoped_ptr(new std::string).Pass()); | |
160 } | |
Alpha Left Google
2014/02/26 03:06:26
Call the callback and then return.
imcheng
2014/02/26 04:41:56
Done.
| |
161 | |
162 media::cast::FrameEventMap frame_events; | |
163 media::cast::PacketEventMap packet_events; | |
164 media::cast::RtpTimestamp rtp_timestamp; | |
165 | |
166 subscriber->GetEventsAndReset(&frame_events, &packet_events, &rtp_timestamp); | |
167 | |
168 media::cast::LogSerializer log_serializer(kMaxSerializedBytes); | |
169 bool success = log_serializer.SerializeEventsForStream( | |
170 is_audio, frame_events, packet_events, rtp_timestamp); | |
171 | |
172 if (!success) { | |
173 VLOG(2) << "Failed to serialize event log."; | |
174 callback.Run(make_scoped_ptr(new std::string).Pass()); | |
175 } | |
Alpha Left Google
2014/02/26 03:06:26
Call the callback and then return.
imcheng
2014/02/26 04:41:56
Done.
| |
176 | |
177 scoped_ptr<std::string> serialized_log = | |
178 log_serializer.GetSerializedLogAndReset(); | |
179 DVLOG(2) << "Serialized log length: " << serialized_log->size(); | |
180 | |
181 callback.Run(serialized_log.Pass()); | |
119 } | 182 } |
120 | 183 |
121 void CastSessionDelegate::StatusNotificationCB( | 184 void CastSessionDelegate::StatusNotificationCB( |
122 media::cast::transport::CastTransportStatus unused_status) { | 185 media::cast::transport::CastTransportStatus unused_status) { |
123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 186 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
124 // TODO(hubbe): Call javascript UDPTransport error function. | 187 // TODO(hubbe): Call javascript UDPTransport error function. |
125 } | 188 } |
126 | 189 |
127 void CastSessionDelegate::StartSendingInternal() { | 190 void CastSessionDelegate::StartSendingInternal() { |
128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 191 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
(...skipping 12 matching lines...) Expand all Loading... | |
141 | 204 |
142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 205 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. |
143 config.local_endpoint = local_endpoint_; | 206 config.local_endpoint = local_endpoint_; |
144 config.receiver_endpoint = remote_endpoint_; | 207 config.receiver_endpoint = remote_endpoint_; |
145 if (audio_config_) { | 208 if (audio_config_) { |
146 config.audio_ssrc = audio_config_->sender_ssrc; | 209 config.audio_ssrc = audio_config_->sender_ssrc; |
147 config.audio_codec = audio_config_->codec; | 210 config.audio_codec = audio_config_->codec; |
148 config.audio_rtp_config = audio_config_->rtp_config; | 211 config.audio_rtp_config = audio_config_->rtp_config; |
149 config.audio_frequency = audio_config_->frequency; | 212 config.audio_frequency = audio_config_->frequency; |
150 config.audio_channels = audio_config_->channels; | 213 config.audio_channels = audio_config_->channels; |
151 | |
152 if (!audio_event_subscriber_.get()) { | |
153 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | |
154 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); | |
155 cast_environment_->Logging()->AddRawEventSubscriber( | |
156 audio_event_subscriber_.get()); | |
157 } | |
158 } | 214 } |
159 if (video_config_) { | 215 if (video_config_) { |
160 config.video_ssrc = video_config_->sender_ssrc; | 216 config.video_ssrc = video_config_->sender_ssrc; |
161 config.video_codec = video_config_->codec; | 217 config.video_codec = video_config_->codec; |
162 config.video_rtp_config = video_config_->rtp_config; | 218 config.video_rtp_config = video_config_->rtp_config; |
163 | |
164 if (!video_event_subscriber_.get()) { | |
165 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | |
166 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); | |
167 cast_environment_->Logging()->AddRawEventSubscriber( | |
168 video_event_subscriber_.get()); | |
169 } | |
170 } | 219 } |
171 | 220 |
172 cast_transport_.reset(new CastTransportSenderIPC( | 221 cast_transport_.reset(new CastTransportSenderIPC( |
173 config, | 222 config, |
174 base::Bind(&CastSessionDelegate::StatusNotificationCB, | 223 base::Bind(&CastSessionDelegate::StatusNotificationCB, |
175 base::Unretained(this)))); | 224 base::Unretained(this)))); |
176 | 225 |
177 cast_sender_.reset(CastSender::CreateCastSender( | 226 cast_sender_.reset(CastSender::CreateCastSender( |
178 cast_environment_, | 227 cast_environment_, |
179 audio_config_.get(), | 228 audio_config_.get(), |
(...skipping 12 matching lines...) Expand all Loading... | |
192 // TODO(pwestin): handle the error codes. | 241 // TODO(pwestin): handle the error codes. |
193 if (result == media::cast::STATUS_INITIALIZED) { | 242 if (result == media::cast::STATUS_INITIALIZED) { |
194 if (!audio_frame_input_available_callback_.is_null()) { | 243 if (!audio_frame_input_available_callback_.is_null()) { |
195 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 244 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
196 } | 245 } |
197 if (!video_frame_input_available_callback_.is_null()) { | 246 if (!video_frame_input_available_callback_.is_null()) { |
198 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 247 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
199 } | 248 } |
200 } | 249 } |
201 } | 250 } |
251 | |
OLD | NEW |