/*****************************************************************************/
/* Copyright (c) 2009 NXP B.V.                                               */
/*                                                                           */
/* This library is free software; you can redistribute it and/or             */
/* modify it under the terms of the GNU Lesser General Public                */
/* License as published by the Free Software Foundation, using               */
/* version 2.1 of the License.                                               */
/*                                                                           */
/* This library is distributed in the hope that it will be useful,           */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU          */
/* Lesser General Public License for more details.                           */
/*                                                                           */
/* You should have received a copy of the GNU Lesser General Public          */
/* License along with this library; if not, write to the Free Software       */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   */
/*                                                                           */
/*****************************************************************************/

#ifndef __GST_STB22X_FRAMED_AUDIO_UTILS_H__
#define __GST_STB22X_FRAMED_AUDIO_UTILS_H__

/**************************************************************
* INCLUDE FILES                                               *
***************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "gststb22xframedaudio.h"

/**************************************************************
* EXPORTED MACROS                                             *
***************************************************************/
#define BYTE_NUMBIT 8       /* bits in byte (char) */
#define LONG_NUMBIT 32      /* bits in unsigned gint32 */

#define GST_STB22X_FRAMED_AUDIO_BIT_TO_BYTE(a) (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT)

/** Useful max macro.*/
#define GST_STB22X_FRAMED_AUDIO_READ_MAX(_a,_b)     ((_a)>(_b) ? (_a):(_b))
/** Useful min macro.*/
#define GST_STB22X_FRAMED_AUDIO_READ_MIN(_a,_b)     ((_a)>(_b) ? (_b):(_a))

/**************************************************************
* EXPORTED TYPEDEFS                                           *
***************************************************************/
typedef struct
{
    /** data bits. */
    UInt8* data;
    /* number of bits in buffer */
    gint32 numBit;
    /* buffer size in bytes */
    gint32 size;
    /*  current bit position in bit stream */
    gint32 currentBit;
    /* number of bytes read/written (only file) */
    gint32 numByte;
} GstStb22xFramedAudioBitBuffer;

/**************************************************************
* EXPORTED DATA                                               *
***************************************************************/

/**************************************************************
* EXPORTED FUNCTION PROTOTYPES                                *
***************************************************************/
/**
 * Generate a valid ADIF header to prime th AAC decoder.
 *
 */
gboolean gst_stb22x_framed_audio_generate_adif_header(GstStb22xFramedAudio *stb22xframedaudio,
                                                      GstBuffer *codec_data,
                                                      GstBuffer** pAdifHeader);

#endif /* __GST_STB22X_FRAMED_AUDIO_UTILS_H__ */
