| 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/lazy_instance.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #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" |
| 9 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | 11 #include "chrome/renderer/media/cast_transport_sender_ipc.h" |
| 10 #include "content/public/renderer/p2p_socket_client.h" | 12 #include "content/public/renderer/p2p_socket_client.h" |
| 11 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
| 12 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
| 13 #include "media/cast/cast_environment.h" | 15 #include "media/cast/cast_environment.h" |
| 14 #include "media/cast/cast_sender.h" | 16 #include "media/cast/cast_sender.h" |
| 15 #include "media/cast/logging/logging_defines.h" | 17 #include "media/cast/logging/logging_defines.h" |
| 16 #include "media/cast/transport/cast_transport_config.h" | 18 #include "media/cast/transport/cast_transport_config.h" |
| 17 #include "media/cast/transport/cast_transport_sender.h" | 19 #include "media/cast/transport/cast_transport_sender.h" |
| 18 | 20 |
| 19 using media::cast::AudioSenderConfig; | 21 using media::cast::AudioSenderConfig; |
| 20 using media::cast::CastEnvironment; | 22 using media::cast::CastEnvironment; |
| 21 using media::cast::CastSender; | 23 using media::cast::CastSender; |
| 22 using media::cast::VideoSenderConfig; | 24 using media::cast::VideoSenderConfig; |
| 23 | 25 |
| 26 static base::LazyInstance<CastThreads> g_cast_threads = |
| 27 LAZY_INSTANCE_INITIALIZER; |
| 28 |
| 24 CastSessionDelegate::CastSessionDelegate() | 29 CastSessionDelegate::CastSessionDelegate() |
| 25 : audio_encode_thread_("CastAudioEncodeThread"), | 30 : transport_configured_(false), |
| 26 video_encode_thread_("CastVideoEncodeThread"), | |
| 27 transport_configured_(false), | |
| 28 io_message_loop_proxy_( | 31 io_message_loop_proxy_( |
| 29 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 32 content::RenderThread::Get()->GetIOMessageLoopProxy()) { |
| 30 DCHECK(io_message_loop_proxy_); | 33 DCHECK(io_message_loop_proxy_); |
| 31 } | 34 } |
| 32 | 35 |
| 33 CastSessionDelegate::~CastSessionDelegate() { | 36 CastSessionDelegate::~CastSessionDelegate() { |
| 34 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 37 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 35 } | 38 } |
| 36 | 39 |
| 37 void CastSessionDelegate::Initialize() { | 40 void CastSessionDelegate::Initialize() { |
| 38 if (cast_environment_) | 41 if (cast_environment_) |
| 39 return; // Already initialized. | 42 return; // Already initialized. |
| 40 | 43 |
| 41 audio_encode_thread_.Start(); | |
| 42 video_encode_thread_.Start(); | |
| 43 | |
| 44 // CastSender uses the renderer's IO thread as the main thread. This reduces | 44 // CastSender uses the renderer's IO thread as the main thread. This reduces |
| 45 // thread hopping for incoming video frames and outgoing network packets. | 45 // thread hopping for incoming video frames and outgoing network packets. |
| 46 // There's no need to decode so no thread assigned for decoding. | 46 // There's no need to decode so no thread assigned for decoding. |
| 47 // Get default logging: All disabled. | 47 // Get default logging: All disabled. |
| 48 cast_environment_ = new CastEnvironment( | 48 cast_environment_ = new CastEnvironment( |
| 49 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 49 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
| 50 base::MessageLoopProxy::current(), | 50 base::MessageLoopProxy::current(), |
| 51 audio_encode_thread_.message_loop_proxy(), | 51 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), |
| 52 NULL, | 52 NULL, |
| 53 video_encode_thread_.message_loop_proxy(), | 53 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), |
| 54 NULL, | 54 NULL, |
| 55 base::MessageLoopProxy::current(), | 55 base::MessageLoopProxy::current(), |
| 56 media::cast::GetDefaultCastSenderLoggingConfig()); | 56 media::cast::GetDefaultCastSenderLoggingConfig()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CastSessionDelegate::StartAudio( | 59 void CastSessionDelegate::StartAudio( |
| 60 const AudioSenderConfig& config, | 60 const AudioSenderConfig& config, |
| 61 const FrameInputAvailableCallback& callback) { | 61 const FrameInputAvailableCallback& callback) { |
| 62 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 62 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 63 | 63 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // TODO(pwestin): handle the error codes. | 146 // TODO(pwestin): handle the error codes. |
| 147 if (result == media::cast::STATUS_INITIALIZED) { | 147 if (result == media::cast::STATUS_INITIALIZED) { |
| 148 if (!audio_frame_input_available_callback_.is_null()) { | 148 if (!audio_frame_input_available_callback_.is_null()) { |
| 149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 150 } | 150 } |
| 151 if (!video_frame_input_available_callback_.is_null()) { | 151 if (!video_frame_input_available_callback_.is_null()) { |
| 152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 } | 155 } |
| OLD | NEW |