Camera ID Incorrectly increasses when adding cameras using the REST API for test app 5

My system has the following specs:
GPU: GTX 1660ti
RAM: 32 GB
OS: Windows 11
Environment: Ubuntu 24.04.1 LTS (Through WSL)
Deepstream Version: 7.1
Nvidia-Driver Version: 566.03 | CUDA Version: 12.7

I have setup deepstream 7.1 with test-app5.
I have started a server using [source-list] along with [source-attr-all].
Here is the relevant part of the config:

num-source-bins=4
use-nvmultiurisrcbin=1
#To display stream name in FPS log, set stream-name-display=1
stream-name-display=1
#sensor-id-list vector is one to one mapped with the uri-list
#identifies each sensor by a unique ID
#sensor-id-list=cam1;cam2;cam3;cam4
#Optional sensor-name-list vector is one to one mapped with the uri-list
#sensor-name-list=cam1;cam2;cam3;cam4
max-batch-size=10
http-ip=localhost
http-port=9500
#Set low latency mode for bitstreams having I and IPPP frames on decoder
#low-latency-mode=0
#sgie batch size is number of sources * fair fraction of number of objects detected per frame per source
#the fair fraction of number of object detected is assumed to be 4
sgie-batch-size=40
#Set the below key to keep the application running at all times

[source-attr-all]
enable=1
type=3
num-sources=1
gpu-id=0
cudadec-memtype=0
latency=100
rtsp-reconnect-interval-sec=10
#Limit the rtsp reconnection attempts
rtsp-reconnect-attempts=4

I add cameras using the following command:

curl -XPOST 'http://172.20.60.31:9500/api/v1/stream/add' -d '{"key":"sensor","value":{"camera_id":"0","camera_name":"front_door","camera_url":"file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4","change":"camera_add","metadata":{"resolution":"1920x1080","codec":"h264","framerate":30}},"headers":{"source":"vst","created_at":"2021-06-01T14:34:13.417Z"}}'

I remove cameras using the following command:

curl -XPOST 'http://172.20.60.31:9500/api/v1/stream/remove' -d '{"key": "sensor","value":{"camera_id": "0","camera_name": "front_door","camera_url": "file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4","change": "camera_remove","metadata":{"resolution": "1920x1080","codec": "h264","framerate": 30}},"headers":{"source": "vst","created_at":"2021-06-01T14:34:13.417Z"}}'

In both cases I specify the camera_id as 0, If I attempt to add a camera with the same ID while this is still running I get an error which is expected.

The problem I am facing is that when the camera finishes processing and the stream ends I will call the same camera add command again a second time, it will work but increase the camera/stream ID from 0 to 1 and if I call it again the same way it will increase it again.

This happens even if I call the camera remove command before adding it again, it will still increase the camera/stream ID even if I specify the camera ID in the add command.

Is this an issue with deepstream or the way I have set up the server?

Any help will be highly appreciated.

I believe this has to do with source_id vs sensor_id (what you specify as camera_id in the REST API). Look at my post for more info.

How do you get the camera_id after you added a new source?

I am keeping track of the added camera with their Camera IDs separately via a custom backend server

I have tried with our deepstream-test5, the source_idwill keep growing, but the sensor_id won’t. This is normal.
Here are the steps I tried.

1. #define EN_DEBUG (1) in the `deepstream_test5_app_main.c`  to open more log
2. remove the source in the `test5_config_file_nvmultiurisrcbin_src_list_attr_all.txt` file.
[source-list]
num-source-bins=0
list=
use-nvmultiurisrcbin=1
#To display stream name in FPS log, set stream-name-display=1
stream-name-display=0
#sensor-id-list vector is one to one mapped with the uri-list
#identifies each sensor by a unique ID
#sensor-id-list=UniqueSensorId1;UniqueSensorId2
#Optional sensor-name-list vector is one to one mapped with the uri-list
#sensor-name-list=UniqueSensorName1;UniqueSensorName2
max-batch-size=10
http-ip=localhost
http-port=9000
#Set low latency mode for bitstreams having I and IPPP frames on decoder
#low-latency-mode=0
#sgie batch size is number of sources * fair fraction of number of objects detected per frame per source
#the fair fraction of number of object detected is assumed to be 4
sgie-batch-size=40
#Set the below key to keep the application running at all times

3. ./deepstream-test5-app -c configs/test5_config_file_nvmultiurisrcbin_src_list_attr_all.txt

4. After adding and removing the source through curl command, observe the following log
"this stream [4:1] was added using REST API"

@yuweiw
I have used your recommended setup.
The problem is that I am trying to do camera management where I want to enable and disable the same camera for a counting application. So once it is setup it has to be maintain the same camera ID which in my case is frame_meta->source_id.

I have predefined nvds analytics configs like so:

[line-crossing-stream-0]
enable=1
#Label;direction;lc
line-crossing-Entry=750;670;800;750;700;750;1500;600
line-crossing-Exit=900;1000;850;900;770;950;1750;630;
#line_color=0.75;0.25;0;1
class-id=-1
#extended when 0- only counts crossing on the configured Line
#              1- assumes extended Line crossing counts all the crossing
extended=0
#LC modes supported:
#loose   : counts all crossing without strong adherence to direction
#balanced: Strict direction adherence expected compared to mode=loose
#strict  : Strict direction adherence expected compared to mode=balanced
mode=balanced

In the above case I have to fix the source_id because I define the line counter for that specific source_id.
When I remove and then add the video via REST API it will increase the source_id and it won’t perform counting for that camera.
So I need a way to maintain the source_id in my application when using the REST API for camera management.

Is there any place in the source code where I can make modifications to achieve this ?
Or any parameters I can change to achieve this?

The source_id is determined by the number of src_pad in the nvstreammux. So if you want to customize this value, you should to modify the link logic of the nvstreammux.
For the nvmultiurisrcbin, you can try to modify the deepstream\sources\libs\gstnvdscustomhelper\gst-nvmultiurisrcbincreator.cpp source code.