Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
backend_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_sndio/backend_map.h
10 //! @brief Backend map.
11 
12 #ifndef ROC_SNDIO_BACKEND_MAP_H_
13 #define ROC_SNDIO_BACKEND_MAP_H_
14 
15 #include "roc_core/noncopyable.h"
16 #include "roc_core/optional.h"
17 #include "roc_core/singleton.h"
18 #include "roc_sndio/driver.h"
19 #include "roc_sndio/ibackend.h"
20 
21 #ifdef ROC_TARGET_PULSEAUDIO
23 #endif // ROC_TARGET_PULSEAUDIO
24 
25 #ifdef ROC_TARGET_SNDFILE
27 #endif // ROC_TARGET_SNDFILE
28 
29 #ifdef ROC_TARGET_SOX
30 #include "roc_sndio/sox_backend.h"
31 #endif // ROC_TARGET_SOX
32 
33 #include "roc_sndio/wav_backend.h"
34 
35 namespace roc {
36 namespace sndio {
37 
38 //! Backend map.
39 class BackendMap : public core::NonCopyable<> {
40 public:
41  //! Get instance.
42  static BackendMap& instance() {
44  }
45 
46  //! Get number of backends available.
47  size_t num_backends() const;
48 
49  //! Get backend by index.
50  IBackend& nth_backend(size_t backend_index) const;
51 
52  //! Get number of drivers available.
53  size_t num_drivers() const;
54 
55  //! Get driver by index.
56  const DriverInfo& nth_driver(size_t driver_index) const;
57 
58  //! Set internal buffer size for all backends that need it.
60  const audio::SampleSpec& sample_spec);
61 
62 private:
63  friend class core::Singleton<BackendMap>;
64 
65  BackendMap();
66 
67  void register_backends_();
68  void register_drivers_();
69 
70  void add_backend_(IBackend*);
71 
72 #ifdef ROC_TARGET_PULSEAUDIO
73  core::Optional<PulseaudioBackend> pulseaudio_backend_;
74 #endif // ROC_TARGET_PULSEAUDIO
75 
76 #ifdef ROC_TARGET_SNDFILE
77  core::Optional<SndfileBackend> sndfile_backend_;
78 #endif // ROC_TARGET_SNDFILE
79 
80 #ifdef ROC_TARGET_SOX
81  core::Optional<SoxBackend> sox_backend_;
82 #endif // ROC_TARGET_SOX
83 
84  core::Optional<WavBackend> wav_backend_;
85 
88 };
89 
90 } // namespace sndio
91 } // namespace roc
92 
93 #endif // ROC_SNDIO_BACKEND_MAP_H_
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:30
Dynamic array.
Definition: array.h:40
Base class for non-copyable objects.
Definition: noncopyable.h:23
Optionally constructed object.
Definition: optional.h:25
static T & instance()
Get singleton instance.
Definition: singleton.h:29
void set_frame_size(core::nanoseconds_t frame_length, const audio::SampleSpec &sample_spec)
Set internal buffer size for all backends that need it.
size_t num_backends() const
Get number of backends available.
size_t num_drivers() const
Get number of drivers available.
IBackend & nth_backend(size_t backend_index) const
Get backend by index.
static BackendMap & instance()
Get instance.
Definition: backend_map.h:42
const DriverInfo & nth_driver(size_t driver_index) const
Get driver by index.
Backend interface.
Definition: ibackend.h:29
Driver types.
Backend interface.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Non-copyable object.
Optionally constructed object.
Pulseaudio backend.
Singleton.
SndFile backend.
SoX backend.
Driver information.
Definition: driver.h:51
WAV backend.