| OLD | NEW |
| 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/task_runner.h" | 10 #include "base/task_runner.h" |
| 11 #include "base/time/tick_clock.h" | 11 #include "base/time/tick_clock.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "media/cast/logging/logging_impl.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 namespace cast { | 16 namespace cast { |
| 16 | 17 |
| 17 class CastEnvironment : public base::RefCountedThreadSafe<CastEnvironment> { | 18 class CastEnvironment : public base::RefCountedThreadSafe<CastEnvironment> { |
| 18 public: | 19 public: |
| 19 // An enumeration of the cast threads. | 20 // An enumeration of the cast threads. |
| 20 enum ThreadId { | 21 enum ThreadId { |
| 21 // The main thread is where the cast system is configured and where timers | 22 // The main thread is where the cast system is configured and where timers |
| 22 // and network IO is performed. | 23 // and network IO is performed. |
| 23 MAIN, | 24 MAIN, |
| 24 // The audio encoder thread is where all send side audio processing is done, | 25 // The audio encoder thread is where all send side audio processing is done, |
| 25 // primarily encoding but also re-sampling. | 26 // primarily encoding but also re-sampling. |
| 26 AUDIO_ENCODER, | 27 AUDIO_ENCODER, |
| 27 // The audio decoder thread is where all receive side audio processing is | 28 // The audio decoder thread is where all receive side audio processing is |
| 28 // done, primarily decoding but also error concealment and re-sampling. | 29 // done, primarily decoding but also error concealment and re-sampling. |
| 29 AUDIO_DECODER, | 30 AUDIO_DECODER, |
| 30 // The video encoder thread is where the video encode processing is done. | 31 // The video encoder thread is where the video encode processing is done. |
| 31 VIDEO_ENCODER, | 32 VIDEO_ENCODER, |
| 32 // The video decoder thread is where the video decode processing is done. | 33 // The video decoder thread is where the video decode processing is done. |
| 33 VIDEO_DECODER, | 34 VIDEO_DECODER, |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 CastEnvironment(base::TickClock* clock, | 37 CastEnvironment(base::TickClock* clock, |
| 37 scoped_refptr<base::TaskRunner> main_thread_proxy, | 38 scoped_refptr<base::TaskRunner> main_thread_proxy, |
| 38 scoped_refptr<base::TaskRunner> audio_encode_thread_proxy, | 39 scoped_refptr<base::TaskRunner> audio_encode_thread_proxy, |
| 39 scoped_refptr<base::TaskRunner> audio_decode_thread_proxy, | 40 scoped_refptr<base::TaskRunner> audio_decode_thread_proxy, |
| 40 scoped_refptr<base::TaskRunner> video_encode_thread_proxy, | 41 scoped_refptr<base::TaskRunner> video_encode_thread_proxy, |
| 41 scoped_refptr<base::TaskRunner> video_decode_thread_proxy); | 42 scoped_refptr<base::TaskRunner> video_decode_thread_proxy, |
| 43 bool enable_data_collection, |
| 44 bool enable_uma_stats, |
| 45 bool enable_tracing); |
| 42 | 46 |
| 43 // These are the same methods in message_loop.h, but are guaranteed to either | 47 // These are the same methods in message_loop.h, but are guaranteed to either |
| 44 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. | 48 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. |
| 45 // They return true iff the thread existed and the task was posted. Note that | 49 // They return true iff the thread existed and the task was posted. Note that |
| 46 // even if the task is posted, there's no guarantee that it will run, since | 50 // even if the task is posted, there's no guarantee that it will run, since |
| 47 // the target thread may already have a Quit message in its queue. | 51 // the target thread may already have a Quit message in its queue. |
| 48 bool PostTask(ThreadId identifier, | 52 bool PostTask(ThreadId identifier, |
| 49 const tracked_objects::Location& from_here, | 53 const tracked_objects::Location& from_here, |
| 50 const base::Closure& task); | 54 const base::Closure& task); |
| 51 | 55 |
| 52 bool PostDelayedTask(ThreadId identifier, | 56 bool PostDelayedTask(ThreadId identifier, |
| 53 const tracked_objects::Location& from_here, | 57 const tracked_objects::Location& from_here, |
| 54 const base::Closure& task, | 58 const base::Closure& task, |
| 55 base::TimeDelta delay); | 59 base::TimeDelta delay); |
| 56 | 60 |
| 57 bool CurrentlyOn(ThreadId identifier); | 61 bool CurrentlyOn(ThreadId identifier); |
| 58 | 62 |
| 59 base::TickClock* Clock(); | 63 base::TickClock* Clock() const; |
| 64 |
| 65 // Logging is not thread safe. Should always be called from the main thread. |
| 66 LoggingImpl* Logging(); |
| 60 | 67 |
| 61 protected: | 68 protected: |
| 62 virtual ~CastEnvironment(); | 69 virtual ~CastEnvironment(); |
| 63 | 70 |
| 64 private: | 71 private: |
| 65 friend class base::RefCountedThreadSafe<CastEnvironment>; | 72 friend class base::RefCountedThreadSafe<CastEnvironment>; |
| 66 | 73 |
| 67 scoped_refptr<base::TaskRunner> GetMessageTaskRunnerForThread( | 74 scoped_refptr<base::TaskRunner> GetMessageTaskRunnerForThread( |
| 68 ThreadId identifier); | 75 ThreadId identifier); |
| 69 | 76 |
| 70 base::TickClock* const clock_; // Not owned by this class. | 77 base::TickClock* const clock_; // Not owned by this class. |
| 71 scoped_refptr<base::TaskRunner> main_thread_proxy_; | 78 scoped_refptr<base::TaskRunner> main_thread_proxy_; |
| 72 scoped_refptr<base::TaskRunner> audio_encode_thread_proxy_; | 79 scoped_refptr<base::TaskRunner> audio_encode_thread_proxy_; |
| 73 scoped_refptr<base::TaskRunner> audio_decode_thread_proxy_; | 80 scoped_refptr<base::TaskRunner> audio_decode_thread_proxy_; |
| 74 scoped_refptr<base::TaskRunner> video_encode_thread_proxy_; | 81 scoped_refptr<base::TaskRunner> video_encode_thread_proxy_; |
| 75 scoped_refptr<base::TaskRunner> video_decode_thread_proxy_; | 82 scoped_refptr<base::TaskRunner> video_decode_thread_proxy_; |
| 76 | 83 |
| 84 scoped_ptr<LoggingImpl> logging_; |
| 85 |
| 77 DISALLOW_COPY_AND_ASSIGN(CastEnvironment); | 86 DISALLOW_COPY_AND_ASSIGN(CastEnvironment); |
| 78 }; | 87 }; |
| 79 | 88 |
| 80 } // namespace cast | 89 } // namespace cast |
| 81 } // namespace media | 90 } // namespace media |
| 82 | 91 |
| 83 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_ | 92 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_ |
| OLD | NEW |