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

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: Changes from olka@, adding callback lock, removing stopping hack, rebase. 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') | no next file with comments »
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 puts into wait mode. Play() 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, bool synchronized_buffers);
84 bool synchronized_buffers);
85 84
86 // This tells the audio thread to stop and clean up the data. 85 // This tells the audio thread to stop and clean up the data.
87 // The method can stop the thread synchronously or asynchronously. 86 // The method can stop the thread synchronously or asynchronously.
88 // In the latter case, the thread will still be running after Stop() 87 // 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 88 // 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). 89 // be made (IOW after Stop() returns, it is safe to delete the callback).
91 // The |loop_for_join| parameter is required for asynchronous operation 90 // 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 91 // in order to join the worker thread and close the thread handle later via a
93 // posted task. 92 // posted task.
94 // If set to NULL, function will wait for the thread to exit before returning. 93 // If set to NULL, function will wait for the thread to exit before returning.
95 void Stop(base::MessageLoop* loop_for_join); 94 void Stop(base::MessageLoop* loop_for_join);
96 95
96 // Releases the thread from wait mode so that it starts running with the given
97 // |callback| and |socket|. This will also reset the index used for
98 // sychronized buffers.
99 void Play(AudioDeviceThread::Callback* callback,
Henrik Grunell 2016/04/29 14:34:55 For output, we could now set the callback once in
Henrik Grunell 2016/05/03 13:34:55 Actually, it's not possible - this is the callback
100 base::SyncSocket::Handle socket);
101
102 // Puts the thread in the wait mode and shuts down the socket.
103 // It can be resumed again with Play().
104 void Pause();
105
97 // Returns true if the thread is stopped or stopping. 106 // Returns true if the thread is stopped or stopping.
98 bool IsStopped(); 107 bool IsStopped();
99 108
100 private: 109 private:
110 // Not sure if we need this extra class and extra lock?
Henrik Grunell 2016/04/29 14:34:55 This was Olga's addition.
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
« no previous file with comments | « no previous file | media/audio/audio_device_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698