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

Unified Diff: media/audio/audio_device_thread.h

Issue 2076793002: Cleanup AudioDeviceThread to reduce locking and unused features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/audio/audio_device_thread.cc » ('j') | media/audio/audio_device_thread.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_device_thread.h
diff --git a/media/audio/audio_device_thread.h b/media/audio/audio_device_thread.h
index 61e5e8724ddc24b289c01c364e3491b137779462..185a60d239036a6dada4d5a9d2809f93696fef43 100644
--- a/media/audio/audio_device_thread.h
+++ b/media/audio/audio_device_thread.h
@@ -8,30 +8,20 @@
#include <stdint.h>
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory.h"
#include "base/sync_socket.h"
-#include "base/synchronization/lock.h"
+#include "base/threading/platform_thread.h"
#include "media/base/audio_parameters.h"
#include "media/base/media_export.h"
-namespace base {
-class MessageLoop;
-}
-
namespace media {
-class AudioBus;
// Data transfer between browser and render process uses a combination
// of sync sockets and shared memory. To read from the socket and render
// data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads
// data from the browser via the socket and fills the shared memory from the
// audio thread via the AudioDeviceThread::Callback interface/class.
-// For more details see the documentation in audio_device.h.
-//
-// TODO(tommi): Multiple audio input/output device instances should be able to
-// share the same thread instead of spinning one per instance.
-class MEDIA_EXPORT AudioDeviceThread {
+class MEDIA_EXPORT AudioDeviceThread : public base::PlatformThread::Delegate {
public:
// This is the callback interface/base class that Audio[Output|Input]Device
// implements to render input/output data. The callbacks run on the
@@ -42,7 +32,6 @@ class MEDIA_EXPORT AudioDeviceThread {
base::SharedMemoryHandle memory,
int memory_length,
int total_segments);
- virtual ~Callback();
// One time initialization for the callback object on the audio thread.
void InitializeOnAudioThread();
@@ -55,6 +44,8 @@ class MEDIA_EXPORT AudioDeviceThread {
virtual void Process(uint32_t pending_data) = 0;
protected:
+ virtual ~Callback();
+
// Protected so that derived classes can access directly.
// The variables are 'const' since values are calculated/set in the
// constructor and must never change.
@@ -72,43 +63,22 @@ class MEDIA_EXPORT AudioDeviceThread {
DISALLOW_COPY_AND_ASSIGN(Callback);
};
- AudioDeviceThread();
- ~AudioDeviceThread();
-
- // Starts the audio thread. The thread must not already be running. If
- // |sychronized_buffers| is set, the browser expects to be notified via the
- // |socket| every time AudioDeviceThread::Process() completes.
- void Start(AudioDeviceThread::Callback* callback,
- base::SyncSocket::Handle socket,
- const char* thread_name,
- bool synchronized_buffers);
-
- // This tells the audio thread to stop and clean up the data.
- // The method can stop the thread synchronously or asynchronously.
- // In the latter case, the thread will still be running after Stop()
- // returns, but the callback pointer is cleared so no further callbacks will
- // be made (IOW after Stop() returns, it is safe to delete the callback).
- // The |loop_for_join| parameter is required for asynchronous operation
- // in order to join the worker thread and close the thread handle later via a
- // posted task.
- // If set to NULL, function will wait for the thread to exit before returning.
- void Stop(base::MessageLoop* loop_for_join);
-
- // Returns true if the thread is stopped or stopping.
- bool IsStopped();
+ // Creates and automatically starts the audio thread.
+ AudioDeviceThread(Callback* callback,
+ base::SyncSocket::Handle socket,
+ const char* thread_name);
+
+ // This tells the audio thread to stop and clean up the data; this is a
+ // synchronous process and the thread will stop before the method returns.
+ ~AudioDeviceThread() override;
private:
- // Our own private SimpleThread override. We implement this in a
- // private class so that we get the following benefits:
- // 1) AudioDeviceThread doesn't expose SimpleThread methods.
- // I.e. the caller can't call Start()/Stop() - which would be bad.
- // 2) We override ThreadMain to add additional on-thread initialization
- // while still synchronized with SimpleThread::Start() to provide
- // reliable initialization.
- class Thread;
-
- base::Lock thread_lock_;
- scoped_refptr<AudioDeviceThread::Thread> thread_;
+ void ThreadMain() final;
+
+ Callback* const callback_;
+ const char* thread_name_;
+ base::CancelableSyncSocket socket_;
+ base::PlatformThreadHandle thread_handle_;
DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
};
« 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