#ifndef config_h
#define config_h

// config.debug bitfield
#define cfg_displayall          0x00001
#define cfg_printsubtitlestats  0x00002
#define cfg_printaudiostats     0x00004
#define cfg_printpicturestats   0x00008
#define cfg_printstatssummary   0x00010
#define cfg_printwarnings       0x00020
#define cfg_printdrawstats      0x00040
#define cfg_printseekstats      0x00080
#define cfg_printbufferstats    0x00100
#define cfg_printsubtitlepush   0x00200
#define cfg_printaudiopush      0x00400
#define cfg_printvideopush      0x00800
#define cfg_printdemuxstats     0x01000
#define cfg_printsubtitlepull   0x02000
#define cfg_printaudiopull      0x04000
#define cfg_printvideopull      0x08000
#define cfg_printreplaystats    0x10000
#define cfg_printnavstats       0x20000

#define cfg_printsubtitleall    0x02202
#define cfg_printaudioall       0x04404
#define cfg_printvideoall       0x08848

// config.subtitles.cfg bitfield
#define cfg_subtitles_show        0x01
#define cfg_subtitles_autoselect  0x02

// config.audio.cfg bitfield
#define cfg_audio_play          0x01
#define cfg_audio_save          0x02
#define cfg_audio_sync          0x04
#define cfg_audio_mute          0x08
#define cfg_audio_autoselect    0x10
#define cfg_audio_currentvolume 0x20 // ignore config volume setting

// config.video.cfg bitfield
#define cfg_video_mono          0x01
#define cfg_video_dither        0x02
#define cfg_video_lock_aspect   0x04
#define cfg_video_fit_screen    0x08
#define cfg_video_force_scaler  0x10
#define cfg_video_pixel_aspect  0x20 // only if scaler is used
#define cfg_video_to_BGR        0x40
//#define cfg_video_deinterlace   0x80 // replaced by deinterlace method

// config.control bitfield
#define cfg_ctrl_scroll_bars    0x001 // multitasking only
#define cfg_ctrl_controls       0x002 // multitasking only
#define cfg_ctrl_multiple_wins  0x004 // multitasking only
#define cfg_ctrl_nocheck        0x008 // use demux params from config
#define cfg_ctrl_loop           0x010
#define cfg_ctrl_autoexit       0x020
#define cfg_ctrl_random         0x040 // playlist option
#define cfg_ctrl_defaultcols    0x080 // ignore bright./contrast/colour settings
#define cfg_ctrl_accel_inteldma 0x100
#define cfg_ctrl_accel_geminus  0x200
#define cfg_ctrl_accel_anymodes 0x400 // fit screen = use screen of that size
#define cfg_ctrl_accel_videooverlay 0x800
#define cfg_ctrl_start_paused   0x1000
#define cfg_ctrl_hide_errors    0x2000
#define cfg_ctrl_accel_videooverlay_not_multitasking 0x4000

enum { KA_COL_256
     , KA_COL_4K
     , KA_COL_32K
     , KA_COL_64K
     , KA_COL_16M
     , KA_COL_MAX
     };

// operating modes
enum { KA_MODE_MULTITASK
     , KA_MODE_DESKTOP
     , KA_MODE_AUTO
     , KA_MODE_MANUAL
     , KA_MODE_MAX
     };

// scaler mode
enum { KA_SCALER_INTERNAL
     , KA_SCALER_SYSTEM
     , KA_SCALER_LINEAR
     , KA_SCALER_BILINEAR
     , KA_SCALER_MAX
     };

enum { KA_DEINTERLACE_NONE
     , KA_DEINTERLACE_BLEND
     , KA_DEINTERLACE_BLEND_X2
     , KA_DEINTERLACE_FIELDS_X2
     , KA_DEINTERLACE_MAX
     };

enum { KA_RESIZE_NONE
     , KA_RESIZE_PANSCAN
     , KA_RESIZE_STRETCH
     , KA_RESIZE_MAX
     };

enum { KA_RESIZETO_MONITOR
     , KA_RESIZETO_5x4
     , KA_RESIZETO_4x3
     , KA_RESIZETO_16x10
     , KA_RESIZETO_16x9
     , KA_RESIZETO_256x135
     , KA_RESIZETO_21x9
     , KA_RESIZETO_MAX
     };

typedef struct
{
  int width;              // screen width
  int height;             // screen height
  int id;                 // index
  int cols;               // 0..4    256, 4K, 32K, 64K, 16M
  int zoom;               // default 100
  int scaler;             // 0... scaler function to use
  int cfg;                // mode specific flags
} video_mode;

typedef struct
{
  int debug;              // debugging flags
  int control;            // control flags
  int program;
  struct
  {
    int cfg;
    int stream;           // 0... stream nr to play
  }  subtitle;
  struct
  {
    int cfg;
    int stream;           // 0... stream nr to play
    int volume;           // 0..127  default current setting
    int module;           // 0 Amplayer, 1 DiskSample
  }  audio;
  struct
  {
    int stream;           // 0... stream nr to play
    int demux_ps;         // forced video demuxer
    int position_x;       // desktop only, default -1 -> centered
    int position_y;       // desktop only, default -1 -> centered
    int colour;           // 0..200  default 100
    int brightness;       // 0..200  default 100
    int contrast;         // 0..200  default 100
    int cfg;              // common video flags
    int mode;             // 0..3 replay mode
    int deinterlace;      // deinterlace method
    int resizemode;       // source, pan & scan, stretch
    int resizeto;          // monitor, aspect ratios
    struct {
      int x;
      int y;
    } monitor_aspect;     // aspect ratio of monitor
    video_mode modes[KA_MODE_MAX];
  }  video;
  char skin[32];
  char language[3];
} ka_config_t;

void config_init(ka_config_t*);
void config_validate(ka_config_t*);
void config_read(ka_config_t*, const char* filename);
void config_save(ka_config_t*, const char* filename);
void config_aspect_ratio(ka_config_t*, int* px, int* py);

extern ka_config_t config;

#endif
