input/CdioParanoia: remove loop from Read()

The Read() method is not required to fill the whole buffer.  By
returning as soon as at least one byte was read, we allow faster
cancellation.
This commit is contained in:
Max Kellermann 2022-07-08 12:26:52 +02:00
parent 5573e78364
commit c32dceb4d4
2 changed files with 38 additions and 47 deletions

1
NEWS
View File

@ -3,6 +3,7 @@ ver 0.23.8 (not yet released)
- curl: fix crash if web server does not understand WebDAV
* input
- cdio_paranoia: fix crash if no drive was found
- cdio_paranoia: faster cancellation
* output
- pipewire: fix crash with PipeWire 0.3.53
* mixer

View File

@ -288,13 +288,9 @@ size_t
CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &,
void *ptr, size_t length)
{
size_t nbytes = 0;
char *wptr = (char *) ptr;
while (length > 0) {
/* end of track ? */
if (IsEOF())
break;
return 0;
//current sector was changed ?
const int16_t *rbuf;
@ -330,19 +326,13 @@ CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &,
assert(diff >= 0 && diff < CDIO_CD_FRAMESIZE_RAW);
const size_t maxwrite = CDIO_CD_FRAMESIZE_RAW - diff; //# of bytes pending in current buffer
const size_t len = std::min(length, maxwrite);
const std::size_t nbytes = std::min(length, maxwrite);
//skip diff bytes from this lsn
memcpy(wptr, ((const char *)rbuf) + diff, len);
//update pointer
wptr += len;
nbytes += len;
memcpy(ptr, ((const char *)rbuf) + diff, nbytes);
//update offset
offset += len;
//update length
length -= len;
}
offset += nbytes;
return nbytes;
}