datasrc.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 165 行

H
165
字号
/*******************************************************************
 * 
 *  Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
 *
 *  Description: 
 *
 *  Author: Amlogic Software
 *  Created: Fri Nov 11 00:18:01 2005
 *
 *******************************************************************/
#ifndef DATASRC_H
#define DATASRC_H

/** @file datasrc.h */
/** @defgroup APP_DATASRC_API Application data source */
/** @addtogroup APP_DATASRC_API */
/*@{*/

typedef enum {
    SRC_UNKNOWN = 0,
    SRC_LOCAL,
    SRC_HTTP,
    SRC_BTFTP,
    SRC_MEMORY,
    SRC_BTOPP
} DataSrcType;

typedef struct __dsrc_mem{
	char  magic[11];
	void * data;
	unsigned len;
}MemoryDataSrc;

typedef struct {
    unsigned            handle;                 /* data handle */
    unsigned char      *streaming_buf;          /* streaming buffer for network play */
    unsigned            streaming_buf_size;     /* streaming buffer size */
    unsigned            streaming_oft;          /* streaming offset */
    OS_EVENT           *streaming_sem;          /* http callback sem for block reading, todo: non_blocking */
    char               *streaming_data;         /* async http data pointer */
    int                 streaming_req_size;     /* async http data size */
    unsigned char      *last_read_data;         /* last read buffer address for clean up */

    struct DataOpt_s   *src;                    /* data source operations */ 
    target_src_request  src_req;                /* target request */
} DataSrc_t;

typedef int  (*DataSrcAcceptFunc)(char *name);
typedef int  (*DataSrcCreateFunc)(DataSrc_t *data, char *name, unsigned arg, unsigned context);
typedef int  (*DataSrcReadFunc)(DataSrc_t *data, void *buf, unsigned size);
typedef int  (*DataSrcRead4TargetFunc)(DataSrc_t *data, unsigned size);
typedef void (*DataSrcReadCleanupFunc)(DataSrc_t *data);
typedef int  (*DataSrcSeekFunc)(DataSrc_t *data, long offset, int fromwhere);
typedef void (*DataSrcDestroyFunc)(DataSrc_t *data);
    
struct DataOpt_s {
    DataSrcType             data_type;
    DataSrcAcceptFunc       data_accept;    
    DataSrcCreateFunc       data_create;    
    DataSrcReadFunc         data_read;    
    DataSrcRead4TargetFunc  data_read4target;    
    DataSrcReadCleanupFunc  data_readcleanup;    
    DataSrcSeekFunc         data_seek;    
    DataSrcDestroyFunc      data_destroy;
    struct DataOpt_s       *next;
};
typedef struct DataOpt_s DataOpt_t;

extern void DataSrcAdd(DataOpt_t *new_src);

/**
 * Create an application data source port.
 *
 * @param [in]  data    pointers to pre-allocated DataSrc_t structure.
 * @param [in]  name    the filename or url to the data streams, like:
 *                      "http://abc.com/abc.mp3" or "c:\abc\abc.mp3",
 *                      note that HTTP data source must be enabled by
 *                      DataSrcEnableHTTP and only local file system
 *                      data source is enabled by default.
 * @param [in]  type    the type of name, if SRC_UNKNOWN is specified,
 *                      the type will be guessed from name.
 * @param [in]  arg     for different type of data source, the argument
 *                      has different meanings. If the data source is
 *                      SRC_LOCAL, the argument has no meanings; if the data
 *                      source is SRC_HTTP, then the argument specify the
 *                      streaming buffer then the data source will use.
 * @param [in]  context If the data source is SRC_LOCAL, context is NULL, if
 *                      the data source is SRC_HTTP, context is the application
 *                      callback to indicate that the reading operation is
 *                      interrupted by user opertion
 * @return TRUE on successful and FALSE on failed case.
 */
extern int  DataSrcCreate(DataSrc_t *data, char *name, DataSrcType type, unsigned arg, unsigned context);

/**
 * Enable HTTP network data source.
 */
extern void DataSrcEnableHTTP();

/**
 * Read data from data port to an assigned data buffer.
 *
 * @param [in]  data    pointers to data source handle.
 * @param [in]  buf     points to the read back data
 * @param [in]  size    the size of data to read
 * @return >0, the real number of bytes read back
 * @return =0, EOF
 * @return <0, An error happened during read operations.
 */
extern int  DataSrcRead(DataSrc_t *data, void *buf, unsigned size);
extern int  DataSrcRead_8M(DataSrc_t *data, void *buf, unsigned size);

/**
 * Read data to memory and prepare the target source descriptor
 * to transfer data to target device.
 *
 * @param [in]  data    pointers to data source handle.
 * @param [in]  size    the size of data to read
 * @return >0, the real number of bytes read back
 * @return =0, EOF
 * @return <0, An error happened during read operations.
 * @note    The data read by DataSrcRead4Target are stored in memory
 *          which is allocated/managed by source data port itself; a
 *          corresponding DataSrcReadCleanup should be called in pair
 *          to free the possible allocated memory after the data is
 *          transfered to target device.
 */
extern int  DataSrcRead4Target(DataSrc_t *data, unsigned size);
extern int  DataSrcRead4Target_8M(DataSrc_t *data, unsigned size);

/**
 * Free the possible allocated memory by DataSrcRead4Target. 
 *
 * @param [in]  data    pointers to data source handle.
 */
extern void DataSrcReadCleanup(DataSrc_t *data);

/**
 * Seek to an offset of the data source.
 *
 * @param [in]  data        pointers to data source handle.
 * @param [in]  offset      offset to a point which is defined by fromwhere parameter
 * @param [in]  fromwhere   SEEK_SET from start, SEEK_CUR from current read position 
 *                          and SEEK_END to the end of the data.
 * @return >=0  current offset of the data with 0 from the beginning.
 * @return <0  an error happened during seek operations. The seek value may exceed the 
 *              allowed range.
 */
extern int  DataSrcSeek(DataSrc_t *data, long offset, int fromwhere);
extern int  DataSrcSeek_8M(DataSrc_t *data, long offset, int fromwhere);

/**
 * Release the data source and close any possible network connection or
 * file handlers underneath.
 *
 * @param [in]  data        pointer to data source handle.
 */
extern void DataSrcDestroy(DataSrc_t *data);

/*@}*/

extern void DataSrcEnableMemory();
extern unsigned memory_8m_buffer_enable;
#endif /* DATASRC_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?