/*
 * cdda_lib.h: The data mangle functions
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: cdda_lib.h,v 1.1.1.4 2005/06/27 13:34:02 cm Exp $
 */

#ifndef __CDDALIB_H
#define __CDDALIB_H

#include <sys/types.h>
#include <cdio/cdtext.h>
#include <cdio/cdio.h>

#define PES_MAX_PACKSIZE            2048

#define PES_HEADER_LEN              9
#define PES_EXT_HEADER_LEN          3
#define LPCM_HEADER_LEN             7

class cReferenceCounter {
  private:
    int refCount;
  public:
    cReferenceCounter();
    ~cReferenceCounter();
    int RefCount(void) { return refCount; };
    int RefIncr(void);
    int RefDecr(void);
};

class cDataMangler {
  public:
    cDataMangler();
    ~cDataMangler();
    bool Swap16(uint8_t data[], uint32_t length);
    bool Conv16_sign(uint8_t data[], uint32_t length, bool bigendian);
};

class cEncapsulator {
  private:
    uint8_t pcmChannels;
    uint8_t pcmFrequency;
    uint8_t pesStreamId;
    uint16_t pesFlags;
    uint8_t buffer[PES_MAX_PACKSIZE];
    uint8_t *p_offset;
  public:
    cEncapsulator();
    ~cEncapsulator();
    int Data(uint8_t *payload, int length);
    void SetPcmParameters(uint8_t channels, uint16_t frequency);
    int ToPcm(uint8_t **packet);
    void SetPesParameters(uint8_t streamId, uint16_t flags);
    int ToPes(uint8_t **packet);
};

#endif
