static av_cold int bktr_init(const char *video_device, int width, int height,

    int format, int *video_fd, int *tuner_fd, int idev, double frequency)

{

    struct meteor_geomet geo;

    int h_max;

    long ioctl_frequency;

    char *arg;

    int c;

    struct sigaction act = { 0 }, old;



    if (idev < 0 || idev > 4)

    {

        arg = getenv ("BKTR_DEV");

        if (arg)

            idev = atoi (arg);

        if (idev < 0 || idev > 4)

            idev = 1;

    }



    if (format < 1 || format > 6)

    {

        arg = getenv ("BKTR_FORMAT");

        if (arg)

            format = atoi (arg);

        if (format < 1 || format > 6)

            format = VIDEO_FORMAT;

    }



    if (frequency <= 0)

    {

        arg = getenv ("BKTR_FREQUENCY");

        if (arg)

            frequency = atof (arg);

        if (frequency <= 0)

            frequency = 0.0;

    }



    sigemptyset(&act.sa_mask);

    act.sa_handler = catchsignal;

    sigaction(SIGUSR1, &act, &old);



    *tuner_fd = open("/dev/tuner0", O_RDONLY);

    if (*tuner_fd < 0)

        av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing: %s\n", strerror(errno));



    *video_fd = open(video_device, O_RDONLY);

    if (*video_fd < 0) {

        av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno));

        return -1;

    }



    geo.rows = height;

    geo.columns = width;

    geo.frames = 1;

    geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;



    switch (format) {

    case PAL:   h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALBDGHI; break;

    case PALN:  h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALN;     break;

    case PALM:  h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALM;     break;

    case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM;    break;

    case NTSC:  h_max = NTSC_HEIGHT;  c = BT848_IFORM_F_NTSCM;    break;

    case NTSCJ: h_max = NTSC_HEIGHT;  c = BT848_IFORM_F_NTSCJ;    break;

    default:    h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALBDGHI; break;

    }



    if (height <= h_max / 2)

        geo.oformat |= METEOR_GEO_EVEN_ONLY;



    if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSETGEO: %s\n", strerror(errno));

        return -1;

    }



    if (ioctl(*video_fd, BT848SFMT, &c) < 0) {

        av_log(NULL, AV_LOG_ERROR, "BT848SFMT: %s\n", strerror(errno));

        return -1;

    }



    c = bktr_dev[idev];

    if (ioctl(*video_fd, METEORSINPUT, &c) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSINPUT: %s\n", strerror(errno));

        return -1;

    }



    video_buf_size = width * height * 12 / 8;



    video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size,

        PROT_READ, MAP_SHARED, *video_fd, (off_t)0);

    if (video_buf == MAP_FAILED) {

        av_log(NULL, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

        return -1;

    }



    if (frequency != 0.0) {

        ioctl_frequency  = (unsigned long)(frequency*16);

        if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency) < 0)

            av_log(NULL, AV_LOG_ERROR, "TVTUNER_SETFREQ: %s\n", strerror(errno));

    }



    c = AUDIO_UNMUTE;

    if (ioctl(*tuner_fd, BT848_SAUDIO, &c) < 0)

        av_log(NULL, AV_LOG_ERROR, "TVTUNER_SAUDIO: %s\n", strerror(errno));



    c = METEOR_CAP_CONTINOUS;

    ioctl(*video_fd, METEORCAPTUR, &c);



    c = SIGUSR1;

    ioctl(*video_fd, METEORSSIGNAL, &c);



    return 0;

}

static av_cold int bktr_init(const char *video_device, int width, int height,

    int format, int *video_fd, int *tuner_fd, int idev, double frequency)

