/*
 * video-fb.h: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: video-fb.h,v 1.2 2004/05/20 15:38:47 stefan Exp $
 */

#ifndef VIDEO_NET_H
#define VIDEO_NET_H
#include "video.h"
#include <avformat.h>

class cFBVideoOut : public cVideoOut , cThread {
private:
  size_t size;
  int line_len;
  char filename[256];
  unsigned char * fb;	// Framebuffer memory
  AVCodec *codec;
  AVCodecContext *c;
  AVFrame *picture;
  AVFrame *tmp_picture;
  AVFrame *tmp2_picture;
  AVFrame *empty_picture;
  uint8_t *video_outbuf, *picture_buf;
  int video_outbuf_size;
  int framecount;
  AVOutputFormat *fmt;
  AVStream *video_st;
  AVFormatContext *oc;
  double video_pts;
  FILE *f;
  cBitmap *current_osd;
  bool active, running;
  uint64_t lastpic;
  int delay;
  bool validframe;
  
protected:
  virtual void Action(void);
    
public:
  cFBVideoOut(char *fn);
  virtual ~cFBVideoOut();
  virtual void Refresh(cBitmap *Bitmap);
  virtual void YUV(uint8_t *Py, uint8_t *Pu, uint8_t *Pv, int Width, int Height, int Ystride, int UVstride);
  virtual void Pause(void);
  
  AVStream *add_video_stream(AVFormatContext *oc, int codec_id);
  AVFrame *alloc_picture(int pix_fmt, int width, int height);
  void open_video(AVFormatContext *oc, AVStream *st);
  void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height);
  void write_video_frame(AVFormatContext *oc, AVStream *st, AVFrame *picture);
  void close_video(AVFormatContext *oc, AVStream *st);
  
};

#endif // VIDEO_NET_H
