mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-24 11:16:51 +00:00
ffmpeg: Add request api support
This commit is contained in:
parent
9875ed1595
commit
421cc1272c
@ -44,6 +44,13 @@ else
|
||||
PKG_FFMPEG_RKMPP="--disable-rkmpp"
|
||||
fi
|
||||
|
||||
if [ "$PROJECT" = "Allwinner" ]; then
|
||||
PKG_DEPENDS_TARGET="$PKG_DEPENDS_TARGET libdrm systemd" # systemd is needed for libudev
|
||||
PKG_FFMPEG_V4L2_REQUEST="--enable-v4l2-request --enable-libudev --enable-libdrm"
|
||||
else
|
||||
PKG_FFMPEG_V4L2_REQUEST="--disable-v4l2-request --disable-libudev"
|
||||
fi
|
||||
|
||||
if build_with_debug; then
|
||||
PKG_FFMPEG_DEBUG="--enable-debug --disable-stripping"
|
||||
else
|
||||
@ -138,6 +145,7 @@ configure_target() {
|
||||
$PKG_FFMPEG_VDPAU \
|
||||
$PKG_FFMPEG_RPI \
|
||||
$PKG_FFMPEG_RKMPP \
|
||||
$PKG_FFMPEG_V4L2_REQUEST \
|
||||
--enable-runtime-cpudetect \
|
||||
--disable-hardcoded-tables \
|
||||
--disable-encoders \
|
||||
|
@ -0,0 +1,54 @@
|
||||
From 7ab07a6b9a8ac8a91213bcbba4a63dc9db03cb53 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Karlman <jonas@kwiboo.se>
|
||||
Date: Mon, 3 Dec 2018 23:48:04 +0100
|
||||
Subject: [PATCH 1/6] avutil: add av_buffer_pool_reclaim()
|
||||
|
||||
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
|
||||
---
|
||||
libavutil/buffer.c | 13 +++++++++++++
|
||||
libavutil/buffer.h | 5 +++++
|
||||
2 files changed, 18 insertions(+)
|
||||
|
||||
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
|
||||
index 8d1aa5fa84..9c5d530c7a 100644
|
||||
--- a/libavutil/buffer.c
|
||||
+++ b/libavutil/buffer.c
|
||||
@@ -272,6 +272,19 @@ static void buffer_pool_free(AVBufferPool *pool)
|
||||
av_freep(&pool);
|
||||
}
|
||||
|
||||
+void av_buffer_pool_reclaim(AVBufferPool *pool)
|
||||
+{
|
||||
+ ff_mutex_lock(&pool->mutex);
|
||||
+ while (pool->pool) {
|
||||
+ BufferPoolEntry *buf = pool->pool;
|
||||
+ pool->pool = buf->next;
|
||||
+
|
||||
+ buf->free(buf->opaque, buf->data);
|
||||
+ av_freep(&buf);
|
||||
+ }
|
||||
+ ff_mutex_unlock(&pool->mutex);
|
||||
+}
|
||||
+
|
||||
void av_buffer_pool_uninit(AVBufferPool **ppool)
|
||||
{
|
||||
AVBufferPool *pool;
|
||||
diff --git a/libavutil/buffer.h b/libavutil/buffer.h
|
||||
index 73b6bd0b14..fab745f853 100644
|
||||
--- a/libavutil/buffer.h
|
||||
+++ b/libavutil/buffer.h
|
||||
@@ -266,6 +266,11 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
|
||||
AVBufferRef* (*alloc)(void *opaque, int size),
|
||||
void (*pool_free)(void *opaque));
|
||||
|
||||
+/**
|
||||
+ * Free all available buffers in a buffer pool.
|
||||
+ */
|
||||
+ void av_buffer_pool_reclaim(AVBufferPool *pool);
|
||||
+
|
||||
/**
|
||||
* Mark the pool as being available for freeing. It will actually be freed only
|
||||
* once all the allocated buffers associated with the pool are released. Thus it
|
||||
--
|
||||
2.21.0
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,247 @@
|
||||
From de3bcf7557503e5d61b43cdc32d0844deab1c295 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
|
||||
|
||||
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
|
||||
---
|
||||
configure | 3 +
|
||||
libavcodec/Makefile | 1 +
|
||||
libavcodec/hwaccels.h | 1 +
|
||||
libavcodec/mpeg12dec.c | 6 ++
|
||||
libavcodec/v4l2_request_mpeg2.c | 154 ++++++++++++++++++++++++++++++++
|
||||
5 files changed, 165 insertions(+)
|
||||
create mode 100644 libavcodec/v4l2_request_mpeg2.c
|
||||
|
||||
diff --git a/configure b/configure
|
||||
index ed587ec05e..c93d67056d 100755
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -2846,6 +2846,8 @@ mpeg2_dxva2_hwaccel_deps="dxva2"
|
||||
mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
|
||||
mpeg2_nvdec_hwaccel_deps="nvdec"
|
||||
mpeg2_nvdec_hwaccel_select="mpeg2video_decoder"
|
||||
+mpeg2_v4l2request_hwaccel_deps="v4l2_request mpeg2_v4l2_request"
|
||||
+mpeg2_v4l2request_hwaccel_select="mpeg2video_decoder"
|
||||
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;"
|
||||
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 mpeg2_v4l2_request linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG2_SLICE;"
|
||||
|
||||
check_header sys/videoio.h
|
||||
test_code cc sys/videoio.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
|
||||
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
|
||||
index 48f6e06545..9b945e3f64 100644
|
||||
--- a/libavcodec/Makefile
|
||||
+++ b/libavcodec/Makefile
|
||||
@@ -871,6 +871,7 @@ OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL) += dxva2_mpeg2.o
|
||||
OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o
|
||||
OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL) += nvdec_mpeg12.o
|
||||
OBJS-$(CONFIG_MPEG2_QSV_HWACCEL) += qsvdec_other.o
|
||||
+OBJS-$(CONFIG_MPEG2_V4L2REQUEST_HWACCEL) += v4l2_request_mpeg2.o
|
||||
OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o
|
||||
OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL) += vdpau_mpeg12.o
|
||||
OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
|
||||
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
|
||||
index 7d73da8676..ef54de2a3b 100644
|
||||
--- a/libavcodec/hwaccels.h
|
||||
+++ b/libavcodec/hwaccels.h
|
||||
@@ -47,6 +47,7 @@ extern const AVHWAccel ff_mpeg2_d3d11va_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_d3d11va2_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_nvdec_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_dxva2_hwaccel;
|
||||
+extern const AVHWAccel ff_mpeg2_v4l2request_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_vaapi_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_vdpau_hwaccel;
|
||||
extern const AVHWAccel ff_mpeg2_videotoolbox_hwaccel;
|
||||
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
|
||||
index 83e537884b..305127bc94 100644
|
||||
--- a/libavcodec/mpeg12dec.c
|
||||
+++ b/libavcodec/mpeg12dec.c
|
||||
@@ -1156,6 +1156,9 @@ static const enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
|
||||
#endif
|
||||
#if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
|
||||
AV_PIX_FMT_VIDEOTOOLBOX,
|
||||
+#endif
|
||||
+#if CONFIG_MPEG2_V4L2REQUEST_HWACCEL
|
||||
+ AV_PIX_FMT_DRM_PRIME,
|
||||
#endif
|
||||
AV_PIX_FMT_YUV420P,
|
||||
AV_PIX_FMT_NONE
|
||||
@@ -2941,6 +2944,9 @@ AVCodec ff_mpeg2video_decoder = {
|
||||
#endif
|
||||
#if CONFIG_MPEG2_XVMC_HWACCEL
|
||||
HWACCEL_XVMC(mpeg2),
|
||||
+#endif
|
||||
+#if CONFIG_MPEG2_V4L2REQUEST_HWACCEL
|
||||
+ HWACCEL_V4L2REQUEST(mpeg2),
|
||||
#endif
|
||||
NULL
|
||||
},
|
||||
diff --git a/libavcodec/v4l2_request_mpeg2.c b/libavcodec/v4l2_request_mpeg2.c
|
||||
new file mode 100644
|
||||
index 0000000000..782b9c2471
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/v4l2_request_mpeg2.c
|
||||
@@ -0,0 +1,154 @@
|
||||
+/*
|
||||
+ * This file is part of FFmpeg.
|
||||
+ *
|
||||
+ * FFmpeg is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * FFmpeg is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with FFmpeg; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ */
|
||||
+
|
||||
+#include "hwaccel.h"
|
||||
+#include "mpegvideo.h"
|
||||
+#include "v4l2_request.h"
|
||||
+
|
||||
+typedef struct V4L2RequestControlsMPEG2 {
|
||||
+ struct v4l2_ctrl_mpeg2_slice_params slice_params;
|
||||
+ struct v4l2_ctrl_mpeg2_quantization quantization;
|
||||
+} V4L2RequestControlsMPEG2;
|
||||
+
|
||||
+static int v4l2_request_mpeg2_start_frame(AVCodecContext *avctx,
|
||||
+ av_unused const uint8_t *buffer,
|
||||
+ av_unused uint32_t size)
|
||||
+{
|
||||
+ const MpegEncContext *s = avctx->priv_data;
|
||||
+ V4L2RequestControlsMPEG2 *controls = s->current_picture_ptr->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)s->current_picture_ptr->f->data[0];
|
||||
+
|
||||
+ controls->slice_params = (struct v4l2_ctrl_mpeg2_slice_params) {
|
||||
+ .bit_size = 0,
|
||||
+ .data_bit_offset = 0,
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */
|
||||
+ .quantiser_scale_code = s->qscale >> 1,
|
||||
+
|
||||
+ .sequence = {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */
|
||||
+ .horizontal_size = s->width,
|
||||
+ .vertical_size = s->height,
|
||||
+ .vbv_buffer_size = req->output.size,
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */
|
||||
+ .profile_and_level_indication = 0,
|
||||
+ .progressive_sequence = s->progressive_sequence,
|
||||
+ .chroma_format = s->chroma_format,
|
||||
+ },
|
||||
+
|
||||
+ .picture = {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */
|
||||
+ .picture_coding_type = s->pict_type,
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */
|
||||
+ .f_code[0][0] = s->mpeg_f_code[0][0],
|
||||
+ .f_code[0][1] = s->mpeg_f_code[0][1],
|
||||
+ .f_code[1][0] = s->mpeg_f_code[1][0],
|
||||
+ .f_code[1][1] = s->mpeg_f_code[1][1],
|
||||
+ .intra_dc_precision = s->intra_dc_precision,
|
||||
+ .picture_structure = s->picture_structure,
|
||||
+ .top_field_first = s->top_field_first,
|
||||
+ .frame_pred_frame_dct = s->frame_pred_frame_dct,
|
||||
+ .concealment_motion_vectors = s->concealment_motion_vectors,
|
||||
+ .q_scale_type = s->q_scale_type,
|
||||
+ .intra_vlc_format = s->intra_vlc_format,
|
||||
+ .alternate_scan = s->alternate_scan,
|
||||
+ .repeat_first_field = s->repeat_first_field,
|
||||
+ .progressive_frame = s->progressive_frame,
|
||||
+ },
|
||||
+ };
|
||||
+
|
||||
+ switch (s->pict_type) {
|
||||
+ case AV_PICTURE_TYPE_B:
|
||||
+ controls->slice_params.backward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->next_picture.f);
|
||||
+ // fall-through
|
||||
+ case AV_PICTURE_TYPE_P:
|
||||
+ controls->slice_params.forward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->last_picture.f);
|
||||
+ }
|
||||
+
|
||||
+ controls->quantization = (struct v4l2_ctrl_mpeg2_quantization) {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Quant matrix extension */
|
||||
+ .load_intra_quantiser_matrix = 1,
|
||||
+ .load_non_intra_quantiser_matrix = 1,
|
||||
+ .load_chroma_intra_quantiser_matrix = 1,
|
||||
+ .load_chroma_non_intra_quantiser_matrix = 1,
|
||||
+ };
|
||||
+
|
||||
+ for (int i = 0; i < 64; i++) {
|
||||
+ int n = s->idsp.idct_permutation[ff_zigzag_direct[i]];
|
||||
+ controls->quantization.intra_quantiser_matrix[i] = s->intra_matrix[n];
|
||||
+ controls->quantization.non_intra_quantiser_matrix[i] = s->inter_matrix[n];
|
||||
+ controls->quantization.chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[n];
|
||||
+ controls->quantization.chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[n];
|
||||
+ }
|
||||
+
|
||||
+ return ff_v4l2_request_reset_frame(avctx, s->current_picture_ptr->f);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
|
||||
+{
|
||||
+ const MpegEncContext *s = avctx->priv_data;
|
||||
+
|
||||
+ return ff_v4l2_request_append_output_buffer(avctx, s->current_picture_ptr->f, buffer, size);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_mpeg2_end_frame(AVCodecContext *avctx)
|
||||
+{
|
||||
+ const MpegEncContext *s = avctx->priv_data;
|
||||
+ V4L2RequestControlsMPEG2 *controls = s->current_picture_ptr->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)s->current_picture_ptr->f->data[0];
|
||||
+
|
||||
+ struct v4l2_ext_control control[] = {
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS,
|
||||
+ .ptr = &controls->slice_params,
|
||||
+ .size = sizeof(controls->slice_params),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION,
|
||||
+ .ptr = &controls->quantization,
|
||||
+ .size = sizeof(controls->quantization),
|
||||
+ },
|
||||
+ };
|
||||
+
|
||||
+ controls->slice_params.bit_size = req->output.used * 8;
|
||||
+
|
||||
+ return ff_v4l2_request_decode_frame(avctx, s->current_picture_ptr->f, control, FF_ARRAY_ELEMS(control));
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_mpeg2_init(AVCodecContext *avctx)
|
||||
+{
|
||||
+ return ff_v4l2_request_init(avctx, V4L2_PIX_FMT_MPEG2_SLICE, 1024 * 1024, NULL, 0);
|
||||
+}
|
||||
+
|
||||
+const AVHWAccel ff_mpeg2_v4l2request_hwaccel = {
|
||||
+ .name = "mpeg2_v4l2request",
|
||||
+ .type = AVMEDIA_TYPE_VIDEO,
|
||||
+ .id = AV_CODEC_ID_MPEG2VIDEO,
|
||||
+ .pix_fmt = AV_PIX_FMT_DRM_PRIME,
|
||||
+ .start_frame = v4l2_request_mpeg2_start_frame,
|
||||
+ .decode_slice = v4l2_request_mpeg2_decode_slice,
|
||||
+ .end_frame = v4l2_request_mpeg2_end_frame,
|
||||
+ .frame_priv_data_size = sizeof(V4L2RequestControlsMPEG2),
|
||||
+ .init = v4l2_request_mpeg2_init,
|
||||
+ .uninit = ff_v4l2_request_uninit,
|
||||
+ .priv_data_size = sizeof(V4L2RequestContext),
|
||||
+ .frame_params = ff_v4l2_request_frame_params,
|
||||
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
|
||||
+};
|
||||
--
|
||||
2.21.0
|
||||
|
@ -0,0 +1,475 @@
|
||||
From bc1ed76cbc2dad2ec308801552e2398fc2de0a07 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
|
||||
|
||||
Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
|
||||
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
|
||||
---
|
||||
configure | 3 +
|
||||
libavcodec/Makefile | 1 +
|
||||
libavcodec/h264_slice.c | 4 +
|
||||
libavcodec/h264dec.c | 3 +
|
||||
libavcodec/hwaccels.h | 1 +
|
||||
libavcodec/v4l2_request_h264.c | 368 +++++++++++++++++++++++++++++++++
|
||||
6 files changed, 380 insertions(+)
|
||||
create mode 100644 libavcodec/v4l2_request_h264.c
|
||||
|
||||
diff --git a/configure b/configure
|
||||
index c93d67056d..296ca78ce7 100755
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -2804,6 +2804,8 @@ 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_select="h264_decoder"
|
||||
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;"
|
||||
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;"
|
||||
check_cc mpeg2_v4l2_request linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG2_SLICE;"
|
||||
|
||||
check_header sys/videoio.h
|
||||
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
|
||||
index 9b945e3f64..2bdfaabb5f 100644
|
||||
--- a/libavcodec/Makefile
|
||||
+++ b/libavcodec/Makefile
|
||||
@@ -852,6 +852,7 @@ OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o
|
||||
OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
|
||||
OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
|
||||
OBJS-$(CONFIG_H264_QSV_HWACCEL) += qsvdec_h2645.o
|
||||
+OBJS-$(CONFIG_H264_V4L2REQUEST_HWACCEL) += v4l2_request_h264.o
|
||||
OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
|
||||
OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o
|
||||
OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
|
||||
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
|
||||
index f78f9f87b0..688d6c4ac2 100644
|
||||
--- a/libavcodec/h264_slice.c
|
||||
+++ b/libavcodec/h264_slice.c
|
||||
@@ -758,6 +758,7 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
|
||||
#define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
|
||||
(CONFIG_H264_D3D11VA_HWACCEL * 2) + \
|
||||
CONFIG_H264_NVDEC_HWACCEL + \
|
||||
+ CONFIG_H264_V4L2REQUEST_HWACCEL + \
|
||||
CONFIG_H264_VAAPI_HWACCEL + \
|
||||
CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
|
||||
CONFIG_H264_VDPAU_HWACCEL)
|
||||
@@ -842,6 +843,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
|
||||
#endif
|
||||
#if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
|
||||
*fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
|
||||
+#endif
|
||||
+#if CONFIG_H264_V4L2REQUEST_HWACCEL
|
||||
+ *fmt++ = AV_PIX_FMT_DRM_PRIME;
|
||||
#endif
|
||||
if (h->avctx->codec->pix_fmts)
|
||||
choices = h->avctx->codec->pix_fmts;
|
||||
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
|
||||
index 33e1056d87..3ccfa60621 100644
|
||||
--- a/libavcodec/h264dec.c
|
||||
+++ b/libavcodec/h264dec.c
|
||||
@@ -1078,6 +1078,9 @@ AVCodec ff_h264_decoder = {
|
||||
#endif
|
||||
#if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
|
||||
HWACCEL_VIDEOTOOLBOX(h264),
|
||||
+#endif
|
||||
+#if CONFIG_H264_V4L2REQUEST_HWACCEL
|
||||
+ HWACCEL_V4L2REQUEST(h264),
|
||||
#endif
|
||||
NULL
|
||||
},
|
||||
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
|
||||
index ef54de2a3b..003200edea 100644
|
||||
--- a/libavcodec/hwaccels.h
|
||||
+++ b/libavcodec/hwaccels.h
|
||||
@@ -27,6 +27,7 @@ extern const AVHWAccel ff_h264_d3d11va_hwaccel;
|
||||
extern const AVHWAccel ff_h264_d3d11va2_hwaccel;
|
||||
extern const AVHWAccel ff_h264_dxva2_hwaccel;
|
||||
extern const AVHWAccel ff_h264_nvdec_hwaccel;
|
||||
+extern const AVHWAccel ff_h264_v4l2request_hwaccel;
|
||||
extern const AVHWAccel ff_h264_vaapi_hwaccel;
|
||||
extern const AVHWAccel ff_h264_vdpau_hwaccel;
|
||||
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
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/v4l2_request_h264.c
|
||||
@@ -0,0 +1,368 @@
|
||||
+/*
|
||||
+ * This file is part of FFmpeg.
|
||||
+ *
|
||||
+ * FFmpeg is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * FFmpeg is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with FFmpeg; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ */
|
||||
+
|
||||
+#include "h264dec.h"
|
||||
+#include "hwaccel.h"
|
||||
+#include "v4l2_request.h"
|
||||
+
|
||||
+typedef struct V4L2RequestControlsH264 {
|
||||
+ struct v4l2_ctrl_h264_sps sps;
|
||||
+ struct v4l2_ctrl_h264_pps pps;
|
||||
+ struct v4l2_ctrl_h264_scaling_matrix scaling_matrix;
|
||||
+ struct v4l2_ctrl_h264_decode_params decode_params;
|
||||
+ struct v4l2_ctrl_h264_slice_params slice_params;
|
||||
+} V4L2RequestControlsH264;
|
||||
+
|
||||
+static void fill_weight_factors(struct v4l2_h264_weight_factors *factors, int list, const H264SliceContext *sl)
|
||||
+{
|
||||
+ for (int i = 0; i < sl->ref_count[list]; i++) {
|
||||
+ if (sl->pwt.luma_weight_flag[list]) {
|
||||
+ factors->luma_weight[i] = sl->pwt.luma_weight[i][list][0];
|
||||
+ factors->luma_offset[i] = sl->pwt.luma_weight[i][list][1];
|
||||
+ } else {
|
||||
+ factors->luma_weight[i] = 1 << sl->pwt.luma_log2_weight_denom;
|
||||
+ factors->luma_offset[i] = 0;
|
||||
+ }
|
||||
+ for (int j = 0; j < 2; j++) {
|
||||
+ if (sl->pwt.chroma_weight_flag[list]) {
|
||||
+ factors->chroma_weight[i][j] = sl->pwt.chroma_weight[i][list][j][0];
|
||||
+ factors->chroma_offset[i][j] = sl->pwt.chroma_weight[i][list][j][1];
|
||||
+ } else {
|
||||
+ factors->chroma_weight[i][j] = 1 << sl->pwt.chroma_log2_weight_denom;
|
||||
+ factors->chroma_offset[i][j] = 0;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void fill_dpb_entry(struct v4l2_h264_dpb_entry *entry, const H264Picture *pic)
|
||||
+{
|
||||
+ entry->reference_ts = ff_v4l2_request_get_capture_timestamp(pic->f);
|
||||
+ entry->frame_num = pic->frame_num;
|
||||
+ entry->pic_num = pic->pic_id;
|
||||
+ entry->flags = V4L2_H264_DPB_ENTRY_FLAG_VALID;
|
||||
+ if (pic->reference)
|
||||
+ 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];
|
||||
+}
|
||||
+
|
||||
+static void fill_dpb(struct v4l2_ctrl_h264_decode_params *decode, const H264Context *h)
|
||||
+{
|
||||
+ int entries = 0;
|
||||
+
|
||||
+ for (int i = 0; i < h->short_ref_count; i++) {
|
||||
+ const H264Picture *pic = h->short_ref[i];
|
||||
+ if (pic)
|
||||
+ fill_dpb_entry(&decode->dpb[entries++], pic);
|
||||
+ }
|
||||
+
|
||||
+ if (!h->long_ref_count)
|
||||
+ return;
|
||||
+
|
||||
+ for (int i = 0; i < FF_ARRAY_ELEMS(h->long_ref); i++) {
|
||||
+ const H264Picture *pic = h->long_ref[i];
|
||||
+ if (pic)
|
||||
+ fill_dpb_entry(&decode->dpb[entries++], pic);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static uint8_t get_dpb_index(struct v4l2_ctrl_h264_decode_params *decode, const H264Ref *ref)
|
||||
+{
|
||||
+ uint64_t timestamp;
|
||||
+
|
||||
+ if (!ref->parent)
|
||||
+ return 0;
|
||||
+
|
||||
+ timestamp = ff_v4l2_request_get_capture_timestamp(ref->parent->f);
|
||||
+
|
||||
+ for (uint8_t i = 0; i < FF_ARRAY_ELEMS(decode->dpb); i++) {
|
||||
+ struct v4l2_h264_dpb_entry *entry = &decode->dpb[i];
|
||||
+ if ((entry->flags & V4L2_H264_DPB_ENTRY_FLAG_VALID) &&
|
||||
+ entry->reference_ts == timestamp)
|
||||
+ // TODO: signal reference type, possible using top 2 bits
|
||||
+ return i | ((ref->reference & 3) << 6);
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void fill_sps(struct v4l2_ctrl_h264_sps *ctrl, const H264Context *h)
|
||||
+{
|
||||
+ const SPS *sps = h->ps.sps;
|
||||
+
|
||||
+ *ctrl = (struct v4l2_ctrl_h264_sps) {
|
||||
+ .profile_idc = sps->profile_idc,
|
||||
+ .constraint_set_flags = sps->constraint_set_flags,
|
||||
+ .level_idc = sps->level_idc,
|
||||
+ .seq_parameter_set_id = sps->sps_id,
|
||||
+ .chroma_format_idc = sps->chroma_format_idc,
|
||||
+ .bit_depth_luma_minus8 = sps->bit_depth_luma - 8,
|
||||
+ .bit_depth_chroma_minus8 = sps->bit_depth_chroma - 8,
|
||||
+ .log2_max_frame_num_minus4 = sps->log2_max_frame_num - 4,
|
||||
+ .pic_order_cnt_type = sps->poc_type,
|
||||
+ .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4,
|
||||
+ .max_num_ref_frames = sps->ref_frame_count,
|
||||
+ .num_ref_frames_in_pic_order_cnt_cycle = sps->poc_cycle_length,
|
||||
+ //.offset_for_ref_frame[255] - not required? not set by libva-v4l2-request - copy sps->offset_for_ref_frame
|
||||
+ .offset_for_non_ref_pic = sps->offset_for_non_ref_pic,
|
||||
+ .offset_for_top_to_bottom_field = sps->offset_for_top_to_bottom_field,
|
||||
+ .pic_width_in_mbs_minus1 = h->mb_width - 1,
|
||||
+ .pic_height_in_map_units_minus1 = sps->frame_mbs_only_flag ? h->mb_height - 1 : h->mb_height / 2 - 1,
|
||||
+ };
|
||||
+
|
||||
+ if (sps->residual_color_transform_flag)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE;
|
||||
+ if (sps->transform_bypass)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS;
|
||||
+ if (sps->delta_pic_order_always_zero_flag)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO;
|
||||
+ if (sps->gaps_in_frame_num_allowed_flag)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED;
|
||||
+ if (sps->frame_mbs_only_flag)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY;
|
||||
+ if (sps->mb_aff)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD;
|
||||
+ if (sps->direct_8x8_inference_flag)
|
||||
+ ctrl->flags |= V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE;
|
||||
+}
|
||||
+
|
||||
+static void fill_pps(struct v4l2_ctrl_h264_pps *ctrl, const H264Context *h)
|
||||
+{
|
||||
+ const PPS *pps = h->ps.pps;
|
||||
+ const H264SliceContext *sl = &h->slice_ctx[0];
|
||||
+
|
||||
+ *ctrl = (struct v4l2_ctrl_h264_pps) {
|
||||
+ .pic_parameter_set_id = sl->pps_id,
|
||||
+ .seq_parameter_set_id = pps->sps_id,
|
||||
+ .num_slice_groups_minus1 = pps->slice_group_count - 1,
|
||||
+ .num_ref_idx_l0_default_active_minus1 = pps->ref_count[0] - 1,
|
||||
+ .num_ref_idx_l1_default_active_minus1 = pps->ref_count[1] - 1,
|
||||
+ .weighted_bipred_idc = pps->weighted_bipred_idc,
|
||||
+ .pic_init_qp_minus26 = pps->init_qp - 26,
|
||||
+ .pic_init_qs_minus26 = pps->init_qs - 26,
|
||||
+ .chroma_qp_index_offset = pps->chroma_qp_index_offset[0],
|
||||
+ .second_chroma_qp_index_offset = pps->chroma_qp_index_offset[1],
|
||||
+ };
|
||||
+
|
||||
+ if (pps->cabac)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE;
|
||||
+ if (pps->pic_order_present)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT;
|
||||
+ if (pps->weighted_pred)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_WEIGHTED_PRED;
|
||||
+ if (pps->deblocking_filter_parameters_present)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT;
|
||||
+ if (pps->constrained_intra_pred)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED;
|
||||
+ if (pps->redundant_pic_cnt_present)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT;
|
||||
+ if (pps->transform_8x8_mode)
|
||||
+ ctrl->flags |= V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE;
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_h264_start_frame(AVCodecContext *avctx,
|
||||
+ av_unused const uint8_t *buffer,
|
||||
+ av_unused uint32_t size)
|
||||
+{
|
||||
+ const H264Context *h = avctx->priv_data;
|
||||
+ const PPS *pps = h->ps.pps;
|
||||
+ V4L2RequestControlsH264 *controls = h->cur_pic_ptr->hwaccel_picture_private;
|
||||
+
|
||||
+ fill_sps(&controls->sps, h);
|
||||
+ fill_pps(&controls->pps, h);
|
||||
+
|
||||
+ memcpy(controls->scaling_matrix.scaling_list_4x4, pps->scaling_matrix4, sizeof(controls->scaling_matrix.scaling_list_4x4));
|
||||
+ memcpy(controls->scaling_matrix.scaling_list_8x8, pps->scaling_matrix8, sizeof(controls->scaling_matrix.scaling_list_8x8));
|
||||
+
|
||||
+ 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],
|
||||
+ };
|
||||
+
|
||||
+ if (h->picture_idr)
|
||||
+ controls->decode_params.flags |= V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC;
|
||||
+
|
||||
+ fill_dpb(&controls->decode_params, h);
|
||||
+
|
||||
+ return ff_v4l2_request_reset_frame(avctx, h->cur_pic_ptr->f);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_h264_end_frame(AVCodecContext *avctx)
|
||||
+{
|
||||
+ const H264Context *h = avctx->priv_data;
|
||||
+ V4L2RequestControlsH264 *controls = h->cur_pic_ptr->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)h->cur_pic_ptr->f->data[0];
|
||||
+
|
||||
+ struct v4l2_ext_control control[] = {
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_SPS,
|
||||
+ .ptr = &controls->sps,
|
||||
+ .size = sizeof(controls->sps),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_PPS,
|
||||
+ .ptr = &controls->pps,
|
||||
+ .size = sizeof(controls->pps),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX,
|
||||
+ .ptr = &controls->scaling_matrix,
|
||||
+ .size = sizeof(controls->scaling_matrix),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS,
|
||||
+ .ptr = &controls->slice_params,
|
||||
+ .size = sizeof(controls->slice_params),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS,
|
||||
+ .ptr = &controls->decode_params,
|
||||
+ .size = sizeof(controls->decode_params),
|
||||
+ },
|
||||
+ };
|
||||
+
|
||||
+ controls->slice_params.size = req->output.used;
|
||||
+
|
||||
+ return ff_v4l2_request_decode_frame(avctx, h->cur_pic_ptr->f, control, FF_ARRAY_ELEMS(control));
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
|
||||
+{
|
||||
+ const H264Context *h = avctx->priv_data;
|
||||
+ const PPS *pps = h->ps.pps;
|
||||
+ const H264SliceContext *sl = &h->slice_ctx[0];
|
||||
+ V4L2RequestControlsH264 *controls = h->cur_pic_ptr->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)h->cur_pic_ptr->f->data[0];
|
||||
+ int i, count;
|
||||
+
|
||||
+ // HACK: trigger decode per slice
|
||||
+ if (req->output.used) {
|
||||
+ v4l2_request_h264_end_frame(avctx);
|
||||
+ ff_v4l2_request_reset_frame(avctx, h->cur_pic_ptr->f);
|
||||
+ }
|
||||
+
|
||||
+ controls->decode_params.num_slices++;
|
||||
+
|
||||
+ controls->slice_params = (struct v4l2_ctrl_h264_slice_params) {
|
||||
+ /* Size in bytes, including header */
|
||||
+ .size = 0,
|
||||
+ /* Offset in bits to slice_data() from the beginning of this slice. */
|
||||
+ .header_bit_size = get_bits_count(&sl->gb),
|
||||
+
|
||||
+ .first_mb_in_slice = sl->first_mb_addr,
|
||||
+ .slice_type = ff_h264_get_slice_type(sl),
|
||||
+ .pic_parameter_set_id = sl->pps_id,
|
||||
+ .colour_plane_id = 0, /* what is this? */
|
||||
+ .frame_num = h->poc.frame_num,
|
||||
+ .idr_pic_id = 0, /* what is this? */
|
||||
+ .pic_order_cnt_lsb = sl->poc_lsb,
|
||||
+ .delta_pic_order_cnt_bottom = sl->delta_poc_bottom,
|
||||
+ .delta_pic_order_cnt0 = sl->delta_poc[0],
|
||||
+ .delta_pic_order_cnt1 = sl->delta_poc[1],
|
||||
+ .redundant_pic_cnt = sl->redundant_pic_count,
|
||||
+
|
||||
+ /* Size in bits of dec_ref_pic_marking() syntax element. */
|
||||
+ .dec_ref_pic_marking_bit_size = 0,
|
||||
+ /* Size in bits of pic order count syntax. */
|
||||
+ .pic_order_cnt_bit_size = 0,
|
||||
+
|
||||
+ .cabac_init_idc = sl->cabac_init_idc,
|
||||
+ .slice_qp_delta = sl->qscale - pps->init_qp,
|
||||
+ .slice_qs_delta = 0, /* XXX not implemented by FFmpeg */
|
||||
+ .disable_deblocking_filter_idc = sl->deblocking_filter < 2 ? !sl->deblocking_filter : sl->deblocking_filter,
|
||||
+ .slice_alpha_c0_offset_div2 = sl->slice_alpha_c0_offset / 2,
|
||||
+ .slice_beta_offset_div2 = sl->slice_beta_offset / 2,
|
||||
+ .slice_group_change_cycle = 0, /* what is this? */
|
||||
+
|
||||
+ .num_ref_idx_l0_active_minus1 = sl->list_count > 0 ? sl->ref_count[0] - 1 : 0,
|
||||
+ .num_ref_idx_l1_active_minus1 = sl->list_count > 1 ? sl->ref_count[1] - 1 : 0,
|
||||
+ };
|
||||
+
|
||||
+ if (FIELD_PICTURE(h))
|
||||
+ controls->slice_params.flags |= V4L2_H264_SLICE_FLAG_FIELD_PIC;
|
||||
+ if (h->picture_structure == PICT_BOTTOM_FIELD)
|
||||
+ controls->slice_params.flags |= V4L2_H264_SLICE_FLAG_BOTTOM_FIELD;
|
||||
+ if (sl->slice_type == AV_PICTURE_TYPE_B && sl->direct_spatial_mv_pred)
|
||||
+ controls->slice_params.flags |= V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED;
|
||||
+
|
||||
+ controls->slice_params.pred_weight_table.chroma_log2_weight_denom = sl->pwt.chroma_log2_weight_denom;
|
||||
+ controls->slice_params.pred_weight_table.luma_log2_weight_denom = sl->pwt.luma_log2_weight_denom;
|
||||
+
|
||||
+ count = sl->list_count > 0 ? sl->ref_count[0] : 0;
|
||||
+ for (i = 0; i < count; i++)
|
||||
+ controls->slice_params.ref_pic_list0[i] = get_dpb_index(&controls->decode_params, &sl->ref_list[0][i]);
|
||||
+ if (count)
|
||||
+ fill_weight_factors(&controls->slice_params.pred_weight_table.weight_factors[0], 0, sl);
|
||||
+
|
||||
+ count = sl->list_count > 1 ? sl->ref_count[1] : 0;
|
||||
+ for (i = 0; i < count; i++)
|
||||
+ controls->slice_params.ref_pic_list1[i] = get_dpb_index(&controls->decode_params, &sl->ref_list[1][i]);
|
||||
+ if (count)
|
||||
+ fill_weight_factors(&controls->slice_params.pred_weight_table.weight_factors[1], 1, sl);
|
||||
+
|
||||
+ return ff_v4l2_request_append_output_buffer(avctx, h->cur_pic_ptr->f, buffer, size);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_h264_init(AVCodecContext *avctx)
|
||||
+{
|
||||
+ const H264Context *h = avctx->priv_data;
|
||||
+ struct v4l2_ctrl_h264_sps sps;
|
||||
+ struct v4l2_ctrl_h264_pps pps;
|
||||
+
|
||||
+ struct v4l2_ext_control control[] = {
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_SPS,
|
||||
+ .ptr = &sps,
|
||||
+ .size = sizeof(sps),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_H264_PPS,
|
||||
+ .ptr = &pps,
|
||||
+ .size = sizeof(pps),
|
||||
+ },
|
||||
+ };
|
||||
+
|
||||
+ fill_sps(&sps, h);
|
||||
+ fill_pps(&pps, h);
|
||||
+
|
||||
+ return ff_v4l2_request_init(avctx, V4L2_PIX_FMT_H264_SLICE_RAW, 2 * 1024 * 1024, control, FF_ARRAY_ELEMS(control));
|
||||
+}
|
||||
+
|
||||
+const AVHWAccel ff_h264_v4l2request_hwaccel = {
|
||||
+ .name = "h264_v4l2request",
|
||||
+ .type = AVMEDIA_TYPE_VIDEO,
|
||||
+ .id = AV_CODEC_ID_H264,
|
||||
+ .pix_fmt = AV_PIX_FMT_DRM_PRIME,
|
||||
+ .start_frame = v4l2_request_h264_start_frame,
|
||||
+ .decode_slice = v4l2_request_h264_decode_slice,
|
||||
+ .end_frame = v4l2_request_h264_end_frame,
|
||||
+ .frame_priv_data_size = sizeof(V4L2RequestControlsH264),
|
||||
+ .init = v4l2_request_h264_init,
|
||||
+ .uninit = ff_v4l2_request_uninit,
|
||||
+ .priv_data_size = sizeof(V4L2RequestContext),
|
||||
+ .frame_params = ff_v4l2_request_frame_params,
|
||||
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
|
||||
+};
|
||||
--
|
||||
2.21.0
|
||||
|
@ -0,0 +1,503 @@
|
||||
From 25065e4e219c6bd688e6b62e40be74f1cfa08e72 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
|
||||
|
||||
Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
|
||||
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
|
||||
---
|
||||
configure | 3 +
|
||||
libavcodec/Makefile | 1 +
|
||||
libavcodec/hevcdec.c | 10 +
|
||||
libavcodec/hwaccels.h | 1 +
|
||||
libavcodec/v4l2_request_hevc.c | 391 +++++++++++++++++++++++++++++++++
|
||||
5 files changed, 406 insertions(+)
|
||||
create mode 100644 libavcodec/v4l2_request_hevc.c
|
||||
|
||||
diff --git a/configure b/configure
|
||||
index 296ca78ce7..9252ca5794 100755
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -2820,6 +2820,8 @@ 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_select="hevc_decoder"
|
||||
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;"
|
||||
|
||||
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;"
|
||||
+check_cc hevc_v4l2_request linux/videodev2.h "int i = V4L2_PIX_FMT_HEVC_SLICE;"
|
||||
check_cc mpeg2_v4l2_request linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG2_SLICE;"
|
||||
|
||||
check_header sys/videoio.h
|
||||
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
|
||||
index 2bdfaabb5f..a4c959e0f5 100644
|
||||
--- a/libavcodec/Makefile
|
||||
+++ b/libavcodec/Makefile
|
||||
@@ -860,6 +860,7 @@ OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL) += dxva2_hevc.o
|
||||
OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
|
||||
OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
|
||||
OBJS-$(CONFIG_HEVC_QSV_HWACCEL) += qsvdec_h2645.o
|
||||
+OBJS-$(CONFIG_HEVC_V4L2REQUEST_HWACCEL) += v4l2_request_hevc.o
|
||||
OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o
|
||||
OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL) += vdpau_hevc.o
|
||||
OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL) += nvdec_mjpeg.o
|
||||
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
|
||||
index c8877626d2..df33433150 100644
|
||||
--- a/libavcodec/hevcdec.c
|
||||
+++ b/libavcodec/hevcdec.c
|
||||
@@ -362,6 +362,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
|
||||
#define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
|
||||
CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
|
||||
CONFIG_HEVC_NVDEC_HWACCEL + \
|
||||
+ CONFIG_HEVC_V4L2REQUEST_HWACCEL + \
|
||||
CONFIG_HEVC_VAAPI_HWACCEL + \
|
||||
CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
|
||||
CONFIG_HEVC_VDPAU_HWACCEL)
|
||||
@@ -388,6 +389,9 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
|
||||
#endif
|
||||
#if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
|
||||
*fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
|
||||
+#endif
|
||||
+#if CONFIG_HEVC_V4L2REQUEST_HWACCEL
|
||||
+ *fmt++ = AV_PIX_FMT_DRM_PRIME;
|
||||
#endif
|
||||
break;
|
||||
case AV_PIX_FMT_YUV420P10:
|
||||
@@ -406,6 +410,9 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
|
||||
#endif
|
||||
#if CONFIG_HEVC_NVDEC_HWACCEL
|
||||
*fmt++ = AV_PIX_FMT_CUDA;
|
||||
+#endif
|
||||
+#if CONFIG_HEVC_V4L2REQUEST_HWACCEL
|
||||
+ *fmt++ = AV_PIX_FMT_DRM_PRIME;
|
||||
#endif
|
||||
break;
|
||||
case AV_PIX_FMT_YUV420P12:
|
||||
@@ -3556,6 +3563,9 @@ AVCodec ff_hevc_decoder = {
|
||||
#endif
|
||||
#if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
|
||||
HWACCEL_VIDEOTOOLBOX(hevc),
|
||||
+#endif
|
||||
+#if CONFIG_HEVC_V4L2REQUEST_HWACCEL
|
||||
+ HWACCEL_V4L2REQUEST(hevc),
|
||||
#endif
|
||||
NULL
|
||||
},
|
||||
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
|
||||
index 003200edea..d183675abe 100644
|
||||
--- a/libavcodec/hwaccels.h
|
||||
+++ b/libavcodec/hwaccels.h
|
||||
@@ -35,6 +35,7 @@ extern const AVHWAccel ff_hevc_d3d11va_hwaccel;
|
||||
extern const AVHWAccel ff_hevc_d3d11va2_hwaccel;
|
||||
extern const AVHWAccel ff_hevc_dxva2_hwaccel;
|
||||
extern const AVHWAccel ff_hevc_nvdec_hwaccel;
|
||||
+extern const AVHWAccel ff_hevc_v4l2request_hwaccel;
|
||||
extern const AVHWAccel ff_hevc_vaapi_hwaccel;
|
||||
extern const AVHWAccel ff_hevc_vdpau_hwaccel;
|
||||
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
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/v4l2_request_hevc.c
|
||||
@@ -0,0 +1,391 @@
|
||||
+/*
|
||||
+ * This file is part of FFmpeg.
|
||||
+ *
|
||||
+ * FFmpeg is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * FFmpeg is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with FFmpeg; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ */
|
||||
+
|
||||
+#include "hevcdec.h"
|
||||
+#include "hwaccel.h"
|
||||
+#include "v4l2_request.h"
|
||||
+
|
||||
+typedef struct V4L2RequestControlsHEVC {
|
||||
+ struct v4l2_ctrl_hevc_sps sps;
|
||||
+ struct v4l2_ctrl_hevc_pps pps;
|
||||
+ struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix;
|
||||
+ struct v4l2_ctrl_hevc_slice_params slice_params;
|
||||
+} V4L2RequestControlsHEVC;
|
||||
+
|
||||
+static void v4l2_request_hevc_fill_pred_table(const HEVCContext *h, struct v4l2_hevc_pred_weight_table *table)
|
||||
+{
|
||||
+ int32_t luma_weight_denom, chroma_weight_denom;
|
||||
+ const SliceHeader *sh = &h->sh;
|
||||
+
|
||||
+ if (sh->slice_type == HEVC_SLICE_I ||
|
||||
+ (sh->slice_type == HEVC_SLICE_P && !h->ps.pps->weighted_pred_flag) ||
|
||||
+ (sh->slice_type == HEVC_SLICE_B && !h->ps.pps->weighted_bipred_flag))
|
||||
+ return;
|
||||
+
|
||||
+ table->luma_log2_weight_denom = sh->luma_log2_weight_denom;
|
||||
+
|
||||
+ if (h->ps.sps->chroma_format_idc)
|
||||
+ table->delta_chroma_log2_weight_denom = sh->chroma_log2_weight_denom - sh->luma_log2_weight_denom;
|
||||
+
|
||||
+ luma_weight_denom = (1 << sh->luma_log2_weight_denom);
|
||||
+ chroma_weight_denom = (1 << sh->chroma_log2_weight_denom);
|
||||
+
|
||||
+ for (int i = 0; i < 15 && i < sh->nb_refs[L0]; i++) {
|
||||
+ table->delta_luma_weight_l0[i] = sh->luma_weight_l0[i] - luma_weight_denom;
|
||||
+ table->luma_offset_l0[i] = sh->luma_offset_l0[i];
|
||||
+ table->delta_chroma_weight_l0[i][0] = sh->chroma_weight_l0[i][0] - chroma_weight_denom;
|
||||
+ table->delta_chroma_weight_l0[i][1] = sh->chroma_weight_l0[i][1] - chroma_weight_denom;
|
||||
+ table->chroma_offset_l0[i][0] = sh->chroma_offset_l0[i][0];
|
||||
+ table->chroma_offset_l0[i][1] = sh->chroma_offset_l0[i][1];
|
||||
+ }
|
||||
+
|
||||
+ if (sh->slice_type != HEVC_SLICE_B)
|
||||
+ return;
|
||||
+
|
||||
+ for (int i = 0; i < 15 && i < sh->nb_refs[L1]; i++) {
|
||||
+ table->delta_luma_weight_l1[i] = sh->luma_weight_l1[i] - luma_weight_denom;
|
||||
+ table->luma_offset_l1[i] = sh->luma_offset_l1[i];
|
||||
+ table->delta_chroma_weight_l1[i][0] = sh->chroma_weight_l1[i][0] - chroma_weight_denom;
|
||||
+ table->delta_chroma_weight_l1[i][1] = sh->chroma_weight_l1[i][1] - chroma_weight_denom;
|
||||
+ table->chroma_offset_l1[i][0] = sh->chroma_offset_l1[i][0];
|
||||
+ table->chroma_offset_l1[i][1] = sh->chroma_offset_l1[i][1];
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static int find_frame_rps_type(const HEVCContext *h, uint64_t timestamp)
|
||||
+{
|
||||
+ const HEVCFrame *frame;
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) {
|
||||
+ frame = h->rps[ST_CURR_BEF].ref[i];
|
||||
+ if (frame && timestamp == ff_v4l2_request_get_capture_timestamp(frame->frame))
|
||||
+ return V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_BEFORE;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < h->rps[ST_CURR_AFT].nb_refs; i++) {
|
||||
+ frame = h->rps[ST_CURR_AFT].ref[i];
|
||||
+ if (frame && timestamp == ff_v4l2_request_get_capture_timestamp(frame->frame))
|
||||
+ return V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_AFTER;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < h->rps[LT_CURR].nb_refs; i++) {
|
||||
+ frame = h->rps[LT_CURR].ref[i];
|
||||
+ if (frame && timestamp == ff_v4l2_request_get_capture_timestamp(frame->frame))
|
||||
+ return V4L2_HEVC_DPB_ENTRY_RPS_LT_CURR;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static uint8_t get_ref_pic_index(const HEVCContext *h, const HEVCFrame *frame,
|
||||
+ struct v4l2_ctrl_hevc_slice_params *slice_params)
|
||||
+{
|
||||
+ uint64_t timestamp;
|
||||
+
|
||||
+ if (!frame)
|
||||
+ return 0;
|
||||
+
|
||||
+ timestamp = ff_v4l2_request_get_capture_timestamp(frame->frame);
|
||||
+
|
||||
+ for (uint8_t i = 0; i < slice_params->num_active_dpb_entries; i++) {
|
||||
+ struct v4l2_hevc_dpb_entry *entry = &slice_params->dpb[i];
|
||||
+ if (entry->timestamp == timestamp)
|
||||
+ return i;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h,
|
||||
+ struct v4l2_ctrl_hevc_slice_params *slice_params)
|
||||
+{
|
||||
+ const HEVCFrame *pic = h->ref;
|
||||
+ const SliceHeader *sh = &h->sh;
|
||||
+ int i, entries = 0;
|
||||
+ RefPicList *rpl;
|
||||
+
|
||||
+ *slice_params = (struct v4l2_ctrl_hevc_slice_params) {
|
||||
+ .bit_size = 0,
|
||||
+ .data_bit_offset = get_bits_count(&h->HEVClc->gb),
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */
|
||||
+ .nal_unit_type = h->nal_unit_type,
|
||||
+ .nuh_temporal_id_plus1 = h->temporal_id + 1,
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
|
||||
+ .slice_type = sh->slice_type,
|
||||
+ .colour_plane_id = sh->colour_plane_id,
|
||||
+ .slice_pic_order_cnt = pic->poc,
|
||||
+ .slice_sao_luma_flag = sh->slice_sample_adaptive_offset_flag[0],
|
||||
+ .slice_sao_chroma_flag = sh->slice_sample_adaptive_offset_flag[1],
|
||||
+ .slice_temporal_mvp_enabled_flag = sh->slice_temporal_mvp_enabled_flag,
|
||||
+ .num_ref_idx_l0_active_minus1 = sh->nb_refs[L0] ? sh->nb_refs[L0] - 1 : 0,
|
||||
+ .num_ref_idx_l1_active_minus1 = sh->nb_refs[L1] ? sh->nb_refs[L1] - 1 : 0,
|
||||
+ .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
|
||||
+ .cabac_init_flag = sh->cabac_init_flag,
|
||||
+ .collocated_from_l0_flag = sh->collocated_list == L0 ? 1 : 0,
|
||||
+ .collocated_ref_idx = sh->slice_temporal_mvp_enabled_flag ? sh->collocated_ref_idx : 0,
|
||||
+ .five_minus_max_num_merge_cand = sh->slice_type == HEVC_SLICE_I ? 0 : 5 - sh->max_num_merge_cand,
|
||||
+ .use_integer_mv_flag = 0,
|
||||
+ .slice_qp_delta = sh->slice_qp_delta,
|
||||
+ .slice_cb_qp_offset = sh->slice_cb_qp_offset,
|
||||
+ .slice_cr_qp_offset = sh->slice_cr_qp_offset,
|
||||
+ .slice_act_y_qp_offset = 0,
|
||||
+ .slice_act_cb_qp_offset = 0,
|
||||
+ .slice_act_cr_qp_offset = 0,
|
||||
+ .slice_deblocking_filter_disabled_flag = sh->disable_deblocking_filter_flag,
|
||||
+ .slice_beta_offset_div2 = sh->beta_offset / 2,
|
||||
+ .slice_tc_offset_div2 = sh->tc_offset / 2,
|
||||
+ .slice_loop_filter_across_slices_enabled_flag = sh->slice_loop_filter_across_slices_enabled_flag,
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */
|
||||
+ .pic_struct = h->sei.picture_timing.picture_struct,
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
|
||||
+ .num_rps_poc_st_curr_before = h->rps[ST_CURR_BEF].nb_refs,
|
||||
+ .num_rps_poc_st_curr_after = h->rps[ST_CURR_AFT].nb_refs,
|
||||
+ .num_rps_poc_lt_curr = h->rps[LT_CURR].nb_refs,
|
||||
+
|
||||
+ .slice_segment_addr = sh->slice_segment_addr,
|
||||
+ .first_slice_segment_in_pic_flag = sh->first_slice_in_pic_flag,
|
||||
+ };
|
||||
+
|
||||
+ for (i = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
|
||||
+ const HEVCFrame *frame = &h->DPB[i];
|
||||
+ if (frame != pic && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {
|
||||
+ struct v4l2_hevc_dpb_entry *entry = &slice_params->dpb[entries++];
|
||||
+
|
||||
+ entry->timestamp = ff_v4l2_request_get_capture_timestamp(frame->frame);
|
||||
+ entry->rps = find_frame_rps_type(h, entry->timestamp);
|
||||
+ entry->field_pic = frame->frame->interlaced_frame;
|
||||
+
|
||||
+ /* TODO: Interleaved: Get the POC for each field. */
|
||||
+ entry->pic_order_cnt[0] = frame->poc;
|
||||
+ entry->pic_order_cnt[1] = frame->poc;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ slice_params->num_active_dpb_entries = entries;
|
||||
+
|
||||
+ if (sh->slice_type != HEVC_SLICE_I) {
|
||||
+ rpl = &h->ref->refPicList[0];
|
||||
+ for (i = 0; i < rpl->nb_refs; i++)
|
||||
+ slice_params->ref_idx_l0[i] = get_ref_pic_index(h, rpl->ref[i], slice_params);
|
||||
+ }
|
||||
+
|
||||
+ if (sh->slice_type == HEVC_SLICE_B) {
|
||||
+ rpl = &h->ref->refPicList[1];
|
||||
+ for (i = 0; i < rpl->nb_refs; i++)
|
||||
+ slice_params->ref_idx_l1[i] = get_ref_pic_index(h, rpl->ref[i], slice_params);
|
||||
+ }
|
||||
+
|
||||
+ v4l2_request_hevc_fill_pred_table(h, &slice_params->pred_weight_table);
|
||||
+
|
||||
+ slice_params->num_entry_point_offsets = sh->num_entry_point_offsets;
|
||||
+ if (slice_params->num_entry_point_offsets > 256) {
|
||||
+ slice_params->num_entry_point_offsets = 256;
|
||||
+ av_log(NULL, AV_LOG_ERROR, "%s: Currently only 256 entry points are supported, but slice has %d entry points.\n", __func__, sh->num_entry_point_offsets);
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < slice_params->num_entry_point_offsets; i++)
|
||||
+ slice_params->entry_point_offset_minus1[i] = sh->entry_point_offset[i] - 1;
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_hevc_start_frame(AVCodecContext *avctx,
|
||||
+ av_unused const uint8_t *buffer,
|
||||
+ av_unused uint32_t size)
|
||||
+{
|
||||
+ const HEVCContext *h = avctx->priv_data;
|
||||
+ const HEVCSPS *sps = h->ps.sps;
|
||||
+ const HEVCPPS *pps = h->ps.pps;
|
||||
+ const ScalingList *sl = pps->scaling_list_data_present_flag ?
|
||||
+ &pps->scaling_list :
|
||||
+ sps->scaling_list_enable_flag ?
|
||||
+ &sps->scaling_list : NULL;
|
||||
+ V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */
|
||||
+ controls->sps = (struct v4l2_ctrl_hevc_sps) {
|
||||
+ .chroma_format_idc = sps->chroma_format_idc,
|
||||
+ .separate_colour_plane_flag = sps->separate_colour_plane_flag,
|
||||
+ .pic_width_in_luma_samples = sps->width,
|
||||
+ .pic_height_in_luma_samples = sps->height,
|
||||
+ .bit_depth_luma_minus8 = sps->bit_depth - 8,
|
||||
+ .bit_depth_chroma_minus8 = sps->bit_depth - 8,
|
||||
+ .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4,
|
||||
+ .sps_max_dec_pic_buffering_minus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering - 1,
|
||||
+ .sps_max_num_reorder_pics = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
|
||||
+ .sps_max_latency_increase_plus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_latency_increase + 1,
|
||||
+ .log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3,
|
||||
+ .log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_coding_block_size,
|
||||
+ .log2_min_luma_transform_block_size_minus2 = sps->log2_min_tb_size - 2,
|
||||
+ .log2_diff_max_min_luma_transform_block_size = sps->log2_max_trafo_size - sps->log2_min_tb_size,
|
||||
+ .max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter,
|
||||
+ .max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra,
|
||||
+ .scaling_list_enabled_flag = sps->scaling_list_enable_flag,
|
||||
+ .amp_enabled_flag = sps->amp_enabled_flag,
|
||||
+ .sample_adaptive_offset_enabled_flag = sps->sao_enabled,
|
||||
+ .pcm_enabled_flag = sps->pcm_enabled_flag,
|
||||
+ .pcm_sample_bit_depth_luma_minus1 = sps->pcm.bit_depth - 1,
|
||||
+ .pcm_sample_bit_depth_chroma_minus1 = sps->pcm.bit_depth_chroma - 1,
|
||||
+ .log2_min_pcm_luma_coding_block_size_minus3 = sps->pcm.log2_min_pcm_cb_size - 3,
|
||||
+ .log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size,
|
||||
+ .pcm_loop_filter_disabled_flag = sps->pcm.loop_filter_disable_flag,
|
||||
+ .num_short_term_ref_pic_sets = sps->nb_st_rps,
|
||||
+ .long_term_ref_pics_present_flag = sps->long_term_ref_pics_present_flag,
|
||||
+ .num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps,
|
||||
+ .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
|
||||
+ .strong_intra_smoothing_enabled_flag = sps->sps_strong_intra_smoothing_enable_flag,
|
||||
+ };
|
||||
+
|
||||
+ if (sl) {
|
||||
+ for (int i = 0; i < 6; i++) {
|
||||
+ for (int j = 0; j < 16; j++)
|
||||
+ controls->scaling_matrix.scaling_list_4x4[i][j] = sl->sl[0][i][j];
|
||||
+ for (int j = 0; j < 64; j++) {
|
||||
+ controls->scaling_matrix.scaling_list_8x8[i][j] = sl->sl[1][i][j];
|
||||
+ controls->scaling_matrix.scaling_list_16x16[i][j] = sl->sl[2][i][j];
|
||||
+ if (i < 2)
|
||||
+ controls->scaling_matrix.scaling_list_32x32[i][j] = sl->sl[3][i * 3][j];
|
||||
+ }
|
||||
+ controls->scaling_matrix.scaling_list_dc_coef_16x16[i] = sl->sl_dc[0][i];
|
||||
+ if (i < 2)
|
||||
+ controls->scaling_matrix.scaling_list_dc_coef_32x32[i] = sl->sl_dc[1][i * 3];
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
|
||||
+ controls->pps = (struct v4l2_ctrl_hevc_pps) {
|
||||
+ .dependent_slice_segment_flag = pps->dependent_slice_segments_enabled_flag,
|
||||
+ .output_flag_present_flag = pps->output_flag_present_flag,
|
||||
+ .num_extra_slice_header_bits = pps->num_extra_slice_header_bits,
|
||||
+ .sign_data_hiding_enabled_flag = pps->sign_data_hiding_flag,
|
||||
+ .cabac_init_present_flag = pps->cabac_init_present_flag,
|
||||
+ .init_qp_minus26 = pps->pic_init_qp_minus26,
|
||||
+ .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
|
||||
+ .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
|
||||
+ .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
|
||||
+ .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
|
||||
+ .pps_cb_qp_offset = pps->cb_qp_offset,
|
||||
+ .pps_cr_qp_offset = pps->cr_qp_offset,
|
||||
+ .pps_slice_chroma_qp_offsets_present_flag = pps->pic_slice_level_chroma_qp_offsets_present_flag,
|
||||
+ .weighted_pred_flag = pps->weighted_pred_flag,
|
||||
+ .weighted_bipred_flag = pps->weighted_bipred_flag,
|
||||
+ .transquant_bypass_enabled_flag = pps->transquant_bypass_enable_flag,
|
||||
+ .tiles_enabled_flag = pps->tiles_enabled_flag,
|
||||
+ .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
|
||||
+ .loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag,
|
||||
+ .pps_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag,
|
||||
+ .deblocking_filter_override_enabled_flag = pps->deblocking_filter_override_enabled_flag,
|
||||
+ .pps_disable_deblocking_filter_flag = pps->disable_dbf,
|
||||
+ .pps_beta_offset_div2 = pps->beta_offset / 2,
|
||||
+ .pps_tc_offset_div2 = pps->tc_offset / 2,
|
||||
+ .lists_modification_present_flag = pps->lists_modification_present_flag,
|
||||
+ .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level - 2,
|
||||
+ .slice_segment_header_extension_present_flag = pps->slice_header_extension_present_flag,
|
||||
+ .scaling_list_enable_flag = pps->scaling_list_data_present_flag, // pps_scaling_list_data_present_flag
|
||||
+ };
|
||||
+
|
||||
+ if (pps->tiles_enabled_flag) {
|
||||
+ controls->pps.num_tile_columns_minus1 = pps->num_tile_columns - 1;
|
||||
+ controls->pps.num_tile_rows_minus1 = pps->num_tile_rows - 1;
|
||||
+
|
||||
+ av_log(avctx, AV_LOG_DEBUG, "%s: avctx=%p tiles_enabled_flag=%d num_tile_columns=%d num_tile_rows=%d\n", __func__, avctx, pps->tiles_enabled_flag, pps->num_tile_columns, pps->num_tile_rows);
|
||||
+
|
||||
+ for (int i = 0; i < pps->num_tile_columns; i++)
|
||||
+ controls->pps.column_width_minus1[i] = pps->column_width[i] - 1;
|
||||
+
|
||||
+ for (int i = 0; i < pps->num_tile_rows; i++)
|
||||
+ controls->pps.row_height_minus1[i] = pps->row_height[i] - 1;
|
||||
+ }
|
||||
+
|
||||
+ return ff_v4l2_request_reset_frame(avctx, h->ref->frame);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_hevc_end_frame(AVCodecContext *avctx)
|
||||
+{
|
||||
+ const HEVCContext *h = avctx->priv_data;
|
||||
+ V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)h->ref->frame->data[0];
|
||||
+
|
||||
+ struct v4l2_ext_control control[] = {
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
|
||||
+ .ptr = &controls->sps,
|
||||
+ .size = sizeof(controls->sps),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
|
||||
+ .ptr = &controls->pps,
|
||||
+ .size = sizeof(controls->pps),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX,
|
||||
+ .ptr = &controls->scaling_matrix,
|
||||
+ .size = sizeof(controls->scaling_matrix),
|
||||
+ },
|
||||
+ {
|
||||
+ .id = V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS,
|
||||
+ .ptr = &controls->slice_params,
|
||||
+ .size = sizeof(controls->slice_params),
|
||||
+ },
|
||||
+ };
|
||||
+
|
||||
+ controls->slice_params.bit_size = req->output.used * 8;
|
||||
+
|
||||
+ return ff_v4l2_request_decode_frame(avctx, h->ref->frame, control, FF_ARRAY_ELEMS(control));
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
|
||||
+{
|
||||
+ const HEVCContext *h = avctx->priv_data;
|
||||
+ V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private;
|
||||
+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)h->ref->frame->data[0];
|
||||
+
|
||||
+ // HACK: trigger decode per slice
|
||||
+ if (req->output.used) {
|
||||
+ v4l2_request_hevc_end_frame(avctx);
|
||||
+ ff_v4l2_request_reset_frame(avctx, h->ref->frame);
|
||||
+ }
|
||||
+
|
||||
+ v4l2_request_hevc_fill_slice_params(h, &controls->slice_params);
|
||||
+
|
||||
+ return ff_v4l2_request_append_output_buffer(avctx, h->ref->frame, buffer, size);
|
||||
+}
|
||||
+
|
||||
+static int v4l2_request_hevc_init(AVCodecContext *avctx)
|
||||
+{
|
||||
+ return ff_v4l2_request_init(avctx, V4L2_PIX_FMT_HEVC_SLICE, 2 * 1024 * 1024, NULL, 0);
|
||||
+}
|
||||
+
|
||||
+const AVHWAccel ff_hevc_v4l2request_hwaccel = {
|
||||
+ .name = "hevc_v4l2request",
|
||||
+ .type = AVMEDIA_TYPE_VIDEO,
|
||||
+ .id = AV_CODEC_ID_HEVC,
|
||||
+ .pix_fmt = AV_PIX_FMT_DRM_PRIME,
|
||||
+ .start_frame = v4l2_request_hevc_start_frame,
|
||||
+ .decode_slice = v4l2_request_hevc_decode_slice,
|
||||
+ .end_frame = v4l2_request_hevc_end_frame,
|
||||
+ .frame_priv_data_size = sizeof(V4L2RequestControlsHEVC),
|
||||
+ .init = v4l2_request_hevc_init,
|
||||
+ .uninit = ff_v4l2_request_uninit,
|
||||
+ .priv_data_size = sizeof(V4L2RequestContext),
|
||||
+ .frame_params = ff_v4l2_request_frame_params,
|
||||
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
|
||||
+};
|
||||
--
|
||||
2.21.0
|
||||
|
@ -0,0 +1,546 @@
|
||||
From 583677006f15ee59600f6f30f5e79aa5f81935b9 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 ++++++++++++++++++++++++++++++++
|
||||
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(+)
|
||||
create mode 100644 libavcodec/h264-ctrls.h
|
||||
create mode 100644 libavcodec/hevc-ctrls.h
|
||||
create mode 100644 libavcodec/mpeg2-ctrls.h
|
||||
|
||||
diff --git a/libavcodec/h264-ctrls.h b/libavcodec/h264-ctrls.h
|
||||
new file mode 100644
|
||||
index 0000000000..e2f83b3cdb
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/h264-ctrls.h
|
||||
@@ -0,0 +1,192 @@
|
||||
+/* SPDX-License-Identifier: GPL-2.0 */
|
||||
+/*
|
||||
+ * These are the H.264 state controls for use with stateless H.264
|
||||
+ * codec drivers.
|
||||
+ *
|
||||
+ * It turns out that these structs are not stable yet and will undergo
|
||||
+ * more changes. So keep them private until they are stable and ready to
|
||||
+ * become part of the official public API.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _H264_CTRLS_H_
|
||||
+#define _H264_CTRLS_H_
|
||||
+
|
||||
+/*
|
||||
+ * This is put insanely high to avoid conflicting with controls that
|
||||
+ * would be added during the phase where those controls are not
|
||||
+ * stable. It should be fixed eventually.
|
||||
+ */
|
||||
+#define V4L2_CID_MPEG_VIDEO_H264_SPS (V4L2_CID_MPEG_BASE+1000)
|
||||
+#define V4L2_CID_MPEG_VIDEO_H264_PPS (V4L2_CID_MPEG_BASE+1001)
|
||||
+#define V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX (V4L2_CID_MPEG_BASE+1002)
|
||||
+#define V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS (V4L2_CID_MPEG_BASE+1003)
|
||||
+#define V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS (V4L2_CID_MPEG_BASE+1004)
|
||||
+
|
||||
+/* enum v4l2_ctrl_type type values */
|
||||
+#define V4L2_CTRL_TYPE_H264_SPS 0x0110
|
||||
+#define V4L2_CTRL_TYPE_H264_PPS 0x0111
|
||||
+#define V4L2_CTRL_TYPE_H264_SCALING_MATRIX 0x0112
|
||||
+#define V4L2_CTRL_TYPE_H264_SLICE_PARAMS 0x0113
|
||||
+#define V4L2_CTRL_TYPE_H264_DECODE_PARAMS 0x0114
|
||||
+
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET0_FLAG 0x01
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET1_FLAG 0x02
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET2_FLAG 0x04
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET3_FLAG 0x08
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET4_FLAG 0x10
|
||||
+#define V4L2_H264_SPS_CONSTRAINT_SET5_FLAG 0x20
|
||||
+
|
||||
+#define V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE 0x01
|
||||
+#define V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS 0x02
|
||||
+#define V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO 0x04
|
||||
+#define V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED 0x08
|
||||
+#define V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY 0x10
|
||||
+#define V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD 0x20
|
||||
+#define V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE 0x40
|
||||
+
|
||||
+struct v4l2_ctrl_h264_sps {
|
||||
+ __u8 profile_idc;
|
||||
+ __u8 constraint_set_flags;
|
||||
+ __u8 level_idc;
|
||||
+ __u8 seq_parameter_set_id;
|
||||
+ __u8 chroma_format_idc;
|
||||
+ __u8 bit_depth_luma_minus8;
|
||||
+ __u8 bit_depth_chroma_minus8;
|
||||
+ __u8 log2_max_frame_num_minus4;
|
||||
+ __u8 pic_order_cnt_type;
|
||||
+ __u8 log2_max_pic_order_cnt_lsb_minus4;
|
||||
+ __u8 max_num_ref_frames;
|
||||
+ __u8 num_ref_frames_in_pic_order_cnt_cycle;
|
||||
+ __s32 offset_for_ref_frame[255];
|
||||
+ __s32 offset_for_non_ref_pic;
|
||||
+ __s32 offset_for_top_to_bottom_field;
|
||||
+ __u16 pic_width_in_mbs_minus1;
|
||||
+ __u16 pic_height_in_map_units_minus1;
|
||||
+ __u32 flags;
|
||||
+};
|
||||
+
|
||||
+#define V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE 0x0001
|
||||
+#define V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT 0x0002
|
||||
+#define V4L2_H264_PPS_FLAG_WEIGHTED_PRED 0x0004
|
||||
+#define V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT 0x0008
|
||||
+#define V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED 0x0010
|
||||
+#define V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT 0x0020
|
||||
+#define V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE 0x0040
|
||||
+#define V4L2_H264_PPS_FLAG_PIC_SCALING_MATRIX_PRESENT 0x0080
|
||||
+
|
||||
+struct v4l2_ctrl_h264_pps {
|
||||
+ __u8 pic_parameter_set_id;
|
||||
+ __u8 seq_parameter_set_id;
|
||||
+ __u8 num_slice_groups_minus1;
|
||||
+ __u8 num_ref_idx_l0_default_active_minus1;
|
||||
+ __u8 num_ref_idx_l1_default_active_minus1;
|
||||
+ __u8 weighted_bipred_idc;
|
||||
+ __s8 pic_init_qp_minus26;
|
||||
+ __s8 pic_init_qs_minus26;
|
||||
+ __s8 chroma_qp_index_offset;
|
||||
+ __s8 second_chroma_qp_index_offset;
|
||||
+ __u16 flags;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_h264_scaling_matrix {
|
||||
+ __u8 scaling_list_4x4[6][16];
|
||||
+ __u8 scaling_list_8x8[6][64];
|
||||
+};
|
||||
+
|
||||
+struct v4l2_h264_weight_factors {
|
||||
+ __s16 luma_weight[32];
|
||||
+ __s16 luma_offset[32];
|
||||
+ __s16 chroma_weight[32][2];
|
||||
+ __s16 chroma_offset[32][2];
|
||||
+};
|
||||
+
|
||||
+struct v4l2_h264_pred_weight_table {
|
||||
+ __u16 luma_log2_weight_denom;
|
||||
+ __u16 chroma_log2_weight_denom;
|
||||
+ struct v4l2_h264_weight_factors weight_factors[2];
|
||||
+};
|
||||
+
|
||||
+#define V4L2_H264_SLICE_TYPE_P 0
|
||||
+#define V4L2_H264_SLICE_TYPE_B 1
|
||||
+#define V4L2_H264_SLICE_TYPE_I 2
|
||||
+#define V4L2_H264_SLICE_TYPE_SP 3
|
||||
+#define V4L2_H264_SLICE_TYPE_SI 4
|
||||
+
|
||||
+#define V4L2_H264_SLICE_FLAG_FIELD_PIC 0x01
|
||||
+#define V4L2_H264_SLICE_FLAG_BOTTOM_FIELD 0x02
|
||||
+#define V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED 0x04
|
||||
+#define V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH 0x08
|
||||
+
|
||||
+struct v4l2_ctrl_h264_slice_params {
|
||||
+ /* Size in bytes, including header */
|
||||
+ __u32 size;
|
||||
+ /* Offset in bits to slice_data() from the beginning of this slice. */
|
||||
+ __u32 header_bit_size;
|
||||
+
|
||||
+ __u16 first_mb_in_slice;
|
||||
+ __u8 slice_type;
|
||||
+ __u8 pic_parameter_set_id;
|
||||
+ __u8 colour_plane_id;
|
||||
+ __u8 redundant_pic_cnt;
|
||||
+ __u16 frame_num;
|
||||
+ __u16 idr_pic_id;
|
||||
+ __u16 pic_order_cnt_lsb;
|
||||
+ __s32 delta_pic_order_cnt_bottom;
|
||||
+ __s32 delta_pic_order_cnt0;
|
||||
+ __s32 delta_pic_order_cnt1;
|
||||
+
|
||||
+ struct v4l2_h264_pred_weight_table pred_weight_table;
|
||||
+ /* Size in bits of dec_ref_pic_marking() syntax element. */
|
||||
+ __u32 dec_ref_pic_marking_bit_size;
|
||||
+ /* Size in bits of pic order count syntax. */
|
||||
+ __u32 pic_order_cnt_bit_size;
|
||||
+
|
||||
+ __u8 cabac_init_idc;
|
||||
+ __s8 slice_qp_delta;
|
||||
+ __s8 slice_qs_delta;
|
||||
+ __u8 disable_deblocking_filter_idc;
|
||||
+ __s8 slice_alpha_c0_offset_div2;
|
||||
+ __s8 slice_beta_offset_div2;
|
||||
+ __u8 num_ref_idx_l0_active_minus1;
|
||||
+ __u8 num_ref_idx_l1_active_minus1;
|
||||
+ __u32 slice_group_change_cycle;
|
||||
+
|
||||
+ /*
|
||||
+ * Entries on each list are indices into
|
||||
+ * v4l2_ctrl_h264_decode_params.dpb[].
|
||||
+ */
|
||||
+ __u8 ref_pic_list0[32];
|
||||
+ __u8 ref_pic_list1[32];
|
||||
+
|
||||
+ __u32 flags;
|
||||
+};
|
||||
+
|
||||
+#define V4L2_H264_DPB_ENTRY_FLAG_VALID 0x01
|
||||
+#define V4L2_H264_DPB_ENTRY_FLAG_ACTIVE 0x02
|
||||
+#define V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM 0x04
|
||||
+
|
||||
+struct v4l2_h264_dpb_entry {
|
||||
+ __u64 reference_ts;
|
||||
+ __u16 frame_num;
|
||||
+ __u16 pic_num;
|
||||
+ /* Note that field is indicated by v4l2_buffer.field */
|
||||
+ __s32 top_field_order_cnt;
|
||||
+ __s32 bottom_field_order_cnt;
|
||||
+ __u32 flags; /* V4L2_H264_DPB_ENTRY_FLAG_* */
|
||||
+};
|
||||
+
|
||||
+#define V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC 0x01
|
||||
+
|
||||
+struct v4l2_ctrl_h264_decode_params {
|
||||
+ struct v4l2_h264_dpb_entry dpb[16];
|
||||
+ __u16 num_slices;
|
||||
+ __u16 nal_ref_idc;
|
||||
+ __u8 ref_pic_list_p0[32];
|
||||
+ __u8 ref_pic_list_b0[32];
|
||||
+ __u8 ref_pic_list_b1[32];
|
||||
+ __s32 top_field_order_cnt;
|
||||
+ __s32 bottom_field_order_cnt;
|
||||
+ __u32 flags; /* V4L2_H264_DECODE_PARAM_FLAG_* */
|
||||
+};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h
|
||||
new file mode 100644
|
||||
index 0000000000..c8c61079c6
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/hevc-ctrls.h
|
||||
@@ -0,0 +1,197 @@
|
||||
+/* SPDX-License-Identifier: GPL-2.0 */
|
||||
+/*
|
||||
+ * These are the HEVC state controls for use with stateless HEVC
|
||||
+ * codec drivers.
|
||||
+ *
|
||||
+ * It turns out that these structs are not stable yet and will undergo
|
||||
+ * more changes. So keep them private until they are stable and ready to
|
||||
+ * become part of the official public API.
|
||||
+ */
|
||||
+
|
||||
+#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)
|
||||
+
|
||||
+/* 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_HEVC_SLICE_TYPE_B 0
|
||||
+#define V4L2_HEVC_SLICE_TYPE_P 1
|
||||
+#define V4L2_HEVC_SLICE_TYPE_I 2
|
||||
+
|
||||
+struct v4l2_ctrl_hevc_sps {
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */
|
||||
+ __u8 chroma_format_idc;
|
||||
+ __u8 separate_colour_plane_flag;
|
||||
+ __u16 pic_width_in_luma_samples;
|
||||
+ __u16 pic_height_in_luma_samples;
|
||||
+ __u8 bit_depth_luma_minus8;
|
||||
+ __u8 bit_depth_chroma_minus8;
|
||||
+ __u8 log2_max_pic_order_cnt_lsb_minus4;
|
||||
+ __u8 sps_max_dec_pic_buffering_minus1;
|
||||
+ __u8 sps_max_num_reorder_pics;
|
||||
+ __u8 sps_max_latency_increase_plus1;
|
||||
+ __u8 log2_min_luma_coding_block_size_minus3;
|
||||
+ __u8 log2_diff_max_min_luma_coding_block_size;
|
||||
+ __u8 log2_min_luma_transform_block_size_minus2;
|
||||
+ __u8 log2_diff_max_min_luma_transform_block_size;
|
||||
+ __u8 max_transform_hierarchy_depth_inter;
|
||||
+ __u8 max_transform_hierarchy_depth_intra;
|
||||
+ __u8 scaling_list_enabled_flag;
|
||||
+ __u8 amp_enabled_flag;
|
||||
+ __u8 sample_adaptive_offset_enabled_flag;
|
||||
+ __u8 pcm_enabled_flag;
|
||||
+ __u8 pcm_sample_bit_depth_luma_minus1;
|
||||
+ __u8 pcm_sample_bit_depth_chroma_minus1;
|
||||
+ __u8 log2_min_pcm_luma_coding_block_size_minus3;
|
||||
+ __u8 log2_diff_max_min_pcm_luma_coding_block_size;
|
||||
+ __u8 pcm_loop_filter_disabled_flag;
|
||||
+ __u8 num_short_term_ref_pic_sets;
|
||||
+ __u8 long_term_ref_pics_present_flag;
|
||||
+ __u8 num_long_term_ref_pics_sps;
|
||||
+ __u8 sps_temporal_mvp_enabled_flag;
|
||||
+ __u8 strong_intra_smoothing_enabled_flag;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_hevc_pps {
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
|
||||
+ __u8 dependent_slice_segment_flag;
|
||||
+ __u8 output_flag_present_flag;
|
||||
+ __u8 num_extra_slice_header_bits;
|
||||
+ __u8 sign_data_hiding_enabled_flag;
|
||||
+ __u8 cabac_init_present_flag;
|
||||
+ __s8 init_qp_minus26;
|
||||
+ __u8 constrained_intra_pred_flag;
|
||||
+ __u8 transform_skip_enabled_flag;
|
||||
+ __u8 cu_qp_delta_enabled_flag;
|
||||
+ __u8 diff_cu_qp_delta_depth;
|
||||
+ __s8 pps_cb_qp_offset;
|
||||
+ __s8 pps_cr_qp_offset;
|
||||
+ __u8 pps_slice_chroma_qp_offsets_present_flag;
|
||||
+ __u8 weighted_pred_flag;
|
||||
+ __u8 weighted_bipred_flag;
|
||||
+ __u8 transquant_bypass_enabled_flag;
|
||||
+ __u8 tiles_enabled_flag;
|
||||
+ __u8 entropy_coding_sync_enabled_flag;
|
||||
+ __u8 num_tile_columns_minus1;
|
||||
+ __u8 num_tile_rows_minus1;
|
||||
+ __u8 column_width_minus1[20];
|
||||
+ __u8 row_height_minus1[22];
|
||||
+ __u8 loop_filter_across_tiles_enabled_flag;
|
||||
+ __u8 pps_loop_filter_across_slices_enabled_flag;
|
||||
+ __u8 deblocking_filter_override_enabled_flag;
|
||||
+ __u8 pps_disable_deblocking_filter_flag;
|
||||
+ __s8 pps_beta_offset_div2;
|
||||
+ __s8 pps_tc_offset_div2;
|
||||
+ __u8 lists_modification_present_flag;
|
||||
+ __u8 log2_parallel_merge_level_minus2;
|
||||
+ __u8 slice_segment_header_extension_present_flag;
|
||||
+ __u8 scaling_list_enable_flag;
|
||||
+};
|
||||
+
|
||||
+#define V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_BEFORE 0x01
|
||||
+#define V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_AFTER 0x02
|
||||
+#define V4L2_HEVC_DPB_ENTRY_RPS_LT_CURR 0x03
|
||||
+
|
||||
+#define V4L2_HEVC_DPB_ENTRIES_NUM_MAX 16
|
||||
+
|
||||
+struct v4l2_hevc_dpb_entry {
|
||||
+ __u64 timestamp;
|
||||
+ __u8 rps;
|
||||
+ __u8 field_pic;
|
||||
+ __u16 pic_order_cnt[2];
|
||||
+ __u8 padding[2];
|
||||
+};
|
||||
+
|
||||
+struct v4l2_hevc_pred_weight_table {
|
||||
+ __u8 luma_log2_weight_denom;
|
||||
+ __s8 delta_chroma_log2_weight_denom;
|
||||
+
|
||||
+ __s8 delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __s8 luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __s8 delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
|
||||
+ __s8 chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
|
||||
+
|
||||
+ __s8 delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __s8 luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __s8 delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
|
||||
+ __s8 chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
|
||||
+
|
||||
+ __u8 padding[2];
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_hevc_slice_params {
|
||||
+ __u32 bit_size;
|
||||
+ __u32 data_bit_offset;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */
|
||||
+ __u8 nal_unit_type;
|
||||
+ __u8 nuh_temporal_id_plus1;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
|
||||
+ __u8 slice_type;
|
||||
+ __u8 colour_plane_id;
|
||||
+ __u16 slice_pic_order_cnt;
|
||||
+ __u8 slice_sao_luma_flag;
|
||||
+ __u8 slice_sao_chroma_flag;
|
||||
+ __u8 slice_temporal_mvp_enabled_flag;
|
||||
+ __u8 num_ref_idx_l0_active_minus1;
|
||||
+ __u8 num_ref_idx_l1_active_minus1;
|
||||
+ __u8 mvd_l1_zero_flag;
|
||||
+ __u8 cabac_init_flag;
|
||||
+ __u8 collocated_from_l0_flag;
|
||||
+ __u8 collocated_ref_idx;
|
||||
+ __u8 five_minus_max_num_merge_cand;
|
||||
+ __u8 use_integer_mv_flag;
|
||||
+ __s8 slice_qp_delta;
|
||||
+ __s8 slice_cb_qp_offset;
|
||||
+ __s8 slice_cr_qp_offset;
|
||||
+ __s8 slice_act_y_qp_offset;
|
||||
+ __s8 slice_act_cb_qp_offset;
|
||||
+ __s8 slice_act_cr_qp_offset;
|
||||
+ __u8 slice_deblocking_filter_disabled_flag;
|
||||
+ __s8 slice_beta_offset_div2;
|
||||
+ __s8 slice_tc_offset_div2;
|
||||
+ __u8 slice_loop_filter_across_slices_enabled_flag;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */
|
||||
+ __u8 pic_struct;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
|
||||
+ struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __u8 num_active_dpb_entries;
|
||||
+ __u8 ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+ __u8 ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
|
||||
+
|
||||
+ __u8 num_rps_poc_st_curr_before;
|
||||
+ __u8 num_rps_poc_st_curr_after;
|
||||
+ __u8 num_rps_poc_lt_curr;
|
||||
+
|
||||
+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
|
||||
+ struct v4l2_hevc_pred_weight_table pred_weight_table;
|
||||
+
|
||||
+ __u32 slice_segment_addr;
|
||||
+ __u32 num_entry_point_offsets;
|
||||
+ __u32 entry_point_offset_minus1[256];
|
||||
+ __u8 first_slice_segment_in_pic_flag;
|
||||
+
|
||||
+ __u8 padding;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_hevc_scaling_matrix {
|
||||
+ __u8 scaling_list_4x4[6][16];
|
||||
+ __u8 scaling_list_8x8[6][64];
|
||||
+ __u8 scaling_list_16x16[6][64];
|
||||
+ __u8 scaling_list_32x32[2][64];
|
||||
+ __u8 scaling_list_dc_coef_16x16[6];
|
||||
+ __u8 scaling_list_dc_coef_32x32[2];
|
||||
+};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/libavcodec/mpeg2-ctrls.h b/libavcodec/mpeg2-ctrls.h
|
||||
new file mode 100644
|
||||
index 0000000000..6601455b3d
|
||||
--- /dev/null
|
||||
+++ b/libavcodec/mpeg2-ctrls.h
|
||||
@@ -0,0 +1,82 @@
|
||||
+/* SPDX-License-Identifier: GPL-2.0 */
|
||||
+/*
|
||||
+ * These are the MPEG2 state controls for use with stateless MPEG-2
|
||||
+ * codec drivers.
|
||||
+ *
|
||||
+ * It turns out that these structs are not stable yet and will undergo
|
||||
+ * more changes. So keep them private until they are stable and ready to
|
||||
+ * become part of the official public API.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _MPEG2_CTRLS_H_
|
||||
+#define _MPEG2_CTRLS_H_
|
||||
+
|
||||
+#define V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS (V4L2_CID_MPEG_BASE+250)
|
||||
+#define V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION (V4L2_CID_MPEG_BASE+251)
|
||||
+
|
||||
+/* enum v4l2_ctrl_type type values */
|
||||
+#define V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS 0x0103
|
||||
+#define V4L2_CTRL_TYPE_MPEG2_QUANTIZATION 0x0104
|
||||
+
|
||||
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_I 1
|
||||
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_P 2
|
||||
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_B 3
|
||||
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_D 4
|
||||
+
|
||||
+struct v4l2_mpeg2_sequence {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */
|
||||
+ __u16 horizontal_size;
|
||||
+ __u16 vertical_size;
|
||||
+ __u32 vbv_buffer_size;
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */
|
||||
+ __u16 profile_and_level_indication;
|
||||
+ __u8 progressive_sequence;
|
||||
+ __u8 chroma_format;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_mpeg2_picture {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */
|
||||
+ __u8 picture_coding_type;
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */
|
||||
+ __u8 f_code[2][2];
|
||||
+ __u8 intra_dc_precision;
|
||||
+ __u8 picture_structure;
|
||||
+ __u8 top_field_first;
|
||||
+ __u8 frame_pred_frame_dct;
|
||||
+ __u8 concealment_motion_vectors;
|
||||
+ __u8 q_scale_type;
|
||||
+ __u8 intra_vlc_format;
|
||||
+ __u8 alternate_scan;
|
||||
+ __u8 repeat_first_field;
|
||||
+ __u16 progressive_frame;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_mpeg2_slice_params {
|
||||
+ __u32 bit_size;
|
||||
+ __u32 data_bit_offset;
|
||||
+ __u64 backward_ref_ts;
|
||||
+ __u64 forward_ref_ts;
|
||||
+
|
||||
+ struct v4l2_mpeg2_sequence sequence;
|
||||
+ struct v4l2_mpeg2_picture picture;
|
||||
+
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */
|
||||
+ __u32 quantiser_scale_code;
|
||||
+};
|
||||
+
|
||||
+struct v4l2_ctrl_mpeg2_quantization {
|
||||
+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Quant matrix extension */
|
||||
+ __u8 load_intra_quantiser_matrix;
|
||||
+ __u8 load_non_intra_quantiser_matrix;
|
||||
+ __u8 load_chroma_intra_quantiser_matrix;
|
||||
+ __u8 load_chroma_non_intra_quantiser_matrix;
|
||||
+
|
||||
+ __u8 intra_quantiser_matrix[64];
|
||||
+ __u8 non_intra_quantiser_matrix[64];
|
||||
+ __u8 chroma_intra_quantiser_matrix[64];
|
||||
+ __u8 chroma_non_intra_quantiser_matrix[64];
|
||||
+};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/libavcodec/v4l2_request_h264.c b/libavcodec/v4l2_request_h264.c
|
||||
index a5c56d81c3..a5dbc08a8d 100644
|
||||
--- a/libavcodec/v4l2_request_h264.c
|
||||
+++ b/libavcodec/v4l2_request_h264.c
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "h264dec.h"
|
||||
#include "hwaccel.h"
|
||||
#include "v4l2_request.h"
|
||||
+#include "h264-ctrls.h"
|
||||
|
||||
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
|
||||
--- a/libavcodec/v4l2_request_hevc.c
|
||||
+++ b/libavcodec/v4l2_request_hevc.c
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "hevcdec.h"
|
||||
#include "hwaccel.h"
|
||||
#include "v4l2_request.h"
|
||||
+#include "hevc-ctrls.h"
|
||||
|
||||
typedef struct V4L2RequestControlsHEVC {
|
||||
struct v4l2_ctrl_hevc_sps sps;
|
||||
diff --git a/libavcodec/v4l2_request_mpeg2.c b/libavcodec/v4l2_request_mpeg2.c
|
||||
index 782b9c2471..37a4eae62c 100644
|
||||
--- a/libavcodec/v4l2_request_mpeg2.c
|
||||
+++ b/libavcodec/v4l2_request_mpeg2.c
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "hwaccel.h"
|
||||
#include "mpegvideo.h"
|
||||
#include "v4l2_request.h"
|
||||
+#include "mpeg2-ctrls.h"
|
||||
|
||||
typedef struct V4L2RequestControlsMPEG2 {
|
||||
struct v4l2_ctrl_mpeg2_slice_params slice_params;
|
||||
--
|
||||
2.21.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user