{

    struct meteor_geomet geo;

    int h_max;

    long ioctl_frequency;

    char *arg;

    int c;

    struct sigaction act = { 0 }, old;



    if (idev < 0 || idev > 4)

    {

        arg = getenv ("BKTR_DEV");

        if (arg)

            idev = atoi (arg);

        if (idev < 0 || idev > 4)

            idev = 1;

    }



    if (format < 1 || format > 6)

    {

        arg = getenv ("BKTR_FORMAT");

        if (arg)

            format = atoi (arg);

        if (format < 1 || format > 6)

            format = VIDEO_FORMAT;

    }



    if (frequency <= 0)

    {

        arg = getenv ("BKTR_FREQUENCY");

        if (arg)

            frequency = atof (arg);

        if (frequency <= 0)

            frequency = 0.0;

    }



    sigemptyset(&act.sa_mask);

    act.sa_handler = catchsignal;

    sigaction(SIGUSR1, &act, &old);



    *tuner_fd = open("/dev/tuner0", O_RDONLY);

    if (*tuner_fd < 0)

        av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing: %s\n", strerror(errno));



    *video_fd = open(video_device, O_RDONLY);

    if (*video_fd < 0) {

        av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno));

        return -1;

    }



    geo.rows = height;

    geo.columns = width;

    geo.frames = 1;

    geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;



    switch (format) {

    case PAL:   h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALBDGHI; break;

    case PALN:  h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALN;     break;

    case PALM:  h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALM;     break;

    case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM;    break;

    case NTSC:  h_max = NTSC_HEIGHT;  c = BT848_IFORM_F_NTSCM;    break;

    case NTSCJ: h_max = NTSC_HEIGHT;  c = BT848_IFORM_F_NTSCJ;    break;

    default:    h_max = PAL_HEIGHT;   c = BT848_IFORM_F_PALBDGHI; break;

    }



    if (height <= h_max / 2)

        geo.oformat |= METEOR_GEO_EVEN_ONLY;



    if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSETGEO: %s\n", strerror(errno));

        return -1;

    }



    if (ioctl(*video_fd, BT848SFMT, &c) < 0) {

        av_log(NULL, AV_LOG_ERROR, "BT848SFMT: %s\n", strerror(errno));

        return -1;

    }



    c = bktr_dev[idev];

    if (ioctl(*video_fd, METEORSINPUT, &c) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSINPUT: %s\n", strerror(errno));

        return -1;

    }



    video_buf_size = width * height * 12 / 8;



    video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size,

        PROT_READ, MAP_SHARED, *video_fd, (off_t)0);

    if (video_buf == MAP_FAILED) {

        av_log(NULL, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

        return -1;

    }



    if (frequency != 0.0) {

        ioctl_frequency  = (unsigned long)(frequency*16);

        if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency) < 0)

            av_log(NULL, AV_LOG_ERROR, "TVTUNER_SETFREQ: %s\n", strerror(errno));

    }



    c = AUDIO_UNMUTE;

    if (ioctl(*tuner_fd, BT848_SAUDIO, &c) < 0)

        av_log(NULL, AV_LOG_ERROR, "TVTUNER_SAUDIO: %s\n", strerror(errno));



    c = METEOR_CAP_CONTINOUS;

    ioctl(*video_fd, METEORCAPTUR, &c);



    c = SIGUSR1;

    ioctl(*video_fd, METEORSSIGNAL, &c);



    return 0;

}

    struct sigaction act = { 0 }, old;
static av_cold int FUNC_0(const char *video_device, int width, int height,

    int format, int *video_fd, int *tuner_fd, int idev, double frequency)

{

    struct meteor_geomet VAR_0;

    int VAR_1;

    long VAR_2;

    char *VAR_3;

    int VAR_4;

    struct sigaction VAR_5 = { 0 }, VAR_6;



    if (idev < 0 || idev > 4)

    {

        VAR_3 = getenv ("BKTR_DEV");

        if (VAR_3)

            idev = atoi (VAR_3);

        if (idev < 0 || idev > 4)

            idev = 1;

    }



    if (format < 1 || format > 6)

    {

        VAR_3 = getenv ("BKTR_FORMAT");

        if (VAR_3)

            format = atoi (VAR_3);

        if (format < 1 || format > 6)

            format = VIDEO_FORMAT;

    }



    if (frequency <= 0)

    {

        VAR_3 = getenv ("BKTR_FREQUENCY");

        if (VAR_3)

            frequency = atof (VAR_3);

        if (frequency <= 0)

            frequency = 0.0;

    }



    sigemptyset(&VAR_5.sa_mask);

    VAR_5.sa_handler = catchsignal;

    sigaction(SIGUSR1, &VAR_5, &VAR_6);



    *tuner_fd = open("/dev/tuner0", O_RDONLY);

    if (*tuner_fd < 0)

        av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing: %s\n", strerror(errno));



    *video_fd = open(video_device, O_RDONLY);

    if (*video_fd < 0) {

        av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno));

        return -1;

    }



    VAR_0.rows = height;

    VAR_0.columns = width;

    VAR_0.frames = 1;

    VAR_0.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;



    switch (format) {

    case PAL:   VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALBDGHI; break;

    case PALN:  VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALN;     break;

    case PALM:  VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALM;     break;

    case SECAM: VAR_1 = SECAM_HEIGHT; VAR_4 = BT848_IFORM_F_SECAM;    break;

    case NTSC:  VAR_1 = NTSC_HEIGHT;  VAR_4 = BT848_IFORM_F_NTSCM;    break;

    case NTSCJ: VAR_1 = NTSC_HEIGHT;  VAR_4 = BT848_IFORM_F_NTSCJ;    break;

    default:    VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALBDGHI; break;

    }



    if (height <= VAR_1 / 2)

        VAR_0.oformat |= METEOR_GEO_EVEN_ONLY;



    if (ioctl(*video_fd, METEORSETGEO, &VAR_0) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSETGEO: %s\n", strerror(errno));

        return -1;

    }



    if (ioctl(*video_fd, BT848SFMT, &VAR_4) < 0) {

        av_log(NULL, AV_LOG_ERROR, "BT848SFMT: %s\n", strerror(errno));

        return -1;

    }



    VAR_4 = bktr_dev[idev];

    if (ioctl(*video_fd, METEORSINPUT, &VAR_4) < 0) {

        av_log(NULL, AV_LOG_ERROR, "METEORSINPUT: %s\n", strerror(errno));

        return -1;

    }



    video_buf_size = width * height * 12 / 8;



    video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size,

        PROT_READ, MAP_SHARED, *video_fd, (off_t)0);

    if (video_buf == MAP_FAILED) {

        av_log(NULL, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));

        return -1;

    }



    if (frequency != 0.0) {

        VAR_2  = (unsigned long)(frequency*16);

        if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &VAR_2) < 0)

            av_log(NULL, AV_LOG_ERROR, "TVTUNER_SETFREQ: %s\n", strerror(errno));

    }



    VAR_4 = AUDIO_UNMUTE;

    if (ioctl(*tuner_fd, BT848_SAUDIO, &VAR_4) < 0)

        av_log(NULL, AV_LOG_ERROR, "TVTUNER_SAUDIO: %s\n", strerror(errno));



    VAR_4 = METEOR_CAP_CONTINOUS;

    ioctl(*video_fd, METEORCAPTUR, &VAR_4);



    VAR_4 = SIGUSR1;

    ioctl(*video_fd, METEORSSIGNAL, &VAR_4);



    return 0;

}

