32 #define _SC_PAGESIZE 8
33 #define sysconf(x) 4096
44 #ifdef XCODER_LINUX_CUSTOM_DRIVER
45 #define NI_LOGAN_NVME_PREFIX "ninvme"
46 #define NI_LOGAN_NVME_PREFIX_SZ 6
47 #elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
48 #define NI_LOGAN_NVME_PREFIX "vd"
49 #define NI_LOGAN_NVME_PREFIX_SZ 2
50 #elif defined(__APPLE__)
51 #define NI_LOGAN_NVME_PREFIX "rdisk"
52 #define NI_LOGAN_NVME_PREFIX_SZ 4
54 #define NI_LOGAN_NVME_PREFIX "nvme"
55 #define NI_LOGAN_NVME_PREFIX_SZ 4
59 #define LOGAN_XCODER_FRAME_OFFSET_DIFF_THRES 100
61 #define LOGAN_XCODER_MAX_NUM_QUEUE_ENTRIES 6000
62 #define LOGAN_XCODER_MAX_NUM_TEMPORAL_LAYER 7
63 #define LOGAN_BUFFER_POOL_SZ_PER_CONTEXT 300
66 #define LOGAN_XCODER_MIN_ENC_PIC_WIDTH 256
67 #define LOGAN_XCODER_MIN_ENC_PIC_HEIGHT 128
68 #define LOGAN_XCODER_MAX_ENC_PIC_WIDTH 8192
69 #define LOGAN_XCODER_MAX_ENC_PIC_HEIGHT 8192
71 #define NI_LOGAN_DEC_FRAME_BUF_POOL_SIZE_INIT 20
72 #define NI_LOGAN_DEC_FRAME_BUF_POOL_SIZE_EXPAND 20
74 #define NI_LOGAN_INPUT_DATA_BUF_CNT_INIT 30
76 #define NI_LOGAN_VPU_FREQ 450
78 #define MAX_THREADS 1000
80 #define NI_LOGAN_ODD2EVEN(X) ((X&1)&&(X>31))?(X+1):(X)
82 #ifdef XCODER_SIM_ENABLED
83 extern int32_t sim_eos_flag;
103 void *(*run)(
void *args);
159 int32_t number_of_buffers,
239 int64_t *p_timestamp,
252 uint64_t frame_offset,
253 int64_t *p_timestamp,
267 int64_t *p_timestamp,
303 uint64_t frame_offset,
314 uint64_t frame_offset,
315 int64_t *p_timestamp,
328 uint64_t frame_offset,
329 int64_t *p_timestamp,
498 void *(*run)(
void *arg),
570 int width,
int height,
int bit_depth_factor,
621 #ifdef MEASURE_LATENCY
641 #define ni_logan_aligned_free(p_memptr) \
647 #if defined(__linux__) || defined(__APPLE__)
648 uint32_t ni_logan_get_kernel_max_io_size(
const char * p_dev);
659 static inline int ni_logan_pthread_mutex_init(ni_pthread_mutex_t *mutex)
662 InitializeCriticalSection(mutex);
666 ni_pthread_mutexattr_t attr;
668 rc = pthread_mutexattr_init(&attr);
678 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
680 return pthread_mutex_init(mutex, &attr);
692 static inline int ni_logan_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
695 DeleteCriticalSection(mutex);
698 return pthread_mutex_destroy(mutex);
710 static bool ni_logan_pthread_mutex_alloc_and_init(ni_pthread_mutex_t **mutex)
713 *mutex = (ni_pthread_mutex_t *)calloc(1,
sizeof(ni_pthread_mutex_t));
719 rc = ni_logan_pthread_mutex_init(*mutex);
737 static bool ni_logan_pthread_mutex_free_and_destroy(ni_pthread_mutex_t **mutex)
741 static void *
const tmp = NULL;
744 memcpy(&p, mutex,
sizeof(p));
747 rc = ni_logan_pthread_mutex_destroy((ni_pthread_mutex_t *)p);
748 memcpy(mutex, &tmp,
sizeof(p));
766 static inline int ni_logan_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
772 EnterCriticalSection(mutex);
774 rc = pthread_mutex_lock(mutex);
792 static inline int ni_logan_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
798 LeaveCriticalSection(mutex);
800 rc = pthread_mutex_unlock(mutex);
811 static unsigned __stdcall __thread_worker(
void *arg)
813 ni_pthread_t *t = (ni_pthread_t *)arg;
814 t->rc = t->start_routine(t->arg);
827 static int ni_logan_pthread_create(ni_pthread_t *thread,
828 const ni_pthread_attr_t *attr,
829 void *(*start_routine)(
void *),
void *arg)
832 thread->start_routine = start_routine;
836 (
void *)CreateThread(NULL, 0, __thread_worker, thread, 0, NULL);
838 (
void *)_beginthreadex(NULL, 0, __thread_worker, thread, 0, NULL);
840 return !thread->handle;
842 return pthread_create(thread, attr, start_routine, arg);
854 static int ni_logan_pthread_join(ni_pthread_t thread,
void **value_ptr)
857 DWORD rc = WaitForSingleObject(thread.handle, INFINITE);
858 if (rc != WAIT_OBJECT_0)
860 if (rc == WAIT_ABANDONED)
866 *value_ptr = thread.rc;
867 CloseHandle(thread.handle);
870 return pthread_join(thread, value_ptr);
882 static inline int ni_logan_pthread_cond_init(ni_pthread_cond_t *cond,
883 const ni_pthread_condattr_t *attr)
886 InitializeConditionVariable(cond);
889 return pthread_cond_init(cond, attr);
901 static inline int ni_logan_pthread_cond_destroy(ni_pthread_cond_t *cond)
907 return pthread_cond_destroy(cond);
919 static inline int ni_logan_pthread_cond_broadcast(ni_pthread_cond_t *cond)
922 WakeAllConditionVariable(cond);
925 return pthread_cond_broadcast(cond);
937 static inline int ni_logan_pthread_cond_wait(ni_pthread_cond_t *cond,
938 ni_pthread_mutex_t *mutex)
941 SleepConditionVariableCS(cond, mutex, INFINITE);
944 return pthread_cond_wait(cond, mutex);
956 static inline int ni_logan_pthread_cond_signal(ni_pthread_cond_t *cond)
959 WakeConditionVariable(cond);
962 return pthread_cond_signal(cond);
974 static int ni_logan_pthread_cond_timedwait(ni_pthread_cond_t *cond,
975 ni_pthread_mutex_t *mutex,
976 const struct timespec *abstime)
979 int64_t abs_ns = abstime->tv_sec * 1000000000LL + abstime->tv_nsec;
982 if (!SleepConditionVariableCS(cond, mutex, t))
984 DWORD err = GetLastError();
985 if (err == ERROR_TIMEOUT)
992 return pthread_cond_timedwait(cond, mutex, abstime);
1004 static inline int ni_logan_pthread_sigmask(
int how,
const ni_sigset_t *set,
1005 ni_sigset_t *oldset)
1010 return pthread_sigmask(how, set, oldset);
#define NI_LOGAN_MAX_NUM_DATA_POINTERS
Main NETINT device API header file provides the ability to communicate with NI T-408 type hardware tr...
Exported logging routines definition.
ni_logan_retcode_t ni_logan_queue_push(ni_logan_queue_buffer_pool_t *p_buffer_pool, ni_logan_queue_t *p_queue, uint64_t frame_offset, int64_t timestamp)
Push into xcoder queue.
LIB_API int32_t ni_logan_gettimeofday(struct timeval *p_tp, void *p_tzp)
ni_logan_buf_t * ni_logan_buf_pool_allocate_buffer(ni_logan_buf_pool_t *p_buffer_pool, int buffer_size)
allocate a memory buffer and place it in the pool
uint8_t * ni_logan_fifo_generic_read(ni_logan_fifo_buffer_t *p_fifo)
Get first filled buffer to read in the fifo.
uint32_t ni_logan_round_up(uint32_t number_to_round, uint32_t multiple)
ni_logan_retcode_t ni_logan_timestamp_get(ni_logan_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frame offset info.
uint8_t * ni_logan_fifo_generic_write(ni_logan_fifo_buffer_t *p_fifo)
Get free buffer to write in the fifo.
int threadpool_auto_add_task_thread(threadpool_t *pool, void *(*run)(void *arg), void *arg, int newThread)
add task to threadpool using newThread control it
LIB_API void ni_logan_overwrite_specified_pos(uint8_t *buf, int pos, int value)
overwrite the 32 bits of integer value at bit position pos
void ni_logan_timestamp_scan_cleanup(ni_logan_timestamp_table_t *pts_list, ni_logan_timestamp_table_t *dts_list, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Timestamp queue clean up.
int32_t ni_logan_dec_fme_buffer_pool_initialize(ni_logan_session_context_t *p_ctx, int32_t number_of_buffers, int width, int height, int height_align, int factor)
decoder frame buffer pool init & free
int32_t ni_logan_posix_memalign(void **pp_memptr, size_t alignment, size_t size)
ni_logan_retcode_t ni_logan_queue_free(ni_logan_queue_t *p_queue, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Free xcoder queue.
int32_t ni_logan_atobool(const char *p_str, bool *b_error)
convert string to boolean
ni_logan_retcode_t ni_logan_queue_pop(ni_logan_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Pop from the xcoder queue.
ni_logan_retcode_t ni_logan_find_blk_name(const char *p_dev, char *p_out_buf, int out_buf_len)
Find NVMe name space block from device name If none is found, assume nvme multi-pathing is disabled a...
LIB_API void ni_logan_usleep(int64_t usec)
LIB_API uint64_t ni_logan_gettime_ns(void)
int ni_logan_fifo_return_read(ni_logan_fifo_buffer_t *p_fifo)
Push back the last read buffer to the fifo.
void ni_logan_buffer_pool_free(ni_logan_queue_buffer_pool_t *p_buffer_pool)
free buffer memory pool
int32_t ni_logan_parse_name(const char *arg, const char *const *names, bool *b_error)
string parser
ni_logan_retcode_t ni_logan_timestamp_done(ni_logan_timestamp_table_t *p_table, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Clean up timestamp handling.
int ni_logan_fifo_is_empty(ni_logan_fifo_buffer_t *p_fifo)
Check if a fifo is empty.
ni_logan_retcode_t ni_logan_timestamp_register(ni_logan_queue_buffer_pool_t *p_buffer_pool, ni_logan_timestamp_table_t *p_table, int64_t timestamp, uint64_t data_info)
Register timestamp in timestamp/frame offset table.
ni_logan_retcode_t ni_logan_timestamp_init(ni_logan_session_context_t *p_ctx, ni_logan_timestamp_table_t **pp_table, const char *name)
Initialize timestamp handling.
LIB_API void ni_logan_copy_hw_yuv420p(uint8_t *p_dst[NI_LOGAN_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_LOGAN_MAX_NUM_DATA_POINTERS], int width, int height, int bit_depth_factor, int dst_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int dst_height[NI_LOGAN_MAX_NUM_DATA_POINTERS], int src_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int src_height[NI_LOGAN_MAX_NUM_DATA_POINTERS])
Copy YUV data to Netint HW YUV420p frame layout to be sent to encoder for encoding....
int ni_logan_fifo_is_full(ni_logan_fifo_buffer_t *p_fifo)
Check if a fifo is full.
struct _ni_logan_queue_t ni_logan_queue_t
void ni_logan_buf_pool_return_buffer(ni_logan_buf_t *buf, ni_logan_buf_pool_t *p_buffer_pool)
return a used memory buffer to the pool
ni_logan_retcode_t ni_logan_queue_print(ni_logan_queue_t *p_queue)
Print xcoder queue.
void ni_logan_dec_fme_buffer_pool_free(ni_logan_buf_pool_t *p_buffer_pool)
free decoder frame buffer pool
ni_logan_retcode_t ni_logan_queue_pop_threshold(ni_logan_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Pop from the xcoder queue with respect to threshold.
int32_t ni_logan_atoi(const char *p_str, bool *b_error)
convert string to integer
LIB_API int ni_logan_insert_emulation_prevent_bytes(uint8_t *buf, int size)
Insert emulation prevention byte(s) as needed into the data buffer.
LIB_API int ni_logan_remove_emulation_prevent_bytes(uint8_t *buf, int size)
Remove emulation prevention byte(s) as needed from the data buffer.
ni_logan_fifo_buffer_t * ni_logan_fifo_initialize(uint32_t number_of_buffers, uint32_t size)
Initialize a fifo buffer.
struct threadpool threadpool_t
ni_logan_retcode_t ni_logan_queue_init(ni_logan_session_context_t *p_ctx, ni_logan_queue_t *p_queue, const char *name)
Initialize xcoder queue.
void ni_logan_fifo_free(ni_logan_fifo_buffer_t *p_fifo)
Free a fifo.
void threadpool_destroy(threadpool_t *pool)
destroy threadpool
void * thread_routine(void *arg)
threadpool control
ni_logan_buf_t * ni_logan_buf_pool_get_buffer(ni_logan_buf_pool_t *p_buffer_pool)
get a free memory buffer from the pool
ni_logan_retcode_t ni_logan_timestamp_get_v2(ni_logan_timestamp_table_t *p_table, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frame offset info.
LIB_API void ni_logan_get_hw_yuv420p_dim(int width, int height, int bit_depth_factor, int is_h264, int plane_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int plane_height[NI_LOGAN_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
void threadpool_init(threadpool_t *pool)
Init the threadpool.
struct _ni_logan_timestamp_table_t ni_logan_timestamp_table_t
double ni_logan_atof(const char *p_str, bool *b_error)
convert string to float
int threadpool_add_task(threadpool_t *pool, void *(*run)(void *arg), void *arg)
add task to threadpool
ni_logan_retcode_t ni_logan_timestamp_get_with_threshold(ni_logan_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frame offset info with respect to threshold.
ni_logan_queue_node_t * p_last
ni_logan_queue_node_t * p_first
ni_pthread_mutex_t pmutex