Go to the documentation of this file.
25 #include <drm_fourcc.h>
28 #include <xf86drmMode.h>
31 #ifndef DRM_FORMAT_MOD_INVALID
32 #define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
80 for (
i = 0;
i <
desc->nb_objects;
i++)
81 close(
desc->objects[
i].fd);
101 fb = drmModeGetFB(
ctx->hwctx->fd, plane->fb_id);
105 "%"PRIu32
": %s.\n", plane->fb_id, strerror(err));
109 if (
fb->width !=
ctx->width ||
fb->height !=
ctx->height) {
111 "dimensions changed: now %"PRIu32
"x%"PRIu32
".\n",
112 ctx->plane_id,
fb->width,
fb->height);
122 err = drmPrimeHandleToFD(
ctx->hwctx->fd,
fb->handle, O_RDONLY, &fd);
126 "framebuffer handle: %s.\n", strerror(err));
135 .size =
fb->height *
fb->pitch,
136 .format_modifier =
ctx->drm_format_modifier,
140 .format =
ctx->drm_format,
156 #if HAVE_LIBDRM_GETFB2
163 int err,
i, nb_objects;
164 uint64_t modifier =
ctx->drm_format_modifier;
166 fb = drmModeGetFB2(
ctx->hwctx->fd, plane->fb_id);
170 "%"PRIu32
": %s.\n", plane->fb_id, strerror(err));
173 if (
fb->pixel_format !=
ctx->drm_format) {
175 "format changed: now %"PRIx32
".\n",
176 ctx->plane_id,
fb->pixel_format);
180 if (
fb->width !=
ctx->width ||
fb->height !=
ctx->height) {
182 "dimensions changed: now %"PRIu32
"x%"PRIu32
".\n",
183 ctx->plane_id,
fb->width,
fb->height);
187 if (!
fb->handles[0]) {
193 if (
fb->flags & DRM_MODE_FB_MODIFIERS)
194 modifier =
fb->modifier;
199 .format =
ctx->drm_format,
204 for (
i = 0;
i < 4 &&
fb->handles[
i];
i++) {
210 for (j = 0; j <
i; j++) {
211 if (
fb->handles[
i] ==
fb->handles[j]) {
217 obj =
desc->layers[0].planes[j].object_index;
224 .offset =
fb->offsets[
i],
225 .pitch =
fb->pitches[
i],
230 err = drmPrimeHandleToFD(
ctx->hwctx->fd,
fb->handles[
i],
235 "framebuffer handle: %s.\n", strerror(err));
244 .format_modifier = modifier,
248 .offset =
fb->offsets[
i],
249 .pitch =
fb->pitches[
i],
253 desc->nb_objects = nb_objects;
254 desc->layers[0].nb_planes =
i;
266 drmModePlane *plane =
NULL;
273 if (
ctx->frame_last) {
276 delay =
ctx->frame_last +
ctx->frame_delay - now;
283 ctx->frame_last = now;
286 plane = drmModeGetPlane(
ctx->hwctx->fd,
ctx->plane_id);
290 "%"PRIu32
": %s.\n",
ctx->plane_id, strerror(err));
296 "an associated framebuffer.\n",
ctx->plane_id);
307 #if HAVE_LIBDRM_GETFB2
308 if (
ctx->fb2_available)
309 err = kmsgrab_get_fb2(avctx, plane,
desc);
340 drmModeFreePlane(plane);
359 drmModeFreePlane(plane);
365 static const struct {
373 #ifdef DRM_FORMAT_R16
412 drmModePlaneRes *plane_res =
NULL;
413 drmModePlane *plane =
NULL;
415 #if HAVE_LIBDRM_GETFB2
416 drmModeFB2 *fb2 =
NULL;
430 err = drmSetClientCap(
ctx->hwctx->fd,
431 DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
434 "capability: primary planes will not be usable.\n");
437 if (
ctx->source_plane > 0) {
438 plane = drmModeGetPlane(
ctx->hwctx->fd,
ctx->source_plane);
442 "%s.\n",
ctx->source_plane, strerror(err));
447 if (plane->fb_id == 0) {
449 "an attached framebuffer.\n",
ctx->source_plane);
454 plane_res = drmModeGetPlaneResources(
ctx->hwctx->fd);
458 "resources: %s.\n", strerror(err));
463 for (
i = 0;
i < plane_res->count_planes;
i++) {
464 plane = drmModeGetPlane(
ctx->hwctx->fd,
465 plane_res->planes[
i]);
469 "plane %"PRIu32
": %s.\n",
470 plane_res->planes[
i], strerror(err));
475 "CRTC %"PRIu32
" FB %"PRIu32
".\n",
476 plane->plane_id, plane->crtc_id, plane->fb_id);
478 if ((
ctx->source_crtc > 0 &&
479 plane->crtc_id !=
ctx->source_crtc) ||
483 drmModeFreePlane(plane);
491 if (
i == plane_res->count_planes) {
492 if (
ctx->source_crtc > 0) {
494 "CRTC %"PRId64
".\n",
ctx->source_crtc);
503 "locate framebuffers.\n", plane->plane_id);
506 ctx->plane_id = plane->plane_id;
508 #if HAVE_LIBDRM_GETFB2
509 fb2 = drmModeGetFB2(
ctx->hwctx->fd, plane->fb_id);
510 if (!fb2 && errno == ENOSYS) {
512 "will try to use GETFB instead.\n");
516 "framebuffer %"PRIu32
": %s.\n",
517 plane->fb_id, strerror(err));
522 "%"PRIu32
": %"PRIu32
"x%"PRIu32
" "
523 "format %"PRIx32
" modifier %"PRIx64
" flags %"PRIx32
".\n",
524 fb2->fb_id, fb2->width, fb2->height,
525 fb2->pixel_format, fb2->modifier, fb2->flags);
527 ctx->width = fb2->width;
528 ctx->height = fb2->height;
530 if (!fb2->handles[0]) {
532 "maybe you need some additional capabilities?\n");
542 "%"PRIx32
" does not match expected format.\n",
547 ctx->drm_format = fb2->pixel_format;
554 "%"PRIx32
" is not a known supported format.\n",
560 if (fb2->flags & DRM_MODE_FB_MODIFIERS) {
562 ctx->drm_format_modifier != fb2->modifier) {
564 "%"PRIx64
" does not match expected modifier.\n",
569 ctx->drm_format_modifier = fb2->modifier;
573 "DRM format %"PRIx32
" modifier %"PRIx64
".\n",
575 ctx->drm_format,
ctx->drm_format_modifier);
577 ctx->fb2_available = 1;
581 if (!
ctx->fb2_available) {
598 fb = drmModeGetFB(
ctx->hwctx->fd, plane->fb_id);
602 "framebuffer %"PRIu32
": %s.\n",
603 plane->fb_id, strerror(err));
609 "%"PRIu32
"x%"PRIu32
" %"PRIu32
"bpp %"PRIu32
"b depth.\n",
610 fb->fb_id,
fb->width,
fb->height,
fb->bpp,
fb->depth);
612 ctx->width =
fb->width;
613 ctx->height =
fb->height;
617 "maybe you need some additional capabilities?\n");
638 if (!
ctx->frames_ref) {
645 ctx->frames->sw_format =
ctx->format,
646 ctx->frames->width =
ctx->width;
647 ctx->frames->height =
ctx->height;
652 "hardware frames context: %d.\n", err);
661 drmModeFreePlaneResources(plane_res);
662 drmModeFreePlane(plane);
664 #if HAVE_LIBDRM_GETFB2
680 #define OFFSET(x) offsetof(KMSGrabContext, x)
681 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
683 {
"device",
"DRM device path",
685 { .str =
"/dev/dri/card0" }, 0, 0,
FLAGS },
686 {
"format",
"Pixel format for framebuffer",
689 {
"format_modifier",
"DRM format modifier for framebuffer",
692 {
"crtc_id",
"CRTC ID to define capture source",
694 { .i64 = 0 }, 0, UINT32_MAX,
FLAGS },
695 {
"plane_id",
"Plane ID to define capture source",
697 { .i64 = 0 }, 0, UINT32_MAX,
FLAGS },
698 {
"framerate",
"Framerate to capture at",
700 { .dbl = 30.0 }, 0, 1000,
FLAGS },
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel 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 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
enum AVMediaType codec_type
General type of the encoded data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
static int kmsgrab_get_fb(AVFormatContext *avctx, drmModePlane *plane, AVDRMFrameDescriptor *desc)
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
AVHWFramesContext * frames
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const struct @235 kmsgrab_formats[]
static av_cold int kmsgrab_read_close(AVFormatContext *avctx)
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
static av_cold int read_close(AVFormatContext *ctx)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
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
#define DRM_FORMAT_MOD_INVALID
int64_t drm_format_modifier
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_usleep(unsigned usec)
Sleep for a period of time.
@ AV_CODEC_ID_WRAPPED_AVFRAME
Passthrough codec, AVFrames wrapped in AVPacket.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const FFInputFormat ff_kmsgrab_demuxer
enum AVPixelFormat format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVDRMDeviceContext * hwctx
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
int flags
A combination of AV_PKT_FLAG values.
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
#define AV_LOG_INFO
Standard information.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
static av_cold int kmsgrab_read_header(AVFormatContext *avctx)
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void kmsgrab_free_frame(void *opaque, uint8_t *data)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_PIX_FMT_X2RGB10BE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), big-endian, X=unused/undefined
This struct describes a set or pool of "hardware" frames (i.e.
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
enum AVPixelFormat pixfmt
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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.
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static const AVOption options[]
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
int64_t av_gettime(void)
Get the current time in microseconds.
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
A reference to a data buffer.
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
static void kmsgrab_free_desc(void *opaque, uint8_t *data)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
AVHWDeviceContext * device
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static const AVClass kmsgrab_class
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
void * priv_data
Format private data.
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.