| 64 | } FBDevContext; |
| 65 | |
| 66 | static av_cold int fbdev_read_header(AVFormatContext *avctx) |
| 67 | { |
| 68 | FBDevContext *fbdev = avctx->priv_data; |
| 69 | AVStream *st = NULL; |
| 70 | enum AVPixelFormat pix_fmt; |
| 71 | int ret, flags = O_RDONLY; |
| 72 | const char* device; |
| 73 | |
| 74 | if (!(st = avformat_new_stream(avctx, NULL))) |
| 75 | return AVERROR(ENOMEM); |
| 76 | avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in microseconds */ |
| 77 | |
| 78 | /* NONBLOCK is ignored by the fbdev driver, only set for consistency */ |
| 79 | if (avctx->flags & AVFMT_FLAG_NONBLOCK) |
| 80 | flags |= O_NONBLOCK; |
| 81 | |
| 82 | if (avctx->url[0]) |
| 83 | device = avctx->url; |
| 84 | else |
| 85 | device = ff_fbdev_default_device(); |
| 86 | |
| 87 | if ((fbdev->fd = avpriv_open(device, flags)) == -1) { |
| 88 | ret = AVERROR(errno); |
| 89 | av_log(avctx, AV_LOG_ERROR, |
| 90 | "Could not open framebuffer device '%s': %s\n", |
| 91 | device, av_err2str(ret)); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) { |
| 96 | ret = AVERROR(errno); |
| 97 | av_log(avctx, AV_LOG_ERROR, |
| 98 | "FBIOGET_VSCREENINFO: %s\n", av_err2str(ret)); |
| 99 | goto fail; |
| 100 | } |
| 101 | |
| 102 | if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) { |
| 103 | ret = AVERROR(errno); |
| 104 | av_log(avctx, AV_LOG_ERROR, |
| 105 | "FBIOGET_FSCREENINFO: %s\n", av_err2str(ret)); |
| 106 | goto fail; |
| 107 | } |
| 108 | |
| 109 | pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo); |
| 110 | if (pix_fmt == AV_PIX_FMT_NONE) { |
| 111 | ret = AVERROR(EINVAL); |
| 112 | av_log(avctx, AV_LOG_ERROR, |
| 113 | "Framebuffer pixel format not supported.\n"); |
| 114 | goto fail; |
| 115 | } |
| 116 | |
| 117 | fbdev->width = fbdev->varinfo.xres; |
| 118 | fbdev->height = fbdev->varinfo.yres; |
| 119 | fbdev->bytes_per_pixel = (fbdev->varinfo.bits_per_pixel + 7) >> 3; |
| 120 | fbdev->frame_linesize = fbdev->width * fbdev->bytes_per_pixel; |
| 121 | fbdev->frame_size = fbdev->frame_linesize * fbdev->height; |
| 122 | fbdev->time_frame = AV_NOPTS_VALUE; |
| 123 | fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->fd, 0); |
nothing calls this directly
no test coverage detected