- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / renderer / media / cast_session_delegate.cc
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_delegate.h"
6
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"
13
14 using media::cast::AudioSenderConfig;
15 using media::cast::CastEnvironment;
16 using media::cast::CastSender;
17 using media::cast::VideoSenderConfig;
18
19 CastSessionDelegate::CastSessionDelegate()
20     : audio_encode_thread_("CastAudioEncodeThread"),
21       video_encode_thread_("CastVideoEncodeThread"),
22       io_message_loop_proxy_(
23           content::RenderThread::Get()->GetIOMessageLoopProxy()) {
24 }
25
26 CastSessionDelegate::~CastSessionDelegate() {
27   DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
28 }
29
30 void CastSessionDelegate::PrepareForSending() {
31   DCHECK(base::MessageLoopProxy::current() == io_message_loop_proxy_);
32
33   if (cast_environment_)
34     return;
35
36   audio_encode_thread_.Start();
37   video_encode_thread_.Start();
38
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(
43       &clock_,
44       base::MessageLoopProxy::current(),
45       audio_encode_thread_.message_loop_proxy(),
46       NULL,
47       video_encode_thread_.message_loop_proxy(),
48       NULL);
49
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(
55       cast_environment_,
56       AudioSenderConfig(),
57       VideoSenderConfig(),
58       NULL,
59       NULL));
60 }