Index: chrome/renderer/media/cast_session_delegate.cc |
diff --git a/chrome/renderer/media/cast_session_delegate.cc b/chrome/renderer/media/cast_session_delegate.cc |
index 9c943f811e24fc8defbef02435090bd590ae583a..9c9996514c34c49d8ad6eaabbd764125797f6fe6 100644 |
--- a/chrome/renderer/media/cast_session_delegate.cc |
+++ b/chrome/renderer/media/cast_session_delegate.cc |
@@ -16,6 +16,8 @@ |
#include "media/cast/logging/encoding_event_subscriber.h" |
#include "media/cast/logging/log_serializer.h" |
#include "media/cast/logging/logging_defines.h" |
+#include "media/cast/logging/stats_event_subscriber.h" |
+#include "media/cast/logging/stats_util.h" |
#include "media/cast/transport/cast_transport_config.h" |
#include "media/cast/transport/cast_transport_sender.h" |
@@ -117,18 +119,13 @@ void CastSessionDelegate::StartVideo( |
void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) { |
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
- // Logging: enable raw events and stats collection. |
- media::cast::CastLoggingConfig logging_config = |
- media::cast::GetLoggingConfigWithRawEventsAndStatsEnabled(); |
- |
// CastSender uses the renderer's IO thread as the main thread. This reduces |
// thread hopping for incoming video frames and outgoing network packets. |
cast_environment_ = new CastEnvironment( |
scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
base::MessageLoopProxy::current(), |
g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), |
- g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), |
- logging_config); |
+ g_cast_threads.Get().GetVideoEncodeMessageLoopProxy()); |
// Rationale for using unretained: The callback cannot be called after the |
// destruction of CastTransportSenderIPC, and they both share the same thread. |
@@ -136,7 +133,6 @@ void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) { |
remote_endpoint, |
base::Bind(&CastSessionDelegate::StatusNotificationCB, |
base::Unretained(this)), |
- logging_config, |
base::Bind(&CastSessionDelegate::LogRawEvents, base::Unretained(this)))); |
cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); |
@@ -147,33 +143,55 @@ void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { |
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
if (enable) { |
if (is_audio) { |
- if (audio_event_subscriber_.get()) |
- return; |
- audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
- media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); |
- cast_environment_->Logging()->AddRawEventSubscriber( |
- audio_event_subscriber_.get()); |
+ if (!audio_event_subscriber_.get()) { |
+ audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
+ media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); |
+ cast_environment_->Logging()->AddRawEventSubscriber( |
+ audio_event_subscriber_.get()); |
+ } |
+ if (!audio_stats_subscriber_.get()) { |
+ audio_stats_subscriber_.reset( |
+ new media::cast::StatsEventSubscriber(media::cast::AUDIO_EVENT)); |
+ cast_environment_->Logging()->AddRawEventSubscriber( |
+ audio_stats_subscriber_.get()); |
+ } |
} else { |
- if (video_event_subscriber_.get()) |
- return; |
- video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
- media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); |
- cast_environment_->Logging()->AddRawEventSubscriber( |
- video_event_subscriber_.get()); |
+ if (!video_event_subscriber_.get()) { |
+ video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
+ media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); |
+ cast_environment_->Logging()->AddRawEventSubscriber( |
+ video_event_subscriber_.get()); |
+ } |
+ if (!video_stats_subscriber_.get()) { |
+ video_stats_subscriber_.reset( |
+ new media::cast::StatsEventSubscriber(media::cast::VIDEO_EVENT)); |
+ cast_environment_->Logging()->AddRawEventSubscriber( |
+ video_stats_subscriber_.get()); |
+ } |
} |
} else { |
if (is_audio) { |
- if (!audio_event_subscriber_.get()) |
- return; |
- cast_environment_->Logging()->RemoveRawEventSubscriber( |
- audio_event_subscriber_.get()); |
- audio_event_subscriber_.reset(); |
+ if (audio_event_subscriber_.get()) { |
+ cast_environment_->Logging()->RemoveRawEventSubscriber( |
+ audio_event_subscriber_.get()); |
+ audio_event_subscriber_.reset(); |
+ } |
+ if (audio_stats_subscriber_.get()) { |
+ cast_environment_->Logging()->RemoveRawEventSubscriber( |
+ audio_stats_subscriber_.get()); |
+ audio_stats_subscriber_.reset(); |
+ } |
} else { |
- if (!video_event_subscriber_.get()) |
- return; |
- cast_environment_->Logging()->RemoveRawEventSubscriber( |
- video_event_subscriber_.get()); |
- video_event_subscriber_.reset(); |
+ if (video_event_subscriber_.get()) { |
+ cast_environment_->Logging()->RemoveRawEventSubscriber( |
+ video_event_subscriber_.get()); |
+ video_event_subscriber_.reset(); |
+ } |
+ if (video_stats_subscriber_.get()) { |
+ cast_environment_->Logging()->RemoveRawEventSubscriber( |
+ video_stats_subscriber_.get()); |
+ video_stats_subscriber_.reset(); |
+ } |
} |
} |
} |
@@ -221,12 +239,18 @@ void CastSessionDelegate::GetEventLogsAndReset( |
void CastSessionDelegate::GetStatsAndReset(bool is_audio, |
const StatsCallback& callback) { |
- media::cast::FrameStatsMap frame_stats = |
- cast_environment_->Logging()->GetFrameStatsData( |
- is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); |
- media::cast::PacketStatsMap packet_stats = |
- cast_environment_->Logging()->GetPacketStatsData( |
- is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT); |
+ media::cast::StatsEventSubscriber* subscriber = |
+ is_audio ? audio_stats_subscriber_.get() : video_stats_subscriber_.get(); |
+ if (!subscriber) { |
+ callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); |
+ return; |
+ } |
+ |
+ media::cast::FrameStatsMap frame_stats; |
+ subscriber->GetFrameStats(&frame_stats); |
+ media::cast::PacketStatsMap packet_stats; |
+ subscriber->GetPacketStats(&packet_stats); |
+ subscriber->Reset(); |
scoped_ptr<base::DictionaryValue> stats = media::cast::ConvertStats( |
frame_stats, packet_stats); |