
/*
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 *  $Id: common.h,v 1.3 2004/12/04 13:09:33 lordjaxom Exp $
 */

#ifndef VDR_BURN_COMMON_H
#define VDR_BURN_COMMON_H

#include <stdint.h>
#include <stdlib.h>
#include <vdr/tools.h>

#define VDRBURNCMD   "vdrburn.sh"
#define BURNMARKFILE "burnmark.vdr"

#define JOBNAMELEN 255
#define MAXTRACKS 9             // the maximum tcmplex-panteltje can handle
#define MAXPAGETITLES 8
// #define DVDSIZE 4462 // from vdrconvert, minus some reserve
// #define DVDSIZE 200

#ifdef DEBUG
#	include <stdio.h>
#	define Dprintf(x...) fprintf(stderr, x)
#else
#	define Dprintf(x...)
#endif

#define strn1cmp(a,b) strncmp(a,b,strlen(b))

enum eBurnState
{
    bsRecordings,
    bsStatus,
    __STATE_COUNT__
};

enum eDiskType
{
    dtDVD,
    dtDVDnm,
    __TYPE_COUNT_REQUANT__,
    dtVDR = __TYPE_COUNT_REQUANT__,
    __TYPE_COUNT__
};

enum eStoreMode
{
    smAuthorOnly,
    smCreateISO,
    smBurnISO,
    smCreateBurn,
    __STORE_COUNT__
};

enum eBurnMode
{
    bmShrink,
    bmDistribute,
    __MODE_COUNT__
};

enum eChaptersMode
{
    cmNoChapters,
    cmEditingMarks,
    cm5Mins,
    cm10Mins,
    cm15Mins,
    cm30Mins,
    cm60Mins,
    __CHAPTERS_COUNT__
};

enum eReturnStatus
{
    rsNone,
    rsOk,
    rsError
};

enum eNextStep
{
    nsContinue,
    nsNext,
    nsRetry
};

enum eVTrackType
{
    ttUnknown,
    ttVideo,
    ttAudioMP2,
    ttAudioAC3
};

class tTrackInfo
{
    char *mFilename;
    eVTrackType mType;
    int mLanguage;

  public:
    tTrackInfo(void): mFilename(NULL)
    {
        setAll(NULL, ttUnknown, -1);
    }
    tTrackInfo(tTrackInfo &info): mFilename(NULL)
    {
        setAll(info.mFilename, info.mType, info.mLanguage);
    }
    ~tTrackInfo() { free(mFilename); }

    void setAll(const char *Filename, eVTrackType Type, int Language)
    {
        if (mFilename) {
            free(mFilename);
        }
        mFilename = Filename ? strdup(Filename) : NULL;
        mType = Type;
        mLanguage = Language;
    }

    const char *Filename() const { return mFilename; }
    eVTrackType Type() const { return mType; }
    int Language() const { return mLanguage; }
};

class tTrackInfoArray
{
    tTrackInfo mArray[MAXTRACKS];
    int mFill;
  public:
    tTrackInfoArray() { mFill = 0; }
    int Size() const { return mFill; }
    void Clear() { mFill = 0; }
    bool Add(const char *Filename, eVTrackType Type, int Language)
    {
        if (mFill >= MAXTRACKS) {
            return false;
        }
        mArray[mFill].setAll(Filename, Type, Language);
        mFill++;
        return true;
    }
    const tTrackInfo *operator[] (int pos) const
    {
        if (pos >= mFill) {
            return NULL;
        }
        return &mArray[pos];
    }
    tTrackInfoArray & operator= (const tTrackInfoArray & trackInfo) {
        Clear();
        for (int i = 0; i < trackInfo.Size(); i++) {
            Add(trackInfo[i]->Filename(), trackInfo[i]->Type(),
                trackInfo[i]->Language());
        }
        return *this;
    }
};

typedef void (*BurnProc) (void *Data);

extern const char *BurnStates[__STATE_COUNT__];
extern const char *DiskTypes[__TYPE_COUNT__];
extern const char *StoreModes[__STORE_COUNT__];
extern const char *BurnModes[__MODE_COUNT__];
extern const char *ChaptersModes[__CHAPTERS_COUNT__];

extern const char *TitleChars;

class cRecording;

uint64_t ScanRecordingSize(const char *FileName, eDiskType dt);
int ScanPageCount(const char *Path);
uint64_t FileSize(const char *FileName);
const char *FileType(const char *FileName);
const char *ProgressBar(double Current, double Total, int Length = 20);

const tTrackInfoArray & FindTitleTracks(const char *Path);

char *EscapeLatin1toUTF8(const char *Text);
char *Convert2UTF8(const char *Text);

#endif // VDR_BURN_COMMON_H
