loader.c 加载文件

用法

Loader_Handle Loader_create(Char *fileName, Loader_Attrs *attrs);/*创建loader*/
Int Loader_prime(Loader_Handle hLoader, Buffer_Handle *hBufPtr);/*读第一帧*/
Int Loader_readData(Loader_Handle hLoader);/*读帧*/

 关键结构体

/* Internal object holding the state of the Loader */
typedef struct Loader_Object {/*Loader.c*/
Buffer_Handle hBuf;
Buffer_Handle hReadBuffer;
Sem_Handle semStart;
Sem_Handle semLock;
Sem_Handle semWait;
Sem_Handle semRead; /* a read is on-going */
Int32 readSize;
Int32 readAhead;
FILE *file;
Int8 *w; /* Where new data is written */
Int8 *r1; /* Start of data to be read */
Int8 *r2; /* End of data to be read */
Char *vBuf;
Int flush;
Int end;
Int async;
Int readerWaiting;
UInt32 vBufSize;
Memory_AllocParams mParams;
Bool started;
} Loader_Object;

typedef struct Loader_Object *Loader_Handle;/*Loader.h*/
/*由此分析Loader_Handle是一个管理Loader的句柄*/

/*这里还有一个非常重要的结构体Buffer_Handle,用来管理buffer的,dm365所有的codec数据通信都其于这个结构体
*/


/**
* @brief Handle through which to reference a Buffer instance.
*/
typedef struct _Buffer_Object *Buffer_Handle;

typedef struct _Buffer_Object {
Buffer_Type type;
_Buffer_State origState;
_Buffer_State usedState;
Memory_AllocParams memParams;
Int8 *userPtr;
Int32 physPtr;
Int id;
Bool reference;
BufTab_Handle hBufTab;
Int32 virtualBufferSize;
} _Buffer_Object;

由于Loader的内存分配是基于Buffer_Handle的,要重点理解Buffer_Handle的创建方法

/**
* @brief Creates and allocates a contiguous Buffer.
*
* @param[in] size Size in bytes of buffer to create.
* @param[in] attrs #Buffer_Attrs to use for creating the Buffer.
*
* @retval Handle for use in subsequent operations (see #Buffer_Handle).
* @retval NULL for failure.
*/
extern Buffer_Handle Buffer_create(Int32 size, Buffer_Attrs *attrs);

显然Int32 size表示缓存大小,Buffer_Attrs *attrs 就是该Buffer_Handle的相关参数,Buffer_Attrs的定义,重点关注memParams,Memory_type

/**
* @brief Attributes used when creating a Buffer instance.
* @see Buffer_Attrs_DEFAULT
*/
typedef struct Buffer_Attrs {
/**
* @brief Parameters used to allocate the buffer using the Codec Engine
* OSAL Memory module.
* @see Buffer_Memory_Params_DEFAULT
*/
Memory_AllocParams memParams;

/**
* @brief The type of buffer to allocate.
* @see Buffer_Type
* @see Buffer_getType
*/
Buffer_Type type;

/**
* @brief The mask to indicate that a buffer is busy in a BufTab (a
* useMask value of 0 indicates a free buffer). Using a flexible mask
* allows multiple "owners" of a buffer (e.g. codec and display device
* driver).
* @see Buffer_setUseMask
* @see Buffer_getUseMask
* @see Buffer_freeUseMask
* @see Buffer_resetUseMask
*/
UInt16 useMask;

/**
* @brief If this is set to true no buffer will be allocated, instead
* the resulting #Buffer_Handle will be a reference to an already existing
* memory area (@see #Buffer_setUserPtr and #Buffer_setSize).
*/
Bool reference;
} Buffer_Attrs;
/**
* @brief Parameters for Memory_alloc() & Memory_free()
*
* @sa Memory_DEFAULTPARAMS
*/
typedef struct Memory_AllocParams {
Memory_type type; /**< Type of allocation
*
* @sa Memory_type
*/
UInt flags; /**< Flags affecting allocation.
*
* @sa Memory_CACHED
* @sa Memory_NONCACHED
*/
UInt align; /**< Alignment of allocation. */
UInt seg; /**< Segment for allocation. */
} Memory_AllocParams;
/**
* @brief Enum values for Memory_AllocParams.type
*
* @sa Memory_AllocParams
*/
typedef enum {
Memory_MALLOC = 0, /**< malloc()-based allocation */
Memory_SEG = 1, /**< DSP/BIOS segment-based allocation */
Memory_CONTIGPOOL = 2, /**< Contiguous, pool-based allocation */
Memory_CONTIGHEAP =3 /**< Contiguous, heap-based allocation */
} Memory_type;



显然 Memory_type表示内存的分配方法,这个关系到物理地址的分配,如果是Memory_MALLOC,则用malloc分配内存,虽然虚拟地址是连续的,但这时的内存在物理上可能不是连续的,但对于dm365的DMA来说,只有物理地址而没有虚拟地址,需要连续的物理地址,这时Memory_type 得用Memory_CONTIGPOOL.

 

 




 



posted on 2011-12-22 15:42  林德伟  阅读(672)  评论(0编辑  收藏  举报