/*
 * recorder.h: The actual DVB recorder
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id: recorder.h 1.4 2005/08/13 11:31:18 kls Exp $
 */

#ifndef __RECORDER_H
#define __RECORDER_H

#include "receiver.h"
#include "recording.h"
#include "remux.h"
#include "ringbuffer.h"
#include "thread.h"

class cFileWriter : public cThread {
friend class cCuttingThread;
private:
  bool isLiveRec;
  bool isBeginning;
  bool ResumeLiveRec;
  char* filename;
  u_int64_t pts;
  cRemux *remux;
  cFileName *fileName;
  cIndexFile *index;
  uchar pictureType;
  int fileSize;
  cUnbufferedFile *recordFile;
  time_t lastDiskSpaceCheck;
  bool RunningLowOnDiskSpace(void);
  bool NextFile(void);
protected:
  virtual void Action(void);
public:
  cFileWriter(const char *FileName, cRemux *Remux,bool IsLiveRec = false, bool IsBeginning = false);
  virtual ~cFileWriter();
  void SetNewRemux(cRemux *Remux) {remux=Remux;}
  void RecordNextIFrame(u_int64_t PTS);
  };

class cRecorder : public cReceiver, cThread {
private:
  bool isLiveRec;
  bool attached;
  cRingBufferLinear *ringBuffer;
  cRemux *remux,*oldRemux;
  cFileWriter *writer;
protected:
  virtual void Activate(bool On);
  virtual void Receive(uchar *Data, int Length);
  virtual void Action(void);
public:
  cRecorder(const char *FileName, int Ca, int Priority, int VPid, const int *APids, const int *DPids, const int *SPids, bool IsLiveRec = false, bool IsBeginning = false);
               // Creates a new recorder that requires conditional access Ca, has
               // the given Priority and will record the given PIDs into the file FileName.
  virtual ~cRecorder();
  void ChangePIDs(cDevice *Device, int VPid, const int *APids, const int *DPids, const int *SPids);
  cFileWriter *GetWriter() {return writer;}
  bool IsAttached() {return attached;}
  };

#endif //__RECORDER_H
