| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 using media::cast::AudioSenderConfig; | 32 using media::cast::AudioSenderConfig; |
| 33 using media::cast::CastEnvironment; | 33 using media::cast::CastEnvironment; |
| 34 using media::cast::CastSender; | 34 using media::cast::CastSender; |
| 35 using media::cast::VideoSenderConfig; | 35 using media::cast::VideoSenderConfig; |
| 36 | 36 |
| 37 static base::LazyInstance<CastThreads> g_cast_threads = | 37 static base::LazyInstance<CastThreads> g_cast_threads = |
| 38 LAZY_INSTANCE_INITIALIZER; | 38 LAZY_INSTANCE_INITIALIZER; |
| 39 | 39 |
| 40 CastSessionDelegateBase::CastSessionDelegateBase() | 40 CastSessionDelegateBase::CastSessionDelegateBase() |
| 41 : io_task_runner_( | 41 : io_task_runner_(content::RenderThread::Get()->GetIOTaskRunner()), |
| 42 content::RenderThread::Get()->GetIOMessageLoopProxy()), | |
| 43 weak_factory_(this) { | 42 weak_factory_(this) { |
| 44 DCHECK(io_task_runner_.get()); | 43 DCHECK(io_task_runner_.get()); |
| 45 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 46 // Note that this also increases the accuracy of PostDelayTask, | 45 // Note that this also increases the accuracy of PostDelayTask, |
| 47 // which is is very helpful to cast. | 46 // which is is very helpful to cast. |
| 48 if (!base::Time::ActivateHighResolutionTimer(true)) { | 47 if (!base::Time::ActivateHighResolutionTimer(true)) { |
| 49 LOG(WARNING) << "Failed to activate high resolution timers for cast."; | 48 LOG(WARNING) << "Failed to activate high resolution timers for cast."; |
| 50 } | 49 } |
| 51 #endif | 50 #endif |
| 52 } | 51 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 std::unique_ptr<base::DictionaryValue> options, | 63 std::unique_ptr<base::DictionaryValue> options, |
| 65 const ErrorCallback& error_callback) { | 64 const ErrorCallback& error_callback) { |
| 66 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 65 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 67 | 66 |
| 68 // CastSender uses the renderer's IO thread as the main thread. This reduces | 67 // CastSender uses the renderer's IO thread as the main thread. This reduces |
| 69 // thread hopping for incoming video frames and outgoing network packets. | 68 // thread hopping for incoming video frames and outgoing network packets. |
| 70 // TODO(hubbe): Create cast environment in ctor instead. | 69 // TODO(hubbe): Create cast environment in ctor instead. |
| 71 cast_environment_ = new CastEnvironment( | 70 cast_environment_ = new CastEnvironment( |
| 72 std::unique_ptr<base::TickClock>(new base::DefaultTickClock()), | 71 std::unique_ptr<base::TickClock>(new base::DefaultTickClock()), |
| 73 base::ThreadTaskRunnerHandle::Get(), | 72 base::ThreadTaskRunnerHandle::Get(), |
| 74 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), | 73 g_cast_threads.Get().GetAudioEncodeTaskRunner(), |
| 75 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy()); | 74 g_cast_threads.Get().GetVideoEncodeTaskRunner()); |
| 76 | 75 |
| 77 // Rationale for using unretained: The callback cannot be called after the | 76 // Rationale for using unretained: The callback cannot be called after the |
| 78 // destruction of CastTransportIPC, and they both share the same thread. | 77 // destruction of CastTransportIPC, and they both share the same thread. |
| 79 cast_transport_.reset(new CastTransportIPC( | 78 cast_transport_.reset(new CastTransportIPC( |
| 80 local_endpoint, remote_endpoint, std::move(options), | 79 local_endpoint, remote_endpoint, std::move(options), |
| 81 base::Bind(&CastSessionDelegateBase::ReceivePacket, | 80 base::Bind(&CastSessionDelegateBase::ReceivePacket, |
| 82 base::Unretained(this)), | 81 base::Unretained(this)), |
| 83 base::Bind(&CastSessionDelegateBase::StatusNotificationCB, | 82 base::Bind(&CastSessionDelegateBase::StatusNotificationCB, |
| 84 base::Unretained(this), error_callback), | 83 base::Unretained(this), error_callback), |
| 85 base::Bind(&media::cast::LogEventDispatcher::DispatchBatchOfEvents, | 84 base::Bind(&media::cast::LogEventDispatcher::DispatchBatchOfEvents, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 error_callback.Run(base::StringPrintf("%s codec runtime error.", | 306 error_callback.Run(base::StringPrintf("%s codec runtime error.", |
| 308 is_for_audio ? "Audio" : "Video")); | 307 is_for_audio ? "Audio" : "Video")); |
| 309 break; | 308 break; |
| 310 } | 309 } |
| 311 } | 310 } |
| 312 | 311 |
| 313 void CastSessionDelegate::ReceivePacket( | 312 void CastSessionDelegate::ReceivePacket( |
| 314 std::unique_ptr<media::cast::Packet> packet) { | 313 std::unique_ptr<media::cast::Packet> packet) { |
| 315 // Do nothing (frees packet) | 314 // Do nothing (frees packet) |
| 316 } | 315 } |
| OLD | NEW |