libASPL
Loading...
Searching...
No Matches
Plugin.hpp
Go to the documentation of this file.
1// Copyright (c) libASPL authors
2// Licensed under MIT
3
4//! @file aspl/Plugin.hpp
5//! @brief Plugin object.
6
7#pragma once
8
9#include <aspl/Device.hpp>
10#include <aspl/DoubleBuffer.hpp>
11#include <aspl/Object.hpp>
12
13#include <CoreAudio/AudioServerPlugIn.h>
14
15#include <mutex>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20namespace aspl {
21
22//! Audio plugin parameters.
24{
25 //! Human readable name of the maker of the plug-in.
26 //! Used by default implementation of Plugin::GetManufacturer().
27 std::string Manufacturer = "libASPL";
28
29 //! Resource bundle path.
30 //! Used by default implementation of Plugin::GetResourceBundlePath().
31 //! Empty string means use plug-in bundle itself.
32 std::string ResourceBundlePath = "";
33};
34
35//! Plugin object.
36//!
37//! Plugin is the root of the Object tree. All other objects are owned by it,
38//! either directly or indirectly.
39//!
40//! Plugin, unlike other objects, has the constant well-known identifier
41//! (@c kAudioObjectPlugInObject). HAL uses it to recursively discover all
42//! other objects in the hierarchy.
43//!
44//! Typically, plugin owns one or more devices, and each device owns one or
45//! more streams and zero or multiple controls. Plugin itself is owned by
46//! Driver, but the latter is not an Object, but rather something like an
47//! entry point to the object tree.
48class Plugin : public Object
49{
50public:
51 //! Construct plugin.
52 explicit Plugin(std::shared_ptr<const Context> context,
53 const PluginParameters& params = {});
54
55 //! @name Getters and setters
56 //! @{
57
58 //! Get plugin manufacturer.
59 //! Human readable name of the maker of the plug-in.
60 //! Can be localized.
61 //! By default returns PluginParameters::Manufacturer.
62 //! @note
63 //! Backs @c kAudioObjectPropertyManufacturer property.
64 virtual std::string GetManufacturer() const;
65
66 //! Get resource bundle path.
67 //! By default returns PluginParameters::ResourceBundlePath.
68 //! @remarks
69 //! Relative to the path of the plug-in bundle.
70 //! Empty string means use plug-in bundle itself.
71 //! @note
72 //! Backs @c kAudioPlugInPropertyResourceBundle property.
73 virtual std::string GetResourceBundlePath() const;
74
75 //! Get devices.
76 //! Returns the list of owned devices.
77 //! Default implementation returns all owned objects of kAudioDeviceClassID class.
78 //! @note
79 //! Backs @c kAudioPlugInPropertyDeviceList property.
80 virtual std::vector<AudioObjectID> GetDeviceIDs() const;
81
82 //! Get device with given UID.
83 //! Returns nullptr if there is no such device.
84 //! @note
85 //! Backs @c kAudioPlugInPropertyTranslateUIDToDevice property.
86 virtual AudioObjectID GetDeviceIDByUID(const std::string& uid) const;
87
88 //! @}
89
90 //! @name Devices
91 //! @{
92
93 //! Get number of devices added.
95
96 //! Get device with given zero-based index.
97 //! Returns nullptr if there are less than idx+1 devices.
98 std::shared_ptr<Device> GetDeviceByIndex(UInt32 idx) const;
99
100 //! Get device with given object ID.
101 //! Returns nullptr if there is no such device.
102 std::shared_ptr<Device> GetDeviceByID(AudioObjectID deviceID) const;
103
104 //! Check if device is already added.
105 bool HasDevice(std::shared_ptr<Device> device) const;
106
107 //! Add device to the plugin.
108 //! Adds device to the owned object list.
109 void AddDevice(std::shared_ptr<Device> device);
110
111 //! Remove device from the plugin.
112 //! Removes device from the owned object list.
113 void RemoveDevice(std::shared_ptr<Device> device);
114
115 //! @}
116
117 //! @name Property dispatch
118 //! @{
119
120 //! Get class ID.
121 AudioClassID GetClass() const override;
122
123 //! Get base class ID.
124 AudioClassID GetBaseClass() const override;
125
126 //! Check if this object is instance of given base class.
127 bool IsInstance(AudioClassID classID) const override;
128
129 //! Check whether given property is present.
132 const AudioObjectPropertyAddress* address) const override;
133
134 //! Check whether given property can be changed.
138 Boolean* outIsSettable) const override;
139
140 //! Get size of property value in bytes.
145 const void* qualifierData,
146 UInt32* outDataSize) const override;
147
148 //! Get property value.
153 const void* qualifierData,
156 void* outData) const override;
157
158 //! Change property value.
163 const void* qualifierData,
165 const void* inData) override;
166
167 //! @}
168
169private:
170 mutable std::recursive_mutex writeMutex_;
171
172 const PluginParameters params_;
173
177};
178
179} // namespace aspl
Audio device object.
Double buffer.
Basic audio object.
Doubly-buffered value with non-blocking read and blocking write.
Base class for audio objects.
Definition Object.hpp:55
Plugin object.
Definition Plugin.hpp:49
OSStatus GetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, UInt32 *outDataSize, void *outData) const override
Get property value.
virtual std::string GetResourceBundlePath() const
Get resource bundle path. By default returns PluginParameters::ResourceBundlePath.
OSStatus IsPropertySettable(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, Boolean *outIsSettable) const override
Check whether given property can be changed.
void AddDevice(std::shared_ptr< Device > device)
Add device to the plugin. Adds device to the owned object list.
AudioClassID GetBaseClass() const override
Get base class ID.
OSStatus SetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, const void *inData) override
Change property value.
virtual AudioObjectID GetDeviceIDByUID(const std::string &uid) const
Get device with given UID. Returns nullptr if there is no such device.
virtual std::string GetManufacturer() const
Get plugin manufacturer. Human readable name of the maker of the plug-in. Can be localized....
std::shared_ptr< Device > GetDeviceByIndex(UInt32 idx) const
Get device with given zero-based index. Returns nullptr if there are less than idx+1 devices.
void RemoveDevice(std::shared_ptr< Device > device)
Remove device from the plugin. Removes device from the owned object list.
virtual std::vector< AudioObjectID > GetDeviceIDs() const
Get devices. Returns the list of owned devices. Default implementation returns all owned objects of k...
Boolean HasProperty(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address) const override
Check whether given property is present.
AudioClassID GetClass() const override
Get class ID.
std::shared_ptr< Device > GetDeviceByID(AudioObjectID deviceID) const
Get device with given object ID. Returns nullptr if there is no such device.
Plugin(std::shared_ptr< const Context > context, const PluginParameters &params={})
Construct plugin.
bool IsInstance(AudioClassID classID) const override
Check if this object is instance of given base class.
UInt32 GetDeviceCount() const
Get number of devices added.
OSStatus GetPropertyDataSize(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 *outDataSize) const override
Get size of property value in bytes.
bool HasDevice(std::shared_ptr< Device > device) const
Check if device is already added.
Audio plugin parameters.
Definition Plugin.hpp:24
std::string Manufacturer
Human readable name of the maker of the plug-in. Used by default implementation of Plugin::GetManufac...
Definition Plugin.hpp:27
std::string ResourceBundlePath
Resource bundle path. Used by default implementation of Plugin::GetResourceBundlePath()....
Definition Plugin.hpp:32