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

Side by Side Diff: media/cast/cast_environment.h

Issue 184813009: Cast Streaming API end-to-end browser_test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 #ifndef MEDIA_CAST_CAST_ENVIRONMENT_H_ 5 #ifndef MEDIA_CAST_CAST_ENVIRONMENT_H_
6 #define MEDIA_CAST_CAST_ENVIRONMENT_H_ 6 #define MEDIA_CAST_CAST_ENVIRONMENT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/lock.h"
12 #include "base/time/tick_clock.h" 13 #include "base/time/tick_clock.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "media/cast/logging/logging_defines.h" 15 #include "media/cast/logging/logging_defines.h"
15 #include "media/cast/logging/logging_impl.h" 16 #include "media/cast/logging/logging_impl.h"
16 17
18 namespace base {
19 class Thread;
20 }
21
17 namespace media { 22 namespace media {
18 namespace cast { 23 namespace cast {
19 24
20 class CastEnvironment : public base::RefCountedThreadSafe<CastEnvironment> { 25 class CastEnvironment : public base::RefCountedThreadSafe<CastEnvironment> {
21 public: 26 public:
22 // An enumeration of the cast threads. 27 // An enumeration of the cast threads.
23 enum ThreadId { 28 enum ThreadId {
24 // The main thread is where the cast system is configured and where timers 29 // The main thread is where the cast system is configured and where timers
25 // and network IO is performed. 30 // and network IO is performed.
26 MAIN, 31 MAIN,
27 // The audio encoder thread is where all send side audio processing is done, 32 // The audio encoder thread is where all send side audio processing is done,
28 // primarily encoding but also re-sampling. 33 // primarily encoding but also re-sampling.
29 AUDIO_ENCODER, 34 AUDIO_ENCODER,
30 // The audio decoder thread is where all receive side audio processing is 35 // The audio decoder thread is where all receive side audio processing is
31 // done, primarily decoding but also error concealment and re-sampling. 36 // done, primarily decoding but also error concealment and re-sampling.
32 AUDIO_DECODER, 37 AUDIO_DECODER,
33 // The video encoder thread is where the video encode processing is done. 38 // The video encoder thread is where the video encode processing is done.
34 VIDEO_ENCODER, 39 VIDEO_ENCODER,
35 // The video decoder thread is where the video decode processing is done. 40 // The video decoder thread is where the video decode processing is done.
36 VIDEO_DECODER, 41 VIDEO_DECODER,
37 // The transport thread is where the transport processing is done. 42 // The transport thread is where the transport processing is done.
38 TRANSPORT, 43 TRANSPORT,
39 }; 44 };
40 45
46 // Use these constructors to create a standalone CastEnvironment. They use
47 // base::DefaultTickClock, and all task runners are created on-demand.
48 CastEnvironment(); // No logging.
hubbe 2014/03/04 22:42:26 This is only used for testing. Seems better to kee
miu 2014/03/06 06:09:15 Done.
49 explicit CastEnvironment(const CastLoggingConfig& logging_config);
50
51 // Use this constructor to create a CastEnvironment that integrates with an
52 // existing environment, such as content::BrowserThread, or a test/simulation
53 // framework. It is valid for any of the proxy args to be NULL for any task
54 // runners that will not be used.
41 CastEnvironment( 55 CastEnvironment(
42 scoped_ptr<base::TickClock> clock, 56 scoped_ptr<base::TickClock> clock,
43 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy, 57 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy,
44 scoped_refptr<base::SingleThreadTaskRunner> audio_encode_thread_proxy, 58 scoped_refptr<base::SingleThreadTaskRunner> audio_encode_thread_proxy,
45 scoped_refptr<base::SingleThreadTaskRunner> audio_decode_thread_proxy, 59 scoped_refptr<base::SingleThreadTaskRunner> audio_decode_thread_proxy,
46 scoped_refptr<base::SingleThreadTaskRunner> video_encode_thread_proxy, 60 scoped_refptr<base::SingleThreadTaskRunner> video_encode_thread_proxy,
47 scoped_refptr<base::SingleThreadTaskRunner> video_decode_thread_proxy, 61 scoped_refptr<base::SingleThreadTaskRunner> video_decode_thread_proxy,
48 scoped_refptr<base::SingleThreadTaskRunner> transport_thread_proxy, 62 scoped_refptr<base::SingleThreadTaskRunner> transport_thread_proxy,
49 const CastLoggingConfig& config); 63 const CastLoggingConfig& logging_config);
50 64
51 // These are the same methods in message_loop.h, but are guaranteed to either 65 // These are the same methods in message_loop.h, but are guaranteed to either
52 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. 66 // get posted to the MessageLoop if it's still alive, or be deleted otherwise.
53 // They return true iff the thread existed and the task was posted. Note that 67 // They return true iff the thread existed and the task was posted. Note that
54 // even if the task is posted, there's no guarantee that it will run, since 68 // even if the task is posted, there's no guarantee that it will run, since
55 // the target thread may already have a Quit message in its queue. 69 // the target thread may already have a Quit message in its queue.
56 bool PostTask(ThreadId identifier, 70 bool PostTask(ThreadId identifier,
57 const tracked_objects::Location& from_here, 71 const tracked_objects::Location& from_here,
58 const base::Closure& task); 72 const base::Closure& task);
59 73
60 bool PostDelayedTask(ThreadId identifier, 74 bool PostDelayedTask(ThreadId identifier,
61 const tracked_objects::Location& from_here, 75 const tracked_objects::Location& from_here,
62 const base::Closure& task, 76 const base::Closure& task,
63 base::TimeDelta delay); 77 base::TimeDelta delay);
64 78
65 bool CurrentlyOn(ThreadId identifier); 79 bool CurrentlyOn(ThreadId identifier);
66 80
67 base::TickClock* Clock() const; 81 // All of the media::cast implementation must use this TickClock.
82 base::TickClock* Clock() const { return clock_.get(); }
68 83
69 // Logging is not thread safe. Should always be called from the main thread. 84 // Logging is not thread safe. Its methods should always be called from the
70 LoggingImpl* Logging(); 85 // main thread.
86 LoggingImpl* Logging() const { return logging_.get(); }
71 87
72 scoped_refptr<base::SingleThreadTaskRunner> 88 scoped_refptr<base::SingleThreadTaskRunner>
73 GetMessageSingleThreadTaskRunnerForThread(ThreadId identifier); 89 GetMessageSingleThreadTaskRunnerForThread(ThreadId identifier);
74 90
75 bool HasAudioEncoderThread() { 91 bool HasAudioEncoderThread() {
76 return audio_encode_thread_proxy_ ? true : false; 92 return audio_encode_thread_proxy_ ? true : false;
77 } 93 }
78 94
79 bool HasVideoEncoderThread() { 95 bool HasVideoEncoderThread() {
80 return video_encode_thread_proxy_ ? true : false; 96 return video_encode_thread_proxy_ ? true : false;
81 } 97 }
82 98
83 protected: 99 protected:
84 virtual ~CastEnvironment(); 100 virtual ~CastEnvironment();
85 101
86 private: 102 private:
87 friend class base::RefCountedThreadSafe<CastEnvironment>; 103 friend class base::RefCountedThreadSafe<CastEnvironment>;
88 104
89 scoped_ptr<base::TickClock> clock_; 105 scoped_ptr<base::TickClock> clock_;
90 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy_; 106 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy_;
91 scoped_refptr<base::SingleThreadTaskRunner> audio_encode_thread_proxy_; 107 scoped_refptr<base::SingleThreadTaskRunner> audio_encode_thread_proxy_;
92 scoped_refptr<base::SingleThreadTaskRunner> audio_decode_thread_proxy_; 108 scoped_refptr<base::SingleThreadTaskRunner> audio_decode_thread_proxy_;
93 scoped_refptr<base::SingleThreadTaskRunner> video_encode_thread_proxy_; 109 scoped_refptr<base::SingleThreadTaskRunner> video_encode_thread_proxy_;
94 scoped_refptr<base::SingleThreadTaskRunner> video_decode_thread_proxy_; 110 scoped_refptr<base::SingleThreadTaskRunner> video_decode_thread_proxy_;
95 scoped_refptr<base::SingleThreadTaskRunner> transport_thread_proxy_; 111 scoped_refptr<base::SingleThreadTaskRunner> transport_thread_proxy_;
96 112
97 scoped_ptr<LoggingImpl> logging_; 113 scoped_ptr<LoggingImpl> logging_;
98 114
115 // Auto-created threads for missing task runners, with the one-time creation
116 // action protected by a lock.
117 base::Lock create_lock_;
118 scoped_ptr<base::Thread> main_thread_;
119 scoped_ptr<base::Thread> audio_encode_thread_;
120 scoped_ptr<base::Thread> audio_decode_thread_;
121 scoped_ptr<base::Thread> video_encode_thread_;
122 scoped_ptr<base::Thread> video_decode_thread_;
123 scoped_ptr<base::Thread> transport_thread_;
124
99 DISALLOW_COPY_AND_ASSIGN(CastEnvironment); 125 DISALLOW_COPY_AND_ASSIGN(CastEnvironment);
100 }; 126 };
101 127
102 } // namespace cast 128 } // namespace cast
103 } // namespace media 129 } // namespace media
104 130
105 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_ 131 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698