mirror of
https://github.com/openharmony/third_party_tinyalsa.git
synced 2026-07-18 13:25:09 -04:00
added PCM_NONBLOCK macro
This commit is contained in:
@@ -88,6 +88,15 @@ extern "C" {
|
||||
*/
|
||||
#define PCM_MONOTONIC 0x00000008
|
||||
|
||||
/** If used with @pcm_open and @pcm_params_get,
|
||||
* it will not cause the function to block if
|
||||
* the PCM is not available. It will also cause
|
||||
* the functions @ref pcm_readi and @ref pcm_writei
|
||||
* to exit if they would cause the caller to wait.
|
||||
* @ingroup libtinyalsa-pcm
|
||||
* */
|
||||
#define PCM_NONBLOCK 0x00000010
|
||||
|
||||
/** For inputs, this means the PCM is recording audio samples.
|
||||
* For outputs, this means the PCM is playing audio samples.
|
||||
* @ingroup libtinyalsa-pcm
|
||||
|
||||
@@ -818,9 +818,13 @@ struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
|
||||
snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device,
|
||||
flags & PCM_IN ? 'c' : 'p');
|
||||
|
||||
fd = open(fn, O_RDWR);
|
||||
if (flags & PCM_NONBLOCK)
|
||||
fd = open(fn, O_RDWR | O_NONBLOCK);
|
||||
else
|
||||
fd = open(fn, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "cannot open device '%s'\n", fn);
|
||||
fprintf(stderr, "cannot open device '%s': %s\n", fn, strerror(errno));
|
||||
goto err_open;
|
||||
}
|
||||
|
||||
@@ -1073,7 +1077,12 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
|
||||
flags & PCM_IN ? 'c' : 'p');
|
||||
|
||||
pcm->flags = flags;
|
||||
pcm->fd = open(fn, O_RDWR);
|
||||
|
||||
if (flags & PCM_NONBLOCK)
|
||||
pcm->fd = open(fn, O_RDWR | O_NONBLOCK);
|
||||
else
|
||||
pcm->fd = open(fn, O_RDWR);
|
||||
|
||||
if (pcm->fd < 0) {
|
||||
oops(pcm, errno, "cannot open device '%s'", fn);
|
||||
return pcm;
|
||||
|
||||
Reference in New Issue
Block a user