| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_receiver_session_delegate.h" | 5 #include "chrome/renderer/media/cast_receiver_session_delegate.h" |
| 6 | 6 |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 CastReceiverSessionDelegate::CastReceiverSessionDelegate() | 10 CastReceiverSessionDelegate::CastReceiverSessionDelegate() |
| 11 : weak_factory_(this) { | 11 : weak_factory_(this) { |
| 12 } | 12 } |
| 13 CastReceiverSessionDelegate::~CastReceiverSessionDelegate() {} | 13 CastReceiverSessionDelegate::~CastReceiverSessionDelegate() {} |
| 14 | 14 |
| 15 void CastReceiverSessionDelegate::LogRawEvents( | 15 void CastReceiverSessionDelegate::LogRawEvents( |
| 16 const std::vector<media::cast::PacketEvent>& packet_events, | 16 const std::vector<media::cast::PacketEvent>& packet_events, |
| 17 const std::vector<media::cast::FrameEvent>& frame_events) { | 17 const std::vector<media::cast::FrameEvent>& frame_events) { |
| 18 NOTREACHED(); | 18 NOTREACHED(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void CastReceiverSessionDelegate::Start( | 21 void CastReceiverSessionDelegate::Start( |
| 22 const media::cast::FrameReceiverConfig& audio_config, | 22 const media::cast::FrameReceiverConfig& audio_config, |
| 23 const media::cast::FrameReceiverConfig& video_config, | 23 const media::cast::FrameReceiverConfig& video_config, |
| 24 const net::IPEndPoint& local_endpoint, | 24 const net::IPEndPoint& local_endpoint, |
| 25 const net::IPEndPoint& remote_endpoint, | 25 const net::IPEndPoint& remote_endpoint, |
| 26 scoped_ptr<base::DictionaryValue> options, | 26 scoped_ptr<base::DictionaryValue> options, |
| 27 const media::VideoCaptureFormat& format, | 27 const media::VideoCaptureFormat& format, |
| 28 const ErrorCallback& error_callback) { | 28 const ErrorCallback& error_callback) { |
| 29 format_ = format; | 29 format_ = format; |
| 30 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 30 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 31 CastSessionDelegateBase::StartUDP(local_endpoint, | 31 CastSessionDelegateBase::StartUDP(local_endpoint, |
| 32 remote_endpoint, | 32 remote_endpoint, |
| 33 options.Pass(), | 33 options.Pass(), |
| 34 error_callback); | 34 error_callback); |
| 35 cast_receiver_ = media::cast::CastReceiver::Create(cast_environment_, | 35 cast_receiver_ = media::cast::CastReceiver::Create(cast_environment_, |
| 36 audio_config, | 36 audio_config, |
| 37 video_config, | 37 video_config, |
| 38 cast_transport_.get()); | 38 cast_transport_.get()); |
| 39 on_audio_decoded_cb_ = base::Bind( | 39 on_audio_decoded_cb_ = base::Bind( |
| 40 &CastReceiverSessionDelegate::OnDecodedAudioFrame, | 40 &CastReceiverSessionDelegate::OnDecodedAudioFrame, |
| 41 weak_factory_.GetWeakPtr()); | 41 weak_factory_.GetWeakPtr()); |
| 42 on_video_decoded_cb_ = base::Bind( | 42 on_video_decoded_cb_ = base::Bind( |
| 43 &CastReceiverSessionDelegate::OnDecodedVideoFrame, | 43 &CastReceiverSessionDelegate::OnDecodedVideoFrame, |
| 44 weak_factory_.GetWeakPtr()); | 44 weak_factory_.GetWeakPtr()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CastReceiverSessionDelegate::ReceivePacket( | 47 void CastReceiverSessionDelegate::ReceivePacket( |
| 48 scoped_ptr<media::cast::Packet> packet) { | 48 scoped_ptr<media::cast::Packet> packet) { |
| 49 cast_receiver_->ReceivePacket(packet.Pass()); | 49 cast_receiver_->ReceivePacket(packet.Pass()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CastReceiverSessionDelegate::StartAudio( | 52 void CastReceiverSessionDelegate::StartAudio( |
| 53 scoped_refptr<CastReceiverAudioValve> audio_valve) { | 53 scoped_refptr<CastReceiverAudioValve> audio_valve) { |
| 54 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 54 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 55 audio_valve_ = audio_valve; | 55 audio_valve_ = audio_valve; |
| 56 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); | 56 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CastReceiverSessionDelegate::OnDecodedAudioFrame( | 59 void CastReceiverSessionDelegate::OnDecodedAudioFrame( |
| 60 scoped_ptr<media::AudioBus> audio_bus, | 60 scoped_ptr<media::AudioBus> audio_bus, |
| 61 const base::TimeTicks& playout_time, | 61 const base::TimeTicks& playout_time, |
| 62 bool is_continous) { | 62 bool is_continous) { |
| 63 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 63 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 64 if (!audio_valve_) | 64 if (!audio_valve_) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 // We're on the IO thread, which doesn't allow blocking | 67 // We're on the IO thread, which doesn't allow blocking |
| 68 // operations. Since we don't know what the Capture callback | 68 // operations. Since we don't know what the Capture callback |
| 69 // will do exactly, we need to jump to a different thread. | 69 // will do exactly, we need to jump to a different thread. |
| 70 // Let's re-use the audio decoder thread. | 70 // Let's re-use the audio decoder thread. |
| 71 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 71 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 72 cast_environment_->PostTask( | 72 cast_environment_->PostTask( |
| 73 media::cast::CastEnvironment::AUDIO, | 73 media::cast::CastEnvironment::AUDIO, |
| 74 FROM_HERE, | 74 FROM_HERE, |
| 75 base::Bind(&CastReceiverAudioValve::Capture, | 75 base::Bind(&CastReceiverAudioValve::Capture, |
| 76 audio_valve_, | 76 audio_valve_, |
| 77 base::Owned(audio_bus.release()), | 77 base::Owned(audio_bus.release()), |
| 78 (playout_time - now).InMilliseconds(), | 78 (playout_time - now).InMilliseconds(), |
| 79 1.0, | 79 1.0, |
| 80 false)); | 80 false)); |
| 81 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); | 81 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void CastReceiverSessionDelegate::StartVideo( | 84 void CastReceiverSessionDelegate::StartVideo( |
| 85 content::VideoCaptureDeliverFrameCB video_callback) { | 85 content::VideoCaptureDeliverFrameCB video_callback) { |
| 86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 86 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 87 frame_callback_ = video_callback; | 87 frame_callback_ = video_callback; |
| 88 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); | 88 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void CastReceiverSessionDelegate::StopVideo() { | 91 void CastReceiverSessionDelegate::StopVideo() { |
| 92 frame_callback_ = content::VideoCaptureDeliverFrameCB(); | 92 frame_callback_ = content::VideoCaptureDeliverFrameCB(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void CastReceiverSessionDelegate::OnDecodedVideoFrame( | 95 void CastReceiverSessionDelegate::OnDecodedVideoFrame( |
| 96 const scoped_refptr<media::VideoFrame>& video_frame, | 96 const scoped_refptr<media::VideoFrame>& video_frame, |
| 97 const base::TimeTicks& playout_time, | 97 const base::TimeTicks& playout_time, |
| 98 bool is_continous) { | 98 bool is_continous) { |
| 99 if (frame_callback_.is_null()) | 99 if (frame_callback_.is_null()) |
| 100 return; | 100 return; |
| 101 frame_callback_.Run(video_frame, playout_time); | 101 frame_callback_.Run(video_frame, playout_time); |
| 102 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); | 102 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); |
| 103 } | 103 } |
| OLD | NEW |