mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-18 22:14:20 +01:00
Avoid zero-length copies
Return early if there is nothing to read/write.
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user