LCOV - code coverage report
Current view: top level - src/libavdevice - fbdev_common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 57 0.0 %
Date: 2017-01-19 23:52:33 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2011 Stefano Sabatini
       3             :  * Copyright (c) 2009 Giliard B. de Freitas <giliarde@gmail.com>
       4             :  * Copyright (C) 2002 Gunnar Monell <gmo@linux.nu>
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include <unistd.h>
      24             : #include <fcntl.h>
      25             : #include <sys/ioctl.h>
      26             : #include <stdlib.h>
      27             : #include "fbdev_common.h"
      28             : #include "libavutil/common.h"
      29             : #include "avdevice.h"
      30             : 
      31             : struct rgb_pixfmt_map_entry {
      32             :     int bits_per_pixel;
      33             :     int red_offset, green_offset, blue_offset, alpha_offset;
      34             :     enum AVPixelFormat pixfmt;
      35             : };
      36             : 
      37             : static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
      38             :     // bpp, red_offset,  green_offset, blue_offset, alpha_offset, pixfmt
      39             :     {  32,       0,           8,          16,           24,   AV_PIX_FMT_RGBA  },
      40             :     {  32,      16,           8,           0,           24,   AV_PIX_FMT_BGRA  },
      41             :     {  32,       8,          16,          24,            0,   AV_PIX_FMT_ARGB  },
      42             :     {  32,       3,           2,           8,            0,   AV_PIX_FMT_ABGR  },
      43             :     {  24,       0,           8,          16,            0,   AV_PIX_FMT_RGB24 },
      44             :     {  24,      16,           8,           0,            0,   AV_PIX_FMT_BGR24 },
      45             :     {  16,      11,           5,           0,            0,   AV_PIX_FMT_RGB565 },
      46             : };
      47             : 
      48           0 : enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
      49             : {
      50             :     int i;
      51             : 
      52           0 :     for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
      53           0 :         const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
      54           0 :         if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
      55           0 :             entry->red_offset     == varinfo->red.offset     &&
      56           0 :             entry->green_offset   == varinfo->green.offset   &&
      57           0 :             entry->blue_offset    == varinfo->blue.offset)
      58           0 :             return entry->pixfmt;
      59             :     }
      60             : 
      61           0 :     return AV_PIX_FMT_NONE;
      62             : }
      63             : 
      64           0 : const char* ff_fbdev_default_device()
      65             : {
      66           0 :     const char *dev = getenv("FRAMEBUFFER");
      67           0 :     if (!dev)
      68           0 :         dev = "/dev/fb0";
      69           0 :     return dev;
      70             : }
      71             : 
      72           0 : int ff_fbdev_get_device_list(AVDeviceInfoList *device_list)
      73             : {
      74             :     struct fb_var_screeninfo varinfo;
      75             :     struct fb_fix_screeninfo fixinfo;
      76             :     char device_file[12];
      77           0 :     AVDeviceInfo *device = NULL;
      78           0 :     int i, fd, ret = 0;
      79           0 :     const char *default_device = ff_fbdev_default_device();
      80             : 
      81           0 :     if (!device_list)
      82           0 :         return AVERROR(EINVAL);
      83             : 
      84           0 :     for (i = 0; i <= 31; i++) {
      85           0 :         snprintf(device_file, sizeof(device_file), "/dev/fb%d", i);
      86             : 
      87           0 :         if ((fd = avpriv_open(device_file, O_RDWR)) < 0) {
      88           0 :             int err = AVERROR(errno);
      89           0 :             if (err != AVERROR(ENOENT))
      90           0 :                 av_log(NULL, AV_LOG_ERROR, "Could not open framebuffer device '%s': %s\n",
      91           0 :                        device_file, av_err2str(err));
      92           0 :             continue;
      93             :         }
      94           0 :         if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) == -1)
      95           0 :             goto fail_device;
      96           0 :         if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) == -1)
      97           0 :             goto fail_device;
      98             : 
      99           0 :         device = av_mallocz(sizeof(AVDeviceInfo));
     100           0 :         if (!device) {
     101           0 :             ret = AVERROR(ENOMEM);
     102           0 :             goto fail_device;
     103             :         }
     104           0 :         device->device_name = av_strdup(device_file);
     105           0 :         device->device_description = av_strdup(fixinfo.id);
     106           0 :         if (!device->device_name || !device->device_description) {
     107           0 :             ret = AVERROR(ENOMEM);
     108           0 :             goto fail_device;
     109             :         }
     110             : 
     111           0 :         if ((ret = av_dynarray_add_nofree(&device_list->devices,
     112             :                                           &device_list->nb_devices, device)) < 0)
     113           0 :             goto fail_device;
     114             : 
     115           0 :         if (default_device && !strcmp(device->device_name, default_device)) {
     116           0 :             device_list->default_device = device_list->nb_devices - 1;
     117           0 :             default_device = NULL;
     118             :         }
     119           0 :         close(fd);
     120           0 :         continue;
     121             : 
     122             :       fail_device:
     123           0 :         if (device) {
     124           0 :             av_freep(&device->device_name);
     125           0 :             av_freep(&device->device_description);
     126           0 :             av_freep(&device);
     127             :         }
     128           0 :         if (fd >= 0)
     129           0 :             close(fd);
     130           0 :         if (ret < 0)
     131           0 :             return ret;
     132             :     }
     133           0 :     return 0;
     134             : }

Generated by: LCOV version 1.12