123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /*
- * QEMU Audio subsystem header
- *
- * Copyright (c) 2003-2005 Vassili Karpov (malc)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- #ifndef QEMU_AUDIO_INT_H
- #define QEMU_AUDIO_INT_H
- #ifdef CONFIG_AUDIO_COREAUDIO
- #define FLOAT_MIXENG
- /* #define RECIPROCAL */
- #endif
- #include "mixeng.h"
- struct audio_pcm_ops;
- struct audio_callback {
- void *opaque;
- audio_callback_fn fn;
- };
- struct audio_pcm_info {
- int bits;
- bool is_signed;
- bool is_float;
- int freq;
- int nchannels;
- int bytes_per_frame;
- int bytes_per_second;
- int swap_endianness;
- };
- typedef struct AudioState AudioState;
- typedef struct SWVoiceCap SWVoiceCap;
- typedef struct STSampleBuffer {
- size_t pos, size;
- st_sample samples[];
- } STSampleBuffer;
- typedef struct HWVoiceOut {
- AudioState *s;
- int enabled;
- int poll_mode;
- int pending_disable;
- struct audio_pcm_info info;
- f_sample *clip;
- uint64_t ts_helper;
- STSampleBuffer *mix_buf;
- void *buf_emul;
- size_t pos_emul, pending_emul, size_emul;
- size_t samples;
- QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
- QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
- struct audio_pcm_ops *pcm_ops;
- QLIST_ENTRY (HWVoiceOut) entries;
- } HWVoiceOut;
- typedef struct HWVoiceIn {
- AudioState *s;
- int enabled;
- int poll_mode;
- struct audio_pcm_info info;
- t_sample *conv;
- size_t total_samples_captured;
- uint64_t ts_helper;
- STSampleBuffer *conv_buf;
- void *buf_emul;
- size_t pos_emul, pending_emul, size_emul;
- size_t samples;
- QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
- struct audio_pcm_ops *pcm_ops;
- QLIST_ENTRY (HWVoiceIn) entries;
- } HWVoiceIn;
- struct SWVoiceOut {
- QEMUSoundCard *card;
- AudioState *s;
- struct audio_pcm_info info;
- t_sample *conv;
- int64_t ratio;
- struct st_sample *buf;
- void *rate;
- size_t total_hw_samples_mixed;
- int active;
- int empty;
- HWVoiceOut *hw;
- char *name;
- struct mixeng_volume vol;
- struct audio_callback callback;
- QLIST_ENTRY (SWVoiceOut) entries;
- };
- struct SWVoiceIn {
- QEMUSoundCard *card;
- AudioState *s;
- int active;
- struct audio_pcm_info info;
- int64_t ratio;
- void *rate;
- size_t total_hw_samples_acquired;
- struct st_sample *buf;
- f_sample *clip;
- HWVoiceIn *hw;
- char *name;
- struct mixeng_volume vol;
- struct audio_callback callback;
- QLIST_ENTRY (SWVoiceIn) entries;
- };
- typedef struct audio_driver audio_driver;
- struct audio_driver {
- const char *name;
- const char *descr;
- void *(*init) (Audiodev *);
- void (*fini) (void *);
- struct audio_pcm_ops *pcm_ops;
- int can_be_default;
- int max_voices_out;
- int max_voices_in;
- int voice_size_out;
- int voice_size_in;
- QLIST_ENTRY(audio_driver) next;
- };
- struct audio_pcm_ops {
- int (*init_out)(HWVoiceOut *hw, audsettings *as, void *drv_opaque);
- void (*fini_out)(HWVoiceOut *hw);
- size_t (*write) (HWVoiceOut *hw, void *buf, size_t size);
- void (*run_buffer_out)(HWVoiceOut *hw);
- /*
- * get a buffer that after later can be passed to put_buffer_out; optional
- * returns the buffer, and writes it's size to size (in bytes)
- * this is unrelated to the above buffer_size_out function
- */
- void *(*get_buffer_out)(HWVoiceOut *hw, size_t *size);
- /*
- * put back the buffer returned by get_buffer_out; optional
- * buf must be equal the pointer returned by get_buffer_out,
- * size may be smaller
- */
- size_t (*put_buffer_out)(HWVoiceOut *hw, void *buf, size_t size);
- void (*enable_out)(HWVoiceOut *hw, bool enable);
- void (*volume_out)(HWVoiceOut *hw, Volume *vol);
- int (*init_in) (HWVoiceIn *hw, audsettings *as, void *drv_opaque);
- void (*fini_in) (HWVoiceIn *hw);
- size_t (*read) (HWVoiceIn *hw, void *buf, size_t size);
- void *(*get_buffer_in)(HWVoiceIn *hw, size_t *size);
- void (*put_buffer_in)(HWVoiceIn *hw, void *buf, size_t size);
- void (*enable_in)(HWVoiceIn *hw, bool enable);
- void (*volume_in)(HWVoiceIn *hw, Volume *vol);
- };
- void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
- void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
- void audio_generic_run_buffer_out(HWVoiceOut *hw);
- void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size);
- size_t audio_generic_put_buffer_out(HWVoiceOut *hw, void *buf, size_t size);
- size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size);
- size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size);
- struct capture_callback {
- struct audio_capture_ops ops;
- void *opaque;
- QLIST_ENTRY (capture_callback) entries;
- };
- struct CaptureVoiceOut {
- HWVoiceOut hw;
- void *buf;
- QLIST_HEAD (cb_listhead, capture_callback) cb_head;
- QLIST_ENTRY (CaptureVoiceOut) entries;
- };
- struct SWVoiceCap {
- SWVoiceOut sw;
- CaptureVoiceOut *cap;
- QLIST_ENTRY (SWVoiceCap) entries;
- };
- typedef struct AudioState {
- struct audio_driver *drv;
- Audiodev *dev;
- void *drv_opaque;
- QEMUTimer *ts;
- QLIST_HEAD (card_listhead, QEMUSoundCard) card_head;
- QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
- QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
- QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
- int nb_hw_voices_out;
- int nb_hw_voices_in;
- int vm_running;
- int64_t period_ticks;
- bool timer_running;
- uint64_t timer_last;
- QTAILQ_ENTRY(AudioState) list;
- } AudioState;
- extern const struct mixeng_volume nominal_volume;
- extern const char *audio_prio_list[];
- void audio_driver_register(audio_driver *drv);
- audio_driver *audio_driver_lookup(const char *name);
- void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
- void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
- int audio_bug (const char *funcname, int cond);
- void *audio_calloc (const char *funcname, int nmemb, size_t size);
- void audio_run(AudioState *s, const char *msg);
- typedef struct RateCtl {
- int64_t start_ticks;
- int64_t bytes_sent;
- } RateCtl;
- void audio_rate_start(RateCtl *rate);
- size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
- size_t bytes_avail);
- static inline size_t audio_ring_dist(size_t dst, size_t src, size_t len)
- {
- return (dst >= src) ? (dst - src) : (len - src + dst);
- }
- #define dolog(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
- #ifdef DEBUG
- #define ldebug(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
- #else
- #define ldebug(fmt, ...) (void)0
- #endif
- #define AUDIO_STRINGIFY_(n) #n
- #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
- typedef struct AudiodevListEntry {
- Audiodev *dev;
- QSIMPLEQ_ENTRY(AudiodevListEntry) next;
- } AudiodevListEntry;
- typedef QSIMPLEQ_HEAD(, AudiodevListEntry) AudiodevListHead;
- AudiodevListHead audio_handle_legacy_opts(void);
- void audio_free_audiodev_list(AudiodevListHead *head);
- void audio_create_pdos(Audiodev *dev);
- AudiodevPerDirectionOptions *audio_get_pdo_in(Audiodev *dev);
- AudiodevPerDirectionOptions *audio_get_pdo_out(Audiodev *dev);
- #endif /* QEMU_AUDIO_INT_H */
|