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

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

Issue 178073004: Cast: IPC from browser to renderer to send packet events from transport to cast library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix sender app 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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (audio_event_subscriber_.get()) { 51 if (audio_event_subscriber_.get()) {
52 cast_environment_->Logging()->RemoveRawEventSubscriber( 52 cast_environment_->Logging()->RemoveRawEventSubscriber(
53 audio_event_subscriber_.get()); 53 audio_event_subscriber_.get());
54 } 54 }
55 if (video_event_subscriber_.get()) { 55 if (video_event_subscriber_.get()) {
56 cast_environment_->Logging()->RemoveRawEventSubscriber( 56 cast_environment_->Logging()->RemoveRawEventSubscriber(
57 video_event_subscriber_.get()); 57 video_event_subscriber_.get());
58 } 58 }
59 } 59 }
60 60
61 void CastSessionDelegate::Initialize() { 61 void CastSessionDelegate::Initialize(
62 const media::cast::CastLoggingConfig& logging_config) {
62 if (cast_environment_) 63 if (cast_environment_)
63 return; // Already initialized. 64 return; // Already initialized.
64 65
65 // 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
66 // thread hopping for incoming video frames and outgoing network packets. 67 // thread hopping for incoming video frames and outgoing network packets.
67 // 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.
68 // Get default logging: All disabled. 69 // Get default logging: All disabled.
69 cast_environment_ = new CastEnvironment( 70 cast_environment_ = new CastEnvironment(
70 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), 71 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(),
71 base::MessageLoopProxy::current(), 72 base::MessageLoopProxy::current(),
72 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), 73 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
73 NULL, 74 NULL,
74 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), 75 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(),
75 NULL, 76 NULL,
76 base::MessageLoopProxy::current(), 77 base::MessageLoopProxy::current(),
77 media::cast::GetDefaultCastSenderLoggingConfig()); 78 logging_config);
78 } 79 }
79 80
80 void CastSessionDelegate::StartAudio( 81 void CastSessionDelegate::StartAudio(
81 const AudioSenderConfig& config, 82 const AudioSenderConfig& config,
82 const FrameInputAvailableCallback& callback) { 83 const FrameInputAvailableCallback& callback) {
83 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 84 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
84 85
85 audio_config_.reset(new AudioSenderConfig(config)); 86 audio_config_.reset(new AudioSenderConfig(config));
86 video_frame_input_available_callback_ = callback; 87 video_frame_input_available_callback_ = callback;
87 StartSendingInternal(); 88 StartSendingInternal();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
128 129
129 // No transport, wait. 130 // No transport, wait.
130 if (!transport_configured_) 131 if (!transport_configured_)
131 return; 132 return;
132 133
133 // No audio or video, wait. 134 // No audio or video, wait.
134 if (!audio_config_ && !video_config_) 135 if (!audio_config_ && !video_config_)
135 return; 136 return;
136 137
137 Initialize(); 138 // TODO(imcheng): Enable raw event and stats collection.
139 media::cast::CastLoggingConfig logging_config =
140 media::cast::GetDefaultCastSenderLoggingConfig();
138 141
139 media::cast::transport::CastTransportConfig config; 142 Initialize(logging_config);
140 143
141 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. 144 media::cast::transport::CastTransportConfig transport_config;
142 config.local_endpoint = local_endpoint_; 145
143 config.receiver_endpoint = remote_endpoint_; 146 // TODO(hubbe): set transport_config.aes_key and transport_config.aes_iv_mask.
147 transport_config.local_endpoint = local_endpoint_;
148 transport_config.receiver_endpoint = remote_endpoint_;
144 if (audio_config_) { 149 if (audio_config_) {
145 config.audio_ssrc = audio_config_->sender_ssrc; 150 transport_config.audio_ssrc = audio_config_->sender_ssrc;
146 config.audio_codec = audio_config_->codec; 151 transport_config.audio_codec = audio_config_->codec;
147 config.audio_rtp_config = audio_config_->rtp_config; 152 transport_config.audio_rtp_config = audio_config_->rtp_config;
148 config.audio_frequency = audio_config_->frequency; 153 transport_config.audio_frequency = audio_config_->frequency;
149 config.audio_channels = audio_config_->channels; 154 transport_config.audio_channels = audio_config_->channels;
150 155
151 if (!audio_event_subscriber_.get()) { 156 if (!audio_event_subscriber_.get()) {
152 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( 157 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
153 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); 158 media::cast::AUDIO_EVENT, kMaxAudioEventEntries));
154 cast_environment_->Logging()->AddRawEventSubscriber( 159 cast_environment_->Logging()->AddRawEventSubscriber(
155 audio_event_subscriber_.get()); 160 audio_event_subscriber_.get());
156 } 161 }
157 } 162 }
158 if (video_config_) { 163 if (video_config_) {
159 config.video_ssrc = video_config_->sender_ssrc; 164 transport_config.video_ssrc = video_config_->sender_ssrc;
160 config.video_codec = video_config_->codec; 165 transport_config.video_codec = video_config_->codec;
161 config.video_rtp_config = video_config_->rtp_config; 166 transport_config.video_rtp_config = video_config_->rtp_config;
162 167
163 if (!video_event_subscriber_.get()) { 168 if (!video_event_subscriber_.get()) {
164 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( 169 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
165 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); 170 media::cast::VIDEO_EVENT, kMaxVideoEventEntries));
166 cast_environment_->Logging()->AddRawEventSubscriber( 171 cast_environment_->Logging()->AddRawEventSubscriber(
167 video_event_subscriber_.get()); 172 video_event_subscriber_.get());
168 } 173 }
169 } 174 }
170 175
171 cast_transport_.reset(new CastTransportSenderIPC( 176 cast_transport_.reset(new CastTransportSenderIPC(
172 config, 177 transport_config,
178 logging_config,
173 base::Bind(&CastSessionDelegate::StatusNotificationCB, 179 base::Bind(&CastSessionDelegate::StatusNotificationCB,
174 base::Unretained(this)))); 180 base::Unretained(this)),
181 base::Bind(&CastSessionDelegate::LogRawEvents, base::Unretained(this))));
175 182
176 cast_sender_.reset(CastSender::CreateCastSender( 183 cast_sender_.reset(CastSender::CreateCastSender(
177 cast_environment_, 184 cast_environment_,
178 audio_config_.get(), 185 audio_config_.get(),
179 video_config_.get(), 186 video_config_.get(),
180 NULL, // GPU. 187 NULL, // GPU.
181 base::Bind(&CastSessionDelegate::InitializationResult, 188 base::Bind(&CastSessionDelegate::InitializationResult,
182 base::Unretained(this)), 189 base::Unretained(this)),
183 cast_transport_.get())); 190 cast_transport_.get()));
184 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); 191 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver());
185 } 192 }
186 193
187 void CastSessionDelegate::InitializationResult( 194 void CastSessionDelegate::InitializationResult(
188 media::cast::CastInitializationStatus result) const { 195 media::cast::CastInitializationStatus result) const {
189 DCHECK(cast_sender_); 196 DCHECK(cast_sender_);
190 197
191 // TODO(pwestin): handle the error codes. 198 // TODO(pwestin): handle the error codes.
192 if (result == media::cast::STATUS_INITIALIZED) { 199 if (result == media::cast::STATUS_INITIALIZED) {
193 if (!audio_frame_input_available_callback_.is_null()) { 200 if (!audio_frame_input_available_callback_.is_null()) {
194 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); 201 audio_frame_input_available_callback_.Run(cast_sender_->frame_input());
195 } 202 }
196 if (!video_frame_input_available_callback_.is_null()) { 203 if (!video_frame_input_available_callback_.is_null()) {
197 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); 204 video_frame_input_available_callback_.Run(cast_sender_->frame_input());
198 } 205 }
199 } 206 }
200 } 207 }
208
209 void CastSessionDelegate::LogRawEvents(
210 const std::vector<media::cast::PacketEvent>& packet_events) {
211 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
212
213 for (std::vector<media::cast::PacketEvent>::const_iterator it =
214 packet_events.begin();
215 it != packet_events.end();
216 ++it) {
217 cast_environment_->Logging()->InsertPacketEvent(it->timestamp,
218 it->type,
219 it->rtp_timestamp,
220 it->frame_id,
221 it->packet_id,
222 it->max_packet_id,
223 it->size);
224 }
225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698