2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_SOUND_SOUNDSYSTEMINTERFACE_H_
12 #define WEBRTC_SOUND_SOUNDSYSTEMINTERFACE_H_
16 #include "webrtc/base/constructormagic.h"
20 class SoundDeviceLocator;
21 class SoundInputStreamInterface;
22 class SoundOutputStreamInterface;
24 // Interface for a platform's sound system.
25 // Implementations must guarantee thread-safety for at least the following use
27 // 1) Concurrent enumeration and opening of devices from different threads.
28 // 2) Concurrent use of different Sound(Input|Output)StreamInterface
29 // instances from different threads (but concurrent use of the _same_ one from
30 // different threads need not be supported).
31 class SoundSystemInterface {
33 typedef std::vector<SoundDeviceLocator *> SoundDeviceLocatorList;
36 // Only one supported sample format at this time.
37 // The values here may be used in lookup tables, so they shouldn't change.
42 // Enable reporting the current stream latency in
43 // Sound(Input|Output)StreamInterface. See those classes for more details.
44 FLAG_REPORT_LATENCY = (1 << 0),
48 // Format for the sound stream.
50 // Sampling frequency in hertz.
52 // Number of channels in the PCM stream.
53 unsigned int channels;
54 // Misc flags. Should be taken from the Flags enum above.
56 // Desired latency, measured as number of bytes of sample data
60 // Special values for the "latency" field of OpenParams.
61 // Use this one to say you don't care what the latency is. The sound system
62 // will optimize for other things instead.
63 static const int kNoLatencyRequirements = -1;
64 // Use this one to say that you want the sound system to pick an appropriate
65 // small latency value. The sound system may pick the minimum allowed one, or
66 // a slightly higher one in the event that the true minimum requires an
67 // undesirable trade-off.
68 static const int kLowLatency = 0;
70 // Max value for the volume parameters for Sound(Input|Output)StreamInterface.
71 static const int kMaxVolume = 255;
72 // Min value for the volume parameters for Sound(Input|Output)StreamInterface.
73 static const int kMinVolume = 0;
75 // Helper for clearing a locator list and deleting the entries.
76 static void ClearSoundDeviceLocatorList(SoundDeviceLocatorList *devices);
78 virtual ~SoundSystemInterface() {}
80 virtual bool Init() = 0;
81 virtual void Terminate() = 0;
83 // Enumerates the available devices. (Any pre-existing locators in the lists
85 virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices) = 0;
86 virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices) = 0;
88 // Gets a special locator for the default device.
89 virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device) = 0;
90 virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device) = 0;
92 // Opens the given device, or returns NULL on error.
93 virtual SoundOutputStreamInterface *OpenPlaybackDevice(
94 const SoundDeviceLocator *device,
95 const OpenParams ¶ms) = 0;
96 virtual SoundInputStreamInterface *OpenCaptureDevice(
97 const SoundDeviceLocator *device,
98 const OpenParams ¶ms) = 0;
100 // A human-readable name for this sound system.
101 virtual const char *GetName() const = 0;
104 SoundSystemInterface() {}
107 DISALLOW_COPY_AND_ASSIGN(SoundSystemInterface);
112 #endif // WEBRTC_SOUND_SOUNDSYSTEMINTERFACE_H_