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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/media/cast_session.h"
6
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "chrome/renderer/media/cast_session_delegate.h"
9 #include "content/public/renderer/render_thread.h"
10 #include "media/base/bind_to_loop.h"
11 #include "media/base/video_frame.h"
12 #include "media/cast/cast_config.h"
13 #include "media/cast/cast_sender.h"
14
CastSession()15 CastSession::CastSession()
16 : delegate_(new CastSessionDelegate()),
17 io_message_loop_proxy_(
18 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
19 }
20
~CastSession()21 CastSession::~CastSession() {
22 // We should always be able to delete the object on the IO thread.
23 CHECK(io_message_loop_proxy_->DeleteSoon(FROM_HERE, delegate_.release()));
24 }
25
~P2PSocketFactory()26 CastSession::P2PSocketFactory::~P2PSocketFactory() {
27 }
28
StartAudio(const media::cast::AudioSenderConfig & config,const FrameInputAvailableCallback & callback)29 void CastSession::StartAudio(const media::cast::AudioSenderConfig& config,
30 const FrameInputAvailableCallback& callback) {
31 io_message_loop_proxy_->PostTask(FROM_HERE,
32 base::Bind(&CastSessionDelegate::StartAudio,
33 base::Unretained(delegate_.get()),
34 config,
35 media::BindToCurrentLoop(callback)));
36 }
37
StartVideo(const media::cast::VideoSenderConfig & config,const FrameInputAvailableCallback & callback)38 void CastSession::StartVideo(const media::cast::VideoSenderConfig& config,
39 const FrameInputAvailableCallback& callback) {
40 io_message_loop_proxy_->PostTask(FROM_HERE,
41 base::Bind(&CastSessionDelegate::StartVideo,
42 base::Unretained(delegate_.get()),
43 config,
44 media::BindToCurrentLoop(callback)));
45 }
46
SetSocketFactory(scoped_ptr<P2PSocketFactory> socket_factory,const net::IPEndPoint & remote_address)47 void CastSession::SetSocketFactory(scoped_ptr<P2PSocketFactory> socket_factory,
48 const net::IPEndPoint& remote_address) {
49 io_message_loop_proxy_->PostTask(
50 FROM_HERE,
51 base::Bind(&CastSessionDelegate::SetSocketFactory,
52 base::Unretained(delegate_.get()),
53 base::Passed(socket_factory.Pass()),
54 remote_address));
55 }
56