static av_cold int FUNC_0(const char *video_device, int width, int height,
int format, int *video_fd, int *tuner_fd, int idev, double frequency)
{ struct meteor_geomet VAR_0; int VAR_1; long VAR_2; char *VAR_3; int VAR_4; struct sigaction VAR_5 = { 0 }, VAR_6; if (idev < 0 || idev > 4)
{ VAR_3 = getenv ("BKTR_DEV"); if (VAR_3)
idev = atoi (VAR_3); if (idev < 0 || idev > 4)
idev = 1; } if (format < 1 || format > 6)
{ VAR_3 = getenv ("BKTR_FORMAT"); if (VAR_3)
format = atoi (VAR_3); if (format < 1 || format > 6)
format = VIDEO_FORMAT; } if (frequency <= 0)
{ VAR_3 = getenv ("BKTR_FREQUENCY"); if (VAR_3)
frequency = atof (VAR_3); if (frequency <= 0)
frequency = 0.0; } sigemptyset(&VAR_5.sa_mask); VAR_5.sa_handler = catchsignal; sigaction(SIGUSR1, &VAR_5, &VAR_6); *tuner_fd = open("/dev/tuner0", O_RDONLY); if (*tuner_fd < 0)
av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing: %s\n", strerror(errno)); *video_fd = open(video_device, O_RDONLY); if (*video_fd < 0) { av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno)); return -1; } VAR_0.rows = height; VAR_0.columns = width; VAR_0.frames = 1; VAR_0.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; switch (format) { case PAL:   VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALBDGHI; break; case PALN:  VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALN;     break; case PALM:  VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALM;     break; case SECAM: VAR_1 = SECAM_HEIGHT; VAR_4 = BT848_IFORM_F_SECAM;    break; case NTSC:  VAR_1 = NTSC_HEIGHT;  VAR_4 = BT848_IFORM_F_NTSCM;    break; case NTSCJ: VAR_1 = NTSC_HEIGHT;  VAR_4 = BT848_IFORM_F_NTSCJ;    break; default:    VAR_1 = PAL_HEIGHT;   VAR_4 = BT848_IFORM_F_PALBDGHI; break; } if (height <= VAR_1 / 2)
VAR_0.oformat |= METEOR_GEO_EVEN_ONLY; if (ioctl(*video_fd, METEORSETGEO, &VAR_0) < 0) { av_log(NULL, AV_LOG_ERROR, "METEORSETGEO: %s\n", strerror(errno)); return -1; } if (ioctl(*video_fd, BT848SFMT, &VAR_4) < 0) { av_log(NULL, AV_LOG_ERROR, "BT848SFMT: %s\n", strerror(errno)); return -1; } VAR_4 = bktr_dev[idev]; if (ioctl(*video_fd, METEORSINPUT, &VAR_4) < 0) { av_log(NULL, AV_LOG_ERROR, "METEORSINPUT: %s\n", strerror(errno)); return -1; } video_buf_size = width * height * 12 / 8; video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size,
PROT_READ, MAP_SHARED, *video_fd, (off_t)0); if (video_buf == MAP_FAILED) { av_log(NULL, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); return -1; } if (frequency != 0.0) { VAR_2  = (unsigned long)(frequency*16); if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &VAR_2) < 0)
av_log(NULL, AV_LOG_ERROR, "TVTUNER_SETFREQ: %s\n", strerror(errno)); } VAR_4 = AUDIO_UNMUTE; if (ioctl(*tuner_fd, BT848_SAUDIO, &VAR_4) < 0)
av_log(NULL, AV_LOG_ERROR, "TVTUNER_SAUDIO: %s\n", strerror(errno)); VAR_4 = METEOR_CAP_CONTINOUS; ioctl(*video_fd, METEORCAPTUR, &VAR_4); VAR_4 = SIGUSR1; ioctl(*video_fd, METEORSSIGNAL, &VAR_4); return 0; }