|
|
/*
|
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2010-2019. All rights reserved.
|
|
|
* Description: queue of subtitle
|
|
|
* Author: Hisilicon
|
|
|
* Create: 2010-03-10
|
|
|
*/
|
|
|
#ifndef SO_QUEUE_H
|
|
|
#define SO_QUEUE_H
|
|
|
|
|
|
#include <unistd.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
#include <stdio.h>
|
|
|
#include <securec.h>
|
|
|
#include "td_type.h"
|
|
|
#include "uapi_so.h"
|
|
|
#include "soc_log.h"
|
|
|
|
|
|
#ifndef __MICROSYS__
|
|
|
#include "uapi_version.h"
|
|
|
#endif
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
#if __cplusplus
|
|
|
extern "C" {
|
|
|
#endif
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
#ifdef __MICROSYS__
|
|
|
extern void *ext_malloc(SOC_MOD_ID_E modId, td_u32 boundary, td_u32 size, td_bool nocache);
|
|
|
extern void ext_free(SOC_MOD_ID_E modId, void *ptr, td_bool nocache);
|
|
|
#define SO_MALLOC(size) (ext_malloc(SOC_ID_SUBT, 0, (size), TD_FALSE))
|
|
|
#define SO_FREE(ptr) \
|
|
|
do { \
|
|
|
if ((ptr != NULL)) { \
|
|
|
ext_free(SOC_ID_SUBT, (ptr), TD_FALSE); \
|
|
|
(ptr) = NULL; \
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if (UAPI_VERSION_CODE >= UAPI_VERSION(1, 0))
|
|
|
#ifndef EXT_MALLOC
|
|
|
#define EXT_MALLOC malloc
|
|
|
#endif
|
|
|
#ifndef EXT_FREE
|
|
|
#define EXT_FREE free
|
|
|
#endif
|
|
|
#define EXT_MEMSO_MALLOC(size) (EXT_MALLOC(size))
|
|
|
#define EXT_MEMSO_FREE(memAddr) (EXT_FREE(memAddr))
|
|
|
#else
|
|
|
#define EXT_MEMSO_MALLOC(size) (malloc(size))
|
|
|
#define EXT_MEMSO_FREE(memAddr) (free(memAddr))
|
|
|
#endif
|
|
|
|
|
|
#ifdef LOG_MODULE_ID
|
|
|
#undef LOG_MODULE_ID
|
|
|
#define LOG_MODULE_ID SOC_ID_SUBT
|
|
|
#endif
|
|
|
|
|
|
#ifndef EXT_PRINT
|
|
|
#define EXT_PRINT(fmt...) soc_print(fmt)
|
|
|
#endif
|
|
|
|
|
|
#if (UAPI_VERSION_CODE >= UAPI_VERSION(1, 0))
|
|
|
|
|
|
#define EXT_FATAL_SO(fmt...) soc_log_fatal(fmt)
|
|
|
#define EXT_ERR_SO(fmt...) soc_log_err(fmt)
|
|
|
#define EXT_WARN_SO(fmt...) soc_log_warn(fmt)
|
|
|
#define EXT_INFO_SO(fmt...) soc_log_info(fmt)
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#define SO_MALLOC(size) (EXT_MEMSO_MALLOC(size))
|
|
|
#define SO_FREE(ptr) \
|
|
|
do { \
|
|
|
if ((ptr) != NULL) { \
|
|
|
EXT_MEMSO_FREE((ptr)); \
|
|
|
(ptr) = NULL; \
|
|
|
} \
|
|
|
} while (0)
|
|
|
#endif
|
|
|
|
|
|
#define SO_RETURN(val, ret, printstr) \
|
|
|
do { \
|
|
|
if ((val)) { \
|
|
|
return (ret); \
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
#define SO_CALL_RETURN(val, fun, ret) \
|
|
|
do { \
|
|
|
if ((val)) { \
|
|
|
fun; \
|
|
|
return (ret); \
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
#ifdef DTV_SECUREC_SUPPORT
|
|
|
#define SO_CHK_FUN_RET_ERR(func) \
|
|
|
do { \
|
|
|
td_s32 secFunRet; \
|
|
|
secFunRet = func; \
|
|
|
if (secFunRet != TD_SUCCESS) { \
|
|
|
EXT_PRINT("Call %s return %d[0x%08X]", #func, secFunRet, secFunRet); \
|
|
|
return secFunRet; \
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>funcִ<63><D6B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>void */
|
|
|
#define SO_CHK_FUN_RET_VOID(func) \
|
|
|
do { \
|
|
|
td_s32 secFunRet = func; \
|
|
|
if (secFunRet != TD_SUCCESS) { \
|
|
|
EXT_PRINT("Call %s return %d[0x%08X]", #func, secFunRet, secFunRet); \
|
|
|
return; \
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
#else
|
|
|
#define SO_CHK_FUN_RET_ERR(func) \
|
|
|
do { \
|
|
|
func; \
|
|
|
} while (0)
|
|
|
// <20><><EFBFBD><EFBFBD>funcִ<63><D6B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>void */
|
|
|
#define SO_CHK_FUN_RET_VOID(func) \
|
|
|
do { \
|
|
|
func; \
|
|
|
} while (0)
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#define SO_SLEEP(ms) \
|
|
|
do { \
|
|
|
struct timespec _ts; \
|
|
|
_ts.tv_sec = (ms) >= 1000 ? (ms) / 1000 : 0; \
|
|
|
_ts.tv_nsec = (_ts.tv_sec > 0) ? ((ms) % 1000) * 1000000 : (ms) * 1000000; \
|
|
|
(td_void) nanosleep(&_ts, NULL); \
|
|
|
} while (0)
|
|
|
|
|
|
#define SO_NORMAL_BUFF_SIZE 1024
|
|
|
|
|
|
typedef td_void *SO_QUEUE_HANDLE;
|
|
|
typedef uapi_so_subtitle_info SO_INFO_S;
|
|
|
|
|
|
/**
|
|
|
\brief create queue
|
|
|
\attention \n
|
|
|
if the size of used buffer is larger than bufsize and the number of node is larger than maxNodeNum, then
|
|
|
can not put node in queue.
|
|
|
\param[in] bufsize bytes of the queue
|
|
|
\param[in] maxNodeNum max number of node in the queue
|
|
|
\param[out] handle handle of the queue
|
|
|
|
|
|
\retval ::TD_SUCCESS if success
|
|
|
\retval ::TD_FAILURE no memory
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueueInit(td_u32 bufsize, td_u32 maxNodeNum, SO_QUEUE_HANDLE *handle);
|
|
|
|
|
|
/**
|
|
|
\brief destroy the queue
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
|
|
|
\retval ::TD_SUCCESS success
|
|
|
\retval ::TD_FAILURE queue no exist
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueueDeinit(SO_QUEUE_HANDLE handle);
|
|
|
|
|
|
/**
|
|
|
\brief free the node in the queue
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
\param[in] info node info
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_void SO_QueueFree(SO_QUEUE_HANDLE handle, const SO_INFO_S *info);
|
|
|
|
|
|
/**
|
|
|
\brief get a node
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
\param[out] info node info of getting
|
|
|
|
|
|
\retval ::TD_SUCCESS success
|
|
|
\retval ::TD_FAILURE queue is empty
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueueGet(SO_QUEUE_HANDLE handle, SO_INFO_S *info);
|
|
|
|
|
|
/**
|
|
|
\brief get a node, but no delete the node in the queue
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
\param[out] info node info
|
|
|
|
|
|
\retval ::TD_SUCCESS success
|
|
|
\retval ::TD_FAILURE queue is empty
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueueGetNodeInfoNotDel(SO_QUEUE_HANDLE handle, SO_INFO_S *info);
|
|
|
|
|
|
/**
|
|
|
\brief insert a node
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
\param[out] info node info
|
|
|
|
|
|
\retval ::TD_SUCCESS success
|
|
|
\retval ::TD_FAILURE no memory or param invalid
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueuePut(SO_QUEUE_HANDLE handle, const SO_INFO_S *info);
|
|
|
|
|
|
/**
|
|
|
\brief reset the queue, delete all nodes
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_void SO_QueueReset(SO_QUEUE_HANDLE handle);
|
|
|
|
|
|
/**
|
|
|
\brief reset the queue, delete nodes by pts
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
|
|
|
\retval ::TD_SUCCESS successs
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_s32 SO_QueueResetByPts(SO_QUEUE_HANDLE handle, td_s64 pts);
|
|
|
|
|
|
td_s32 SO_QueueResetAfterPts(SO_QUEUE_HANDLE handle, td_s64 pts);
|
|
|
|
|
|
/**
|
|
|
\brief remove all nodes
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_void SO_QueueRemove(SO_QUEUE_HANDLE handle);
|
|
|
|
|
|
/**
|
|
|
\brief get total number of the nodes
|
|
|
\attention \n
|
|
|
non
|
|
|
\param[in] handle handle of the queue
|
|
|
|
|
|
\retval ::TD_SUCCESS
|
|
|
|
|
|
\see \n
|
|
|
non
|
|
|
*/
|
|
|
td_u32 SO_QueueNum(SO_QUEUE_HANDLE handle);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
#if __cplusplus
|
|
|
}
|
|
|
#endif
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
#endif /* SO_QUEUE_H */
|