
#ifndef CLASSDATA_H
#define CLASSDATA_H 1
/*
**
**  $VER: classdata.h 1.2 (17.11.97)
**  mpegsystem.datatype 1.2
**
**  mpegsystem.datatype class data
**
**  Written 1997 by Roland 'Gizzy' Mainz
**
*/

/*****************************************************************************/
/* MPEG system stream related structures */

/* Header lengths (in bytes) */
#define START_CODE_LENGTH         (4)
#define PACK_HEADER_LENGTH        (8)
#define SYSTEM_HEADER_LENGTH     (14)
#define PACKET_LENGTH_LENGTH      (2)

/* ISO stream codes seen */
#define PACK_START_CODE           (1)
#define SYSTEM_START_CODE         (2)
#define ISO_11172_END_CODE        (3)

#define MAX_MPEG_STREAMS (48)

/* Stream level information on required buffer size */
typedef struct Stream
{
   UBYTE stream_id;
   long  STD_buffer_bound_scale;      /* defined in ISO 11172 */
   long  STD_buffer_size_bound;
} STREAM;

/* Pack header information structure*/
typedef struct Pack_header
{
   long SCR;
   long mux_rate;                     /* defined in ISO 11172 */
} PACK_header;

/* System header information structure*/
typedef struct System_header
{
    ULONG  header_length;
    long   rate_bound;                 /* defined in ISO 11172 */
    long   audio_bound;
    BOOL   fixed_flag;
    BOOL   CSPS_flag;
    BOOL   system_audio_lock_flag;
    BOOL   system_video_lock_flag;
    long   video_bound;
    STREAM STD_buffer_info[ MAX_MPEG_STREAMS ];
} SYSTEM_header;

/* Packet header information structure*/
typedef struct Packet_header
{
   UBYTE  stream_id;
   ULONG  packetlength;
   long   STD_buffer_scale;    /* defined in ISO 11172 */
   long   STD_buffer_size;
   long   PTS;
   long   DTS;
   UBYTE *packet_ptr;
} PACKET_header;

/*****************************************************************************/

#define MAX_DATA_BUF_LEN (65536UL)

/* This node holds file offset and size of a single system stream packet */
struct PacketBlock
{
    struct MinNode node;
    long           system_offset; /* file offset in system stream */
    long           length;        /* packet length */
};

/* A single stream */
struct StreamList
{
    BPTR                sl_handle;           /* System-stream handle      */
    LONG                sl_size;             /* Full size of our stream   */
    struct MinList      sl_packetblocklist;  /* List of packets referring to this particular stream */
};


/*****************************************************************************/
/* Handler specific structures */

/* FileHandle context */
struct StreamHandle
{
    struct StreamList *sl;
    LONG               currpos;      /* Current file position   */
};

/* Startup message for demux process */
struct StartupMsg
{
    struct Message             sm_Message; /* Embedded exec message */
    UWORD                      sm_Pad0;
    struct ClassBase          *sm_CB;      /* Pointer to the class library base */
    struct MPEGSystemInstData *sm_msid;    /* Pointer to the instance data */
};

/*****************************************************************************/

/* mpegsystem.datatype class instance data */
struct MPEGSystemInstData
{
    /* Misc */
    struct SignalSemaphore  msid_SigSem;          /* Instance data lock                      */
    UWORD                   msid_Pad0;
    APTR                    msid_Pool;
    STRPTR                  msid_ProjectName;     /* Shortcut to DTA_Name                    */
    BPTR                    msid_VerboseOutput;   /* Verbose output                          */

    /* Prefs */
    BOOL                    msid_DoSyntax;
    BOOL                    msid_DoDebug;
    BOOL                    msid_IgnoreErrors;
    UWORD                   msid_Pad1;

    /* Video stream related */
    Object                 *msid_CurrVideo;
    ULONG                   msid_TicksPerFrame;

    /* Audio stream related */
    Object                 *msid_CurrAudio;
    UBYTE                  *msid_Sample;
    ULONG                   msid_SampleLength;
    ULONG                   msid_Period;
    ULONG                   msid_SamplesPerFrame;

    /* Virtual stream splitter handler */
    struct
    {
      struct StartupMsg  Startup;
      struct Process    *Process;
      LONG               OpenCount;
    } Handler;

    /* Demultiplexer scan context */
    struct
    {
      jmp_buf           exit_buf;
      LONG              retval,
                        retval2;

      BOOL              system_found; /* get_next_start_code static */

      long              curr_file_pos;
      UBYTE            *curr_file_pos_in_buffer;

      UBYTE            *raw_data_buf;
      UBYTE            *raw_data_buf_ptr;
      long              raw_data_buf_len;
      BPTR              fdin;
      long              M,
                        N;

      struct StreamList fd_demuxa[ MAX_MPEG_STREAMS ];
    } Demux;
};


/*****************************************************************************/

#endif /* !CLASSDATA_H */

