FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
kmsgrab.c
Go to the documentation of this file.
1 /*
2  * KMS/DRM input device
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <fcntl.h>
22 #include <unistd.h>
23 
24 #include <drm.h>
25 #include <drm_fourcc.h>
26 #include <drm_mode.h>
27 #include <xf86drm.h>
28 #include <xf86drmMode.h>
29 
30 #include "libavutil/hwcontext.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/mathematics.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/time.h"
38 
39 #include "libavformat/avformat.h"
40 #include "libavformat/internal.h"
41 
42 typedef struct KMSGrabContext {
43  const AVClass *class;
44 
48 
51 
52  uint32_t plane_id;
53  uint32_t drm_format;
54  unsigned int width;
55  unsigned int height;
56 
57  int64_t frame_delay;
58  int64_t frame_last;
59 
60  const char *device_path;
63  int64_t source_plane;
64  int64_t source_crtc;
67 
68 static void kmsgrab_free_desc(void *opaque, uint8_t *data)
69 {
71 
72  close(desc->objects[0].fd);
73 
74  av_free(desc);
75 }
76 
77 static void kmsgrab_free_frame(void *opaque, uint8_t *data)
78 {
79  AVFrame *frame = (AVFrame*)data;
80 
81  av_frame_free(&frame);
82 }
83 
85 {
86  KMSGrabContext *ctx = avctx->priv_data;
87  drmModePlane *plane;
88  drmModeFB *fb;
90  AVFrame *frame;
91  int64_t now;
92  int err, fd;
93 
94  now = av_gettime();
95  if (ctx->frame_last) {
96  int64_t delay;
97  while (1) {
98  delay = ctx->frame_last + ctx->frame_delay - now;
99  if (delay <= 0)
100  break;
101  av_usleep(delay);
102  now = av_gettime();
103  }
104  }
105  ctx->frame_last = now;
106 
107  plane = drmModeGetPlane(ctx->hwctx->fd, ctx->plane_id);
108  if (!plane) {
109  av_log(avctx, AV_LOG_ERROR, "Failed to get plane "
110  "%"PRIu32".\n", ctx->plane_id);
111  return AVERROR(EIO);
112  }
113  if (!plane->fb_id) {
114  av_log(avctx, AV_LOG_ERROR, "Plane %"PRIu32" no longer has "
115  "an associated framebuffer.\n", ctx->plane_id);
116  return AVERROR(EIO);
117  }
118 
119  fb = drmModeGetFB(ctx->hwctx->fd, plane->fb_id);
120  if (!fb) {
121  av_log(avctx, AV_LOG_ERROR, "Failed to get framebuffer "
122  "%"PRIu32".\n", plane->fb_id);
123  return AVERROR(EIO);
124  }
125  if (fb->width != ctx->width || fb->height != ctx->height) {
126  av_log(avctx, AV_LOG_ERROR, "Plane %"PRIu32" framebuffer "
127  "dimensions changed: now %"PRIu32"x%"PRIu32".\n",
128  ctx->plane_id, fb->width, fb->height);
129  return AVERROR(EIO);
130  }
131  if (!fb->handle) {
132  av_log(avctx, AV_LOG_ERROR, "No handle set on framebuffer.\n");
133  return AVERROR(EIO);
134  }
135 
136  err = drmPrimeHandleToFD(ctx->hwctx->fd, fb->handle, O_RDONLY, &fd);
137  if (err < 0) {
138  err = errno;
139  av_log(avctx, AV_LOG_ERROR, "Failed to get PRIME fd from "
140  "framebuffer handle: %s.\n", strerror(errno));
141  return AVERROR(err);
142  }
143 
144  desc = av_mallocz(sizeof(*desc));
145  if (!desc)
146  return AVERROR(ENOMEM);
147 
148  *desc = (AVDRMFrameDescriptor) {
149  .nb_objects = 1,
150  .objects[0] = {
151  .fd = fd,
152  .size = fb->height * fb->pitch,
153  .format_modifier = ctx->drm_format_modifier,
154  },
155  .nb_layers = 1,
156  .layers[0] = {
157  .format = ctx->drm_format,
158  .nb_planes = 1,
159  .planes[0] = {
160  .object_index = 0,
161  .offset = 0,
162  .pitch = fb->pitch,
163  },
164  },
165  };
166 
167  frame = av_frame_alloc();
168  if (!frame)
169  return AVERROR(ENOMEM);
170 
171  frame->hw_frames_ctx = av_buffer_ref(ctx->frames_ref);
172  if (!frame->hw_frames_ctx)
173  return AVERROR(ENOMEM);
174 
175  frame->buf[0] = av_buffer_create((uint8_t*)desc, sizeof(*desc),
176  &kmsgrab_free_desc, avctx, 0);
177  if (!frame->buf[0])
178  return AVERROR(ENOMEM);
179 
180  frame->data[0] = (uint8_t*)desc;
181  frame->format = AV_PIX_FMT_DRM_PRIME;
182  frame->width = fb->width;
183  frame->height = fb->height;
184 
185  drmModeFreeFB(fb);
186  drmModeFreePlane(plane);
187 
188  pkt->buf = av_buffer_create((uint8_t*)frame, sizeof(*frame),
189  &kmsgrab_free_frame, avctx, 0);
190  if (!pkt->buf)
191  return AVERROR(ENOMEM);
192 
193  pkt->data = (uint8_t*)frame;
194  pkt->size = sizeof(*frame);
195  pkt->pts = now;
196  pkt->flags |= AV_PKT_FLAG_TRUSTED;
197 
198  return 0;
199 }
200 
201 static const struct {
203  uint32_t drm_format;
204 } kmsgrab_formats[] = {
205 #ifdef DRM_FORMAT_R8
206  { AV_PIX_FMT_GRAY8, DRM_FORMAT_R8 },
207 #endif
208 #ifdef DRM_FORMAT_R16
209  { AV_PIX_FMT_GRAY16LE, DRM_FORMAT_R16 },
210  { AV_PIX_FMT_GRAY16BE, DRM_FORMAT_R16 | DRM_FORMAT_BIG_ENDIAN },
211 #endif
212  { AV_PIX_FMT_BGR8, DRM_FORMAT_BGR233 },
213  { AV_PIX_FMT_RGB555LE, DRM_FORMAT_XRGB1555 },
214  { AV_PIX_FMT_RGB555BE, DRM_FORMAT_XRGB1555 | DRM_FORMAT_BIG_ENDIAN },
215  { AV_PIX_FMT_BGR555LE, DRM_FORMAT_XBGR1555 },
216  { AV_PIX_FMT_BGR555BE, DRM_FORMAT_XBGR1555 | DRM_FORMAT_BIG_ENDIAN },
217  { AV_PIX_FMT_RGB565LE, DRM_FORMAT_RGB565 },
218  { AV_PIX_FMT_RGB565BE, DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN },
219  { AV_PIX_FMT_BGR565LE, DRM_FORMAT_BGR565 },
220  { AV_PIX_FMT_BGR565BE, DRM_FORMAT_BGR565 | DRM_FORMAT_BIG_ENDIAN },
221  { AV_PIX_FMT_RGB24, DRM_FORMAT_RGB888 },
222  { AV_PIX_FMT_BGR24, DRM_FORMAT_BGR888 },
223  { AV_PIX_FMT_0RGB, DRM_FORMAT_BGRX8888 },
224  { AV_PIX_FMT_0BGR, DRM_FORMAT_RGBX8888 },
225  { AV_PIX_FMT_RGB0, DRM_FORMAT_XBGR8888 },
226  { AV_PIX_FMT_BGR0, DRM_FORMAT_XRGB8888 },
227  { AV_PIX_FMT_ARGB, DRM_FORMAT_BGRA8888 },
228  { AV_PIX_FMT_ABGR, DRM_FORMAT_RGBA8888 },
229  { AV_PIX_FMT_RGBA, DRM_FORMAT_ABGR8888 },
230  { AV_PIX_FMT_BGRA, DRM_FORMAT_ARGB8888 },
231  { AV_PIX_FMT_YUYV422, DRM_FORMAT_YUYV },
232  { AV_PIX_FMT_YVYU422, DRM_FORMAT_YVYU },
233  { AV_PIX_FMT_UYVY422, DRM_FORMAT_UYVY },
234 };
235 
237 {
238  KMSGrabContext *ctx = avctx->priv_data;
239  drmModePlaneRes *plane_res = NULL;
240  drmModePlane *plane = NULL;
241  drmModeFB *fb = NULL;
242  AVStream *stream;
243  int err, i;
244 
245  for (i = 0; i < FF_ARRAY_ELEMS(kmsgrab_formats); i++) {
246  if (kmsgrab_formats[i].pixfmt == ctx->format) {
247  ctx->drm_format = kmsgrab_formats[i].drm_format;
248  break;
249  }
250  }
251  if (i >= FF_ARRAY_ELEMS(kmsgrab_formats)) {
252  av_log(avctx, AV_LOG_ERROR, "Unsupported format %s.\n",
254  return AVERROR(EINVAL);
255  }
256 
258  ctx->device_path, NULL, 0);
259  if (err < 0) {
260  av_log(avctx, AV_LOG_ERROR, "Failed to open DRM device.\n");
261  return err;
262  }
263  ctx->device = (AVHWDeviceContext*) ctx->device_ref->data;
264  ctx->hwctx = (AVDRMDeviceContext*)ctx->device->hwctx;
265 
266  err = drmSetClientCap(ctx->hwctx->fd,
267  DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
268  if (err < 0) {
269  av_log(avctx, AV_LOG_WARNING, "Failed to set universal planes "
270  "capability: primary planes will not be usable.\n");
271  }
272 
273  if (ctx->source_plane > 0) {
274  plane = drmModeGetPlane(ctx->hwctx->fd, ctx->source_plane);
275  if (!plane) {
276  err = errno;
277  av_log(avctx, AV_LOG_ERROR, "Failed to get plane %"PRId64": "
278  "%s.\n", ctx->source_plane, strerror(err));
279  err = AVERROR(err);
280  goto fail;
281  }
282 
283  if (plane->fb_id == 0) {
284  av_log(avctx, AV_LOG_ERROR, "Plane %"PRId64" does not have "
285  "an attached framebuffer.\n", ctx->source_plane);
286  err = AVERROR(EINVAL);
287  goto fail;
288  }
289  } else {
290  plane_res = drmModeGetPlaneResources(ctx->hwctx->fd);
291  if (!plane_res) {
292  av_log(avctx, AV_LOG_ERROR, "Failed to get plane "
293  "resources: %s.\n", strerror(errno));
294  err = AVERROR(EINVAL);
295  goto fail;
296  }
297 
298  for (i = 0; i < plane_res->count_planes; i++) {
299  plane = drmModeGetPlane(ctx->hwctx->fd,
300  plane_res->planes[i]);
301  if (!plane) {
302  err = errno;
303  av_log(avctx, AV_LOG_VERBOSE, "Failed to get "
304  "plane %"PRIu32": %s.\n",
305  plane_res->planes[i], strerror(err));
306  continue;
307  }
308 
309  av_log(avctx, AV_LOG_DEBUG, "Plane %"PRIu32": "
310  "CRTC %"PRIu32" FB %"PRIu32".\n",
311  plane->plane_id, plane->crtc_id, plane->fb_id);
312 
313  if ((ctx->source_crtc > 0 &&
314  plane->crtc_id != ctx->source_crtc) ||
315  plane->fb_id == 0) {
316  // Either not connected to the target source CRTC
317  // or not active.
318  drmModeFreePlane(plane);
319  plane = NULL;
320  continue;
321  }
322 
323  break;
324  }
325 
326  if (i == plane_res->count_planes) {
327  if (ctx->source_crtc > 0) {
328  av_log(avctx, AV_LOG_ERROR, "No usable planes found on "
329  "CRTC %"PRId64".\n", ctx->source_crtc);
330  } else {
331  av_log(avctx, AV_LOG_ERROR, "No usable planes found.\n");
332  }
333  err = AVERROR(EINVAL);
334  goto fail;
335  }
336 
337  av_log(avctx, AV_LOG_INFO, "Using plane %"PRIu32" to "
338  "locate framebuffers.\n", plane->plane_id);
339  }
340 
341  ctx->plane_id = plane->plane_id;
342 
343  fb = drmModeGetFB(ctx->hwctx->fd, plane->fb_id);
344  if (!fb) {
345  err = errno;
346  av_log(avctx, AV_LOG_ERROR, "Failed to get "
347  "framebuffer %"PRIu32": %s.\n",
348  plane->fb_id, strerror(err));
349  err = AVERROR(err);
350  goto fail;
351  }
352 
353  av_log(avctx, AV_LOG_INFO, "Template framebuffer is %"PRIu32": "
354  "%"PRIu32"x%"PRIu32" %"PRIu32"bpp %"PRIu32"b depth.\n",
355  fb->fb_id, fb->width, fb->height, fb->bpp, fb->depth);
356 
357  ctx->width = fb->width;
358  ctx->height = fb->height;
359 
360  if (!fb->handle) {
361  av_log(avctx, AV_LOG_ERROR, "No handle set on framebuffer: "
362  "maybe you need some additional capabilities?\n");
363  err = AVERROR(EINVAL);
364  goto fail;
365  }
366 
367  stream = avformat_new_stream(avctx, NULL);
368  if (!stream) {
369  err = AVERROR(ENOMEM);
370  goto fail;
371  }
372 
375  stream->codecpar->width = fb->width;
376  stream->codecpar->height = fb->height;
378 
379  avpriv_set_pts_info(stream, 64, 1, 1000000);
380 
382  if (!ctx->frames_ref) {
383  err = AVERROR(ENOMEM);
384  goto fail;
385  }
386  ctx->frames = (AVHWFramesContext*)ctx->frames_ref->data;
387 
389  ctx->frames->sw_format = ctx->format,
390  ctx->frames->width = fb->width;
391  ctx->frames->height = fb->height;
392 
393  err = av_hwframe_ctx_init(ctx->frames_ref);
394  if (err < 0) {
395  av_log(avctx, AV_LOG_ERROR, "Failed to initialise "
396  "hardware frames context: %d.\n", err);
397  goto fail;
398  }
399 
400  ctx->frame_delay = av_rescale_q(1, (AVRational) { ctx->framerate.den,
401  ctx->framerate.num }, AV_TIME_BASE_Q);
402 
403  err = 0;
404 fail:
405  if (plane_res)
406  drmModeFreePlaneResources(plane_res);
407  if (plane)
408  drmModeFreePlane(plane);
409  if (fb)
410  drmModeFreeFB(fb);
411 
412  return err;
413 }
414 
416 {
417  KMSGrabContext *ctx = avctx->priv_data;
418 
421 
422  return 0;
423 }
424 
425 #define OFFSET(x) offsetof(KMSGrabContext, x)
426 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
427 static const AVOption options[] = {
428  { "device", "DRM device path",
429  OFFSET(device_path), AV_OPT_TYPE_STRING,
430  { .str = "/dev/dri/card0" }, 0, 0, FLAGS },
431  { "format", "Pixel format for framebuffer",
433  { .i64 = AV_PIX_FMT_BGR0 }, 0, UINT32_MAX, FLAGS },
434  { "format_modifier", "DRM format modifier for framebuffer",
435  OFFSET(drm_format_modifier), AV_OPT_TYPE_INT64,
436  { .i64 = DRM_FORMAT_MOD_NONE }, 0, INT64_MAX, FLAGS },
437  { "crtc_id", "CRTC ID to define capture source",
438  OFFSET(source_crtc), AV_OPT_TYPE_INT64,
439  { .i64 = 0 }, 0, UINT32_MAX, FLAGS },
440  { "plane_id", "Plane ID to define capture source",
441  OFFSET(source_plane), AV_OPT_TYPE_INT64,
442  { .i64 = 0 }, 0, UINT32_MAX, FLAGS },
443  { "framerate", "Framerate to capture at",
444  OFFSET(framerate), AV_OPT_TYPE_RATIONAL,
445  { .dbl = 30.0 }, 0, 1000, FLAGS },
446  { NULL },
447 };
448 
449 static const AVClass kmsgrab_class = {
450  .class_name = "kmsgrab indev",
451  .item_name = av_default_item_name,
452  .option = options,
453  .version = LIBAVUTIL_VERSION_INT,
455 };
456 
458  .name = "kmsgrab",
459  .long_name = NULL_IF_CONFIG_SMALL("KMS screen capture"),
460  .priv_data_size = sizeof(KMSGrabContext),
464  .flags = AVFMT_NOFILE,
465  .priv_class = &kmsgrab_class,
466 };
static const AVClass kmsgrab_class
Definition: kmsgrab.c:449
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
int plane
Definition: avisynth_c.h:422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
int64_t source_crtc
Definition: kmsgrab.c:64
#define NULL
Definition: coverity.c:32
static const AVOption options[]
Definition: kmsgrab.c:427
int64_t frame_delay
Definition: kmsgrab.c:57
static const char * format[]
Definition: af_aiir.c:330
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
static void kmsgrab_free_desc(void *opaque, uint8_t *data)
Definition: kmsgrab.c:68
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4882
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:418
const char * desc
Definition: nvenc.c:65
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3900
int num
Numerator.
Definition: rational.h:59
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:108
enum AVPixelFormat format
Definition: kmsgrab.c:61
int size
Definition: avcodec.h:1446
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:111
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
static AVPacket pkt
int nb_objects
Number of DRM objects making up this frame.
const char * device_path
Definition: kmsgrab.c:60
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
Definition: frame.h:564
Format I/O context.
Definition: avformat.h:1351
DRM frame descriptor.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
uint8_t
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
int width
Video only.
Definition: avcodec.h:3966
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
AVOptions.
uint32_t plane_id
Definition: kmsgrab.c:52
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4455
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition: hwcontext.c:571
uint8_t * data
Definition: avcodec.h:1445
static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: kmsgrab.c:84
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
int fd
DRM PRIME fd for the object.
Definition: hwcontext_drm.h:52
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
static av_cold int kmsgrab_read_close(AVFormatContext *avctx)
Definition: kmsgrab.c:415
int width
Definition: frame.h:284
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3896
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1428
#define OFFSET(x)
Definition: kmsgrab.c:425
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:28
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:329
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
#define fail()
Definition: checkasm.h:117
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1451
common internal API header
static const struct @195 kmsgrab_formats[]
#define fb(width, name)
Definition: cbs_av1.c:584
uint32_t drm_format
Definition: kmsgrab.c:53
AVRational framerate
Definition: kmsgrab.c:65
AVFormatContext * ctx
Definition: movenc.c:48
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:210
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES]
Array of objects making up the frame.
Passthrough codec, AVFrames wrapped in AVPacket.
Definition: avcodec.h:700
AVHWDeviceContext * device
Definition: kmsgrab.c:46
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:110
#define FF_ARRAY_ELEMS(a)
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
Stream structure.
Definition: avformat.h:874
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:299
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int64_t source_plane
Definition: kmsgrab.c:63
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
unsigned int width
Definition: kmsgrab.c:54
uint8_t * data
The data buffer.
Definition: buffer.h:89
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
Describe the class of an AVClass context structure.
Definition: log.h:67
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
Rational number (pair of numerator and denominator).
Definition: rational.h:58
DRM-managed buffers exposed through PRIME buffer sharing.
Definition: pixfmt.h:328
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:113
AVDRMDeviceContext * hwctx
Definition: kmsgrab.c:47
API-specific header for AV_HWDEVICE_TYPE_DRM.
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
Definition: avcodec.h:1491
#define flags(name, subs,...)
Definition: cbs_av1.c:596
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
A reference to a data buffer.
Definition: buffer.h:81
Main libavformat public API header.
Y , 8bpp.
Definition: pixfmt.h:74
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
int fd
File descriptor of DRM device.
static void kmsgrab_free_frame(void *opaque, uint8_t *data)
Definition: kmsgrab.c:77
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:243
#define FLAGS
Definition: kmsgrab.c:426
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
unsigned int height
Definition: kmsgrab.c:55
uint32_t drm_format
Definition: kmsgrab.c:203
int den
Denominator.
Definition: rational.h:60
static av_cold int kmsgrab_read_header(AVFormatContext *avctx)
Definition: kmsgrab.c:236
pixel format definitions
#define av_free(p)
AVHWFramesContext * frames
Definition: kmsgrab.c:50
int64_t drm_format_modifier
Definition: kmsgrab.c:62
void * priv_data
Format private data.
Definition: avformat.h:1379
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
AVInputFormat ff_kmsgrab_demuxer
Definition: kmsgrab.c:457
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:202
AVBufferRef * device_ref
Definition: kmsgrab.c:45
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:112
int height
Definition: frame.h:284
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:647
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1021
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2362
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: avcodec.h:1422
AVBufferRef * frames_ref
Definition: kmsgrab.c:49
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1438
int64_t frame_last
Definition: kmsgrab.c:58