libxcoder 5.8.0
Loading...
Searching...
No Matches
ni_util.h
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file ni_util.h
24 *
25 * \brief Utility definitions
26 ******************************************************************************/
27
28#pragma once
29
30#ifdef _WIN32
31#define _SC_PAGESIZE 4096
32#define sysconf(x) x
33#endif
34
35#include "ni_device_api.h"
36#include "ni_log.h"
37#include "ni_defs.h"
38
39#ifdef __cplusplus
40extern "C"
41{
42#endif
43
44#define NI_INVALID_POWER 0xFFFFFFFF
45/* Value and formula retrieved from tps25940 EFUSE manual */
46#define TPS25940_IMON_OS 0.8f
47#define TPS25940_GAIN_IMON 52.0f
48#define TPS25940_R_IMON 5.6f
49
50/* Value and formula retrieved from tps25946 EFUSE manual */
51#define TPS25946_GAIN_IMON 182.0f
52#define TPS25974_GAIN_IMON 105.5f
53#define TPS25946_R_IMON_T2A 1000.0f
54#define TPS25946_R_IMON_T1U_UA 1130.0f
55#define TPS25946_R_IMON_T1S 562.0f
56#define TPS25974_R_IMON_T1M 750.0f
57
58/* Value and formula retrieved from MAX15162AAWE+T EFUSE manual */
59#define MAX15162AAWE_C_IRATIO 4000.0f
60#define MAX15162AAWE_R_IMON 1500.0f
61
62/* Value and formula retrieved from MAX17613B EFUSE manual */
63#define MAX17613B_R_ISET_TOTAL 1510.0f /* Voltage Divider at ADC */
64#define MAX17613B_R_ISET_R2 1000.0f
65#define MAX17613B_C_IRATIO 3000.0f
66
67#define MCU_FSR_ADC 4096.0f
68#define MCU_REF_VOLTAGE 2500.0f //mV
69
70static inline int ni_min(int a, int b)
71{
72 return a < b ? a : b;
73}
74
75static inline int ni_max(int a, int b)
76{
77 return a > b ? a : b;
78}
79
80static inline float ni_minf(float a, float b)
81{
82 return a < b ? a : b;
83}
84
85static inline float ni_maxf(float a, float b)
86{
87 return a > b ? a : b;
88}
89
90static inline int clip3(int min, int max, int a)
91{
92 return ni_min(ni_max(min, a), max);
93}
94
95static inline float clip3f(float min, float max, float a)
96{
97 return ni_minf(ni_maxf(min, a), max);
98}
99
100#define NIALIGN(x, a) (((x) + (a)-1) & ~((a)-1))
101// Compile time assert macro
102#define COMPILE_ASSERT(condition) ((void)sizeof(char[1 - 2 * !(condition)]))
103
104#define XCODER_MAX_NUM_TS_TABLE 32
105#define XCODER_FRAME_OFFSET_DIFF_THRES 100
106#define XCODER_MAX_ENC_PACKETS_PER_READ 16
107#define XCODER_MAX_NUM_QUEUE_ENTRIES 6000
108#define XCODER_MAX_NUM_TEMPORAL_LAYER 7
109#define BUFFER_POOL_SZ_PER_CONTEXT 300
110
111// for _T400_ENC
112#define XCODER_MIN_ENC_PIC_WIDTH 144
113#define XCODER_MIN_ENC_PIC_HEIGHT 128
114#define XCODER_MAX_ENC_PIC_WIDTH 8192
115#define XCODER_MAX_ENC_PIC_HEIGHT 8192
116
117#define NI_DEC_FRAME_BUF_POOL_SIZE_INIT 20
118#define NI_DEC_FRAME_BUF_POOL_SIZE_EXPAND 20
119
120
121// memory buffer pool operations (one use is for decoder frame buffer pool)
123
124void ni_buf_pool_return_buffer(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool);
125
126ni_buf_t *ni_buf_pool_allocate_buffer(ni_buf_pool_t *p_buffer_pool, int buffer_size);
127
128// decoder frame buffer pool init & free
129int32_t ni_dec_fme_buffer_pool_initialize(ni_session_context_t* p_ctx, int32_t number_of_buffers, int width, int height, int height_align, int factor);
130void ni_dec_fme_buffer_pool_free(ni_buf_pool_t *p_buffer_pool);
131
132// timestamp buffer pool operations
134
135ni_retcode_t ni_find_blk_name(const char *p_dev, char *p_out_buf, int out_buf_len);
136ni_retcode_t ni_check_dev_name(const char *p_dev);
137ni_retcode_t ni_timestamp_init(ni_session_context_t* p_ctx, ni_timestamp_table_t **pp_table, const char *name);
139ni_retcode_t ni_timestamp_register(ni_queue_buffer_pool_t *p_buffer_pool, ni_timestamp_table_t *p_table, int64_t timestamp, uint64_t data_info);
140ni_retcode_t ni_timestamp_get(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool);
141ni_retcode_t ni_timestamp_get_v2(ni_timestamp_table_t *p_table, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, ni_queue_buffer_pool_t *p_buffer_pool);
142
143ni_retcode_t ni_timestamp_get_with_threshold(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool);
144
146 ni_timestamp_table_t *dts_list,
147 ni_queue_buffer_pool_t *p_buffer_pool);
148
149ni_retcode_t ni_queue_init(ni_session_context_t* p_ctx, ni_queue_t *p_queue, const char *name);
150ni_retcode_t ni_queue_push(ni_queue_buffer_pool_t *p_buffer_pool, ni_queue_t *p_queue, uint64_t frame_offset, int64_t timestamp);
151ni_retcode_t ni_queue_pop(ni_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool);
152ni_retcode_t ni_queue_pop_threshold(ni_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool);
155
156int32_t ni_atobool(const char *p_str, bool *b_error);
157int32_t ni_atoi(const char *p_str, bool *b_error);
158double ni_atof(const char *p_str, bool *b_error);
159LIB_API ni_retcode_t ni_strtoi(const char *str, int32_t *out_val);
160LIB_API ni_retcode_t ni_strtod_val(const char *str, double *out_val);
161int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error);
162uint32_t ni_decode_power_measurement(uint32_t power_value, const uint8_t *serial_number);
163
164/*!******************************************************************************
165 * \brief precheck a device can be read by ni_device_capability_query()
166 * INFO OR ERROR logs will not be printed in this function
167 * \param[in] p_dev device path string. eg: "/dev/nvme1n2"
168 *
169 * \return
170 * returns NI_RETCODE_FAILURE
171 * when the device can not be read by ni_device_capability_query()
172 *
173 * returns NI_RETCODE_SUCCESS
174 * when the device can not be read by ni_device_capability_query() or
175 * the result can not be determined to prevent query failures due to
176 * some reasons such as missing commands on the system
177 *******************************************************************************/
179
180// Netint HW YUV420p data layout related utility functions
181
182/*!*****************************************************************************
183 * \brief Get dimension information of Netint HW YUV420p frame to be sent
184 * to encoder for encoding. Caller usually retrieves this info and
185 * uses it in the call to ni_encoder_frame_buffer_alloc for buffer
186 * allocation.
187 *
188 * \param[in] width source YUV frame width
189 * \param[in] height source YUV frame height
190 * \param[in] bit_depth_factor 1 for 8 bit, 2 for 10 bit
191 * \param[in] is_semiplanar non-0 for semiplnar frame, 0 otherwise
192 * \param[out] plane_stride size (in bytes) of each plane width
193 * \param[out] plane_height size of each plane height
194 *
195 * \return Y/Cb/Cr stride and height info
196 *
197 ******************************************************************************/
198LIB_API void ni_get_hw_yuv420p_dim(int width, int height, int bit_depth_factor,
199 int is_semiplanar,
200 int plane_stride[NI_MAX_NUM_DATA_POINTERS],
201 int plane_height[NI_MAX_NUM_DATA_POINTERS]);
202
203/*!*****************************************************************************
204 * \brief Get dimension information of frame to be sent
205 * to encoder for encoding. Caller usually retrieves this info and
206 * uses it in the call to ni_encoder_frame_buffer_alloc for buffer
207 * allocation.
208 * The returned stride and height info will take alignment
209 * requirements into account.
210 *
211 * \param[in] width source frame width
212 * \param[in] height source frame height
213 * \param[in] pix_fmt ni pixel format
214 * \param[out] plane_stride size (in bytes) of each plane width
215 * \param[out] plane_height size of each plane height
216 *
217 * \return stride and height info
218 *
219 ******************************************************************************/
220LIB_API void ni_get_frame_dim(int width, int height,
221 ni_pix_fmt_t pix_fmt,
222 int plane_stride[NI_MAX_NUM_DATA_POINTERS],
223 int plane_height[NI_MAX_NUM_DATA_POINTERS]);
224
225/*!*****************************************************************************
226 * \brief Get dimension information of frame to be sent
227 * to encoder for encoding. Caller usually retrieves this info and
228 * uses it in the call to ni_encoder_frame_buffer_alloc for buffer
229 * allocation.
230 * The returned stride and height info will take into account both min
231 * resolution and alignment requirements.
232 *
233 * \param[in] width source frame width
234 * \param[in] height source frame height
235 * \param[in] pix_fmt ni pixel format
236 * \param[out] plane_stride size (in bytes) of each plane width
237 * \param[out] plane_height size of each plane height
238 *
239 * \return stride and height info
240 *
241 ******************************************************************************/
242LIB_API void ni_get_min_frame_dim(int width, int height,
243 ni_pix_fmt_t pix_fmt,
244 int plane_stride[NI_MAX_NUM_DATA_POINTERS],
245 int plane_height[NI_MAX_NUM_DATA_POINTERS]);
246
247/*!*****************************************************************************
248 * \brief Copy YUV data to Netint HW YUV420p frame layout to be sent
249 * to encoder for encoding. Data buffer (dst) is usually allocated by
250 * ni_encoder_frame_buffer_alloc.
251 *
252 * \param[out] p_dst pointers of Y/Cb/Cr to which data is copied
253 * \param[in] p_src pointers of Y/Cb/Cr from which data is copied
254 * \param[in] width source YUV frame width
255 * \param[in] height source YUV frame height
256 * \param[in] bit_depth_factor 1 for 8 bit, 2 for 10 bit
257 * \param[in] is_semiplanar non-0 for semiplanar frame, 0 otherwise
258 * \param[in] conf_win_right right offset of conformance window
259 * \param[in] dst_stride size (in bytes) of each plane width in destination
260 * \param[in] dst_height size of each plane height in destination
261 * \param[in] src_stride size (in bytes) of each plane width in source
262 * \param[in] src_height size of each plane height in source
263 *
264 * \return Y/Cb/Cr data
265 *
266 ******************************************************************************/
268 uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS],
269 int width, int height, int bit_depth_factor,
270 int is_semiplanar, int conf_win_right,
271 int dst_stride[NI_MAX_NUM_DATA_POINTERS],
272 int dst_height[NI_MAX_NUM_DATA_POINTERS],
273 int src_stride[NI_MAX_NUM_DATA_POINTERS],
274 int src_height[NI_MAX_NUM_DATA_POINTERS]);
275
276/*!*****************************************************************************
277 * \brief Copy RGBA or YUV data to Netint HW frame layout to be sent
278 * to encoder for encoding. Data buffer (dst) is usually allocated by
279 * ni_encoder_frame_buffer_alloc.
280 *
281 * \param[out] p_dst pointers to which data is copied
282 * \param[in] p_src pointers from which data is copied
283 * \param[in] width source frame width
284 * \param[in] height source frame height
285 * \param[in] factor 1 for 8 bit, 2 for 10 bit
286 * \param[in] pix_fmt pixel format to distinguish between planar types and/or components
287 * \param[in] conf_win_right right offset of conformance window
288 * \param[in] dst_stride size (in bytes) of each plane width in destination
289 * \param[in] dst_height size of each plane height in destination
290 * \param[in] src_stride size (in bytes) of each plane width in source
291 * \param[in] src_height size of each plane height in source
292 *
293 * \return copied data
294 *
295 ******************************************************************************/
297 uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS],
298 int frame_width, int frame_height,
299 int factor, ni_pix_fmt_t pix_fmt,
300 int conf_win_right,
301 int dst_stride[NI_MAX_NUM_DATA_POINTERS],
302 int dst_height[NI_MAX_NUM_DATA_POINTERS],
303 int src_stride[NI_MAX_NUM_DATA_POINTERS],
304 int src_height[NI_MAX_NUM_DATA_POINTERS]);
305
306/*!*****************************************************************************
307 * \brief Copy yuv444p data to yuv420p frame layout to be sent
308 * to encoder for encoding. Data buffer (dst) is usually allocated by
309 * ni_encoder_frame_buffer_alloc.
310 *
311 * \param[out] p_dst0 pointers of Y/Cb/Cr as yuv420p output0
312 * \param[out] p_dst1 pointers of Y/Cb/Cr as yuv420p output1
313 * \param[in] p_src pointers of Y/Cb/Cr as yuv444p intput
314 * \param[in] width source YUV frame width
315 * \param[in] height source YUV frame height
316 * \param[in] factor 1 for 8 bit, 2 for 10 bit
317 * \param[in] mode 0 for
318 * out0 is Y+1/2V, with the original input as the out0, 1/4V
319 * copy to data[1] 1/4V copy to data[2]
320 * out1 is U+1/2V, U copy to data[0], 1/4V copy to data[1], 1/4V
321 * copy to data[2]
322 * mode 1 for
323 * out0 is Y+1/2u+1/2v, with the original input as the output0,
324 * 1/4U copy to data[1] 1/4V copy to data[2]
325 * out1 is (1/2U+1/2V)+1/4U+1/4V, 1/2U & 1/2V copy to data[0],
326 * 1/4U copy to data[1], 1/4V copy to data[2]
327 *
328 * \return Y/Cb/Cr data
329 *
330 ******************************************************************************/
332 uint8_t *p_dst1[NI_MAX_NUM_DATA_POINTERS],
333 uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS],
334 int width, int height, int factor,
335 int mode);
336
337// NAL operations
338
339/*!*****************************************************************************
340 * \brief Insert emulation prevention byte(s) as needed into the data buffer
341 *
342 * \param buf data buffer to be worked on - new byte(s) will be inserted
343 * size number of bytes starting from buf to check
344 *
345 * \return the number of emulation prevention bytes inserted into buf, 0 if
346 * none.
347 *
348 * Note: caller *MUST* ensure for newly inserted bytes, buf has enough free
349 * space starting from buf + size
350 ******************************************************************************/
351LIB_API int ni_insert_emulation_prevent_bytes(uint8_t *buf, int size);
352
353/*!*****************************************************************************
354 * \brief Remove emulation prevention byte(s) as needed from the data buffer
355 *
356 * \param buf data buffer to be worked on - emu prevent byte(s) will be
357 * removed from.
358 * size number of bytes starting from buf to check
359 *
360 * \return the number of emulation prevention bytes removed from buf, 0 if
361 * none.
362 *
363 * Note: buf will be modified if emu prevent byte(s) found and removed.
364 ******************************************************************************/
365LIB_API int ni_remove_emulation_prevent_bytes(uint8_t *buf, int size);
366
367/*!*****************************************************************************
368 * \brief Get time for logs with microsecond timestamps
369 *
370 * \param[in/out] p_tp timeval struct
371 * \param[in] p_tzp void *
372 *
373 * \return return 0 for success, -1 for error
374 ******************************************************************************/
375LIB_API int32_t ni_gettimeofday(struct timeval *p_tp, void *p_tzp);
376
377/*!*****************************************************************************
378 * \brief Allocate aligned memory
379 *
380 * \param[in/out] memptr The address of the allocated memory will be a
381 * multiple of alignment, which must be a power of two
382 * and a multiple of sizeof(void *). If size is 0, then
383 * the value placed is either NULL, or a unique pointer
384 * value that can later be successfully passed to free.
385 * \param[in] alignment The alignment value of the allocated value.
386 * \param[in] size The allocated memory size.
387 *
388 * \return 0 for success, ENOMEM for error
389 ******************************************************************************/
390LIB_API int ni_posix_memalign(void **memptr, size_t alignment, size_t size);
391
392uint32_t ni_round_up(uint32_t number_to_round, uint32_t multiple);
393
394#ifdef _WIN32
395#define ni_aligned_free(p_memptr) do { \
396 if ((p_memptr) != NULL) { \
397 _aligned_free(p_memptr); \
398 p_memptr = NULL; \
399 } \
400}while(0)
401#else
402#define ni_aligned_free(p_memptr) do { \
403 if ((p_memptr) != NULL) { \
404 free(p_memptr); \
405 p_memptr = NULL; \
406 } \
407}while(0)
408#endif
409
410// This method is used in device session close function to unset all the
411// pointers in the session context.
412#define ni_memfree(p_memptr) do { \
413 if ((p_memptr) != NULL) { \
414 free(p_memptr); \
415 p_memptr = NULL; \
416 } \
417}while(0)
418
419#if __linux__ || __APPLE__
420uint32_t ni_get_kernel_max_io_size(const char * p_dev);
421#endif
422
423LIB_API uint64_t ni_gettime_ns(void);
424LIB_API void ni_usleep(int64_t usec);
425LIB_API char *ni_strtok(char *s, const char *delim, char **saveptr);
426LIB_API ni_retcode_t ni_strncpy(char *dest, size_t dmax,
427 const char *src, size_t slen);
428LIB_API ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src);
429LIB_API ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum);
430LIB_API ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src);
431LIB_API ni_retcode_t ni_strncat(char *dest, size_t dmax, const char *src, size_t slen);
432LIB_API ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode);
433LIB_API struct tm* ni_localtime(struct tm *dest, const time_t *src);
434LIB_API int ni_fscanf(FILE *stream, const char *fmt, ...);
435LIB_API int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args);
436LIB_API int ni_sprintf(char *dest, size_t dmax, const char *fmt, ...);
437
439ni_network_layer_convert_output(float *dst, uint32_t num, ni_packet_t *p_packet,
440 ni_network_data_t *p_network, uint32_t layer);
444 uint8_t *dst, uint32_t dst_len, const char *tensor_file,
447 uint8_t *dst, uint32_t dst_len, float *src, uint32_t src_len,
450 float *dst, uint32_t dst_len, uint8_t *src, uint32_t src_len,
452
453LIB_API void ni_calculate_sha256(const uint8_t aui8Data[],
454 size_t ui32DataLength, uint8_t aui8Hash[]);
455/*!*****************************************************************************
456* \brief Copy Descriptor data to Netint HW descriptor frame layout to be sent
457* to encoder for encoding. Data buffer (dst) is usually allocated by
458* ni_encoder_frame_buffer_alloc. Only necessary when metadata size in
459* source is insufficient
460*
461* \param[out] p_dst pointers of Y/Cb/Cr to which data is copied
462* \param[in] p_src pointers of Y/Cb/Cr from which data is copied
463*
464* \return descriptor data
465*
466******************************************************************************/
468 uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS]);
469
470/*!*****************************************************************************
471 * \brief Get libxcoder API version
472 *
473 * \return char pointer to libxcoder API version
474 ******************************************************************************/
476
477#ifndef DEPRECATION_AS_ERROR
478/*!*****************************************************************************
479 * \brief Get FW API version libxcoder is compatible with
480 *
481 * \return char pointer to FW API version libxcoder is compatible with
482 ******************************************************************************/
484#endif
485
486/*!*****************************************************************************
487 * \brief Get formatted FW API version string from unformatted FW API version
488 * string
489 *
490 * \param[in] ver_str pointer to string containing FW API. Only up to 3
491 * characters will be read
492 * \param[out] fmt_str pointer to string buffer of at least size 5 to output
493 * formated version string to
494 *
495 * \return none
496 ******************************************************************************/
497LIB_API void ni_fmt_fw_api_ver_str(const char ver_str[], char fmt_str[]);
498
499/*!*****************************************************************************
500 * \brief Compare two 3 character strings containing a FW API version. Handle
501 * comparision when FW API version format length changed from 2 to 3.
502 *
503 * \param[in] ver1 pointer to string containing FW API. Only up to 3
504 * characters will be read
505 * \param[in] ver2 pointer to string containing FW API. Only up to 3
506 * characters will be read
507 *
508 * \return 0 if ver1 == ver2, 1 if ver1 > ver2, -1 if ver1 < ver2
509 ******************************************************************************/
510LIB_API int ni_cmp_fw_api_ver(const char ver1[], const char ver2[]);
511
512/*!*****************************************************************************
513 * \brief Get libxcoder SW release version
514 *
515 * \return char pointer to libxcoder SW release version
516 ******************************************************************************/
518
519/*!*****************************************************************************
520 * \brief initialize a mutex
521 *
522 * \param[in] thread mutex
523 *
524 * \return On success returns 0
525 * On failure returns <0
526 ******************************************************************************/
527LIB_API int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex);
528
529/*!*****************************************************************************
530 * \brief destory a mutex
531 *
532 * \param[in] thread mutex
533 *
534 * \return On success returns 0
535 * On failure returns <0
536 ******************************************************************************/
537LIB_API int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex);
538
539/*!*****************************************************************************
540 * \brief thread mutex lock
541 *
542 * \param[in] thread mutex
543 *
544 * \return On success returns 0
545 * On failure returns <0
546 ******************************************************************************/
547LIB_API int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex);
548
549/*!*****************************************************************************
550 * \brief thread mutex unlock
551 *
552 * \param[in] thread mutex
553 *
554 * \return On success returns 0
555 * On failure returns <0
556 ******************************************************************************/
557LIB_API int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex);
558
559/*!*****************************************************************************
560 * \brief create a new thread
561 *
562 * \param[in] thread thread id
563 * \param[in] attr attributes to the new thread
564 * \param[in] start_routine entry of the thread routine
565 * \param[in] arg sole argument of the routine
566 *
567 * \return On success returns 0
568 * On failure returns <0
569 ******************************************************************************/
570LIB_API int ni_pthread_create(ni_pthread_t *thread,
571 const ni_pthread_attr_t *attr,
572 void *(*start_routine)(void *), void *arg);
573
574/*!*****************************************************************************
575 * \brief join with a terminated thread
576 *
577 * \param[in] thread thread id
578 * \param[out] value_ptr return status
579 *
580 * \return On success returns 0
581 * On failure returns <0
582 ******************************************************************************/
583LIB_API int ni_pthread_join(ni_pthread_t thread, void **value_ptr);
584
585/*!*****************************************************************************
586 * \brief initialize condition variables
587 *
588 * \param[in] cond condition variable
589 * \param[in] attr attribute to the condvar
590 *
591 * \return On success returns 0
592 * On failure returns <0
593 ******************************************************************************/
594LIB_API int ni_pthread_cond_init(ni_pthread_cond_t *cond,
595 const ni_pthread_condattr_t *attr);
596
597/*!*****************************************************************************
598 * \brief destroy condition variables
599 *
600 * \param[in] cond condition variable
601 *
602 * \return On success returns 0
603 * On failure returns <0
604 ******************************************************************************/
605LIB_API int ni_pthread_cond_destroy(ni_pthread_cond_t *cond);
606
607/*!*****************************************************************************
608 * \brief broadcast a condition
609 *
610 * \param[in] cond condition variable
611 *
612 * \return On success returns 0
613 * On failure returns <0
614 ******************************************************************************/
615LIB_API int ni_pthread_cond_broadcast(ni_pthread_cond_t *cond);
616
617/*!*****************************************************************************
618 * \brief wait on a condition
619 *
620 * \param[in] cond condition variable
621 * \param[in] mutex mutex related to the condvar
622 *
623 * \return On success returns 0
624 * On failure returns <0
625 ******************************************************************************/
626LIB_API int ni_pthread_cond_wait(ni_pthread_cond_t *cond,
627 ni_pthread_mutex_t *mutex);
628
629/*!******************************************************************************
630 * \brief signal a condition
631 *
632 * \param[in] cond condition variable
633 *
634 * \return On success returns 0
635 * On failure returns <0
636 *******************************************************************************/
637LIB_API int ni_pthread_cond_signal(ni_pthread_cond_t *cond);
638
639/*!*****************************************************************************
640 * \brief wait on a condition
641 *
642 * \param[in] cond condition variable
643 * \param[in] mutex mutex related to the condvar
644 * \param[in[ abstime abstract value of timeout
645 *
646 * \return On success returns 0
647 * On failure returns <0
648 ******************************************************************************/
649LIB_API int ni_pthread_cond_timedwait(ni_pthread_cond_t *cond,
650 ni_pthread_mutex_t *mutex,
651 const struct timespec *abstime);
652
653/*!*****************************************************************************
654 * \brief examine and change mask of blocked signals
655 *
656 * \param[in] how behavior of this call, can be value of SIG_BLOCK,
657 * SIG_UNBLOCK and SIG_SETMASK
658 * \param[in] set current value of the signal mask. If NULL, the mask keeps
659 * unchanged.
660 * \param[in] old_set previous value of the signal mask, can be NULL.
661 *
662 * \return On success returns 0
663 * On failure returns <0
664 ******************************************************************************/
665LIB_API int ni_pthread_sigmask(int how, const ni_sigset_t *set,
666 ni_sigset_t *oldset);
667
668/*!*****************************************************************************
669 * \brief Get text string for the provided error
670 *
671 * \return char pointer for the provided error
672 ******************************************************************************/
673LIB_API const char *ni_get_rc_txt(ni_retcode_t rc);
674
675/*!*****************************************************************************
676 * \brief Retrieve key and value from 'key=value' pair
677 *
678 * \param[in] p_str pointer to string to extract pair from
679 * \param[out] key pointer to key
680 * \param[out] value pointer to value
681 *
682 * \return return 0 if successful, otherwise 1
683 *
684 ******************************************************************************/
685LIB_API int ni_param_get_key_value(char *p_str, char *key, char *value);
686
687/*!*****************************************************************************
688 * \brief Retrieve encoder config parameter values from --xcoder-params
689 *
690 * \param[in] xcoderParams pointer to string containing xcoder params
691 * \param[out] params pointer to xcoder params to fill out
692 * \param[out] ctx pointer to session context
693 *
694 * \return return 0 if successful, -1 otherwise
695 *
696 ******************************************************************************/
697LIB_API int ni_retrieve_xcoder_params(char xcoderParams[],
698 ni_xcoder_params_t *params,
700
701/*!*****************************************************************************
702 * \brief Retrieve custom gop config values from --xcoder-gop
703 *
704 * \param[in] xcoderGop pointer to string containing xcoder gop
705 * \param[out] params pointer to xcoder params to fill out
706 * \param[out] ctx pointer to session context
707 *
708 * \return return 0 if successful, -1 otherwise
709 *
710 ******************************************************************************/
711LIB_API int ni_retrieve_xcoder_gop(char xcoderGop[],
712 ni_xcoder_params_t *params,
714
715/*!*****************************************************************************
716 * \brief Retrieve decoder config parameter values from --decoder-params
717 *
718 * \param[in] xcoderParams pointer to string containing xcoder params
719 * \param[out] params pointer to xcoder params to fill out
720 * \param[out] ctx pointer to session context
721 *
722 * \return return 0 if successful, -1 otherwise
723 *
724 ******************************************************************************/
725LIB_API int ni_retrieve_decoder_params(char xcoderParams[],
726 ni_xcoder_params_t *params,
728
729/*!*****************************************************************************
730 * \brief return error string according to error code from firmware
731 *
732 * \param[in] rc error code return from firmware
733 *
734 * \return error string
735 ******************************************************************************/
736LIB_API const char *ni_ai_errno_to_str(int rc);
737#ifdef __cplusplus
738}
739#endif
Common NETINT definitions used by all modules.
#define NI_DEPRECATED
Definition ni_defs.h:80
#define NI_MAX_NUM_DATA_POINTERS
Definition ni_defs.h:244
ni_retcode_t
Definition ni_defs.h:447
Public definitions for operating NETINT video processing devices for video processing.
ni_pix_fmt_t
Logging definitions.
LIB_API void ni_usleep(int64_t usec)
Definition ni_util.c:366
LIB_API int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
thread mutex lock
Definition ni_util.c:4768
ni_retcode_t ni_timestamp_register(ni_queue_buffer_pool_t *p_buffer_pool, ni_timestamp_table_t *p_table, int64_t timestamp, uint64_t data_info)
Register timestamp in timestamp/frameoffset table.
Definition ni_util.c:2013
LIB_API int ni_retrieve_xcoder_params(char xcoderParams[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
Retrieve encoder config parameter values from –xcoder-params.
Definition ni_util.c:4497
void ni_buffer_pool_free(ni_queue_buffer_pool_t *p_buffer_pool)
Definition ni_util.c:1427
LIB_API ni_retcode_t ni_network_layer_convert_output(float *dst, uint32_t num, ni_packet_t *p_packet, ni_network_data_t *p_network, uint32_t layer)
Definition ni_util.c:3788
LIB_API ni_retcode_t ni_network_convert_data_to_tensor(float *dst, uint32_t dst_len, uint8_t *src, uint32_t src_len, ni_network_layer_params_t *p_param)
Definition ni_util.c:3963
ni_retcode_t ni_queue_push(ni_queue_buffer_pool_t *p_buffer_pool, ni_queue_t *p_queue, uint64_t frame_offset, int64_t timestamp)
Push into xcoder queue.
Definition ni_util.c:2181
void ni_dec_fme_buffer_pool_free(ni_buf_pool_t *p_buffer_pool)
Definition ni_util.c:1373
LIB_API void ni_copy_hw_yuv420p(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int width, int height, int bit_depth_factor, int is_semiplanar, int conf_win_right, int dst_stride[NI_MAX_NUM_DATA_POINTERS], int dst_height[NI_MAX_NUM_DATA_POINTERS], int src_stride[NI_MAX_NUM_DATA_POINTERS], int src_height[NI_MAX_NUM_DATA_POINTERS])
Copy YUV data to Netint HW YUV420p frame layout to be sent to encoder for encoding....
Definition ni_util.c:3056
int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error)
Parse name.
Definition ni_util.c:2673
LIB_API int ni_pthread_cond_destroy(ni_pthread_cond_t *cond)
destroy condition variables
Definition ni_util.c:4907
ni_retcode_t ni_quadra_card_identify_precheck(const char *p_dev)
precheck a device can be read by ni_device_capability_query() INFO OR ERROR logs will not be printed ...
Definition ni_util.c:5435
ni_retcode_t ni_queue_init(ni_session_context_t *p_ctx, ni_queue_t *p_queue, const char *name)
Initialize xcoder queue.
Definition ni_util.c:2154
LIB_API const char * ni_ai_errno_to_str(int rc)
return error string according to error code from firmware
Definition ni_util.c:5032
LIB_API ni_retcode_t ni_strtod_val(const char *str, double *out_val)
Safely convert a decimal string to a double with full validation. Trailing whitespace is tolerated.
Definition ni_util.c:2612
LIB_API ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition ni_util.c:663
LIB_API void ni_copy_frame_data(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, ni_pix_fmt_t pix_fmt, int conf_win_right, int dst_stride[NI_MAX_NUM_DATA_POINTERS], int dst_height[NI_MAX_NUM_DATA_POINTERS], int src_stride[NI_MAX_NUM_DATA_POINTERS], int src_height[NI_MAX_NUM_DATA_POINTERS])
Copy RGBA or YUV data to Netint HW frame layout to be sent to encoder for encoding....
Definition ni_util.c:3102
ni_retcode_t ni_queue_print(ni_queue_t *p_queue)
Print xcoder queue info.
Definition ni_util.c:2493
ni_buf_t * ni_buf_pool_allocate_buffer(ni_buf_pool_t *p_buffer_pool, int buffer_size)
Definition ni_util.c:1222
LIB_API int ni_insert_emulation_prevent_bytes(uint8_t *buf, int size)
Insert emulation prevention byte(s) as needed into the data buffer.
Definition ni_util.c:3295
uint32_t ni_decode_power_measurement(uint32_t power_value, const uint8_t *serial_number)
decode the raw current obtained and determine power
Definition ni_util.c:5095
LIB_API int ni_pthread_create(ni_pthread_t *thread, const ni_pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
create a new thread
Definition ni_util.c:4832
LIB_API void ni_fmt_fw_api_ver_str(const char ver_str[], char fmt_str[])
Get formatted FW API version string from unformatted FW API version string.
Definition ni_util.c:4353
LIB_API int ni_pthread_cond_signal(ni_pthread_cond_t *cond)
signal a condition
Definition ni_util.c:4962
ni_buf_t * ni_buf_pool_get_buffer(ni_buf_pool_t *p_buffer_pool)
Definition ni_util.c:1105
LIB_API uint64_t ni_gettime_ns(void)
Definition ni_util.c:2701
LIB_API char * ni_get_libxcoder_api_ver(void)
Get libxcoder API version.
Definition ni_util.c:4307
LIB_API int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args)
Definition ni_util.c:1054
LIB_API int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
destory a mutex
Definition ni_util.c:4750
LIB_API int ni_remove_emulation_prevent_bytes(uint8_t *buf, int size)
Remove emulation prevention byte(s) as needed from the data buffer.
Definition ni_util.c:3348
int32_t ni_dec_fme_buffer_pool_initialize(ni_session_context_t *p_ctx, int32_t number_of_buffers, int width, int height, int height_align, int factor)
Definition ni_util.c:1264
ni_retcode_t ni_timestamp_get_with_threshold(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Definition ni_util.c:2064
LIB_API ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode)
Definition ni_util.c:998
int32_t ni_atobool(const char *p_str, bool *b_error)
Convert string to boolean.
Definition ni_util.c:2550
uint32_t ni_round_up(uint32_t number_to_round, uint32_t multiple)
Definition ni_util.c:177
ni_retcode_t ni_queue_pop(ni_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Pop from the xcoder queue.
Definition ni_util.c:2252
LIB_API char * ni_get_libxcoder_release_ver(void)
Get libxcoder SW release version.
Definition ni_util.c:4419
LIB_API int ni_pthread_cond_init(ni_pthread_cond_t *cond, const ni_pthread_condattr_t *attr)
initialize condition variables
Definition ni_util.c:4888
LIB_API char * ni_strtok(char *s, const char *delim, char **saveptr)
Definition ni_util.c:429
LIB_API int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex)
initialize a mutex
Definition ni_util.c:4712
ni_retcode_t ni_timestamp_get(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frameoffset info.
Definition ni_util.c:2040
LIB_API ni_retcode_t ni_strncat(char *dest, size_t dmax, const char *src, size_t slen)
Definition ni_util.c:822
LIB_API struct tm * ni_localtime(struct tm *dest, const time_t *src)
Definition ni_util.c:1018
LIB_API void ni_get_hw_yuv420p_dim(int width, int height, int bit_depth_factor, int is_semiplanar, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
Definition ni_util.c:2743
int32_t ni_atoi(const char *p_str, bool *b_error)
Definition ni_util.c:2633
LIB_API void ni_copy_hw_descriptors(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS])
Copy Descriptor data to Netint HW descriptor frame layout to be sent to encoder for encoding....
Definition ni_util.c:4283
ni_retcode_t ni_timestamp_init(ni_session_context_t *p_ctx, ni_timestamp_table_t **pp_table, const char *name)
Initialize timestamp handling.
Definition ni_util.c:1948
LIB_API ni_retcode_t ni_network_layer_convert_tensor(uint8_t *dst, uint32_t dst_len, const char *tensor_file, ni_network_layer_params_t *p_param)
Definition ni_util.c:3943
LIB_API int ni_retrieve_xcoder_gop(char xcoderGop[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
Retrieve custom gop config values from –xcoder-gop.
Definition ni_util.c:4571
LIB_API void ni_get_min_frame_dim(int width, int height, ni_pix_fmt_t pix_fmt, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of frame to be sent to encoder for encoding. Caller usually retrieves this ...
Definition ni_util.c:2884
LIB_API int ni_pthread_cond_broadcast(ni_pthread_cond_t *cond)
broadcast a condition
Definition ni_util.c:4925
LIB_API ni_retcode_t ni_network_convert_tensor_to_data(uint8_t *dst, uint32_t dst_len, float *src, uint32_t src_len, ni_network_layer_params_t *p_param)
Definition ni_util.c:3953
LIB_API uint32_t ni_ai_network_layer_size(ni_network_layer_params_t *p_param)
Definition ni_util.c:4070
ni_retcode_t ni_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...
Definition ni_util.c:1821
LIB_API ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition ni_util.c:460
void ni_buf_pool_return_buffer(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool)
Definition ni_util.c:1166
double ni_atof(const char *p_str, bool *b_error)
Convert string to floating.
Definition ni_util.c:2653
LIB_API int ni_fscanf(FILE *stream, const char *fmt,...)
Definition ni_util.c:1035
ni_retcode_t ni_queue_free(ni_queue_t *p_queue, ni_queue_buffer_pool_t *p_buffer_pool)
Free xcoder queue.
Definition ni_util.c:2453
LIB_API ni_retcode_t ni_strtoi(const char *str, int32_t *out_val)
Safely convert a decimal string to a 32-bit integer with full validation. Trailing whitespace is tole...
Definition ni_util.c:2577
LIB_API void ni_calculate_sha256(const uint8_t aui8Data[], size_t ui32DataLength, uint8_t aui8Hash[])
Definition ni_util.c:4257
LIB_API int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
Definition ni_util.c:206
LIB_API NI_DEPRECATED char * ni_get_compat_fw_api_ver(void)
Get FW API version libxcoder is compatible with.
Definition ni_util.c:4320
LIB_API int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
Definition ni_util.c:1077
LIB_API int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
thread mutex unlock
Definition ni_util.c:4794
LIB_API int ni_cmp_fw_api_ver(const char ver1[], const char ver2[])
Compare two 3 character strings containing a FW API version. Handle comparision when FW API version f...
Definition ni_util.c:4383
void ni_timestamp_scan_cleanup(ni_timestamp_table_t *pts_list, ni_timestamp_table_t *dts_list, ni_queue_buffer_pool_t *p_buffer_pool)
Definition ni_util.c:2072
LIB_API int ni_pthread_sigmask(int how, const ni_sigset_t *set, ni_sigset_t *oldset)
examine and change mask of blocked signals
Definition ni_util.c:5016
LIB_API void ni_copy_yuv_444p_to_420p(uint8_t *p_dst0[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_dst1[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int width, int height, int factor, int mode)
Copy yuv444p data to yuv420p frame layout to be sent to encoder for encoding. Data buffer (dst) is us...
Definition ni_util.c:3182
LIB_API int ni_retrieve_decoder_params(char xcoderParams[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
Retrieve decoder config parameter values from –decoder-params.
Definition ni_util.c:4642
LIB_API int ni_param_get_key_value(char *p_str, char *key, char *value)
Retrieve key and value from 'key=value' pair.
Definition ni_util.c:4464
ni_retcode_t ni_check_dev_name(const char *p_dev)
check dev name
Definition ni_util.c:1892
LIB_API uint32_t ni_ai_network_layer_dims(ni_network_layer_params_t *p_param)
Definition ni_util.c:4076
LIB_API int32_t ni_gettimeofday(struct timeval *p_tp, void *p_tzp)
Get time for logs with microsecond timestamps.
Definition ni_util.c:147
LIB_API int ni_pthread_cond_wait(ni_pthread_cond_t *cond, ni_pthread_mutex_t *mutex)
wait on a condition
Definition ni_util.c:4944
LIB_API void ni_get_frame_dim(int width, int height, ni_pix_fmt_t pix_fmt, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of frame to be sent to encoder for encoding. Caller usually retrieves this ...
Definition ni_util.c:2795
LIB_API ni_retcode_t ni_strncpy(char *dest, size_t dmax, const char *src, size_t slen)
Definition ni_util.c:525
LIB_API int ni_pthread_cond_timedwait(ni_pthread_cond_t *cond, ni_pthread_mutex_t *mutex, const struct timespec *abstime)
wait on a condition
Definition ni_util.c:4982
ni_retcode_t ni_queue_pop_threshold(ni_queue_t *p_queue, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Definition ni_util.c:2358
LIB_API const char * ni_get_rc_txt(ni_retcode_t rc)
Get text string for the provided error.
Definition ni_util.c:4440
ni_retcode_t ni_timestamp_done(ni_timestamp_table_t *p_table, ni_queue_buffer_pool_t *p_buffer_pool)
Clean up timestamp handling.
Definition ni_util.c:1988
LIB_API ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src)
Definition ni_util.c:704
ni_retcode_t ni_timestamp_get_v2(ni_timestamp_table_t *p_table, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, ni_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frameoffset info.
Definition ni_util.c:2116
LIB_API int ni_pthread_join(ni_pthread_t thread, void **value_ptr)
join with a terminated thread
Definition ni_util.c:4859