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,61 +288,51 @@ size_t ...@@ -288,61 +288,51 @@ 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; /* end of track ? */
char *wptr = (char *) ptr; if (IsEOF())
return 0;
while (length > 0) {
/* end of track ? */ //current sector was changed ?
if (IsEOF()) const int16_t *rbuf;
break;
const int32_t lsn_relofs = offset / CDIO_CD_FRAMESIZE_RAW;
//current sector was changed ? if (lsn_relofs != buffer_lsn) {
const int16_t *rbuf; const ScopeUnlock unlock(mutex);
const int32_t lsn_relofs = offset / CDIO_CD_FRAMESIZE_RAW; try {
if (lsn_relofs != buffer_lsn) { rbuf = para.Read().data;
const ScopeUnlock unlock(mutex); } catch (...) {
char *s_err = cdio_cddap_errors(drv);
try { if (s_err) {
rbuf = para.Read().data; FmtError(cdio_domain,
} catch (...) { "paranoia_read: {}", s_err);
char *s_err = cdio_cddap_errors(drv); cdio_cddap_free_messages(s_err);
if (s_err) {
FmtError(cdio_domain,
"paranoia_read: {}", s_err);
cdio_cddap_free_messages(s_err);
}
throw;
} }
//store current buffer throw;
memcpy(buffer, rbuf, CDIO_CD_FRAMESIZE_RAW);
buffer_lsn = lsn_relofs;
} else {
//use cached sector
rbuf = (const int16_t *)buffer;
} }
//correct offset //store current buffer
const int diff = offset - lsn_relofs * CDIO_CD_FRAMESIZE_RAW; memcpy(buffer, rbuf, CDIO_CD_FRAMESIZE_RAW);
buffer_lsn = lsn_relofs;
} else {
//use cached sector
rbuf = (const int16_t *)buffer;
}
assert(diff >= 0 && diff < CDIO_CD_FRAMESIZE_RAW); //correct offset
const int diff = offset - lsn_relofs * CDIO_CD_FRAMESIZE_RAW;
const size_t maxwrite = CDIO_CD_FRAMESIZE_RAW - diff; //# of bytes pending in current buffer assert(diff >= 0 && diff < CDIO_CD_FRAMESIZE_RAW);
const size_t len = std::min(length, maxwrite);
//skip diff bytes from this lsn const size_t maxwrite = CDIO_CD_FRAMESIZE_RAW - diff; //# of bytes pending in current buffer
memcpy(wptr, ((const char *)rbuf) + diff, len); const std::size_t nbytes = std::min(length, maxwrite);
//update pointer
wptr += len;
nbytes += len;
//update offset //skip diff bytes from this lsn
offset += len; memcpy(ptr, ((const char *)rbuf) + diff, nbytes);
//update length
length -= len; //update offset
} offset += nbytes;
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