• 初始化和登录

    可以借鉴:002_usb红外摄像头初始化登录.md

  • 查看摄像头的能力

    可以借鉴:003_usb红外摄系统能力查询.md

  • 配置参数

    int configure_device(void)
    {
        USB_COMMON_COND cond = {0};
        cond.dwSize = sizeof(cond);
        cond.byChannelID = USB_CHANNEL_IR;
    
        USB_THERMAL_STREAM_PARAM tsp = {0};
        tsp.dwSize = sizeof(tsp);
        tsp.byVideoCodingType = 8; //
        tsp.dwWidth = 256; tsp.dwHeight = 192; tsp.dwFrameRate = 25;
    
        USB_CONFIG_INPUT_INFO in = {0};
        USB_CONFIG_OUTPUT_INFO out = {0};
        in.lpCondBuffer = &cond; in.dwCondBufferSize = sizeof(cond);
        in.lpInBuffer = &tsp; in.dwInBufferSize = sizeof(tsp);
        if (!USB_SetDeviceConfig(g_userId, USB_SET_THERMAL_STREAM_PARAM, &in, &out)) return -1;
    
        USB_VIDEO_PARAM vp = {0};
        vp.dwVideoFormat = USB_STREAM_YUY2;
        vp.dwWidth = 256; vp.dwHeight = 192; vp.dwFramerate = 25;
        in.lpInBuffer = &vp; in.dwInBufferSize = sizeof(vp);
        if (!USB_SetDeviceConfig(g_userId, USB_SET_VIDEO_PARAM, &in, &out)) return -1;
        printf("Config: type=8 YUY2 256x192@25\n");
        return 0;
    }
    
    • 参数解析
  • 开启流&设置流回调

    static void __stdcall cb(LONG h, USB_FRAME_INFO *f, void *u)
    {
        (void)h; (void)u;
        if (!f || !f->pBuf || f->dwStreamType != USB_STREAM_YUY2) return;
        g_frameCnt++;
    
        if (g_frameCnt == 1)
        {
            printf("[CB#1] %lux%lu buf=%lu\n",
                   (unsigned long)f->dwWidth, (unsigned long)f->dwHeight,
                   (unsigned long)f->dwBufSize);
            printf("  raw: ");
            for (int i = 0; i < f->dwBufSize; i++) printf("%02x ", f->pBuf[i]);
            printf("\n");
        }
    
        if (g_frameCnt <= 3 || (g_frameCnt % 25) == 0)
            printf("[CB#%d] frame\n", g_frameCnt);
    }
    
    int start_stream(int seconds)
    {
        USB_STREAM_CALLBACK_PARAM cp = {0};
        cp.dwSize = sizeof(cp);
        cp.dwStreamType = USB_STREAM_YUY2;
        cp.funcStreamCallBack = cb;
    
        LONG h = USB_StartStreamCallback(g_userId, &cp);
        if (h < 0) return -1;
    
        sleep(seconds);
        USB_StopChannel(g_userId, (DWORD)h);
        return 0;
    }