/* coding: utf-8; */
#include "soundio-demo.h"
#include <stdbool.h>

#ifndef __SOUNDIO_CLASS_H__
#define __SOUNDIO_CLASS_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
	WorkerHandle handle;

	int (*WaveInCallback) (const char * data, const unsigned long size, void * pObject);
	void *user_data;

	pthread_t thread;

	int stop_wait;
} tagSoundIn;

#define OUT_RING_SZ 32
typedef struct {
	WorkerHandle handle;
	WorkerHandle mixer;

	int (*WaveOutCallback) (void * pdata);

	pthread_t thread;
	pthread_cond_t wq_cond;
	pthread_mutex_t mutex;
	struct {
		void *tag;
		void *data;
		int data_len;
	} ring[OUT_RING_SZ];
	int wq_idx;
	int n_works;

	int stop_wait; /* us */
	bool quit;
} tagSoundOut;


bool SoundIn_init(tagSoundIn *in);
bool SoundIn_uninit(tagSoundIn *in);
bool SoundIn_start(tagSoundIn *in);
bool SoundIn_stop(tagSoundIn *in);

bool SoundOut_init(tagSoundOut *out);
bool SoundOut_uninit(tagSoundOut *out);
bool SoundOut_start(tagSoundOut *out);
/* should be called in the same thread as SoundOut_start */
bool SoundOut_stop(tagSoundOut *out);
bool SoundOut_play_data(tagSoundOut *out, void *data, int data_len, void *tag);
bool SoundOut_set_volume(tagSoundOut *out, int _volume);
int SoundOut_get_volume(tagSoundOut *out);

#ifdef __cplusplus
}
#endif

#endif /* __SOUNDIO_CLASS_H__ */
