Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Lukasz Marek authored on 2014/04/28 08:34:18... | ... |
@@ -20,9 +20,13 @@ |
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 |
*/ |
22 | 22 |
|
23 |
+#include <unistd.h> |
|
24 |
+#include <fcntl.h> |
|
25 |
+#include <sys/ioctl.h> |
|
23 | 26 |
#include <stdlib.h> |
24 | 27 |
#include "fbdev_common.h" |
25 | 28 |
#include "libavutil/common.h" |
29 |
+#include "avdevice.h" |
|
26 | 30 |
|
27 | 31 |
struct rgb_pixfmt_map_entry { |
28 | 32 |
int bits_per_pixel; |
... | ... |
@@ -65,3 +69,61 @@ const char* ff_fbdev_default_device() |
65 | 65 |
return dev; |
66 | 66 |
} |
67 | 67 |
|
68 |
+int ff_fbdev_get_device_list(AVDeviceInfoList *device_list) |
|
69 |
+{ |
|
70 |
+ struct fb_var_screeninfo varinfo; |
|
71 |
+ struct fb_fix_screeninfo fixinfo; |
|
72 |
+ char device_file[12]; |
|
73 |
+ AVDeviceInfo *device = NULL; |
|
74 |
+ int i, fd, ret = 0; |
|
75 |
+ const char *default_device = ff_fbdev_default_device(); |
|
76 |
+ |
|
77 |
+ if (!device_list) |
|
78 |
+ return AVERROR(EINVAL); |
|
79 |
+ |
|
80 |
+ for (i = 0; i <= 31; i++) { |
|
81 |
+ snprintf(device_file, sizeof(device_file), "/dev/fb%d", i); |
|
82 |
+ |
|
83 |
+ if ((fd = avpriv_open(device_file, O_RDWR)) < 0) |
|
84 |
+ continue; |
|
85 |
+ if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) == -1) |
|
86 |
+ goto fail_device; |
|
87 |
+ if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) == -1) |
|
88 |
+ goto fail_device; |
|
89 |
+ |
|
90 |
+ device = av_mallocz(sizeof(AVDeviceInfo)); |
|
91 |
+ if (!device) { |
|
92 |
+ ret = AVERROR(ENOMEM); |
|
93 |
+ goto fail_device; |
|
94 |
+ } |
|
95 |
+ device->device_name = av_strdup(device_file); |
|
96 |
+ device->device_description = av_strdup(fixinfo.id); |
|
97 |
+ if (!device->device_name || !device->device_description) { |
|
98 |
+ ret = AVERROR(ENOMEM); |
|
99 |
+ goto fail_device; |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ if ((ret = av_dynarray_add_nofree(&device_list->devices, |
|
103 |
+ &device_list->nb_devices, device)) < 0) |
|
104 |
+ goto fail_device; |
|
105 |
+ |
|
106 |
+ if (default_device && !strcmp(device->device_name, default_device)) { |
|
107 |
+ device_list->default_device = device_list->nb_devices - 1; |
|
108 |
+ default_device = NULL; |
|
109 |
+ } |
|
110 |
+ close(fd); |
|
111 |
+ continue; |
|
112 |
+ |
|
113 |
+ fail_device: |
|
114 |
+ if (device) { |
|
115 |
+ av_free(device->device_name); |
|
116 |
+ av_free(device->device_description); |
|
117 |
+ av_freep(&device); |
|
118 |
+ } |
|
119 |
+ if (fd >= 0) |
|
120 |
+ close(fd); |
|
121 |
+ if (ret < 0) |
|
122 |
+ return ret; |
|
123 |
+ } |
|
124 |
+ return 0; |
|
125 |
+} |
... | ... |
@@ -27,8 +27,12 @@ |
27 | 27 |
#include <linux/fb.h> |
28 | 28 |
#include "libavutil/pixfmt.h" |
29 | 29 |
|
30 |
+struct AVDeviceInfoList; |
|
31 |
+ |
|
30 | 32 |
enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo); |
31 | 33 |
|
32 | 34 |
const char* ff_fbdev_default_device(void); |
33 | 35 |
|
36 |
+int ff_fbdev_get_device_list(struct AVDeviceInfoList *device_list); |
|
37 |
+ |
|
34 | 38 |
#endif /* AVDEVICE_FBDEV_COMMON_H */ |
... | ... |
@@ -186,61 +186,7 @@ static av_cold int fbdev_write_trailer(AVFormatContext *h) |
186 | 186 |
|
187 | 187 |
static int fbdev_get_device_list(AVFormatContext *s, AVDeviceInfoList *device_list) |
188 | 188 |
{ |
189 |
- struct fb_var_screeninfo varinfo; |
|
190 |
- struct fb_fix_screeninfo fixinfo; |
|
191 |
- char device_file[12]; |
|
192 |
- AVDeviceInfo *device = NULL; |
|
193 |
- int i, fd, ret = 0; |
|
194 |
- const char *default_device = ff_fbdev_default_device(); |
|
195 |
- |
|
196 |
- if (!device_list) |
|
197 |
- return AVERROR(EINVAL); |
|
198 |
- |
|
199 |
- for (i = 0; i <= 31; i++) { |
|
200 |
- snprintf(device_file, sizeof(device_file), "/dev/fb%d", i); |
|
201 |
- |
|
202 |
- if ((fd = avpriv_open(device_file, O_RDWR)) < 0) |
|
203 |
- continue; |
|
204 |
- if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) == -1) |
|
205 |
- goto fail_device; |
|
206 |
- if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) == -1) |
|
207 |
- goto fail_device; |
|
208 |
- |
|
209 |
- device = av_mallocz(sizeof(AVDeviceInfo)); |
|
210 |
- if (!device) { |
|
211 |
- ret = AVERROR(ENOMEM); |
|
212 |
- goto fail_device; |
|
213 |
- } |
|
214 |
- device->device_name = av_strdup(device_file); |
|
215 |
- device->device_description = av_strdup(fixinfo.id); |
|
216 |
- if (!device->device_name || !device->device_description) { |
|
217 |
- ret = AVERROR(ENOMEM); |
|
218 |
- goto fail_device; |
|
219 |
- } |
|
220 |
- |
|
221 |
- if ((ret = av_dynarray_add_nofree(&device_list->devices, |
|
222 |
- &device_list->nb_devices, device)) < 0) |
|
223 |
- goto fail_device; |
|
224 |
- |
|
225 |
- if (default_device && !strcmp(device->device_name, default_device)) { |
|
226 |
- device_list->default_device = device_list->nb_devices - 1; |
|
227 |
- default_device = NULL; |
|
228 |
- } |
|
229 |
- close(fd); |
|
230 |
- continue; |
|
231 |
- |
|
232 |
- fail_device: |
|
233 |
- if (device) { |
|
234 |
- av_free(device->device_name); |
|
235 |
- av_free(device->device_description); |
|
236 |
- av_freep(&device); |
|
237 |
- } |
|
238 |
- if (fd >= 0) |
|
239 |
- close(fd); |
|
240 |
- if (ret < 0) |
|
241 |
- return ret; |
|
242 |
- } |
|
243 |
- return 0; |
|
189 |
+ return ff_fbdev_get_device_list(device_list); |
|
244 | 190 |
} |
245 | 191 |
|
246 | 192 |
#define OFFSET(x) offsetof(FBDevContext, x) |