25 #include <drm_fourcc.h>
28 #include <xf86drmMode.h>
115 "an associated framebuffer.\n", ctx->
plane_id);
119 fb = drmModeGetFB(ctx->
hwctx->
fd, plane->fb_id);
122 "%"PRIu32
".\n", plane->fb_id);
125 if (fb->width != ctx->
width || fb->height != ctx->
height) {
127 "dimensions changed: now %"PRIu32
"x%"PRIu32
".\n",
128 ctx->
plane_id, fb->width, fb->height);
136 err = drmPrimeHandleToFD(ctx->
hwctx->
fd, fb->handle, O_RDONLY, &fd);
140 "framebuffer handle: %s.\n", strerror(errno));
152 .size = fb->height * fb->pitch,
182 frame->
width = fb->width;
183 frame->
height = fb->height;
186 drmModeFreePlane(plane);
194 pkt->
size =
sizeof(*frame);
201 static const struct {
208 #ifdef DRM_FORMAT_R16
239 drmModePlaneRes *plane_res =
NULL;
241 drmModeFB *fb =
NULL;
266 err = drmSetClientCap(ctx->
hwctx->
fd,
267 DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
270 "capability: primary planes will not be usable.\n");
283 if (plane->fb_id == 0) {
290 plane_res = drmModeGetPlaneResources(ctx->
hwctx->
fd);
293 "resources: %s.\n", strerror(errno));
298 for (i = 0; i < plane_res->count_planes; i++) {
299 plane = drmModeGetPlane(ctx->
hwctx->
fd,
300 plane_res->planes[i]);
304 "plane %"PRIu32
": %s.\n",
305 plane_res->planes[i], strerror(err));
310 "CRTC %"PRIu32
" FB %"PRIu32
".\n",
311 plane->plane_id, plane->crtc_id, plane->fb_id);
318 drmModeFreePlane(plane);
326 if (i == plane_res->count_planes) {
338 "locate framebuffers.\n", plane->plane_id);
343 fb = drmModeGetFB(ctx->
hwctx->
fd, plane->fb_id);
347 "framebuffer %"PRIu32
": %s.\n",
348 plane->fb_id, strerror(err));
354 "%"PRIu32
"x%"PRIu32
" %"PRIu32
"bpp %"PRIu32
"b depth.\n",
355 fb->fb_id, fb->width, fb->height, fb->bpp, fb->depth);
357 ctx->
width = fb->width;
362 "maybe you need some additional capabilities?\n");
396 "hardware frames context: %d.\n", err);
406 drmModeFreePlaneResources(plane_res);
408 drmModeFreePlane(plane);
425 #define OFFSET(x) offsetof(KMSGrabContext, x)
426 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
428 {
"device",
"DRM device path",
430 { .str =
"/dev/dri/card0" }, 0, 0,
FLAGS },
431 {
"format",
"Pixel format for framebuffer",
434 {
"format_modifier",
"DRM format modifier for framebuffer",
436 { .i64 = DRM_FORMAT_MOD_NONE }, 0, INT64_MAX,
FLAGS },
437 {
"crtc_id",
"CRTC ID to define capture source",
439 { .i64 = 0 }, 0, UINT32_MAX,
FLAGS },
440 {
"plane_id",
"Plane ID to define capture source",
442 { .i64 = 0 }, 0, UINT32_MAX,
FLAGS },
443 {
"framerate",
"Framerate to capture at",
445 { .dbl = 30.0 }, 0, 1000,
FLAGS },
464 .priv_class = &kmsgrab_class,
static const AVClass kmsgrab_class
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
static const AVOption options[]
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
static void kmsgrab_free_desc(void *opaque, uint8_t *data)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
enum AVPixelFormat format
int width
The allocated dimensions of the frames in this pool.
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_usleep(unsigned usec)
Sleep for a period of time.
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
int nb_objects
Number of DRM objects making up this frame.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const struct @162 kmsgrab_formats[]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
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.
static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
int fd
DRM PRIME fd for the object.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static av_cold int kmsgrab_read_close(AVFormatContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVMediaType codec_type
General type of the encoded data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
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.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
common internal API header
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
packed RGB 8:8:8, 24bpp, BGRBGR...
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES]
Array of objects making up the frame.
Passthrough codec, AVFrames wrapped in AVPacket.
AVHWDeviceContext * device
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
#define FF_ARRAY_ELEMS(a)
static int read_header(FFV1Context *f)
int64_t av_gettime(void)
Get the current time in microseconds.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
#define AV_LOG_INFO
Standard information.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
uint8_t * data
The data buffer.
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
static const char * format
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
DRM-managed buffers exposed through PRIME buffer sharing.
This struct describes a set or pool of "hardware" frames (i.e.
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined ...
AVDRMDeviceContext * hwctx
API-specific header for AV_HWDEVICE_TYPE_DRM.
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
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.
A reference to a data buffer.
int fd
File descriptor of DRM device.
static void kmsgrab_free_frame(void *opaque, uint8_t *data)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static av_cold int kmsgrab_read_header(AVFormatContext *avctx)
AVHWFramesContext * frames
int64_t drm_format_modifier
void * priv_data
Format private data.
Y , 16bpp, little-endian.
AVInputFormat ff_kmsgrab_demuxer
enum AVPixelFormat pixfmt
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
AVCodecParameters * codecpar
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.
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...