Re: [FFmpeg-devel] [PATCH 1/5] avutil/buffer: add av_buffer_pool_flush()

2020-12-09 Thread Jonas Karlman
On 2020-12-10 00:17, James Almer wrote:
> On 12/9/2020 8:06 PM, Lynne wrote:
>> Dec 9, 2020, 23:42 by jo...@kwiboo.se:
>>
>>> On 2020-12-09 23:09, Lynne wrote:
>>>
>>>> Dec 9, 2020, 21:25 by jo...@kwiboo.se:
>>>>
>>>>> Signed-off-by: Jonas Karlman 
>>>>> ---
>>>>>   doc/APIchanges  |  3 +++
>>>>>   libavutil/buffer.c  | 13 +
>>>>>   libavutil/buffer.h  |  5 +
>>>>>   libavutil/version.h |  2 +-
>>>>>   4 files changed, 22 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/doc/APIchanges b/doc/APIchanges
>>>>> index 3fb9e12525..4a739ce453 100644
>>>>> --- a/doc/APIchanges
>>>>> +++ b/doc/APIchanges
>>>>> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>>>>>   
>>>>>   API changes, most recent first:
>>>>>   
>>>>> +2020-xx-xx - xx - lavu 56.63.100 - buffer.h
>>>>> +  Add av_buffer_pool_flush().
>>>>> +
>>>>>   2020-12-03 - xx - lavu 56.62.100 - timecode.h
>>>>>   Add av_timecode_init_from_components.
>>>>>   
>>>>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>>>>> index d67b4bbdaf..a0683664cf 100644
>>>>> --- a/libavutil/buffer.c
>>>>> +++ b/libavutil/buffer.c
>>>>> @@ -300,6 +300,19 @@ static void buffer_pool_free(AVBufferPool *pool)
>>>>>   av_freep();
>>>>>   }
>>>>>   
>>>>> +void av_buffer_pool_flush(AVBufferPool *pool)
>>>>> +{
>>>>> +ff_mutex_lock(>mutex);
>>>>> +while (pool->pool) {
>>>>> +BufferPoolEntry *buf = pool->pool;
>>>>> +pool->pool = buf->next;
>>>>> +
>>>>> +buf->free(buf->opaque, buf->data);
>>>>> +av_freep();
>>>>> +}
>>>>> +ff_mutex_unlock(>mutex);
>>>>> +}
>>>>>
>>>>
>>>> This frees all buffers from the pool, which an API user probably has 
>>>> references to,
>>>> leading to very nasty crashes. I can't see how this is even useful nor 
>>>> needed.
>>>>
>>>
>>> This function should only free buffers that has been returned to the pool 
>>> and
>>> is once again part of the pool->pool linked list.
>>>
>>> Main use-case is to flush and free all returned buffers in a pool used by a
>>> hwaccel ctx while a new hwaccel ctx is being initialized, i.e. during seek
>>> of H.264 video and a SPS change triggers initialization of a new hwaccel 
>>> ctx.
>>>
>>> For devices with memory constraints keeping all previously allocated buffers
>>> for the old hwaccel ctx around while trying to allocate new buffers for a 
>>> new
>>> hwaccel ctx tend to cause to much memory usage, especially for 2160p video.
>>>
>>> This function works around this limitation by freeing all buffers that has
>>> already been returned to the pool during hwaccel uninit, before the last
>>> buffer is returned, the last buffer is most of the time being displayed and
>>> is not returned to the pool until next frame has been decoded and displayed
>>> from next hwaccel ctx.
>>> Without this the pool buffers is only freed once the last buffer is 
>>> returned.
>>>
>>> Please note that I may have mixed up hwaccel and hw frames ctx above :-)
>>>
>>> This function is being called from ff_v4l2_request_uninit and
>>> v4l2_request_hwframe_ctx_free in next patch.
>>>
>>
>> Why can't av_buffer_pool_uninit() free all the buffers currently returned in 
>> the pool?
>> You only seem to be calling it the function during uninitialization.
> 
> av_buffer_pool_uninit() frees them only after *all* the buffers have 
> been returned. In the example Jonas gave above, there may be one or two 
> frames created from buffers allocated by the pool still active and yet 
> to be unref'd by the time another hwcontext is created and new buffers 
> from a new pool start being allocated.
> 
> His intention is to free all the buffers currently held by the pool (as 
> they will not be reused anymore) to free as much memory as possible. The 
> remaining buffers will be freed once the few remaining frames using them 
> are unref'd.
> 

Correct, bellow is a short log on what ha

Re: [FFmpeg-devel] [PATCH 3/5] h264dec: add idr_pic_id to slice context

