Commit dfc191ad authored by hclam@chromium.org's avatar hclam@chromium.org

Cast: Don't create threads for each CastSessionDelegate

We shouldn't create threads for each instance of CastSessionDelegate.

Cast encoding threads are now managed by a singleton object of
CastThreads. Threads used by Cast are now started and stopped
accordingly when there are CastSessionDelegate objects.

Tested with browser_tests --gtest_filter=CastStreaming*

BUG=317006

Review URL: https://codereview.chromium.org/174403002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252810 0039d316-1c4b-4281-b951-d872f2087c98
parent adcaebd0
......@@ -169,6 +169,8 @@
'renderer/media/cast_session.h',
'renderer/media/cast_session_delegate.cc',
'renderer/media/cast_session_delegate.h',
'renderer/media/cast_threads.cc',
'renderer/media/cast_threads.h',
'renderer/media/cast_transport_sender_ipc.cc',
'renderer/media/cast_transport_sender_ipc.h',
'renderer/media/cast_udp_transport.cc',
......
......@@ -4,8 +4,10 @@
#include "chrome/renderer/media/cast_session_delegate.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "chrome/renderer/media/cast_threads.h"
#include "chrome/renderer/media/cast_transport_sender_ipc.h"
#include "content/public/renderer/p2p_socket_client.h"
#include "content/public/renderer/render_thread.h"
......@@ -21,10 +23,11 @@ using media::cast::CastEnvironment;
using media::cast::CastSender;
using media::cast::VideoSenderConfig;
static base::LazyInstance<CastThreads> g_cast_threads =
LAZY_INSTANCE_INITIALIZER;
CastSessionDelegate::CastSessionDelegate()
: audio_encode_thread_("CastAudioEncodeThread"),
video_encode_thread_("CastVideoEncodeThread"),
transport_configured_(false),
: transport_configured_(false),
io_message_loop_proxy_(
content::RenderThread::Get()->GetIOMessageLoopProxy()) {
DCHECK(io_message_loop_proxy_);
......@@ -38,9 +41,6 @@ void CastSessionDelegate::Initialize() {
if (cast_environment_)
return; // Already initialized.
audio_encode_thread_.Start();
video_encode_thread_.Start();
// CastSender uses the renderer's IO thread as the main thread. This reduces
// thread hopping for incoming video frames and outgoing network packets.
// There's no need to decode so no thread assigned for decoding.
......@@ -48,9 +48,9 @@ void CastSessionDelegate::Initialize() {
cast_environment_ = new CastEnvironment(
scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(),
base::MessageLoopProxy::current(),
audio_encode_thread_.message_loop_proxy(),
g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
NULL,
video_encode_thread_.message_loop_proxy(),
g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(),
NULL,
base::MessageLoopProxy::current(),
media::cast::GetDefaultCastSenderLoggingConfig());
......
......@@ -78,13 +78,6 @@ class CastSessionDelegate {
scoped_ptr<media::cast::CastSender> cast_sender_;
scoped_ptr<media::cast::transport::CastTransportSender> cast_transport_;
// Utilities threads owned by this class. They are used by CastSender for
// encoding.
// TODO(hclam): See crbug.com/317006 for more details.
// This class shouldn't create and own threads.
base::Thread audio_encode_thread_;
base::Thread video_encode_thread_;
// Configuration for audio and video.
scoped_ptr<media::cast::AudioSenderConfig> audio_config_;
scoped_ptr<media::cast::VideoSenderConfig> video_config_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/media/cast_threads.h"
#include "base/logging.h"
CastThreads::CastThreads()
: audio_encode_thread_("CastAudioEncodeThread"),
video_encode_thread_("CastVideoEncodeThread") {
audio_encode_thread_.Start();
video_encode_thread_.Start();
}
scoped_refptr<base::SingleThreadTaskRunner>
CastThreads::GetAudioEncodeMessageLoopProxy() {
return audio_encode_thread_.message_loop_proxy();
}
scoped_refptr<base::SingleThreadTaskRunner>
CastThreads::GetVideoEncodeMessageLoopProxy() {
return video_encode_thread_.message_loop_proxy();
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Manages threads used by Cast Streaming Extensions API. There is a
// singleton object of this class in the renderer.
//
// There are two threads owned by this class:
// 1. Audio encode thread.
// 2. Video encode thread.
// These two threads are started this object is created.
#ifndef CHROME_RENDERER_MEDIA_CAST_THREADS_H_
#define CHROME_RENDERER_MEDIA_CAST_THREADS_H_
#include "base/lazy_instance.h"
#include "base/threading/thread.h"
class CastThreads {
public:
scoped_refptr<base::SingleThreadTaskRunner>
GetAudioEncodeMessageLoopProxy();
scoped_refptr<base::SingleThreadTaskRunner>
GetVideoEncodeMessageLoopProxy();
private:
friend struct base::DefaultLazyInstanceTraits<CastThreads>;
CastThreads();
base::Thread audio_encode_thread_;
base::Thread video_encode_thread_;
DISALLOW_COPY_AND_ASSIGN(CastThreads);
};
#endif // CHROME_RENDERER_MEDIA_CAST_THREADS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment