Files
bytetrack-counter-cpp/AGENTS.md
T

70 lines
2.4 KiB
Markdown

# AGENTS.md — ByteTrack Counter C++
## RKNN Dynamic Shape Requirement
The RKNN model (`zenai_apc_cicalengka_20260609.rknn`) is exported with **dynamic input shapes** (`model inference type: dynamic_shape`). The C API **requires** calling `rknn_set_input_shapes()` before `rknn_inputs_set()`. Without it, `librknnrt.so` crashes with:
```
std::out_of_range: vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 1)
```
This is called in the constructor of `RKNNYOLO` at `src/rknn_yolo.cpp:60`, right after querying input attributes:
```cpp
in_attr.dims[0] = 1;
in_attr.dims[1] = imgsz_;
in_attr.dims[2] = imgsz_;
in_attr.dims[3] = 3;
in_attr.n_dims = 4;
ret = rknn_set_input_shapes(rknn_ctx_, io_num.n_input, &in_attr);
```
## Build
```bash
cd /opt/bytetrack-counter-cpp/build
cmake .. -DHAS_RKNN=ON
make -j$(nproc)
```
## Service
```bash
systemctl restart bytetrack-counter
journalctl -u bytetrack-counter -f
```
## Reset via .reset file
Place a `.reset` file in `SHM_DIR` (default `/dev/shm/bytetrack-counter`) to trigger a full state reset:
- **Startup**: deleting `.reset` before service starts clears all state files on boot
- **Runtime**: dropping `.reset` while service runs calls `BatchStore::reset()` — ends active batch, clears in-memory state, deletes `STATE_FILE`, clears live stream JPEG + writes blank frame on next write
```bash
touch /dev/shm/bytetrack-counter/.reset
```
## Shared memory
`SHM_DIR` (`/dev/shm/bytetrack-counter` by default) stores:
- `LIVE_STREAM_FRAME_PATH` JPEG snapshot
- `RECORD_SHM_DIR` video recordings before move to disk
- `.reset` trigger file
Directory auto-created at startup.
## Video recordings
- Recordings are written to `SHM_DIR` as `batch_pending_*.mp4`, confirmed when ayam detected, and moved via `fork()` (non-blocking) to `OUTPUT_DIR/<batch counting_date>/batch_N_HHMMSS.mp4`.
- The day folder uses the **batch counting date** (today before `DAILY_CUTOFF_TIME`, tomorrow after), forwarded from `BatchStore` through the batch-closed callback — matching the SQLite `counting_date`.
- Retention cleanup compares day folders with `std::localtime` to match folder naming.
## Source override
```bash
bytetrack-counter <config.env> --source /tmp/test.mp4 # local file (single pass)
bytetrack-counter <config.env> --source rtsp://cam:554/x # live stream
bytetrack-counter <config.env> -s path # or --source=path
```