MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / fbdev_write_header

Function fbdev_write_header

libavdevice/fbdev_enc.c:45–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43} FBDevContext;
44
45static av_cold int fbdev_write_header(AVFormatContext *h)
46{
47 FBDevContext *fbdev = h->priv_data;
48 enum AVPixelFormat pix_fmt;
49 int ret, flags = O_RDWR;
50 const char* device;
51
52 if (h->nb_streams != 1 || h->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
53 av_log(fbdev, AV_LOG_ERROR, "Only a single video stream is supported.\n");
54 return AVERROR(EINVAL);
55 }
56
57 if (h->url[0])
58 device = h->url;
59 else
60 device = ff_fbdev_default_device();
61
62 if ((fbdev->fd = avpriv_open(device, flags)) == -1) {
63 ret = AVERROR(errno);
64 av_log(h, AV_LOG_ERROR,
65 "Could not open framebuffer device '%s': %s\n",
66 device, av_err2str(ret));
67 return ret;
68 }
69
70 if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) {
71 ret = AVERROR(errno);
72 av_log(h, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", av_err2str(ret));
73 goto fail;
74 }
75
76 if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) {
77 ret = AVERROR(errno);
78 av_log(h, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", av_err2str(ret));
79 goto fail;
80 }
81
82 pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
83 if (pix_fmt == AV_PIX_FMT_NONE) {
84 ret = AVERROR(EINVAL);
85 av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n");
86 goto fail;
87 }
88
89 fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->fd, 0);
90 if (fbdev->data == MAP_FAILED) {
91 ret = AVERROR(errno);
92 av_log(h, AV_LOG_ERROR, "Error in mmap(): %s\n", av_err2str(ret));
93 goto fail;
94 }
95
96 return 0;
97 fail:
98 close(fbdev->fd);
99 return ret;
100}
101
102static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt)

Callers

nothing calls this directly

Calls 5

av_logFunction · 0.85
ff_fbdev_default_deviceFunction · 0.85
avpriv_openFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected