| 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.h" | 5 #include "chrome/renderer/media/cast_session.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "chrome/renderer/media/cast_session_delegate.h" | 8 #include "chrome/renderer/media/cast_session_delegate.h" |
| 9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
| 10 #include "content/public/renderer/video_encode_accelerator.h" | 10 #include "content/public/renderer/video_encode_accelerator.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (!shm->Map(size)) { | 35 if (!shm->Map(size)) { |
| 36 NOTREACHED() << "Map failed"; | 36 NOTREACHED() << "Map failed"; |
| 37 } | 37 } |
| 38 callback.Run(shm.Pass()); | 38 callback.Run(shm.Pass()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 CastSession::CastSession() | 43 CastSession::CastSession() |
| 44 : delegate_(new CastSessionDelegate()), | 44 : delegate_(new CastSessionDelegate()), |
| 45 io_message_loop_proxy_( | 45 io_task_runner_( |
| 46 content::RenderThread::Get()->GetIOMessageLoopProxy()) {} | 46 content::RenderThread::Get()->GetIOMessageLoopProxy()) {} |
| 47 | 47 |
| 48 CastSession::~CastSession() { | 48 CastSession::~CastSession() { |
| 49 // We should always be able to delete the object on the IO thread. | 49 // We should always be able to delete the object on the IO thread. |
| 50 CHECK(io_message_loop_proxy_->DeleteSoon(FROM_HERE, delegate_.release())); | 50 CHECK(io_task_runner_->DeleteSoon(FROM_HERE, delegate_.release())); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CastSession::StartAudio(const media::cast::AudioSenderConfig& config, | 53 void CastSession::StartAudio(const media::cast::AudioSenderConfig& config, |
| 54 const AudioFrameInputAvailableCallback& callback, | 54 const AudioFrameInputAvailableCallback& callback, |
| 55 const ErrorCallback& error_callback) { | 55 const ErrorCallback& error_callback) { |
| 56 DCHECK(content::RenderThread::Get() | 56 DCHECK(content::RenderThread::Get() |
| 57 ->GetTaskRunner()->BelongsToCurrentThread()); | 57 ->GetTaskRunner()->BelongsToCurrentThread()); |
| 58 | 58 |
| 59 io_message_loop_proxy_->PostTask( | 59 io_task_runner_->PostTask( |
| 60 FROM_HERE, | 60 FROM_HERE, |
| 61 base::Bind(&CastSessionDelegate::StartAudio, | 61 base::Bind(&CastSessionDelegate::StartAudio, |
| 62 base::Unretained(delegate_.get()), | 62 base::Unretained(delegate_.get()), |
| 63 config, | 63 config, |
| 64 media::BindToCurrentLoop(callback), | 64 media::BindToCurrentLoop(callback), |
| 65 media::BindToCurrentLoop(error_callback))); | 65 media::BindToCurrentLoop(error_callback))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void CastSession::StartVideo(const media::cast::VideoSenderConfig& config, | 68 void CastSession::StartVideo(const media::cast::VideoSenderConfig& config, |
| 69 const VideoFrameInputAvailableCallback& callback, | 69 const VideoFrameInputAvailableCallback& callback, |
| 70 const ErrorCallback& error_callback) { | 70 const ErrorCallback& error_callback) { |
| 71 DCHECK(content::RenderThread::Get() | 71 DCHECK(content::RenderThread::Get() |
| 72 ->GetTaskRunner()->BelongsToCurrentThread()); | 72 ->GetTaskRunner()->BelongsToCurrentThread()); |
| 73 | 73 |
| 74 io_message_loop_proxy_->PostTask( | 74 io_task_runner_->PostTask( |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 base::Bind(&CastSessionDelegate::StartVideo, | 76 base::Bind(&CastSessionDelegate::StartVideo, |
| 77 base::Unretained(delegate_.get()), | 77 base::Unretained(delegate_.get()), |
| 78 config, | 78 config, |
| 79 media::BindToCurrentLoop(callback), | 79 media::BindToCurrentLoop(callback), |
| 80 media::BindToCurrentLoop(error_callback), | 80 media::BindToCurrentLoop(error_callback), |
| 81 media::BindToCurrentLoop( | 81 media::BindToCurrentLoop( |
| 82 base::Bind(&CreateVideoEncodeAccelerator)), | 82 base::Bind(&CreateVideoEncodeAccelerator)), |
| 83 media::BindToCurrentLoop( | 83 media::BindToCurrentLoop( |
| 84 base::Bind(&CreateVideoEncodeMemory)))); | 84 base::Bind(&CreateVideoEncodeMemory)))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void CastSession::StartUDP(const net::IPEndPoint& remote_endpoint, | 87 void CastSession::StartUDP(const net::IPEndPoint& remote_endpoint, |
| 88 scoped_ptr<base::DictionaryValue> options, | 88 scoped_ptr<base::DictionaryValue> options, |
| 89 const ErrorCallback& error_callback) { | 89 const ErrorCallback& error_callback) { |
| 90 io_message_loop_proxy_->PostTask( | 90 io_task_runner_->PostTask( |
| 91 FROM_HERE, | 91 FROM_HERE, |
| 92 base::Bind( | 92 base::Bind( |
| 93 &CastSessionDelegate::StartUDP, | 93 &CastSessionDelegate::StartUDP, |
| 94 base::Unretained(delegate_.get()), | 94 base::Unretained(delegate_.get()), |
| 95 net::IPEndPoint(), | 95 net::IPEndPoint(), |
| 96 remote_endpoint, | 96 remote_endpoint, |
| 97 base::Passed(&options), | 97 base::Passed(&options), |
| 98 media::BindToCurrentLoop(error_callback))); | 98 media::BindToCurrentLoop(error_callback))); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CastSession::ToggleLogging(bool is_audio, bool enable) { | 101 void CastSession::ToggleLogging(bool is_audio, bool enable) { |
| 102 io_message_loop_proxy_->PostTask( | 102 io_task_runner_->PostTask( |
| 103 FROM_HERE, | 103 FROM_HERE, |
| 104 base::Bind(&CastSessionDelegate::ToggleLogging, | 104 base::Bind(&CastSessionDelegate::ToggleLogging, |
| 105 base::Unretained(delegate_.get()), | 105 base::Unretained(delegate_.get()), |
| 106 is_audio, | 106 is_audio, |
| 107 enable)); | 107 enable)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void CastSession::GetEventLogsAndReset( | 110 void CastSession::GetEventLogsAndReset( |
| 111 bool is_audio, const std::string& extra_data, | 111 bool is_audio, const std::string& extra_data, |
| 112 const EventLogsCallback& callback) { | 112 const EventLogsCallback& callback) { |
| 113 io_message_loop_proxy_->PostTask( | 113 io_task_runner_->PostTask( |
| 114 FROM_HERE, | 114 FROM_HERE, |
| 115 base::Bind(&CastSessionDelegate::GetEventLogsAndReset, | 115 base::Bind(&CastSessionDelegate::GetEventLogsAndReset, |
| 116 base::Unretained(delegate_.get()), | 116 base::Unretained(delegate_.get()), |
| 117 is_audio, | 117 is_audio, |
| 118 extra_data, | 118 extra_data, |
| 119 media::BindToCurrentLoop(callback))); | 119 media::BindToCurrentLoop(callback))); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void CastSession::GetStatsAndReset(bool is_audio, | 122 void CastSession::GetStatsAndReset(bool is_audio, |
| 123 const StatsCallback& callback) { | 123 const StatsCallback& callback) { |
| 124 io_message_loop_proxy_->PostTask( | 124 io_task_runner_->PostTask( |
| 125 FROM_HERE, | 125 FROM_HERE, |
| 126 base::Bind(&CastSessionDelegate::GetStatsAndReset, | 126 base::Bind(&CastSessionDelegate::GetStatsAndReset, |
| 127 base::Unretained(delegate_.get()), | 127 base::Unretained(delegate_.get()), |
| 128 is_audio, | 128 is_audio, |
| 129 media::BindToCurrentLoop(callback))); | 129 media::BindToCurrentLoop(callback))); |
| 130 } | 130 } |
| OLD | NEW |