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.
5 #include "chrome/renderer/media/cast_session.h"
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_current_loop.h"
11 #include "media/base/video_frame.h"
12 #include "media/cast/cast_config.h"
13 #include "media/cast/cast_sender.h"
15 CastSession::CastSession()
16 : delegate_(new CastSessionDelegate()),
17 io_message_loop_proxy_(
18 content::RenderThread::Get()->GetIOMessageLoopProxy()) {}
20 CastSession::~CastSession() {
21 // We should always be able to delete the object on the IO thread.
22 CHECK(io_message_loop_proxy_
->DeleteSoon(FROM_HERE
, delegate_
.release()));
25 void CastSession::StartAudio(const media::cast::AudioSenderConfig
& config
,
26 const FrameInputAvailableCallback
& callback
) {
27 DCHECK(content::RenderThread::Get()
29 ->message_loop_proxy()
30 ->BelongsToCurrentThread());
32 io_message_loop_proxy_
->PostTask(
34 base::Bind(&CastSessionDelegate::StartAudio
,
35 base::Unretained(delegate_
.get()),
37 media::BindToCurrentLoop(callback
)));
40 void CastSession::StartVideo(const media::cast::VideoSenderConfig
& config
,
41 const FrameInputAvailableCallback
& callback
) {
42 DCHECK(content::RenderThread::Get()
44 ->message_loop_proxy()
45 ->BelongsToCurrentThread());
47 io_message_loop_proxy_
->PostTask(
49 base::Bind(&CastSessionDelegate::StartVideo
,
50 base::Unretained(delegate_
.get()),
52 media::BindToCurrentLoop(callback
)));
55 void CastSession::StartUDP(const net::IPEndPoint
& local_endpoint
,
56 const net::IPEndPoint
& remote_endpoint
) {
57 io_message_loop_proxy_
->PostTask(
60 &CastSessionDelegate::StartUDP
,
61 base::Unretained(delegate_
.get()),