mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pw-cat: handle midi EOF better
Return 0 when there are no more events, 1 when we have an event and < 0 for errors. Use this to correctly push the last set of events on EOS and then return 0 and stop without an error.
This commit is contained in:
parent
d8bac82e72
commit
8b874a9514
2 changed files with 9 additions and 4 deletions
|
|
@ -124,7 +124,7 @@ static int peek_event(struct midi_file *mf, struct midi_track *tr, struct midi_e
|
|||
int res;
|
||||
|
||||
if (tr_avail(tr) == 0)
|
||||
return -EIO;
|
||||
return 0;
|
||||
|
||||
save = tr->p;
|
||||
status = *tr->p;
|
||||
|
|
@ -182,7 +182,7 @@ static int peek_event(struct midi_file *mf, struct midi_track *tr, struct midi_e
|
|||
tr->p = save;
|
||||
|
||||
event->size = size;
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int midi_file_add_track(struct midi_file *mf, struct midi_track *track)
|
||||
|
|
@ -213,7 +213,7 @@ int midi_file_peek_event(struct midi_file *mf, struct midi_event *event)
|
|||
found = tr;
|
||||
}
|
||||
if (found == NULL)
|
||||
return -EIO;
|
||||
return 0;
|
||||
|
||||
return peek_event(mf, found, event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -962,6 +962,7 @@ static int midi_play(struct data *d, void *src, unsigned int n_frames)
|
|||
struct spa_pod_builder b;
|
||||
struct spa_pod_frame f;
|
||||
uint32_t first_frame, last_frame;
|
||||
bool have_data = false;
|
||||
|
||||
spa_zero(b);
|
||||
spa_pod_builder_init(&b, src, n_frames);
|
||||
|
|
@ -977,8 +978,11 @@ static int midi_play(struct data *d, void *src, unsigned int n_frames)
|
|||
uint8_t *buf;
|
||||
|
||||
res = midi_file_peek_event(&d->midi.mf, &ev);
|
||||
if (res < 0)
|
||||
if (res <= 0) {
|
||||
if (have_data)
|
||||
break;
|
||||
return res;
|
||||
}
|
||||
|
||||
if (ev.status == 0xff)
|
||||
goto next;
|
||||
|
|
@ -997,6 +1001,7 @@ static int midi_play(struct data *d, void *src, unsigned int n_frames)
|
|||
buf[0] = ev.status;
|
||||
memcpy(&buf[1], ev.data, ev.size);
|
||||
}
|
||||
have_data = true;
|
||||
next:
|
||||
midi_file_consume_event(&d->midi.mf, &ev);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue