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

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: Code review (tommi@). Created 4 years, 7 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
« no previous file with comments | « no previous file | media/audio/audio_device_thread.cc » ('j') | media/audio/audio_device_thread.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 suspends it. Resume() must then be called to
79 // actually start running. The thread must not already be started. If
79 // |sychronized_buffers| is set, the browser expects to be notified via the 80 // |sychronized_buffers| is set, the browser expects to be notified via the
80 // |socket| every time AudioDeviceThread::Process() completes. 81 // |socket| every time AudioDeviceThread::Process() completes.
81 void Start(AudioDeviceThread::Callback* callback, 82 void StartSuspended(const char* thread_name, bool synchronized_buffers);
82 base::SyncSocket::Handle socket,
83 const char* thread_name,
84 bool synchronized_buffers);
85 83
86 // This tells the audio thread to stop and clean up the data. 84 // This tells the audio thread to stop and clean up the data.
87 // The method can stop the thread synchronously or asynchronously. 85 // The method can stop the thread synchronously or asynchronously.
88 // In the latter case, the thread will still be running after Stop() 86 // 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 87 // 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). 88 // be made (IOW after Stop() returns, it is safe to delete the callback).
91 // The |loop_for_join| parameter is required for asynchronous operation 89 // 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 90 // in order to join the worker thread and close the thread handle later via a
93 // posted task. 91 // posted task.
94 // If set to NULL, function will wait for the thread to exit before returning. 92 // If set to NULL, function will wait for the thread to exit before returning.
95 void Stop(base::MessageLoop* loop_for_join); 93 void Stop(base::MessageLoop* loop_for_join);
96 94
95 // Resumes the thread so that it starts running with the given |callback| and
96 // |socket|. This will also reset the index used for sychronized buffers.
97 void Resume(AudioDeviceThread::Callback* callback,
98 base::SyncSocket::Handle socket);
99
100 // Suspends the thread and shuts down the socket. It can be resumed again with
101 // Resume().
102 void Suspend();
103
97 // Returns true if the thread is stopped or stopping. 104 // Returns true if the thread is stopped or stopping.
98 bool IsStopped(); 105 bool IsStopped();
99 106
100 private: 107 private:
101 // Our own private SimpleThread override. We implement this in a 108 // Our own private SimpleThread override. We implement this in a
102 // private class so that we get the following benefits: 109 // private class so that we get the following benefits:
103 // 1) AudioDeviceThread doesn't expose SimpleThread methods. 110 // 1) AudioDeviceThread doesn't expose SimpleThread methods.
104 // I.e. the caller can't call Start()/Stop() - which would be bad. 111 // I.e. the caller can't call Start()/Stop() - which would be bad.
105 // 2) We override ThreadMain to add additional on-thread initialization 112 // 2) We override ThreadMain to add additional on-thread initialization
106 // while still synchronized with SimpleThread::Start() to provide 113 // while still synchronized with SimpleThread::Start() to provide
107 // reliable initialization. 114 // reliable initialization.
115 // TODO(grunell): Do we still need this extra layer?
108 class Thread; 116 class Thread;
109 117
110 base::Lock thread_lock_; 118 base::Lock thread_lock_;
111 scoped_refptr<AudioDeviceThread::Thread> thread_; 119 scoped_refptr<AudioDeviceThread::Thread> thread_;
112 120
113 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 121 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
114 }; 122 };
115 123
116 } // namespace media. 124 } // namespace media.
117 125
118 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 126 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_device_thread.cc » ('j') | media/audio/audio_device_thread.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698