Skip to content

Commit

Permalink
dsoundaudio: dsound_get_buffer_in should honor *size
Browse files Browse the repository at this point in the history
This patch prevents an underflow of variable samples in function
audio_pcm_hw_run_in(). See commit 599eac4 "audio:
audio_generic_get_buffer_in should honor *size". This time the
while loop in audio_pcm_hw_run_in() will terminate nevertheless,
because it seems the recording stream in Windows is always rate
limited.

Signed-off-by: Volker Rümelin <[email protected]>
Message-id: [email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
Volker Rümelin authored and kraxel committed Apr 6, 2020
1 parent 1747029 commit 8d1439b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1491,15 +1491,13 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size)

size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
{
size_t src_size, copy_size;
void *src = hw->pcm_ops->get_buffer_in(hw, &src_size);
copy_size = MIN(size, src_size);
void *src = hw->pcm_ops->get_buffer_in(hw, &size);

memcpy(buf, src, copy_size);
hw->pcm_ops->put_buffer_in(hw, src, copy_size);
return copy_size;
}
memcpy(buf, src, size);
hw->pcm_ops->put_buffer_in(hw, src, size);

return size;
}

static int audio_driver_init(AudioState *s, struct audio_driver *drv,
bool msg, Audiodev *dev)
Expand Down
2 changes: 1 addition & 1 deletion audio/dsoundaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size)
}

req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul);
req_size = MIN(req_size, hw->size_emul - hw->pos_emul);
req_size = MIN(*size, MIN(req_size, hw->size_emul - hw->pos_emul));

if (req_size == 0) {
*size = 0;
Expand Down

0 comments on commit 8d1439b

Please sign in to comment.