| 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 faab4f974b33317423bb82a956d3eb0901467aaf..193aff6e9a263eba62bc01903d267af962ff4b70 100644
|
| --- a/chrome/renderer/media/cast_session_delegate.cc
|
| +++ b/chrome/renderer/media/cast_session_delegate.cc
|
| @@ -15,6 +15,7 @@
|
| #include "media/cast/cast_environment.h"
|
| #include "media/cast/cast_sender.h"
|
| #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/transport/cast_transport_config.h"
|
| #include "media/cast/transport/cast_transport_sender.h"
|
| @@ -29,13 +30,16 @@ static base::LazyInstance<CastThreads> g_cast_threads =
|
|
|
| namespace {
|
|
|
| +// Allow 10MB for serialized video / audio event logs.
|
| +const int kMaxSerializedBytes = 9000000;
|
| +
|
| // Allow about 9MB for video event logs. Assume serialized log data for
|
| // each frame will take up to 150 bytes.
|
| -const int kMaxVideoEventEntries = 9000000 / 150;
|
| +const int kMaxVideoEventEntries = kMaxSerializedBytes / 150;
|
|
|
| // Allow about 9MB for audio event logs. Assume serialized log data for
|
| // each frame will take up to 75 bytes.
|
| -const int kMaxAudioEventEntries = 9000000 / 75;
|
| +const int kMaxAudioEventEntries = kMaxSerializedBytes / 75;
|
|
|
| } // namespace
|
|
|
| @@ -49,14 +53,10 @@ CastSessionDelegate::CastSessionDelegate()
|
| CastSessionDelegate::~CastSessionDelegate() {
|
| DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
|
|
|
| - if (audio_event_subscriber_.get()) {
|
| - cast_environment_->Logging()->RemoveRawEventSubscriber(
|
| - audio_event_subscriber_.get());
|
| - }
|
| - if (video_event_subscriber_.get()) {
|
| - cast_environment_->Logging()->RemoveRawEventSubscriber(
|
| - video_event_subscriber_.get());
|
| - }
|
| + for (EventSubscriberMap::iterator it = event_subscriber_map_.begin();
|
| + it != event_subscriber_map_.end();
|
| + ++it)
|
| + cast_environment_->Logging()->RemoveRawEventSubscriber(it->second.get());
|
| }
|
|
|
| void CastSessionDelegate::Initialize() {
|
| @@ -108,14 +108,59 @@ void CastSessionDelegate::StartUDP(
|
| StartSendingInternal();
|
| }
|
|
|
| +void CastSessionDelegate::ToggleLogging(const int stream_id,
|
| + const bool enable,
|
| + const bool is_audio) {
|
| + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
|
| + EventSubscriberMap::iterator it = event_subscriber_map_.find(stream_id);
|
| + if (enable) {
|
| + DCHECK(it == event_subscriber_map_.end());
|
| +
|
| + linked_ptr<media::cast::EncodingEventSubscriber> event_subscriber(
|
| + new media::cast::EncodingEventSubscriber(
|
| + is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT,
|
| + is_audio ? kMaxAudioEventEntries : kMaxVideoEventEntries));
|
| +
|
| + cast_environment_->Logging()->AddRawEventSubscriber(event_subscriber.get());
|
| +
|
| + event_subscriber_map_.insert(std::make_pair(stream_id, event_subscriber));
|
| + } else {
|
| + DCHECK(it != event_subscriber_map_.end());
|
| + cast_environment_->Logging()->RemoveRawEventSubscriber(it->second.get());
|
| + event_subscriber_map_.erase(it);
|
| + }
|
| +}
|
| +
|
| void CastSessionDelegate::GetEventLogsAndReset(
|
| - const EventLogsCallback& callback) {
|
| - if (!cast_sender_.get())
|
| + const EventLogsCallback& callback,
|
| + const int stream_id) {
|
| + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
|
| + EventSubscriberMap::iterator it = event_subscriber_map_.find(stream_id);
|
| + if (it == event_subscriber_map_.end()) {
|
| + VLOG(2) << "Did not find event subscriber for stream " << stream_id << ".";
|
| return;
|
| + }
|
| +
|
| + media::cast::FrameEventMap frame_events;
|
| + media::cast::PacketEventMap packet_events;
|
| + media::cast::RtpTimestamp rtp_timestamp;
|
| +
|
| + it->second->GetEventsAndReset(&frame_events, &packet_events, &rtp_timestamp);
|
|
|
| - // TODO(imcheng): Get data from event subscribers.
|
| - scoped_ptr<std::string> result(new std::string);
|
| - callback.Run(result.Pass());
|
| + media::cast::LogSerializer log_serializer(kMaxSerializedBytes);
|
| + bool success = log_serializer.SerializeEventsForStream(
|
| + stream_id, frame_events, packet_events, rtp_timestamp);
|
| +
|
| + if (!success) {
|
| + VLOG(2) << "Failed to serialize event log.";
|
| + return;
|
| + }
|
| +
|
| + scoped_ptr<std::string> serialized_log =
|
| + log_serializer.GetSerializedLogAndReset();
|
| + DVLOG(2) << "Serialized log length: " << serialized_log->size();
|
| +
|
| + callback.Run(serialized_log.Pass());
|
| }
|
|
|
| void CastSessionDelegate::StatusNotificationCB(
|
| @@ -148,25 +193,11 @@ void CastSessionDelegate::StartSendingInternal() {
|
| config.audio_rtp_config = audio_config_->rtp_config;
|
| config.audio_frequency = audio_config_->frequency;
|
| config.audio_channels = audio_config_->channels;
|
| -
|
| - 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 (video_config_) {
|
| config.video_ssrc = video_config_->sender_ssrc;
|
| config.video_codec = video_config_->codec;
|
| config.video_rtp_config = video_config_->rtp_config;
|
| -
|
| - 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());
|
| - }
|
| }
|
|
|
| cast_transport_.reset(new CastTransportSenderIPC(
|
| @@ -199,3 +230,4 @@ void CastSessionDelegate::InitializationResult(
|
| }
|
| }
|
| }
|
| +
|
|
|