#ifndef audiocodec_h
#define audiocodec_h

#include "audio.h"
#include "ka_acodec.h"
#include "ka_error.h"

typedef struct ka_audiocodec_s ka_audiocodec_t;

typedef enum
{ EAUDIOCODEC_DECODE_TRYLATER  = 0
, EAUDIOCODEC_DECODE_PROCESSED = 1
, EAUDIOCODEC_DECODE_INERROR   = 2
} ka_eaudiocodec_decode;

#define AUDIOCODEC_STATE_READY     1
#define AUDIOCODEC_STATE_INERROR   2
#define AUDIOCODEC_STATE_NOWORK    4 // Current input & output done
#define AUDIOCODEC_STATE_COMPLETED 8 // No work + no future input

typedef int   (*audiocodec_Allow) (const ka_aparams_t* params);
typedef ka_audiocodec_t* (*audiocodec_Open)  (ka_error_t* pErrorBlock);
typedef void  (*audiocodec_Close) (ka_audiocodec_t**);
typedef int   (*audiocodec_Start) (ka_audiocodec_t*, const ka_aparams_t* params);
typedef void  (*audiocodec_Stop) (ka_audiocodec_t*);
typedef ka_eaudiocodec_decode (*audiocodec_Decode)(ka_audiocodec_t*, ka_block_t* block);
typedef int   (*audiocodec_GetPos)(ka_audiocodec_t*, audio_info_t* info);
typedef void  (*audiocodec_Pause) (ka_audiocodec_t*, int pause);
typedef int   (*audiocodec_Volume)(ka_audiocodec_t*, int vol);

typedef struct
{
  const char*       name;
  audiocodec_Allow  allow;
  audiocodec_Open   open;
  audiocodec_Close  close;
  audiocodec_Start  start;
  audiocodec_Stop   stop;
  audiocodec_GetPos getPos;
  audiocodec_Decode decode;
  audiocodec_Pause  pause;
  audiocodec_Volume volume;
} kav_audiocodec_t;

extern const kav_audiocodec_t kav_amp_codec;
extern const kav_audiocodec_t kav_disk_codec;

struct ka_audiocodec_s
{
  const kav_audiocodec_t* vptr;
  ka_error_t* pErrorBlock;
};

#endif
