libxcoder 5.8.0
Loading...
Searching...
No Matches
ni_filter_utils.c
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 filter_utils.c
24 *
25 * \brief Video filtering utility functions shared by Libxcoder API examples
26 ******************************************************************************/
27
28#include "ni_generic_utils.h"
29#include "ni_filter_utils.h"
30#include "ni_log.h"
31#include "ni_util.h"
32
33int ni_scaler_params_set_value(ni_scale_params_t *params, const char *name, const char *value)
34{
35 if (!params || !name || !value)
36 {
37 ni_log(NI_LOG_ERROR, "Error: Null pointer received in ni_scaler_params_set_value\n");
38 return -1;
39 }
40
41 if (!strcmp("width", name))
42 {
43 if (ni_strtoi(value, &params->width) != NI_RETCODE_SUCCESS)
44 {
45 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
46 return -1;
47 }
48 } else if (!strcmp("height", name))
49 {
50 if (ni_strtoi(value, &params->height) != NI_RETCODE_SUCCESS)
51 {
52 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
53 return -1;
54 }
55 } else if (!strcmp("format", name))
56 {
57 if (!strcmp(value, "yuv420p"))
58 {
59 params->format = GC620_I420;
60 } else if (!strcmp(value, "yuv420p10le"))
61 {
62 params->format = GC620_I010;
63 } else if (!strcmp(value, "nv12"))
64 {
65 params->format = GC620_NV12;
66 } else if (!strcmp(value, "p010le"))
67 {
68 params->format = GC620_P010_MSB;
69 } else
70 {
71 ni_log(NI_LOG_ERROR, "Error: pixel format %s not supported in scale\n", value);
72 return -1;
73 }
74 } else
75 {
76 ni_log(NI_LOG_ERROR, "Error: invalid scale param name %s\n", name);
77 return -1;
78 }
79
80 return 0;
81}
82
83int ni_drawbox_params_set_value(ni_drawbox_params_t *params, const char *name, const char *value)
84{
85 if (!params || !name || !value)
86 {
87 ni_log(NI_LOG_ERROR, "Error: Null pointer received in ni_drawbox_params_set_value\n");
88 return -1;
89 }
90
91 if (!strcmp("width", name))
92 {
93 if (ni_strtoi(value, &params->box_w) != NI_RETCODE_SUCCESS)
94 {
95 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
96 return -1;
97 }
98 } else if (!strcmp("height", name))
99 {
100 if (ni_strtoi(value, &params->box_h) != NI_RETCODE_SUCCESS)
101 {
102 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
103 return -1;
104 }
105 } else if (!strcmp("x", name))
106 {
107 if (ni_strtoi(value, &params->box_x) != NI_RETCODE_SUCCESS)
108 {
109 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
110 return -1;
111 }
112 } else if (!strcmp("y", name))
113 {
114 if (ni_strtoi(value, &params->box_y) != NI_RETCODE_SUCCESS)
115 {
116 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for %s: %s\n", __func__, name, value);
117 return -1;
118 }
119 } else
120 {
121 ni_log(NI_LOG_ERROR, "Error: invalid drawbox param name %s\n", name);
122 return -1;
123 }
124
125 return 0;
126}
127
128int retrieve_filter_params(char filter_params[], ni_scale_params_t *scale_params, ni_drawbox_params_t *drawbox_params)
129{
130 char key[64], value[64];
131 char *curr = filter_params, *colon_pos;
132 int ret = 0;
133
134 //reset all params to default values first
135 memset(scale_params, 0, sizeof(ni_scale_params_t));
136 memset(drawbox_params, 0, sizeof(ni_drawbox_params_t));
137 scale_params->format = GC620_I420;
138
139 if (strncmp("ni_quadra_scale", curr, 15) == 0)
140 {
141 scale_params->enabled = 1;
142 curr += 16;
143 }
144 else if (strncmp("ni_quadra_drawbox", curr, 17) == 0)
145 {
146 drawbox_params->enabled = 1;
147 curr += 18;
148 }
149 else
150 {
151 ni_log(NI_LOG_ERROR, "Error: invalid filter, must be one of [ni_quadra_scale, ni_quadra_drawbox]");
152 return -1;
153 }
154
155 while (*curr)
156 {
157 colon_pos = strchr(curr, ':');
158
159 if (colon_pos)
160 {
161 *colon_pos = '\0';
162 }
163
164 if (strlen(curr) > sizeof(key) + sizeof(value) - 1 ||
165 ni_param_get_key_value(curr, key, value))
166 {
167 ni_log(NI_LOG_ERROR, "Error: cannot retrieve key/value from filter param: %s\n", curr);
168 ret = -1;
169 break;
170 }
171
172 if (scale_params->enabled)
173 {
174 ret = ni_scaler_params_set_value(scale_params, key, value);
175 } else
176 {
177 ret = ni_drawbox_params_set_value(drawbox_params, key, value);
178 }
179 if (ret != 0)
180 {
181 break;
182 }
183
184 if (colon_pos)
185 {
186 curr = colon_pos + 1;
187 } else
188 {
189 curr += strlen(curr);
190 }
191 }
192 return ret;
193}
194
195/*!*****************************************************************************
196 * \brief Init scaler params here - both user setting params and fixed params.
197 *
198 * \param
199 *
200 * \return 0 if successful, < 0 otherwise
201 ******************************************************************************/
202void init_scaler_params(ni_scaler_input_params_t *p_scaler_params, ni_scaler_opcode_t op, int in_rec_width,
203 int in_rec_height, int in_rec_x, int in_rec_y, int out_rec_x, int out_rec_y)
204{
205 p_scaler_params->op = op;
206 // input_format/width/height, output_format/width/height should be assigned by users for all ops
207 if (op == NI_SCALER_OPCODE_CROP)
208 {
209 // fixed numbers
210 p_scaler_params->out_rec_width = 0;
211 p_scaler_params->out_rec_height = 0;
212 p_scaler_params->out_rec_x = 0;
213 p_scaler_params->out_rec_y = 0;
214 p_scaler_params->rgba_color = 0;
215
216 // params set by user
217 p_scaler_params->in_rec_width = in_rec_width;
218 p_scaler_params->in_rec_height = in_rec_height;
219 p_scaler_params->in_rec_x = in_rec_x;
220 p_scaler_params->in_rec_y = in_rec_y;
221 } else if (op == NI_SCALER_OPCODE_SCALE)
222 {
223 // fixed params
224 p_scaler_params->in_rec_width = 0;
225 p_scaler_params->in_rec_height = 0;
226 p_scaler_params->in_rec_x = 0;
227 p_scaler_params->in_rec_y = 0;
228
229 p_scaler_params->out_rec_width = 0;
230 p_scaler_params->out_rec_height = 0;
231 p_scaler_params->out_rec_x = 0;
232 p_scaler_params->out_rec_y = 0;
233
234 p_scaler_params->rgba_color = 0;
235 } else if (op == NI_SCALER_OPCODE_PAD)
236 {
237 // fixed params
238 p_scaler_params->in_rec_width = p_scaler_params->input_width;
239 p_scaler_params->in_rec_height = p_scaler_params->input_height;
240 p_scaler_params->in_rec_x = 0;
241 p_scaler_params->in_rec_y = 0;
242
243 p_scaler_params->out_rec_width = p_scaler_params->input_width;
244 p_scaler_params->out_rec_height = p_scaler_params->input_height;
245
246 /*
247 Scaler uses BGRA color, or ARGB in little-endian
248 ui32RgbaColor = (s->rgba_color[3] << 24) | (s->rgba_color[0] << 16) |
249 (s->rgba_color[1] << 8) | s->rgba_color[2];
250 here p_scaler_params->rgba_color = ui32RgbaColor;
251 */
252 p_scaler_params->rgba_color =
253 4278190080; // now padding color is black
254
255 // params set by user
256 p_scaler_params->out_rec_x = out_rec_x;
257 p_scaler_params->out_rec_y = out_rec_y;
258 } else if (op == NI_SCALER_OPCODE_OVERLAY)
259 {
260 // fixed params
261 // set the in_rec params to the w/h of overlay(the upper) frames
262 p_scaler_params->in_rec_width = p_scaler_params->input_width;
263 p_scaler_params->in_rec_height = p_scaler_params->input_height;
264
265 // the output w/h is the main frame's w/h (main frame is the lower/background frame)
266 p_scaler_params->out_rec_width = p_scaler_params->output_width;
267 p_scaler_params->out_rec_height = p_scaler_params->output_height;
268 p_scaler_params->out_rec_x = 0;
269 p_scaler_params->out_rec_y = 0;
270 p_scaler_params->rgba_color = 0;
271
272 // params set by user
273 p_scaler_params->in_rec_x = in_rec_x;
274 p_scaler_params->in_rec_y = in_rec_y;
275 }
276}
277
278/*!*****************************************************************************
279 * \brief open scaler session
280 *
281 * \param
282 *
283 * \return 0 if successful, < 0 otherwise
284 ******************************************************************************/
285int scaler_session_open(ni_session_context_t *p_scaler_ctx, int iXcoderGUID, ni_scaler_opcode_t op)
286{
287 int ret = 0;
288
289 p_scaler_ctx->session_id = NI_INVALID_SESSION_ID;
290
291 p_scaler_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
292 p_scaler_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
293 p_scaler_ctx->hw_id = iXcoderGUID;
294 p_scaler_ctx->device_type = NI_DEVICE_TYPE_SCALER;
295 p_scaler_ctx->scaler_operation = op;
297
299
300 if (ret != NI_RETCODE_SUCCESS)
301 {
302 ni_log(NI_LOG_ERROR, "Error: ni_scaler_session_open() failure!\n");
303 return -1;
304 } else
305 {
306#ifdef _WIN32
307 ni_log(NI_LOG_INFO, "Scaler session open: device_handle %p, session_id %u.\n",
308 p_scaler_ctx->device_handle, p_scaler_ctx->session_id);
309#else
310 ni_log(NI_LOG_INFO, "Scaler session open: device_handle %d, session_id %u.\n",
311 p_scaler_ctx->device_handle, p_scaler_ctx->session_id);
312#endif
313 return 0;
314 }
315}
316
317/*!*****************************************************************************
318 * \brief Launch scaler operation and get the result hw frame
319 *
320 * \param
321 *
322 * \return 0 if successful, < 0 otherwise
323 ******************************************************************************/
324int launch_scaler_operation(ni_session_context_t *p_scaler_ctx, int iXcoderGUID,
325 ni_frame_t *p_frame_in_up, ni_frame_t *p_frame_in_bg,
326 ni_session_data_io_t *p_data_out, ni_scaler_input_params_t scaler_params)
327{
328 int ret = 0;
329 niFrameSurface1_t *frame_surface_up;
330 niFrameSurface1_t *frame_surface_bg;
331 niFrameSurface1_t *frame_surface_output;
332
333 if (p_scaler_ctx->session_id == NI_INVALID_SESSION_ID)
334 {
335 // Open scaler session
336 if (0 != scaler_session_open(p_scaler_ctx, iXcoderGUID, scaler_params.op))
337 {
338 ni_log(NI_LOG_ERROR, "Error: scaler open session error\n");
339 return -1;
340 }
341
342 // init scaler hwframe pool
343 if (0 != ni_scaler_frame_pool_alloc(p_scaler_ctx, scaler_params))
344 {
345 ni_log(NI_LOG_ERROR, "Error: init filter hwframe pool\n");
346 return -1;
347 }
348 }
349
350 // allocate a ni_frame_t structure on the host PC
351 ret = ni_frame_buffer_alloc_hwenc(&p_data_out->data.frame,
352 scaler_params.output_width,
353 scaler_params.output_height, 0);
354 if (ret != 0)
355 {
356 return -1;
357 }
358
359 // out_frame retrieved from decoder
360 frame_surface_up = (niFrameSurface1_t *)(p_frame_in_up->p_data[3]);
361 frame_surface_bg = (niFrameSurface1_t *)(p_frame_in_bg->p_data[3]);
362
363 // Allocate scaler input frame
364 ret = ni_scaler_input_frame_alloc(p_scaler_ctx, scaler_params, frame_surface_up);
365 if (ret != 0)
366 {
367 return -1;
368 }
369
370 // Allocate scaler destination frame.
371 ret = ni_scaler_dest_frame_alloc(p_scaler_ctx, scaler_params, frame_surface_bg);
372 if (ret != 0)
373 {
374 return -1;
375 }
376
377 // Retrieve hardware frame info from 2D engine and put it in the ni_frame_t structure.
378 ret = ni_device_session_read_hwdesc(p_scaler_ctx, p_data_out, NI_DEVICE_TYPE_SCALER);
379 frame_surface_output = (niFrameSurface1_t *)(p_data_out->data.frame.p_data[3]);
380 ni_log(NI_LOG_DEBUG, "%s: output FID %u \n", __func__,
381 frame_surface_output->ui16FrameIdx);
382 if (ret < 0)
383 {
384 ni_frame_buffer_free(p_frame_in_up);
385 ni_frame_buffer_free(p_frame_in_bg);
386 ni_frame_buffer_free(&p_data_out->data.frame);
387 }
388
389 return ret;
390}
391
392/*!*****************************************************************************
393 * \brief Use crop->pad->overlay to simulate a drawbox filter.
394 *
395 * \param
396 *
397 * \return 0 if successful, < 0 otherwise
398 ******************************************************************************/
400 ni_session_context_t *p_overlay_ctx, ni_session_context_t *p_fmt_ctx,
401 ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, ni_drawbox_params_t *p_box_params,
402 int iXcoderGUID, int input_format, int output_format)
403{
404 // set default box params
405 int box_width = 80;
406 int box_height = 60;
407 int box_x = 160;
408 int box_y = 100;
409 int line_width = 4;
410 if (p_box_params)
411 {
412 box_width = ((int)((p_box_params->box_w + 1) / 2) * 2);
413 box_height = ((int)((p_box_params->box_h + 1) / 2) * 2);
414 box_x = p_box_params->box_x;
415 box_y = p_box_params->box_y;
416 }
417
418 /*
419 To simulate a drawbox filter, we need to
420 1. Crop at the box set position
421 2. Padding the crop output frame for fixed fixels (depends on the line_width of the box)
422 Recycle the crop hwFrame
423 3. Overlay the padding result on the original frame
424 Recycle the padding hwFrame
425 4. if format-change is needed, launch a scale operation and do format change
426 Recycle the overlay hwFrame
427 */
428
429 int ret = 0;
430 niFrameSurface1_t *p_surface_in;
431 p_surface_in = (niFrameSurface1_t *)(p_frame_in->p_data[3]);
432
433 ni_scaler_input_params_t crop_params = {0};
434 crop_params.input_format = input_format;
435 crop_params.input_width = p_surface_in->ui16width;
436 crop_params.input_height = p_surface_in->ui16height;
437 crop_params.output_format = GC620_I420;
438 crop_params.output_width = box_width;
439 crop_params.output_height = box_height;
440 init_scaler_params(&crop_params, NI_SCALER_OPCODE_CROP, box_width,
441 box_height, box_x, box_y, 0, 0);
442 ni_session_data_io_t crop_data = {0};
443 ret = launch_scaler_operation(p_crop_ctx, iXcoderGUID, p_frame_in,
444 p_frame_in, &crop_data, crop_params);
445 if (ret != 0)
446 {
447 ni_log(NI_LOG_ERROR, "Failed to lauch scaler operation %d\n", crop_params.op);
448 return -1;
449 }
450 niFrameSurface1_t *crop_frame_surface =
451 (niFrameSurface1_t *)(crop_data.data.frame.p_data[3]);
452 ni_hw_frame_ref(crop_frame_surface);
453
454 ni_scaler_input_params_t pad_params = {0};
455 pad_params.input_format = input_format;
456 pad_params.input_width = crop_params.output_width;
457 pad_params.input_height = crop_params.output_height;
458 pad_params.output_format = GC620_I420;
459 pad_params.output_width = crop_params.output_width + line_width * 2;
460 pad_params.output_height = crop_params.output_height + line_width * 2;
461 init_scaler_params(&pad_params, NI_SCALER_OPCODE_PAD, 0, 0, 0, 0,
462 line_width, line_width);
463 ni_session_data_io_t pad_data = {0};
464 ret = launch_scaler_operation(p_pad_ctx, iXcoderGUID, &crop_data.data.frame,
465 &crop_data.data.frame, &pad_data, pad_params);
466 // recycle HwFrameIdx first, then free the frame
467 ni_hw_frame_unref(crop_frame_surface->ui16FrameIdx);
468 ni_frame_buffer_free(&(crop_data.data.frame));
469 if (ret != 0)
470 {
471 ni_log(NI_LOG_ERROR, "Failed to lauch scaler operation %d\n", pad_params.op);
472 return -1;
473 }
474 niFrameSurface1_t *pad_frame_surface =
475 (niFrameSurface1_t *)(pad_data.data.frame.p_data[3]);
476 ni_hw_frame_ref(pad_frame_surface);
477
478 ni_scaler_input_params_t overlay_params = {0};
479 overlay_params.input_format = input_format;
480 overlay_params.input_width = pad_params.output_width;
481 overlay_params.input_height = pad_params.output_height;
482 overlay_params.output_format = GC620_I420;
483 overlay_params.output_width = p_surface_in->ui16width;
484 overlay_params.output_height = p_surface_in->ui16height;
485 int overlay_x = box_x - line_width;
486 int overlay_y = box_y - line_width;
487 init_scaler_params(&overlay_params, NI_SCALER_OPCODE_OVERLAY, 0, 0,
488 overlay_x, overlay_y, 0, 0);
489 ni_session_data_io_t ovly_data = {0};
490 if (output_format == GC620_I420)
491 ret = launch_scaler_operation(p_overlay_ctx, iXcoderGUID,
492 &pad_data.data.frame, p_frame_in,
493 p_data_out, overlay_params);
494 else
495 ret = launch_scaler_operation(p_overlay_ctx, iXcoderGUID,
496 &pad_data.data.frame, p_frame_in,
497 &ovly_data, overlay_params);
498 // recycle HwFrameIdx first, then free the frame
499 ni_hw_frame_unref(pad_frame_surface->ui16FrameIdx);
500 ni_frame_buffer_free(&(pad_data.data.frame));
501 if (ret != 0)
502 {
503 ni_log(NI_LOG_ERROR, "Failed to lauch scaler operation %d\n", overlay_params.op);
504 return -1;
505 }
506
507 if (output_format != GC620_I420) // use scale filter to do format change
508 {
509 niFrameSurface1_t *ovly_frame_surface =
510 (niFrameSurface1_t *)(ovly_data.data.frame.p_data[3]);
511 ni_hw_frame_ref(ovly_frame_surface);
512 ovly_frame_surface->ui16width = overlay_params.output_width;
513 ovly_frame_surface->ui16height = overlay_params.output_height;
514 ret = scale_filter(p_fmt_ctx, &(ovly_data.data.frame), p_data_out,
515 iXcoderGUID, overlay_params.output_width,
516 overlay_params.output_height, GC620_I420,
517 output_format);
518 ni_hw_frame_unref(ovly_frame_surface->ui16FrameIdx);
519 ni_frame_buffer_free(&ovly_data.data.frame);
520 if (ret != 0)
521 {
522 ni_log(NI_LOG_ERROR, "Failed to lauch scaler operation 0\n");
523 return -1;
524 }
525 }
526
527 return 0;
528}
529
530/*!*****************************************************************************
531 * \brief Do a scale and/or format-change operation.
532 *
533 * \param
534 *
535 * \return 0 if successful, < 0 otherwise
536 ******************************************************************************/
538 ni_session_data_io_t *p_data_out, int iXcoderGUID,
539 int scale_width, int scale_height, int in_format, int out_format)
540{
541 int ret;
542 niFrameSurface1_t *p_surface_in;
543 ni_scaler_input_params_t scale_params = {0};
544
545 p_surface_in = (niFrameSurface1_t *)p_frame_in->p_data[3];
546 scale_params.output_format = out_format; // rgba or bgrp or yuv420p;
547 scale_params.output_width = scale_width;
548 scale_params.output_height = scale_height;
549 scale_params.input_format = in_format;
550 scale_params.input_width = p_surface_in ? p_surface_in->ui16width : 0;
551 scale_params.input_height = p_surface_in ? p_surface_in->ui16height : 0;
552 init_scaler_params(&scale_params, NI_SCALER_OPCODE_SCALE, 0, 0, 0, 0, 0, 0);
553
554 ret = launch_scaler_operation(p_ctx, iXcoderGUID, p_frame_in, p_frame_in,
555 p_data_out, scale_params);
556 if (ret != 0)
557 {
558 ni_log(NI_LOG_ERROR, "Failed to lauch scaler operation %d\n", scale_params.op);
559 return -1;
560 }
561
562 return ret;
563}
@ NI_DEVICE_TYPE_SCALER
Definition ni_defs.h:362
@ NI_SCALER_OPCODE_PAD
Definition ni_defs.h:597
@ NI_SCALER_OPCODE_OVERLAY
Definition ni_defs.h:598
@ NI_SCALER_OPCODE_CROP
Definition ni_defs.h:595
@ NI_SCALER_OPCODE_SCALE
Definition ni_defs.h:594
enum _ni_scaler_opcode ni_scaler_opcode_t
@ NI_RETCODE_SUCCESS
Definition ni_defs.h:448
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
ni_retcode_t ni_scaler_frame_pool_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params)
init output pool of scaler frames
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
ni_retcode_t ni_scaler_dest_frame_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params, niFrameSurface1_t *p_surface)
allocate device destination frame from scaler hwframe pool
ni_retcode_t ni_scaler_input_frame_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params, niFrameSurface1_t *p_src_surface)
allocate device input frame by hw descriptor. This call won't actually allocate a frame but sends the...
ni_retcode_t ni_frame_buffer_alloc_hwenc(ni_frame_t *p_frame, int video_width, int video_height, int extra_len)
Allocate memory for the hwDescriptor buffer based on provided parameters taking into account pic size...
int ni_device_session_read_hwdesc(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Read data from the device If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from decoder If ...
#define GC620_I420
#define GC620_NV12
#define GC620_P010_MSB
#define NI_INVALID_SESSION_ID
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define GC620_I010
void init_scaler_params(ni_scaler_input_params_t *p_scaler_params, ni_scaler_opcode_t op, int in_rec_width, int in_rec_height, int in_rec_x, int in_rec_y, int out_rec_x, int out_rec_y)
Init scaler params here - both user setting params and fixed params.
int scale_filter(ni_session_context_t *p_ctx, ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, int iXcoderGUID, int scale_width, int scale_height, int in_format, int out_format)
Do a scale and/or format-change operation.
int retrieve_filter_params(char filter_params[], ni_scale_params_t *scale_params, ni_drawbox_params_t *drawbox_params)
int ni_scaler_params_set_value(ni_scale_params_t *params, const char *name, const char *value)
int drawbox_filter(ni_session_context_t *p_crop_ctx, ni_session_context_t *p_pad_ctx, ni_session_context_t *p_overlay_ctx, ni_session_context_t *p_fmt_ctx, ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, ni_drawbox_params_t *p_box_params, int iXcoderGUID, int input_format, int output_format)
Use crop->pad->overlay to simulate a drawbox filter.
int launch_scaler_operation(ni_session_context_t *p_scaler_ctx, int iXcoderGUID, ni_frame_t *p_frame_in_up, ni_frame_t *p_frame_in_bg, ni_session_data_io_t *p_data_out, ni_scaler_input_params_t scaler_params)
Launch scaler operation and get the result hw frame.
int scaler_session_open(ni_session_context_t *p_scaler_ctx, int iXcoderGUID, ni_scaler_opcode_t op)
open scaler session
int ni_drawbox_params_set_value(ni_drawbox_params_t *params, const char *name, const char *value)
void ni_hw_frame_unref(uint16_t hwframe_index)
void ni_hw_frame_ref(const niFrameSurface1_t *p_surface)
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Definition ni_log.c:183
Logging definitions.
@ NI_LOG_DEBUG
Definition ni_log.h:64
@ NI_LOG_ERROR
Definition ni_log.h:62
@ NI_LOG_INFO
Definition ni_log.h:63
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_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
Utility definitions.
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
ni_device_handle_t device_handle
ni_device_handle_t blk_io_handle
union _ni_session_data_io::@19 data