| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using media::cast::AudioSenderConfig; | 22 using media::cast::AudioSenderConfig; |
| 23 using media::cast::CastEnvironment; | 23 using media::cast::CastEnvironment; |
| 24 using media::cast::CastSender; | 24 using media::cast::CastSender; |
| 25 using media::cast::VideoSenderConfig; | 25 using media::cast::VideoSenderConfig; |
| 26 | 26 |
| 27 static base::LazyInstance<CastThreads> g_cast_threads = | 27 static base::LazyInstance<CastThreads> g_cast_threads = |
| 28 LAZY_INSTANCE_INITIALIZER; | 28 LAZY_INSTANCE_INITIALIZER; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Allow 10MB for serialized video / audio event logs. | 32 // Allow 9MB for serialized video / audio event logs. |
| 33 const int kMaxSerializedBytes = 9000000; | 33 const int kMaxSerializedBytes = 9000000; |
| 34 | 34 |
| 35 // Allow about 9MB for video event logs. Assume serialized log data for | 35 // Assume serialized log data for each frame will take up to 150 bytes. |
| 36 // each frame will take up to 150 bytes. | |
| 37 const int kMaxVideoEventEntries = kMaxSerializedBytes / 150; | 36 const int kMaxVideoEventEntries = kMaxSerializedBytes / 150; |
| 38 | 37 |
| 39 // Allow about 9MB for audio event logs. Assume serialized log data for | 38 // Assume serialized log data for each frame will take up to 75 bytes. |
| 40 // each frame will take up to 75 bytes. | |
| 41 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75; | 39 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75; |
| 42 | 40 |
| 43 } // namespace | 41 } // namespace |
| 44 | 42 |
| 45 CastSessionDelegate::CastSessionDelegate() | 43 CastSessionDelegate::CastSessionDelegate() |
| 46 : io_message_loop_proxy_( | 44 : io_message_loop_proxy_( |
| 47 content::RenderThread::Get()->GetIOMessageLoopProxy()), | 45 content::RenderThread::Get()->GetIOMessageLoopProxy()), |
| 48 weak_factory_(this) { | 46 weak_factory_(this) { |
| 49 DCHECK(io_message_loop_proxy_); | 47 DCHECK(io_message_loop_proxy_); |
| 50 } | 48 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 169 } |
| 172 | 170 |
| 173 void CastSessionDelegate::GetEventLogsAndReset( | 171 void CastSessionDelegate::GetEventLogsAndReset( |
| 174 bool is_audio, | 172 bool is_audio, |
| 175 const EventLogsCallback& callback) { | 173 const EventLogsCallback& callback) { |
| 176 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 174 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 177 | 175 |
| 178 media::cast::EncodingEventSubscriber* subscriber = | 176 media::cast::EncodingEventSubscriber* subscriber = |
| 179 is_audio ? audio_event_subscriber_.get() : video_event_subscriber_.get(); | 177 is_audio ? audio_event_subscriber_.get() : video_event_subscriber_.get(); |
| 180 if (!subscriber) { | 178 if (!subscriber) { |
| 181 callback.Run(make_scoped_ptr(new std::string).Pass()); | 179 callback.Run(make_scoped_ptr(new base::BinaryValue).Pass()); |
| 182 return; | 180 return; |
| 183 } | 181 } |
| 184 | 182 |
| 185 media::cast::proto::LogMetadata metadata; | 183 media::cast::proto::LogMetadata metadata; |
| 186 media::cast::FrameEventMap frame_events; | 184 media::cast::FrameEventMap frame_events; |
| 187 media::cast::PacketEventMap packet_events; | 185 media::cast::PacketEventMap packet_events; |
| 188 | 186 |
| 189 subscriber->GetEventsAndReset(&metadata, &frame_events, &packet_events); | 187 subscriber->GetEventsAndReset(&metadata, &frame_events, &packet_events); |
| 190 | 188 |
| 191 media::cast::LogSerializer log_serializer(kMaxSerializedBytes); | 189 scoped_ptr<char[]> serialized_log(new char[kMaxSerializedBytes]); |
| 192 bool success = log_serializer.SerializeEventsForStream( | 190 int output_bytes; |
| 193 metadata, frame_events, packet_events); | 191 bool success = media::cast::SerializeEvents(metadata, |
| 192 frame_events, |
| 193 packet_events, |
| 194 true, |
| 195 kMaxSerializedBytes, |
| 196 serialized_log.get(), |
| 197 &output_bytes); |
| 194 | 198 |
| 195 if (!success) { | 199 if (!success) { |
| 196 VLOG(2) << "Failed to serialize event log."; | 200 VLOG(2) << "Failed to serialize event log."; |
| 197 callback.Run(make_scoped_ptr(new std::string).Pass()); | 201 callback.Run(make_scoped_ptr(new base::BinaryValue).Pass()); |
| 198 return; | 202 return; |
| 199 } | 203 } |
| 200 | 204 |
| 201 scoped_ptr<std::string> serialized_log = | 205 DVLOG(2) << "Serialized log length: " << output_bytes; |
| 202 log_serializer.GetSerializedLogAndReset(); | |
| 203 DVLOG(2) << "Serialized log length: " << serialized_log->size(); | |
| 204 | 206 |
| 205 callback.Run(serialized_log.Pass()); | 207 scoped_ptr<base::BinaryValue> blob( |
| 208 new base::BinaryValue(serialized_log.Pass(), output_bytes)); |
| 209 callback.Run(blob.Pass()); |
| 206 } | 210 } |
| 207 | 211 |
| 208 void CastSessionDelegate::GetStatsAndReset(bool is_audio, | 212 void CastSessionDelegate::GetStatsAndReset(bool is_audio, |
| 209 const StatsCallback& callback) { | 213 const StatsCallback& callback) { |
| 210 media::cast::FrameStatsMap frame_stats = | 214 media::cast::FrameStatsMap frame_stats = |
| 211 cast_environment_->Logging()->GetFrameStatsData( | 215 cast_environment_->Logging()->GetFrameStatsData( |
| 212 is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); | 216 is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); |
| 213 media::cast::PacketStatsMap packet_stats = | 217 media::cast::PacketStatsMap packet_stats = |
| 214 cast_environment_->Logging()->GetPacketStatsData( | 218 cast_environment_->Logging()->GetPacketStatsData( |
| 215 is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); | 219 is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 ++it) { | 258 ++it) { |
| 255 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, | 259 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, |
| 256 it->type, | 260 it->type, |
| 257 it->rtp_timestamp, | 261 it->rtp_timestamp, |
| 258 it->frame_id, | 262 it->frame_id, |
| 259 it->packet_id, | 263 it->packet_id, |
| 260 it->max_packet_id, | 264 it->max_packet_id, |
| 261 it->size); | 265 it->size); |
| 262 } | 266 } |
| 263 } | 267 } |
| OLD | NEW |