mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-11 04:27:56 -05:00
modules: use safer pod parsing for control sequence
This commit is contained in:
parent
28510f3117
commit
8495bffee5
5 changed files with 73 additions and 80 deletions
|
|
@ -56,7 +56,8 @@ static void rtp_midi_process_playback(void *data)
|
|||
goto done;
|
||||
|
||||
/* the ringbuffer contains series of sequences, one for each
|
||||
* received packet */
|
||||
* received packet. This is not in shared mem so we can safely use
|
||||
* the iterators here. */
|
||||
SPA_POD_SEQUENCE_FOREACH((struct spa_pod_sequence*)pod, c) {
|
||||
/* try to render with given delay */
|
||||
uint32_t target = c->offset + impl->target_buffer;
|
||||
|
|
@ -406,9 +407,10 @@ static int write_event(uint8_t *p, uint32_t buffer_size, uint32_t value, void *e
|
|||
}
|
||||
|
||||
static void rtp_midi_flush_packets(struct impl *impl,
|
||||
struct spa_pod_sequence *sequence, uint32_t timestamp, uint32_t rate)
|
||||
struct spa_pod_parser *parser, uint32_t timestamp, uint32_t rate)
|
||||
{
|
||||
struct spa_pod_control *c;
|
||||
struct spa_pod_control c;
|
||||
const void *c_body;
|
||||
struct rtp_header header;
|
||||
struct rtp_midi_header midi_header;
|
||||
struct iovec iov[3];
|
||||
|
|
@ -431,20 +433,19 @@ static void rtp_midi_flush_packets(struct impl *impl,
|
|||
prev_offset = len = base = 0;
|
||||
max_size = impl->payload_size - sizeof(midi_header);
|
||||
|
||||
SPA_POD_SEQUENCE_FOREACH(sequence, c) {
|
||||
while (spa_pod_parser_get_control_body(parser, &c, &c_body) >= 0) {
|
||||
uint32_t delta, offset;
|
||||
uint8_t event[16];
|
||||
size_t size;
|
||||
|
||||
if (c->type != SPA_CONTROL_UMP)
|
||||
if (c.type != SPA_CONTROL_UMP)
|
||||
continue;
|
||||
|
||||
size = spa_ump_to_midi(SPA_POD_BODY(&c->value),
|
||||
SPA_POD_BODY_SIZE(&c->value), event, sizeof(event));
|
||||
size = spa_ump_to_midi(c_body, c.value.size, event, sizeof(event));
|
||||
if (size <= 0)
|
||||
continue;
|
||||
|
||||
offset = c->offset * impl->rate / rate;
|
||||
offset = c.offset * impl->rate / rate;
|
||||
|
||||
if (len > 0 && (len + size > max_size ||
|
||||
offset - base > impl->psamples)) {
|
||||
|
|
@ -513,9 +514,11 @@ static void rtp_midi_process_capture(void *data)
|
|||
struct impl *impl = data;
|
||||
struct pw_buffer *buf;
|
||||
struct spa_data *d;
|
||||
uint32_t offs, size, timestamp, rate;
|
||||
struct spa_pod *pod;
|
||||
void *ptr;
|
||||
uint32_t timestamp, rate;
|
||||
struct spa_pod_parser parser;
|
||||
struct spa_pod_frame frame;
|
||||
struct spa_pod_sequence seq;
|
||||
const void *seq_body;
|
||||
|
||||
if ((buf = pw_stream_dequeue_buffer(impl->stream)) == NULL) {
|
||||
pw_log_info("Out of stream buffers: %m");
|
||||
|
|
@ -523,9 +526,6 @@ static void rtp_midi_process_capture(void *data)
|
|||
}
|
||||
d = buf->buffer->datas;
|
||||
|
||||
offs = SPA_MIN(d[0].chunk->offset, d[0].maxsize);
|
||||
size = SPA_MIN(d[0].chunk->size, d[0].maxsize - offs);
|
||||
|
||||
if (SPA_LIKELY(impl->io_position)) {
|
||||
rate = impl->io_position->clock.rate.denom;
|
||||
timestamp = impl->io_position->clock.position * impl->rate / rate;
|
||||
|
|
@ -534,11 +534,10 @@ static void rtp_midi_process_capture(void *data)
|
|||
timestamp = 0;
|
||||
}
|
||||
|
||||
ptr = SPA_PTROFF(d[0].data, offs, void);
|
||||
|
||||
if ((pod = spa_pod_from_data(ptr, size, 0, size)) == NULL)
|
||||
goto done;
|
||||
if (!spa_pod_is_sequence(pod))
|
||||
spa_pod_parser_init_from_data(&parser, d[0].data, d[0].maxsize,
|
||||
d[0].chunk->offset, d[0].chunk->size);
|
||||
if (spa_pod_parser_push_sequence_body(&parser, &frame, &seq, &seq_body) < 0)
|
||||
goto done;
|
||||
|
||||
if (!impl->have_sync) {
|
||||
|
|
@ -547,7 +546,7 @@ static void rtp_midi_process_capture(void *data)
|
|||
impl->have_sync = true;
|
||||
}
|
||||
|
||||
rtp_midi_flush_packets(impl, (struct spa_pod_sequence*)pod, timestamp, rate);
|
||||
rtp_midi_flush_packets(impl, &parser, timestamp, rate);
|
||||
|
||||
done:
|
||||
pw_stream_queue_buffer(impl->stream, buf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue