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 "content/public/renderer/p2p_socket_client.h" | 9 #include "content/public/renderer/p2p_socket_client.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(DummyTransport); | 64 DISALLOW_COPY_AND_ASSIGN(DummyTransport); |
| 65 }; | 65 }; |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 CastSessionDelegate::CastSessionDelegate() | 68 CastSessionDelegate::CastSessionDelegate() |
| 69 : audio_encode_thread_("CastAudioEncodeThread"), | 69 : audio_encode_thread_("CastAudioEncodeThread"), |
| 70 video_encode_thread_("CastVideoEncodeThread"), | 70 video_encode_thread_("CastVideoEncodeThread"), |
| 71 io_message_loop_proxy_( | 71 io_message_loop_proxy_( |
| 72 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 72 content::RenderThread::Get()->GetIOMessageLoopProxy()), |
| 73 } | 73 weak_factory_(this) { |
| 74 | |
| 75 CastSessionDelegate::~CastSessionDelegate() { | |
| 76 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | |
| 77 } | |
| 78 | |
| 79 void CastSessionDelegate::Initialize() { | |
| 80 if (cast_environment_) | |
| 81 return; // Already initialized. | |
| 82 | 74 |
| 83 cast_transport_.reset(new DummyTransport()); | 75 cast_transport_.reset(new DummyTransport()); |
| 84 audio_encode_thread_.Start(); | 76 audio_encode_thread_.Start(); |
| 85 video_encode_thread_.Start(); | 77 video_encode_thread_.Start(); |
| 86 | 78 |
| 87 // CastSender uses the renderer's IO thread as the main thread. This reduces | 79 // CastSender uses the renderer's IO thread as the main thread. This reduces |
| 88 // thread hopping for incoming video frames and outgoing network packets. | 80 // thread hopping for incoming video frames and outgoing network packets. |
| 89 // There's no need to decode so no thread assigned for decoding. | 81 // There's no need to decode so no thread assigned for decoding. |
| 90 // Get default logging: All disabled. | 82 // Get default logging: All disabled. |
| 91 cast_environment_ = new CastEnvironment( | 83 cast_environment_ = new CastEnvironment( |
| 92 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 84 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
| 93 base::MessageLoopProxy::current(), | 85 base::MessageLoopProxy::current(), |
| 94 audio_encode_thread_.message_loop_proxy(), | 86 audio_encode_thread_.message_loop_proxy(), |
| 95 NULL, | 87 NULL, |
| 96 video_encode_thread_.message_loop_proxy(), | 88 video_encode_thread_.message_loop_proxy(), |
| 97 NULL, | 89 NULL, |
| 98 base::MessageLoopProxy::current(), | 90 base::MessageLoopProxy::current(), |
| 99 media::cast::GetDefaultCastSenderLoggingConfig()); | 91 media::cast::GetDefaultCastSenderLoggingConfig()); |
| 92 cast_sender_ = | |
| 93 CastSender::Create(cast_environment_, | |
| 94 base::Bind(&CastSessionDelegate::InitializationResult, | |
| 95 weak_factory_.GetWeakPtr()), | |
| 96 cast_transport_.get())); | |
| 97 } | |
| 98 | |
| 99 CastSessionDelegate::~CastSessionDelegate() { | |
| 100 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | |
| 100 } | 101 } |
| 101 | 102 |
| 102 void CastSessionDelegate::StartAudio( | 103 void CastSessionDelegate::StartAudio( |
| 103 const AudioSenderConfig& config, | 104 const AudioSenderConfig& config, |
| 104 const FrameInputAvailableCallback& callback) { | 105 const FrameInputAvailableCallback& callback) { |
| 105 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 106 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 106 | 107 |
| 107 audio_config_.reset(new AudioSenderConfig(config)); | 108 cast_sender_->InitializeAudio(config); |
| 108 StartSendingInternal(callback, true); | 109 audio_frame_input_available_callback_.reset( |
|
Alpha Left Google
2014/02/18 22:28:13
This is very odd. We rarely use a scoped_ptr to ho
mikhal1
2014/03/05 21:44:05
As mentioned before, resolved when rebased.
On 201
| |
| 110 new FrameInputAvailableCallback(callback)); | |
| 109 } | 111 } |
| 110 | 112 |
| 111 void CastSessionDelegate::StartVideo( | 113 void CastSessionDelegate::StartVideo( |
| 112 const VideoSenderConfig& config, | 114 const VideoSenderConfig& config, |
| 113 const FrameInputAvailableCallback& callback) { | 115 const FrameInputAvailableCallback& callback) { |
| 114 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 116 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 115 | 117 |
| 116 video_config_.reset(new VideoSenderConfig(config)); | 118 // Initialize video - set gpu to NULL. |
|
Alpha Left Google
2014/02/18 22:28:13
nit: This comment should be a TODO to pass in a va
mikhal1
2014/03/05 21:44:05
Done.
| |
| 117 StartSendingInternal(callback, false); | 119 cast_sender_->InitializeVideo(config, NULL); |
| 118 } | 120 video_frame_input_available_callback_.reset( |
|
Alpha Left Google
2014/02/18 22:28:13
This should just be:
video_frame_input_available_c
mikhal1
2014/03/05 21:44:05
Done.
| |
| 119 | 121 new FrameInputAvailableCallback(callback)); |
| 120 void CastSessionDelegate::StartSendingInternal( | |
| 121 const FrameInputAvailableCallback& callback, | |
| 122 bool is_audio) { | |
| 123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | |
| 124 | |
| 125 Initialize(); | |
| 126 | |
| 127 if (is_audio) { | |
| 128 audio_frame_input_available_callback_.reset( | |
| 129 new FrameInputAvailableCallback(callback)); | |
| 130 } else { | |
| 131 video_frame_input_available_callback_.reset( | |
| 132 new FrameInputAvailableCallback(callback)); | |
| 133 } | |
| 134 | |
| 135 cast_sender_.reset(CastSender::CreateCastSender( | |
| 136 cast_environment_, | |
| 137 audio_config_.get(), | |
| 138 video_config_.get(), | |
| 139 NULL, // GPU. | |
| 140 base::Bind(&CastSessionDelegate::InitializationResult, | |
| 141 base::Unretained(this)), | |
| 142 cast_transport_.get())); | |
| 143 } | 122 } |
| 144 | 123 |
| 145 void CastSessionDelegate::InitializationResult( | 124 void CastSessionDelegate::InitializationResult( |
| 146 media::cast::CastInitializationStatus result) const { | 125 media::cast::CastInitializationStatus result) const { |
| 147 DCHECK(cast_sender_); | 126 DCHECK(cast_sender_); |
| 148 | 127 |
| 149 // TODO(pwestin): handle the error codes. | 128 // TODO(pwestin): handle the error codes. |
| 150 if (result == media::cast::STATUS_INITIALIZED) { | 129 if (result == media::cast::STATUS_AUDIO_INITIALIZED) { |
| 151 if (audio_frame_input_available_callback_) { | 130 if (audio_frame_input_available_callback_) |
|
Alpha Left Google
2014/02/18 22:28:13
This should be audio_frame_input_available_callbac
mikhal1
2014/03/05 21:44:05
Done.
| |
| 152 audio_frame_input_available_callback_->Run(cast_sender_->frame_input()); | 131 audio_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
| 153 } | 132 } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { |
| 154 if (video_frame_input_available_callback_) { | 133 if (video_frame_input_available_callback_) |
| 155 video_frame_input_available_callback_->Run(cast_sender_->frame_input()); | 134 video_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
| 156 } | |
| 157 } | 135 } |
| 158 } | 136 } |
| OLD | NEW |