#ifndef DVBOUT_HPP
#define DVBOUT_HPP

#include "render_device.hpp"
#include "mpeg.hpp"

#include <linux/dvb/video.h>
#include <linux/dvb/audio.h>
#include <poll.h>

class DvbDraw : public ost::Thread
{
public:
  bool running;
private:
  void run();
  void Final() 
  { delete this; } // we instantiate dvbdraw as a pointer so this is safe
};

class Dvb : public Render_device
{
private:
  int fd_video;

  mpeg_frame iframe;
  pollfd pfd[1];

  int initialized;
  bool locked;

  // first frame ready
  bool ffr;

  DvbDraw *d;

  struct video_still_picture still;

  void my_write(unsigned char* data, int len);

public:
  // for synchronization with drawer
  ost::Mutex locked_mutex;

  Dvb();
  ~Dvb();

  void init();
  void deinit();
  
  void redraw();
  void create_packet_and_write();

  void lock();
  void unlock();

 private:
  void run();
};

#endif