2020-12-09 Thread Jonas Karlman
On 2020-12-09 23:23, Mark Thompson wrote:
> On 09/12/2020 20:25, Jonas Karlman wrote:
>> From: Ezequiel Garcia 
>>
>> Signed-off-by: Ezequiel Garcia 
>> Signed-off-by: Jonas Karlman 
>> ---
>>   libavcodec/h264_slice.c | 2 +-
>>   libavcodec/h264dec.h| 1 +
>>   2 files changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
>> index fa7a639053..8a3ce1a688 100644
>> --- a/libavcodec/h264_slice.c
>> +++ b/libavcodec/h264_slice.c
>> @@ -1824,7 +1824,7 @@ static int h264_slice_header_parse(const H264Context 
>> *h, H264SliceContext *sl,
>>   }
>>   
>>   if (nal->type == H264_NAL_IDR_SLICE)
>> -get_ue_golomb_long(>gb); /* idr_pic_id */
>> +sl->idr_pic_id = get_ue_golomb_long(>gb);
>>   
>>   if (sps->poc_type == 0) {
>>   sl->poc_lsb = get_bits(>gb, sps->log2_max_poc_lsb);
>> diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
>> index 29c4d4e42c..2ca9965b41 100644
>> --- a/libavcodec/h264dec.h
>> +++ b/libavcodec/h264dec.h
>> @@ -335,6 +335,7 @@ typedef struct H264SliceContext {
>>   int delta_poc[2];
>>   int curr_pic_num;
>>   int max_pic_num;
>> +int idr_pic_id;
>>   } H264SliceContext;
>>   
>>   /**
>>
> 
> This feels very suspicious: idr_pic_id is unrelated to decoding, so a decoder 
> which doesn't ignore must be doing something wrong?  (It's for detecting 
> frame boundaries under packet loss so you don't splice together parts of 
> unrelated intra frames.)

The Hantro VPU IP block seems to want this information together with the bit 
size of the ref_pic_marking for proper decoding, see [1] for how hwregs is 
configured.

I have not done any test with setting a forced idr_pic_id=0 in hw block.

Docs only mention the following:
 reference picture related

 h264_idrp_id
 instantaneous decoding refresh picture id

I will run some limited tests to see if decoded frame output changes when this 
hw reg is skipped.

[1] 
https://git.linuxtv.org/media_tree.git/tree/drivers/staging/media/hantro/hantro_g1_h264_dec.c#n89

Best regards,
Jonas

> 
> - Mark
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/5] avutil/buffer: add av_buffer_pool_flush()

2020-12-09 Thread Jonas Karlman
On 2020-12-09 23:09, Lynne wrote:
> Dec 9, 2020, 21:25 by jo...@kwiboo.se:
> 
>> Signed-off-by: Jonas Karlman 
>> ---
>>  doc/APIchanges  |  3 +++
>>  libavutil/buffer.c  | 13 +
>>  libavutil/buffer.h  |  5 +
>>  libavutil/version.h |  2 +-
>>  4 files changed, 22 insertions(+), 1 deletion(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index 3fb9e12525..4a739ce453 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>>  
>>  API changes, most recent first:
>>  
>> +2020-xx-xx - xx - lavu 56.63.100 - buffer.h
>> +  Add av_buffer_pool_flush().
>> +
>>  2020-12-03 - xx - lavu 56.62.100 - timecode.h
>>  Add av_timecode_init_from_components.
>>  
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index d67b4bbdaf..a0683664cf 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -300,6 +300,19 @@ static void buffer_pool_free(AVBufferPool *pool)
>>  av_freep();
>>  }
>>  
>> +void av_buffer_pool_flush(AVBufferPool *pool)
>> +{
>> +ff_mutex_lock(>mutex);
>> +while (pool->pool) {
>> +BufferPoolEntry *buf = pool->pool;
>> +pool->pool = buf->next;
>> +
>> +buf->free(buf->opaque, buf->data);
>> +av_freep();
>> +}
>> +ff_mutex_unlock(>mutex);
>> +}
>>
> 
> This frees all buffers from the pool, which an API user probably has 
> references to,
> leading to very nasty crashes. I can't see how this is even useful nor needed.
> 

This function should only free buffers that has been returned to the pool and
is once again part of the pool->pool linked list.

Main use-case is to flush and free all returned buffers in a pool used by a
hwaccel ctx while a new hwaccel ctx is being initialized, i.e. during seek
of H.264 video and a SPS change triggers initialization of a new hwaccel ctx.

For devices with memory constraints keeping all previously allocated buffers
for the old hwaccel ctx around while trying to allocate new buffers for a new
hwaccel ctx tend to cause to much memory usage, especially for 2160p video.

This function works around this limitation by freeing all buffers that has
already been returned to the pool during hwaccel uninit, before the last
buffer is returned, the last buffer is most of the time being displayed and
is not returned to the pool until next frame has been decoded and displayed
from next hwaccel ctx.
Without this the pool buffers is only freed once the last buffer is returned.

Please note that I may have mixed up hwaccel and hw frames ctx above :-)

This function is being called from ff_v4l2_request_uninit and
v4l2_request_hwframe_ctx_free in next patch.

Best regards,
Jonas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 5/5] h264dec: add V4L2 request API hwaccel

2020-12-09 Thread Jonas Karlman
From: Jernej Skrabec 

Signed-off-by: Jernej Skrabec 
Signed-off-by: Jonas Karlman 
---
 Changelog  |   1 +
 configure  |   3 +
 libavcodec/Makefile|   1 +
 libavcodec/h264_slice.c|   4 +
 libavcodec/h264dec.c   |   3 +
 libavcodec/hwaccels.h  |   1 +
 libavcodec/v4l2_request_h264.c | 457 +
 libavcodec/version.h   |   4 +-
 8 files changed, 472 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/v4l2_request_h264.c

diff --git a/Changelog b/Changelog
index 8f5e849f8d..f7930e0816 100644
--- a/Changelog
+++ b/Changelog
@@ -52,6 +52,7 @@ version :
 - Microsoft Paint (MSP) version 2 decoder
 - Microsoft Paint (MSP) demuxer
 - AV1 monochrome encoding support via libaom >= 2.0.1
+- V4L2 mem2mem stateless H.264 hwaccel
 
 
 version 4.3:
diff --git a/configure b/configure
index fac85bfab4..56a8c407f3 100755
--- a/configure
+++ b/configure
@@ -2945,6 +2945,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"
@@ -6613,6 +6615,7 @@ if enabled v4l2_m2m; then
 fi
 
 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;"
 
 check_headers 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 2fafc4e028..dcda71fad0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -926,6 +926,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 5ad1c347ed..533d84bb01 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -769,6 +769,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)
@@ -853,6 +854,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 46495d586f..4ad4d3a3dd 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1075,6 +1075,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 8e54cf73f9..969a1da0f4 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -32,6 +32,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 00..5ade6616e3
--- /dev/null
+++ b/libavcodec/v4l2_request_h264.c
@@ -0,0 +1,457 @@
+/*
+ * 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 

[FFmpeg-devel] [PATCH 4/5] h264dec: add ref_pic_marking and pic_order_cnt bit_size to slice context

2020-12-09 Thread Jonas Karlman
From: Boris Brezillon 

Signed-off-by: Boris Brezillon 
Signed-off-by: Jonas Karlman 
---
 libavcodec/h264_slice.c | 6 +-
 libavcodec/h264dec.h| 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 8a3ce1a688..5ad1c347ed 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1742,7 +1742,7 @@ static int h264_slice_header_parse(const H264Context *h, 
H264SliceContext *sl,
 unsigned int slice_type, tmp, i;
 int field_pic_flag, bottom_field_flag;
 int first_slice = sl == h->slice_ctx && !h->current_slice;
-int picture_structure;
+int picture_structure, pos;
 
 if (first_slice)
 av_assert0(!h->setup_finished);
@@ -1826,6 +1826,7 @@ static int h264_slice_header_parse(const H264Context *h, 
H264SliceContext *sl,
 if (nal->type == H264_NAL_IDR_SLICE)
 sl->idr_pic_id = get_ue_golomb_long(>gb);
 
+pos = sl->gb.index;
 if (sps->poc_type == 0) {
 sl->poc_lsb = get_bits(>gb, sps->log2_max_poc_lsb);
 
@@ -1839,6 +1840,7 @@ static int h264_slice_header_parse(const H264Context *h, 
H264SliceContext *sl,
 if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)
 sl->delta_poc[1] = get_se_golomb(>gb);
 }
+sl->pic_order_cnt_bit_size = sl->gb.index - pos;
 
 sl->redundant_pic_count = 0;
 if (pps->redundant_pic_cnt_present)
@@ -1876,12 +1878,14 @@ static int h264_slice_header_parse(const H264Context 
*h, H264SliceContext *sl,
 return ret;
 }
 
+pos = sl->gb.index;
 sl->explicit_ref_marking = 0;
 if (nal->ref_idc) {
 ret = ff_h264_decode_ref_pic_marking(sl, >gb, nal, h->avctx);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 return AVERROR_INVALIDDATA;
 }
+sl->ref_pic_marking_bit_size = sl->gb.index - pos;
 
 if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
 tmp = get_ue_golomb_31(>gb);
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 2ca9965b41..ad5a20ff8e 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -328,6 +328,7 @@ typedef struct H264SliceContext {
 MMCO mmco[MAX_MMCO_COUNT];
 int  nb_mmco;
 int explicit_ref_marking;
+int ref_pic_marking_bit_size;
 
 int frame_num;
 int poc_lsb;
@@ -336,6 +337,7 @@ typedef struct H264SliceContext {
 int curr_pic_num;
 int max_pic_num;
 int idr_pic_id;
+int pic_order_cnt_bit_size;
 } H264SliceContext;
 
 /**
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 3/5] h264dec: add idr_pic_id to slice context

2020-12-09 Thread Jonas Karlman
From: Ezequiel Garcia 

Signed-off-by: Ezequiel Garcia 
Signed-off-by: Jonas Karlman 
---
 libavcodec/h264_slice.c | 2 +-
 libavcodec/h264dec.h| 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index fa7a639053..8a3ce1a688 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1824,7 +1824,7 @@ static int h264_slice_header_parse(const H264Context *h, 
H264SliceContext *sl,
 }
 
 if (nal->type == H264_NAL_IDR_SLICE)
-get_ue_golomb_long(>gb); /* idr_pic_id */
+sl->idr_pic_id = get_ue_golomb_long(>gb);
 
 if (sps->poc_type == 0) {
 sl->poc_lsb = get_bits(>gb, sps->log2_max_poc_lsb);
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 29c4d4e42c..2ca9965b41 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -335,6 +335,7 @@ typedef struct H264SliceContext {
 int delta_poc[2];
 int curr_pic_num;
 int max_pic_num;
+int idr_pic_id;
 } H264SliceContext;
 
 /**
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/5] avcodec: add common V4L2 request API code

2020-12-09 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 configure |  12 +
 libavcodec/Makefile   |   1 +
 libavcodec/hwconfig.h |   2 +
 libavcodec/v4l2_request.c | 987 ++
 libavcodec/v4l2_request.h |  77 +++
 5 files changed, 1079 insertions(+)
 create mode 100644 libavcodec/v4l2_request.c
 create mode 100644 libavcodec/v4l2_request.h

diff --git a/configure b/configure
index 10cf61007b..fac85bfab4 100755
--- a/configure
+++ b/configure
@@ -278,6 +278,7 @@ External library support:
if openssl, gnutls or mbedtls is not used [no]
   --enable-libtwolame  enable MP2 encoding via libtwolame [no]
   --enable-libuavs3d   enable AVS3 decoding via libuavs3d [no]
+  --enable-libudev enable libudev [no]
   --enable-libv4l2 enable libv4l2/v4l-utils [no]
   --enable-libvidstab  enable video stabilization using vid.stab [no]
   --enable-libvmaf enable vmaf filter via libvmaf [no]
@@ -345,6 +346,7 @@ External library support:
   --enable-omx-rpi enable OpenMAX IL code for Raspberry Pi [no]
   --enable-rkmpp   enable Rockchip Media Process Platform code [no]
   --disable-v4l2-m2m   disable V4L2 mem2mem code [autodetect]
+  --enable-v4l2-requestenable V4L2 request API code [no]
   --disable-vaapi  disable Video Acceleration API (mainly Unix/Intel) 
code [autodetect]
   --disable-vdpau  disable Nvidia Video Decode and Presentation API 
for Unix code [autodetect]
   --disable-videotoolbox   disable VideoToolbox code [autodetect]
@@ -1812,6 +1814,7 @@ EXTERNAL_LIBRARY_LIST="
 libtheora
 libtwolame
 libuavs3d
+libudev
 libv4l2
 libvmaf
 libvorbis
@@ -1866,6 +1869,7 @@ HWACCEL_LIBRARY_LIST="
 mmal
 omx
 opencl
+v4l2_request
 vulkan
 "
 
@@ -2913,6 +2917,7 @@ d3d11va_deps="dxva_h ID3D11VideoDecoder 
ID3D11VideoContext"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 nvdec_deps="ffnvcodec"
+v4l2_request_deps="linux_videodev2_h linux_media_h v4l2_timeval_to_ns libdrm 
libudev"
 vaapi_x11_deps="xlib"
 videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
@@ -6423,6 +6428,7 @@ enabled libtwolame&& require libtwolame twolame.h 
twolame_init -ltwolame
  { check_lib libtwolame twolame.h 
twolame_encode_buffer_float32_interleaved -ltwolame ||
die "ERROR: libtwolame must be installed and 
version must be >= 0.3.10"; }
 enabled libuavs3d && require_pkg_config libuavs3d "uavs3d >= 1.1.41" 
uavs3d.h uavs3d_decode
+enabled libudev   && require_pkg_config libudev libudev libudev.h 
udev_new
 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 >= 1.5.2" 
libvmaf.h compute_vmaf
@@ -6521,6 +6527,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"; }
 enabled vapoursynth   && require_pkg_config vapoursynth 
"vapoursynth-script >= 42" VSScript.h vsscript_init
 
 
@@ -6602,6 +6612,8 @@ if enabled v4l2_m2m; then
 check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
 fi
 
+check_func_headers "linux/media.h linux/videodev2.h" v4l2_timeval_to_ns
+
 check_headers 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 9b370ffc44..2fafc4e028 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -155,6 +155,7 @@ OBJS-$(CONFIG_VP3DSP)  += vp3dsp.o
 OBJS-$(CONFIG_VP56DSP) += vp56dsp.o
 OBJS-$(CONFIG_VP8DSP)  += vp8dsp.o
 OBJS-$(CONFIG_V4L2_M2M)+= v4l2_m2m.o v4l2_context.o 
v4l2_buffers.o v4l2_fmt.o
+OBJS-$(CONFIG_V4L2_REQUEST)+= v4l2_request.o
 OBJS-$(CONFIG_WMA_FREQS)   += wma_freqs.o
 OBJS-$(CONFIG_WMV2DSP)  

[FFmpeg-devel] [PATCH 0/5] Add V4L2 request API H.264 hwaccel

2020-12-09 Thread Jonas Karlman
Hello,

This is a follow up to an old RFC [1], adding a new hwaccel using the
V4L2 request API for stateless decoding of H.264.

The V4L2 ctrls needed for stateless decoding of H.264 is targeted for being
de-staged and moved to public linux uapi with linux v5.11.

De-stage of MPEG-2 and VP8 stateless codec APIs will hopefully follow in
v5.12, HEVC and VP9 will follow later.

These patches must be used with latest linux-media or linux-next tree.
De-stage H.264 stateless codec APIs pull-request [2] has been merged into
linux-media tree and is on track for inclusion in v5.11.

Patch 1 contains a new buffer pool function av_buffer_pool_flush() that will
free all available buffers in a buffer pool. This can be used to save memory
when seeking in e.g. H.264 where a new hwaccel instance may get init:ed before
the current one is uninit. The V4L2 request API hwaccel use this function
to minimize memory usage.

Patch 2 adds common code used in the hwaccel, libudev is used to enumerate
media and video devices to locate devices that support stateless decoding.

Patch 3-4 add idr_pic_id, ref_pic_marking and pic_order_cnt bit_size in
H.264 slice context for use by the V4L2 request API H.264 hwaccel.

Patch 5 adds the V4L2 request API H.264 hwaccel.

Use --enable-v4l2-request --enable-libdrm --enable-libudev to enable hwaccel.

Playback can be tested using kodi-gbm or mpv with any supported device using
cedrus, hantro or rkvdec drivers located in staging.

This hwaccel has in one form or another been used in LibreELEC community and
nightly images since Dec 20th 2018.

A copy of this series can also be found at [3].

[1] http://ffmpeg.org/pipermail/ffmpeg-devel/2019-April/242316.html
[2] 
https://patchwork.linuxtv.org/project/linux-media/patch/d68da172-b251-000f-653d-38a8a4c7b...@xs4all.nl/
[3] https://github.com/Kwiboo/FFmpeg/commits/v4l2-request-hwaccel-master-stable

Regards,
Jonas

Boris Brezillon (1):
  h264dec: add ref_pic_marking and pic_order_cnt bit_size to slice
context

Ezequiel Garcia (1):
  h264dec: add idr_pic_id to slice context

Jernej Skrabec (1):
  h264dec: add V4L2 request API hwaccel

Jonas Karlman (2):
  avutil/buffer: add av_buffer_pool_flush()
  avcodec: add common V4L2 request API code

 Changelog  |   1 +
 configure  |  15 +
 doc/APIchanges |   3 +
 libavcodec/Makefile|   2 +
 libavcodec/h264_slice.c|  12 +-
 libavcodec/h264dec.c   |   3 +
 libavcodec/h264dec.h   |   3 +
 libavcodec/hwaccels.h  |   1 +
 libavcodec/hwconfig.h  |   2 +
 libavcodec/v4l2_request.c  | 987 +
 libavcodec/v4l2_request.h  |  77 +++
 libavcodec/v4l2_request_h264.c | 457 +++
 libavcodec/version.h   |   4 +-
 libavutil/buffer.c |  13 +
 libavutil/buffer.h |   5 +
 libavutil/version.h|   2 +-
 16 files changed, 1582 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/v4l2_request.c
 create mode 100644 libavcodec/v4l2_request.h
 create mode 100644 libavcodec/v4l2_request_h264.c

-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/5] avutil/buffer: add av_buffer_pool_flush()

2020-12-09 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 doc/APIchanges  |  3 +++
 libavutil/buffer.c  | 13 +
 libavutil/buffer.h  |  5 +
 libavutil/version.h |  2 +-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 3fb9e12525..4a739ce453 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xx - lavu 56.63.100 - buffer.h
+  Add av_buffer_pool_flush().
+
 2020-12-03 - xx - lavu 56.62.100 - timecode.h
   Add av_timecode_init_from_components.
 
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index d67b4bbdaf..a0683664cf 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -300,6 +300,19 @@ static void buffer_pool_free(AVBufferPool *pool)
 av_freep();
 }
 
+void av_buffer_pool_flush(AVBufferPool *pool)
+{
+ff_mutex_lock(>mutex);
+while (pool->pool) {
+BufferPoolEntry *buf = pool->pool;
+pool->pool = buf->next;
+
+buf->free(buf->opaque, buf->data);
+av_freep();
+}
+ff_mutex_unlock(>mutex);
+}
+
 void av_buffer_pool_uninit(AVBufferPool **ppool)
 {
 AVBufferPool *pool;
diff --git a/libavutil/buffer.h b/libavutil/buffer.h
index fd4e381efa..cef2d08f5a 100644
--- a/libavutil/buffer.h
+++ b/libavutil/buffer.h
@@ -283,6 +283,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_flush(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
diff --git a/libavutil/version.h b/libavutil/version.h
index 9b311b5b27..9db2797aee 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  62
+#define LIBAVUTIL_VERSION_MINOR  63
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 0/4] Add AVDRMFrameDescriptor.format field

2019-05-12 Thread Jonas Karlman
On 2019-05-12 19:28, Mark Thompson wrote:
> On 09/05/2019 20:38, Jonas Karlman wrote:
>> Hello,
>>
>> When a multi-layer AVDRMFrameDescriptor is used to describe a frame the 
>> overall
>> frame format is missing and applications need to deduce the frame 
>> DRM_FORMAT_*
>> based on sw_format or the layers format.
>>
>> This patchset adds a AVDRMFrameDescriptor.format field to remove any 
>> ambiguity
>> of what frame format a multi-layer descriptor may have.
>>
>> Kodi has up until now only supported single layer AVDRMFrameDescriptor,
>> when trying to add support for multi-layer frame descriptors [1],
>> we did not want to try and deduce the frame format, hence this patchset.
>>
>> [1] https://github.com/xbmc/xbmc/pull/16102
>>
>> Patch 1 adds a new field, format, to the AVDRMFrameDescriptor struct.
>> Patch 2-4 adds code to set the new format field.
>>
>> Regards,
>> Jonas
>>
>> ---
>>
>> Jonas Karlman (4):
>>   hwcontext_drm: Add AVDRMFrameDescriptor.format field
>>   hwcontext_vaapi: Set AVDRMFrameDescriptor.format in map_from
>>   rkmppdec: Set AVDRMFrameDescriptor.format
>>   kmsgrab: Set AVDRMFrameDescriptor.format
>>
>>  doc/APIchanges  |  3 +++
>>  libavcodec/rkmppdec.c   |  1 +
>>  libavdevice/kmsgrab.c   |  1 +
>>  libavutil/hwcontext_drm.h   |  4 
>>  libavutil/hwcontext_vaapi.c | 38 +
>>  libavutil/version.h |  4 ++--
>>  6 files changed, 49 insertions(+), 2 deletions(-)
> Can you argue why this case should be put in FFmpeg rather than constructing 
> the format you want in the client code?
>
> The intent of the existing format information is that each layer is 
> definitely usable as the specific format stated if the device supports that 
> format and format modifier.  That isn't true for the top-level format - some 
> devices enforce additional constraints which aren't visible.  For example, if 
> you take an R8 + GR88 frame from an AMD device, it probably won't work as 
> NV12 with Intel video hardware because there the whole frame is required to 
> be in one object (well, not quite - actually the offset from the luma plane 
> to the chroma plane just has some relatively small limit; in practice this 
> gets enforced as single-object, though), but it will work perfectly well as 
> R8 and GR88 planes.

The reason why I wanted to offload this to FFmpeg is that the top-level format 
is already known while the application would have to guess/calculate correct 
format to use when importing the video buffer into a drm plane.

The main issue we are facing is that kernel api do not have a distinction 
between single/multi layer/object when importing a video buffer into a 
framebuffer, drmModeAddFB2WithModifiers is expecting the top-level format 
regardless if the planes come from multiple objects or not.
(Kernel driver may still enforce additional constraints, e.g. on Rockchip the 
luma plane must be contiguous after chroma plane, and Allwinner have similar 
limits as Intel, chorma and luma plane must be in close proximity)

In order to support HDR video using a framebuffer tied to a drm plane on Intel, 
the top-level format passed to drmModeAddFB2WithModifiers must be P010 even if 
vaExportSurfaceHandle exports the video buffer as two layers, R16 + RG1616.

Changing vaapi_map_to_drm_esh in hwcontext_vaapi to try and use 
VA_EXPORT_SURFACE_COMPOSED_LAYERS and fallback to 
VA_EXPORT_SURFACE_SEPARATE_LAYERS could also work for our use case, the Intel 
vaapi driver support both export methods and AMD only the separate layers 
method.
From what I understand support for composed layers wont be added to AMD as it 
technically are multiple objects. I am not even sure if AMD have support for 
NV12 as a drm plane format.

Regards,
Jonas

>
> Thanks,
>
> - Mark

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 4/4] kmsgrab: Set AVDRMFrameDescriptor.format

2019-05-09 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 libavdevice/kmsgrab.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavdevice/kmsgrab.c b/libavdevice/kmsgrab.c
index d0de774871..1ebc30ea92 100644
--- a/libavdevice/kmsgrab.c
+++ b/libavdevice/kmsgrab.c
@@ -162,6 +162,7 @@ static int kmsgrab_read_packet(AVFormatContext *avctx, 
AVPacket *pkt)
 .pitch= fb->pitch,
 },
 },
+.format = ctx->drm_format,
 };
 
 frame = av_frame_alloc();
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 3/4] rkmppdec: Set AVDRMFrameDescriptor.format

2019-05-09 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 libavcodec/rkmppdec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c
index 143d05bd51..3ea64d867e 100644
--- a/libavcodec/rkmppdec.c
+++ b/libavcodec/rkmppdec.c
@@ -419,6 +419,7 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, 
AVFrame *frame)
 goto fail;
 }
 
+desc->format = drmformat;
 desc->nb_objects = 1;
 desc->objects[0].fd = mpp_buffer_get_fd(buffer);
 desc->objects[0].size = mpp_buffer_get_size(buffer);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/4] hwcontext_drm: Add AVDRMFrameDescriptor.format field

2019-05-09 Thread Jonas Karlman
A AVDRMFrameDescriptor for a NV12 frame may be described in
a single layer descriptor with multiple planes,

(AVDRMFrameDescriptor) {
.nb_layers = 1,
.layers[0] = {
.format   = DRM_FORMAT_NV12,
.nb_planes= 2,
.planes[0] = {
.object_index = 0,
},
.planes[1] = {
.object_index = 0,
},
},
}

or a multi-layer descriptor with one plane in each layer.

(AVDRMFrameDescriptor) {
.nb_layers = 2,
.layers[0] = {
.format   = DRM_FORMAT_R8,
.nb_planes= 1,
.planes[0] = {
.object_index = 0,
},
},
.layers[1] = {
.format   = DRM_FORMAT_RG88,
.nb_planes= 1,
.planes[0] = {
.object_index = 1,
},
},
}

With a multi-layer descriptor, the frame format is missing.

Add a AVDRMFrameDescriptor.format field to remove any ambiguity of
what frame format a multi-layer descriptor may have.

Signed-off-by: Jonas Karlman 
---
 doc/APIchanges| 3 +++
 libavutil/hwcontext_drm.h | 4 
 libavutil/version.h   | 4 ++--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index e75c4044ce..d9c21ec030 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-05-08 - xx - lavu 56.27.100 - hwcontext_drm.h
+  Add AVDRMFrameDescriptor.format.
+
 2019-04-20 - 3153a6502a - lavc 58.52.100 - avcodec.h
   Add AV_CODEC_FLAG_DROPCHANGED to allow avcodec_receive_frame to drop
   frames whose parameters differ from first decoded frame in stream.
diff --git a/libavutil/hwcontext_drm.h b/libavutil/hwcontext_drm.h
index 42709f215e..0ccbd19acc 100644
--- a/libavutil/hwcontext_drm.h
+++ b/libavutil/hwcontext_drm.h
@@ -147,6 +147,10 @@ typedef struct AVDRMFrameDescriptor {
  * Array of layers in the frame.
  */
 AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES];
+/**
+ * Format of the frame (DRM_FORMAT_*).
+ */
+uint32_t format;
 } AVDRMFrameDescriptor;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index c0968de621..12b4f9fc3a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  26
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR  27
+#define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/4] hwcontext_vaapi: Set AVDRMFrameDescriptor.format in map_from

2019-05-09 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 libavutil/hwcontext_vaapi.c | 38 +
 1 file changed, 38 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 8624369bb9..d55eccbdcf 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1121,6 +1121,43 @@ static void vaapi_unmap_to_drm_esh(AVHWFramesContext 
*hwfc,
 av_freep(_desc);
 }
 
+static uint32_t vaapi_va_fourcc_to_drm_format(uint32_t fourcc)
+{
+switch (fourcc) {
+case VA_FOURCC_NV12:
+return DRM_FORMAT_NV12;
+case VA_FOURCC_I420:
+return DRM_FORMAT_YUV420;
+case VA_FOURCC_YV12:
+return DRM_FORMAT_YVU420;
+case VA_FOURCC_YV16:
+return DRM_FORMAT_YVU422;
+case VA_FOURCC_YUY2:
+return DRM_FORMAT_YUYV;
+case VA_FOURCC_UYVY:
+return DRM_FORMAT_UYVY;
+case VA_FOURCC_Y800:
+return DRM_FORMAT_R8;
+#ifdef DRM_FORMAT_P010
+case VA_FOURCC_P010:
+return DRM_FORMAT_P010;
+#endif
+case VA_FOURCC_RGBA:
+return DRM_FORMAT_ABGR;
+case VA_FOURCC_RGBX:
+return DRM_FORMAT_XBGR;
+case VA_FOURCC_BGRA:
+return DRM_FORMAT_ARGB;
+case VA_FOURCC_BGRX:
+return DRM_FORMAT_XRGB;
+case VA_FOURCC_ARGB:
+return DRM_FORMAT_BGRA;
+case VA_FOURCC_ABGR:
+return DRM_FORMAT_RGBA;
+}
+return 0;
+}
+
 static int vaapi_map_to_drm_esh(AVHWFramesContext *hwfc, AVFrame *dst,
 const AVFrame *src, int flags)
 {
@@ -1178,6 +1215,7 @@ static int vaapi_map_to_drm_esh(AVHWFramesContext *hwfc, 
AVFrame *dst,
 va_desc.layers[i].pitch[j];
 }
 }
