/*
 * Copyright 2010 Trident Microsystems (Far East) Ltd. All rights reserved.
 * All prior copyright rights in this work and the accompanying software
 * products transferred to Trident Microsystems (Far East) Ltd. by written
 * agreement.
 */
/*****************************************************************************/
/* Copyright (c) 2010 NXP B.V.  All rights are reserved.                     */
/*                                                                           */
/* Redistribution and use in source and binary forms, with or without        */
/* modification, are permitted provided that the following conditions        */
/* are met:                                                                  */
/*                                                                           */
/* Redistributions of source code must retain the above copyright            */
/* notice, this list of conditions and the following disclaimer.             */
/*                                                                           */
/* Redistributions in binary form must reproduce the above copyright         */
/* notice, this list of conditions and the following disclaimer in the       */
/* documentation and/or other materials provided with the distribution.      */
/*                                                                           */
/* Neither the name of NXP nor the names of its                              */
/* contributors may be used to endorse or promote products derived from      */
/* this software without specific prior written permission.                  */
/*                                                                           */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     */
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     */
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE         */
/* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH          */
/* DAMAGE.                                                                   */
/*                                                                           */
/*****************************************************************************/
/*
 * Module name  : tmAvFormats.h  %version: SOUsb225#2 %
 *
 * Last Update  : %date_modified: Tue Jul  8 18:07:50 2003 %
 *
 * Description: This header file contains the standard enumerations, types, and
 * structures used for the DVP audio and video software streams.
 *
 * TriMedia audio and video format definitions. The definitions in this file are
 * fundamental to the TM Software Streaming Architecture (TSSA).
 *
 * Document ref: DVP Coding Guidelines Specification
 *
 *############################################################
 */

#ifndef TMAVFORMATS_H
#define TMAVFORMATS_H

#define _TMAVFORMATS_H_ /*disable <tm1/tmAvFormats.h>*/

//-----------------------------------------------------------------------------
// Standard include files:
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// Project include files:
//-----------------------------------------------------------------------------
//
#ifndef TMNXTYPES_H
#include "tmNxTypes.h"
#endif

//{{DVI
typedef struct tmXY           // Definition of common x/y coordinate
{
    Int32   x;
    Int32   y;
} tmXY_t, *ptmXY_t;

typedef struct tmRect         // Definition of common rectangle
{
    tmXY_t  ul;                 // upper left is inside rectangle
    tmXY_t  lr;                 // lower right is _outside_
} tmRect_t, *ptmRect_t;
//}}

typedef enum tmComponentClass {
    ccClock,
    ccSystemDecoder,
    ccVideoDecoder,
    ccVideoEncoder,
    ccVideoRenderer,
    ccVideoDigitizer,
    ccVideoTransform,
    ccAudioDecoder,
    ccAudioEncoder,
    ccAudioRenderer,
    ccAudioDigitizer,
    ccAudioTransform,
    ccGraphics2D,
    ccGenericIn,
    ccGenericOut,
    ccUnion,
    ccSubsystem
} tmComponentClass_t;                        /* mutually exclusive */

/* Audio, Video etc. format class definitions */
/* These should NOT be or'ed                  */
typedef enum tmAvDataClass {
    avdcGeneric             = (Int) 0xffffffffu,
    avdcSystem              = 0x00000001,
    avdcVideo               = 0x00000002,
    avdcAudio               = 0x00000004,
    avdcControl             = 0x00000008,

//{{DVI
    avdcDraw                = 0x00000010,
    avdcVideoOutStream      = 0x00000020,
    avdcAuxVideoData        = 0x00000040     // new auxiliary data class
//}}
} tmAvDataClass_t;                           /* can NOT be or'ed */

typedef enum tmAvDataType {
    avdtGeneric             = (Int) 0xffffffffu,
    avdtNone                = (Int) 0x80000000u
} tmAvDataType_t;

typedef enum tmAvDataSubtype {
    avdsGeneric             = (Int) 0xffffffffu,
    avdsNone                = (Int) 0x80000000u
} tmAvDataSubtype_t;

typedef enum tmAvClock {  /* these are not currently used */
    clockMPEG_90KHz,
    clockMICROSECONDS,
    clockSMPTE_23_976,
    clockSMPTE_24,
    clockSMPTE_25,
    clockSMPTE_29_97,
    clockSMPTE_30,
    clockSMPTE_50,
    clockSMPTE_59_94,
    clockSMPTE_60
} tmAvClock_t;

//{}DVI tmTimestamp_t moved to tmtypes.h

