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.h" | |
| 6 | |
| 7 #include "base/synchronization/waitable_event.h" | |
| 8 #include "chrome/renderer/media/cast_receiver_audio_valve.h" | |
| 9 #include "content/public/renderer/media_stream_source_api.h" | |
| 10 #include "content/public/renderer/render_thread.h" | |
| 11 #include "media/base/audio_capturer_source.h" | |
| 12 #include "media/base/video_capturer_source.h" | |
| 13 #include "third_party/WebKit/public/platform/WebMediaStream.h" | |
| 14 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
| 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 16 | |
| 17 // This is a render thread object. | |
| 18 class CastStreamingAudioCapturerSource : public media::AudioCapturerSource { | |
| 19 public: | |
| 20 CastStreamingAudioCapturerSource( | |
| 21 scoped_refptr<CastReceiverSession> cast_receiver_session); | |
| 22 void Initialize(const media::AudioParameters& params, | |
| 23 CaptureCallback* callback, | |
| 24 int session_id) override; | |
| 25 void Start() override; | |
| 26 void Stop() override; | |
| 27 void SetVolume(double volume) override; | |
| 28 void SetAutomaticGainControl(bool enable) override; | |
| 29 private: | |
| 30 ~CastStreamingAudioCapturerSource() override; | |
| 31 scoped_refptr<CastReceiverSession> cast_receiver_session_; | |
|
miu
2015/02/11 02:52:49
nit: const scoped_refptr<...>
hubbe
2015/02/11 22:38:17
Done.
| |
| 32 scoped_refptr<CastReceiverAudioValve> audio_valve_; | |
| 33 }; | |
| 34 | |
| 35 // This is a render thread object. | |
| 36 class CastStreamingVideoCapturerSource : public media::VideoCapturerSource { | |
| 37 public: | |
| 38 explicit CastStreamingVideoCapturerSource( | |
| 39 scoped_refptr<CastReceiverSession> cast_receiver_session); | |
| 40 protected: | |
| 41 void GetCurrentSupportedFormats( | |
| 42 int max_requested_width, | |
| 43 int max_requested_height, | |
| 44 double max_requested_frame_rate, | |
| 45 const VideoCaptureDeviceFormatsCB& callback) override; | |
| 46 void StartCapture( | |
| 47 const media::VideoCaptureParams& params, | |
| 48 const content::VideoCaptureDeliverFrameCB& frame_callback, | |
| 49 scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner, | |
| 50 const RunningCallback& running_callback) override; | |
| 51 void StopCapture() override; | |
| 52 private: | |
| 53 scoped_refptr<CastReceiverSession> cast_receiver_session_; | |
|
miu
2015/02/11 02:52:49
ditto on const scoped_refptr<...>
hubbe
2015/02/11 22:38:16
Done.
| |
| 54 }; | |
| 55 | |
| 56 CastReceiverSession::CastReceiverSession() | |
| 57 : delegate_(new CastReceiverSessionDelegate()), | |
| 58 io_message_loop_proxy_( | |
| 59 content::RenderThread::Get()->GetIOMessageLoopProxy()) {} | |
| 60 | |
| 61 CastReceiverSession::~CastReceiverSession() { | |
| 62 // We should always be able to delete the object on the IO thread. | |
| 63 CHECK(io_message_loop_proxy_->DeleteSoon(FROM_HERE, delegate_.release())); | |
| 64 } | |
| 65 | |
| 66 void CastReceiverSession::Start( | |
| 67 const media::cast::FrameReceiverConfig& audio_config, | |
| 68 const media::cast::FrameReceiverConfig& video_config, | |
| 69 const net::IPEndPoint& local_endpoint, | |
| 70 const net::IPEndPoint& remote_endpoint, | |
| 71 scoped_ptr<base::DictionaryValue> options, | |
| 72 const media::VideoCaptureFormat& capture_format, | |
| 73 const StartCB& start_callback) { | |
| 74 format_ = capture_format; | |
| 75 io_message_loop_proxy_->PostTask( | |
| 76 FROM_HERE, | |
| 77 base::Bind(&CastReceiverSessionDelegate::Start, | |
| 78 base::Unretained(delegate_.get()), | |
| 79 audio_config, | |
| 80 video_config, | |
| 81 local_endpoint, | |
| 82 remote_endpoint, | |
| 83 base::Passed(&options), | |
| 84 format_)); | |
| 85 blink::WebMediaStreamSource video_source; | |
| 86 content::InitializeWebMediaStreamSourceForVideo( | |
| 87 make_scoped_ptr(new CastStreamingVideoCapturerSource(this)), | |
| 88 &video_source, | |
| 89 true, | |
| 90 true); | |
| 91 blink::WebVector<blink::WebMediaStreamTrack> video_tracks( | |
| 92 static_cast<size_t>(1)); | |
| 93 video_tracks[0].initialize(video_source); | |
| 94 | |
| 95 blink::WebMediaStreamSource audio_source; | |
| 96 content::InitializeWebMediaStreamSourceForAudio( | |
| 97 new CastStreamingAudioCapturerSource(this), | |
| 98 &audio_source, | |
| 99 true, | |
| 100 true); | |
| 101 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks( | |
| 102 static_cast<size_t>(1)); | |
| 103 audio_tracks[0].initialize(audio_source); | |
| 104 | |
| 105 blink::WebMediaStream stream; | |
| 106 stream.initialize(audio_tracks, video_tracks); | |
| 107 | |
| 108 base::MessageLoop::current()->PostTask( | |
| 109 FROM_HERE, | |
| 110 base::Bind(start_callback, stream)); | |
| 111 } | |
| 112 | |
| 113 void CastReceiverSession::StartAudio( | |
| 114 scoped_refptr<CastReceiverAudioValve> audio_valve) { | |
| 115 io_message_loop_proxy_->PostTask( | |
| 116 FROM_HERE, | |
| 117 base::Bind(&CastReceiverSessionDelegate::StartAudio, | |
| 118 base::Unretained(delegate_.get()), | |
| 119 audio_valve)); | |
| 120 } | |
| 121 | |
| 122 void CastReceiverSession::StartVideo( | |
| 123 content::VideoCaptureDeliverFrameCB frame_callback) { | |
| 124 io_message_loop_proxy_->PostTask( | |
| 125 FROM_HERE, | |
| 126 base::Bind(&CastReceiverSessionDelegate::StartVideo, | |
| 127 base::Unretained(delegate_.get()), | |
| 128 frame_callback)); | |
| 129 } | |
| 130 | |
| 131 void CastReceiverSession::StopVideo() { | |
| 132 io_message_loop_proxy_->PostTask( | |
| 133 FROM_HERE, | |
| 134 base::Bind(&CastReceiverSessionDelegate::StopVideo, | |
| 135 base::Unretained(delegate_.get()))); | |
| 136 } | |
| 137 | |
| 138 CastStreamingVideoCapturerSource::CastStreamingVideoCapturerSource( | |
|
miu
2015/02/11 02:52:49
Should this class include a destructor with a DCHE
hubbe
2015/02/11 22:38:16
For video it is actually not relevant if they call
| |
| 139 scoped_refptr<CastReceiverSession> cast_receiver_session) | |
| 140 : cast_receiver_session_(cast_receiver_session) { | |
| 141 } | |
| 142 | |
| 143 void CastStreamingVideoCapturerSource::GetCurrentSupportedFormats( | |
| 144 int max_requested_width, | |
| 145 int max_requested_height, | |
| 146 double max_requested_frame_rate, | |
| 147 const VideoCaptureDeviceFormatsCB& callback) { | |
| 148 std::vector<media::VideoCaptureFormat> formats; | |
| 149 if (cast_receiver_session_->format().IsValid()) { | |
| 150 formats.push_back(cast_receiver_session_->format()); | |
| 151 } | |
| 152 callback.Run(formats); | |
| 153 } | |
| 154 | |
| 155 void CastStreamingVideoCapturerSource::StartCapture( | |
| 156 const media::VideoCaptureParams& params, | |
| 157 const content::VideoCaptureDeliverFrameCB& frame_callback, | |
| 158 scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner, | |
| 159 const RunningCallback& running_callback) { | |
| 160 if (frame_callback_task_runner != | |
| 161 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | |
| 162 DCHECK(false) << "Only IO thread supported right now."; | |
| 163 running_callback.Run(false); | |
| 164 return; | |
| 165 } | |
| 166 cast_receiver_session_->StartVideo(frame_callback); | |
| 167 running_callback.Run(true); | |
| 168 } | |
| 169 | |
| 170 void CastStreamingVideoCapturerSource::StopCapture() { | |
| 171 cast_receiver_session_->StopVideo(); | |
| 172 } | |
| 173 | |
| 174 CastStreamingAudioCapturerSource::CastStreamingAudioCapturerSource( | |
| 175 scoped_refptr<CastReceiverSession> cast_receiver_session) | |
| 176 : cast_receiver_session_(cast_receiver_session) { | |
| 177 } | |
| 178 | |
| 179 CastStreamingAudioCapturerSource::~CastStreamingAudioCapturerSource() {} | |
|
miu
2015/02/11 02:52:49
Do we need to check that Stop() was called first?
hubbe
2015/02/11 22:38:16
Done.
| |
| 180 | |
| 181 void CastStreamingAudioCapturerSource::Initialize( | |
| 182 const media::AudioParameters& params, | |
| 183 CaptureCallback* callback, | |
| 184 int session_id) { | |
| 185 // TODO(hubbe): Consider converting the audio to whatever the caller wants. | |
| 186 if (params.sample_rate() != | |
| 187 cast_receiver_session_->audio_config_.rtp_timebase || | |
| 188 params.channels() != cast_receiver_session_->audio_config_.channels) { | |
| 189 callback->OnCaptureError(); | |
| 190 return; | |
| 191 } | |
| 192 audio_valve_ = new CastReceiverAudioValve(callback); | |
| 193 } | |
| 194 | |
| 195 void CastStreamingAudioCapturerSource::Start() { | |
| 196 cast_receiver_session_->StartAudio(audio_valve_); | |
| 197 } | |
| 198 | |
| 199 void CastStreamingAudioCapturerSource::Stop() { | |
| 200 audio_valve_->Stop(); | |
| 201 } | |
| 202 | |
| 203 void CastStreamingAudioCapturerSource::SetVolume(double volume) { | |
| 204 // not supported | |
| 205 } | |
| 206 | |
| 207 void CastStreamingAudioCapturerSource::SetAutomaticGainControl(bool enable) { | |
| 208 // not supported | |
| 209 } | |
| OLD | NEW |