#ifndef WEBRTCPUSH_CAMERA_V4L2_H
#define WEBRTCPUSH_CAMERA_V4L2_H

#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct camera_v4l2 camera_v4l2_t;

typedef struct {
    const char *dev;      /* /dev/video0 */
    int width;
    int height;
    int fps;
    const char *format;   /* "NV12" (默认) 或 "YUYV" */
} camera_cfg_t;

camera_v4l2_t *camera_v4l2_open(const camera_cfg_t *cfg);
void camera_v4l2_close(camera_v4l2_t *c);

/* 输出尺寸为 hor_stride*ver_stride*3/2 的 NV12 (内部做 YUYV->NV12 + stride 对齐) */
int camera_v4l2_get_frame(camera_v4l2_t *c, uint8_t *nv12_out, size_t out_size,
                           int hor_stride, int ver_stride, int height);

void camera_v4l2_get_stride(camera_v4l2_t *c, int *hor_stride, int *ver_stride);

#ifdef __cplusplus
}
#endif
#endif
