libxcoder  3.5.1
ni_enc_api_logan.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_enc_api_logan.h
24 *
25 * \brief NETINT encoder API header file
26 *
27 *******************************************************************************/
28 #pragma once
29 
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36 #include "ni_defs_logan.h"
37 #include "ni_rsrc_api_logan.h"
38 #include "ni_util_logan.h"
39 #include "ni_device_api_logan.h"
40 #include "ni_av_codec_logan.h"
41 
42 typedef struct _ni_logan_enc_context
43 {
44  char *dev_xcoder; /* from the user command, which device allocation method we use */
45  int dev_enc_idx; /* index of the decoder on the xcoder card */
46  char *dev_enc_name; /* dev name of the xcoder card to use */
47  int keep_alive_timeout; /* keep alive timeout setting */
48  int set_high_priority; /*set_high_priority*/
49 
53  int64_t bit_rate;
54  int width;
55  int height;
56  int ff_log_level; /* ffmpeg log level */
58  int pix_fmt;
59 
60  // color metrics
62  int color_trc;
65 
66  // sample_aspect_ratio
67  int sar_num;
68  int sar_den;
69 
70  void *p_session_ctx; /* ni_logan_session_context_t */
71  void *p_encoder_params; /* ni_logan_encoder_params_t */
72  ni_logan_session_data_io_t *p_input_fme; /* used for sending raw data to xcoder */
73  ni_logan_session_data_io_t output_pkt; /* used for receiving bitstream from xcoder */
75 
76  /* Variables that need to be initialized */
77  int started;
78  uint8_t *p_spsPpsHdr;
80  int spsPpsAttach; /* Attach SPS&PPS to Packet */
82  int firstPktArrived; /* specially treat first pkt of the encoded bitstream */
84  int reconfigCount; /* count of reconfig */
86  int64_t first_frame_pts;
87  int64_t latest_dts;
88 
89  // original ConformanceWindowOffsets
90  int orig_conf_win_top; /*!*< A conformance window size of TOP */
91  int orig_conf_win_bottom; /*!*< A conformance window size of BOTTOM */
92  int orig_conf_win_left; /*!*< A conformance window size of LEFT */
93  int orig_conf_win_right; /*!*< A conformance window size of RIGHT */
94 
95  // to generate encoded bitstream headers
96  uint8_t *extradata;
98 
99  // low delay mode flags
100  int gotPacket; /* used to stop receiving packets when a packet is already received */
101  int sentFrame; /* used to continue receiving packets when a frame is sent and a packet is not yet received */
102 
103  // sync framerate
106 
107  /* actual device index/name of encoder after opened */
110 
111  int eos_fme_received; // received the eos frame from the ffmpeg interface
112  int encoder_flushing; // NI hardware encoder start flushing
113  int encoder_eof; // recieved eof from NI hardware encoder
115 
116 /*!*****************************************************************************
117  * \brief Initialize encode parameters, including ni_logan_enc_context_t,
118  * ni_logan_session_context_t and ni_logan_encoder_params_t
119  *
120  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
121  *
122  * \return On success
123  * NI_LOGAN_RETCODE_SUCCESS
124  * On failure
125  * NI_LOGAN_RETCODE_FAILURE
126  * NI_LOGAN_RETCODE_INVALID_PARAM,
127  * NI_LOGAN_RETCODE_ERROR_MEM_ALOC, etc
128  ******************************************************************************/
129 LIB_API int ni_logan_encode_init(ni_logan_enc_context_t *p_enc_ctx);
130 
131 /*!*****************************************************************************
132  * \brief Parse encoder parameters
133  * Check whether the parameters are reasonable
134  *
135  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
136  *
137  * \return On success
138  * NI_LOGAN_RETCODE_SUCCESS
139  * On failure
140  * NI_LOGAN_RETCODE_FAILURE,
141  * NI_LOGAN_RETCODE_INVALID_PARAM, etc.
142  ******************************************************************************/
144 
145 /*!*****************************************************************************
146  * \brief Get encoder headers from the hardware
147  *
148  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
149  *
150  * \return On success
151  * NI_LOGAN_RETCODE_SUCCESS
152  * On failure
153  * NI_LOGAN_RETCODE_FAILURE,
154  * NI_LOGAN_RETCODE_ERROR_MEM_ALOC, etc
155  ******************************************************************************/
156 LIB_API int ni_logan_encode_header(ni_logan_enc_context_t *p_enc_ctx);
157 
158 /*!*****************************************************************************
159  * \brief Open encoder
160  *
161  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
162  *
163  * \return On success
164  * NI_LOGAN_RETCODE_SUCCESS
165  * On failure
166  * NI_LOGAN_RETCODE_FAILURE
167  * NI_LOGAN_RETCODE_INVALID_PARAM, etc.
168  ******************************************************************************/
169 LIB_API int ni_logan_encode_open(ni_logan_enc_context_t *p_enc_ctx);
170 
171 /*!*****************************************************************************
172  * \brief Close encoder
173  *
174  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
175  *
176  * \return On success
177  * NI_LOGAN_RETCODE_SUCCESS
178  * On failure
179  * NI_LOGAN_RETCODE_FAILURE
180  * NI_LOGAN_RETCODE_INVALID_PARAM,
181  * NI_LOGAN_RETCODE_ERROR_MEM_ALOC,
182  * NI_LOGAN_RETCODE_ERROR_NVME_CMD_FAILED, etc
183  ******************************************************************************/
184 LIB_API int ni_logan_encode_close(ni_logan_enc_context_t *p_enc_ctx);
185 
186 
187 /*!*****************************************************************************
188  * \brief Get allocated ni_frame from fifo pool
189  *
190  * \param[in] p_enc_ctx Pointer to ni_logan_enc_context_t
191  *
192  * \return On success
193  * NI_LOGAN_RETCODE_SUCCESS
194  * On failure
195  * NI_LOGAN_RETCODE_FAILURE
196  ******************************************************************************/
197 LIB_API int ni_logan_encode_get_frame(ni_logan_enc_context_t *p_enc_ctx);
198 
199 /*!*****************************************************************************
200  * \brief Fill reconfig vfr
201  *
202  * \param[in] p_enc_ctx Pointer to ni_logan_enc_context_t
203  * \param[in/out] ni_frame aux_data may be updated
204  * \param[in] pts frame pts
205  *
206  * \return
207  ******************************************************************************/
209  ni_logan_frame_t *ni_frame,
210  int64_t pts);
211 
212 /*!*****************************************************************************
213  * \brief Copy frame data to NI frame
214  *
215  * \param[in/out] p_enc_ctx Pointer to ni_logan_enc_context_t
216  * \param[in] p_dec_frame Pointer to ni_logan_frame_t,
217  * contains aux data from NI decoder
218  * \param[in] p_data Pointer to input frame data
219  * \param[in] linesize Pointer to linesize of input frame
220  *
221  * \return On success
222  * NI_LOGAN_RETCODE_SUCCESS
223  * On failure
224  * NI_LOGAN_RETCODE_FAILURE,
225  * NI_LOGAN_RETCODE_ERROR_MEM_ALOC, etc
226  ******************************************************************************/
228  ni_logan_frame_t *p_dec_frame,
229  uint8_t *p_data[NI_LOGAN_MAX_NUM_DATA_POINTERS],
230  int linesize[NI_LOGAN_MAX_NUM_DATA_POINTERS]);
231 
232 
233 /*!*****************************************************************************
234  * \brief Send encode data to NI device
235  *
236  * \param[in] p_enc_ctx Pointer to ni_logan_enc_context_t
237  *
238  * \return On success
239  * NI_LOGAN_RETCODE_SUCCESS
240  * On failure
241  * NI_LOGAN_RETCODE_FAILURE,
242  * NI_LOGAN_RETCODE_INVALID_PARAM, etc.
243  ******************************************************************************/
244 LIB_API int ni_logan_encode_send(ni_logan_enc_context_t *p_enc_ctx);
245 
246 /*!*****************************************************************************
247  * \brief Copy NI packet to packet data buffer
248  *
249  * \param[in] p_enc_ctx Pointer to ni_logan_enc_context_t
250  * \param[out] p_data Pointer to output packet data buffer,
251  * \param[in] first_packet flag of first packet
252  * \param[in] sps_pps_attach flag of attached SPS/PPS
253  *
254  * \return On success
255  * NI_LOGAN_RETCODE_SUCCESS
256  * On failure
257  * NI_LOGAN_RETCODE_FAILURE,
258  * NI_LOGAN_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG, etc
259  ******************************************************************************/
261  uint8_t *p_data,
262  int first_packet,
263  int sps_pps_attach);
264 
265 /*!*****************************************************************************
266  * \brief Receive encoded data from NI device
267  *
268  * \param[in] p_enc_ctx Pointer to ni_logan_enc_context_t
269  *
270  * \return 0 when no packets received
271  * > 0 when new packet received, means the size of packet
272  * < 0 when failed, NI_LOGAN_RETCODE_FAILURE,
273  * NI_LOGAN_RETCODE_INVALID_PARAM, etc.
274  ******************************************************************************/
275 LIB_API int ni_logan_encode_receive(ni_logan_enc_context_t *p_enc_ctx);
276 
277 #ifdef __cplusplus
278 }
279 #endif
NETINT audio/video related utility functions.
Common NETINT definitions used by all modules.
#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...
LIB_API int ni_logan_encode_get_frame(ni_logan_enc_context_t *p_enc_ctx)
Get allocated ni_frame from fifo pool.
LIB_API int ni_logan_encode_open(ni_logan_enc_context_t *p_enc_ctx)
Open encoder.
LIB_API int ni_logan_encode_send(ni_logan_enc_context_t *p_enc_ctx)
Send encode data to NI device.
LIB_API int ni_logan_encode_copy_frame_data(ni_logan_enc_context_t *p_enc_ctx, ni_logan_frame_t *p_dec_frame, uint8_t *p_data[NI_LOGAN_MAX_NUM_DATA_POINTERS], int linesize[NI_LOGAN_MAX_NUM_DATA_POINTERS])
Copy frame data to NI frame.
LIB_API int ni_logan_encode_header(ni_logan_enc_context_t *p_enc_ctx)
Get encoder headers from the hardware.
LIB_API int ni_logan_encode_receive(ni_logan_enc_context_t *p_enc_ctx)
Receive encoded data from NI device.
LIB_API int ni_logan_encode_params_parse(ni_logan_enc_context_t *p_enc_ctx)
Parse encoder parameters Check whether the parameters are reasonable.
LIB_API void ni_logan_encode_reconfig_vfr(ni_logan_enc_context_t *p_enc_ctx, ni_logan_frame_t *ni_frame, int64_t pts)
Fill reconfig vfr.
LIB_API int ni_logan_encode_close(ni_logan_enc_context_t *p_enc_ctx)
Close encoder.
struct _ni_logan_enc_context ni_logan_enc_context_t
LIB_API int ni_logan_encode_init(ni_logan_enc_context_t *p_enc_ctx)
Initialize encode parameters, including ni_logan_enc_context_t, ni_logan_session_context_t and ni_log...
LIB_API int ni_logan_encode_copy_packet_data(ni_logan_enc_context_t *p_enc_ctx, uint8_t *p_data, int first_packet, int sps_pps_attach)
Copy NI packet to packet data buffer.
Exported definitions related to resource management of NI T-408 devices.
Exported utility routines definition.
ni_logan_fifo_buffer_t * input_data_fifo
ni_logan_session_data_io_t * p_input_fme
ni_logan_session_data_io_t output_pkt