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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } | |
| 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 | 73 |
| 83 cast_transport_.reset(new DummyTransport()); | 74 cast_transport_.reset(new DummyTransport()); |
| 84 audio_encode_thread_.Start(); | 75 audio_encode_thread_.Start(); |
| 85 video_encode_thread_.Start(); | 76 video_encode_thread_.Start(); |
| 86 | 77 |
| 87 // CastSender uses the renderer's IO thread as the main thread. This reduces | 78 // CastSender uses the renderer's IO thread as the main thread. This reduces |
| 88 // thread hopping for incoming video frames and outgoing network packets. | 79 // thread hopping for incoming video frames and outgoing network packets. |
| 89 // There's no need to decode so no thread assigned for decoding. | 80 // There's no need to decode so no thread assigned for decoding. |
| 90 // Get default logging: All disabled. | 81 // Get default logging: All disabled. |
| 91 cast_environment_ = new CastEnvironment( | 82 cast_environment_ = new CastEnvironment( |
| 92 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 83 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
| 93 base::MessageLoopProxy::current(), | 84 base::MessageLoopProxy::current(), |
| 94 audio_encode_thread_.message_loop_proxy(), | 85 audio_encode_thread_.message_loop_proxy(), |
| 95 NULL, | 86 NULL, |
| 96 video_encode_thread_.message_loop_proxy(), | 87 video_encode_thread_.message_loop_proxy(), |
| 97 NULL, | 88 NULL, |
| 98 base::MessageLoopProxy::current(), | 89 base::MessageLoopProxy::current(), |
| 99 media::cast::GetDefaultCastSenderLoggingConfig()); | 90 media::cast::GetDefaultCastSenderLoggingConfig()); |
| 91 cast_sender_.reset(CastSender::CreateCastSender( | |
| 92 cast_environment_, | |
| 93 base::Bind(&CastSessionDelegate::InitializationResult, | |
| 94 base::Unretained(this)), | |
|
Ami GONE FROM CHROMIUM
2014/02/13 18:02:14
What makes this Unretained safe?
Is it that this b
Alpha Left Google
2014/02/13 19:53:59
I too this this needs an explanation.
Please make
mikhal1
2014/02/14 18:03:16
Switching to a weak ptr.
On 2014/02/13 19:53:59, A
| |
| 95 cast_transport_.get())); | |
| 96 } | |
| 97 | |
| 98 CastSessionDelegate::~CastSessionDelegate() { | |
| 99 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | |
| 100 } | 100 } |
| 101 | 101 |
| 102 void CastSessionDelegate::StartAudio( | 102 void CastSessionDelegate::StartAudio( |
| 103 const AudioSenderConfig& config, | 103 const AudioSenderConfig& config, |
| 104 const FrameInputAvailableCallback& callback) { | 104 const FrameInputAvailableCallback& callback) { |
| 105 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 105 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 106 | 106 |
| 107 audio_config_.reset(new AudioSenderConfig(config)); | 107 cast_sender_->InitializeAudio(config); |
| 108 StartSendingInternal(callback, true); | 108 audio_frame_input_available_callback_.reset( |
| 109 new FrameInputAvailableCallback(callback)); | |
| 109 } | 110 } |
| 110 | 111 |
| 111 void CastSessionDelegate::StartVideo( | 112 void CastSessionDelegate::StartVideo( |
| 112 const VideoSenderConfig& config, | 113 const VideoSenderConfig& config, |
| 113 const FrameInputAvailableCallback& callback) { | 114 const FrameInputAvailableCallback& callback) { |
| 114 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 115 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 115 | 116 |
| 116 video_config_.reset(new VideoSenderConfig(config)); | 117 // Initialize video - set gpu to NULL. |
| 117 StartSendingInternal(callback, false); | 118 cast_sender_->InitializeVideo(config, NULL); |
| 118 } | 119 video_frame_input_available_callback_.reset( |
| 119 | |
| 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)); | 120 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 } | 121 } |
| 144 | 122 |
| 145 void CastSessionDelegate::InitializationResult( | 123 void CastSessionDelegate::InitializationResult( |
| 146 media::cast::CastInitializationStatus result) const { | 124 media::cast::CastInitializationStatus result) const { |
| 147 DCHECK(cast_sender_); | 125 DCHECK(cast_sender_); |
| 148 | 126 |
| 149 // TODO(pwestin): handle the error codes. | 127 // TODO(pwestin): handle the error codes. |
| 150 if (result == media::cast::STATUS_INITIALIZED) { | 128 if (result == media::cast::STATUS_AUDIO_INITIALIZED) { |
| 151 if (audio_frame_input_available_callback_) { | 129 if (audio_frame_input_available_callback_) |
| 152 audio_frame_input_available_callback_->Run(cast_sender_->frame_input()); | 130 audio_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
| 153 } | 131 } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { |
| 154 if (video_frame_input_available_callback_) { | 132 if (video_frame_input_available_callback_) |
| 155 video_frame_input_available_callback_->Run(cast_sender_->frame_input()); | 133 video_frame_input_available_callback_->Run(cast_sender_->frame_input()); |
| 156 } | |
| 157 } | 134 } |
| 158 } | 135 } |
| OLD | NEW |