166a358217004e1580453e46ce99041533e994985henrike@webrtc.org/*
266a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
366a358217004e1580453e46ce99041533e994985henrike@webrtc.org *
466a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  Use of this source code is governed by a BSD-style license
566a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  that can be found in the LICENSE file in the root of the source
666a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  tree. An additional intellectual property rights grant can be found
766a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  in the file PATENTS.  All contributing project authors may
866a358217004e1580453e46ce99041533e994985henrike@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
966a358217004e1580453e46ce99041533e994985henrike@webrtc.org */
1066a358217004e1580453e46ce99041533e994985henrike@webrtc.org
1166a358217004e1580453e46ce99041533e994985henrike@webrtc.org#ifndef WEBRTC_SOUND_ALSASOUNDSYSTEM_H_
1266a358217004e1580453e46ce99041533e994985henrike@webrtc.org#define WEBRTC_SOUND_ALSASOUNDSYSTEM_H_
1366a358217004e1580453e46ce99041533e994985henrike@webrtc.org
1466a358217004e1580453e46ce99041533e994985henrike@webrtc.org#include "webrtc/sound/alsasymboltable.h"
1566a358217004e1580453e46ce99041533e994985henrike@webrtc.org#include "webrtc/sound/soundsysteminterface.h"
1666a358217004e1580453e46ce99041533e994985henrike@webrtc.org#include "webrtc/base/constructormagic.h"
1766a358217004e1580453e46ce99041533e994985henrike@webrtc.org
1866a358217004e1580453e46ce99041533e994985henrike@webrtc.orgnamespace rtc {
1966a358217004e1580453e46ce99041533e994985henrike@webrtc.org
2066a358217004e1580453e46ce99041533e994985henrike@webrtc.orgclass AlsaStream;
2166a358217004e1580453e46ce99041533e994985henrike@webrtc.orgclass AlsaInputStream;
2266a358217004e1580453e46ce99041533e994985henrike@webrtc.orgclass AlsaOutputStream;
2366a358217004e1580453e46ce99041533e994985henrike@webrtc.org
2466a358217004e1580453e46ce99041533e994985henrike@webrtc.org// Sound system implementation for ALSA, the predominant sound device API on
2566a358217004e1580453e46ce99041533e994985henrike@webrtc.org// Linux (but typically not used directly by applications anymore).
2666a358217004e1580453e46ce99041533e994985henrike@webrtc.orgclass AlsaSoundSystem : public SoundSystemInterface {
2766a358217004e1580453e46ce99041533e994985henrike@webrtc.org  friend class AlsaStream;
2866a358217004e1580453e46ce99041533e994985henrike@webrtc.org  friend class AlsaInputStream;
2966a358217004e1580453e46ce99041533e994985henrike@webrtc.org  friend class AlsaOutputStream;
3066a358217004e1580453e46ce99041533e994985henrike@webrtc.org public:
3166a358217004e1580453e46ce99041533e994985henrike@webrtc.org  static SoundSystemInterface *Create() {
3266a358217004e1580453e46ce99041533e994985henrike@webrtc.org    return new AlsaSoundSystem();
3366a358217004e1580453e46ce99041533e994985henrike@webrtc.org  }
3466a358217004e1580453e46ce99041533e994985henrike@webrtc.org
3566a358217004e1580453e46ce99041533e994985henrike@webrtc.org  AlsaSoundSystem();
3666a358217004e1580453e46ce99041533e994985henrike@webrtc.org
37a35ae7f507cc4e909dd4253106c97528db315adbtfarina  ~AlsaSoundSystem() override;
3866a358217004e1580453e46ce99041533e994985henrike@webrtc.org
39a35ae7f507cc4e909dd4253106c97528db315adbtfarina  bool Init() override;
40a35ae7f507cc4e909dd4253106c97528db315adbtfarina  void Terminate() override;
4166a358217004e1580453e46ce99041533e994985henrike@webrtc.org
42a35ae7f507cc4e909dd4253106c97528db315adbtfarina  bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices) override;
43a35ae7f507cc4e909dd4253106c97528db315adbtfarina  bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices) override;
4466a358217004e1580453e46ce99041533e994985henrike@webrtc.org
45a35ae7f507cc4e909dd4253106c97528db315adbtfarina  bool GetDefaultPlaybackDevice(SoundDeviceLocator **device) override;
46a35ae7f507cc4e909dd4253106c97528db315adbtfarina  bool GetDefaultCaptureDevice(SoundDeviceLocator **device) override;
4766a358217004e1580453e46ce99041533e994985henrike@webrtc.org
48a35ae7f507cc4e909dd4253106c97528db315adbtfarina  SoundOutputStreamInterface *OpenPlaybackDevice(
4966a358217004e1580453e46ce99041533e994985henrike@webrtc.org      const SoundDeviceLocator *device,
50a35ae7f507cc4e909dd4253106c97528db315adbtfarina      const OpenParams &params) override;
51a35ae7f507cc4e909dd4253106c97528db315adbtfarina  SoundInputStreamInterface *OpenCaptureDevice(
5266a358217004e1580453e46ce99041533e994985henrike@webrtc.org      const SoundDeviceLocator *device,
53a35ae7f507cc4e909dd4253106c97528db315adbtfarina      const OpenParams &params) override;
5466a358217004e1580453e46ce99041533e994985henrike@webrtc.org
55a35ae7f507cc4e909dd4253106c97528db315adbtfarina  const char *GetName() const override;
5666a358217004e1580453e46ce99041533e994985henrike@webrtc.org
5766a358217004e1580453e46ce99041533e994985henrike@webrtc.org private:
5866a358217004e1580453e46ce99041533e994985henrike@webrtc.org  bool IsInitialized() { return initialized_; }
5966a358217004e1580453e46ce99041533e994985henrike@webrtc.org
6066a358217004e1580453e46ce99041533e994985henrike@webrtc.org  bool EnumerateDevices(SoundDeviceLocatorList *devices,
6166a358217004e1580453e46ce99041533e994985henrike@webrtc.org                        bool capture_not_playback);
6266a358217004e1580453e46ce99041533e994985henrike@webrtc.org
6366a358217004e1580453e46ce99041533e994985henrike@webrtc.org  bool GetDefaultDevice(SoundDeviceLocator **device);
6466a358217004e1580453e46ce99041533e994985henrike@webrtc.org
6566a358217004e1580453e46ce99041533e994985henrike@webrtc.org  static size_t FrameSize(const OpenParams &params);
6666a358217004e1580453e46ce99041533e994985henrike@webrtc.org
6766a358217004e1580453e46ce99041533e994985henrike@webrtc.org  template <typename StreamInterface>
6866a358217004e1580453e46ce99041533e994985henrike@webrtc.org  StreamInterface *OpenDevice(
6966a358217004e1580453e46ce99041533e994985henrike@webrtc.org      const SoundDeviceLocator *device,
7066a358217004e1580453e46ce99041533e994985henrike@webrtc.org      const OpenParams &params,
7166a358217004e1580453e46ce99041533e994985henrike@webrtc.org      snd_pcm_stream_t type,
7266a358217004e1580453e46ce99041533e994985henrike@webrtc.org      StreamInterface *(AlsaSoundSystem::*start_fn)(
7366a358217004e1580453e46ce99041533e994985henrike@webrtc.org          snd_pcm_t *handle,
7466a358217004e1580453e46ce99041533e994985henrike@webrtc.org          size_t frame_size,
7566a358217004e1580453e46ce99041533e994985henrike@webrtc.org          int wait_timeout_ms,
7666a358217004e1580453e46ce99041533e994985henrike@webrtc.org          int flags,
7766a358217004e1580453e46ce99041533e994985henrike@webrtc.org          int freq));
7866a358217004e1580453e46ce99041533e994985henrike@webrtc.org
7966a358217004e1580453e46ce99041533e994985henrike@webrtc.org  SoundOutputStreamInterface *StartOutputStream(
8066a358217004e1580453e46ce99041533e994985henrike@webrtc.org      snd_pcm_t *handle,
8166a358217004e1580453e46ce99041533e994985henrike@webrtc.org      size_t frame_size,
8266a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int wait_timeout_ms,
8366a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int flags,
8466a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int freq);
8566a358217004e1580453e46ce99041533e994985henrike@webrtc.org
8666a358217004e1580453e46ce99041533e994985henrike@webrtc.org  SoundInputStreamInterface *StartInputStream(
8766a358217004e1580453e46ce99041533e994985henrike@webrtc.org      snd_pcm_t *handle,
8866a358217004e1580453e46ce99041533e994985henrike@webrtc.org      size_t frame_size,
8966a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int wait_timeout_ms,
9066a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int flags,
9166a358217004e1580453e46ce99041533e994985henrike@webrtc.org      int freq);
9266a358217004e1580453e46ce99041533e994985henrike@webrtc.org
9366a358217004e1580453e46ce99041533e994985henrike@webrtc.org  const char *GetError(int err);
9466a358217004e1580453e46ce99041533e994985henrike@webrtc.org
9566a358217004e1580453e46ce99041533e994985henrike@webrtc.org  bool initialized_;
9666a358217004e1580453e46ce99041533e994985henrike@webrtc.org  AlsaSymbolTable symbol_table_;
9766a358217004e1580453e46ce99041533e994985henrike@webrtc.org
983c089d751ede283e21e186885eaf705c3257ccd2henrikg  RTC_DISALLOW_COPY_AND_ASSIGN(AlsaSoundSystem);
9966a358217004e1580453e46ce99041533e994985henrike@webrtc.org};
10066a358217004e1580453e46ce99041533e994985henrike@webrtc.org
10166a358217004e1580453e46ce99041533e994985henrike@webrtc.org}  // namespace rtc
10266a358217004e1580453e46ce99041533e994985henrike@webrtc.org
10366a358217004e1580453e46ce99041533e994985henrike@webrtc.org#endif  // WEBRTC_SOUND_ALSASOUNDSYSTEM_H_
104