#ifndef audio_h
#define audio_h

#include "inttypes.h"
#include "ka_acodec.h"
#include "ka_block.h"
#include "ka_error.h"

#define AUDIO_STATUS_CODECOPEN        0x001 // Decoder open
#define AUDIO_STATUS_READYFORINPUT    0x002 // Accepting input, but none received
#define AUDIO_STATUS_DECODINGINPUT    0x004 // Already treating some input
#define AUDIO_STATUS_READYFOROUTPUT   0x008 // Output parameters (freq, ...) known
#define AUDIO_STATUS_REPLAYOUTPUT     0x010 // Playing output
#define AUDIO_STATUS_DONEOUTPUT       0x020 // Output completed
#define AUDIO_STATUS_COMPLETED        0x040 // Output completed, no more input
#define AUDIO_STATUS_DISABLED         0x080 // Not accepting input (in error)
#define AUDIO_STATUS_PAUSED           0x100 // Replay of output paused

#define AUDIO_STATUS_ERRORMASK        0x07E // Flags to reset on error
#define AUDIO_STATUS_STOPMASK         0x01E // Flags to reset on stop
#define AUDIO_STATUS_BLOCKPROCESSMASK 0x01C

typedef struct audio_s audio_t;

// Audio Frame Information Block
typedef struct
{
  char name[256];   // audio type decriptor
  int type;         // audio type
  int channels;
  int samp_rate;    // Hz
  int bitrate;      // Kbit/sec
  uint32_t section; // section to which the audio belongs
  uint32_t pts;     // current pts
  int status;
  uint32_t cfg;
} audio_info_t;

audio_t* audio_new(ka_error_t* pErrorBlock);
void audio_delete(audio_t**);
int audio_allow(audio_t*, const ka_aparams_t*);
int audio_open(audio_t*, ka_error_t* pErrorBlock, const ka_aparams_t*);
void audio_close(audio_t*);
int  audio_decode(audio_t*, ka_block_t*);
void audio_pause(audio_t*, int pause);
int  audio_volume(audio_t*, int vol);
  /* use -1 to read current value */
  /* use -2 to mute audio */
  /* use -3 to unmute audio */
void audio_checkStart(audio_t*, uint32_t reftime, uint32_t section);
void audio_checkState(audio_t*);
const audio_info_t* audio_info(audio_t*);
const ka_aparams_t* audio_getParams(audio_t*);

#endif
