FFmpeg
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 {
80 
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 
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;
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",
253  av_get_pix_fmt_name(ctx->format));
254  return AVERROR(EINVAL);
255  }
256 
257  err = av_hwdevice_ctx_create(&ctx->device_ref, AV_HWDEVICE_TYPE_DRM,
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 
381  ctx->frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
382  if (!ctx->frames_ref) {
383  err = AVERROR(ENOMEM);
384  goto fail;
385  }
386  ctx->frames = (AVHWFramesContext*)ctx->frames_ref->data;
387 
388  ctx->frames->format = AV_PIX_FMT_DRM_PRIME;
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 
419  av_buffer_unref(&ctx->frames_ref);
420  av_buffer_unref(&ctx->device_ref);
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",
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 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4480
KMSGrabContext::frames_ref
AVBufferRef * frames_ref
Definition: kmsgrab.c:49
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:329
KMSGrabContext::frame_last
int64_t frame_last
Definition: kmsgrab.c:58
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
pixdesc.h
KMSGrabContext::device_path
const char * device_path
Definition: kmsgrab.c:60
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:243
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
AV_PIX_FMT_DRM_PRIME
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
Definition: pixfmt.h:328
KMSGrabContext::plane_id
uint32_t plane_id
Definition: kmsgrab.c:52
AVOption
AVOption.
Definition: opt.h:246
data
const char data[16]
Definition: mxf.c:91
KMSGrabContext::width
unsigned int width
Definition: kmsgrab.c:54
KMSGrabContext::frame_delay
int64_t frame_delay
Definition: kmsgrab.c:57
KMSGrabContext::height
unsigned int height
Definition: kmsgrab.c:55
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
av_buffer_create
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
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
mathematics.h
AVDRMFrameDescriptor
DRM frame descriptor.
Definition: hwcontext_drm.h:133
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:228
KMSGrabContext::frames
AVHWFramesContext * frames
Definition: kmsgrab.c:50
AV_PIX_FMT_RGB555BE
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
kmsgrab_read_close
static av_cold int kmsgrab_read_close(AVFormatContext *avctx)
Definition: kmsgrab.c:415
AV_PIX_FMT_GRAY16BE
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
framerate
int framerate
Definition: h264_levels.c:65
fail
#define fail()
Definition: checkasm.h:120
plane
int plane
Definition: avisynth_c.h:384
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVInputFormat
Definition: avformat.h:640
av_cold
#define av_cold
Definition: attributes.h:84
kmsgrab_read_packet
static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: kmsgrab.c:84
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
AVCodecParameters::width
int width
Video only.
Definition: avcodec.h:4023
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:224
KMSGrabContext::drm_format_modifier
int64_t drm_format_modifier
Definition: kmsgrab.c:62
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
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
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AV_CODEC_ID_WRAPPED_AVFRAME
@ AV_CODEC_ID_WRAPPED_AVFRAME
Passthrough codec, AVFrames wrapped in AVPacket.
Definition: avcodec.h:708
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
KMSGrabContext::device_ref
AVBufferRef * device_ref
Definition: kmsgrab.c:45
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1460
AV_PIX_FMT_RGB565LE
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
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
KMSGrabContext::framerate
AVRational framerate
Definition: kmsgrab.c:65
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_BGR565LE
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:111
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
time.h
AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
Definition: log.h:42
KMSGrabContext
Definition: kmsgrab.c:42
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_BGR555BE
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:112
KMSGrabContext::source_crtc
int64_t source_crtc
Definition: kmsgrab.c:64
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
desc
const char * desc
Definition: nvenc.c:68
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
AVPacket::size
int size
Definition: avcodec.h:1478
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
avpriv_set_pts_info
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:4910
KMSGrabContext::drm_format
uint32_t drm_format
Definition: kmsgrab.c:53
OFFSET
#define OFFSET(x)
Definition: kmsgrab.c:425
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:463
KMSGrabContext::format
enum AVPixelFormat format
Definition: kmsgrab.c:61
KMSGrabContext::hwctx
AVDRMDeviceContext * hwctx
Definition: kmsgrab.c:47
AV_PIX_FMT_BGR565BE
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:110
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
kmsgrab_read_header
static av_cold int kmsgrab_read_header(AVFormatContext *avctx)
Definition: kmsgrab.c:236
AV_PIX_FMT_RGB555LE
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:108
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
kmsgrab_free_frame
static void kmsgrab_free_frame(void *opaque, uint8_t *data)
Definition: kmsgrab.c:77
internal.h
AVCodecParameters::height
int height
Definition: avcodec.h:4024
fb
#define fb(width, name)
Definition: cbs_av1.c:553
uint8_t
uint8_t
Definition: audio_convert.c:194
av_mallocz
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
hwcontext_drm.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
AV_PIX_FMT_YVYU422
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:210
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:870
pixfmt
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:202
pixfmt.h
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
AVClass::class_name
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
av_hwdevice_ctx_create
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
avformat.h
drm_format
uint32_t drm_format
Definition: kmsgrab.c:203
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
options
static const AVOption options[]
Definition: kmsgrab.c:427
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Definition: opt.h:234
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AV_PIX_FMT_RGB565BE
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
av_gettime
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
ff_kmsgrab_demuxer
AVInputFormat ff_kmsgrab_demuxer
Definition: kmsgrab.c:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
kmsgrab_formats
static const struct @204 kmsgrab_formats[]
AV_PIX_FMT_GRAY16LE
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
AVCodecParameters::format
int format
Definition: avcodec.h:3981
AV_PIX_FMT_BGR555LE
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:113
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
kmsgrab_free_desc
static void kmsgrab_free_desc(void *opaque, uint8_t *data)
Definition: kmsgrab.c:68
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
KMSGrabContext::device
AVHWDeviceContext * device
Definition: kmsgrab.c:46
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
hwcontext.h
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
kmsgrab_class
static const AVClass kmsgrab_class
Definition: kmsgrab.c:449
KMSGrabContext::source_plane
int64_t source_plane
Definition: kmsgrab.c:63
AVDRMDeviceContext
DRM device.
Definition: hwcontext_drm.h:157
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AV_PKT_FLAG_TRUSTED
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
Definition: avcodec.h:1523
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1370
FLAGS
#define FLAGS
Definition: kmsgrab.c:426
AV_HWDEVICE_TYPE_DRM
@ AV_HWDEVICE_TYPE_DRM
Definition: hwcontext.h:36
av_get_pix_fmt_name
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:2438