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

Side by Side Diff: media/audio/audio_device_thread.h

Issue 1703473002: Make AudioOutputDevice restartable and reinitializable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_mixing
Patch Set: Created 4 years, 10 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
OLDNEW
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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const int total_segments_; 68 const int total_segments_;
69 int segment_length_; 69 int segment_length_;
70 70
71 private: 71 private:
72 DISALLOW_COPY_AND_ASSIGN(Callback); 72 DISALLOW_COPY_AND_ASSIGN(Callback);
73 }; 73 };
74 74
75 AudioDeviceThread(); 75 AudioDeviceThread();
76 ~AudioDeviceThread(); 76 ~AudioDeviceThread();
77 77
78 // Starts the audio thread. The thread must not already be running. If 78 // Starts the audio thread and puts in wait mode. StartRun() must
79 // |sychronized_buffers| is set, the browser expects to be notified via the 79 // be called to release it and actually start running. The thread must not
80 // |socket| every time AudioDeviceThread::Process() completes. 80 // already be started. If |sychronized_buffers| is set, the browser expects
81 void Start(AudioDeviceThread::Callback* callback, 81 // to be notified via the |socket| every time AudioDeviceThread::Process()
82 base::SyncSocket::Handle socket, 82 // completes.
83 const char* thread_name, 83 void Start(const char* thread_name,
84 bool synchronized_buffers); 84 bool synchronized_buffers);
85 85
86 // This tells the audio thread to stop and clean up the data. 86 // This tells the audio thread to stop and clean up the data.
87 // The method can stop the thread synchronously or asynchronously. 87 // The method can stop the thread synchronously or asynchronously.
88 // In the latter case, the thread will still be running after Stop() 88 // In the latter case, the thread will still be running after Stop()
89 // returns, but the callback pointer is cleared so no further callbacks will 89 // returns, but the callback pointer is cleared so no further callbacks will
90 // be made (IOW after Stop() returns, it is safe to delete the callback). 90 // be made (IOW after Stop() returns, it is safe to delete the callback).
91 // The |loop_for_join| parameter is required for asynchronous operation 91 // The |loop_for_join| parameter is required for asynchronous operation
92 // in order to join the worker thread and close the thread handle later via a 92 // in order to join the worker thread and close the thread handle later via a
93 // posted task. 93 // posted task.
94 // If set to NULL, function will wait for the thread to exit before returning. 94 // If set to NULL, function will wait for the thread to exit before returning.
95 void Stop(base::MessageLoop* loop_for_join); 95 void Stop(base::MessageLoop* loop_for_join);
96 96
97 // Releases the thread from wait mode so that it starts running with the given
98 // |callback| and |socket|. This will also reset the index used for
99 // sychronized buffers.
100 void StartRun(AudioDeviceThread::Callback* callback,
101 base::SyncSocket::Handle socket);
102
103 // Stops running the thread, puts it in wait mode and shuts down the socket.
104 // It can then be started again with StartRun().
105 void StopRun();
106
97 // Returns true if the thread is stopped or stopping. 107 // Returns true if the thread is stopped or stopping.
98 bool IsStopped(); 108 bool IsStopped();
99 109
100 private: 110 private:
101 // Our own private SimpleThread override. We implement this in a 111 // Our own private SimpleThread override. We implement this in a
102 // private class so that we get the following benefits: 112 // private class so that we get the following benefits:
103 // 1) AudioDeviceThread doesn't expose SimpleThread methods. 113 // 1) AudioDeviceThread doesn't expose SimpleThread methods.
104 // I.e. the caller can't call Start()/Stop() - which would be bad. 114 // I.e. the caller can't call Start()/Stop() - which would be bad.
105 // 2) We override ThreadMain to add additional on-thread initialization 115 // 2) We override ThreadMain to add additional on-thread initialization
106 // while still synchronized with SimpleThread::Start() to provide 116 // while still synchronized with SimpleThread::Start() to provide
107 // reliable initialization. 117 // reliable initialization.
108 class Thread; 118 class Thread;
109 119
110 base::Lock thread_lock_; 120 base::Lock thread_lock_;
111 scoped_refptr<AudioDeviceThread::Thread> thread_; 121 scoped_refptr<AudioDeviceThread::Thread> thread_;
112 122
113 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 123 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
114 }; 124 };
115 125
116 } // namespace media. 126 } // namespace media.
117 127
118 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 128 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698