/******************************************************************************
Copyright (c) 2006 Analog Devices, Inc.  All Rights Reserved.  This software is
proprietary and confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************

$Revision: 1.1 $
$Date: 2008/03/27 03:03:18 $
$LastChangedBy: cjakob $

Project:    MP4 ADTS Indexer
Title:      MP4 ADTS Indexer
Author:     CFJ

Description:
            MP4 ADTS Indexer library header

References:
            None

******************************************************************************/
#ifndef __ADI_AACI_INDEXER_H__
#define __ADI_AACI_INDEXER_H__

///////////////
// Macros

// Instance memory object sizes required
#define ADI_AACI_FASTB0_PRIO0_STATE_MEM_NUMBYTES   (1060) 	// >= sizeof(adi_aaci_t)

// Maximum number of time indices tracked before being culled
#define ADI_AACI_MAX_NUM_INDICES					(128)			


//////////////////
// enums
typedef enum
{
	ADI_AACI_INVALID_BITSTREAM		= -100, 
	ADI_AACI_SUCCESS 				= 0,
	ADI_AACI_OPERATION_FAILED		= 10,	
	ADI_AACI_INVALID_CONFIG_PARAMS	= 11,
	ADI_AACI_NEED_MORE_DATA 		= 100	 
} adi_aaci_return_code_t;


//////////////////
// Typedefs
typedef struct 						adi_aaci_t adi_aaci_t;		// Instance
typedef unsigned char 				adi_aaci_bitstream_data_t;
typedef unsigned int 				adi_aaci_time_t;			// Time in milliseconds


//////////////////
// API structures
// Pointers to memory pools that need to be passed to the indexer on creation
typedef struct 
{
    struct
    {
        void *prio0;
    } fastb0;	
} adi_aaci_state_mem_t;

typedef struct 
{
    // empty data struct - this module does not require any temporary scratch memory per instance
} adi_aaci_scratch_mem_t;

typedef struct 
{
	adi_aaci_state_mem_t 	state;
	adi_aaci_scratch_mem_t	scratch;
} adi_aaci_mem_t;

typedef struct 
{
	adi_aaci_bitstream_data_t* 	circular_buffer_base;
	int 						circular_buffer_length;
	unsigned int				use_circular_bitstream_buffer;	
} adi_aaci_config_t;

typedef struct 
{
	unsigned int				stream_offset;				// Current Stream offset (if seeking forward); OR Desired Stream Offset (when seek is done)
	adi_aaci_time_t				milliseconds;				// Current time (ms) if seeking forward; OR Time corresponding to Desired stream offset
	unsigned int				num_input_bytes_consumed;	// Number of bytes parsed when seeking forward
	adi_aaci_bitstream_data_t	*unconsumed_input_data_ptr;	// Pointer to next unconsumed byte
} adi_aaci_output_status_t;


//////////////////
// Indexer API Prototypes
#if defined(__cplusplus) 
extern "C" { /* this is added to support integration into C++ systems */
#endif

adi_aaci_t* adi_aaci_create (
	adi_aaci_mem_t 	*memory
);

adi_aaci_return_code_t adi_aaci_init (
	adi_aaci_t *instance,
	adi_aaci_config_t 		*config_params
);

adi_aaci_return_code_t adi_aaci_indexer (
    adi_aaci_t 					*instance_handle,
    adi_aaci_time_t 			milliseconds,
    int				 			stream_byte_offset
);

adi_aaci_return_code_t adi_aaci_seek (
    adi_aaci_t 					*instance_handle,
    adi_aaci_time_t 			seek_milliseconds,
    adi_aaci_time_t 			milliseconds,     
    int				 			stream_byte_offset,       
    int 						num_input_bytes,
    adi_aaci_bitstream_data_t 	*input_bitstream,
    adi_aaci_output_status_t 	*indexer_status
);

#if defined(__cplusplus) 
}
#endif

#endif // __ADI_AACI_INDEXER_H__


