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