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_delegate.h"
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "content/public/renderer/render_thread.h"
10 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/cast_sender.h"
14 using media::cast::AudioSenderConfig;
15 using media::cast::CastEnvironment;
16 using media::cast::CastSender;
17 using media::cast::VideoSenderConfig;
19 CastSessionDelegate::CastSessionDelegate()
20 : audio_encode_thread_("CastAudioEncodeThread"),
21 video_encode_thread_("CastVideoEncodeThread"),
22 io_message_loop_proxy_(
23 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
26 CastSessionDelegate::~CastSessionDelegate() {
27 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
30 void CastSessionDelegate::PrepareForSending() {
31 DCHECK(base::MessageLoopProxy::current() == io_message_loop_proxy_);
33 if (cast_environment_)
36 audio_encode_thread_.Start();
37 video_encode_thread_.Start();
39 // CastSender uses the renderer's IO thread as the main thread. This reduces
40 // thread hopping for incoming video frames and outgoing network packets.
41 // There's no need to decode so no thread assigned for decoding.
42 cast_environment_ = new CastEnvironment(
44 base::MessageLoopProxy::current(),
45 audio_encode_thread_.message_loop_proxy(),
47 video_encode_thread_.message_loop_proxy(),
50 // TODO(hclam): A couple things need to be done here:
51 // 1. Pass audio and video configuration to CastSender.
52 // 2. Connect media::cast::PacketSender to net::Socket interface.
53 // 3. Implement VideoEncoderController to configure hardware encoder.
54 cast_sender_.reset(CastSender::CreateCastSender(