Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
backend_dispatcher.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Roc 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_dispatcher.h
10 //! @brief Backend dispatcher.
11 
12 #ifndef ROC_SNDIO_BACKEND_DISPATCHER_H_
13 #define ROC_SNDIO_BACKEND_DISPATCHER_H_
14 
15 #include "roc_core/array.h"
16 #include "roc_core/iallocator.h"
17 #include "roc_core/noncopyable.h"
18 #include "roc_core/shared_ptr.h"
19 #include "roc_core/singleton.h"
20 #include "roc_sndio/ibackend.h"
21 #include "roc_sndio/isink.h"
22 #include "roc_sndio/isource.h"
23 
24 namespace roc {
25 namespace sndio {
26 
27 //! Backend dispatcher.
29 public:
30  //! Get instance.
33  }
34 
35  //! Set internal buffer size for all backends that need it.
36  void set_frame_size(size_t size);
37 
38  //! Create and open a sink.
39  ISink* open_sink(core::IAllocator& allocator,
40  const char* driver,
41  const char* output,
42  const Config& config);
43 
44  //! Create and open a source.
46  const char* driver,
47  const char* input,
48  const Config& config);
49 
50  //! Append supported drivers from all registered backends to array.
52 
53  //! Append supported file formats from all registered backends to array.
55 
56 private:
57  friend class core::Singleton<BackendDispatcher>;
58 
59  BackendDispatcher();
60 
61  IBackend* select_backend_(const char* driver, const char* inout, int flags);
62  IBackend* probe_backends_(const char* driver, const char* inout, int flags);
63 
64  void add_backend_(IBackend& backend);
65 
66  enum { MaxBackends = 8 };
67 
68  IBackend* backends_[MaxBackends];
69  size_t n_backends_;
70 };
71 
72 } // namespace sndio
73 } // namespace roc
74 
75 #endif // ROC_SNDIO_BACKEND_DISPATCHER_H_
Sink interface.
Definition: isink.h:21
Memory allocator interface.
Definition: iallocator.h:23
ISink * open_sink(core::IAllocator &allocator, const char *driver, const char *output, const Config &config)
Create and open a sink.
Singleton.
Sink interface.
Root namespace.
Backend interface.
Shared ownership intrusive pointer.
Dynamic array.
Sink and source config.
Definition: config.h:22
Source interface.
Singleton.
Definition: singleton.h:26
Base class for non-copyable objects.
Definition: noncopyable.h:23
ISource * open_source(core::IAllocator &allocator, const char *driver, const char *input, const Config &config)
Create and open a source.
void set_frame_size(size_t size)
Set internal buffer size for all backends that need it.
static BackendDispatcher & instance()
Get instance.
bool get_device_drivers(core::Array< DriverInfo > &arr)
Append supported drivers from all registered backends to array.
Dynamic array.
Definition: array.h:25
Non-copyable object.
Source interface.
Definition: isource.h:21
static T & instance()
Get singleton instance.
Definition: singleton.h:29
Backend interface.
Definition: ibackend.h:27
bool get_file_drivers(core::Array< DriverInfo > &arr)
Append supported file formats from all registered backends to array.
Memory allocator interface.