ffmpeg: update request api patches

This commit is contained in:
Jernej Skrabec 2019-05-25 18:43:46 +02:00 committed by MilhouseVH
parent 61ad04c423
commit 5897e8155e
5 changed files with 99 additions and 52 deletions

View File

@ -1,21 +1,21 @@
From 4bd117a06e468ad2259f3011c95c182150f295ef Mon Sep 17 00:00:00 2001
From 0ba3c868e1d828520b8facaa4ce36d9b80339cc6 Mon Sep 17 00:00:00 2001
From: Jonas Karlman <jonas@kwiboo.se>
Date: Sat, 15 Dec 2018 22:32:16 +0100
Subject: [PATCH 2/6] Add common V4L2 request API code
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
configure | 8 +
configure | 12 +
libavcodec/Makefile | 1 +
libavcodec/hwaccel.h | 2 +
libavcodec/v4l2_request.c | 885 ++++++++++++++++++++++++++++++++++++++
libavcodec/v4l2_request.c | 888 ++++++++++++++++++++++++++++++++++++++
libavcodec/v4l2_request.h | 65 +++
5 files changed, 961 insertions(+)
5 files changed, 968 insertions(+)
create mode 100644 libavcodec/v4l2_request.c
create mode 100644 libavcodec/v4l2_request.h
diff --git a/configure b/configure
index 172611bb4a..ed587ec05e 100755
index 172611bb4a..6401cae9e7 100755
--- a/configure
+++ b/configure
@@ -264,6 +264,7 @@ External library support:
@ -66,7 +66,18 @@ index 172611bb4a..ed587ec05e 100755
enabled libv4l2 && require_pkg_config libv4l2 libv4l2 libv4l2.h v4l2_ioctl
enabled libvidstab && require_pkg_config libvidstab "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
enabled libvmaf && require_pkg_config libvmaf "libvmaf >= 0.6.2" libvmaf.h compute_vmaf
@@ -6230,6 +6236,8 @@ check_cc h264_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H264;"
@@ -6153,6 +6159,10 @@ enabled rkmpp && { require_pkg_config rkmpp rockchip_mpp rockchip/r
{ enabled libdrm ||
die "ERROR: rkmpp requires --enable-libdrm"; }
}
+enabled v4l2_request && { enabled libdrm ||
+ die "ERROR: v4l2-request requires --enable-libdrm"; } &&
+ { enabled libudev ||
+ die "ERROR: v4l2-request requires --enable-libudev"; }
if enabled gcrypt; then
GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
@@ -6230,6 +6240,8 @@ check_cc h264_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H264;"
check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
@ -101,10 +112,10 @@ index 3aaa92571c..2eefc91e7e 100644
#endif /* AVCODEC_HWACCEL_H */
diff --git a/libavcodec/v4l2_request.c b/libavcodec/v4l2_request.c
new file mode 100644
index 0000000000..f66cba3ae8
index 0000000000..4589209e60
--- /dev/null
+++ b/libavcodec/v4l2_request.c
@@ -0,0 +1,885 @@
@@ -0,0 +1,888 @@
+/*
+ * This file is part of FFmpeg.
+ *
@ -181,7 +192,7 @@ index 0000000000..f66cba3ae8
+ .type = buf->buffer.type,
+ .memory = buf->buffer.memory,
+ .index = buf->index,
+ .timestamp.tv_usec = buf->index,
+ .timestamp.tv_usec = buf->index + 1,
+ .bytesused = buf->used,
+ .request_fd = request_fd,
+ .flags = (request_fd >= 0) ? V4L2_BUF_FLAG_REQUEST_FD : 0,
@ -282,6 +293,8 @@ index 0000000000..f66cba3ae8
+ return -1;
+ }
+
+ memset(req->output.addr + req->output.used, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ ret = v4l2_request_queue_buffer(ctx, req->request_fd, &req->output);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "%s: queue output buffer %d failed for request %d, %s (%d)\n", __func__, req->output.index, req->request_fd, strerror(errno), errno);
@ -827,7 +840,6 @@ index 0000000000..f66cba3ae8
+ buf->buffer.type = type;
+ buf->buffer.memory = V4L2_MEMORY_MMAP;
+ buf->buffer.index = buf->index;
+ buf->buffer.timestamp.tv_usec = buf->index;
+
+ ret = ioctl(ctx->video_fd, VIDIOC_QUERYBUF, &buf->buffer);
+ if (ret < 0) {
@ -835,6 +847,8 @@ index 0000000000..f66cba3ae8
+ return ret;
+ }
+
+ buf->buffer.timestamp.tv_usec = buf->index + 1;
+
+ if (V4L2_TYPE_IS_OUTPUT(type)) {
+ void *addr = mmap(NULL, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->video_fd, V4L2_TYPE_IS_MULTIPLANAR(type) ? buf->buffer.m.planes[0].m.mem_offset : buf->buffer.m.offset);
+ if (addr == MAP_FAILED) {

View File

@ -1,4 +1,4 @@
From de3bcf7557503e5d61b43cdc32d0844deab1c295 Mon Sep 17 00:00:00 2001
From f4f6c74953b0bfaadec93b01d855a15f08c558a2 Mon Sep 17 00:00:00 2001
From: Jonas Karlman <jonas@kwiboo.se>
Date: Sat, 15 Dec 2018 22:32:16 +0100
Subject: [PATCH 3/6] Add V4L2 request API mpeg2 hwaccel
@ -14,7 +14,7 @@ Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
create mode 100644 libavcodec/v4l2_request_mpeg2.c
diff --git a/configure b/configure
index ed587ec05e..c93d67056d 100755
index 6401cae9e7..b163ed8dbe 100755
--- a/configure
+++ b/configure
@@ -2846,6 +2846,8 @@ mpeg2_dxva2_hwaccel_deps="dxva2"
@ -26,7 +26,7 @@ index ed587ec05e..c93d67056d 100755
mpeg2_vaapi_hwaccel_deps="vaapi"
mpeg2_vaapi_hwaccel_select="mpeg2video_decoder"
mpeg2_vdpau_hwaccel_deps="vdpau"
@@ -6237,6 +6239,7 @@ check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
@@ -6241,6 +6243,7 @@ check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
check_func_headers "linux/media.h linux/videodev2.h" v4l2_timeval_to_ns

View File

@ -1,4 +1,4 @@
From bc1ed76cbc2dad2ec308801552e2398fc2de0a07 Mon Sep 17 00:00:00 2001
From 250fab0e761f4956c009a6333c6799f63440b091 Mon Sep 17 00:00:00 2001
From: Jernej Skrabec <jernej.skrabec@siol.net>
Date: Sat, 15 Dec 2018 22:32:16 +0100
Subject: [PATCH 4/6] Add V4L2 request API h264 hwaccel
@ -11,12 +11,12 @@ Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
libavcodec/h264_slice.c | 4 +
libavcodec/h264dec.c | 3 +
libavcodec/hwaccels.h | 1 +
libavcodec/v4l2_request_h264.c | 368 +++++++++++++++++++++++++++++++++
6 files changed, 380 insertions(+)
libavcodec/v4l2_request_h264.c | 367 +++++++++++++++++++++++++++++++++
6 files changed, 379 insertions(+)
create mode 100644 libavcodec/v4l2_request_h264.c
diff --git a/configure b/configure
index c93d67056d..296ca78ce7 100755
index b163ed8dbe..698a91d5dc 100755
--- a/configure
+++ b/configure
@@ -2804,6 +2804,8 @@ h264_dxva2_hwaccel_deps="dxva2"
@ -28,7 +28,7 @@ index c93d67056d..296ca78ce7 100755
h264_vaapi_hwaccel_deps="vaapi"
h264_vaapi_hwaccel_select="h264_decoder"
h264_vdpau_hwaccel_deps="vdpau"
@@ -6239,6 +6241,7 @@ check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
@@ -6243,6 +6245,7 @@ check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
check_func_headers "linux/media.h linux/videodev2.h" v4l2_timeval_to_ns
@ -98,10 +98,10 @@ index ef54de2a3b..003200edea 100644
extern const AVHWAccel ff_h264_videotoolbox_hwaccel;
diff --git a/libavcodec/v4l2_request_h264.c b/libavcodec/v4l2_request_h264.c
new file mode 100644
index 0000000000..a5c56d81c3
index 0000000000..3687325fad
--- /dev/null
+++ b/libavcodec/v4l2_request_h264.c
@@ -0,0 +1,368 @@
@@ -0,0 +1,367 @@
+/*
+ * This file is part of FFmpeg.
+ *
@ -164,8 +164,10 @@ index 0000000000..a5c56d81c3
+ entry->flags |= V4L2_H264_DPB_ENTRY_FLAG_ACTIVE;
+ if (pic->long_ref)
+ entry->flags |= V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM;
+ entry->top_field_order_cnt = pic->field_poc[0];
+ entry->bottom_field_order_cnt = pic->field_poc[1];
+ if (pic->field_poc[0] != INT_MAX)
+ entry->top_field_order_cnt = pic->field_poc[0];
+ if (pic->field_poc[1] != INT_MAX)
+ entry->bottom_field_order_cnt = pic->field_poc[1];
+}
+
+static void fill_dpb(struct v4l2_ctrl_h264_decode_params *decode, const H264Context *h)
@ -174,7 +176,7 @@ index 0000000000..a5c56d81c3
+
+ for (int i = 0; i < h->short_ref_count; i++) {
+ const H264Picture *pic = h->short_ref[i];
+ if (pic)
+ if (pic && (pic->field_poc[0] != INT_MAX || pic->field_poc[1] != INT_MAX))
+ fill_dpb_entry(&decode->dpb[entries++], pic);
+ }
+
@ -183,7 +185,7 @@ index 0000000000..a5c56d81c3
+
+ for (int i = 0; i < FF_ARRAY_ELEMS(h->long_ref); i++) {
+ const H264Picture *pic = h->long_ref[i];
+ if (pic)
+ if (pic && (pic->field_poc[0] != INT_MAX || pic->field_poc[1] != INT_MAX))
+ fill_dpb_entry(&decode->dpb[entries++], pic);
+ }
+}
@ -299,11 +301,8 @@ index 0000000000..a5c56d81c3
+ controls->decode_params = (struct v4l2_ctrl_h264_decode_params) {
+ .num_slices = 0,
+ .nal_ref_idc = h->nal_ref_idc,
+ //.ref_pic_list_p0[32] - not required? not set by libva-v4l2-request
+ //.ref_pic_list_b0[32] - not required? not set by libva-v4l2-request
+ //.ref_pic_list_b1[32] - not required? not set by libva-v4l2-request
+ .top_field_order_cnt = h->cur_pic_ptr->field_poc[0],
+ .bottom_field_order_cnt = h->cur_pic_ptr->field_poc[1],
+ .top_field_order_cnt = h->cur_pic_ptr->field_poc[0] != INT_MAX ? h->cur_pic_ptr->field_poc[0] : 0,
+ .bottom_field_order_cnt = h->cur_pic_ptr->field_poc[1] != INT_MAX ? h->cur_pic_ptr->field_poc[1] : 0,
+ };
+
+ if (h->picture_idr)

View File

@ -1,4 +1,4 @@
From 25065e4e219c6bd688e6b62e40be74f1cfa08e72 Mon Sep 17 00:00:00 2001
From 55751072c14f2ef678489be3d527f34604bb5602 Mon Sep 17 00:00:00 2001
From: Jernej Skrabec <jernej.skrabec@siol.net>
Date: Sat, 15 Dec 2018 22:32:16 +0100
Subject: [PATCH 5/6] Add V4L2 request API hevc hwaccel
@ -15,7 +15,7 @@ Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
create mode 100644 libavcodec/v4l2_request_hevc.c
diff --git a/configure b/configure
index 296ca78ce7..9252ca5794 100755
index 698a91d5dc..2d39cecbdf 100755
--- a/configure
+++ b/configure
@@ -2820,6 +2820,8 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
@ -27,7 +27,7 @@ index 296ca78ce7..9252ca5794 100755
hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
hevc_vaapi_hwaccel_select="hevc_decoder"
hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
@@ -6242,6 +6244,7 @@ check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
@@ -6246,6 +6248,7 @@ check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
check_func_headers "linux/media.h linux/videodev2.h" v4l2_timeval_to_ns
check_cc h264_v4l2_request linux/videodev2.h "int i = V4L2_PIX_FMT_H264_SLICE_RAW;"
@ -103,7 +103,7 @@ index 003200edea..d183675abe 100644
extern const AVHWAccel ff_hevc_videotoolbox_hwaccel;
diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c
new file mode 100644
index 0000000000..300c1866ce
index 0000000000..38969d77fb
--- /dev/null
+++ b/libavcodec/v4l2_request_hevc.c
@@ -0,0 +1,391 @@
@ -480,7 +480,7 @@ index 0000000000..300c1866ce
+
+static int v4l2_request_hevc_init(AVCodecContext *avctx)
+{
+ return ff_v4l2_request_init(avctx, V4L2_PIX_FMT_HEVC_SLICE, 2 * 1024 * 1024, NULL, 0);
+ return ff_v4l2_request_init(avctx, V4L2_PIX_FMT_HEVC_SLICE, 3 * 1024 * 1024, NULL, 0);
+}
+
+const AVHWAccel ff_hevc_v4l2request_hwaccel = {

View File

@ -1,27 +1,50 @@
From 583677006f15ee59600f6f30f5e79aa5f81935b9 Mon Sep 17 00:00:00 2001
From d80cbc949372d6f19dc8c3b5f97b336864bd259c Mon Sep 17 00:00:00 2001
From: Jernej Skrabec <jernej.skrabec@siol.net>
Date: Thu, 14 Feb 2019 23:20:05 +0100
Subject: [PATCH 6/6] Add and use private linux headers for V4L2 request API
ctrls
---
libavcodec/h264-ctrls.h | 192 +++++++++++++++++++++++++++++++
libavcodec/hevc-ctrls.h | 197 ++++++++++++++++++++++++++++++++
configure | 4 +-
libavcodec/h264-ctrls.h | 197 +++++++++++++++++++++++++++++++
libavcodec/hevc-ctrls.h | 203 ++++++++++++++++++++++++++++++++
libavcodec/mpeg2-ctrls.h | 82 +++++++++++++
libavcodec/v4l2_request_h264.c | 1 +
libavcodec/v4l2_request_hevc.c | 1 +
libavcodec/v4l2_request_mpeg2.c | 1 +
6 files changed, 474 insertions(+)
7 files changed, 487 insertions(+), 2 deletions(-)
create mode 100644 libavcodec/h264-ctrls.h
create mode 100644 libavcodec/hevc-ctrls.h
create mode 100644 libavcodec/mpeg2-ctrls.h
diff --git a/configure b/configure
index 2d39cecbdf..23b1e57882 100755
--- a/configure
+++ b/configure
@@ -2804,7 +2804,7 @@ h264_dxva2_hwaccel_deps="dxva2"
h264_dxva2_hwaccel_select="h264_decoder"
h264_nvdec_hwaccel_deps="nvdec"
h264_nvdec_hwaccel_select="h264_decoder"
-h264_v4l2request_hwaccel_deps="v4l2_request h264_v4l2_request"
+h264_v4l2request_hwaccel_deps="v4l2_request"
h264_v4l2request_hwaccel_select="h264_decoder"
h264_vaapi_hwaccel_deps="vaapi"
h264_vaapi_hwaccel_select="h264_decoder"
@@ -2820,7 +2820,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
hevc_dxva2_hwaccel_select="hevc_decoder"
hevc_nvdec_hwaccel_deps="nvdec"
hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_v4l2request_hwaccel_deps="v4l2_request hevc_v4l2_request"
+hevc_v4l2request_hwaccel_deps="v4l2_request"
hevc_v4l2request_hwaccel_select="hevc_decoder"
hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
hevc_vaapi_hwaccel_select="hevc_decoder"
diff --git a/libavcodec/h264-ctrls.h b/libavcodec/h264-ctrls.h
new file mode 100644
index 0000000000..e2f83b3cdb
index 0000000000..e1404d78d6
--- /dev/null
+++ b/libavcodec/h264-ctrls.h
@@ -0,0 +1,192 @@
@@ -0,0 +1,197 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * These are the H.264 state controls for use with stateless H.264
@ -35,6 +58,11 @@ index 0000000000..e2f83b3cdb
+#ifndef _H264_CTRLS_H_
+#define _H264_CTRLS_H_
+
+#include <linux/videodev2.h>
+
+/* Our pixel format isn't stable at the moment */
+#define V4L2_PIX_FMT_H264_SLICE_RAW v4l2_fourcc('S', '2', '6', '4') /* H264 parsed slices */
+
+/*
+ * This is put insanely high to avoid conflicting with controls that
+ * would be added during the phase where those controls are not
@ -216,10 +244,10 @@ index 0000000000..e2f83b3cdb
+#endif
diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h
new file mode 100644
index 0000000000..c8c61079c6
index 0000000000..eee4479c7a
--- /dev/null
+++ b/libavcodec/hevc-ctrls.h
@@ -0,0 +1,197 @@
@@ -0,0 +1,203 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * These are the HEVC state controls for use with stateless HEVC
@ -233,21 +261,27 @@ index 0000000000..c8c61079c6
+#ifndef _HEVC_CTRLS_H_
+#define _HEVC_CTRLS_H_
+
+#define V4L2_CID_MPEG_VIDEO_HEVC_SPS (V4L2_CID_MPEG_BASE + 645)
+#define V4L2_CID_MPEG_VIDEO_HEVC_PPS (V4L2_CID_MPEG_BASE + 646)
+#define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (V4L2_CID_MPEG_BASE + 647)
+#define V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX (V4L2_CID_MPEG_BASE + 648)
+#include <linux/videodev2.h>
+
+/* The pixel format isn't stable at the moment and will likely be renamed. */
+#define V4L2_PIX_FMT_HEVC_SLICE v4l2_fourcc('S', '2', '6', '5') /* HEVC parsed slices */
+
+#define V4L2_CID_MPEG_VIDEO_HEVC_SPS (V4L2_CID_MPEG_BASE + 1008)
+#define V4L2_CID_MPEG_VIDEO_HEVC_PPS (V4L2_CID_MPEG_BASE + 1009)
+#define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (V4L2_CID_MPEG_BASE + 1010)
+#define V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX (V4L2_CID_MPEG_BASE + 1011)
+
+/* enum v4l2_ctrl_type type values */
+#define V4L2_CTRL_TYPE_HEVC_SPS 0x0115
+#define V4L2_CTRL_TYPE_HEVC_PPS 0x0116
+#define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0117
+#define V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX 0x0118
+#define V4L2_CTRL_TYPE_HEVC_SPS 0x0120
+#define V4L2_CTRL_TYPE_HEVC_PPS 0x0121
+#define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122
+#define V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX 0x0123
+
+#define V4L2_HEVC_SLICE_TYPE_B 0
+#define V4L2_HEVC_SLICE_TYPE_P 1
+#define V4L2_HEVC_SLICE_TYPE_I 2
+
+/* The controls are not stable at the moment and will likely be reworked. */
+struct v4l2_ctrl_hevc_sps {
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */
+ __u8 chroma_format_idc;
@ -506,7 +540,7 @@ index 0000000000..6601455b3d
+
+#endif
diff --git a/libavcodec/v4l2_request_h264.c b/libavcodec/v4l2_request_h264.c
index a5c56d81c3..a5dbc08a8d 100644
index 3687325fad..2145a974eb 100644
--- a/libavcodec/v4l2_request_h264.c
+++ b/libavcodec/v4l2_request_h264.c
@@ -19,6 +19,7 @@
@ -518,7 +552,7 @@ index a5c56d81c3..a5dbc08a8d 100644
typedef struct V4L2RequestControlsH264 {
struct v4l2_ctrl_h264_sps sps;
diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c
index 300c1866ce..7c7948cfbf 100644
index 38969d77fb..b73eb2ab03 100644
--- a/libavcodec/v4l2_request_hevc.c
+++ b/libavcodec/v4l2_request_hevc.c
@@ -19,6 +19,7 @@