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()) {
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()));
26 void CastSession::StartAudio(const media::cast::AudioSenderConfig
& config
,
27 const FrameInputAvailableCallback
& callback
) {
28 io_message_loop_proxy_
->PostTask(FROM_HERE
,
30 &CastSessionDelegate::StartAudio
,
31 base::Unretained(delegate_
.get()),
33 media::BindToCurrentLoop(callback
)));
36 void CastSession::StartVideo(const media::cast::VideoSenderConfig
& config
,
37 const FrameInputAvailableCallback
& callback
) {
38 io_message_loop_proxy_
->PostTask(FROM_HERE
,
40 &CastSessionDelegate::StartVideo
,
41 base::Unretained(delegate_
.get()),
43 media::BindToCurrentLoop(callback
)));
46 void CastSession::StartSending(const SendPacketCallback
& callback
) {
47 io_message_loop_proxy_
->PostTask(FROM_HERE
,
49 &CastSessionDelegate::StartSending
,
50 base::Unretained(delegate_
.get()),
51 media::BindToCurrentLoop(callback
)));
54 void CastSession::ReceivePacket(const std::vector
<char>& packet
) {
55 io_message_loop_proxy_
->PostTask(FROM_HERE
,
57 &CastSessionDelegate::ReceivePacket
,
58 base::Unretained(delegate_
.get()),