| 72 | } |
| 73 | |
| 74 | int ff_fbdev_get_device_list(AVDeviceInfoList *device_list) |
| 75 | { |
| 76 | struct fb_var_screeninfo varinfo; |
| 77 | struct fb_fix_screeninfo fixinfo; |
| 78 | char device_file[12]; |
| 79 | AVDeviceInfo *device = NULL; |
| 80 | int i, fd, ret = 0; |
| 81 | const char *default_device = ff_fbdev_default_device(); |
| 82 | |
| 83 | if (!device_list) |
| 84 | return AVERROR(EINVAL); |
| 85 | |
| 86 | for (i = 0; i <= 31; i++) { |
| 87 | snprintf(device_file, sizeof(device_file), "/dev/fb%d", i); |
| 88 | |
| 89 | if ((fd = avpriv_open(device_file, O_RDWR)) < 0) { |
| 90 | int err = AVERROR(errno); |
| 91 | if (err != AVERROR(ENOENT)) |
| 92 | av_log(NULL, AV_LOG_ERROR, "Could not open framebuffer device '%s': %s\n", |
| 93 | device_file, av_err2str(err)); |
| 94 | continue; |
| 95 | } |
| 96 | if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) == -1) |
| 97 | goto fail_device; |
| 98 | if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) == -1) |
| 99 | goto fail_device; |
| 100 | |
| 101 | device = av_mallocz(sizeof(AVDeviceInfo)); |
| 102 | if (!device) { |
| 103 | ret = AVERROR(ENOMEM); |
| 104 | goto fail_device; |
| 105 | } |
| 106 | device->device_name = av_strdup(device_file); |
| 107 | device->device_description = av_strdup(fixinfo.id); |
| 108 | if (!device->device_name || !device->device_description) { |
| 109 | ret = AVERROR(ENOMEM); |
| 110 | goto fail_device; |
| 111 | } |
| 112 | |
| 113 | if ((ret = av_dynarray_add_nofree(&device_list->devices, |
| 114 | &device_list->nb_devices, device)) < 0) |
| 115 | goto fail_device; |
| 116 | |
| 117 | if (default_device && !strcmp(device->device_name, default_device)) { |
| 118 | device_list->default_device = device_list->nb_devices - 1; |
| 119 | default_device = NULL; |
| 120 | } |
| 121 | close(fd); |
| 122 | continue; |
| 123 | |
| 124 | fail_device: |
| 125 | if (device) { |
| 126 | av_freep(&device->device_name); |
| 127 | av_freep(&device->device_description); |
| 128 | av_freep(&device); |
| 129 | } |
| 130 | if (fd >= 0) |
| 131 | close(fd); |
no test coverage detected