Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/renderer/media/cast_session_delegate.cc

Issue 170063006: Cast: Add JS API to get raw events logs from cast extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
49 CastSessionDelegate::~CastSessionDelegate() { 53 CastSessionDelegate::~CastSessionDelegate() {
50 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 54 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
51 55
52 if (audio_event_subscriber_.get()) { 56 for (EventSubscriberMap::iterator it = event_subscriber_map_.begin();
53 cast_environment_->Logging()->RemoveRawEventSubscriber( 57 it != event_subscriber_map_.end();
54 audio_event_subscriber_.get()); 58 ++it)
55 } 59 cast_environment_->Logging()->RemoveRawEventSubscriber(it->second.get());
56 if (video_event_subscriber_.get()) {
57 cast_environment_->Logging()->RemoveRawEventSubscriber(
58 video_event_subscriber_.get());
59 }
60 } 60 }
61 61
62 void CastSessionDelegate::Initialize() { 62 void CastSessionDelegate::Initialize() {
63 if (cast_environment_) 63 if (cast_environment_)
64 return; // Already initialized. 64 return; // Already initialized.
65 65
66 // CastSender uses the renderer's IO thread as the main thread. This reduces 66 // CastSender uses the renderer's IO thread as the main thread. This reduces
67 // thread hopping for incoming video frames and outgoing network packets. 67 // thread hopping for incoming video frames and outgoing network packets.
68 // There's no need to decode so no thread assigned for decoding. 68 // There's no need to decode so no thread assigned for decoding.
69 // Get default logging: All disabled. 69 // Get default logging: All disabled.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void CastSessionDelegate::StartUDP( 101 void CastSessionDelegate::StartUDP(
102 const net::IPEndPoint& local_endpoint, 102 const net::IPEndPoint& local_endpoint,
103 const net::IPEndPoint& remote_endpoint) { 103 const net::IPEndPoint& remote_endpoint) {
104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
105 transport_configured_ = true; 105 transport_configured_ = true;
106 local_endpoint_ = local_endpoint; 106 local_endpoint_ = local_endpoint;
107 remote_endpoint_ = remote_endpoint; 107 remote_endpoint_ = remote_endpoint;
108 StartSendingInternal(); 108 StartSendingInternal();
109 } 109 }
110 110
111 void CastSessionDelegate::StartLogging(const int stream_id,
112 const bool is_audio) {
113 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
114 DCHECK(event_subscriber_map_.find(stream_id) == event_subscriber_map_.end());
115
116 linked_ptr<media::cast::EncodingEventSubscriber> event_subscriber(
117 new media::cast::EncodingEventSubscriber(
118 is_audio ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT,
119 is_audio ? kMaxAudioEventEntries : kMaxVideoEventEntries));
120
121 cast_environment_->Logging()->AddRawEventSubscriber(event_subscriber.get());
122
123 event_subscriber_map_.insert(std::make_pair(stream_id, event_subscriber));
124 }
125
111 void CastSessionDelegate::GetEventLogsAndReset( 126 void CastSessionDelegate::GetEventLogsAndReset(
112 const EventLogsCallback& callback) { 127 const EventLogsCallback& callback,
113 if (!cast_sender_.get()) 128 const int stream_id) {
129 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
130 EventSubscriberMap::iterator it = event_subscriber_map_.find(stream_id);
131 if (it == event_subscriber_map_.end()) {
132 VLOG(2) << "Did not find event subscriber for stream " << stream_id << ".";
114 return; 133 return;
134 }
115 135
116 // TODO(imcheng): Get data from event subscribers. 136 media::cast::FrameEventMap frame_events;
117 scoped_ptr<std::string> result(new std::string); 137 media::cast::PacketEventMap packet_events;
118 callback.Run(result.Pass()); 138 media::cast::RtpTimestamp rtp_timestamp;
139
140 it->second->GetEventsAndReset(&frame_events, &packet_events, &rtp_timestamp);
141
142 media::cast::LogSerializer log_serializer(kMaxSerializedBytes);
143 bool success = log_serializer.SerializeEventsForStream(
144 stream_id, frame_events, packet_events, rtp_timestamp);
145
146 if (!success) {
147 VLOG(2) << "Failed to serialize event log.";
148 return;
149 }
150
151 scoped_ptr<std::string> serialized_log =
152 log_serializer.GetSerializedLogAndReset();
153 DVLOG(2) << "Serialized log length: " << serialized_log->size();
154
155 callback.Run(serialized_log.Pass());
119 } 156 }
120 157
121 void CastSessionDelegate::StatusNotificationCB( 158 void CastSessionDelegate::StatusNotificationCB(
122 media::cast::transport::CastTransportStatus unused_status) { 159 media::cast::transport::CastTransportStatus unused_status) {
123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 160 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
124 // TODO(hubbe): Call javascript UDPTransport error function. 161 // TODO(hubbe): Call javascript UDPTransport error function.
125 } 162 }
126 163
127 void CastSessionDelegate::StartSendingInternal() { 164 void CastSessionDelegate::StartSendingInternal() {
128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 165 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
(...skipping 12 matching lines...) Expand all
141 178
142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. 179 // TODO(hubbe): set config.aes_key and config.aes_iv_mask.
143 config.local_endpoint = local_endpoint_; 180 config.local_endpoint = local_endpoint_;
144 config.receiver_endpoint = remote_endpoint_; 181 config.receiver_endpoint = remote_endpoint_;
145 if (audio_config_) { 182 if (audio_config_) {
146 config.audio_ssrc = audio_config_->sender_ssrc; 183 config.audio_ssrc = audio_config_->sender_ssrc;
147 config.audio_codec = audio_config_->codec; 184 config.audio_codec = audio_config_->codec;
148 config.audio_rtp_config = audio_config_->rtp_config; 185 config.audio_rtp_config = audio_config_->rtp_config;
149 config.audio_frequency = audio_config_->frequency; 186 config.audio_frequency = audio_config_->frequency;
150 config.audio_channels = audio_config_->channels; 187 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 } 188 }
159 if (video_config_) { 189 if (video_config_) {
160 config.video_ssrc = video_config_->sender_ssrc; 190 config.video_ssrc = video_config_->sender_ssrc;
161 config.video_codec = video_config_->codec; 191 config.video_codec = video_config_->codec;
162 config.video_rtp_config = video_config_->rtp_config; 192 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 } 193 }
171 194
172 cast_transport_.reset(new CastTransportSenderIPC( 195 cast_transport_.reset(new CastTransportSenderIPC(
173 config, 196 config,
174 base::Bind(&CastSessionDelegate::StatusNotificationCB, 197 base::Bind(&CastSessionDelegate::StatusNotificationCB,
175 base::Unretained(this)))); 198 base::Unretained(this))));
176 199
177 cast_sender_.reset(CastSender::CreateCastSender( 200 cast_sender_.reset(CastSender::CreateCastSender(
178 cast_environment_, 201 cast_environment_,
179 audio_config_.get(), 202 audio_config_.get(),
(...skipping 12 matching lines...) Expand all
192 // TODO(pwestin): handle the error codes. 215 // TODO(pwestin): handle the error codes.
193 if (result == media::cast::STATUS_INITIALIZED) { 216 if (result == media::cast::STATUS_INITIALIZED) {
194 if (!audio_frame_input_available_callback_.is_null()) { 217 if (!audio_frame_input_available_callback_.is_null()) {
195 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); 218 audio_frame_input_available_callback_.Run(cast_sender_->frame_input());
196 } 219 }
197 if (!video_frame_input_available_callback_.is_null()) { 220 if (!video_frame_input_available_callback_.is_null()) {
198 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); 221 video_frame_input_available_callback_.Run(cast_sender_->frame_input());
199 } 222 }
200 } 223 }
201 } 224 }
225
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698