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 #ifndef MEDIA_CAST_CAST_ENVIRONMENT_H_
6 #define MEDIA_CAST_CAST_ENVIRONMENT_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/task_runner.h"
12 #include "base/time/tick_clock.h"
13 #include "base/time/time.h"
14 #include "media/cast/logging/logging_defines.h"
15 #include "media/cast/logging/logging_impl.h"
20 class CastEnvironment
: public base::RefCountedThreadSafe
<CastEnvironment
> {
22 // An enumeration of the cast threads.
24 // The main thread is where the cast system is configured and where timers
25 // and network IO is performed.
27 // The audio encoder thread is where all send side audio processing is done,
28 // primarily encoding but also re-sampling.
30 // The audio decoder thread is where all receive side audio processing is
31 // done, primarily decoding but also error concealment and re-sampling.
33 // The video encoder thread is where the video encode processing is done.
35 // The video decoder thread is where the video decode processing is done.
37 // The transport thread is where the transport processing is done.
41 CastEnvironment(base::TickClock
* clock
,
42 scoped_refptr
<base::TaskRunner
> main_thread_proxy
,
43 scoped_refptr
<base::TaskRunner
> audio_encode_thread_proxy
,
44 scoped_refptr
<base::TaskRunner
> audio_decode_thread_proxy
,
45 scoped_refptr
<base::TaskRunner
> video_encode_thread_proxy
,
46 scoped_refptr
<base::TaskRunner
> video_decode_thread_proxy
,
47 scoped_refptr
<base::TaskRunner
> transport_thread_proxy
,
48 const CastLoggingConfig
& config
);
50 // These are the same methods in message_loop.h, but are guaranteed to either
51 // get posted to the MessageLoop if it's still alive, or be deleted otherwise.
52 // They return true iff the thread existed and the task was posted. Note that
53 // even if the task is posted, there's no guarantee that it will run, since
54 // the target thread may already have a Quit message in its queue.
55 bool PostTask(ThreadId identifier
,
56 const tracked_objects::Location
& from_here
,
57 const base::Closure
& task
);
59 bool PostDelayedTask(ThreadId identifier
,
60 const tracked_objects::Location
& from_here
,
61 const base::Closure
& task
,
62 base::TimeDelta delay
);
64 bool CurrentlyOn(ThreadId identifier
);
66 base::TickClock
* Clock() const;
68 // Logging is not thread safe. Should always be called from the main thread.
69 LoggingImpl
* Logging();
71 scoped_refptr
<base::TaskRunner
> GetMessageTaskRunnerForThread(
75 virtual ~CastEnvironment();
78 friend class base::RefCountedThreadSafe
<CastEnvironment
>;
80 base::TickClock
* const clock_
; // Not owned by this class.
81 scoped_refptr
<base::TaskRunner
> main_thread_proxy_
;
82 scoped_refptr
<base::TaskRunner
> audio_encode_thread_proxy_
;
83 scoped_refptr
<base::TaskRunner
> audio_decode_thread_proxy_
;
84 scoped_refptr
<base::TaskRunner
> video_encode_thread_proxy_
;
85 scoped_refptr
<base::TaskRunner
> video_decode_thread_proxy_
;
86 scoped_refptr
<base::TaskRunner
> transport_thread_proxy_
;
88 scoped_ptr
<LoggingImpl
> logging_
;
90 DISALLOW_COPY_AND_ASSIGN(CastEnvironment
);
96 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_