#ifndef XINE_HPP
#define XINE_HPP

#include "player.hpp"

#include <cc++/thread.h>

#include <xine.h>

class Xine : public Player
{
public:
  int is_playing();
  int is_buffering();
  int is_mute();
  void gather_info();
  void addfile(const Simplefile &file);
  void play();
  void stop_player();
  void pause();
  void ff();
  void fb();

  int getpos();
  void setpos(int p);

  void mute();
  void volup();
  void voldown();
  int getvol();
  void setvol(int vol);

  void update_cdrom(const std::string& cdrom);

  void collect_info(const std::string& filename);

  ~Xine();
  Xine();

private:
  void config_update(xine_cfg_entry_t *entry, int type, int min, int max, int value, const char *string);
  void config_update_string(char *key, const char *string);
  void config_set_num(char *key, int val);
  void send_event(int event);
  // requires the stream to be ok and the mutex to be locked before entering
  void set_time(int time);
  void gather_info_internal();

  void setvol();

  static void event_listener(void *user_data, const xine_event_t *event);
  void check_stream();

  ost::Mutex stream_mutex;

  int volume;

  xine_t *xine;
  xine_stream_t* stream;
  bool stream_valid;
  xine_video_port_t *vo_port;
  xine_audio_port_t *ao_port;
  xine_event_queue_t *event_queue;
};

#endif
