freebsd-dev/usr.sbin/bhyve/audio.h
Scott Long 7e3c742061 Add the PCI HDAudio device model from the 2016 GSoC. Detailed information
can be found at

https://wiki.freebsd.org/SummerOfCode2016/HDAudioEmulationForBhyve

This commit has evolved from the original work to include Capsicum
integration.  As part of that, it only opens the host audio devices once
and leaves them open, instead of opening and closing them on each guest
access.  Thanks to Peter Grehan and Marcelo Araujo for their help in
bringing the work forward and providing some of the final techncial push.

Submitted by:	Alex Teaca <iateaca@freebsd.org>
Differential Revision:	D7840, D12419
2019-06-24 19:31:32 +00:00

87 lines
2.9 KiB
C

/*-
* Copyright (c) 2016 Alex Teaca <iateaca@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _AUDIO_EMUL_H_
#define _AUDIO_EMUL_H_
#include <sys/types.h>
#include <sys/soundcard.h>
/*
* Audio Player data structures
*/
struct audio;
struct audio_params {
int channels;
int format;
int rate;
};
/*
* Audio Player API
*/
/*
* audio_init - initialize an instance of audio player
* @dev_name - the backend sound device used to play / capture
* @dir - dir = 1 for write mode, dir = 0 for read mode
* Returns NULL on error and the address of the audio player instance
*/
struct audio *audio_init(const char *dev_name, uint8_t dir);
/*
* audio_set_params - reset the sound device and set the audio params
* @aud - the audio player to be configured
* @params - the audio parameters to be set
* Returns -1 on error and 0 on success
*/
int audio_set_params(struct audio *aud, struct audio_params *params);
/*
* audio_playback - plays samples to the sound device using blocking operations
* @aud - the audio player used to play the samples
* @buf - the buffer containing the samples
* @count - the number of bytes in buffer
* Returns -1 on error and 0 on success
*/
int audio_playback(struct audio *aud, const void *buf, size_t count);
/*
* audio_record - records samples from the sound device using blocking
* operations.
* @aud - the audio player used to capture the samples
* @buf - the buffer to receive the samples
* @count - the number of bytes to capture in buffer
* Returns -1 on error and 0 on success
*/
int audio_record(struct audio *aud, void *buf, size_t count);
#endif /* _AUDIO_EMUL_H_ */