OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_AUDIO_AUDIO_DEVICE_THREAD_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ |
6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ | 6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "base/sync_socket.h" | 13 #include "base/sync_socket.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "media/base/audio_parameters.h" | 16 #include "media/base/audio_parameters.h" |
17 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class MessageLoop; | 20 class SingleThreadTaskRunner; |
21 } | 21 } |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 class AudioBus; | 24 class AudioBus; |
25 | 25 |
26 // Data transfer between browser and render process uses a combination | 26 // Data transfer between browser and render process uses a combination |
27 // of sync sockets and shared memory. To read from the socket and render | 27 // of sync sockets and shared memory. To read from the socket and render |
28 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads | 28 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads |
29 // data from the browser via the socket and fills the shared memory from the | 29 // data from the browser via the socket and fills the shared memory from the |
30 // audio thread via the AudioDeviceThread::Callback interface/class. | 30 // audio thread via the AudioDeviceThread::Callback interface/class. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 void Start(AudioDeviceThread::Callback* callback, | 87 void Start(AudioDeviceThread::Callback* callback, |
88 base::SyncSocket::Handle socket, | 88 base::SyncSocket::Handle socket, |
89 const char* thread_name, | 89 const char* thread_name, |
90 bool synchronized_buffers); | 90 bool synchronized_buffers); |
91 | 91 |
92 // This tells the audio thread to stop and clean up the data. | 92 // This tells the audio thread to stop and clean up the data. |
93 // The method can stop the thread synchronously or asynchronously. | 93 // The method can stop the thread synchronously or asynchronously. |
94 // In the latter case, the thread will still be running after Stop() | 94 // In the latter case, the thread will still be running after Stop() |
95 // returns, but the callback pointer is cleared so no further callbacks will | 95 // returns, but the callback pointer is cleared so no further callbacks will |
96 // be made (IOW after Stop() returns, it is safe to delete the callback). | 96 // be made (IOW after Stop() returns, it is safe to delete the callback). |
97 // The |loop_for_join| parameter is required for asynchronous operation | 97 // The |task_runner_for_join| parameter is required for asynchronous operation |
98 // in order to join the worker thread and close the thread handle later via a | 98 // in order to join the worker thread and close the thread handle later via a |
99 // posted task. | 99 // posted task. |
100 // If set to NULL, function will wait for the thread to exit before returning. | 100 // If set to NULL, function will wait for the thread to exit before returning. |
101 void Stop(base::MessageLoop* loop_for_join); | 101 void Stop(scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_join); |
102 | 102 |
103 // Returns true if the thread is stopped or stopping. | 103 // Returns true if the thread is stopped or stopping. |
104 bool IsStopped(); | 104 bool IsStopped(); |
105 | 105 |
106 private: | 106 private: |
107 // Our own private SimpleThread override. We implement this in a | 107 // Our own private SimpleThread override. We implement this in a |
108 // private class so that we get the following benefits: | 108 // private class so that we get the following benefits: |
109 // 1) AudioDeviceThread doesn't expose SimpleThread methods. | 109 // 1) AudioDeviceThread doesn't expose SimpleThread methods. |
110 // I.e. the caller can't call Start()/Stop() - which would be bad. | 110 // I.e. the caller can't call Start()/Stop() - which would be bad. |
111 // 2) We override ThreadMain to add additional on-thread initialization | 111 // 2) We override ThreadMain to add additional on-thread initialization |
112 // while still synchronized with SimpleThread::Start() to provide | 112 // while still synchronized with SimpleThread::Start() to provide |
113 // reliable initialization. | 113 // reliable initialization. |
114 class Thread; | 114 class Thread; |
115 | 115 |
116 base::Lock thread_lock_; | 116 base::Lock thread_lock_; |
117 scoped_refptr<AudioDeviceThread::Thread> thread_; | 117 scoped_refptr<AudioDeviceThread::Thread> thread_; |
118 | 118 |
119 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); | 119 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); |
120 }; | 120 }; |
121 | 121 |
122 } // namespace media. | 122 } // namespace media. |
123 | 123 |
124 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ | 124 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ |
OLD | NEW |