NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __NVDS_ENCODE_OBJECT_COMMON_H__
19 #define __NVDS_ENCODE_OBJECT_COMMON_H__
20 
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif
25 
26 #define get_max(x, y) (((x) > (y)) ? (x) : (y))
27 #define ROUND_DOWN_2(num) ((num)&(~1))
28 
29 typedef GList NvDsBufferList;
30 
31 typedef struct _NvDsObjEncCtx
32 {
38  GCond buffer_cond;
40  int num_cores;
43  gboolean buffers_alloted;
44  GThreadPool *thread_pool;
45  int gpu_id;
50  /* List of available & initialised encoder instances.
51  * As allocating jtegra surfaces take up a lot of time,
52  * maintaining two lists helps in re-using encoder instances
53  * with already allocated surfaces.
54  */
56  /* List of available & un-initialised encoder instances */
57  GList *free_list;
58  /* List of encode instances in-use */
59  GList *occupied_list;
62  /* To calculate avg encode time (in ms) */
63  long double avg_encode_time;
64  /* No. of encodes for which calcEncodeTime is enabled by the user */
65  long long int total_encodes;
66  long double total_encode_time;
68 
69 typedef struct _NvDsJpegConvArgs
70 {
79  long long int initTimeSec;
80  long long int initTimeUsec;
82 
83 void NvDsCloseJpegLib (void *);
84 
85 void NvDsCloseJpegLib_DGPU (void *);
86 
87 void NvDsOpenJpegLib (void *);
88 
89 void NvDsOpenJpegLib_DGPU (void *);
90 
91 gboolean jpeg_convert (NvDsJpegConvArgs *);
92 
94 
95 gboolean allocate_buffers (NvDsObjEncCtxHandle, NvBufSurface *, int, int);
96 
98 
99 void jpeg_write_to_file (uint8_t *, uint64_t, char *);
100 
102 
103 gpointer nvds_copy_image_encode_meta (gpointer, gpointer);
104 
105 void nvds_release_image_encode_meta (gpointer, gpointer);
106 
108 
110 
111 /* Initialises encoder instances by allocating memory for structures and
112  * calling jpeg function calls.
113  */
116 
117 /* Frees allocated structures and calls destroy on encoder instances */
120 
121 /* Acquires an encoder instance from the pool of encoder instances.
122  * Acquire takes place from the free_init_list first for an
123  * encoder instance whose jtegra surfaces have already been allocated.
124  * If no such instances are available then acquire takes place from the
125  * free_list which has encoder instances whose jtegra surfaces haven't been
126  * allocated.
127  */
130 
131 /* Releases the encoder instance back to the free_init_list after encode
132  * has finished.
133  */
136 
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif
NvDsCloseJpegLib_DGPU
void NvDsCloseJpegLib_DGPU(void *)
NvDsOpenJpegLib_DGPU
void NvDsOpenJpegLib_DGPU(void *)
_NvDsObjEncCtx::avg_encode_time
long double avg_encode_time
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:63
_NvDsObjEncCtx::total_encode_time
long double total_encode_time
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:66
_NvDsJpegConvArgs::height
uint height
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:78
_NvDsObjEncCtx::handle_nvml_lib
void * handle_nvml_lib
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:48
destroy_encoder_instances
void destroy_encoder_instances(NvDsObjEncCtxHandle)
_NvDsObjEncCtx::signal_encode
GCond signal_encode
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:61
_NvDsJpegConvArgs::width
uint width
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:77
NvDsObjEncCtx
struct _NvDsObjEncCtx NvDsObjEncCtx
_NvDsJpegConvArgs::initTimeSec
long long int initTimeSec
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:79
_NvDsObjEncCtx::empty_list_mutex
GMutex empty_list_mutex
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:37
NvBufSurface
Holds information about batched buffers.
Definition: includes/nvbufsurface.h:602
acquire_encoder_instance
GList * acquire_encoder_instance(NvDsObjEncCtxHandle)
deallocate_buffers
gboolean deallocate_buffers(NvDsObjEncCtxHandle)
_NvDsObjEncCtx::frame_finish_cond
GCond frame_finish_cond
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:39
_NvDsObjEncCtx::empty_list
NvDsBufferList * empty_list
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:33
NvDsCloseJpegLib
void NvDsCloseJpegLib(void *)
_NvDsObjEncCtx::free_init_list
GList * free_init_list
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:55
_NvDsObjEncUsrArgs
Holds user parameters for a nvds_obj_enc_process call.
Definition: includes/nvds_obj_encode.h:61
_NvDsObjEncCtx::total_encodes
long long int total_encodes
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:65
_NvDsObjEncCtx::num_empty_elements
int num_empty_elements
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:34
jpeg_convert
gboolean jpeg_convert(NvDsJpegConvArgs *)
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: includes/nvbufsurftransform.h:40
nvds_acquire_buffer_from_pool
NvDsBufferList * nvds_acquire_buffer_from_pool(NvDsObjEncCtxHandle)
uint
unsigned int uint
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:25
_NvDsObjEncCtx::full_list
NvDsBufferList * full_list
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:35
_NvDsJpegConvArgs::objMeta
NvDsObjectMeta * objMeta
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:74
_NvDsJpegConvArgs::initTimeUsec
long long int initTimeUsec
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:80
NvDsOpenJpegLib
void NvDsOpenJpegLib(void *)
destroy_encoder_instances_dgpu
void destroy_encoder_instances_dgpu(NvDsObjEncCtxHandle)
_NvDsObjEncCtx::cuda_stream
cudaStream_t cuda_stream
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:46
jpeg_write_to_file
void jpeg_write_to_file(uint8_t *, uint64_t, char *)
NvDsBufferList
GList NvDsBufferList
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:29
_NvDsJpegConvArgs::scratchBuffer
NvBufSurface * scratchBuffer
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:73
nvds_copy_image_encode_meta
gpointer nvds_copy_image_encode_meta(gpointer, gpointer)
release_encoder_instance
void release_encoder_instance(NvDsObjEncCtxHandle, GList *)
_NvDsObjEncCtx::supports_unified_mem
int supports_unified_mem
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:47
calculate_encode_time
void calculate_encode_time(NvDsJpegConvArgs *)
init_encoder_instances_dgpu
void init_encoder_instances_dgpu(NvDsObjEncCtx *)
_NvDsObjEncCtx::occupied_list
GList * occupied_list
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:59
_NvDsJpegConvArgs::tempList
NvDsBufferList * tempList
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:71
NvDsJpegConvArgs
struct _NvDsJpegConvArgs NvDsJpegConvArgs
_NvDsObjEncCtx::num_cores
int num_cores
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:40
_NvDsJpegConvArgs::userData
NvDsObjEncUsrArgs * userData
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:76
_NvDsJpegConvArgs
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:69
_NvDsObjEncCtx::enc_list_mutex
GMutex enc_list_mutex
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:60
_NvDsObjEncCtx::handle_jpeg_lib
void * handle_jpeg_lib
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:49
nvds_release_image_encode_meta
void nvds_release_image_encode_meta(gpointer, gpointer)
_NvDsObjEncCtx::scratch_buffer
NvBufSurface ** scratch_buffer
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:42
release_encoder_instance_dgpu
void release_encoder_instance_dgpu(NvDsObjEncCtxHandle, GList *)
_NvDsJpegConvArgs::ctx
NvDsObjEncCtxHandle ctx
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:72
_NvDsObjEncCtx::free_list
GList * free_list
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:57
init_encoder_instances
void init_encoder_instances(NvDsObjEncCtx *)
nvds_release_buffer_to_pool
void nvds_release_buffer_to_pool(NvDsObjEncCtxHandle, NvDsBufferList *)
_NvDsObjEncCtx::num_full_elements
int num_full_elements
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:36
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: includes/nvdsmeta.h:308
allocate_buffers
gboolean allocate_buffers(NvDsObjEncCtxHandle, NvBufSurface *, int, int)
_NvDsObjEncCtx::buffer_cond
GCond buffer_cond
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:38
_NvDsObjEncCtx::buffers_alloted
gboolean buffers_alloted
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:43
_NvDsObjEncCtx::thread_pool
GThreadPool * thread_pool
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:44
_NvDsObjEncCtx::gpu_id
int gpu_id
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:45
_NvDsObjEncCtx
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:31
_NvDsJpegConvArgs::frameMeta
NvDsFrameMeta * frameMeta
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:75
_NvDsObjEncCtx::is_integrated
int is_integrated
Definition: sources/libs/nvll_batch_jpeg_encode/nvds_obj_encode_common.h:41
acquire_encoder_instance_dgpu
GList * acquire_encoder_instance_dgpu(NvDsObjEncCtxHandle)
jpeg_convert_dgpu
gboolean jpeg_convert_dgpu(NvDsJpegConvArgs *)
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: includes/nvdsmeta.h:367