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

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

Issue 173713004: Cast: Plumb raw event logs to cast extension, install EncodingEventSubscriber on CastSessionDelegat… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « chrome/renderer/media/cast_session_delegate.h ('k') | media/cast/cast.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/renderer/media/cast_transport_sender_ipc.h" 9 #include "chrome/renderer/media/cast_transport_sender_ipc.h"
10 #include "content/public/renderer/p2p_socket_client.h" 10 #include "content/public/renderer/p2p_socket_client.h"
11 #include "content/public/renderer/render_thread.h" 11 #include "content/public/renderer/render_thread.h"
12 #include "media/cast/cast_config.h" 12 #include "media/cast/cast_config.h"
13 #include "media/cast/cast_environment.h" 13 #include "media/cast/cast_environment.h"
14 #include "media/cast/cast_sender.h" 14 #include "media/cast/cast_sender.h"
15 #include "media/cast/logging/encoding_event_subscriber.h"
15 #include "media/cast/logging/logging_defines.h" 16 #include "media/cast/logging/logging_defines.h"
16 #include "media/cast/transport/cast_transport_config.h" 17 #include "media/cast/transport/cast_transport_config.h"
17 #include "media/cast/transport/cast_transport_sender.h" 18 #include "media/cast/transport/cast_transport_sender.h"
18 19
19 using media::cast::AudioSenderConfig; 20 using media::cast::AudioSenderConfig;
20 using media::cast::CastEnvironment; 21 using media::cast::CastEnvironment;
21 using media::cast::CastSender; 22 using media::cast::CastSender;
22 using media::cast::VideoSenderConfig; 23 using media::cast::VideoSenderConfig;
23 24
25 namespace {
26
27 // Allow about 9MB for video event logs. Assume serialized log data for
28 // each frame will take up to 150 bytes.
29 const int kMaxVideoEventEntries = 9000000 / 150;
30
31 // Allow about 9MB for audio event logs. Assume serialized log data for
32 // each frame will take up to 75 bytes.
33 const int kMaxAudioEventEntries = 9000000 / 75;
34
35 } // namespace
36
24 CastSessionDelegate::CastSessionDelegate() 37 CastSessionDelegate::CastSessionDelegate()
25 : audio_encode_thread_("CastAudioEncodeThread"), 38 : audio_encode_thread_("CastAudioEncodeThread"),
26 video_encode_thread_("CastVideoEncodeThread"), 39 video_encode_thread_("CastVideoEncodeThread"),
27 transport_configured_(false), 40 transport_configured_(false),
28 io_message_loop_proxy_( 41 io_message_loop_proxy_(
29 content::RenderThread::Get()->GetIOMessageLoopProxy()) { 42 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
30 DCHECK(io_message_loop_proxy_); 43 DCHECK(io_message_loop_proxy_);
31 } 44 }
32 45
33 CastSessionDelegate::~CastSessionDelegate() { 46 CastSessionDelegate::~CastSessionDelegate() {
34 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 47 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
48
49 if (audio_event_subscriber_.get()) {
50 cast_environment_->Logging()->RemoveRawEventSubscriber(
51 audio_event_subscriber_.get());
52 }
53 if (video_event_subscriber_.get()) {
54 cast_environment_->Logging()->RemoveRawEventSubscriber(
55 video_event_subscriber_.get());
56 }
35 } 57 }
36 58
37 void CastSessionDelegate::Initialize() { 59 void CastSessionDelegate::Initialize() {
38 if (cast_environment_) 60 if (cast_environment_)
39 return; // Already initialized. 61 return; // Already initialized.
40 62
41 audio_encode_thread_.Start(); 63 audio_encode_thread_.Start();
42 video_encode_thread_.Start(); 64 video_encode_thread_.Start();
43 65
44 // 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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void CastSessionDelegate::StartUDP( 101 void CastSessionDelegate::StartUDP(
80 const net::IPEndPoint& local_endpoint, 102 const net::IPEndPoint& local_endpoint,
81 const net::IPEndPoint& remote_endpoint) { 103 const net::IPEndPoint& remote_endpoint) {
82 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
83 transport_configured_ = true; 105 transport_configured_ = true;
84 local_endpoint_ = local_endpoint; 106 local_endpoint_ = local_endpoint;
85 remote_endpoint_ = remote_endpoint; 107 remote_endpoint_ = remote_endpoint;
86 StartSendingInternal(); 108 StartSendingInternal();
87 } 109 }
88 110
111 void CastSessionDelegate::GetEventLogsAndReset(
112 const EventLogsCallback& callback) {
113 if (!cast_sender_.get())
114 return;
115
116 // TODO(imcheng): Get data from event subscribers.
117 scoped_ptr<std::string> result(new std::string);
118 callback.Run(result.Pass());
119 }
120
89 void CastSessionDelegate::StatusNotificationCB( 121 void CastSessionDelegate::StatusNotificationCB(
90 media::cast::transport::CastTransportStatus unused_status) { 122 media::cast::transport::CastTransportStatus unused_status) {
91 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
92 // TODO(hubbe): Call javascript UDPTransport error function. 124 // TODO(hubbe): Call javascript UDPTransport error function.
93 } 125 }
94 126
95 void CastSessionDelegate::StartSendingInternal() { 127 void CastSessionDelegate::StartSendingInternal() {
96 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
97 129
98 // No transport, wait. 130 // No transport, wait.
(...skipping 10 matching lines...) Expand all
109 141
110 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. 142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask.
111 config.local_endpoint = local_endpoint_; 143 config.local_endpoint = local_endpoint_;
112 config.receiver_endpoint = remote_endpoint_; 144 config.receiver_endpoint = remote_endpoint_;
113 if (audio_config_) { 145 if (audio_config_) {
114 config.audio_ssrc = audio_config_->sender_ssrc; 146 config.audio_ssrc = audio_config_->sender_ssrc;
115 config.audio_codec = audio_config_->codec; 147 config.audio_codec = audio_config_->codec;
116 config.audio_rtp_config = audio_config_->rtp_config; 148 config.audio_rtp_config = audio_config_->rtp_config;
117 config.audio_frequency = audio_config_->frequency; 149 config.audio_frequency = audio_config_->frequency;
118 config.audio_channels = audio_config_->channels; 150 config.audio_channels = audio_config_->channels;
151 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
152 media::cast::AUDIO_EVENT, kMaxAudioEventEntries));
153
154 // Currently on main thread, can call logging directly.
Alpha Left Google 2014/02/21 01:59:19 This comment is not necessary.
imcheng 2014/02/21 03:17:25 I suppose... it helps to remind me this is making
155 cast_environment_->Logging()->AddRawEventSubscriber(
156 audio_event_subscriber_.get());
119 } 157 }
120 if (video_config_) { 158 if (video_config_) {
121 config.video_ssrc = video_config_->sender_ssrc; 159 config.video_ssrc = video_config_->sender_ssrc;
122 config.video_codec = video_config_->codec; 160 config.video_codec = video_config_->codec;
123 config.video_rtp_config = video_config_->rtp_config; 161 config.video_rtp_config = video_config_->rtp_config;
162
163 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
164 media::cast::VIDEO_EVENT, kMaxVideoEventEntries));
165
166 // Currently on main thread, can call logging directly.
Alpha Left Google 2014/02/21 01:59:19 This comment is not necessary.
imcheng 2014/02/21 03:17:25 Done.
imcheng 2014/02/21 03:17:25 Done.
167 cast_environment_->Logging()->AddRawEventSubscriber(
168 video_event_subscriber_.get());
124 } 169 }
125 170
126 cast_transport_.reset(new CastTransportSenderIPC( 171 cast_transport_.reset(new CastTransportSenderIPC(
127 config, 172 config,
128 base::Bind(&CastSessionDelegate::StatusNotificationCB, 173 base::Bind(&CastSessionDelegate::StatusNotificationCB,
129 base::Unretained(this)))); 174 base::Unretained(this))));
130 175
131 cast_sender_.reset(CastSender::CreateCastSender( 176 cast_sender_.reset(CastSender::CreateCastSender(
132 cast_environment_, 177 cast_environment_,
133 audio_config_.get(), 178 audio_config_.get(),
(...skipping 12 matching lines...) Expand all
146 // TODO(pwestin): handle the error codes. 191 // TODO(pwestin): handle the error codes.
147 if (result == media::cast::STATUS_INITIALIZED) { 192 if (result == media::cast::STATUS_INITIALIZED) {
148 if (!audio_frame_input_available_callback_.is_null()) { 193 if (!audio_frame_input_available_callback_.is_null()) {
149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); 194 audio_frame_input_available_callback_.Run(cast_sender_->frame_input());
150 } 195 }
151 if (!video_frame_input_available_callback_.is_null()) { 196 if (!video_frame_input_available_callback_.is_null()) {
152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); 197 video_frame_input_available_callback_.Run(cast_sender_->frame_input());
153 } 198 }
154 } 199 }
155 } 200 }
OLDNEW
« no previous file with comments | « chrome/renderer/media/cast_session_delegate.h ('k') | media/cast/cast.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698