pulse-server: split out volume handling

Part of !776.
This commit is contained in:
Barnabás Pőcze 2021-06-18 22:04:45 +02:00
parent 43e2c64307
commit 4496c33751
6 changed files with 59 additions and 38 deletions

View file

@ -136,6 +136,7 @@ pipewire_module_protocol_pulse_sources = [
'module-protocol-pulse/format.c',
'module-protocol-pulse/manager.c',
'module-protocol-pulse/pulse-server.c',
'module-protocol-pulse/volume.c',
'module-protocol-pulse/modules/module-combine-sink.c',
'module-protocol-pulse/modules/module-echo-cancel.c',
'module-protocol-pulse/modules/module-ladspa-sink.c',

View file

@ -29,6 +29,9 @@
#include "format.h"
#include "volume.h"
struct pw_manager;
struct pw_manager_object;
struct device_info {
uint32_t direction;

View file

@ -35,6 +35,7 @@
#include <pipewire/private.h>
#include "format.h"
#include "volume.h"
struct defs {
struct spa_fraction min_req;
@ -123,15 +124,6 @@ struct buffer_attr {
uint32_t fragsize;
};
struct volume {
uint8_t channels;
float values[CHANNELS_MAX];
};
#define VOLUME_INIT (struct volume) { \
.channels = 0, \
}
struct stream {
uint32_t create_tag;
uint32_t channel; /* index in map */

View file

@ -84,6 +84,7 @@
#include "defs.h"
#include "format.h"
#include "internal.h"
#include "volume.h"
#define DEFAULT_MIN_REQ "256/48000"
#define DEFAULT_DEFAULT_REQ "960/48000"
@ -99,7 +100,6 @@
#define MAX_FORMATS 32
#define MAX_CLIENTS 64
#include "volume.c"
#include "message.c"
#include "manager.h"
#include "dbus-name.c"

View file

@ -22,24 +22,15 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <spa/param/props.h>
#include <spa/param/audio/raw.h>
#include <spa/pod/iter.h>
#include <spa/utils/defs.h>
#include <pipewire/log.h>
#include "volume.h"
static inline bool volume_valid(const struct volume *vol)
{
if (vol->channels == 0 || vol->channels > CHANNELS_MAX)
return false;
return true;
}
static inline void volume_make(struct volume *vol, uint8_t channels)
{
uint8_t i;
for (i = 0; i < channels; i++)
vol->values[i] = 1.0f;
vol->channels = channels;
}
static inline int volume_compare(struct volume *vol, struct volume *other)
int volume_compare(struct volume *vol, struct volume *other)
{
uint8_t i;
if (vol->channels != other->channels) {
@ -55,7 +46,7 @@ static inline int volume_compare(struct volume *vol, struct volume *other)
return 0;
}
static int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bool monitor)
int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bool monitor)
{
struct spa_pod_object *obj = (struct spa_pod_object *) param;
struct spa_pod_prop *prop;

View file

@ -26,7 +26,22 @@
#ifndef PULSE_SERVER_VOLUME_H
#define PULSE_SERVER_VOLUME_H
#include "internal.h"
#include <stdbool.h>
#include <stdint.h>
#include "format.h"
struct spa_pod;
struct volume {
uint8_t channels;
float values[CHANNELS_MAX];
};
#define VOLUME_INIT \
(struct volume) { \
.channels = 0, \
}
struct volume_info {
struct volume volume;
@ -40,7 +55,8 @@ struct volume_info {
uint32_t flags;
};
#define VOLUME_INFO_INIT (struct volume_info) { \
#define VOLUME_INFO_INIT \
(struct volume_info) { \
.volume = VOLUME_INIT, \
.mute = false, \
.level = 1.0, \
@ -48,4 +64,22 @@ struct volume_info {
.steps = 256, \
}
static inline bool volume_valid(const struct volume *vol)
{
if (vol->channels == 0 || vol->channels > CHANNELS_MAX)
return false;
return true;
}
static inline void volume_make(struct volume *vol, uint8_t channels)
{
uint8_t i;
for (i = 0; i < channels; i++)
vol->values[i] = 1.0f;
vol->channels = channels;
}
int volume_compare(struct volume *vol, struct volume *other);
int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bool monitor);
#endif