| 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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 DCHECK(io_message_loop_proxy_.get()); | 38 DCHECK(io_message_loop_proxy_.get()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 CastSessionDelegateBase::~CastSessionDelegateBase() { | 41 CastSessionDelegateBase::~CastSessionDelegateBase() { |
| 42 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 42 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CastSessionDelegateBase::StartUDP( | 45 void CastSessionDelegateBase::StartUDP( |
| 46 const net::IPEndPoint& local_endpoint, | 46 const net::IPEndPoint& local_endpoint, |
| 47 const net::IPEndPoint& remote_endpoint, | 47 const net::IPEndPoint& remote_endpoint, |
| 48 scoped_ptr<base::DictionaryValue> options) { | 48 scoped_ptr<base::DictionaryValue> options, |
| 49 const ErrorCallback& error_callback) { |
| 49 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 50 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 50 | 51 |
| 51 // CastSender uses the renderer's IO thread as the main thread. This reduces | 52 // CastSender uses the renderer's IO thread as the main thread. This reduces |
| 52 // thread hopping for incoming video frames and outgoing network packets. | 53 // thread hopping for incoming video frames and outgoing network packets. |
| 53 // TODO(hubbe): Create cast environment in ctor instead. | 54 // TODO(hubbe): Create cast environment in ctor instead. |
| 54 cast_environment_ = new CastEnvironment( | 55 cast_environment_ = new CastEnvironment( |
| 55 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 56 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
| 56 base::MessageLoopProxy::current(), | 57 base::MessageLoopProxy::current(), |
| 57 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), | 58 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), |
| 58 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy()); | 59 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy()); |
| 59 | 60 |
| 60 // Rationale for using unretained: The callback cannot be called after the | 61 // Rationale for using unretained: The callback cannot be called after the |
| 61 // destruction of CastTransportSenderIPC, and they both share the same thread. | 62 // destruction of CastTransportSenderIPC, and they both share the same thread. |
| 62 cast_transport_.reset(new CastTransportSenderIPC( | 63 cast_transport_.reset(new CastTransportSenderIPC( |
| 63 local_endpoint, | 64 local_endpoint, |
| 64 remote_endpoint, | 65 remote_endpoint, |
| 65 options.Pass(), | 66 options.Pass(), |
| 66 base::Bind(&CastSessionDelegateBase::ReceivePacket, | 67 base::Bind(&CastSessionDelegateBase::ReceivePacket, |
| 67 base::Unretained(this)), | 68 base::Unretained(this)), |
| 68 base::Bind(&CastSessionDelegateBase::StatusNotificationCB, | 69 base::Bind(&CastSessionDelegateBase::StatusNotificationCB, |
| 69 base::Unretained(this)), | 70 base::Unretained(this), error_callback), |
| 70 base::Bind(&CastSessionDelegateBase::LogRawEvents, | 71 base::Bind(&CastSessionDelegateBase::LogRawEvents, |
| 71 base::Unretained(this)))); | 72 base::Unretained(this)))); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void CastSessionDelegateBase::StatusNotificationCB( | 75 void CastSessionDelegateBase::StatusNotificationCB( |
| 75 media::cast::CastTransportStatus unused_status) { | 76 const ErrorCallback& error_callback, |
| 77 media::cast::CastTransportStatus status) { |
| 76 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 78 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 77 // TODO(hubbe): Call javascript UDPTransport error function. | 79 std::string error_message; |
| 80 |
| 81 switch (status) { |
| 82 case media::cast::TRANSPORT_AUDIO_UNINITIALIZED: |
| 83 case media::cast::TRANSPORT_VIDEO_UNINITIALIZED: |
| 84 case media::cast::TRANSPORT_AUDIO_INITIALIZED: |
| 85 case media::cast::TRANSPORT_VIDEO_INITIALIZED: |
| 86 return; // Not errors, do nothing. |
| 87 case media::cast::TRANSPORT_INVALID_CRYPTO_CONFIG: |
| 88 error_callback.Run("Invalid encrypt/decrypt configuration."); |
| 89 break; |
| 90 case media::cast::TRANSPORT_SOCKET_ERROR: |
| 91 error_callback.Run("Socket error."); |
| 92 break; |
| 93 } |
| 78 } | 94 } |
| 79 | 95 |
| 80 CastSessionDelegate::CastSessionDelegate() | 96 CastSessionDelegate::CastSessionDelegate() |
| 81 : weak_factory_(this) { | 97 : weak_factory_(this) { |
| 82 DCHECK(io_message_loop_proxy_.get()); | 98 DCHECK(io_message_loop_proxy_.get()); |
| 83 } | 99 } |
| 84 | 100 |
| 85 CastSessionDelegate::~CastSessionDelegate() { | 101 CastSessionDelegate::~CastSessionDelegate() { |
| 86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 102 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 87 } | 103 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 base::Bind(&CastSessionDelegate::OnOperationalStatusChange, | 141 base::Bind(&CastSessionDelegate::OnOperationalStatusChange, |
| 126 weak_factory_.GetWeakPtr(), false, error_callback), | 142 weak_factory_.GetWeakPtr(), false, error_callback), |
| 127 create_vea_cb, | 143 create_vea_cb, |
| 128 create_video_encode_mem_cb); | 144 create_video_encode_mem_cb); |
| 129 } | 145 } |
| 130 | 146 |
| 131 | 147 |
| 132 void CastSessionDelegate::StartUDP( | 148 void CastSessionDelegate::StartUDP( |
| 133 const net::IPEndPoint& local_endpoint, | 149 const net::IPEndPoint& local_endpoint, |
| 134 const net::IPEndPoint& remote_endpoint, | 150 const net::IPEndPoint& remote_endpoint, |
| 135 scoped_ptr<base::DictionaryValue> options) { | 151 scoped_ptr<base::DictionaryValue> options, |
| 152 const ErrorCallback& error_callback) { |
| 136 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 153 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 137 CastSessionDelegateBase::StartUDP(local_endpoint, | 154 CastSessionDelegateBase::StartUDP(local_endpoint, |
| 138 remote_endpoint, | 155 remote_endpoint, |
| 139 options.Pass()); | 156 options.Pass(), |
| 157 error_callback); |
| 140 event_subscribers_.reset( | 158 event_subscribers_.reset( |
| 141 new media::cast::RawEventSubscriberBundle(cast_environment_)); | 159 new media::cast::RawEventSubscriberBundle(cast_environment_)); |
| 142 | 160 |
| 143 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); | 161 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); |
| 144 } | 162 } |
| 145 | 163 |
| 146 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { | 164 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { |
| 147 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 165 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 148 if (!event_subscribers_.get()) | 166 if (!event_subscribers_.get()) |
| 149 return; | 167 return; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } else { | 337 } else { |
| 320 cast_environment_->Logging()->InsertFrameEvent( | 338 cast_environment_->Logging()->InsertFrameEvent( |
| 321 it->timestamp, | 339 it->timestamp, |
| 322 it->type, | 340 it->type, |
| 323 it->media_type, | 341 it->media_type, |
| 324 it->rtp_timestamp, | 342 it->rtp_timestamp, |
| 325 it->frame_id); | 343 it->frame_id); |
| 326 } | 344 } |
| 327 } | 345 } |
| 328 } | 346 } |
| OLD | NEW |