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

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

Issue 10834033: Move AudioDevice and AudioInputDevice to media. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and fixed a few lint issues Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « content/test/webrtc_audio_device_test.cc ('k') | 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 CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
13 #include "base/sync_socket.h" 13 #include "base/sync_socket.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "content/common/content_export.h" 15 #include "media/base/media_export.h"
16 #include "media/audio/audio_parameters.h" 16 #include "media/audio/audio_parameters.h"
17 17
18 class MessageLoop; 18 class MessageLoop;
19 19
20 namespace media {
21
20 // Data transfer between browser and render process uses a combination 22 // Data transfer between browser and render process uses a combination
21 // of sync sockets and shared memory. To read from the socket and render 23 // of sync sockets and shared memory. To read from the socket and render
22 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads 24 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads
23 // data from the browser via the socket and fills the shared memory from the 25 // data from the browser via the socket and fills the shared memory from the
24 // audio thread via the AudioDeviceThread::Callback interface/class. 26 // audio thread via the AudioDeviceThread::Callback interface/class.
25 // For more details see the documentation in audio_device.h. 27 // For more details see the documentation in audio_device.h.
26 // 28 //
27 // TODO(tommi): Multiple Audio[Input]Device instances should be able to share 29 // TODO(tommi): Multiple audio input/output device instances should be able to
28 // the same thread instead of spinning one per instance. 30 // share the same thread instead of spinning one per instance.
29 class CONTENT_EXPORT AudioDeviceThread { 31 class MEDIA_EXPORT AudioDeviceThread {
30 public: 32 public:
31 // This is the callback interface/base class that Audio[Input]Device 33 // This is the callback interface/base class that Audio[Output|Input]Device
32 // implements to render input/output data. The callback happens on the 34 // implements to render input/output data. The callbacks run on the
33 // AudioDevice thread. 35 // thread owned by AudioDeviceThread.
34 class Callback { 36 class Callback {
35 public: 37 public:
36 Callback(const media::AudioParameters& audio_parameters, 38 Callback(const AudioParameters& audio_parameters,
37 base::SharedMemoryHandle memory, 39 base::SharedMemoryHandle memory,
38 int memory_length); 40 int memory_length);
39 virtual ~Callback(); 41 virtual ~Callback();
40 42
41 // One time initialization for the callback object on the audio thread. 43 // One time initialization for the callback object on the audio thread.
42 void InitializeOnAudioThread(); 44 void InitializeOnAudioThread();
43 45
44 // Derived implementations must call shared_memory_.Map appropriately 46 // Derived implementations must call shared_memory_.Map appropriately
45 // before Process can be called. 47 // before Process can be called.
46 virtual void MapSharedMemory() = 0; 48 virtual void MapSharedMemory() = 0;
47 49
48 // Called whenever we receive notifications about pending data. 50 // Called whenever we receive notifications about pending data.
49 virtual void Process(int pending_data) = 0; 51 virtual void Process(int pending_data) = 0;
50 52
51 protected: 53 protected:
52 // Protected so that derived classes can access directly. 54 // Protected so that derived classes can access directly.
53 // The variables are 'const' since values are calculated/set in the 55 // The variables are 'const' since values are calculated/set in the
54 // constructor and must never change. 56 // constructor and must never change.
55 const media::AudioParameters audio_parameters_; 57 const AudioParameters audio_parameters_;
56 const int samples_per_ms_; 58 const int samples_per_ms_;
57 const int bytes_per_ms_; 59 const int bytes_per_ms_;
58 60
59 // Audio buffers that are allocated in InitializeOnAudioThread() based on 61 // Audio buffers that are allocated in InitializeOnAudioThread() based on
60 // info from audio_parameters_. 62 // info from audio_parameters_.
61 std::vector<float*> audio_data_; 63 std::vector<float*> audio_data_;
62 base::SharedMemory shared_memory_; 64 base::SharedMemory shared_memory_;
63 const int memory_length_; 65 const int memory_length_;
64 66
65 private: 67 private:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // while still synchronized with SimpleThread::Start() to provide 99 // while still synchronized with SimpleThread::Start() to provide
98 // reliable initialization. 100 // reliable initialization.
99 class Thread; 101 class Thread;
100 102
101 base::Lock thread_lock_; 103 base::Lock thread_lock_;
102 scoped_refptr<AudioDeviceThread::Thread> thread_; 104 scoped_refptr<AudioDeviceThread::Thread> thread_;
103 105
104 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 106 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
105 }; 107 };
106 108
107 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 109 } // namespace media.
110
111 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
OLDNEW
« no previous file with comments | « content/test/webrtc_audio_device_test.cc ('k') | media/audio/audio_device_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698