| Index: chrome/renderer/media/cast_receiver_session.cc
|
| diff --git a/chrome/renderer/media/cast_receiver_session.cc b/chrome/renderer/media/cast_receiver_session.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7b789238699121132bd792641f113d85eb589748
|
| --- /dev/null
|
| +++ b/chrome/renderer/media/cast_receiver_session.cc
|
| @@ -0,0 +1,208 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/renderer/media/cast_receiver_session.h"
|
| +
|
| +#include "base/synchronization/waitable_event.h"
|
| +#include "chrome/renderer/media/cast_receiver_audio_valve.h"
|
| +#include "content/public/renderer/media_stream_source_api.h"
|
| +#include "content/public/renderer/render_thread.h"
|
| +#include "media/base/audio_capturer_source.h"
|
| +#include "media/base/video_capturer_source.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStream.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
|
| +
|
| +// This is a render thread object.
|
| +class CastStreamingAudioCapturerSource : public media::AudioCapturerSource {
|
| + public:
|
| + CastStreamingAudioCapturerSource(
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session);
|
| + void Initialize(const media::AudioParameters& params,
|
| + CaptureCallback* callback,
|
| + int session_id) override;
|
| + void Start() override;
|
| + void Stop() override;
|
| + void SetVolume(double volume) override;
|
| + void SetAutomaticGainControl(bool enable) override;
|
| + private:
|
| + ~CastStreamingAudioCapturerSource() override;
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session_;
|
| + scoped_refptr<CastReceiverAudioValve> audio_valve_;
|
| +};
|
| +
|
| +// This is a render thread object.
|
| +class CastStreamingVideoCapturerSource : public media::VideoCapturerSource {
|
| + public:
|
| + explicit CastStreamingVideoCapturerSource(
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session);
|
| + protected:
|
| + void GetCurrentSupportedFormats(
|
| + int max_requested_width,
|
| + int max_requested_height,
|
| + double max_requested_frame_rate,
|
| + const VideoCaptureDeviceFormatsCB& callback) override;
|
| + void StartCapture(
|
| + const media::VideoCaptureParams& params,
|
| + const content::VideoCaptureDeliverFrameCB& frame_callback,
|
| + scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner,
|
| + const RunningCallback& running_callback) override;
|
| + void StopCapture() override;
|
| + private:
|
| + ~CastStreamingVideoCapturerSource() override;
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session_;
|
| +};
|
| +
|
| +CastReceiverSession::CastReceiverSession()
|
| + : delegate_(new CastReceiverSessionDelegate()),
|
| + io_message_loop_proxy_(
|
| + content::RenderThread::Get()->GetIOMessageLoopProxy()) {}
|
| +
|
| +CastReceiverSession::~CastReceiverSession() {
|
| + // We should always be able to delete the object on the IO thread.
|
| + CHECK(io_message_loop_proxy_->DeleteSoon(FROM_HERE, delegate_.release()));
|
| +}
|
| +
|
| +void CastReceiverSession::Start(
|
| + const media::cast::FrameReceiverConfig& audio_config,
|
| + const media::cast::FrameReceiverConfig& video_config,
|
| + const net::IPEndPoint& local_endpoint,
|
| + const net::IPEndPoint& remote_endpoint,
|
| + scoped_ptr<base::DictionaryValue> options,
|
| + const media::VideoCaptureFormat& capture_format,
|
| + const StartCB& start_callback) {
|
| + format_ = capture_format;
|
| + io_message_loop_proxy_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CastReceiverSessionDelegate::Start,
|
| + base::Unretained(delegate_.get()),
|
| + audio_config,
|
| + video_config,
|
| + local_endpoint,
|
| + remote_endpoint,
|
| + base::Passed(&options),
|
| + format_));
|
| + blink::WebMediaStreamSource video_source;
|
| + content::InitializeVideoWebMediaStreamSource(
|
| + new CastStreamingVideoCapturerSource(this),
|
| + &video_source);
|
| + blink::WebVector<blink::WebMediaStreamTrack> video_tracks(
|
| + static_cast<size_t>(1));
|
| + video_tracks[0].initialize(video_source);
|
| +
|
| + blink::WebMediaStreamSource audio_source;
|
| + content::InitializeAudioWebMediaStreamSource(
|
| + new CastStreamingAudioCapturerSource(this),
|
| + &audio_source);
|
| + blink::WebVector<blink::WebMediaStreamTrack> audio_tracks(
|
| + static_cast<size_t>(1));
|
| + audio_tracks[0].initialize(audio_source);
|
| +
|
| + blink::WebMediaStream stream;
|
| + stream.initialize(audio_tracks, video_tracks);
|
| +
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(start_callback, stream));
|
| +}
|
| +
|
| +void CastReceiverSession::StartAudio(
|
| + scoped_refptr<CastReceiverAudioValve> audio_valve) {
|
| + io_message_loop_proxy_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CastReceiverSessionDelegate::StartAudio,
|
| + base::Unretained(delegate_.get()),
|
| + audio_valve));
|
| +}
|
| +
|
| +void CastReceiverSession::StartVideo(
|
| + content::VideoCaptureDeliverFrameCB frame_callback) {
|
| + io_message_loop_proxy_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CastReceiverSessionDelegate::StartVideo,
|
| + base::Unretained(delegate_.get()),
|
| + frame_callback));
|
| +}
|
| +
|
| +void CastReceiverSession::StopVideo() {
|
| + io_message_loop_proxy_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CastReceiverSessionDelegate::StopVideo,
|
| + base::Unretained(delegate_.get())));
|
| +}
|
| +
|
| +CastStreamingVideoCapturerSource::CastStreamingVideoCapturerSource(
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session)
|
| + : cast_receiver_session_(cast_receiver_session) {
|
| +}
|
| +
|
| +CastStreamingVideoCapturerSource::~CastStreamingVideoCapturerSource() {}
|
| +
|
| +void CastStreamingVideoCapturerSource::GetCurrentSupportedFormats(
|
| + int max_requested_width,
|
| + int max_requested_height,
|
| + double max_requested_frame_rate,
|
| + const VideoCaptureDeviceFormatsCB& callback) {
|
| + std::vector<media::VideoCaptureFormat> formats;
|
| + if (cast_receiver_session_->format().IsValid()) {
|
| + formats.push_back(cast_receiver_session_->format());
|
| + }
|
| + callback.Run(formats);
|
| +}
|
| +
|
| +void CastStreamingVideoCapturerSource::StartCapture(
|
| + const media::VideoCaptureParams& params,
|
| + const content::VideoCaptureDeliverFrameCB& frame_callback,
|
| + scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner,
|
| + const RunningCallback& running_callback) {
|
| + if (frame_callback_task_runner !=
|
| + content::RenderThread::Get()->GetIOMessageLoopProxy()) {
|
| + DCHECK(false) << "Only IO thread supported right now.";
|
| + running_callback.Run(false);
|
| + return;
|
| + }
|
| + cast_receiver_session_->StartVideo(frame_callback);
|
| + running_callback.Run(true);
|
| +}
|
| +
|
| +void CastStreamingVideoCapturerSource::StopCapture() {
|
| + cast_receiver_session_->StopVideo();
|
| +}
|
| +
|
| +CastStreamingAudioCapturerSource::CastStreamingAudioCapturerSource(
|
| + scoped_refptr<CastReceiverSession> cast_receiver_session)
|
| + : cast_receiver_session_(cast_receiver_session) {
|
| +}
|
| +
|
| +CastStreamingAudioCapturerSource::~CastStreamingAudioCapturerSource() {}
|
| +
|
| +void CastStreamingAudioCapturerSource::Initialize(
|
| + const media::AudioParameters& params,
|
| + CaptureCallback* callback,
|
| + int session_id) {
|
| + // TODO(hubbe): Consider converting the audio to whatever the caller wants.
|
| + if (params.sample_rate() !=
|
| + cast_receiver_session_->audio_config_.rtp_timebase ||
|
| + params.channels() != cast_receiver_session_->audio_config_.channels) {
|
| + callback->OnCaptureError();
|
| + return;
|
| + }
|
| + audio_valve_ = new CastReceiverAudioValve(callback);
|
| +}
|
| +
|
| +void CastStreamingAudioCapturerSource::Start() {
|
| + cast_receiver_session_->StartAudio(audio_valve_);
|
| +}
|
| +
|
| +void CastStreamingAudioCapturerSource::Stop() {
|
| + audio_valve_->Stop();
|
| +}
|
| +
|
| +void CastStreamingAudioCapturerSource::SetVolume(double volume) {
|
| + // not supported
|
| +}
|
| +
|
| +void CastStreamingAudioCapturerSource::SetAutomaticGainControl(bool enable) {
|
| + // not supported
|
| +}
|
|
|