mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
tools: use safer spa_pod_parser for control events
This commit is contained in:
parent
a3da53f66e
commit
5743849b50
3 changed files with 32 additions and 26 deletions
|
|
@ -665,7 +665,7 @@ static const char *controller_name(uint8_t ctrl)
|
|||
return controller_names[ctrl];
|
||||
}
|
||||
|
||||
static void dump_mem(FILE *out, const char *label, uint8_t *data, uint32_t size)
|
||||
static void dump_mem(FILE *out, const char *label, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
fprintf(out, "%s: ", label);
|
||||
while (size--)
|
||||
|
|
|
|||
|
|
@ -1174,28 +1174,31 @@ static int midi_play(struct data *d, void *src, unsigned int n_frames, bool *nul
|
|||
|
||||
static int midi_record(struct data *d, void *src, unsigned int n_frames, bool *null_frame)
|
||||
{
|
||||
struct spa_pod *pod;
|
||||
struct spa_pod_control *c;
|
||||
uint32_t frame;
|
||||
struct spa_pod_parser parser;
|
||||
struct spa_pod_frame frame;
|
||||
struct spa_pod_sequence seq;
|
||||
const void *seq_body, *c_body;
|
||||
struct spa_pod_control c;
|
||||
uint32_t offset;
|
||||
|
||||
frame = d->clock_time;
|
||||
offset = d->clock_time;
|
||||
d->clock_time += d->position->clock.duration;
|
||||
|
||||
if ((pod = spa_pod_from_data(src, n_frames, 0, n_frames)) == NULL)
|
||||
return 0;
|
||||
if (!spa_pod_is_sequence(pod))
|
||||
spa_pod_parser_init_from_data(&parser, src, n_frames, 0, n_frames);
|
||||
|
||||
if (spa_pod_parser_push_sequence_body(&parser, &frame, &seq, &seq_body) < 0)
|
||||
return 0;
|
||||
|
||||
SPA_POD_SEQUENCE_FOREACH((struct spa_pod_sequence*)pod, c) {
|
||||
while (spa_pod_parser_get_control_body(&parser, &c, &c_body) >= 0) {
|
||||
struct midi_event ev;
|
||||
|
||||
if (c->type != SPA_CONTROL_UMP)
|
||||
if (c.type != SPA_CONTROL_UMP)
|
||||
continue;
|
||||
|
||||
ev.track = 0;
|
||||
ev.sec = (frame + c->offset) / (float) d->position->clock.rate.denom;
|
||||
ev.data = SPA_POD_BODY(&c->value),
|
||||
ev.size = SPA_POD_BODY_SIZE(&c->value);
|
||||
ev.sec = (offset + c.offset) / (float) d->position->clock.rate.denom;
|
||||
ev.data = (uint8_t*)c_body;
|
||||
ev.size = c.value.size;
|
||||
ev.type = MIDI_EVENT_TYPE_UMP;
|
||||
|
||||
if (d->verbose)
|
||||
|
|
|
|||
|
|
@ -62,11 +62,14 @@ static void on_process(void *_data, struct spa_io_position *position)
|
|||
struct pw_buffer *b;
|
||||
struct spa_buffer *buf;
|
||||
struct spa_data *d;
|
||||
struct spa_pod *pod;
|
||||
struct spa_pod_control *c;
|
||||
uint64_t frame;
|
||||
struct spa_pod_parser parser;
|
||||
struct spa_pod_frame frame;
|
||||
struct spa_pod_sequence seq;
|
||||
const void *seq_body, *c_body;
|
||||
struct spa_pod_control c;
|
||||
uint64_t offset;
|
||||
|
||||
frame = data->clock_time;
|
||||
offset = data->clock_time;
|
||||
data->clock_time += position->clock.duration;
|
||||
|
||||
b = pw_filter_dequeue_buffer(data->in_port);
|
||||
|
|
@ -79,24 +82,24 @@ static void on_process(void *_data, struct spa_io_position *position)
|
|||
if (d->data == NULL)
|
||||
goto done;
|
||||
|
||||
if ((pod = spa_pod_from_data(d->data, d->maxsize, d->chunk->offset, d->chunk->size)) == NULL)
|
||||
goto done;
|
||||
if (!spa_pod_is_sequence(pod))
|
||||
spa_pod_parser_init_from_data(&parser, d->data, d->maxsize, d->chunk->offset, d->chunk->size);
|
||||
|
||||
if (spa_pod_parser_push_sequence_body(&parser, &frame, &seq, &seq_body) < 0)
|
||||
goto done;
|
||||
|
||||
SPA_POD_SEQUENCE_FOREACH((struct spa_pod_sequence*)pod, c) {
|
||||
while (spa_pod_parser_get_control_body(&parser, &c, &c_body) >= 0) {
|
||||
struct midi_event ev;
|
||||
|
||||
if (c->type != SPA_CONTROL_UMP)
|
||||
if (c.type != SPA_CONTROL_UMP)
|
||||
continue;
|
||||
|
||||
ev.track = 0;
|
||||
ev.sec = (frame + c->offset) / (float) position->clock.rate.denom;
|
||||
ev.data = SPA_POD_BODY(&c->value),
|
||||
ev.size = SPA_POD_BODY_SIZE(&c->value);
|
||||
ev.sec = (offset + c.offset) / (float) position->clock.rate.denom;
|
||||
ev.data = (uint8_t*)c_body;
|
||||
ev.size = c.value.size;
|
||||
ev.type = MIDI_EVENT_TYPE_UMP;
|
||||
|
||||
fprintf(stdout, "%4d: ", c->offset);
|
||||
fprintf(stdout, "%4d: ", c.offset);
|
||||
midi_file_dump_event(stdout, &ev);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue