123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #pragma once
- #include <pulse/sample.h>
- #include <pulse/pulseaudio.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define AMS_OPT_RECORD 0x01
- #define AMS_OPT_PLAY 0x02
- #define AMS_OPT_RECPLAY 0x03
- #define AMS_OPT_AS_STREAM 0x00
- #define AMS_OPT_AS_ENGINE 0x04
- #include "precompile.h"
- #include "audiostream.h"
- #include <stdbool.h>
- #ifndef MAX_PATH_EX
- #define MAX_PATH_EX 512
- #endif
- #ifndef MAX_PATH
- #define MAX_PATH 260
- #endif
- #ifndef RVC_DELAY_AUDIO_LEN
- #define RVC_DELAY_AUDIO_LEN 160
- #endif
- #ifndef NSEC_PER_SEC
- #define NSEC_PER_SEC 1000000000LL
- #endif
-
- #define pa_memzero(x,l) (memset((x), 0, (l)))
- #define pa_zero(x) (pa_memzero(&(x), sizeof(x)))
- /*internally is always float*/
- typedef int16_t sample_t;
- typedef struct audio_data_callback_s
- {
- void* input;
- size_t inputlen;
- unsigned long frameCount;
- size_t usamprate;
- }audio_data_callback_t;
- typedef struct audio_device_s
- {
- int id; /*audo device id*/
- int channels; /*max channels*/
- int samprate; /*default samplerate*/
- double low_latency; /*default low latency*/
- double high_latency; /*default high latency*/
- char name[MAX_PATH_EX]; /*device name*/
- char description[MAX_PATH]; /*device description*/
- } audio_device_t;
- typedef struct audio_context_s
- {
- void* micspkpulse_parent;
- bool bstart_put_flag;
- bool bstart_get_flag;
- int num_input_dev; /*number of audio input devices in list*/
- audio_device_t* list_input_devices; /*audio input devices list*/
- int num_output_dev;
- audio_device_t* list_output_devices; /*audio output devices list*/
- int device; /*current device list index*/
- int channels; /*channels*/
- int samprate; /*sample rate*/
- double latency; /*current sugested latency*/
- pa_sample_format_t eformat;
- int play_device; /*current device list index*/
- int play_channels; /*channels*/
- int play_samprate; /*sample rate*/
- double play_latency; /*current sugested latency*/
- pa_sample_format_t play_eformat;
- /*all ts are monotonic based: both real and generated*/
- int64_t current_ts; /*current buffer generated timestamp*/
- int64_t last_ts; /*last real timestamp (in nanosec)*/
- int64_t snd_begintime; /*sound capture start ref time*/
- int64_t ts_drift; /*drift between real and generated ts*/
- volatile int stream_flag; /*stream flag*/
- volatile int play_stream_flag; /*stream flag*/
- pthread_t readthreadid;
- pthread_t writethreadid;
- char* paudio_buffer;
- size_t uaudio_len;
- char* paudio_in;
- size_t uaudio_inlen;
- }audio_context_t;
- typedef struct audiomicspkpulse_s
- {
- audiostream_t base;
- int opt;
- int rec_dev_id;
- int ply_dev_id;
- int play_frame_samples;
- int capture_frame_samples;
- void* ply_dbuf;
- short* ply_buf;
- unsigned ply_buf_cnt;
- void* rec_buf;
- void* rec_dbuf;
- unsigned long rec_buf_cnt;
- apr_thread_t* audio_work_thread;
- sem_t* audio_device_started_sem;
- bool baudio_device_started_flag;
- int dev_type;
- int (*on_rx_audio)(char* frame, void* user_data);
- int (*on_tx_audio)(void* audiodata, void* user_data);
- int (*on_audio_ns)(void* pdst, size_t udstlen, void* psrc, size_t usrclen, void* user_data);
- int (*on_audio_play_ns)(void* pdst, size_t udstlen, void* psrc, size_t usrclen, void* user_data);
- int (*on_audio_playing)(void* pdata, size_t ulen, void* user_data);
- void (*on_audio_device_event)(bool bopen, int iret, bool bmicro, int idev, const char* strmessage, void* user_data);
- void* user_data;
- audio_context_t* audio_ctx;
- }audiomicspkpulse_t;
- typedef void (*lpfn_audio_device_event)(bool bopen, int iret, bool bmicro, int idev, const char* strmessage, void* user_data);
- apr_status_t audiomicspkpulse_create(apr_pool_t* pool,
- audioengine_t* engine,
- int opt,
- int clock,
- const char* rec_dev_key,
- const char* ply_dev_key,
- int idev_type,
- lpfn_audio_device_event lpevent,
- audiomicspkpulse_t** p_micspk);
- void audiomicspkpulse_destroy(audiomicspkpulse_t* micspk);
- #ifdef __cplusplus
- } // extern "C" {
- #endif
|