+drm_desc->format = vaapi_va_fourcc_to_drm_format(va_desc.fourcc);
 
 err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
 _unmap_to_drm_esh, drm_desc);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 0/4] Add AVDRMFrameDescriptor.format field

2019-05-09 Thread Jonas Karlman
Hello,

When a multi-layer AVDRMFrameDescriptor is used to describe a frame the overall
frame format is missing and applications need to deduce the frame DRM_FORMAT_*
based on sw_format or the layers format.

This patchset adds a AVDRMFrameDescriptor.format field to remove any ambiguity
of what frame format a multi-layer descriptor may have.

Kodi has up until now only supported single layer AVDRMFrameDescriptor,
when trying to add support for multi-layer frame descriptors [1],
we did not want to try and deduce the frame format, hence this patchset.

[1] https://github.com/xbmc/xbmc/pull/16102

Patch 1 adds a new field, format, to the AVDRMFrameDescriptor struct.
Patch 2-4 adds code to set the new format field.

Regards,
Jonas

---

Jonas Karlman (4):
  hwcontext_drm: Add AVDRMFrameDescriptor.format field
  hwcontext_vaapi: Set AVDRMFrameDescriptor.format in map_from
  rkmppdec: Set AVDRMFrameDescriptor.format
  kmsgrab: Set AVDRMFrameDescriptor.format

 doc/APIchanges  |  3 +++
 libavcodec/rkmppdec.c   |  1 +
 libavdevice/kmsgrab.c   |  1 +
 libavutil/hwcontext_drm.h   |  4 
 libavutil/hwcontext_vaapi.c | 38 +
 libavutil/version.h |  4 ++--
 6 files changed, 49 insertions(+), 2 deletions(-)

