Index: chrome/renderer/media/cast_session_delegate.cc |
diff --git a/chrome/renderer/media/cast_session_delegate.cc b/chrome/renderer/media/cast_session_delegate.cc |
index 5da3443f493cb3339e0c6ce789e1a66776af4f78..c8ec09f0481452d46b45bb11900d53118a6af21c 100644 |
--- a/chrome/renderer/media/cast_session_delegate.cc |
+++ b/chrome/renderer/media/cast_session_delegate.cc |
@@ -69,16 +69,8 @@ CastSessionDelegate::CastSessionDelegate() |
: audio_encode_thread_("CastAudioEncodeThread"), |
video_encode_thread_("CastVideoEncodeThread"), |
io_message_loop_proxy_( |
- content::RenderThread::Get()->GetIOMessageLoopProxy()) { |
-} |
- |
-CastSessionDelegate::~CastSessionDelegate() { |
- DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
-} |
- |
-void CastSessionDelegate::Initialize() { |
- if (cast_environment_) |
- return; // Already initialized. |
+ content::RenderThread::Get()->GetIOMessageLoopProxy()), |
+ weak_factory_(this) { |
cast_transport_.reset(new DummyTransport()); |
audio_encode_thread_.Start(); |
@@ -97,6 +89,15 @@ void CastSessionDelegate::Initialize() { |
NULL, |
base::MessageLoopProxy::current(), |
media::cast::GetDefaultCastSenderLoggingConfig()); |
+ cast_sender_.reset( |
+ CastSender::Create(cast_environment_, |
+ base::Bind(&CastSessionDelegate::InitializationResult, |
+ weak_factory_.GetWeakPtr()), |
+ cast_transport_.get())); |
+} |
+ |
+CastSessionDelegate::~CastSessionDelegate() { |
+ DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
} |
void CastSessionDelegate::StartAudio( |
@@ -104,8 +105,9 @@ void CastSessionDelegate::StartAudio( |
const FrameInputAvailableCallback& callback) { |
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
- audio_config_.reset(new AudioSenderConfig(config)); |
- StartSendingInternal(callback, true); |
+ cast_sender_->InitializeAudio(config); |
+ audio_frame_input_available_callback_.reset( |
+ new FrameInputAvailableCallback(callback)); |
} |
void CastSessionDelegate::StartVideo( |
@@ -113,33 +115,10 @@ void CastSessionDelegate::StartVideo( |
const FrameInputAvailableCallback& callback) { |
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
- video_config_.reset(new VideoSenderConfig(config)); |
- StartSendingInternal(callback, false); |
-} |
- |
-void CastSessionDelegate::StartSendingInternal( |
- const FrameInputAvailableCallback& callback, |
- bool is_audio) { |
- DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
- |
- Initialize(); |
- |
- if (is_audio) { |
- audio_frame_input_available_callback_.reset( |
- new FrameInputAvailableCallback(callback)); |
- } else { |
- video_frame_input_available_callback_.reset( |
- new FrameInputAvailableCallback(callback)); |
- } |
- |
- cast_sender_.reset(CastSender::CreateCastSender( |
- cast_environment_, |
- audio_config_.get(), |
- video_config_.get(), |
- NULL, // GPU. |
- base::Bind(&CastSessionDelegate::InitializationResult, |
- base::Unretained(this)), |
- cast_transport_.get())); |
+ // Initialize video - set gpu to NULL. |
+ cast_sender_->InitializeVideo(config, NULL); |
+ video_frame_input_available_callback_.reset( |
+ new FrameInputAvailableCallback(callback)); |
} |
void CastSessionDelegate::InitializationResult( |
@@ -147,12 +126,11 @@ void CastSessionDelegate::InitializationResult( |
DCHECK(cast_sender_); |
// TODO(pwestin): handle the error codes. |
- if (result == media::cast::STATUS_INITIALIZED) { |
- if (audio_frame_input_available_callback_) { |
+ if (result == media::cast::STATUS_AUDIO_INITIALIZED) { |
+ if (audio_frame_input_available_callback_) |
audio_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
- } |
- if (video_frame_input_available_callback_) { |
+ } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { |
+ if (video_frame_input_available_callback_) |
video_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
- } |
} |
} |