2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2020 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2021-04-15 15:53:05 -04:00
|
|
|
|
|
|
|
|
#ifndef PULSE_SERVER_FORMAT_H
|
|
|
|
|
#define PULSE_SERVER_FORMAT_H
|
|
|
|
|
|
2021-06-18 21:49:24 +02:00
|
|
|
#include <spa/utils/defs.h>
|
|
|
|
|
#include <pipewire/properties.h>
|
|
|
|
|
|
|
|
|
|
struct spa_pod;
|
|
|
|
|
struct spa_pod_builder;
|
|
|
|
|
|
2025-01-08 17:23:15 +01:00
|
|
|
#define RATE_MAX (48000u*16u)
|
2021-04-15 15:53:05 -04:00
|
|
|
#define CHANNELS_MAX (64u)
|
|
|
|
|
|
|
|
|
|
enum sample_format {
|
|
|
|
|
SAMPLE_U8,
|
|
|
|
|
SAMPLE_ALAW,
|
|
|
|
|
SAMPLE_ULAW,
|
|
|
|
|
SAMPLE_S16LE,
|
|
|
|
|
SAMPLE_S16BE,
|
|
|
|
|
SAMPLE_FLOAT32LE,
|
|
|
|
|
SAMPLE_FLOAT32BE,
|
|
|
|
|
SAMPLE_S32LE,
|
|
|
|
|
SAMPLE_S32BE,
|
|
|
|
|
SAMPLE_S24LE,
|
|
|
|
|
SAMPLE_S24BE,
|
|
|
|
|
SAMPLE_S24_32LE,
|
|
|
|
|
SAMPLE_S24_32BE,
|
|
|
|
|
SAMPLE_MAX,
|
|
|
|
|
SAMPLE_INVALID = -1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
|
#define SAMPLE_S16NE SAMPLE_S16BE
|
|
|
|
|
#define SAMPLE_FLOAT32NE SAMPLE_FLOAT32BE
|
|
|
|
|
#define SAMPLE_S32NE SAMPLE_S32BE
|
|
|
|
|
#define SAMPLE_S24NE SAMPLE_S24BE
|
|
|
|
|
#define SAMPLE_S24_32NE SAMPLE_S24_32BE
|
2023-03-01 13:42:02 +01:00
|
|
|
#define SAMPLE_S16RE SAMPLE_S16LE
|
|
|
|
|
#define SAMPLE_FLOAT32RE SAMPLE_FLOAT32LE
|
|
|
|
|
#define SAMPLE_S32RE SAMPLE_S32LE
|
|
|
|
|
#define SAMPLE_S24RE SAMPLE_S24LE
|
|
|
|
|
#define SAMPLE_S24_32RE SAMPLE_S24_32LE
|
2021-04-15 15:53:05 -04:00
|
|
|
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
|
#define SAMPLE_S16NE SAMPLE_S16LE
|
|
|
|
|
#define SAMPLE_FLOAT32NE SAMPLE_FLOAT32LE
|
|
|
|
|
#define SAMPLE_S32NE SAMPLE_S32LE
|
|
|
|
|
#define SAMPLE_S24NE SAMPLE_S24LE
|
|
|
|
|
#define SAMPLE_S24_32NE SAMPLE_S24_32LE
|
2023-03-01 13:42:02 +01:00
|
|
|
#define SAMPLE_S16RE SAMPLE_S16BE
|
|
|
|
|
#define SAMPLE_FLOAT32RE SAMPLE_FLOAT32BE
|
|
|
|
|
#define SAMPLE_S32RE SAMPLE_S32BE
|
|
|
|
|
#define SAMPLE_S24RE SAMPLE_S24BE
|
|
|
|
|
#define SAMPLE_S24_32RE SAMPLE_S24_32BE
|
2021-04-15 15:53:05 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct format {
|
|
|
|
|
uint32_t pa;
|
|
|
|
|
uint32_t id;
|
|
|
|
|
const char *name;
|
|
|
|
|
uint32_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sample_spec {
|
|
|
|
|
uint32_t format;
|
|
|
|
|
uint32_t rate;
|
|
|
|
|
uint8_t channels;
|
|
|
|
|
};
|
2021-06-18 21:49:24 +02:00
|
|
|
#define SAMPLE_SPEC_INIT \
|
|
|
|
|
(struct sample_spec) { \
|
|
|
|
|
.format = SPA_AUDIO_FORMAT_UNKNOWN, \
|
|
|
|
|
.rate = 0, \
|
|
|
|
|
.channels = 0, \
|
|
|
|
|
}
|
2021-04-15 15:53:05 -04:00
|
|
|
|
|
|
|
|
enum channel_position {
|
|
|
|
|
CHANNEL_POSITION_INVALID = -1,
|
|
|
|
|
CHANNEL_POSITION_MONO = 0,
|
|
|
|
|
CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
|
CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
|
CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_REAR_CENTER,
|
|
|
|
|
CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
|
CHANNEL_POSITION_REAR_RIGHT,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_LFE,
|
|
|
|
|
CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
|
|
|
|
|
CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
|
CHANNEL_POSITION_SIDE_RIGHT,
|
|
|
|
|
CHANNEL_POSITION_AUX0,
|
|
|
|
|
CHANNEL_POSITION_AUX1,
|
|
|
|
|
CHANNEL_POSITION_AUX2,
|
|
|
|
|
CHANNEL_POSITION_AUX3,
|
|
|
|
|
CHANNEL_POSITION_AUX4,
|
|
|
|
|
CHANNEL_POSITION_AUX5,
|
|
|
|
|
CHANNEL_POSITION_AUX6,
|
|
|
|
|
CHANNEL_POSITION_AUX7,
|
|
|
|
|
CHANNEL_POSITION_AUX8,
|
|
|
|
|
CHANNEL_POSITION_AUX9,
|
|
|
|
|
CHANNEL_POSITION_AUX10,
|
|
|
|
|
CHANNEL_POSITION_AUX11,
|
|
|
|
|
CHANNEL_POSITION_AUX12,
|
|
|
|
|
CHANNEL_POSITION_AUX13,
|
|
|
|
|
CHANNEL_POSITION_AUX14,
|
|
|
|
|
CHANNEL_POSITION_AUX15,
|
|
|
|
|
CHANNEL_POSITION_AUX16,
|
|
|
|
|
CHANNEL_POSITION_AUX17,
|
|
|
|
|
CHANNEL_POSITION_AUX18,
|
|
|
|
|
CHANNEL_POSITION_AUX19,
|
|
|
|
|
CHANNEL_POSITION_AUX20,
|
|
|
|
|
CHANNEL_POSITION_AUX21,
|
|
|
|
|
CHANNEL_POSITION_AUX22,
|
|
|
|
|
CHANNEL_POSITION_AUX23,
|
|
|
|
|
CHANNEL_POSITION_AUX24,
|
|
|
|
|
CHANNEL_POSITION_AUX25,
|
|
|
|
|
CHANNEL_POSITION_AUX26,
|
|
|
|
|
CHANNEL_POSITION_AUX27,
|
|
|
|
|
CHANNEL_POSITION_AUX28,
|
|
|
|
|
CHANNEL_POSITION_AUX29,
|
|
|
|
|
CHANNEL_POSITION_AUX30,
|
|
|
|
|
CHANNEL_POSITION_AUX31,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_TOP_CENTER,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_TOP_FRONT_LEFT,
|
|
|
|
|
CHANNEL_POSITION_TOP_FRONT_RIGHT,
|
|
|
|
|
CHANNEL_POSITION_TOP_FRONT_CENTER,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_TOP_REAR_LEFT,
|
|
|
|
|
CHANNEL_POSITION_TOP_REAR_RIGHT,
|
|
|
|
|
CHANNEL_POSITION_TOP_REAR_CENTER,
|
|
|
|
|
|
|
|
|
|
CHANNEL_POSITION_MAX
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct channel {
|
|
|
|
|
uint32_t channel;
|
|
|
|
|
const char *name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct channel_map {
|
|
|
|
|
uint8_t channels;
|
|
|
|
|
uint32_t map[CHANNELS_MAX];
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-18 21:49:24 +02:00
|
|
|
#define CHANNEL_MAP_INIT \
|
|
|
|
|
(struct channel_map) { \
|
|
|
|
|
.channels = 0, \
|
|
|
|
|
}
|
2021-04-15 15:53:05 -04:00
|
|
|
|
|
|
|
|
enum encoding {
|
|
|
|
|
ENCODING_ANY,
|
|
|
|
|
ENCODING_PCM,
|
|
|
|
|
ENCODING_AC3_IEC61937,
|
|
|
|
|
ENCODING_EAC3_IEC61937,
|
|
|
|
|
ENCODING_MPEG_IEC61937,
|
|
|
|
|
ENCODING_DTS_IEC61937,
|
|
|
|
|
ENCODING_MPEG2_AAC_IEC61937,
|
|
|
|
|
ENCODING_TRUEHD_IEC61937,
|
|
|
|
|
ENCODING_DTSHD_IEC61937,
|
|
|
|
|
ENCODING_MAX,
|
|
|
|
|
ENCODING_INVALID = -1,
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-18 21:49:24 +02:00
|
|
|
struct format_info {
|
|
|
|
|
enum encoding encoding;
|
|
|
|
|
struct pw_properties *props;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-15 15:53:05 -04:00
|
|
|
uint32_t format_pa2id(enum sample_format format);
|
|
|
|
|
const char *format_id2name(uint32_t format);
|
|
|
|
|
uint32_t format_name2id(const char *name);
|
|
|
|
|
uint32_t format_paname2id(const char *name, size_t size);
|
|
|
|
|
enum sample_format format_id2pa(uint32_t id);
|
|
|
|
|
const char *format_id2paname(uint32_t id);
|
2021-06-18 21:49:24 +02:00
|
|
|
const char *format_encoding2name(enum encoding enc);
|
2021-09-01 13:20:37 +02:00
|
|
|
uint32_t format_encoding2id(enum encoding enc);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
2021-04-15 15:53:05 -04:00
|
|
|
uint32_t sample_spec_frame_size(const struct sample_spec *ss);
|
2025-01-16 16:16:39 +01:00
|
|
|
void sample_spec_silence(const struct sample_spec *ss, void *data, size_t size);
|
2021-04-15 15:53:05 -04:00
|
|
|
bool sample_spec_valid(const struct sample_spec *ss);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
2023-02-23 12:41:37 +01:00
|
|
|
void sample_spec_fix(struct sample_spec *ss, struct channel_map *map,
|
|
|
|
|
const struct sample_spec *fix_ss, const struct channel_map *fix_map,
|
|
|
|
|
struct spa_dict *props);
|
2023-02-23 09:22:56 +01:00
|
|
|
|
2021-04-15 15:53:05 -04:00
|
|
|
uint32_t channel_pa2id(enum channel_position channel);
|
2025-10-22 13:04:53 +02:00
|
|
|
const char *channel_id2name(uint32_t channel, char *buf, size_t size);
|
2021-04-15 15:53:05 -04:00
|
|
|
uint32_t channel_name2id(const char *name);
|
|
|
|
|
enum channel_position channel_id2pa(uint32_t id, uint32_t *aux);
|
|
|
|
|
const char *channel_id2paname(uint32_t id, uint32_t *aux);
|
|
|
|
|
uint32_t channel_paname2id(const char *name, size_t size);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
2025-10-21 13:06:25 +02:00
|
|
|
void channel_map_to_positions(const struct channel_map *map, uint32_t *pos, uint32_t max_pos);
|
2021-04-15 15:53:05 -04:00
|
|
|
void channel_map_parse(const char *str, struct channel_map *map);
|
|
|
|
|
bool channel_map_valid(const struct channel_map *map);
|
2023-02-23 12:39:36 +01:00
|
|
|
void channel_map_parse_position(const char *str, struct channel_map *map);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
2022-02-21 16:53:03 +01:00
|
|
|
int format_parse_param(const struct spa_pod *param, bool collect, struct sample_spec *ss,
|
2021-08-25 17:33:22 +02:00
|
|
|
struct channel_map *map, const struct sample_spec *def_ss,
|
|
|
|
|
const struct channel_map *def_map);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
|
|
|
|
const struct spa_pod *format_build_param(struct spa_pod_builder *b, uint32_t id,
|
2021-08-18 16:58:22 +02:00
|
|
|
const struct sample_spec *spec, const struct channel_map *map);
|
2021-08-12 17:22:57 +02:00
|
|
|
|
|
|
|
|
int format_info_from_spec(struct format_info *info, const struct sample_spec *ss,
|
|
|
|
|
const struct channel_map *map);
|
|
|
|
|
int format_info_from_param(struct format_info *info, struct spa_pod *param, uint32_t index);
|
|
|
|
|
|
2021-06-18 21:49:24 +02:00
|
|
|
const struct spa_pod *format_info_build_param(struct spa_pod_builder *b, uint32_t id,
|
2021-08-18 16:58:22 +02:00
|
|
|
const struct format_info *info, uint32_t *rate);
|
|
|
|
|
|
|
|
|
|
int format_info_to_spec(const struct format_info *info, struct sample_spec *ss,
|
|
|
|
|
struct channel_map *map);
|
2021-06-18 21:49:24 +02:00
|
|
|
|
|
|
|
|
static inline void format_info_clear(struct format_info *info)
|
|
|
|
|
{
|
|
|
|
|
pw_properties_free(info->props);
|
|
|
|
|
spa_zero(*info);
|
|
|
|
|
}
|
2021-04-15 15:53:05 -04:00
|
|
|
|
|
|
|
|
#endif
|