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

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

Issue 174183003: Cast:Transport: Dividing A/V Initialization pipeline (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responding to review + rebasing 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 | Annotate | Revision Log
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 24 matching lines...) Expand all
35 35
36 // Allow about 9MB for audio event logs. Assume serialized log data for 36 // Allow about 9MB for audio event logs. Assume serialized log data for
37 // each frame will take up to 75 bytes. 37 // each frame will take up to 75 bytes.
38 const int kMaxAudioEventEntries = 9000000 / 75; 38 const int kMaxAudioEventEntries = 9000000 / 75;
39 39
40 } // namespace 40 } // namespace
41 41
42 CastSessionDelegate::CastSessionDelegate() 42 CastSessionDelegate::CastSessionDelegate()
43 : transport_configured_(false), 43 : transport_configured_(false),
44 io_message_loop_proxy_( 44 io_message_loop_proxy_(
45 content::RenderThread::Get()->GetIOMessageLoopProxy()) { 45 content::RenderThread::Get()->GetIOMessageLoopProxy()),
46 weak_factory_(this) {
46 DCHECK(io_message_loop_proxy_); 47 DCHECK(io_message_loop_proxy_);
47 } 48 }
48 49
49 CastSessionDelegate::~CastSessionDelegate() { 50 CastSessionDelegate::~CastSessionDelegate() {
50 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 51 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
51 52
52 if (audio_event_subscriber_.get()) { 53 if (audio_event_subscriber_.get()) {
53 cast_environment_->Logging()->RemoveRawEventSubscriber( 54 cast_environment_->Logging()->RemoveRawEventSubscriber(
54 audio_event_subscriber_.get()); 55 audio_event_subscriber_.get());
55 } 56 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void CastSessionDelegate::StartVideo( 92 void CastSessionDelegate::StartVideo(
92 const VideoSenderConfig& config, 93 const VideoSenderConfig& config,
93 const FrameInputAvailableCallback& callback) { 94 const FrameInputAvailableCallback& callback) {
94 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 95 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
95 audio_frame_input_available_callback_ = callback; 96 audio_frame_input_available_callback_ = callback;
96 97
97 video_config_.reset(new VideoSenderConfig(config)); 98 video_config_.reset(new VideoSenderConfig(config));
98 StartSendingInternal(); 99 StartSendingInternal();
99 } 100 }
100 101
101 void CastSessionDelegate::StartUDP( 102 void CastSessionDelegate::StartUDP(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::GetEventLogsAndReset( 111 void CastSessionDelegate::GetEventLogsAndReset(
112 const EventLogsCallback& callback) { 112 const EventLogsCallback& callback) {
113 if (!cast_sender_.get()) 113 if (!cast_sender_.get())
(...skipping 16 matching lines...) Expand all
130 // No transport, wait. 130 // No transport, wait.
131 if (!transport_configured_) 131 if (!transport_configured_)
132 return; 132 return;
133 133
134 // No audio or video, wait. 134 // No audio or video, wait.
135 if (!audio_config_ && !video_config_) 135 if (!audio_config_ && !video_config_)
136 return; 136 return;
137 137
138 Initialize(); 138 Initialize();
139 139
140 media::cast::transport::CastTransportConfig config; 140 // Rationale for using unretained: The callback cannot be called after the
141 // destruction of CastTransportSenderIPC, and they both share the same thread.
142 cast_transport_.reset(new CastTransportSenderIPC(
143 local_endpoint_,
144 remote_endpoint_,
145 base::Bind(&CastSessionDelegate::StatusNotificationCB,
146 base::Unretained(this))));
141 147
142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask.
143 config.local_endpoint = local_endpoint_;
144 config.receiver_endpoint = remote_endpoint_;
145 if (audio_config_) { 148 if (audio_config_) {
146 config.audio_ssrc = audio_config_->sender_ssrc; 149 media::cast::transport::CastTransportAudioConfig config;
147 config.audio_codec = audio_config_->codec; 150 config.base.ssrc = audio_config_->sender_ssrc;
148 config.audio_rtp_config = audio_config_->rtp_config; 151 config.codec = audio_config_->codec;
149 config.audio_frequency = audio_config_->frequency; 152 config.base.rtp_config = audio_config_->rtp_config;
150 config.audio_channels = audio_config_->channels; 153 config.frequency = audio_config_->frequency;
154 config.channels = audio_config_->channels;
155 cast_transport_->InitializeAudio(config);
151 156
152 if (!audio_event_subscriber_.get()) { 157 if (!audio_event_subscriber_.get()) {
153 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( 158 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
154 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); 159 media::cast::AUDIO_EVENT, kMaxAudioEventEntries));
155 cast_environment_->Logging()->AddRawEventSubscriber( 160 cast_environment_->Logging()->AddRawEventSubscriber(
156 audio_event_subscriber_.get()); 161 audio_event_subscriber_.get());
157 } 162 }
158 } 163 }
159 if (video_config_) { 164 if (video_config_) {
160 config.video_ssrc = video_config_->sender_ssrc; 165 media::cast::transport::CastTransportVideoConfig config;
161 config.video_codec = video_config_->codec; 166 config.base.ssrc = video_config_->sender_ssrc;
162 config.video_rtp_config = video_config_->rtp_config; 167 config.codec = video_config_->codec;
163 168 config.base.rtp_config = video_config_->rtp_config;
169 cast_transport_->InitializeVideo(config);
164 if (!video_event_subscriber_.get()) { 170 if (!video_event_subscriber_.get()) {
165 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( 171 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber(
166 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); 172 media::cast::VIDEO_EVENT, kMaxVideoEventEntries));
167 cast_environment_->Logging()->AddRawEventSubscriber( 173 cast_environment_->Logging()->AddRawEventSubscriber(
168 video_event_subscriber_.get()); 174 video_event_subscriber_.get());
169 } 175 }
170 } 176 }
171 177
172 cast_transport_.reset(new CastTransportSenderIPC(
173 config,
174 base::Bind(&CastSessionDelegate::StatusNotificationCB,
175 base::Unretained(this))));
176
177 cast_sender_.reset(CastSender::CreateCastSender( 178 cast_sender_.reset(CastSender::CreateCastSender(
178 cast_environment_, 179 cast_environment_,
179 audio_config_.get(), 180 audio_config_.get(),
180 video_config_.get(), 181 video_config_.get(),
181 NULL, // GPU. 182 NULL, // GPU.
182 base::Bind(&CastSessionDelegate::InitializationResult, 183 base::Bind(&CastSessionDelegate::InitializationResult,
183 base::Unretained(this)), 184 weak_factory_.GetWeakPtr()),
184 cast_transport_.get())); 185 cast_transport_.get()));
185 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); 186 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver());
186 } 187 }
187 188
188 void CastSessionDelegate::InitializationResult( 189 void CastSessionDelegate::InitializationResult(
189 media::cast::CastInitializationStatus result) const { 190 media::cast::CastInitializationStatus result) const {
190 DCHECK(cast_sender_); 191 DCHECK(cast_sender_);
191 192
192 // TODO(pwestin): handle the error codes. 193 // TODO(pwestin): handle the error codes.
193 if (result == media::cast::STATUS_INITIALIZED) { 194 if (result == media::cast::STATUS_INITIALIZED) {
194 if (!audio_frame_input_available_callback_.is_null()) { 195 if (!audio_frame_input_available_callback_.is_null()) {
195 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); 196 audio_frame_input_available_callback_.Run(cast_sender_->frame_input());
196 } 197 }
197 if (!video_frame_input_available_callback_.is_null()) { 198 if (!video_frame_input_available_callback_.is_null()) {
198 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); 199 video_frame_input_available_callback_.Run(cast_sender_->frame_input());
199 } 200 }
200 } 201 }
201 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698