/*****************************************************************************/
/* 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   */
/*                                                                           */
/*****************************************************************************/
/*
 * gsttiquicktime_h264.h
 *
 * This file declares structure and macro used for creating byte-stream syntax
 * needed for decoding H.264 stream demuxed via qtdemuxer.
 *
 * Original Author:
 *     Brijesh Singh, Texas Instruments, Inc.
 *
 * Copyright (C) $year Texas Instruments Incorporated - http://www.ti.com/
 *
 * This program 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 version 2.1 of the License.
 * whether express or implied; without even the implied warranty of *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */
/*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
1   20090205    laird       First Version
2   20090313    laird       Stopping wasteful memcpys
--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.
*/
#ifndef __GST_STB22XFRAMEDVIDEO_H264_H__
#define __GST_STB22XFRAMEDVIDEO_H264_H__

/**************************************************************
* INCLUDE FILES                                               *
***************************************************************/
#include <gst/gst.h>

/**************************************************************
* EXPORTED MACROS                                             *
***************************************************************/
/* Get version number from avcC atom  */
#define AVCC_ATOM_GET_VERSION(header,pos) \
    GST_BUFFER_DATA(header)[pos]

/* Get stream profile from avcC atom  */
#define AVCC_ATOM_GET_STREAM_PROFILE(header,pos) \
    GST_BUFFER_DATA(header)[pos]

/* Get compatible profiles from avcC atom */
#define AVCC_ATOM_GET_COMPATIBLE_PROFILES(header,pos) \
    GST_BUFFER_DATA(header)[pos]

/* Get stream level from avcC atom */
#define AVCC_ATOM_GET_STREAM_LEVEL(header,pos) \
    GST_BUFFER_DATA(header)[pos]

/* Get NAL length from avcC atom  */
#define AVCC_ATOM_GET_NAL_LENGTH(header,pos) \
    (GST_BUFFER_DATA(header)[pos] & 0x03) + 1

/* Get number of SPS from avcC atom */
#define AVCC_ATOM_GET_NUM_SPS(header,pos) \
    GST_BUFFER_DATA(header)[pos] & 0x1f

/* Get SPS length from avcC atom */
#define AVCC_ATOM_GET_SPS_NAL_LENGTH(header, pos) \
    GST_BUFFER_DATA(header)[pos] << 8 | GST_BUFFER_DATA(header)[pos+1]

#define AVCC_ATOM_GET_PPS_NAL_LENGTH(header, pos) \
    GST_BUFFER_DATA(header)[pos] << 8 | GST_BUFFER_DATA(header)[pos+1]

/* Get number of PPS from avcC atom */
#define AVCC_ATOM_GET_NUM_PPS(header,pos) \
    GST_BUFFER_DATA(header)[pos]

/* Get PPS length from avcC atom */
#define AVCC_ATOM_GET_PPS_LENGTH(header,pos) \
    GST_BUFFER_DATA(header)[pos] << 8 | GST_BUFFER_DATA(header)[pos+1]

/**************************************************************
* EXPORTED TYPEDEFS                                           *
***************************************************************/

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

/**************************************************************
* EXPORTED FUNCTION PROTOTYPES                                *
***************************************************************/
/** Function to check if we have valid avcC header */
int gst_stb22x_framed_video_valid_quicktime_header (GstBuffer *buf);

/** Function to read sps and pps data field from avcc header */
GstBuffer* gst_stb22x_framed_video_get_sps_pps_data (GstBuffer *buf);

/** Function to read NAL length field from avcc header */
guint8 gst_stb22x_framed_video_get_nal_length (GstBuffer *buf);

/** Function to get number of es buffers in a NAL.*/
gint gst_stb22x_framed_video_get_num_es_buffers (GstBuffer *buf,
                                                 guint8 nal_length);

/** Function to get predefind NAL prefix code */
GstBuffer* gst_stb22x_framed_video_get_es_prefix_code (void);

/** Function to parse input stream and create vector list for writev */
gboolean gst_stb22x_framed_video_parse_and_create_buffer (GstBuffer *buf,
                                                          GstBuffer *es_code_prefix,
                                                          guint8 nal_length,
                                                          struct iovec** pIov);

#endif /* __GST_STB22XFRAMEDVIDEO_H264_H__ */

