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