#ifndef AVIFILE_UTILS_H
#define AVIFILE_UTILS_H

#include <default.h>

/**
 *  Utility functions.
 *    plain C functions are here
 */


/**
 *  These two functions return number of ticks ( processor cycles )
 *   since power-on. Return value of first one wraps around each
 *   few seconds ( depends on processor ), but calculations with
 *   32-bit 'int' are a bit faster than with 64-bit 'int64_t'.
 *  They can be used for very precise and fast measurement of time
 *   intervals - call to localcount() takes less than 0.2us on 500
 *   MHz processor, and its resolution is measured in nanoseconds.
 *   On systems with properly configured Linux kernel they can be 
 *   used as 3-4 times faster alternative to gettimeofday() 
 *   because they do not require a trip to kernel and back.
 *   On other systems they will probably be even more efficient.
 *  For processors without time-stamp counter feature ( a few
 *   old Pentium-compatible models by Cyrix and maybe others )
 *   these functions are emulated using gettimeofday().
 */

extern unsigned int (*localcount)(void);
extern int64_t (*longcount)(void);

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* A thread-save usec sleep */
int avi_usleep(unsigned long);

void memory_lock_init(void);
void memory_lock(void);
void memory_unlock(void);

const char* fcc_type(fourcc_t fcc);
const char* wave_type(short fmt); // not sure - will be special type

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* AVIFILE_UTILS_H */
