Commit c32dceb4 authored by Max Kellermann's avatar Max Kellermann

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.
parent 5573e783
...@@ -3,6 +3,7 @@ ver 0.23.8 (not yet released) ...@@ -3,6 +3,7 @@ ver 0.23.8 (not yet released)
- curl: fix crash if web server does not understand WebDAV - curl: fix crash if web server does not understand WebDAV
* input * input
- cdio_paranoia: fix crash if no drive was found - cdio_paranoia: fix crash if no drive was found
- cdio_paranoia: faster cancellation
* output * output
- pipewire: fix crash with PipeWire 0.3.53 - pipewire: fix crash with PipeWire 0.3.53
* mixer * mixer
......
...@@ -288,13 +288,9 @@ size_t ...@@ -288,13 +288,9 @@ size_t
CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &, CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &,
void *ptr, size_t length) void *ptr, size_t length)
{ {
size_t nbytes = 0;
char *wptr = (char *) ptr;
while (length > 0) {
/* end of track ? */ /* end of track ? */
if (IsEOF()) if (IsEOF())
break; return 0;
//current sector was changed ? //current sector was changed ?
const int16_t *rbuf; const int16_t *rbuf;
...@@ -330,19 +326,13 @@ CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &, ...@@ -330,19 +326,13 @@ CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &,
assert(diff >= 0 && diff < CDIO_CD_FRAMESIZE_RAW); 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 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 //skip diff bytes from this lsn
memcpy(wptr, ((const char *)rbuf) + diff, len); memcpy(ptr, ((const char *)rbuf) + diff, nbytes);
//update pointer
wptr += len;
nbytes += len;
//update offset //update offset
offset += len; offset += nbytes;
//update length
length -= len;
}
return nbytes; return nbytes;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment