hikvision.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef __HIKVISION_H__
  2. #define __HIKVISION_H__
  3. /* Hikvision ISAPI helper.
  4. *
  5. * The ISAPI RTSP URL is fixed by protocol:
  6. * sub = rtsp://USER:PASS@IP:554/Streaming/Channels/{chan*100+2}
  7. * main = rtsp://USER:PASS@IP:554/Streaming/Channels/{chan*100+1}
  8. * where `chan` is the login channel number (usually 1).
  9. *
  10. * ISAPI read/write (device parameter access) goes over HTTP Digest auth and is
  11. * performed by shelling out to the system `curl` binary (no compile-time deps).
  12. */
  13. /* One camera credential from [camera_list]. */
  14. typedef struct {
  15. int id; /* index used by layouts / workers */
  16. char ip[64]; /* camera host/IP */
  17. char user[64];
  18. char pass[64];
  19. int login_chan; /* Hikvision login channel (default 1) */
  20. int port; /* RTSP port, default 554 */
  21. int http_port; /* ISAPI HTTP port, default 80 */
  22. } HvCam;
  23. /* Resolved RTSP URLs for one camera. */
  24. typedef struct {
  25. char sub[512]; /* sub-stream URL (e.g. .../Channels/102) */
  26. char main[512]; /* main-stream URL (e.g. .../Channels/101) */
  27. } HvUrls;
  28. /* Build sub/main RTSP URLs for a camera into out->sub / out->main. */
  29. void hv_build_urls(const HvCam *cam, HvUrls *out);
  30. /* Perform a single ISAPI HTTP(S) request via system curl.
  31. * method : "GET" or "PUT"
  32. * url : full http://host/ISAPI/... path
  33. * body : for PUT, the XML payload (may be NULL)
  34. * outbuf : on success receives the response body (caller must free with
  35. * free()); on failure NULL.
  36. * Returns 0 on success (HTTP 2xx), non-zero on failure.
  37. * SAFETY: caller must sanitise cam->user/pass/url (we quote them). */
  38. int hv_request(const HvCam *cam, const char *method, const char *urlpath,
  39. const char *body, char **outbuf);
  40. /* Read a streaming channel's encoding params (resolution/bitrate/etc.) and log
  41. * a one-line summary via flog(). Returns 0 on success, non-zero on failure. */
  42. int hv_read_and_log(const HvCam *cam, int chan_enc_id);
  43. /* Write a channel's main encoding params (resolution / fps / bitrate).
  44. * enc_id : encoding channel id (101 main, 102 sub for login chan 1)
  45. * width/height : video resolution
  46. * fps : frame rate
  47. * bitrate_kbps : target bitrate in kbps
  48. * Returns 0 on success, non-zero on failure. */
  49. int hv_write_params(const HvCam *cam, int enc_id,
  50. int width, int height, int fps, int bitrate_kbps);
  51. #endif