/* This is tmAvFormat superclass.  Its subclasses follow */
#define tmAvFormatVARIABLES \
    UInt16          size;   \
    UInt16          hash;           /* not to be used by components */  \
    UInt32          referenceCount; /* not to be used by components */  \
    tmAvDataClass_t dataClass;  \
    UInt32          dataType;   \
    UInt32          dataSubtype;    \
    UInt32          description \

typedef
    struct tmAvFormat
    {
        tmAvFormatVARIABLES;
    }
    tmAvFormat_t, *ptmAvFormat_t;

/* user flags of header->flags */
#define tmAvHeaderFlagsUserMask         ((Int) 0xff000000u)
/* TSSA flags of header->flags */
#define tmAvHeaderFlagsTSSAMask         0x00f00000
/* cleared flags on each DataIn putEmpty */
#define tmAvHeaderFlagsTSSAClearMask    0x000000ff

typedef enum tmAvHeaderFlags {
    avhNone                    = 0x00000000,
    avhValidTimestamp          = 0x00000001,
    avhPacketContainsError     = 0x00000002,
    avhValidDts                = 0x00000004,
    avhField1                  = 0x00000008,
    avhField2                  = 0x00000010,
    avhPacketContainsStartCode = 0x00000020,
    avhPacketNewStream         = 0x00000040,
    avhNewTimeOffset           = 0x00000080,
    avhPesPacketStart          = 0x00000100,
    avhPesPacketEnd            = 0x00000200,

    /* tssa reserved bits <23..20> */
    avhValidReferenceCount     = 0x00100000

    /* user reserved bits <31..24> */
} tmAvHeaderFlags_t;

/* use this tmAvHeaderFieldId_t to define top/bottom field in above enum */
typedef enum tmAvHeaderFieldId {
    avhFieldTop                = 0x00000000,
    avhFieldBottom             = avhField2
} tmAvHeaderFieldId_t;

/* this is tmAvHeader superclass, but we don't know of any subclasses yet */

typedef struct tmAvHeader {
    UInt16          id;           /* read only */
    UInt8           refCount;     /* used for tee-ing and user mistake trapping */
    UInt32          flags;        /* read only to receiver */
    Pointer         userSender;   /* reserved for an user sender. read only to receiver. */
    Pointer         userReceiver; /* reserved for an user receiver. read only to sender. */
    Pointer         userPointer;  /* reserved for an user. read/write on both ends. */
    tmTimeStamp_t   time;         /* time stamp */
    Pointer         format;       /* subclass of tmAvFormat_t */
} tmAvHeader_t, *ptmAvHeader_t;

typedef struct tmAvBufferDescriptor {
    UInt32             bufSize;
    UInt32             dataSize;
    Pointer            data;
    UInt32             address; //{}DVI !!new structure member
} tmAvBufferDescriptor_t, *ptmAvBufferDescriptor_t;

//{{DVI Flexible array macros
typedef struct tmAvPacket tmAvPacket_t, *ptmAvPacket_t;

#define tmAvPacketVARIABLES(N)                                                 \
    ptmAvHeader_t          header;                                             \
    UInt16                 allocatedBuffers;                                   \
    UInt16                 buffersInUse;                                       \
    tmAvBufferDescriptor_t buffers [N]                                         \

struct tmAvPacket
{
    tmAvPacketVARIABLES (1);
};

#define tmAvPacket(N)                                                          \
    struct                                                                     \
    {                                                                          \
       tmAvPacketVARIABLES (N);                                                \
    }                                                                          \

//This macro requires <stdlib.h>
#define tmAvPacketSIZE(N)                                                      \
    (offsetof (tmAvPacket_t, buffers) +                                        \
            (N)*sizeof ((ptmAvPacket_t) Null)->buffers)                        \
//}}

//{{DVI
// NOTE: format type list points to arrays of class ,type, and subtype
//       (format i is described by entry i in every array)
typedef struct tmAvFormatTypeList {
    UInt32             nrOfElements;    // number of elements in list
    tmAvDataClass_t   *dataClass;       // ptr to array of data classes
    UInt32            *dataType;        // ptr to array of data types
    UInt32            *dataSubtype;     // ptr to array of subtypes
} tmAvFormatTypeList_t, *ptmAvFormatTypeList_t;
//}}

#ifndef TMSYSTEMFORMATS_H
#include "tmSystemFormats.h"
#endif

#ifndef TMAUDIOFORMATS_H
#include "tmAudioFormats.h"
#endif

#ifndef TMVIDEOFORMATS_H
#include "tmVideoFormats.h"
#endif

#endif
