update to new types

This commit is contained in:
Wim Taymans 2018-08-24 11:00:33 +02:00
parent ffa3b03982
commit be2dee53bc
4 changed files with 42 additions and 67 deletions

View file

@ -100,7 +100,7 @@ static int set_mask(pa_context *c, struct global *g)
{ {
const char *str; const char *str;
if (g->type == c->t->node) { if (g->type == PW_ID_INTERFACE_Node) {
if (g->props == NULL) if (g->props == NULL)
return 0; return 0;
if ((str = pw_properties_get(g->props, "media.class")) == NULL) if ((str = pw_properties_get(g->props, "media.class")) == NULL)
@ -137,18 +137,18 @@ static int set_mask(pa_context *c, struct global *g)
g->event = PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT; g->event = PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT;
} }
} }
else if (g->type == c->t->module) { else if (g->type == PW_ID_INTERFACE_Module) {
g->mask = PA_SUBSCRIPTION_MASK_MODULE; g->mask = PA_SUBSCRIPTION_MASK_MODULE;
g->event = PA_SUBSCRIPTION_EVENT_MODULE; g->event = PA_SUBSCRIPTION_EVENT_MODULE;
} }
else if (g->type == c->t->client) { else if (g->type == PW_ID_INTERFACE_Client) {
g->mask = PA_SUBSCRIPTION_MASK_CLIENT; g->mask = PA_SUBSCRIPTION_MASK_CLIENT;
g->event = PA_SUBSCRIPTION_EVENT_CLIENT; g->event = PA_SUBSCRIPTION_EVENT_CLIENT;
} }
else if (g->type == c->t->port) { else if (g->type == PW_ID_INTERFACE_Port) {
pw_log_debug("found port %d", g->id); pw_log_debug("found port %d", g->id);
} }
else if (g->type == c->t->link) { else if (g->type == PW_ID_INTERFACE_Link) {
if ((str = pw_properties_get(g->props, "link.output")) == NULL) if ((str = pw_properties_get(g->props, "link.output")) == NULL)
return 0; return 0;
g->link_info.src = pa_context_find_global(c, pw_properties_parse_int(str)); g->link_info.src = pa_context_find_global(c, pw_properties_parse_int(str));
@ -262,7 +262,7 @@ static void remote_state_changed(void *data, enum pw_remote_state old,
c->core_proxy = pw_remote_get_core_proxy(c->remote); c->core_proxy = pw_remote_get_core_proxy(c->remote);
c->registry_proxy = pw_core_proxy_get_registry(c->core_proxy, c->registry_proxy = pw_core_proxy_get_registry(c->core_proxy,
c->t->registry, PW_ID_INTERFACE_Registry,
PW_VERSION_REGISTRY, 0); PW_VERSION_REGISTRY, 0);
pw_registry_proxy_add_listener(c->registry_proxy, pw_registry_proxy_add_listener(c->registry_proxy,
&c->registry_listener, &c->registry_listener,
@ -329,7 +329,6 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
c = pw_remote_get_user_data(r); c = pw_remote_get_user_data(r);
c->loop = loop; c->loop = loop;
c->core = core; c->core = core;
c->t = pw_core_get_type(core);
c->remote = r; c->remote = r;
pw_remote_add_listener(r, &c->remote_listener, &remote_events, c); pw_remote_add_listener(r, &c->remote_listener, &remote_events, c);

View file

@ -25,7 +25,6 @@
#include <spa/utils/defs.h> #include <spa/utils/defs.h>
#include <spa/utils/hook.h> #include <spa/utils/hook.h>
#include <spa/utils/ringbuffer.h> #include <spa/utils/ringbuffer.h>
#include <spa/param/format-utils.h>
#include <spa/param/audio/format-utils.h> #include <spa/param/audio/format-utils.h>
#include <pulse/stream.h> #include <pulse/stream.h>
@ -228,7 +227,6 @@ struct pa_context {
struct pw_loop *loop; struct pw_loop *loop;
struct pw_core *core; struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote; struct pw_remote *remote;
struct spa_hook remote_listener; struct spa_hook remote_listener;
@ -264,21 +262,6 @@ struct pa_context {
struct global *pa_context_find_global(pa_context *c, uint32_t id); struct global *pa_context_find_global(pa_context *c, uint32_t id);
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
}
#define MAX_BUFFERS 64 #define MAX_BUFFERS 64
#define MASK_BUFFERS (MAX_BUFFERS-1) #define MASK_BUFFERS (MAX_BUFFERS-1)
@ -289,8 +272,6 @@ struct pa_stream {
struct pw_stream *stream; struct pw_stream *stream;
struct spa_hook stream_listener; struct spa_hook stream_listener;
struct type type;
pa_context *context; pa_context *context;
pa_proplist *proplist; pa_proplist *proplist;

View file

@ -67,22 +67,21 @@ static int ensure_global(pa_context *c, struct global *g)
uint32_t client_version; uint32_t client_version;
const void *events; const void *events;
pw_destroy_t destroy; pw_destroy_t destroy;
struct pw_type *t = c->t;
if (g->proxy != NULL) if (g->proxy != NULL)
return 0; return 0;
if (g->type == t->node) { if (g->type == PW_ID_INTERFACE_Node) {
events = &node_events; events = &node_events;
client_version = PW_VERSION_NODE; client_version = PW_VERSION_NODE;
destroy = (pw_destroy_t) pw_node_info_free; destroy = (pw_destroy_t) pw_node_info_free;
} }
else if (g->type == t->module) { else if (g->type == PW_ID_INTERFACE_Module) {
events = &module_events; events = &module_events;
client_version = PW_VERSION_MODULE; client_version = PW_VERSION_MODULE;
destroy = (pw_destroy_t) pw_module_info_free; destroy = (pw_destroy_t) pw_module_info_free;
} }
else if (g->type == t->client) { else if (g->type == PW_ID_INTERFACE_Client) {
events = &client_events; events = &client_events;
client_version = PW_VERSION_CLIENT; client_version = PW_VERSION_CLIENT;
destroy = (pw_destroy_t) pw_client_info_free; destroy = (pw_destroy_t) pw_client_info_free;

View file

@ -35,33 +35,33 @@
#define MAX_SIZE (4*1024*1024) #define MAX_SIZE (4*1024*1024)
static const uint32_t audio_formats[] = { static const uint32_t audio_formats[] = {
[PA_SAMPLE_U8] = offsetof(struct spa_type_audio_format, U8), [PA_SAMPLE_U8] = SPA_AUDIO_FORMAT_U8,
[PA_SAMPLE_ALAW] = offsetof(struct spa_type_audio_format, UNKNOWN), [PA_SAMPLE_ALAW] = SPA_AUDIO_FORMAT_UNKNOWN,
[PA_SAMPLE_ULAW] = offsetof(struct spa_type_audio_format, UNKNOWN), [PA_SAMPLE_ULAW] = SPA_AUDIO_FORMAT_UNKNOWN,
[PA_SAMPLE_S16NE] = offsetof(struct spa_type_audio_format, S16), [PA_SAMPLE_S16NE] = SPA_AUDIO_FORMAT_S16,
[PA_SAMPLE_S16RE] = offsetof(struct spa_type_audio_format, S16_OE), [PA_SAMPLE_S16RE] = SPA_AUDIO_FORMAT_S16_OE,
[PA_SAMPLE_FLOAT32NE] = offsetof(struct spa_type_audio_format, F32), [PA_SAMPLE_FLOAT32NE] = SPA_AUDIO_FORMAT_F32,
[PA_SAMPLE_FLOAT32RE] = offsetof(struct spa_type_audio_format, F32_OE), [PA_SAMPLE_FLOAT32RE] = SPA_AUDIO_FORMAT_F32_OE,
[PA_SAMPLE_S32NE] = offsetof(struct spa_type_audio_format, S32), [PA_SAMPLE_S32NE] = SPA_AUDIO_FORMAT_S32,
[PA_SAMPLE_S32RE] = offsetof(struct spa_type_audio_format, S32_OE), [PA_SAMPLE_S32RE] = SPA_AUDIO_FORMAT_S32_OE,
[PA_SAMPLE_S24NE] = offsetof(struct spa_type_audio_format, S24), [PA_SAMPLE_S24NE] = SPA_AUDIO_FORMAT_S24,
[PA_SAMPLE_S24RE] = offsetof(struct spa_type_audio_format, S24_OE), [PA_SAMPLE_S24RE] = SPA_AUDIO_FORMAT_S24_OE,
[PA_SAMPLE_S24_32NE] = offsetof(struct spa_type_audio_format, S24_32), [PA_SAMPLE_S24_32NE] = SPA_AUDIO_FORMAT_S24_32,
[PA_SAMPLE_S24_32RE] = offsetof(struct spa_type_audio_format, S24_32_OE), [PA_SAMPLE_S24_32RE] = SPA_AUDIO_FORMAT_S24_32_OE,
}; };
static inline uint32_t format_pa2id(pa_stream *s, pa_sample_format_t format) static inline uint32_t format_pa2id(pa_stream *s, pa_sample_format_t format)
{ {
if (format < 0 || format >= SPA_N_ELEMENTS(audio_formats)) if (format < 0 || format >= SPA_N_ELEMENTS(audio_formats))
return s->type.audio_format.UNKNOWN; return SPA_AUDIO_FORMAT_UNKNOWN;
return *SPA_MEMBER(&s->type.audio_format, audio_formats[format], uint32_t); return audio_formats[format];
} }
static inline pa_sample_format_t format_id2pa(pa_stream *s, uint32_t id) static inline pa_sample_format_t format_id2pa(pa_stream *s, uint32_t id)
{ {
int i; int i;
for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) { for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
if (id == *SPA_MEMBER(&s->type.audio_format, audio_formats[i], uint32_t)) if (id == audio_formats[i])
return i; return i;
} }
return PA_SAMPLE_INVALID; return PA_SAMPLE_INVALID;
@ -110,7 +110,7 @@ static struct global *find_linked(pa_stream *s, uint32_t idx)
pa_context *c = s->context; pa_context *c = s->context;
spa_list_for_each(g, &c->globals, link) { spa_list_for_each(g, &c->globals, link) {
if (g->type != c->t->link) if (g->type != PW_ID_INTERFACE_Link)
continue; continue;
pw_log_debug("%d %d %d", idx, pw_log_debug("%d %d %d", idx,
@ -185,7 +185,6 @@ static void stream_state_changed(void *data, enum pw_stream_state old,
static const struct spa_pod *get_buffers_param(pa_stream *s, pa_buffer_attr *attr, struct spa_pod_builder *b) static const struct spa_pod *get_buffers_param(pa_stream *s, pa_buffer_attr *attr, struct spa_pod_builder *b)
{ {
const struct spa_pod *param; const struct spa_pod *param;
struct pw_type *t = pw_core_get_type(s->context->core);
int32_t blocks, buffers, size, maxsize, stride; int32_t blocks, buffers, size, maxsize, stride;
blocks = 1; blocks = 1;
@ -210,14 +209,14 @@ static const struct spa_pod *get_buffers_param(pa_stream *s, pa_buffer_attr *att
size, buffers); size, buffers);
param = spa_pod_builder_object(b, param = spa_pod_builder_object(b,
t->param.idBuffers, t->param_buffers.Buffers, SPA_ID_PARAM_Buffers, SPA_ID_OBJECT_ParamBuffers,
":", t->param_buffers.buffers, "iru", buffers, ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers,
SPA_POD_PROP_MIN_MAX(3, MAX_BUFFERS), SPA_POD_PROP_MIN_MAX(3, MAX_BUFFERS),
":", t->param_buffers.blocks, "i", blocks, ":", SPA_PARAM_BUFFERS_blocks, "i", blocks,
":", t->param_buffers.size, "iru", size * stride, ":", SPA_PARAM_BUFFERS_size, "iru", size * stride,
SPA_POD_PROP_MIN_MAX(size * stride, maxsize * stride), SPA_POD_PROP_MIN_MAX(size * stride, maxsize * stride),
":", t->param_buffers.stride, "i", stride, ":", SPA_PARAM_BUFFERS_stride, "i", stride,
":", t->param_buffers.align, "i", 16); ":", SPA_PARAM_BUFFERS_align, "i", 16);
return param; return param;
} }
@ -288,9 +287,9 @@ static void stream_format_changed(void *data, const struct spa_pod *format)
"I", &info.media_type, "I", &info.media_type,
"I", &info.media_subtype); "I", &info.media_subtype);
if (info.media_type != s->type.media_type.audio || if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != s->type.media_subtype.raw || info.media_subtype != SPA_MEDIA_SUBTYPE_raw ||
spa_format_audio_raw_parse(format, &info.info.raw, &s->type.format_audio) < 0 || spa_format_audio_raw_parse(format, &info.info.raw) < 0 ||
info.info.raw.layout != SPA_AUDIO_LAYOUT_INTERLEAVED) { info.info.raw.layout != SPA_AUDIO_LAYOUT_INTERLEAVED) {
res = -EINVAL; res = -EINVAL;
goto done; goto done;
@ -438,7 +437,6 @@ pa_stream* stream_new(pa_context *c, const char *name,
NULL)); NULL));
s->refcount = 1; s->refcount = 1;
s->context = c; s->context = c;
init_type(&s->type, pw_core_get_type(c->core)->map);
spa_list_init(&s->pending); spa_list_init(&s->pending);
pw_stream_add_listener(s->stream, &s->stream_listener, &stream_events, s); pw_stream_add_listener(s->stream, &s->stream_listener, &stream_events, s);
@ -657,16 +655,14 @@ static const struct spa_pod *get_param(pa_stream *s, pa_sample_spec *ss, pa_chan
struct spa_pod_builder *b) struct spa_pod_builder *b)
{ {
const struct spa_pod *param; const struct spa_pod *param;
struct pw_type *t = pw_core_get_type(s->context->core);
param = spa_pod_builder_object(b, param = spa_pod_builder_object(b,
t->param.idEnumFormat, t->spa_format, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", s->type.media_type.audio, "I", SPA_MEDIA_TYPE_audio,
"I", s->type.media_subtype.raw, "I", SPA_MEDIA_SUBTYPE_raw,
":", s->type.format_audio.format, "I", format_pa2id(s, ss->format), ":", SPA_FORMAT_AUDIO_format, "I", format_pa2id(s, ss->format),
":", s->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
":", s->type.format_audio.channels, "i", ss->channels, ":", SPA_FORMAT_AUDIO_channels, "i", ss->channels,
":", s->type.format_audio.rate, "i", ss->rate); ":", SPA_FORMAT_AUDIO_rate, "i", ss->rate);
return param; return param;
} }