mirror of
https://github.com/Genymobile/scrcpy
synced 2024-11-11 01:10:32 +00:00
Avoid zero-length copies
Return early if there is nothing to read/write.
This commit is contained in:
parent
09e8c20168
commit
fd9498e07c
@ -46,6 +46,9 @@ sc_audiobuf_read(struct sc_audiobuf *buf, void *to_, uint32_t samples_count) {
|
|||||||
uint32_t head = atomic_load_explicit(&buf->head, memory_order_acquire);
|
uint32_t head = atomic_load_explicit(&buf->head, memory_order_acquire);
|
||||||
|
|
||||||
uint32_t can_read = (buf->alloc_size + head - tail) % buf->alloc_size;
|
uint32_t can_read = (buf->alloc_size + head - tail) % buf->alloc_size;
|
||||||
|
if (!can_read) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (samples_count > can_read) {
|
if (samples_count > can_read) {
|
||||||
samples_count = can_read;
|
samples_count = can_read;
|
||||||
}
|
}
|
||||||
@ -86,6 +89,9 @@ sc_audiobuf_write(struct sc_audiobuf *buf, const void *from_,
|
|||||||
uint32_t tail = atomic_load_explicit(&buf->tail, memory_order_acquire);
|
uint32_t tail = atomic_load_explicit(&buf->tail, memory_order_acquire);
|
||||||
|
|
||||||
uint32_t can_write = (buf->alloc_size + tail - head - 1) % buf->alloc_size;
|
uint32_t can_write = (buf->alloc_size + tail - head - 1) % buf->alloc_size;
|
||||||
|
if (!can_write) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (samples_count > can_write) {
|
if (samples_count > can_write) {
|
||||||
samples_count = can_write;
|
samples_count = can_write;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user