Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/logging_defines.h" | 15 #include "media/cast/logging/logging_defines.h" |
| 16 #include "media/cast/transport/cast_transport_config.h" | 16 #include "media/cast/transport/cast_transport_config.h" |
| 17 #include "media/cast/transport/cast_transport_sender.h" | 17 #include "media/cast/transport/cast_transport_sender.h" |
| 18 | 18 |
| 19 using media::cast::AudioSenderConfig; | 19 using media::cast::AudioSenderConfig; |
| 20 using media::cast::CastEnvironment; | 20 using media::cast::CastEnvironment; |
| 21 using media::cast::CastSender; | 21 using media::cast::CastSender; |
| 22 using media::cast::VideoSenderConfig; | 22 using media::cast::VideoSenderConfig; |
| 23 | 23 |
| 24 CastSessionDelegate::CastSessionDelegate() | 24 CastSessionDelegate::CastSessionDelegate() |
| 25 : audio_encode_thread_("CastAudioEncodeThread"), | 25 : audio_encode_thread_("CastAudioEncodeThread"), |
| 26 video_encode_thread_("CastVideoEncodeThread"), | 26 video_encode_thread_("CastVideoEncodeThread"), |
| 27 transport_configured_(false), | 27 transport_configured_(false), |
| 28 io_message_loop_proxy_( | 28 io_message_loop_proxy_( |
| 29 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 29 content::RenderThread::Get()->GetIOMessageLoopProxy()), |
| 30 weak_factory_(this) { | |
| 30 DCHECK(io_message_loop_proxy_); | 31 DCHECK(io_message_loop_proxy_); |
| 31 } | 32 } |
| 32 | 33 |
| 33 CastSessionDelegate::~CastSessionDelegate() { | 34 CastSessionDelegate::~CastSessionDelegate() { |
| 34 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 35 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void CastSessionDelegate::Initialize() { | 38 void CastSessionDelegate::Initialize() { |
| 38 if (cast_environment_) | 39 if (cast_environment_) |
| 39 return; // Already initialized. | 40 return; // Already initialized. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // No transport, wait. | 99 // No transport, wait. |
| 99 if (!transport_configured_) | 100 if (!transport_configured_) |
| 100 return; | 101 return; |
| 101 | 102 |
| 102 // No audio or video, wait. | 103 // No audio or video, wait. |
| 103 if (!audio_config_ && !video_config_) | 104 if (!audio_config_ && !video_config_) |
| 104 return; | 105 return; |
| 105 | 106 |
| 106 Initialize(); | 107 Initialize(); |
| 107 | 108 |
| 108 media::cast::transport::CastTransportConfig config; | 109 media::cast::transport::CastTransportAudioConfig audio_config; |
| 110 media::cast::transport::CastTransportVideoConfig video_config; | |
| 109 | 111 |
| 110 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 112 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. |
| 111 config.local_endpoint = local_endpoint_; | 113 cast_transport_.reset(new CastTransportSenderIPC( |
| 112 config.receiver_endpoint = remote_endpoint_; | 114 local_endpoint_, |
| 115 remote_endpoint_, | |
| 116 base::Bind(&CastSessionDelegate::StatusNotificationCB, | |
| 117 weak_factory_.GetWeakPtr()))); | |
|
hubbe
2014/02/21 23:41:23
How can we get callbacks if the CastTransportSende
mikhal1
2014/02/24 17:02:50
Specifically here, probably not. But we already ha
hubbe
2014/02/25 00:37:04
It is harmful in two ways:
1: There is extra overh
Ami GONE FROM CHROMIUM
2014/02/25 00:57:25
FWIW I consider #1 above to be a non-issue, and #2
mikhal1
2014/02/25 18:07:02
Back to unretained, added a comment,
On 2014/02/25
| |
| 113 if (audio_config_) { | 118 if (audio_config_) { |
| 114 config.audio_ssrc = audio_config_->sender_ssrc; | 119 audio_config.base.ssrc = audio_config_->sender_ssrc; |
| 115 config.audio_codec = audio_config_->codec; | 120 audio_config.codec = audio_config_->codec; |
| 116 config.audio_rtp_config = audio_config_->rtp_config; | 121 audio_config.base.rtp_config = audio_config_->rtp_config; |
| 117 config.audio_frequency = audio_config_->frequency; | 122 audio_config.frequency = audio_config_->frequency; |
| 118 config.audio_channels = audio_config_->channels; | 123 audio_config.channels = audio_config_->channels; |
| 124 cast_transport_->InitializeAudio(audio_config); | |
| 119 } | 125 } |
| 120 if (video_config_) { | 126 if (video_config_) { |
| 121 config.video_ssrc = video_config_->sender_ssrc; | 127 video_config.base.ssrc = video_config_->sender_ssrc; |
| 122 config.video_codec = video_config_->codec; | 128 video_config.codec = video_config_->codec; |
| 123 config.video_rtp_config = video_config_->rtp_config; | 129 video_config.base.rtp_config = video_config_->rtp_config; |
| 130 cast_transport_->InitializeVideo(video_config); | |
| 124 } | 131 } |
| 125 | 132 |
| 126 cast_transport_.reset(new CastTransportSenderIPC( | |
| 127 config, | |
| 128 base::Bind(&CastSessionDelegate::StatusNotificationCB, | |
| 129 base::Unretained(this)))); | |
| 130 | |
| 131 cast_sender_.reset(CastSender::CreateCastSender( | 133 cast_sender_.reset(CastSender::CreateCastSender( |
| 132 cast_environment_, | 134 cast_environment_, |
| 133 audio_config_.get(), | 135 audio_config_.get(), |
| 134 video_config_.get(), | 136 video_config_.get(), |
| 135 NULL, // GPU. | 137 NULL, // GPU. |
| 136 base::Bind(&CastSessionDelegate::InitializationResult, | 138 base::Bind(&CastSessionDelegate::InitializationResult, |
| 137 base::Unretained(this)), | 139 weak_factory_.GetWeakPtr()), |
| 138 cast_transport_.get())); | 140 cast_transport_.get())); |
| 139 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); | 141 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void CastSessionDelegate::InitializationResult( | 144 void CastSessionDelegate::InitializationResult( |
| 143 media::cast::CastInitializationStatus result) const { | 145 media::cast::CastInitializationStatus result) const { |
| 144 DCHECK(cast_sender_); | 146 DCHECK(cast_sender_); |
| 145 | 147 |
| 146 // TODO(pwestin): handle the error codes. | 148 // TODO(pwestin): handle the error codes. |
| 147 if (result == media::cast::STATUS_INITIALIZED) { | 149 if (result == media::cast::STATUS_INITIALIZED) { |
| 148 if (!audio_frame_input_available_callback_.is_null()) { | 150 if (!audio_frame_input_available_callback_.is_null()) { |
| 149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 151 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 150 } | 152 } |
| 151 if (!video_frame_input_available_callback_.is_null()) { | 153 if (!video_frame_input_available_callback_.is_null()) { |
| 152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 154 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 } | 157 } |
| OLD | NEW |