Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/renderer/media/cast_session_delegate.cc

Issue 174403002: Cast: Don't create threads for each CastSessionDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing files Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/media/cast_session_delegate.h" 5 #include "chrome/renderer/media/cast_session_delegate.h"
6 6
7 #include "base/lazy_instance.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "chrome/renderer/media/cast_threads.h"
9 #include "chrome/renderer/media/cast_transport_sender_ipc.h" 11 #include "chrome/renderer/media/cast_transport_sender_ipc.h"
10 #include "content/public/renderer/p2p_socket_client.h" 12 #include "content/public/renderer/p2p_socket_client.h"
11 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
12 #include "media/cast/cast_config.h" 14 #include "media/cast/cast_config.h"
13 #include "media/cast/cast_environment.h" 15 #include "media/cast/cast_environment.h"
14 #include "media/cast/cast_sender.h" 16 #include "media/cast/cast_sender.h"
15 #include "media/cast/logging/logging_defines.h" 17 #include "media/cast/logging/logging_defines.h"
16 #include "media/cast/transport/cast_transport_config.h" 18 #include "media/cast/transport/cast_transport_config.h"
17 #include "media/cast/transport/cast_transport_sender.h" 19 #include "media/cast/transport/cast_transport_sender.h"
18 20
19 using media::cast::AudioSenderConfig; 21 using media::cast::AudioSenderConfig;
20 using media::cast::CastEnvironment; 22 using media::cast::CastEnvironment;
21 using media::cast::CastSender; 23 using media::cast::CastSender;
22 using media::cast::VideoSenderConfig; 24 using media::cast::VideoSenderConfig;
23 25
26 static base::LazyInstance<CastThreads> g_cast_threads =
27 LAZY_INSTANCE_INITIALIZER;
28
24 CastSessionDelegate::CastSessionDelegate() 29 CastSessionDelegate::CastSessionDelegate()
25 : audio_encode_thread_("CastAudioEncodeThread"), 30 : transport_configured_(false),
26 video_encode_thread_("CastVideoEncodeThread"),
27 transport_configured_(false),
28 io_message_loop_proxy_( 31 io_message_loop_proxy_(
29 content::RenderThread::Get()->GetIOMessageLoopProxy()) { 32 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
30 DCHECK(io_message_loop_proxy_); 33 DCHECK(io_message_loop_proxy_);
34 g_cast_threads.Get().IncrementUsage();
scherkus (not reviewing) 2014/02/21 16:25:48 do we ever create objects but not initialize them?
31 } 35 }
32 36
33 CastSessionDelegate::~CastSessionDelegate() { 37 CastSessionDelegate::~CastSessionDelegate() {
34 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 38 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
39 g_cast_threads.Get().DecrementUsage();
35 } 40 }
36 41
37 void CastSessionDelegate::Initialize() { 42 void CastSessionDelegate::Initialize() {
38 if (cast_environment_) 43 if (cast_environment_)
39 return; // Already initialized. 44 return; // Already initialized.
40 45
41 audio_encode_thread_.Start();
42 video_encode_thread_.Start();
43
44 // CastSender uses the renderer's IO thread as the main thread. This reduces 46 // CastSender uses the renderer's IO thread as the main thread. This reduces
45 // thread hopping for incoming video frames and outgoing network packets. 47 // thread hopping for incoming video frames and outgoing network packets.
46 // There's no need to decode so no thread assigned for decoding. 48 // There's no need to decode so no thread assigned for decoding.
47 // Get default logging: All disabled. 49 // Get default logging: All disabled.
48 cast_environment_ = new CastEnvironment( 50 cast_environment_ = new CastEnvironment(
49 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), 51 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(),
50 base::MessageLoopProxy::current(), 52 base::MessageLoopProxy::current(),
51 audio_encode_thread_.message_loop_proxy(), 53 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
52 NULL, 54 NULL,
53 video_encode_thread_.message_loop_proxy(), 55 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(),
54 NULL, 56 NULL,
55 base::MessageLoopProxy::current(), 57 base::MessageLoopProxy::current(),
56 media::cast::GetDefaultCastSenderLoggingConfig()); 58 media::cast::GetDefaultCastSenderLoggingConfig());
57 } 59 }
58 60
59 void CastSessionDelegate::StartAudio( 61 void CastSessionDelegate::StartAudio(
60 const AudioSenderConfig& config, 62 const AudioSenderConfig& config,
61 const FrameInputAvailableCallback& callback) { 63 const FrameInputAvailableCallback& callback) {
62 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 64 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
63 65
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // TODO(pwestin): handle the error codes. 148 // TODO(pwestin): handle the error codes.
147 if (result == media::cast::STATUS_INITIALIZED) { 149 if (result == media::cast::STATUS_INITIALIZED) {
148 if (!audio_frame_input_available_callback_.is_null()) { 150 if (!audio_frame_input_available_callback_.is_null()) {
149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); 151 audio_frame_input_available_callback_.Run(cast_sender_->frame_input());
150 } 152 }
151 if (!video_frame_input_available_callback_.is_null()) { 153 if (!video_frame_input_available_callback_.is_null()) {
152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); 154 video_frame_input_available_callback_.Run(cast_sender_->frame_input());
153 } 155 }
154 } 156 }
155 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698