mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2026-01-23 18:10:56 +01:00
fixup! lavu: add RKMPP hwcontext
add initial support for rk3576 Signed-off-by: nyanmisaka <nst799610810@gmail.com>
This commit is contained in:
parent
5ddd3d4f5b
commit
521affc277
2 changed files with 56 additions and 11 deletions
|
|
@ -52,6 +52,7 @@ static const struct {
|
|||
{ AV_PIX_FMT_NV21, DRM_FORMAT_NV21, },
|
||||
{ AV_PIX_FMT_NV16, DRM_FORMAT_NV16, },
|
||||
{ AV_PIX_FMT_NV24, DRM_FORMAT_NV24, },
|
||||
{ AV_PIX_FMT_NV42, DRM_FORMAT_NV42, },
|
||||
/* semi-planar YUV 10-bit */
|
||||
{ AV_PIX_FMT_P010, DRM_FORMAT_P010, },
|
||||
{ AV_PIX_FMT_P210, DRM_FORMAT_P210, },
|
||||
|
|
@ -96,15 +97,15 @@ static int rkmpp_device_create(AVHWDeviceContext *hwdev, const char *device,
|
|||
AVRKMPPDeviceContext *hwctx = hwdev->hwctx;
|
||||
AVDictionaryEntry *opt_d = NULL;
|
||||
|
||||
hwctx->flags = MPP_BUFFER_FLAGS_DMA32 | MPP_BUFFER_FLAGS_CACHABLE;
|
||||
hwctx->flags = MPP_BUFFER_FLAGS_DMA32;
|
||||
|
||||
opt_d = av_dict_get(opts, "dma32", NULL, 0);
|
||||
if (opt_d && !strtol(opt_d->value, NULL, 10))
|
||||
hwctx->flags &= ~MPP_BUFFER_FLAGS_DMA32;
|
||||
|
||||
opt_d = av_dict_get(opts, "cacheable", NULL, 0);
|
||||
if (opt_d && !strtol(opt_d->value, NULL, 10))
|
||||
hwctx->flags &= ~MPP_BUFFER_FLAGS_CACHABLE;
|
||||
if (opt_d && strtol(opt_d->value, NULL, 10))
|
||||
hwctx->flags |= MPP_BUFFER_FLAGS_CACHABLE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -299,7 +300,8 @@ static int rkmpp_frames_init(AVHWFramesContext *hwfc)
|
|||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
ret = mpp_buffer_group_get_internal(&avfc->buf_group, MPP_BUFFER_TYPE_DRM | hwctx->flags);
|
||||
ret = mpp_buffer_group_get_internal(&avfc->buf_group,
|
||||
MPP_BUFFER_TYPE_DRM | hwctx->flags | avfc->flags);
|
||||
if (ret != MPP_OK) {
|
||||
av_log(hwfc, AV_LOG_ERROR, "Failed to get MPP internal buffer group: %d\n", ret);
|
||||
return AVERROR_EXTERNAL;
|
||||
|
|
@ -356,13 +358,13 @@ typedef struct RKMPPDRMMapping {
|
|||
static void rkmpp_unmap_frame(AVHWFramesContext *hwfc,
|
||||
HWMapDescriptor *hwmap)
|
||||
{
|
||||
AVRKMPPDeviceContext *hwctx = hwfc->device_ctx->hwctx;
|
||||
AVRKMPPFramesContext *avfc = hwfc->hwctx;
|
||||
RKMPPDRMMapping *map = hwmap->priv;
|
||||
|
||||
for (int i = 0; i < map->nb_regions; i++) {
|
||||
#if HAVE_LINUX_DMA_BUF_H
|
||||
struct dma_buf_sync sync = { .flags = DMA_BUF_SYNC_END | map->sync_flags };
|
||||
if (hwctx->flags & MPP_BUFFER_FLAGS_CACHABLE)
|
||||
if (avfc->flags & MPP_BUFFER_FLAGS_CACHABLE)
|
||||
ioctl(map->object[i], DMA_BUF_IOCTL_SYNC, &sync);
|
||||
#endif
|
||||
if (map->address[i] && map->unmap[i])
|
||||
|
|
@ -375,7 +377,7 @@ static void rkmpp_unmap_frame(AVHWFramesContext *hwfc,
|
|||
static int rkmpp_map_frame(AVHWFramesContext *hwfc,
|
||||
AVFrame *dst, const AVFrame *src, int flags)
|
||||
{
|
||||
AVRKMPPDeviceContext *hwctx = hwfc->device_ctx->hwctx;
|
||||
AVRKMPPFramesContext *avfc = hwfc->hwctx;
|
||||
const AVRKMPPDRMFrameDescriptor *desc = (AVRKMPPDRMFrameDescriptor *)src->data[0];
|
||||
#if HAVE_LINUX_DMA_BUF_H
|
||||
struct dma_buf_sync sync_start = { 0 };
|
||||
|
|
@ -435,7 +437,7 @@ static int rkmpp_map_frame(AVHWFramesContext *hwfc,
|
|||
#if HAVE_LINUX_DMA_BUF_H
|
||||
/* We're not checking for errors here because the kernel may not
|
||||
* support the ioctl, in which case its okay to carry on */
|
||||
if (hwctx->flags & MPP_BUFFER_FLAGS_CACHABLE)
|
||||
if (avfc->flags & MPP_BUFFER_FLAGS_CACHABLE)
|
||||
ioctl(desc->drm_desc.objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,18 +47,57 @@
|
|||
#ifndef DRM_FORMAT_Y210
|
||||
#define DRM_FORMAT_Y210 fourcc_code('Y', '2', '1', '0')
|
||||
#endif
|
||||
#ifndef DRM_FORMAT_VUY888
|
||||
#define DRM_FORMAT_VUY888 fourcc_code('V', 'U', '2', '4')
|
||||
#endif
|
||||
|
||||
/* ARM AFBC (16x16) */
|
||||
#ifndef DRM_FORMAT_MOD_VENDOR_ARM
|
||||
#define DRM_FORMAT_MOD_VENDOR_ARM 0x08
|
||||
#define DRM_FORMAT_MOD_VENDOR_ARM 0x08
|
||||
#endif
|
||||
#ifndef DRM_FORMAT_MOD_ARM_TYPE_AFBC
|
||||
#define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
|
||||
#define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
|
||||
#endif
|
||||
#ifndef AFBC_FORMAT_MOD_BLOCK_SIZE_16x16
|
||||
#define AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 (1ULL)
|
||||
#endif
|
||||
#ifndef AFBC_FORMAT_MOD_SPARSE
|
||||
#define AFBC_FORMAT_MOD_SPARSE (1ULL << 6)
|
||||
#endif
|
||||
|
||||
#define drm_is_afbc(mod) \
|
||||
((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \
|
||||
(DRM_FORMAT_MOD_VENDOR_ARM << 4)))
|
||||
|
||||
/* Rockchip RFBC (64x4) */
|
||||
#undef DRM_FORMAT_MOD_VENDOR_ROCKCHIP
|
||||
#define DRM_FORMAT_MOD_VENDOR_ROCKCHIP 0x0b
|
||||
#undef DRM_FORMAT_MOD_ROCKCHIP_TYPE_SHIFT
|
||||
#define DRM_FORMAT_MOD_ROCKCHIP_TYPE_SHIFT 52
|
||||
#undef DRM_FORMAT_MOD_ROCKCHIP_TYPE_MASK
|
||||
#define DRM_FORMAT_MOD_ROCKCHIP_TYPE_MASK 0xf
|
||||
#undef DRM_FORMAT_MOD_ROCKCHIP_TYPE_RFBC
|
||||
#define DRM_FORMAT_MOD_ROCKCHIP_TYPE_RFBC 0x1
|
||||
#undef ROCKCHIP_RFBC_BLOCK_SIZE_64x4
|
||||
#define ROCKCHIP_RFBC_BLOCK_SIZE_64x4 (1ULL)
|
||||
|
||||
#undef fourcc_mod_code
|
||||
#define fourcc_mod_code(vendor, val) \
|
||||
((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
|
||||
|
||||
#undef DRM_FORMAT_MOD_ROCKCHIP_CODE
|
||||
#define DRM_FORMAT_MOD_ROCKCHIP_CODE(__type, __val) \
|
||||
fourcc_mod_code(ROCKCHIP, ((__u64)(__type) << DRM_FORMAT_MOD_ROCKCHIP_TYPE_SHIFT) | \
|
||||
((__val) & 0x000fffffffffffffULL))
|
||||
|
||||
#undef DRM_FORMAT_MOD_ROCKCHIP_RFBC
|
||||
#define DRM_FORMAT_MOD_ROCKCHIP_RFBC(mode) \
|
||||
DRM_FORMAT_MOD_ROCKCHIP_CODE(DRM_FORMAT_MOD_ROCKCHIP_TYPE_RFBC, mode)
|
||||
|
||||
#define drm_is_rfbc(mod) \
|
||||
(((mod >> 56) & 0xff) == DRM_FORMAT_MOD_VENDOR_ROCKCHIP) && \
|
||||
(((mod >> 52) & DRM_FORMAT_MOD_ROCKCHIP_TYPE_MASK) == DRM_FORMAT_MOD_ROCKCHIP_TYPE_RFBC)
|
||||
|
||||
/**
|
||||
* DRM Prime Frame descriptor for RKMPP HWDevice.
|
||||
*/
|
||||
|
|
@ -85,6 +124,10 @@ typedef struct AVRKMPPFramesContext {
|
|||
* MPP buffer group.
|
||||
*/
|
||||
MppBufferGroup buf_group;
|
||||
/**
|
||||
* MPP buffer allocation flags at frames context level.
|
||||
*/
|
||||
int flags;
|
||||
|
||||
/**
|
||||
* The descriptors of all frames in the pool after creation.
|
||||
|
|
@ -102,7 +145,7 @@ typedef struct AVRKMPPFramesContext {
|
|||
*/
|
||||
typedef struct AVRKMPPDeviceContext {
|
||||
/**
|
||||
* MPP buffer allocation flags.
|
||||
* MPP buffer allocation flags at device context level.
|
||||
*/
|
||||
int flags;
|
||||
} AVRKMPPDeviceContext;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue