mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-13 13:30:05 -05:00
audioconvert: improve tag and latency handling
Don't just forward the tag and latency events to the follower but let the audioconvert aggregate and emit the updated tag/latency event that is then configured on the follower. When using the DSP mode of the audioconvert, this results in an accumulated latency/tag from all the DSP ports instead of just the last DSP port param update. Put properties with media. prefix in tags in pw-cat.
This commit is contained in:
parent
c5f188784d
commit
ebeae802ad
5 changed files with 246 additions and 131 deletions
|
|
@ -1549,6 +1549,7 @@ int pw_impl_port_recalc_latency(struct pw_impl_port *port)
|
|||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
bool changed;
|
||||
int count = 0;
|
||||
|
||||
if (port->destroying)
|
||||
return 0;
|
||||
|
|
@ -1571,6 +1572,7 @@ int pw_impl_port_recalc_latency(struct pw_impl_port *port)
|
|||
latency.min_quantum, latency.max_quantum,
|
||||
latency.min_rate, latency.max_rate,
|
||||
latency.min_ns, latency.max_ns);
|
||||
count++;
|
||||
}
|
||||
} else {
|
||||
spa_list_for_each(l, &port->links, input_link) {
|
||||
|
|
@ -1586,13 +1588,16 @@ int pw_impl_port_recalc_latency(struct pw_impl_port *port)
|
|||
latency.min_quantum, latency.max_quantum,
|
||||
latency.min_rate, latency.max_rate,
|
||||
latency.min_ns, latency.max_ns);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
spa_latency_info_combine_finish(&latency);
|
||||
|
||||
current = &port->latency[latency.direction];
|
||||
|
||||
changed = spa_latency_info_compare(current, &latency) != 0;
|
||||
current = port->have_latency ? &port->latency[latency.direction] : NULL;
|
||||
if (current == NULL)
|
||||
changed = count > 0;
|
||||
else
|
||||
changed = spa_latency_info_compare(current, &latency) != 0;
|
||||
|
||||
pw_log_info("port %d: %s %s latency %f-%f %d-%d %"PRIu64"-%"PRIu64,
|
||||
port->info.id, changed ? "set" : "keep",
|
||||
|
|
@ -1604,13 +1609,14 @@ int pw_impl_port_recalc_latency(struct pw_impl_port *port)
|
|||
if (!changed)
|
||||
return 0;
|
||||
|
||||
*current = latency;
|
||||
port->latency[latency.direction] = latency;
|
||||
port->have_latency = count > 0;
|
||||
|
||||
if (!port->have_latency_param)
|
||||
return 0;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
param = spa_latency_build(&b, SPA_PARAM_Latency, &latency);
|
||||
param = port->have_latency ? spa_latency_build(&b, SPA_PARAM_Latency, &latency) : NULL;
|
||||
return pw_impl_port_set_param(port, SPA_PARAM_Latency, 0, param);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -847,6 +847,7 @@ struct pw_impl_port {
|
|||
struct spa_latency_info latency[2]; /**< latencies */
|
||||
unsigned int have_latency_param:1;
|
||||
unsigned int ignore_latency:1;
|
||||
unsigned int have_latency:1;
|
||||
|
||||
unsigned int have_tag_param:1;
|
||||
struct spa_pod *tag[2]; /**< tags */
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <spa/param/audio/layout.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
#include <spa/param/audio/type-info.h>
|
||||
#include <spa/param/tag-utils.h>
|
||||
#include <spa/param/props.h>
|
||||
#include <spa/utils/result.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
|
@ -1569,7 +1570,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
struct data data = { 0, };
|
||||
struct pw_loop *l;
|
||||
const struct spa_pod *params[1];
|
||||
const struct spa_pod *params[2];
|
||||
uint32_t n_params = 0;
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
const char *prog;
|
||||
|
|
@ -1886,7 +1888,7 @@ int main(int argc, char *argv[])
|
|||
ret = av_codec_params_to_audio_info(&data, data.encoded.audio_stream->codecpar, &info);
|
||||
if (ret < 0)
|
||||
goto error_bad_file;
|
||||
params[0] = spa_format_audio_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
params[n_params++] = spa_format_audio_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1902,11 +1904,11 @@ int main(int argc, char *argv[])
|
|||
if (data.channelmap.n_channels)
|
||||
memcpy(info.position, data.channelmap.channels, data.channels * sizeof(int));
|
||||
|
||||
params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
break;
|
||||
}
|
||||
case TYPE_MIDI:
|
||||
params[0] = spa_pod_builder_add_object(&b,
|
||||
params[n_params++] = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_application),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_control));
|
||||
|
|
@ -1928,10 +1930,25 @@ int main(int argc, char *argv[])
|
|||
memcpy(info.position, i->info.position,
|
||||
info.channels * sizeof(uint32_t));
|
||||
}
|
||||
params[0] = spa_format_audio_dsd_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
params[n_params++] = spa_format_audio_dsd_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (data.mode == mode_playback) {
|
||||
struct spa_dict_item items[64];
|
||||
uint32_t i, n_items = 0;
|
||||
|
||||
for (i = 0; i < data.props->dict.n_items; i++) {
|
||||
if (spa_strstartswith(data.props->dict.items[i].key, "media."))
|
||||
items[n_items++] = data.props->dict.items[i];
|
||||
}
|
||||
if (n_items > 0) {
|
||||
struct spa_pod_frame f;
|
||||
spa_tag_build_start(&b, &f, SPA_PARAM_Tag, SPA_DIRECTION_OUTPUT);
|
||||
spa_tag_build_add_dict(&b, &SPA_DICT_INIT(items, n_items));
|
||||
params[n_params++] = spa_tag_build_end(&b, &f);
|
||||
}
|
||||
}
|
||||
|
||||
data.stream = pw_stream_new(data.core, prog, data.props);
|
||||
data.props = NULL;
|
||||
|
|
@ -1955,7 +1972,7 @@ int main(int argc, char *argv[])
|
|||
PW_ID_ANY,
|
||||
flags |
|
||||
PW_STREAM_FLAG_MAP_BUFFERS,
|
||||
params, 1);
|
||||
params, n_params);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "error: failed connect: %s\n", spa_strerror(ret));
|
||||
goto error_connect_fail;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue