Video Input Application
This chapter describes the GK7206 video input (VI) application example — sample_vio. The application demonstrates the various working modes of VI/VPSS, including online/offline modes, single/dual sensor, WDR, LDC, AHD, and other advanced features.
The application source code is located in the SDK directory sample/vio/. It serves as a reference template for developing video capture applications.
1 Application Overview
1.1 Features
- Multiple working modes: online/offline, single/dual sensor, WDR, LDC, AHD, and more
- Dual output paths: VO output (display) or VENC output (encoding)
- Flexible configuration: supports various combinations of resolutions and features
- Memory-efficient: supports lightweight modes suited to the 26 MB memory environment
1.2 Technical Specifications
| Parameter | Value |
|---|---|
Working modes | 0~11 (see the table below) |
Output mode | 0=VO output, 1=VENC output |
Resolution | Per the sensor configuration |
Frame rate | Determined by the sensor |
Memory footprint | Relatively high (heavy modes easily OOM) |
1.3 Working Mode List
| work_mode | Description | Command example |
|---|---|---|
| 0 | vi online vpss online | ./sample_vio 0 |
| 1 | vi offline vpss online (for 4K) | ./sample_vio 1 |
| 2 | vi offline vpss offline | ./sample_vio 2 |
| 3 | online/offline + WDR | ./sample_vio 3 |
| 4 | offline switching linear/WDR | ./sample_vio 4 |
| 5 | offline switching resolution | ./sample_vio 5 |
| 6 | Dual sensor | ./sample_vio 6 |
| 7 | Dual sensor stitching | ./sample_vio 7 |
| 10 | offline online LDC | ./sample_vio 10 |
| 11 | ahd mipi | ./sample_vio 11 |
1.4 Directory Structure
sample/vio/
├── Makefile # Build script
└── sample_vio.c # Main program2 Build and Deployment
2.1 Prerequisites
Before building this application, make sure the following preparations have been completed:
- SDK environment is set up: follow SDK Compilation to set up the cross-compilation toolchain and SDK configuration
- Sensor is connected: an SC465SL or compatible image sensor must be connected
2.2 Build the Application
# Enter the sample directory
cd <SDK_PATH>/sample
# Build the vio sample
make -C vio clean && make -C vio2.3 Deploy to the Board
# Mount the SD card (recommended)
mkdir -p /sd_card
mount -t vfat /dev/mmcblk1p1 /sd_card
# Transfer to the development board via SCP
scp sample/vio/sample_vio root@<board IP>:/sd_card/Warning
Heavy modes (e.g. dual sensor, 4K) easily run out of memory; it is recommended to mount the SD card before running.
2.4 Run the Application
# Add execute permission
chmod +x /sd_card/sample_vio
# Enter the SD card directory
cd /sd_card
# Run (work_mode 0, stream_mode 1)
./sample_vio 0 1
# Or with VENC output (RTSP stream can be pulled)
./sample_vio 0 1
# Or with VO output (requires a display device)
./sample_vio 0 02.5 Expected Output
After a successful run (stream_mode=1), the terminal prints information similar to the following:
sample_vio running
work_mode: 0
stream_mode: 1
...
rtsp://192.168.1.100:554/livestream/0
...3 Internal Execution Logic in Detail
3.1 Application Architecture
The application uses the following architecture:
Sensor → VI → VPSS → VO/VENC3.2 Online Mode vs Offline Mode
| Mode | Description | Suitable scenarios |
|---|---|---|
| Online mode | VI outputs directly to VPSS without a memory copy | High real-time requirements |
| Offline mode | VI writes to memory; VPSS reads from memory | Buffering or post-processing needed |
3.3 VI/VPSS Initialization Flow
// Step 1: System initialization
sample_comm_sys_init(&sys_config);
// Step 2: ISP initialization
sample_comm_isp_init();
// Step 3: Start VI
sample_comm_vi_start(...);
// Step 4: Start VPSS
sample_comm_vpss_start(...);
// Step 5: Select the output based on stream_mode
if (stream_mode == 0) {
// VO output
sample_comm_vo_start(...);
xmedia_bind_vpss_to_vo(...);
} else {
// VENC output
sample_comm_venc_start(...);
xmedia_bind_vpss_to_venc(...);
}4 Key Programming Points
4.1 Working Mode Configuration
switch(work_mode) {
case 0: // vi online vpss online
sys_config.sys_conf.pipe_mode[0].vicap_viproc_mode = XMEDIA_WORK_MODE_ONLINE;
sys_config.sys_conf.pipe_mode[0].viproc_vpss_mode = XMEDIA_WORK_MODE_ONLINE;
break;
case 1: // vi offline vpss online
sys_config.sys_conf.pipe_mode[0].vicap_viproc_mode = XMEDIA_WORK_MODE_OFFLINE;
sys_config.sys_conf.pipe_mode[0].viproc_vpss_mode = XMEDIA_WORK_MODE_ONLINE;
break;
// ... other modes
}4.2 Dual Sensor Configuration
// Configure two sensors
sys_config.sensor_num = 2;
sys_config.sensor_type[0] = SENSOR0_TYPE;
sys_config.sensor_type[1] = SENSOR1_TYPE;5 Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
Killed (OOM) | Heavy mode in 26 MB of memory | Mount the SD card and use a lightweight mode |
sample_comm_vi_init failed! | Sensor initialization failed | Check the sensor connection and configuration |
open vo err | No display device | Use stream_mode=1 or connect a display device |