-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 2/6] Add common V4L2 request API code

2019-04-09 Thread Jonas Karlman
On 2019-04-09 01:32, Jonas Karlman wrote:
> On 2019-04-09 00:35, James Almer wrote:
>> On 4/8/2019 5:12 PM, Jonas Karlman wrote:
>>> Signed-off-by: Jonas Karlman 
>>> ---
>>>  configure |   8 +
>>>  libavcodec/Makefile   |   1 +
>>>  libavcodec/hwaccel.h  |   2 +
>>>  libavcodec/v4l2_request.c | 885 ++
>>>  libavcodec/v4l2_request.h |  65 +++
>>>  5 files changed, 961 insertions(+)
>>>  create mode 100644 libavcodec/v4l2_request.c
>>>  create mode 100644 libavcodec/v4l2_request.h
>>> +int ff_v4l2_request_uninit(AVCodecContext *avctx)
>>> +{
>>> +V4L2RequestContext *ctx = avctx->internal->hwaccel_priv_data;
>>> +int ret;
>>> +
>>> +av_log(avctx, AV_LOG_DEBUG, "%s: avctx=%p ctx=%p\n", __func__, avctx, 
>>> ctx);
>>> +
>>> +if (ctx->video_fd >= 0) {
>>> +ret = ioctl(ctx->video_fd, VIDIOC_STREAMOFF, >output_type);
>>> +if (ret < 0)
>>> +av_log(avctx, AV_LOG_ERROR, "%s: output stream off failed, %s 
>>> (%d)\n", __func__, strerror(errno), errno);
>>> +
>>> +ret = ioctl(ctx->video_fd, VIDIOC_STREAMOFF, >format.type);
>>> +if (ret < 0)
>>> +av_log(avctx, AV_LOG_ERROR, "%s: capture stream off failed, %s 
>>> (%d)\n", __func__, strerror(errno), errno);
>>> +}
>>> +
>>> +if (avctx->hw_frames_ctx) {
>>> +AVHWFramesContext *hwfc = 
>>> (AVHWFramesContext*)avctx->hw_frames_ctx->data;
>>> +av_buffer_pool_reclaim(hwfc->pool);
>> What's the idea behind this? Calling this function will free all the
>> unused buffers currently residing in the pool, but will do nothing with
>> those already in assigned to some AVBufferRef created with
>> av_buffer_pool_get(). Those will in fact go back to the pool once they
>> are not needed anymore.
>>
>> Other than immediately freeing up some memory, the new function you
>> added is not going to do much. It wont be until av_buffer_pool_uninit()
>> is called and all the assigned buffers if any returned to the pool that
>> everything will be effectively freed.
> This was added to solve an issue with seeking h264 files, during seeking a 
> new hwaccel instance / buffer pool would be created (pps/sps changed)
> and since we need to pre-allocate output/capture buffers during hwaccel init 
> there was situations where too much CMA memory got consumed
> while there was multiple hwaccel instances / buffer pools active.
>
> This may have been a bigger issue in the beginning when we pre-allocated 20 
> buffers similar to vaapi hwaccel and when we had a bug in Kodi that
> would hold reference on two instead of one AVFrame while waiting on next 
> frame being decoded, in some situations (seeking too fast) this bug
> resulted in Kodi having reference on AVFrame's from three different buffer 
> pools requiring enough CMA memory for 60 capture and output buffers.
>
> We have since then fixed the bug in Kodi and minimized the number of buffers 
> that is pre-allocated in hwaccel.
> Immediately freeing up unused buffers helps the likelihood of successful 
> initializing a new hwaccel instance / buffer pool, especially useful for 4K 
> content.
>
> Regards,
> Jonas

I captured debug logs while playing a h264 video and seeking a few times, see 
http://ix.io/1FJ0 for the log.
There we can see that with the first call to ff_v4l2_request_uninit() there is 
9 unused buffers that immediately can be freed (around 90MiB)
while a new hwframes context is being created and the player is waiting on next 
decoded frame from seek point to be presented on screen.

Regards,
Jonas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 2/6] Add common V4L2 request API code

2019-04-08 Thread Jonas Karlman
On 2019-04-09 00:35, James Almer wrote:
> On 4/8/2019 5:12 PM, Jonas Karlman wrote:
>> Signed-off-by: Jonas Karlman 
>> ---
>>  configure |   8 +
>>  libavcodec/Makefile   |   1 +
>>  libavcodec/hwaccel.h  |   2 +
>>  libavcodec/v4l2_request.c | 885 ++
>>  libavcodec/v4l2_request.h |  65 +++
>>  5 files changed, 961 insertions(+)
>>  create mode 100644 libavcodec/v4l2_request.c
>>  create mode 100644 libavcodec/v4l2_request.h
>> +int ff_v4l2_request_uninit(AVCodecContext *avctx)
>> +{
>> +V4L2RequestContext *ctx = avctx->internal->hwaccel_priv_data;
>> +int ret;
>> +
>> +av_log(avctx, AV_LOG_DEBUG, "%s: avctx=%p ctx=%p\n", __func__, avctx, 
>> ctx);
>> +
>> +if (ctx->video_fd >= 0) {
>> +ret = ioctl(ctx->video_fd, VIDIOC_STREAMOFF, >output_type);
>> +if (ret < 0)
>> +av_log(avctx, AV_LOG_ERROR, "%s: output stream off failed, %s 
>> (%d)\n", __func__, strerror(errno), errno);
>> +
>> +ret = ioctl(ctx->video_fd, VIDIOC_STREAMOFF, >format.type);
>> +if (ret < 0)
>> +av_log(avctx, AV_LOG_ERROR, "%s: capture stream off failed, %s 
>> (%d)\n", __func__, strerror(errno), errno);
>> +}
>> +
>> +if (avctx->hw_frames_ctx) {
>> +AVHWFramesContext *hwfc = 
>> (AVHWFramesContext*)avctx->hw_frames_ctx->data;
>> +av_buffer_pool_reclaim(hwfc->pool);
> What's the idea behind this? Calling this function will free all the
> unused buffers currently residing in the pool, but will do nothing with
> those already in assigned to some AVBufferRef created with
> av_buffer_pool_get(). Those will in fact go back to the pool once they
> are not needed anymore.
>
> Other than immediately freeing up some memory, the new function you
> added is not going to do much. It wont be until av_buffer_pool_uninit()
> is called and all the assigned buffers if any returned to the pool that
> everything will be effectively freed.

This was added to solve an issue with seeking h264 files, during seeking a new 
hwaccel instance / buffer pool would be created (pps/sps changed)
and since we need to pre-allocate output/capture buffers during hwaccel init 
there was situations where too much CMA memory got consumed
while there was multiple hwaccel instances / buffer pools active.

This may have been a bigger issue in the beginning when we pre-allocated 20 
buffers similar to vaapi hwaccel and when we had a bug in Kodi that
would hold reference on two instead of one AVFrame while waiting on next frame 
being decoded, in some situations (seeking too fast) this bug
resulted in Kodi having reference on AVFrame's from three different buffer 
pools requiring enough CMA memory for 60 capture and output buffers.

We have since then fixed the bug in Kodi and minimized the number of buffers 
that is pre-allocated in hwaccel.
Immediately freeing up unused buffers helps the likelihood of successful 
initializing a new hwaccel instance / buffer pool, especially useful for 4K 
content.

Regards,
Jonas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 1/6] avutil: add av_buffer_pool_reclaim()

2019-04-08 Thread Jonas Karlman
On 2019-04-08 23:04, James Almer wrote:
> On 4/8/2019 5:12 PM, Jonas Karlman wrote:
>> Signed-off-by: Jonas Karlman 
>> ---
>>  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();
>>  }
>>  
>> +void av_buffer_pool_reclaim(AVBufferPool *pool)
>> +{
>> +ff_mutex_lock(>mutex);
>> +while (pool->pool) {
>> +BufferPoolEntry *buf = pool->pool;
>> +pool->pool = buf->next;
>> +
>> +buf->free(buf->opaque, buf->data);
>> +av_freep();
>> +}
>> +ff_mutex_unlock(>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);
> Maybe flush instead of reclaim? It'd be more in line with other API.
>
> Also, you need to add an entry for the new function in doc/APIChanges,
> and increase LIBAVUTIL_VERSION_MINOR by 1 in libavutil/version.h

Thanks, I will rename to av_buffer_pool_flush() and add to doc/APIChanges and 
fix LIBAVUTIL_VERSION_MINOR in v2.

Regards,
Jonas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 6/6] Add and use private linux headers for V4L2 request API ctrls

2019-04-08 Thread Jonas Karlman
On 2019-04-08 22:57, Carl Eugen Hoyos wrote:
> 2019-04-08 22:14 GMT+02:00, Jonas Karlman :
>> From: Jernej Skrabec 
>>
>> ---
>>  libavcodec/h264-ctrls.h | 192 +++
>>  libavcodec/hevc-ctrls.h | 197 
>>  libavcodec/mpeg2-ctrls.h|  82 +
>>  libavcodec/v4l2_request_h264.c  |   5 +-
>>  libavcodec/v4l2_request_hevc.c  |   1 +
>>  libavcodec/v4l2_request_mpeg2.c |   1 +
>>  6 files changed, 476 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/libavcodec/h264-ctrls.h b/libavcodec/h264-ctrls.h
>> new file mode 100644
>> index 00..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.
> If this is the sixth patch, how does compilation of the first
> five patches work without it?

It currently does not, the non-public kernel headers containing format ctrls 
was added to patchset if someone wants to compile the code.
I forgot to add a DO-NOT-MERGE tag to this patch, the V4L2 format ctrls should 
come from kernel linux/videodev2.h uapi header once they are stable in a future 
kernel version.

Regards,
Jonas

>
> Carl Eugen
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 2/6] Add common V4L2 request API code

2019-04-08 Thread Jonas Karlman
On 2019-04-08 22:52, Carl Eugen Hoyos wrote:
> 2019-04-08 22:12 GMT+02:00, Jonas Karlman :
>> Signed-off-by: Jonas Karlman 
>> ---
>>  configure |   8 +
>>  libavcodec/Makefile   |   1 +
>>  libavcodec/hwaccel.h  |   2 +
>>  libavcodec/v4l2_request.c | 885 ++
>>  libavcodec/v4l2_request.h |  65 +++
>>  5 files changed, 961 insertions(+)
>>  create mode 100644 libavcodec/v4l2_request.c
>>  create mode 100644 libavcodec/v4l2_request.h
>>
>> diff --git a/configure b/configure
>> index f6123f53e5..ea3945d34a 100755
>> --- a/configure
>> +++ b/configure
>> @@ -271,6 +271,7 @@ External library support:
>>--enable-libtls  enable LibreSSL (via libtls), needed for https
>> support
>> if openssl, gnutls or mbedtls is not used [no]
>>--enable-libtwolame  enable MP2 encoding via libtwolame [no]
>> +  --enable-libudev enable libudev [no]
>>--enable-libv4l2 enable libv4l2/v4l-utils [no]
>>--enable-libvidstab  enable video stabilization using vid.stab [no]
>>--enable-libvmaf enable vmaf filter via libvmaf [no]
>> @@ -335,6 +336,7 @@ External library support:
>>--enable-omx-rpi enable OpenMAX IL code for Raspberry Pi [no]
>>--enable-rkmpp   enable Rockchip Media Process Platform code [no]
>>--disable-v4l2-m2m   disable V4L2 mem2mem code [autodetect]
>> +  --enable-v4l2-requestenable V4L2 request API code [no]
> Why can't this be auto-detected?

I guess it could, will look into using auto-detected for v2.

Regards,
Jonas

>
> Carl Eugen
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [RFC 0/6] Add V4L2 request API hwaccels

2019-04-08 Thread Jonas Karlman
On 2019-04-08 22:41, Mark Thompson wrote:
> On 08/04/2019 21:09, Jonas Karlman wrote:
>> Hello,
>>
>> This is a request for comments on a new hwaccel using the V4L2 request API
>> that was created in collaboration with Jernej Skrabec.
>>
>> The V4L2 ctrls needed for statless decoding is not yet stable and reside in
>> private kernel headers. This patchset adds a copy of the kernel private 
>> headers
>> needed for the hwaccel to compile.
> When is the interface likely to become stable?

The V4L2 request API should already be considered stable and is part of linux 
uapi since v4.20.
Hwaccels make use of a function v4l2_timeval_to_ns that was added in v5.0, 
configure should check for this function.

The format ctrls needed for stateless decoding is however not stable and only 
MPEG-2 ctrls has been added
in a non-public kernel header at [1], it will hopefully be promoted to 
linux/videodev2.h uapi header in 2-4 linux versions.
H264 and HEVC ctrls is currently in review on linux-media mailing list and is 
even further away.

[1] https://github.com/torvalds/linux/blob/master/include/media/mpeg2-ctrls.h

>
> I don't think including kernel headers here is a good idea.  Please just 
> check for appropriate headers - if the user is capable of building this then 
> they can also install the headers for their kernel.

Sorry for not being more clear in my cover letter, the headers is not intended 
to be added to ffmpeg and was only added to patchset in order to be able to 
build working hwaccels.
The format ctrls has intentionally been put in non-public kernel headers that 
wont be installed into userspace since the ctrls currently is considered 
unstable.

My hope is to get early feedback on current code and to re-submit hwaccels once 
format ctrls have been promoted to public kernel uapi headers.

>
>
> If I wanted to buy a single Allwinner SBC to test this on, what should I get?

The Pine H64 "Model B" at [2] could be a good candidate.

The MPEG-2 hwaccel should also works on Rockchip RK3399 SBCs with rockchip vpu 
patchset at [3].
Support for Rockchip RK3288 SBCs requires additional patches at [4] and [5].

[2] https://www.pine64.org/?product_cat=model-b
[3] https://patchwork.kernel.org/project/linux-media/list/?series=87499
[4] 
https://github.com/Kwiboo/linux-rockchip/commit/1f78093e05c7360515a185f48b7c5cb8ba1e3e15
[5] 
https://github.com/Kwiboo/linux-rockchip/commit/9216da3f1521a0be5889235abe7fa093a4894160

Regards,
Jonas

>
> Thanks,
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [RFC 6/6] Add and use private linux headers for V4L2 request API ctrls

2019-04-08 Thread Jonas Karlman
From: Jernej Skrabec 

---
 libavcodec/h264-ctrls.h | 192 +++
 libavcodec/hevc-ctrls.h | 197 
 libavcodec/mpeg2-ctrls.h|  82 +
 libavcodec/v4l2_request_h264.c  |   5 +-
 libavcodec/v4l2_request_hevc.c  |   1 +
 libavcodec/v4l2_request_mpeg2.c |   1 +
 6 files changed, 476 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/libavcodec/h264-ctrls.h b/libavcodec/h264-ctrls.h
new file mode 100644
index 00..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_SPS0x0110
+#define V4L2_CTRL_TYPE_H264_PPS0x0111
+#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_INFERENCE0x40
+
+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 

[FFmpeg-devel] [RFC 5/6] Add V4L2 request API hevc hwaccel

2019-04-08 Thread Jonas Karlman
From: Jernej Skrabec 

Signed-off-by: Jernej Skrabec 
Signed-off-by: Jonas Karlman 
---
 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 b4fda11e13..6853ec258d 100755
--- a/configure
+++ b/configure
@@ -2893,6 +2893,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"
@@ -6386,6 +6388,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_headers sys/videoio.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a6b9f1b5e2..f13dd25212 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -878,6 +878,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 857c10dd12..bb9b7f28d1 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:
@@ -3577,6 +3584,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 00..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
+ * MERCHANTAB

[FFmpeg-devel] [RFC 4/6] Add V4L2 request API h264 hwaccel

2019-04-08 Thread Jonas Karlman
From: Jernej Skrabec 

Signed-off-by: Jernej Skrabec 
Signed-off-by: Jonas Karlman 
---
 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 79fa5530f1..b4fda11e13 100755
--- a/configure
+++ b/configure
@@ -2877,6 +2877,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"
@@ -6383,6 +6385,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_headers sys/videoio.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a26c6b38ea..a6b9f1b5e2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -870,6 +870,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 1c9a270fb6..a0bba6f17e 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -765,6 +765,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)
@@ -849,6 +850,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 837c3b7538..161fefba1c 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1075,6 +1075,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 00..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 Licens

[FFmpeg-devel] [RFC 3/6] Add V4L2 request API mpeg2 hwaccel

2019-04-08 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 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 ea3945d34a..79fa5530f1 100755
--- a/configure
+++ b/configure
@@ -2919,6 +2919,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"
@@ -6381,6 +6383,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_headers 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 796727dde7..a26c6b38ea 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -889,6 +889,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 00..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 siz

[FFmpeg-devel] [RFC 2/6] Add common V4L2 request API code

2019-04-08 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 configure |   8 +
 libavcodec/Makefile   |   1 +
 libavcodec/hwaccel.h  |   2 +
 libavcodec/v4l2_request.c | 885 ++
 libavcodec/v4l2_request.h |  65 +++
 5 files changed, 961 insertions(+)
 create mode 100644 libavcodec/v4l2_request.c
 create mode 100644 libavcodec/v4l2_request.h

diff --git a/configure b/configure
index f6123f53e5..ea3945d34a 100755
--- a/configure
+++ b/configure
@@ -271,6 +271,7 @@ External library support:
   --enable-libtls  enable LibreSSL (via libtls), needed for https 
support
if openssl, gnutls or mbedtls is not used [no]
   --enable-libtwolame  enable MP2 encoding via libtwolame [no]
+  --enable-libudev enable libudev [no]
   --enable-libv4l2 enable libv4l2/v4l-utils [no]
   --enable-libvidstab  enable video stabilization using vid.stab [no]
   --enable-libvmaf enable vmaf filter via libvmaf [no]
@@ -335,6 +336,7 @@ External library support:
   --enable-omx-rpi enable OpenMAX IL code for Raspberry Pi [no]
   --enable-rkmpp   enable Rockchip Media Process Platform code [no]
   --disable-v4l2-m2m   disable V4L2 mem2mem code [autodetect]
+  --enable-v4l2-requestenable V4L2 request API code [no]
   --disable-vaapi  disable Video Acceleration API (mainly Unix/Intel) 
code [autodetect]
   --disable-vdpau  disable Nvidia Video Decode and Presentation API 
for Unix code [autodetect]
   --disable-videotoolbox   disable VideoToolbox code [autodetect]
@@ -1786,6 +1788,7 @@ EXTERNAL_LIBRARY_LIST="
 libtesseract
 libtheora
 libtwolame
+libudev
 libv4l2
 libvorbis
 libvpx
@@ -1838,6 +1841,7 @@ HWACCEL_LIBRARY_LIST="
 mmal
 omx
 opencl
+v4l2_request
 "
 
 DOCUMENT_LIST="
@@ -2855,6 +2859,7 @@ d3d11va_deps="dxva_h ID3D11VideoDecoder 
ID3D11VideoContext"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 nvdec_deps="ffnvcodec"
+v4l2_request_deps="linux_videodev2_h linux_media_h v4l2_timeval_to_ns libdrm 
libudev"
 vaapi_x11_deps="xlib"
 videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
@@ -6201,6 +6206,7 @@ enabled libtls&& require_pkg_config libtls 
libtls tls.h tls_configur
 enabled libtwolame&& require libtwolame twolame.h twolame_init 
-ltwolame &&
  { check_lib libtwolame twolame.h 
twolame_encode_buffer_float32_interleaved -ltwolame ||
die "ERROR: libtwolame must be installed and 
version must be >= 0.3.10"; }
+enabled libudev   && require_pkg_config libudev libudev libudev.h 
udev_new
 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 >= 1.3.9" 
libvmaf.h compute_vmaf
@@ -6374,6 +6380,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;"
 
+check_func_headers "linux/media.h linux/videodev2.h" v4l2_timeval_to_ns
+
 check_headers 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 de873c1643..796727dde7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -147,6 +147,7 @@ OBJS-$(CONFIG_VP3DSP)  += vp3dsp.o
 OBJS-$(CONFIG_VP56DSP) += vp56dsp.o
 OBJS-$(CONFIG_VP8DSP)  += vp8dsp.o
 OBJS-$(CONFIG_V4L2_M2M)+= v4l2_m2m.o v4l2_context.o 
v4l2_buffers.o v4l2_fmt.o
+OBJS-$(CONFIG_V4L2_REQUEST)+= v4l2_request.o
 OBJS-$(CONFIG_WMA_FREQS)   += wma_freqs.o
 OBJS-$(CONFIG_WMV2DSP) += wmv2dsp.o
 
diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
index 3aaa92571c..2eefc91e7e 100644
--- a/libavcodec/hwaccel.h
+++ b/libavcodec/hwaccel.h
@@ -80,5 +80,7 @@ typedef struct AVCodecHWConfigInternal {
 HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD,  NONE, ff_ ## codec ## 
_d3d11va_hwaccel)
 #define HWACCEL_XVMC(codec) \
 HW_CONFIG_HWACCEL(0, 0, 1, XVMC, NONE, ff_ ## codec ## 
_xvmc_hwaccel)
+#define HWACCEL_V4L2REQUEST(codec) \
+HW_CONFIG_HWACCEL(1, 0, 0, DRM_PRIME,DRM,  ff_ ## codec ## 
_v4l2request_hwaccel)
 
 #endif /* AVCODEC_

[FFmpeg-devel] [RFC 1/6] avutil: add av_buffer_pool_reclaim()

2019-04-08 Thread Jonas Karlman
Signed-off-by: Jonas Karlman 
---
 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();
 }
 
+void av_buffer_pool_reclaim(AVBufferPool *pool)
+{
+ff_mutex_lock(>mutex);
+while (pool->pool) {
+BufferPoolEntry *buf = pool->pool;
+pool->pool = buf->next;
+
+buf->free(buf->opaque, buf->data);
+av_freep();
+}
+ff_mutex_unlock(>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.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [RFC 0/6] Add V4L2 request API hwaccels

2019-04-08 Thread Jonas Karlman
Hello,

This is a request for comments on a new hwaccel using the V4L2 request API
that was created in collaboration with Jernej Skrabec.

The V4L2 ctrls needed for statless decoding is not yet stable and reside in
private kernel headers. This patchset adds a copy of the kernel private headers
needed for the hwaccel to compile.

Patch 1 contains a new buffer pool function av_buffer_pool_reclaim() that will
free all available buffers in a buffer pool. This can be used to save memory
when seeking in e.g. H264 where a new hwaccel instance may get init:ed before
the current one is uninit. VAAPI may alloc 20+20 buffers during such overlap.

Patch 2 adds common code used in the hwaccels, libudev is used to enumerate
media and video devices to locate devices that supports stateless decoding.

Patch 3-5 adds hwaccels for MPEG-2, H264 and HEVC.

Patch 6 adds private linux headers for V4L2 ctrls. These headers will not be
needed once stable ctrls is moved to linux uapi headers.

Use --enable-v4l2-request --enable-libdrm --enable-libudev to enable hwaccels.

Playback can be tested using mpv patched with [1] or kodi-gbm on
Allwinner (H3, H6, A64) devices using the cedrus driver running linux v5.0.x
with patches from [2].

This hwaccel has in one form or another been used in Jernej Skrabec's
LibreELEC community images for Allwinner at [4] since Dec 20th 2018.

Latest work-in-progress version of this patchset can be found at [3].

Any feedback is welcomed, thanks.

[1] https://github.com/mpv-player/mpv/pull/6461
[2] 
https://github.com/LibreELEC/LibreELEC.tv/tree/allwinner/projects/Allwinner/patches/linux
[3] https://github.com/Kwiboo/FFmpeg/commits/v4l2-request-hwaccel
[4] 
https://forum.libreelec.tv/thread/13228-early-community-images-for-h3-h6-and-a64/?postID=99416#post99416

Regards,
Jonas

---

Jernej Skrabec (3):
  Add V4L2 request API h264 hwaccel
  Add V4L2 request API hevc hwaccel
  Add and use private linux headers for V4L2 request API ctrls

Jonas Karlman (3):
  avutil: add av_buffer_pool_reclaim()
  Add common V4L2 request API code
  Add V4L2 request API mpeg2 hwaccel

 configure   |  17 +
 libavcodec/Makefile |   4 +
 libavcodec/h264-ctrls.h | 192 +++
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hevc-ctrls.h | 197 +++
 libavcodec/hevcdec.c|  10 +
 libavcodec/hwaccel.h|   2 +
 libavcodec/hwaccels.h   |   3 +
 libavcodec/mpeg12dec.c  |   6 +
 libavcodec/mpeg2-ctrls.h|  82 +++
 libavcodec/v4l2_request.c   | 885 
 libavcodec/v4l2_request.h   |  65 +++
 libavcodec/v4l2_request_h264.c  | 369 +
 libavcodec/v4l2_request_hevc.c  | 392 ++
 libavcodec/v4l2_request_mpeg2.c | 155 ++
 libavutil/buffer.c  |  13 +
 libavutil/buffer.h  |   5 +
 18 files changed, 2404 insertions(+)
 create mode 100644 libavcodec/h264-ctrls.h
 create mode 100644 libavcodec/hevc-ctrls.h
 create mode 100644 libavcodec/mpeg2-ctrls.h
 create mode 100644 libavcodec/v4l2_request.c
 create mode 100644 libavcodec/v4l2_request.h
 create mode 100644 libavcodec/v4l2_request_h264.c
 create mode 100644 libavcodec/v4l2_request_hevc.c
 create mode 100644 libavcodec/v4l2_request_mpeg2.c

-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".