[FFmpeg-devel] [PATCH v2 1/2] lavfi/edge_common: Add 16bit versions of gaussian_blur and sobel

2022-07-11 Thread Thilo Borgmann

Hi,

1/2 adds 16 bit versions of ff_gaussian_blur and ff_sobel.

2/2 adds new mode to cropdetect.

Thanks,
ThiloFrom fc8c179e2de4dee3d32d2e02684f3e3215af63c6 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Sun, 10 Jul 2022 12:40:27 +0200
Subject: [PATCH v2 1/2] lavfi/edge_common: Add 16bit versions of gaussian_blur
 and sobel

---
 libavfilter/edge_common.c   | 134 
 libavfilter/edge_common.h   |  14 +++-
 libavfilter/vf_blurdetect.c |   4 +-
 libavfilter/vf_edgedetect.c |   4 +-
 4 files changed, 121 insertions(+), 35 deletions(-)

diff --git a/libavfilter/edge_common.c b/libavfilter/edge_common.c
index d72e8521cd..f0bf273b84 100644
--- a/libavfilter/edge_common.c
+++ b/libavfilter/edge_common.c
@@ -50,7 +50,7 @@ static int get_rounded_direction(int gx, int gy)
 void ff_sobel(int w, int h,
 uint16_t *dst, int dst_linesize,
 int8_t *dir, int dir_linesize,
-const uint8_t *src, int src_linesize)
+const uint8_t *src, int src_linesize, int src_stride)
 {
 int i, j;
 
@@ -60,13 +60,43 @@ void ff_sobel(int w, int h,
 src += src_linesize;
 for (i = 1; i < w - 1; i++) {
 const int gx =
--1*src[-src_linesize + i-1] + 1*src[-src_linesize + i+1]
--2*src[i-1] + 2*src[i+1]
--1*src[ src_linesize + i-1] + 1*src[ src_linesize + i+1];
+-1*src[-src_linesize + (i-1)*src_stride] + 1*src[-src_linesize 
+ (i+1)*src_stride]
+-2*src[(i-1)*src_stride] + 2*src[  
  (i+1)*src_stride]
+-1*src[ src_linesize + (i-1)*src_stride] + 1*src[ src_linesize 
+ (i+1)*src_stride];
 const int gy =
--1*src[-src_linesize + i-1] + 1*src[ src_linesize + i-1]
--2*src[-src_linesize + i  ] + 2*src[ src_linesize + i  ]
--1*src[-src_linesize + i+1] + 1*src[ src_linesize + i+1];
+-1*src[-src_linesize + (i-1)*src_stride] + 1*src[ src_linesize 
+ (i-1)*src_stride]
+-2*src[-src_linesize + (i  )*src_stride] + 2*src[ src_linesize 
+ (i  )*src_stride]
+-1*src[-src_linesize + (i+1)*src_stride] + 1*src[ src_linesize 
+ (i+1)*src_stride];
+
+dst[i] = FFABS(gx) + FFABS(gy);
+dir[i] = get_rounded_direction(gx, gy);
+}
+}
+}
+
+void ff_sobel16(int w, int h,
+uint16_t *dst, int dst_linesize,
+int8_t *dir, int dir_linesize,
+const uint8_t *src, int src_linesize, int src_stride)
+{
+int i, j;
+uint16_t *src16 = (uint16_t *)src;
+int src16_stride   = src_stride   / 2;
+int src16_linesize = src_linesize / 2;
+
+for (j = 1; j < h - 1; j++) {
+dst += dst_linesize;
+dir += dir_linesize;
+src16 += src16_linesize;
+for (i = 1; i < w - 1; i++) {
+const int gx =
+-1*src16[-src16_linesize + (i-1)*src16_stride] + 
1*src16[-src16_linesize + (i+1)*src16_stride]
+-2*src16[  (i-1)*src16_stride] + 2*src16[  
(i+1)*src16_stride]
+-1*src16[ src16_linesize + (i-1)*src16_stride] + 1*src16[ 
src16_linesize + (i+1)*src16_stride];
+const int gy =
+-1*src16[-src16_linesize + (i-1)*src16_stride] + 1*src16[ 
src16_linesize + (i-1)*src16_stride]
+-2*src16[-src16_linesize + (i  )*src16_stride] + 2*src16[ 
src16_linesize + (i  )*src16_stride]
+-1*src16[-src16_linesize + (i+1)*src16_stride] + 1*src16[ 
src16_linesize + (i+1)*src16_stride];
 
 dst[i] = FFABS(gx) + FFABS(gy);
 dir[i] = get_rounded_direction(gx, gy);
@@ -141,37 +171,37 @@ void ff_double_threshold(int low, int high, int w, int h,
 // Applies gaussian blur, using 5x5 kernels, sigma = 1.4
 void ff_gaussian_blur(int w, int h,
   uint8_t *dst, int dst_linesize,
-  const uint8_t *src, int src_linesize)
+  const uint8_t *src, int src_linesize, int src_stride)
 {
 int i, j;
 
 memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
 memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
 for (j = 2; j < h - 2; j++) {
-dst[0] = src[0];
-dst[1] = src[1];
+dst[0] = src[(0)*src_stride];
+dst[1] = src[(1)*src_stride];
 for (i = 2; i < w - 2; i++) {
 /* Gaussian mask of size 5x5 with sigma = 1.4 */
-dst[i] = ((src[-2*src_linesize + i-2] + src[2*src_linesize + i-2]) 
* 2
-+ (src[-2*src_linesize + i-1] + src[2*src_linesize + i-1]) 
* 4
-+ (src[-2*src_linesize + i  ] + src[2*src_linesize + i  ]) 
* 5
-+ (src[-2*src_linesize + i+1] + src[2*src_linesize + i+1]) 
* 4
-+ (src[-2*src_linesize + i+2] 

[FFmpeg-devel] [PATCH v2 2/2] lavfi/cropdetect: Add new mode to detect crop-area based on motion vectors and edges

2022-07-11 Thread Thilo Borgmann

$subject

-ThiloFrom ccc2b5ab29c4ca00c0a59af318fc865d37832377 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Mon, 11 Jul 2022 10:48:53 +0200
Subject: [PATCH v2 2/2] lavfi/cropdetect: Add new mode to detect crop-area
 based on motion vectors and edges

This filter allows crop detection even if the video is embedded in non-black 
areas.
---
 doc/filters.texi   |  42 +++-
 libavfilter/vf_cropdetect.c| 211 -
 tests/fate/filter-video.mak|   8 +-
 tests/ref/fate/filter-metadata-cropdetect1 |   9 +
 tests/ref/fate/filter-metadata-cropdetect2 |   9 +
 5 files changed, 276 insertions(+), 3 deletions(-)
 create mode 100644 tests/ref/fate/filter-metadata-cropdetect1
 create mode 100644 tests/ref/fate/filter-metadata-cropdetect2

diff --git a/doc/filters.texi b/doc/filters.texi
index d65e83d4d0..bd2d2429d7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10075,7 +10075,7 @@ Auto-detect the crop size.
 
 It calculates the necessary cropping parameters and prints the
 recommended parameters via the logging system. The detected dimensions
-correspond to the non-black area of the input video.
+correspond to the non-black or video area of the input video according to 
@var{mode}.
 
 It accepts the following parameters:
 
@@ -10106,8 +10106,48 @@ detect the current optimal crop area. Default value is 
0.
 This can be useful when channel logos distort the video area. 0
 indicates 'never reset', and returns the largest area encountered during
 playback.
+
+@item mv_threshold
+Set motion in pixel units as threshold for motion detection. It defaults to 8.
+
+@item low
+@item high
+Set low and high threshold values used by the Canny thresholding
+algorithm.
+
+The high threshold selects the "strong" edge pixels, which are then
+connected through 8-connectivity with the "weak" edge pixels selected
+by the low threshold.
+
+@var{low} and @var{high} threshold values must be chosen in the range
+[0,1], and @var{low} should be lesser or equal to @var{high}.
+
+Default value for @var{low} is @code{5/255}, and default value for @var{high}
+is @code{15/255}.
 @end table
 
+@subsection Examples
+
+@itemize
+@item
+Find video area surrounded by black borders:
+@example
+ffmpeg -i file.mp4 -vf cropdetect,metadata=mode=print -f null -
+@end example
+
+@item
+Find an embedded video area, generate motion vectors beforehand:
+@example
+ffmpeg -i file.mp4 -vf mestimate,cropdetect=mode=mvedges,metadata=mode=print 
-f null -
+@end example
+
+@item
+Find an embedded video area, use motion vectors from decoder:
+@example
+ffmpeg -flags2 +export_mvs -i file.mp4 -vf 
cropdetect=mode=mvedges,metadata=mode=print -f null -
+@end example
+@end itemize
+
 @anchor{cue}
 @section cue
 
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index b887b9ecb1..68313064bd 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -26,11 +26,14 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/motion_vector.h"
+#include "libavutil/qsort.h"
 
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
+#include "edge_common.h"
 
 typedef struct CropDetectContext {
 const AVClass *class;
@@ -42,6 +45,16 @@ typedef struct CropDetectContext {
 int frame_nb;
 int max_pixsteps[4];
 int max_outliers;
+int mode;
+int window_size;
+int mv_threshold;
+float   low, high;
+uint8_t low_u8, high_u8;
+uint8_t  *filterbuf;
+uint8_t  *tmpbuf;
+uint16_t *gradients;
+char *directions;
+int  *bboxes[4];
 } CropDetectContext;
 
 static const enum AVPixelFormat pix_fmts[] = {
@@ -61,6 +74,17 @@ static const enum AVPixelFormat pix_fmts[] = {
 AV_PIX_FMT_NONE
 };
 
+enum CropMode {
+MODE_BLACK,
+MODE_MV_EDGES,
+MODE_NB
+};
+
+static int comp(const int *a,const int *b)
+{
+return FFDIFFSIGN(*a, *b);
+}
+
 static int checkline(void *ctx, const unsigned char *src, int stride, int len, 
int bpp)
 {
 int total = 0;
@@ -116,11 +140,43 @@ static int checkline(void *ctx, const unsigned char *src, 
int stride, int len, i
 return total;
 }
 
+static int checkline_edge(void *ctx, const unsigned char *src, int stride, int 
len, int bpp)
+{
+const uint16_t *src16 = (const uint16_t *)src;
+
+switch (bpp) {
+case 1:
+while (--len >= 0) {
+if(src[0]) return 0;
+src += stride;
+}
+break;
+case 2:
+stride >>= 1;
+while (--len >= 0) {
+if(src16[0]) return 0;
+src16 += stride;
+}
+break;
+case 3:
+case 4:
+while (--len >= 0) {
+if(src[0] || src[1] || src[2]) return 0;
+src += stride;
+}
+break;
+}
+
+return 1;
+}
+
 static av_cold int init(AVFilterContext *ctx)
 {
 CropDetectContext *s = ctx->priv;
 
 s->fram

Re: [FFmpeg-devel] [PATCH] avcodec/aarch64: Access externs via GOT with PIC

2022-07-11 Thread Martin Storsjö

On Mon, 11 Jul 2022, Triang3l wrote:

However, static libraries barely have anything to configure overall as 
far as I know, so disabling exports specifically for FFmpeg may be 
complicated — but thankfully, we can (and even should, to reduce the 
file size) use -fvisibility=hidden globally in our application, if that 
helps fix the issue.


Yes, we could consider if we should build the libraries with 
-fvisibility=hidden (maybe as an option), but that's not always 
necessarily the best option. In particular we would want to set the 
default visibility for e.g. the public API symbols in that case. (Trying 
to export such symbols via the version script doesn't help, when they're 
explicitly set as hidden originally.)


Note that building your own application code with this option doesn't help 
much here; it's the libavcodec object files that would need to be build 
that way.


-Wl,-Bsymbolic should be fine too, and possibly even less 
intrusive.


Yes, that's quite non-intrusive, and should be easy to add as a linker 
option in your case.


If using __attribute__((visibility("hidden"))) for the lookup 
tables prevents dynamic relocations from being inserted, and if that 
doesn't break common usages of libavcodec, yes, it should be a way 
better solution than introducing an additional memory load at runtime.


I did a quick test with that and it seems like it works - I'll post a 
patch for that shortly.


If we're able to avoid using the global object table this way though, 
maybe it could be desirable to also get rid of `movrelx` in the AArch32 
code as well?


I wouldn't start touching that - if I remember correctly, movrelx is 
needed there for a bunch of other reasons - due to different relocation 
types and addressing modes there.


By the way, I'm also super confused by how the offset is applied in 
the local `movrel` currently, it looks very inconsistent. The `adrp` and 
`add` combination, as I understand its operation, should work for any 
32-bit literal value, not specifically for addresses of known objects — 
`adrp` accepting the upper 20 bits as a literal and adding them to the 
PC, and then `add` just adding the lower 12 bits, the offset within the 
page, also taken as a literal.


Trust me, it specifically needs to be like this for a reason.

if everything `movrel` does is adding the PC to the input literal… do we 
even need to emit `sub` for negative offsets in it?


When the final binary is linked and run, then yes, all the adrp+add pair 
does is add a literal to PC.


But before that, when an object file is assembled, the instruction opcodes 
can't be finalized with the actual literal value, as the distance from the 
adrp/add pair to the targeted symbol only is known at link time.


Therefore, the object file stores relocations that say "fix up this adrp 
instruction with the actual offset to 'symbol X + 42 bytes'". For ELF 
object files, the object file format and relocations allow a negative 
offset, but for MachO and COFF, it doesn't (or it might be limited 
accidentally by the tools). In either case; on MachO and COFF we can't 
practically express a relocation against "symbol minus some bytes" - so we 
produce an extra 'sub' instruction in those cases.


This is also true for the Windows implementation — whose existence 
overall is questionable, as Windows DLLs use a different relocation 
method, and PIC doesn't apply to them at all if I understand correctly;


While Windows code doesn't do proper strict PIC like on ELF, CONFIG_PIC 
does end up set in those configurations (like I already mentioned in the 
previous mail), and referencing symbols with adrp+add is generally 
preferrable over the non-PIC codepath of "ldr rX, =\val+\offset".


The latter will always store an absolute address in the constant island 
produced by the ldr pseudo instruction, and storing an absolute address 
emits a so called "base relocation" into the linked PE-COFF DLL. When a 
DLL is loaded at a non-default address, the loader will need to fix those 
up - essentially the same as text relocations on ELF. When using adrp+add 
on PE-COFF, no such base relocations are needed.


So while PE-COFF doesn't have true strict PIC, in practice you need very 
few base relocations on AArch64 - but if we'd skip the adrp+add 
instructions and use the non-PIC codepath of ldr as you suggest, we'd have 
much more base relocations.


is there a reason to emit the subtraction instruction that you can 
remember,


Yes, there is a reason.

or would it be safe to possibly even remove the offset argument 
completely?


No, it's not safe to remove that, it's clearly there for a reason.

// Martin
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Martin Storsjö
Signed-off-by: Martin Storsjö 
---
 doc/APIchanges | 3 +++
 libavutil/attributes.h | 6 ++
 libavutil/version.h| 2 +-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 20b944933a..5d84bc27d7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-xx-xx - xx - lavu 57.28.100 - attributes.h
+  Add av_visibility_hidden, for setting hidden visibilty on symbols.
+
 2022-06-12 - xx - lavf 59.25.100 - avio.h
   Add avio_vprintf(), similar to avio_printf() but allow to use it
   from within a function taking a variable argument list as input.
diff --git a/libavutil/attributes.h b/libavutil/attributes.h
index 04c615c952..dc4c88932c 100644
--- a/libavutil/attributes.h
+++ b/libavutil/attributes.h
@@ -170,4 +170,10 @@
 #define av_noreturn
 #endif
 
+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) 
|| defined(__MACH__))
+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif
+
 #endif /* AVUTIL_ATTRIBUTES_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 2e9e02dda8..87178e9e9a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  27
+#define LIBAVUTIL_VERSION_MINOR  28
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.25.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/2] libavcodec: Set hidden visibility on global symbols accessed from AArch64 assembly

2022-07-11 Thread Martin Storsjö
The AArch64 assembly accesses those symbols directly, without
indirection via e.g. the GOT on ELF. In order for this not to
require text relocations, those symbols need to be resolved fully
at link time, i.e. those symbols can't be interposable.

Normally, so far, this is achieved when linking shared libraries
in two ways; we have a version script (libavcodec/libavcodec.v) which
marks all symbols that don't start with av* as local. Additionally,
we try to add -Wl,-Bsymbolic to the linker options if supported,
making sure that such symbol references are resolved fully at link
time, instead of making them interposable.

When the libavcodec static library is linked into another shared
library, there's no guarantee that it uses similar options (even though
that would be favourable), which would end up requiring text relocations
in the AArch64 assembly.

Explicitly mark the symbols that are accessed from AArch64 assembly
as hidden, so that they are resolved fully at link time even without
the version script and -Wl,-Bsymbolic.

Signed-off-by: Martin Storsjö 
---
 libavcodec/aacsbrdata.h | 2 +-
 libavcodec/fft.h| 2 +-
 libavcodec/vp9dsp.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/aacsbrdata.h b/libavcodec/aacsbrdata.h
index 7a11594c9b..aa382c4b52 100644
--- a/libavcodec/aacsbrdata.h
+++ b/libavcodec/aacsbrdata.h
@@ -268,7 +268,7 @@ static const int8_t sbr_offset[6][16] = {
 };
 
 /* First eight entries repeated at end to simplify SIMD implementations. */
-const DECLARE_ALIGNED(16, INTFLOAT, AAC_RENAME(ff_sbr_noise_table))[][2] = {
+const av_visibility_hidden DECLARE_ALIGNED(16, INTFLOAT, 
AAC_RENAME(ff_sbr_noise_table))[][2] = {
 {Q31(-0.99948153278296f), Q31(-0.59483417516607f)}, {Q31( 0.97113454393991f), 
Q31(-0.67528515225647f)},
 {Q31( 0.14130051758487f), Q31(-0.95090983575689f)}, {Q31(-0.47005496701697f), 
Q31(-0.37340549728647f)},
 {Q31( 0.80705063769351f), Q31( 0.29653668284408f)}, {Q31(-0.38981478896926f), 
Q31( 0.89572605717087f)},
diff --git a/libavcodec/fft.h b/libavcodec/fft.h
index 706c9d07f5..c2241fbc7c 100644
--- a/libavcodec/fft.h
+++ b/libavcodec/fft.h
@@ -114,7 +114,7 @@ void ff_init_ff_cos_tabs(int index);
 #endif
 
 #define COSTABLE(size) \
-COSTABLE_CONST DECLARE_ALIGNED(32, FFTSample, 
FFT_NAME(ff_cos_##size))[size/2]
+COSTABLE_CONST av_visibility_hidden DECLARE_ALIGNED(32, FFTSample, 
FFT_NAME(ff_cos_##size))[size/2]
 
 extern COSTABLE(16);
 extern COSTABLE(32);
diff --git a/libavcodec/vp9dsp.c b/libavcodec/vp9dsp.c
index d8ddf74d4f..1be942d78b 100644
--- a/libavcodec/vp9dsp.c
+++ b/libavcodec/vp9dsp.c
@@ -29,7 +29,7 @@
 
 #include "vp9dsp.h"
 
-const DECLARE_ALIGNED(16, int16_t, ff_vp9_subpel_filters)[3][16][8] = {
+const av_visibility_hidden DECLARE_ALIGNED(16, int16_t, 
ff_vp9_subpel_filters)[3][16][8] = {
 [FILTER_8TAP_REGULAR] = {
 {  0,  0,   0, 128,   0,   0,  0,  0 },
 {  0,  1,  -5, 126,   8,  -3,  1,  0 },
-- 
2.25.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 1/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Andreas Rheinhardt
Martin Storsjö:
> Signed-off-by: Martin Storsjö 
> ---
>  doc/APIchanges | 3 +++
>  libavutil/attributes.h | 6 ++
>  libavutil/version.h| 2 +-
>  3 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 20b944933a..5d84bc27d7 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,9 @@ libavutil: 2021-04-27
>  
>  API changes, most recent first:
>  
> +2022-xx-xx - xx - lavu 57.28.100 - attributes.h
> +  Add av_visibility_hidden, for setting hidden visibilty on symbols.
> +
>  2022-06-12 - xx - lavf 59.25.100 - avio.h
>Add avio_vprintf(), similar to avio_printf() but allow to use it
>from within a function taking a variable argument list as input.
> diff --git a/libavutil/attributes.h b/libavutil/attributes.h
> index 04c615c952..dc4c88932c 100644
> --- a/libavutil/attributes.h
> +++ b/libavutil/attributes.h
> @@ -170,4 +170,10 @@
>  #define av_noreturn
>  #endif
>  
> +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && 
> (defined(__ELF__) || defined(__MACH__))
> +#define av_visibility_hidden __attribute__((visibility("hidden")))
> +#else
> +#define av_visibility_hidden
> +#endif
> +
>  #endif /* AVUTIL_ATTRIBUTES_H */
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 2e9e02dda8..87178e9e9a 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  57
> -#define LIBAVUTIL_VERSION_MINOR  27
> +#define LIBAVUTIL_VERSION_MINOR  28
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Hidden stuff is by definition not part of installed headers, so that
there is no point in adding a public define for this.
(Anyway: visibilty is not the correct spelling.)

- Andreas
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Martin Storsjö

On Mon, 11 Jul 2022, Andreas Rheinhardt wrote:


Martin Storsjö:

Signed-off-by: Martin Storsjö 
---
 doc/APIchanges | 3 +++
 libavutil/attributes.h | 6 ++
 libavutil/version.h| 2 +-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 20b944933a..5d84bc27d7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27

 API changes, most recent first:

+2022-xx-xx - xx - lavu 57.28.100 - attributes.h
+  Add av_visibility_hidden, for setting hidden visibilty on symbols.
+
 2022-06-12 - xx - lavf 59.25.100 - avio.h
   Add avio_vprintf(), similar to avio_printf() but allow to use it
   from within a function taking a variable argument list as input.
diff --git a/libavutil/attributes.h b/libavutil/attributes.h
index 04c615c952..dc4c88932c 100644
--- a/libavutil/attributes.h
+++ b/libavutil/attributes.h
@@ -170,4 +170,10 @@
 #define av_noreturn
 #endif

+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) 
|| defined(__MACH__))
+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif
+
 #endif /* AVUTIL_ATTRIBUTES_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 2e9e02dda8..87178e9e9a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */

 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  27
+#define LIBAVUTIL_VERSION_MINOR  28
 #define LIBAVUTIL_VERSION_MICRO 100

 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


Hidden stuff is by definition not part of installed headers, so that
there is no point in adding a public define for this.


Good point - attribute.h would otherwise have been the natural spot, but I 
agree that it'd be better to not make it public at all. In what header 
would you prefer to have it?


// Martin
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Andreas Rheinhardt
Martin Storsjö:
> On Mon, 11 Jul 2022, Andreas Rheinhardt wrote:
> 
>> Martin Storsjö:
>>> Signed-off-by: Martin Storsjö 
>>> ---
>>>  doc/APIchanges | 3 +++
>>>  libavutil/attributes.h | 6 ++
>>>  libavutil/version.h    | 2 +-
>>>  3 files changed, 10 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/doc/APIchanges b/doc/APIchanges
>>> index 20b944933a..5d84bc27d7 100644
>>> --- a/doc/APIchanges
>>> +++ b/doc/APIchanges
>>> @@ -14,6 +14,9 @@ libavutil: 2021-04-27
>>>
>>>  API changes, most recent first:
>>>
>>> +2022-xx-xx - xx - lavu 57.28.100 - attributes.h
>>> +  Add av_visibility_hidden, for setting hidden visibilty on symbols.
>>> +
>>>  2022-06-12 - xx - lavf 59.25.100 - avio.h
>>>    Add avio_vprintf(), similar to avio_printf() but allow to use it
>>>    from within a function taking a variable argument list as input.
>>> diff --git a/libavutil/attributes.h b/libavutil/attributes.h
>>> index 04c615c952..dc4c88932c 100644
>>> --- a/libavutil/attributes.h
>>> +++ b/libavutil/attributes.h
>>> @@ -170,4 +170,10 @@
>>>  #    define av_noreturn
>>>  #endif
>>>
>>> +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) &&
>>> (defined(__ELF__) || defined(__MACH__))
>>> +#    define av_visibility_hidden __attribute__((visibility("hidden")))
>>> +#else
>>> +#    define av_visibility_hidden
>>> +#endif
>>> +
>>>  #endif /* AVUTIL_ATTRIBUTES_H */
>>> diff --git a/libavutil/version.h b/libavutil/version.h
>>> index 2e9e02dda8..87178e9e9a 100644
>>> --- a/libavutil/version.h
>>> +++ b/libavutil/version.h
>>> @@ -79,7 +79,7 @@
>>>   */
>>>
>>>  #define LIBAVUTIL_VERSION_MAJOR  57
>>> -#define LIBAVUTIL_VERSION_MINOR  27
>>> +#define LIBAVUTIL_VERSION_MINOR  28
>>>  #define LIBAVUTIL_VERSION_MICRO 100
>>>
>>>  #define LIBAVUTIL_VERSION_INT  
>>> AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
>>
>> Hidden stuff is by definition not part of installed headers, so that
>> there is no point in adding a public define for this.
> 
> Good point - attribute.h would otherwise have been the natural spot, but
> I agree that it'd be better to not make it public at all. In what header
> would you prefer to have it?
> 

The typical place we put such things is libavutil/internal.h.

- Andreas
___
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 2/2] libavcodec: Set hidden visibility on global symbols accessed from AArch64 assembly

2022-07-11 Thread Andreas Rheinhardt
Martin Storsjö:
> The AArch64 assembly accesses those symbols directly, without
> indirection via e.g. the GOT on ELF. In order for this not to
> require text relocations, those symbols need to be resolved fully
> at link time, i.e. those symbols can't be interposable.
> 
> Normally, so far, this is achieved when linking shared libraries
> in two ways; we have a version script (libavcodec/libavcodec.v) which
> marks all symbols that don't start with av* as local. Additionally,
> we try to add -Wl,-Bsymbolic to the linker options if supported,
> making sure that such symbol references are resolved fully at link
> time, instead of making them interposable.
> 
> When the libavcodec static library is linked into another shared
> library, there's no guarantee that it uses similar options (even though
> that would be favourable), which would end up requiring text relocations
> in the AArch64 assembly.
> 
> Explicitly mark the symbols that are accessed from AArch64 assembly
> as hidden, so that they are resolved fully at link time even without
> the version script and -Wl,-Bsymbolic.
> 
> Signed-off-by: Martin Storsjö 
> ---
>  libavcodec/aacsbrdata.h | 2 +-
>  libavcodec/fft.h| 2 +-
>  libavcodec/vp9dsp.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/aacsbrdata.h b/libavcodec/aacsbrdata.h
> index 7a11594c9b..aa382c4b52 100644
> --- a/libavcodec/aacsbrdata.h
> +++ b/libavcodec/aacsbrdata.h
> @@ -268,7 +268,7 @@ static const int8_t sbr_offset[6][16] = {
>  };
>  
>  /* First eight entries repeated at end to simplify SIMD implementations. */
> -const DECLARE_ALIGNED(16, INTFLOAT, AAC_RENAME(ff_sbr_noise_table))[][2] = {
> +const av_visibility_hidden DECLARE_ALIGNED(16, INTFLOAT, 
> AAC_RENAME(ff_sbr_noise_table))[][2] = {
>  {Q31(-0.99948153278296f), Q31(-0.59483417516607f)}, {Q31( 
> 0.97113454393991f), Q31(-0.67528515225647f)},
>  {Q31( 0.14130051758487f), Q31(-0.95090983575689f)}, 
> {Q31(-0.47005496701697f), Q31(-0.37340549728647f)},
>  {Q31( 0.80705063769351f), Q31( 0.29653668284408f)}, 
> {Q31(-0.38981478896926f), Q31( 0.89572605717087f)},
> diff --git a/libavcodec/fft.h b/libavcodec/fft.h
> index 706c9d07f5..c2241fbc7c 100644
> --- a/libavcodec/fft.h
> +++ b/libavcodec/fft.h
> @@ -114,7 +114,7 @@ void ff_init_ff_cos_tabs(int index);
>  #endif
>  
>  #define COSTABLE(size) \
> -COSTABLE_CONST DECLARE_ALIGNED(32, FFTSample, 
> FFT_NAME(ff_cos_##size))[size/2]
> +COSTABLE_CONST av_visibility_hidden DECLARE_ALIGNED(32, FFTSample, 
> FFT_NAME(ff_cos_##size))[size/2]
>  
>  extern COSTABLE(16);
>  extern COSTABLE(32);
> diff --git a/libavcodec/vp9dsp.c b/libavcodec/vp9dsp.c
> index d8ddf74d4f..1be942d78b 100644
> --- a/libavcodec/vp9dsp.c
> +++ b/libavcodec/vp9dsp.c
> @@ -29,7 +29,7 @@
>  
>  #include "vp9dsp.h"
>  
> -const DECLARE_ALIGNED(16, int16_t, ff_vp9_subpel_filters)[3][16][8] = {
> +const av_visibility_hidden DECLARE_ALIGNED(16, int16_t, 
> ff_vp9_subpel_filters)[3][16][8] = {

Shouldn't you set this in vp9dsp.h, so that all users of it can benefit
from knowing that this symbol is always in the same DSO?

>  [FILTER_8TAP_REGULAR] = {
>  {  0,  0,   0, 128,   0,   0,  0,  0 },
>  {  0,  1,  -5, 126,   8,  -3,  1,  0 },

___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Henrik Gramner
On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:
> +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && 
> (defined(__ELF__) || defined(__MACH__))
> +#define av_visibility_hidden __attribute__((visibility("hidden")))
> +#else
> +#define av_visibility_hidden
> +#endif

The usual approach is to compile with -fvisibility=hidden and
explicitly flag exported API symbols.

Is there a reason for doing this the other way around?
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Triang3l
Yes, making everything except for av_ hidden by default would be more 
consistent with the current build process, which includes libavcodec.v. 
Though, this is a special case that results not only in increasing the 
shared object file size if libavcodec.v is not used, which is 
undesirable, yet harmless, but also in making the library not linkable 
with PIC at all unless those symbols are hidden or forced to be resolved 
at link time some other way.


Thanks for implementing the fix very quickly, by the way!

I'd also suggest writing a comment in the code describing specifically 
the original issue that the current instances of the usage of 
visibility("hidden") resolves, so the reason why it's used there is not 
forgotten, and there's a clear pattern of relation between movrel X() 
and av_visibility_hidden to follow when adding new assembly code. Though 
if the convention is to rely on `git blame` for this purpose, that 
shouldn't be necessary.


— Triang3l

On 11/07/2022 15:12, Henrik Gramner wrote:

On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:

+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) 
|| defined(__MACH__))
+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif

The usual approach is to compile with -fvisibility=hidden and
explicitly flag exported API symbols.

Is there a reason for doing this the other way around?
___
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".


Re: [FFmpeg-devel] [PATCH 1/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Andreas Rheinhardt
Henrik Gramner:
> On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:
>> +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && 
>> (defined(__ELF__) || defined(__MACH__))
>> +#define av_visibility_hidden __attribute__((visibility("hidden")))
>> +#else
>> +#define av_visibility_hidden
>> +#endif
> 
> The usual approach is to compile with -fvisibility=hidden and
> explicitly flag exported API symbols.
> 
> Is there a reason for doing this the other way around?

-fvisibility=hidden only affects the visibility of symbols defined in
the currently compiled translation unit. It does not allow the compiler
to make assumptions about external declarations that are used in this
translation unit (in other words, it has to presume the worst: That it
comes from a different DSO). E.g. this is ff_rdft_end on 32bit x86 if
ff_fft_end is declared with an explicit hidden attribute:

00bb :

  bb:   83 44 24 04 18  addl   $0x18,0x4(%esp)

  c0:   e9 fc ff ff ff  jmpc1 

c1: R_386_PC32  ff_fft_end


And this is the same function if one uses -fvisibility=hidden instead of
the attribute:

00bb :

  bb:   53  push   %ebx

  bc:   e8 fc ff ff ff  call   bd 

bd: R_386_PC32  __x86.get_pc_thunk.bx

  c1:   81 c3 02 00 00 00   add$0x2,%ebx

c3: R_386_GOTPC _GLOBAL_OFFSET_TABLE_

  c7:   83 ec 14sub$0x14,%esp

  ca:   8b 44 24 1c mov0x1c(%esp),%eax

  ce:   83 c0 18add$0x18,%eax

  d1:   50  push   %eax

  d2:   e8 fc ff ff ff  call   d3 

d3: R_386_PLT32 ff_fft_end

  d7:   83 c4 18add$0x18,%esp

  da:   5b  pop%ebx

  db:   c3  ret


The code is the same as if one had not used -fvisibility=hidden at all.

Of course, adding the attribute to every function/object is way too much
effort; that's why the pragma exists.

- Andreas
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Timo Rothenpieler

On 11.07.2022 16:26, Andreas Rheinhardt wrote:

Henrik Gramner:

On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:

+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) 
|| defined(__MACH__))
+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif


The usual approach is to compile with -fvisibility=hidden and
explicitly flag exported API symbols.

Is there a reason for doing this the other way around?


-fvisibility=hidden only affects the visibility of symbols defined in
the currently compiled translation unit. It does not allow the compiler
to make assumptions about external declarations that are used in this
translation unit (in other words, it has to presume the worst: That it
comes from a different DSO). E.g. this is ff_rdft_end on 32bit x86 if
ff_fft_end is declared with an explicit hidden attribute:

00bb :

   bb:  83 44 24 04 18  addl   $0x18,0x4(%esp)

   c0:  e9 fc ff ff ff  jmpc1 

c1: R_386_PC32  ff_fft_end


And this is the same function if one uses -fvisibility=hidden instead of
the attribute:

00bb :

   bb:  53  push   %ebx

   bc:  e8 fc ff ff ff  call   bd 

bd: R_386_PC32  __x86.get_pc_thunk.bx

   c1:  81 c3 02 00 00 00   add$0x2,%ebx

c3: R_386_GOTPC _GLOBAL_OFFSET_TABLE_

   c7:  83 ec 14sub$0x14,%esp

   ca:  8b 44 24 1c mov0x1c(%esp),%eax

   ce:  83 c0 18add$0x18,%eax

   d1:  50  push   %eax

   d2:  e8 fc ff ff ff  call   d3 

d3: R_386_PLT32 ff_fft_end

   d7:  83 c4 18add$0x18,%esp

   da:  5b  pop%ebx

   db:  c3  ret


The code is the same as if one had not used -fvisibility=hidden at all.

Of course, adding the attribute to every function/object is way too much
effort; that's why the pragma exists.


Is this still true if you also add -fno-semantic-interposition?
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Andreas Rheinhardt
Timo Rothenpieler:
> On 11.07.2022 16:26, Andreas Rheinhardt wrote:
>> Henrik Gramner:
>>> On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö 
>>> wrote:
 +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) &&
 (defined(__ELF__) || defined(__MACH__))
 +#    define av_visibility_hidden __attribute__((visibility("hidden")))
 +#else
 +#    define av_visibility_hidden
 +#endif
>>>
>>> The usual approach is to compile with -fvisibility=hidden and
>>> explicitly flag exported API symbols.
>>>
>>> Is there a reason for doing this the other way around?
>>
>> -fvisibility=hidden only affects the visibility of symbols defined in
>> the currently compiled translation unit. It does not allow the compiler
>> to make assumptions about external declarations that are used in this
>> translation unit (in other words, it has to presume the worst: That it
>> comes from a different DSO). E.g. this is ff_rdft_end on 32bit x86 if
>> ff_fft_end is declared with an explicit hidden attribute:
>>
>> 00bb :
>>
>>    bb:    83 44 24 04 18   addl   $0x18,0x4(%esp)
>>
>>    c0:    e9 fc ff ff ff   jmp    c1 
>>
>>     c1: R_386_PC32    ff_fft_end
>>
>>
>> And this is the same function if one uses -fvisibility=hidden instead of
>> the attribute:
>>
>> 00bb :
>>
>>    bb:    53   push   %ebx
>>
>>    bc:    e8 fc ff ff ff   call   bd 
>>
>>     bd: R_386_PC32    __x86.get_pc_thunk.bx
>>
>>    c1:    81 c3 02 00 00 00    add    $0x2,%ebx
>>
>>     c3: R_386_GOTPC    _GLOBAL_OFFSET_TABLE_
>>
>>    c7:    83 ec 14 sub    $0x14,%esp
>>
>>    ca:    8b 44 24 1c  mov    0x1c(%esp),%eax
>>
>>    ce:    83 c0 18 add    $0x18,%eax
>>
>>    d1:    50   push   %eax
>>
>>    d2:    e8 fc ff ff ff   call   d3 
>>
>>     d3: R_386_PLT32    ff_fft_end
>>
>>    d7:    83 c4 18 add    $0x18,%esp
>>
>>    da:    5b   pop    %ebx
>>
>>    db:    c3   ret
>>
>>
>> The code is the same as if one had not used -fvisibility=hidden at all.
>>
>> Of course, adding the attribute to every function/object is way too much
>> effort; that's why the pragma exists.
> 
> Is this still true if you also add -fno-semantic-interposition?

Why should that change anything here? It just means that the compiler
may inline functions even though they could potentially be interposed.
But of course the compiler can't inline functions whose definition it
can't see.
Anyway, I tested it and there is no change.

- Andreas
___
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] avformat/flacdec: Implement decoding of 32-bit PCM

2022-07-11 Thread Martijn van Beurden
Op ma 20 jun. 2022 om 22:14 schreef Martijn van Beurden :

> Recently libFLAC gained the ability (not in any released version yet
> though) to create FLAC files containing 32-bit int PCM samples. To
> keep complexity reasonable, the choice was made to limit residuals
> to 32-bit integers, which the encoder must make sure of. In case
> the encoder cannot find any predictor of which the residuals fit
> this limit, it must default to using a verbatim subframe. Tests have
> shown that this does not happen often (<0.1% of subframes on a
> music corpus of various styles). See also discussion here:
> https://github.com/ietf-wg-cellar/flac-specification/pull/148
>
> This patch adds decoding of these files to ffmpeg.
> ---
>  libavcodec/flac.c |   4 +-
>  libavcodec/flacdec.c  | 248 ++
>  libavcodec/get_bits.h |  12 ++
>  libavcodec/mathops.h  |   9 ++
>  4 files changed, 250 insertions(+), 23 deletions(-)
>
> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index dd68830622..f326d8fa5c 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -27,7 +27,7 @@
>  #include "flac.h"
>  #include "flacdata.h"
>
> -static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
> +static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 32 };
>
>  static const AVChannelLayout flac_channel_layouts[8] = {
>  AV_CHANNEL_LAYOUT_MONO,
> @@ -81,7 +81,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx,
> GetBitContext *gb,
>
>  /* bits per sample */
>  bps_code = get_bits(gb, 3);
> -if (bps_code == 3 || bps_code == 7) {
> +if (bps_code == 3) {
>  av_log(avctx, AV_LOG_ERROR + log_level_offset,
> "invalid sample size code (%d)\n",
> bps_code);
> diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
> index 87f20c7425..49952ce120 100644
> --- a/libavcodec/flacdec.c
> +++ b/libavcodec/flacdec.c
> @@ -63,6 +63,9 @@ typedef struct FLACContext {
>  int32_t *decoded[FLAC_MAX_CHANNELS];///< decoded samples
>  uint8_t *decoded_buffer;
>  unsigned int decoded_buffer_size;
> +int64_t *decoded_33bps;  ///< decoded samples for a
> 33 bps subframe
> +uint8_t *decoded_buffer_33bps;
> +unsigned int decoded_buffer_size_33bps;
>  int buggy_lpc;  ///< use workaround for old
> lavc encoded files
>
>  FLACDSPContext dsp;
> @@ -154,6 +157,24 @@ static int allocate_buffers(FLACContext *s)
>   s->flac_stream_info.channels,
>   s->flac_stream_info.max_blocksize,
>   AV_SAMPLE_FMT_S32P, 0);
> +if (ret >= 0 && s->flac_stream_info.bps == 32 &&
> s->flac_stream_info.channels == 2) {
> +buf_size = av_samples_get_buffer_size(NULL, 1,
> +
> s->flac_stream_info.max_blocksize,
> +  AV_SAMPLE_FMT_S64P, 0);
> +if (buf_size < 0)
> +return buf_size;
> +
> +av_fast_malloc(&s->decoded_buffer_33bps,
> &s->decoded_buffer_size_33bps, buf_size);
> +if (!s->decoded_buffer)
> +return AVERROR(ENOMEM);
> +
> +ret = av_samples_fill_arrays((uint8_t **)&s->decoded_33bps, NULL,
> + s->decoded_buffer_33bps,
> + 1,
> + s->flac_stream_info.max_blocksize,
> + AV_SAMPLE_FMT_S64P, 0);
> +
> +}
>  return ret < 0 ? ret : 0;
>  }
>
> @@ -331,6 +352,94 @@ static int decode_subframe_fixed(FLACContext *s,
> int32_t *decoded,
>  return 0;
>  }
>
> +static int decode_subframe_fixed_wide(FLACContext *s, int32_t *decoded,
> +  int pred_order, int bps)
> +{
> +const int blocksize = s->blocksize;
> +int i;
> +int ret;
> +
> +/* warm up samples */
> +for (i = 0; i < pred_order; i++) {
> +decoded[i] = get_sbits_long(&s->gb, bps);
> +}
> +
> +if ((ret = decode_residuals(s, decoded, pred_order)) < 0)
> +return ret;
> +
> +switch (pred_order) {
> +case 0:
> +break;
> +case 1:
> +for (i = pred_order; i < blocksize; i++)
> +decoded[i] += decoded[i-1];
> +break;
> +case 2:
> +for (i = pred_order; i < blocksize; i++)
> +decoded[i] = (int64_t)decoded[i] + 2*(int64_t)decoded[i-1] -
> (int64_t)decoded[i-2];
> +break;
> +case 3:
> +for (i = pred_order; i < blocksize; i++)
> +decoded[i] = (int64_t)decoded[i] + 3*(int64_t)decoded[i-1] -
> 3*(int64_t)decoded[i-2] + (int64_t)decoded[i-3];
> +break;
> +case 4:
> +for (i = pred_order; i < blocksize; i++)
> +decoded[i] = (int64_t)decoded[i] + 4*(int64_t)decoded[i-1] -
> 6*(int64_t)decoded[i-2] + 4*(int64_t)decoded[i-3] - (int64_t)decoded[i-4];
> +break;
> +default:
> +

Re: [FFmpeg-devel] [PATCH 1/2] lavc/aarch64: Assign callback with function

2022-07-11 Thread Martin Storsjö

On Wed, 29 Jun 2022, Hubert Mazur wrote:


Assign c->sad[0] callback with already existing neon implementation
of pix_abs16 function.

Signed-off-by: Hubert Mazur 
---
libavcodec/aarch64/me_cmp_init_aarch64.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c 
b/libavcodec/aarch64/me_cmp_init_aarch64.c
index 9fb63e9973..bec9148a1a 100644
--- a/libavcodec/aarch64/me_cmp_init_aarch64.c
+++ b/libavcodec/aarch64/me_cmp_init_aarch64.c
@@ -35,5 +35,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, 
AVCodecContext *avctx)
if (have_neon(cpu_flags)) {
c->pix_abs[0][0] = ff_pix_abs16_neon;
c->pix_abs[0][3] = ff_pix_abs16_xy2_neon;
+
+c->sad[0] = ff_pix_abs16_neon;
}
}
--
2.34.1


LGTM, although I wouldn't use the word "callback" for these. I'll push 
this with a reworded commit message.


// Martin

___
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 2/2] lavc/aarch64: Add pix_abs16_x2 neon implementation

2022-07-11 Thread Martin Storsjö

On Wed, 29 Jun 2022, Hubert Mazur wrote:


Provide neon implementation for pix_abs16_x2 function.

Performance tests of implementation are below.
- pix_abs_0_1_c: 291.9
- pix_abs_0_1_neon: 73.7

Benchmarks and tests run with checkasm tool on AWS Graviton 3.

Signed-off-by: Hubert Mazur 
---
libavcodec/aarch64/me_cmp_init_aarch64.c |   3 +
libavcodec/aarch64/me_cmp_neon.S | 134 +++
2 files changed, 137 insertions(+)

diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S
index a7937bd8be..c2fd94f4b3 100644
--- a/libavcodec/aarch64/me_cmp_neon.S
+++ b/libavcodec/aarch64/me_cmp_neon.S
@@ -203,3 +203,137 @@ function ff_pix_abs16_xy2_neon, export=1
fmovw0, s0  // copy result to general 
purpose register
ret
endfunc
+
+function ff_pix_abs16_x2_neon, export=1
+// x0   unused
+// x1   uint8_t *pix1
+// x2   uint8_t *pix2
+// x3   ptrdiff_t stride
+// x4   int h


As this is 'int', it would be w4, not x4


+
+// preserve value of v8-v12 registers
+stp d10, d11, [sp, #-0x10]!
+stp d8, d9, [sp, #-0x10]!
+


Yes, if possible, avoid using v8-v15. Also if you still do need to back up 
registers, don't update sp in each write; something like this is 
preferred:


stp d8,  d9,  [sp, #-0x20]!
stp d10, d11, [sp, #0x10]



+// initialize buffers
+movid18, #0
+moviv20.8h, #1
+add x5, x2, #1 // pix2 + 1
+cmp w4, #4
+b.lt2f


Do the cmp earlier, e.g. before the first movi, to avoid having b.lt 
needing to wait for the result of the cmp.



+
+// make 4 iterations at once
+1:
+// v0 - pix1
+// v1 - pix2
+// v2 - pix2 + 1
+ld1 {v0.16b}, [x1], x3
+ld1 {v1.16b}, [x2], x3
+ld1 {v2.16b}, [x5], x3
+
+ld1 {v3.16b}, [x1], x3
+ld1 {v4.16b}, [x2], x3
+ld1 {v5.16b}, [x5], x3
+
+ld1 {v6.16b}, [x1], x3
+ld1 {v7.16b}, [x2], x3
+ld1 {v8.16b}, [x5], x3
+
+ld1 {v9.16b}, [x1], x3
+ld1 {v10.16b}, [x2], x3
+ld1 {v11.16b}, [x5], x3


I guess this goes for the existing ff_pix_abs16_xy2_neon too, but I think 
it could be more efficient to start doing e.g. the first few steps of the 
first iteration after loading the data for the second iteration.



+
+// abs(pix1[0] - avg2(pix2[0], pix2[1]))
+// avg2(a,b) = (((a) + (b) + 1) >> 1)
+// abs(x) = (x < 0 ? -x : x)
+
+// pix2[0] + pix2[1]
+uaddl   v30.8h, v1.8b, v2.8b
+uaddl2  v29.8h, v1.16b, v2.16b
+// add one to each element
+add v30.8h, v30.8h, v20.8h
+add v29.8h, v29.8h, v20.8h
+// divide by 2, narrow width and store in v30
+uqshrn  v30.8b, v30.8h, #1
+uqshrn2 v30.16b, v29.8h, #1


Instead of add+uqshrn, you can do uqrshrn, where the 'r' stands for 
rounding, which implicitly adds the 1 before right shifting. But for this 
particular case, there's an even simpler alternative; you can do rhadd, 
which does rounding halving add, which avoids the whole widening/narrowing 
here. Thus these 6 instructions could just be "rhadd v30.16b, v1.16b, 
v2.16b".




+
+// abs(pix1[0] - avg2(pix2[0], pix2[1]))
+uabdv16.16b, v0.16b, v30.16b
+uaddlv  h16, v16.16b


In general, avoid doing the horizontal adds (uaddlv here) too early.

Here, I think it would be better to just accumulate things in a regular 
vector (e.g. "uaddw v18.8h, v18.8h, v16.8b", "uaddw2 v19.8h, v19.8h, 
v16.16b"), then finally add v18.8h and v19.8h into each other in the end, 
and just do one single addv.


Also then you can fuse the accumulation into the absolute operation, so 
you should be able to make do with just uabal + uabal2.


The finally when you have the calculation for each iteration simplified as 
suggested, it becomes a tight sequence of 3 instructions where each of 
them relies on the result of the previous one. Then it's better to 
interleave the instructions from the 4 parallel iterations, e.g. like 
this:


load (1st iteration)
load (2nd iteration)
rhadd (1st iteration)
load (3rd iteration)
rhadd (2nd iteration)
uabal (1st iteration)
uabal2 (1st iteration)
load (4th iteration)
rhadd (3rd iteration)
uabal (2nd iteration)
uabal2 (2nd iteration)
rhadd (4th iteration)
uabal (3rd iteration)
uabal2 (3rd iteration)
uabal (4th iteration)
uabal2 (4th iteration)

That way, you have a quite ideal distance between all instructions and the 
preceding/following instructions that depend on it

Re: [FFmpeg-devel] [PATCH 1/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Martin Storsjö

On Mon, 11 Jul 2022, Henrik Gramner wrote:


On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:

+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) 
|| defined(__MACH__))
+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif


The usual approach is to compile with -fvisibility=hidden and
explicitly flag exported API symbols.

Is there a reason for doing this the other way around?


Personally - primarily because that's way much more effort than I can put 
up right now, while this fixes the aarch64 text relocation issue (only) 
with fairly little effort.


// Martin
___
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/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

2022-07-11 Thread Martin Storsjö

On Tue, 12 Jul 2022, Martin Storsjö wrote:


On Mon, 11 Jul 2022, Henrik Gramner wrote:


On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö  wrote:
+#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && 
(defined(__ELF__) || defined(__MACH__))

+#define av_visibility_hidden __attribute__((visibility("hidden")))
+#else
+#define av_visibility_hidden
+#endif


The usual approach is to compile with -fvisibility=hidden and
explicitly flag exported API symbols.

Is there a reason for doing this the other way around?


Personally - primarily because that's way much more effort than I can put up 
right now, while this fixes the aarch64 text relocation issue (only) with 
fairly little effort.


... but I do kinda agree that that would be the ideal end form of the 
code. But Andreas point about that not getting the advantage for code 
referencing other hidden variables still stands though.


// Martin
___
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/3] tools/target_dec_fuzzer: Adjust threshold for ANM

2022-07-11 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
48923/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ANM_fuzzer-6391662321991680

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index f44cc6f857..3ba87b7f1c 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -209,6 +209,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 maxsamples = maxsamples_per_frame * maxiteration;
 switch (c->p.id) {
 case AV_CODEC_ID_AGM: maxpixels  /= 1024;  break;
+case AV_CODEC_ID_ANM: maxpixels  /= 1024;  break;
 case AV_CODEC_ID_ARBC:maxpixels  /= 1024;  break;
 case AV_CODEC_ID_ARGO:maxpixels  /= 1024;  break;
 case AV_CODEC_ID_BINKVIDEO:   maxpixels  /= 32;break;
-- 
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/3] avformat/mxfdec: SMPTE RDD 48:2018 support

2022-07-11 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/mxf.c|  3 +++
 libavformat/mxf.h|  1 +
 libavformat/mxfdec.c | 48 
 3 files changed, 52 insertions(+)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 36d662b58c..8ef928b8fc 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -66,6 +66,9 @@ const MXFCodecUL ff_mxf_codec_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x01 
}, 16,   AV_CODEC_ID_V210 }, /* V210 */
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0E,0x04,0x02,0x01,0x02,0x11,0x00,0x00 
}, 14, AV_CODEC_ID_PRORES }, /* Avid MC7 ProRes */
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x06,0x00,0x00 
}, 14, AV_CODEC_ID_PRORES }, /* Apple ProRes */
+{ { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x01,0x00 
}, 15,   AV_CODEC_ID_FFV1 }, /*FFV1 V0 */
+{ { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x02,0x00 
}, 15,   AV_CODEC_ID_FFV1 }, /*FFV1 V1 */
+{ { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x04,0x00 
}, 15,   AV_CODEC_ID_FFV1 }, /*FFV1 V3 */
 /* SoundEssenceCompression */
 { { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 
}, 14,AV_CODEC_ID_AAC }, /* MPEG-2 AAC ADTS (legacy) */
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 
}, 13,  AV_CODEC_ID_PCM_S16LE }, /* uncompressed */
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index 4d9f5119a3..2561605ce5 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -54,6 +54,7 @@ enum MXFMetadataSetType {
 AudioChannelLabelSubDescriptor,
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
+FFV1SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 400941c348..c4d9d6ed93 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -237,6 +237,12 @@ typedef struct MXFMCASubDescriptor {
 char *language;
 } MXFMCASubDescriptor;
 
+typedef struct MXFFFV1SubDescriptor {
+MXFMetadataSet meta;
+uint8_t *extradata;
+int extradata_size;
+} MXFFFV1SubDescriptor;
+
 typedef struct MXFIndexTableSegment {
 MXFMetadataSet meta;
 int edit_unit_byte_count;
@@ -337,6 +343,7 @@ static const uint8_t mxf_crypto_source_container_ul[]  
= { 0x06,0x0e,0x2b,0x
 static const uint8_t mxf_encrypted_triplet_key[]   = { 
0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 
};
 static const uint8_t mxf_encrypted_essence_container[] = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 
};
 static const uint8_t mxf_sony_mpeg4_extradata[]= { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 
};
+static const uint8_t mxf_ffv1_extradata[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x04,0x01,0x06,0x0c,0x01,0x00,0x00,0x00 
};
 static const uint8_t mxf_avid_project_name[]   = { 
0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf 
};
 static const uint8_t mxf_jp2k_rsiz[]   = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00 
};
 static const uint8_t mxf_indirect_value_utf16le[]  = { 
0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01
 };
@@ -377,6 +384,9 @@ static void mxf_free_metadataset(MXFMetadataSet **ctx, int 
freectx)
 av_freep(&((MXFDescriptor *)*ctx)->file_descriptors_refs);
 av_freep(&((MXFDescriptor *)*ctx)->sub_descriptors_refs);
 break;
+case FFV1SubDescriptor:
+av_freep(&((MXFFFV1SubDescriptor *)*ctx)->extradata);
+break;
 case AudioChannelLabelSubDescriptor:
 case SoundfieldGroupLabelSubDescriptor:
 case GroupOfSoundfieldGroupsLabelSubDescriptor:
@@ -1473,6 +1483,25 @@ static int mxf_read_mca_sub_descriptor(void *arg, 
AVIOContext *pb, int tag, int
 return 0;
 }
 
+static int mxf_read_ffv1_sub_descriptor(void *arg, AVIOContext *pb, int tag, 
int size, UID uid, int64_t klv_offset)
+{
+MXFFFV1SubDescriptor *ffv1_sub_descriptor = arg;
+
+if (IS_KLV_KEY(uid, mxf_ffv1_extradata)) {
+if (ffv1_sub_descriptor->extradata)
+av_log(NULL, AV_LOG_WARNING, "Duplicate ffv1_extradata\n");
+av_free(ffv1_sub_descriptor->extradata);
+ffv1_sub_descriptor->extradata_size = 0;
+ffv1_sub_descriptor->extradata = av_malloc(size);
+if (!ffv1_sub_descriptor->extradata)
+return AVERROR(ENOMEM);
+ffv1_sub_descriptor->extradata_size = size;
+avio_read(pb, ffv1_sub_descriptor->extradata, size);
+}
+
+return 0;
+}
+
 static int mxf_read_indirect_value(void *arg, AVIOContext *pb, int size)
 {
 MXFTaggedV

[FFmpeg-devel] [PATCH 2/3] avformat/mpc8: Check and propagate more errors

2022-07-11 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
48846/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-5278532493770752

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/mpc8.c | 40 +---
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index 2822a08b55..95a1529c5d 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -135,37 +135,40 @@ static void mpc8_get_chunk_header(AVIOContext *pb, int 
*tag, int64_t *size)
 *size += pos;
 }
 
-static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)
+static int mpc8_parse_seektable(AVFormatContext *s, int64_t off)
 {
 MPCContext *c = s->priv_data;
 int tag;
 int64_t size, pos, ppos[2];
 uint8_t *buf;
 int i, t, seekd, ret;
+int64_t ret64;
 GetBitContext gb;
 
 if (s->nb_streams == 0) {
 av_log(s, AV_LOG_ERROR, "No stream added before parsing seek table\n");
-return;
+return AVERROR_INVALIDDATA;
 }
 
-avio_seek(s->pb, off, SEEK_SET);
+ret64 = avio_seek(s->pb, off, SEEK_SET);
+if (ret64 < 0)
+return AVERROR_INVALIDDATA;
 mpc8_get_chunk_header(s->pb, &tag, &size);
-if(tag != TAG_SEEKTABLE){
+if(tag != TAG_SEEKTABLE || avio_feof(s->pb)){
 av_log(s, AV_LOG_ERROR, "No seek table at given position\n");
-return;
+return AVERROR_INVALIDDATA;
 }
 if (size > INT_MAX/10 || size<=0) {
 av_log(s, AV_LOG_ERROR, "Bad seek table size\n");
-return;
+return AVERROR_INVALIDDATA;
 }
 if(!(buf = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE)))
-return;
+return AVERROR(ENOMEM);
 ret = avio_read(s->pb, buf, size);
 if (ret != size) {
 av_log(s, AV_LOG_ERROR, "seek table truncated\n");
 av_free(buf);
-return;
+return AVERROR_INVALIDDATA;
 }
 memset(buf+size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
@@ -174,14 +177,14 @@ static void mpc8_parse_seektable(AVFormatContext *s, 
int64_t off)
 if(size > UINT_MAX/4 || size > c->samples/1152){
 av_log(s, AV_LOG_ERROR, "Seek table is too big\n");
 av_free(buf);
-return;
+return AVERROR_INVALIDDATA;
 }
 seekd = get_bits(&gb, 4);
 for(i = 0; i < 2; i++){
 pos = gb_get_v(&gb);
 if (av_sat_add64(pos, c->header_pos) != pos + (uint64_t)c->header_pos) 
{
 av_free(buf);
-return;
+return AVERROR_INVALIDDATA;
 }
 
 pos += c->header_pos;
@@ -191,7 +194,7 @@ static void mpc8_parse_seektable(AVFormatContext *s, 
int64_t off)
 for(; i < size; i++){
 if (get_bits_left(&gb) < 13) {
 av_free(buf);
-return;
+return AVERROR_INVALIDDATA;
 }
 t = get_unary(&gb, 1, 33) << 12;
 t += get_bits(&gb, 12);
@@ -203,26 +206,31 @@ static void mpc8_parse_seektable(AVFormatContext *s, 
int64_t off)
 ppos[0] = pos;
 }
 av_free(buf);
+return 0;
 }
 
-static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, 
int64_t size)
+static int mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, 
int64_t size)
 {
 AVIOContext *pb = s->pb;
 int64_t pos, off;
+int ret;
 
 switch(tag){
 case TAG_SEEKTBLOFF:
 pos = avio_tell(pb);
 off = ffio_read_varlen(pb);
 if (pos > INT64_MAX - size || off < 0 || off > INT64_MAX - chunk_pos)
-return;
+return AVERROR_INVALIDDATA;
 pos += size;
-mpc8_parse_seektable(s, chunk_pos + off);
+ret = mpc8_parse_seektable(s, chunk_pos + off);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
 avio_seek(pb, pos, SEEK_SET);
 break;
 default:
 avio_skip(pb, size);
 }
+return 0;
 }
 
 static int mpc8_read_header(AVFormatContext *s)
@@ -249,7 +257,9 @@ static int mpc8_read_header(AVFormatContext *s)
 }
 if(tag == TAG_STREAMHDR)
 break;
-mpc8_handle_chunk(s, tag, pos, size);
+ret = mpc8_handle_chunk(s, tag, pos, size);
+if (ret < 0)
+return ret;
 }
 if(tag != TAG_STREAMHDR){
 av_log(s, AV_LOG_ERROR, "Stream header not found\n");
-- 
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 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-11 Thread James Zern
On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
 wrote:
>
> Stores the item ids of all the items found in the file and
> processes the primary item at the end of the meta box. This patch
> does not change any behavior. It sets up the code for parsing
> alpha channel (and possibly images with 'grid') in follow up
> patches.
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  libavformat/isom.h |   4 ++
>  libavformat/mov.c  | 148 -
>  2 files changed, 97 insertions(+), 55 deletions(-)
>
> [...]

@@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
AVIOContext *pb, MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+ret = mov_read_default(c, pb, atom);
+if (ret < 0)

In some other cases these two lines are combined, if ((ret = ...

+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+ret = avif_add_stream(c, c->primary_item_id);
+if (ret)

This could be updated too and use '< 0' to match other code.

+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be
provided by the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
___
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 v10 00/10] make QSV works with the Intel's oneVPL

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1][2]. oneVPL is a successor to Intel(R) 
Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[3].

It is recommended to use oneVPL for new work, even for currently available
hardwares[4]. Hence, this patchset added a new option --enable-onevpl to bring
the support for oneVPL in QSV, new features for oneVPL will be implemented in
other patchset, for example, we are implementing av1_qsv encoder
(https://github.com/intel-media-ci/ffmpeg/pull/515).

option --enble-libmfx still works with Intel(R) Media SDK.

Note user can't enable onevpl and libmfx together.

oneVPL dispatcher:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v10:
  - Split the API changes into separate patch files.
  - Use separate functions for mfx session creation when using oneVPL
  - Other fixes

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://www.intel.com/content/www/us/en/developer/tools/oneapi/onevpl.html
[3] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix
[4] 
https://www.intel.com/content/www/us/en/develop/documentation/upgrading-from-msdk-to-onevpl/top.html

Haihao Xiang (13):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  lavu/hwcontext_qsv: add loader field to AVQSVDeviceContext
  lavu/hwcontext_qsv: make qsv hwdevice works with oneVPL
  lavc/qsv: create mfx session using oneVPL for decoding/encoding
  lavfi/qsv: create mfx session using oneVPL for qsv filters
  configure: add --enable-libvpl option

 configure|  32 +-
 doc/APIchanges   |   3 +
 libavcodec/qsv.c | 245 +++--
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  21 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 141 +++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  72 ++--
 libavfilter/vf_scale_qsv.c   |  87 ++---
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 588 ---
 libavutil/hwcontext_qsv.h|  13 +-
 libavutil/version.h  |   2 +-
 21 files changed, 1092 insertions(+), 185 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".


[FFmpeg-devel] [PATCH v10 01/13] configure: ensure --enable-libmfx uses libmfx 1.x

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1], some early versions of oneVPL still use libmfx
as library name[2]. However some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to ensure
user builds FFmpeg against a right version of libmfx, this patch added a
check for version < 2.0 and warning message about the used obsolete
features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 9d6457d81b..9f0c2eabc0 100755
--- a/configure
+++ b/configure
@@ -6573,10 +6573,12 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx "libmfx >= 1.28" 
"mfx/mfxvideo.h" MFXInit ||
-   { require libmfx "mfx/mfxvideo.h mfx/mfxdefs.h" 
MFXInit "-llibmfx $advapi32_extralibs" &&
- { test_cpp_condition mfx/mfxdefs.h 
"MFX_VERSION >= 1028" || die "ERROR: libmfx version must be >= 1.28"; }  &&
- warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfx/mfxvideo.h" MFXInit ||
+ { require libmfx "mfx/mfxvideo.h 
mfx/mfxdefs.h" MFXInit "-llibmfx $advapi32_extralibs" &&
+   { test_cpp_condition mfx/mfxdefs.h 
"MFX_VERSION >= 1028 && MFX_VERSION < 2000" || die "ERROR: libmfx version must 
be >= 1.28 and < 2.0"; }  &&
+   warn "using libmfx without pkg-config"; } } 
&&
+ warn "build FFmpeg against libmfx 1.x, 
obsolete features of libmfx such as OPAQUE memory,\n"\
+   "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
-- 
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 v10 02/13] configure: fix the check for MFX_CODEC_VP9

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 9f0c2eabc0..959526ec8f 100755
--- a/configure
+++ b/configure
@@ -6581,7 +6581,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx >= 1.28 libmfx
"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
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 v10 03/13] qsv: remove mfx/ prefix from mfx headers

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 19 ---
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/configure b/configure
index 959526ec8f..7bf652a874 100755
--- a/configure
+++ b/configure
@@ -6573,15 +6573,20 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfx/mfxvideo.h" MFXInit ||
- { require libmfx "mfx/mfxvideo.h 
mfx/mfxdefs.h" MFXInit "-llibmfx $advapi32_extralibs" &&
-   { test_cpp_condition mfx/mfxdefs.h 
"MFX_VERSION >= 1028 && MFX_VERSION < 2000" || die "ERROR: libmfx version must 
be >= 1.28 and < 2.0"; }  &&
-   warn "using libmfx without pkg-config"; } } 
&&
- warn "build FFmpeg against libmfx 1.x, 
obsolete features of libmfx such as OPAQUE memory,\n"\
-   "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } 
||
+ { require libmfx "mfxvideo.h mfxdefs.h" 
MFXInit "-llibmfx $advapi32_extralibs" &&
+   { test_cpp_condition mfxdefs.h "MFX_VERSION 
>= 1028 && MFX_VERSION < 2000" || die "ERROR: libmfx version must be >= 1.28 
and < 2.0"; }  &&
+ warn "using libmfx without pkg-config"; } 
} &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 385b43bb6c..25331ccce8 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -38,7 +38,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H

[FFmpeg-devel] [PATCH v10 04/13] qsv: load user plugin for MFX_VERSION < 2.0

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 25331ccce8..74fc8ff18e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,9 +36,14 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #include "mfxvp8.h"
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -323,6 +327,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -366,6 +371,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index cb1e55ae30..949955bda0 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -65,6 +65,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
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 v10 06/13] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index ad6ac70f72..97a5ad46dd 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -44,7 +44,7 @@
 #else
 #define QSV_HAVE_AVBR   0
 #define QSV_HAVE_VCM0
-#define QSV_HAVE_MF 1
+#define QSV_HAVE_MF !QSV_ONEVPL
 #endif
 
 #define QSV_COMMON_OPTS \
-- 
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 v10 09/13] lavu/hwcontext_qsv: add loader field to AVQSVDeviceContext

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

In oneVPL, a valid mfxLoader handle is needed when creating mfx session
for decoding, encoding and processing[1], so add loader field to
AVQSVDeviceContext. User should fill this field before calling
av_hwdevice_ctx_init() if using oneVPL

This is in preparation for oneVPL support

[1]https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher
---
 doc/APIchanges|  3 +++
 libavutil/hwcontext_qsv.h | 11 +++
 libavutil/version.h   |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 20b944933a..1672aa0321 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-07-05 - xx - lavu 57.28.100 - hwcontext_qsv.h
+  Add loader field to AVQSVDeviceContext
+
 2022-06-12 - xx - lavf 59.25.100 - avio.h
   Add avio_vprintf(), similar to avio_printf() but allow to use it
   from within a function taking a variable argument list as input.
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index 42e34d0dda..e2dba8ad83 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -34,6 +34,17 @@
  */
 typedef struct AVQSVDeviceContext {
 mfxSession session;
+/**
+ * The mfxLoader handle used for mfxSession creation
+ *
+ * This field is only available for oneVPL user. For non-oneVPL user, this
+ * field must be set to NULL.
+ *
+ * Filled by the user before calling av_hwdevice_ctx_init() and should be
+ * cast to mfxLoader handle. Deallocating the AVHWDeviceContext will always
+ * release this interface.
+ */
+void *loader;
 } AVQSVDeviceContext;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index 2e9e02dda8..87178e9e9a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  27
+#define LIBAVUTIL_VERSION_MINOR  28
 #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".


[FFmpeg-devel] [PATCH v10 05/13] qsv: build audio related code when MFX_VERSION < 2.0

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 74fc8ff18e..cc4b6cfd5d 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #include "mfxvp8.h"
 
@@ -129,8 +130,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -140,7 +143,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 954f882637..3647891d13 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 typedef struct QSVAsyncFrame {
@@ -100,8 +102,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -111,7 +115,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 543c58a967..802abd987d 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
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 v10 07/13] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 0c699d3b04..0d4d8b3347 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -141,7 +141,9 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
+#if !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
+#endif
 { MFX_RATECONTROL_LA_HRD,  "LA_HRD" },
 { MFX_RATECONTROL_QVBR,"QVBR" },
 };
-- 
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 v10 10/13] lavu/hwcontext_qsv: make qsv hwdevice works with oneVPL

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add config filters for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Co-authored-by: galinart 
Signed-off-by: galinart 
Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 530 +++---
 1 file changed, 492 insertions(+), 38 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 21a2a805f8..9b0c255cf4 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -49,6 +49,7 @@
 #include "pixdesc.h"
 #include "time.h"
 #include "imgutils.h"
+#include "avassert.h"
 
 #define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
 (MFX_VERSION_MAJOR > (MAJOR) || \
@@ -58,6 +59,12 @@
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
 #define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
+#if QSV_ONEVPL
+#include 
+#else
+#define MFXUnload(a) do { } while(0)
+#endif
+
 typedef struct QSVDevicePriv {
 AVBufferRef *child_device_ctx;
 } QSVDevicePriv;
@@ -619,6 +626,435 @@ static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId 
mid, mfxHDL *hdl)
 return MFX_ERR_NONE;
 }
 
+#if QSV_ONEVPL
+
+static int qsv_d3d11_update_config(void *ctx, mfxHDL handle, mfxConfig cfg)
+{
+#if CONFIG_D3D11VA
+mfxStatus sts;
+IDXGIAdapter *pDXGIAdapter;
+DXGI_ADAPTER_DESC adapterDesc;
+IDXGIDevice *pDXGIDevice = NULL;
+HRESULT hr;
+ID3D11Device *device = handle;
+mfxVariant impl_value;
+
+hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, 
(void**)&pDXGIDevice);
+if (SUCCEEDED(hr)) {
+hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error IDXGIDevice_GetAdapter %d\n", hr);
+goto fail;
+}
+
+hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error IDXGIAdapter_GetDesc %d\n", hr);
+goto fail;
+}
+} else {
+av_log(ctx, AV_LOG_ERROR, "Error ID3D11Device_QueryInterface %d\n", 
hr);
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U16;
+impl_value.Data.U16 = adapterDesc.DeviceId;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 
*)"mfxExtendedDeviceId.DeviceID", impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Error adding a MFX configuration"
+   "DeviceID property: %d.\n", sts);
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_PTR;
+impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 
*)"mfxExtendedDeviceId.DeviceLUID", impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Error adding a MFX configuration"
+   "DeviceLUID property: %d.\n", sts);
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U32;
+impl_value.Data.U32 = 0x0001;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 
*)"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Error adding a MFX configuration"
+   "LUIDDeviceNodeMask property: %d.\n", sts);
+goto fail;
+}
+
+return 0;
+
+fail:
+#endif
+return AVERROR_UNKNOWN;
+}
+
+static int qsv_d3d9_update_config(void *ctx, mfxHDL handle, mfxConfig cfg)
+{
+int ret = AVERROR_UNKNOWN;
+#if CONFIG_DXVA2
+mfxStatus sts;
+IDirect3DDeviceManager9* devmgr = handle;
+IDirect3DDevice9Ex *device = NULL;
+HANDLE device_handle = 0;
+IDirect3D9Ex *d3d9ex = NULL;
+LUID luid;
+D3DDEVICE_CREATION_PARAMETERS params;
+HRESULT hr;
+mfxVariant impl_value;
+
+hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error OpenDeviceHandle %d\n", hr);
+goto fail;
+}
+
+hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, 
TRUE);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error LockDevice %d\n", hr);
+goto fail;
+}
+
+hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error 
IDirect3DDevice9_GetCreationParameters %d\n", hr);
+goto unlock;
+}
+
+hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9Ex_GetAdapterLUID 
%d\n", hr);
+goto unlock;
+}
+
+hr = IDirect3D9Ex_GetAd

[FFmpeg-devel] [PATCH v10 12/13] lavfi/qsv: create mfx session using oneVPL for qsv filters

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

Use the mfxLoader handle in qsv hwdevice to create mfx session for qsv
filters.

This is in preparation for oneVPL support
---
 libavfilter/qsvvpp.c | 109 ---
 libavfilter/qsvvpp.h |   5 ++
 libavfilter/vf_deinterlace_qsv.c |  13 ++--
 libavfilter/vf_scale_qsv.c   |  11 ++--
 4 files changed, 115 insertions(+), 23 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 3f984fd5f9..5068ce0d5a 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -23,8 +23,6 @@
 
 #include "libavutil/common.h"
 #include "libavutil/mathematics.h"
-#include "libavutil/hwcontext.h"
-#include "libavutil/hwcontext_qsv.h"
 #include "libavutil/time.h"
 #include "libavutil/pixdesc.h"
 
@@ -32,6 +30,12 @@
 #include "qsvvpp.h"
 #include "video.h"
 
+#if QSV_ONEVPL
+#include 
+#else
+#define MFXUnload(a) do { } while(0)
+#endif
+
 #define IS_VIDEO_MEMORY(mode)  (mode & 
(MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \
 
MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
 #if QSV_HAVE_OPAQUE
@@ -614,13 +618,10 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 }
 
 /* create a "slave" session with those same properties, to be used for vpp 
*/
-ret = MFXInit(impl, &ver, &s->session);
-if (ret < 0)
-return ff_qsvvpp_print_error(avctx, ret, "Error initializing a 
session");
-else if (ret > 0) {
-ff_qsvvpp_print_warning(avctx, ret, "Warning in session 
initialization");
-return AVERROR_UNKNOWN;
-}
+ret = ff_qsvvpp_create_mfx_session(avctx, device_hwctx->loader, impl, &ver,
+   &s->session);
+if (ret)
+return ret;
 
 if (handle) {
 ret = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
@@ -906,3 +907,93 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 
 return 0;
 }
+
+#if QSV_ONEVPL
+
+int ff_qsvvpp_create_mfx_session(void *ctx,
+ void *loader,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession)
+{
+mfxStatus sts;
+mfxSession session = NULL;
+uint32_t impl_idx = 0;
+
+av_log(ctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified MFX 
loader\n");
+
+if (!loader) {
+av_log(ctx, AV_LOG_ERROR, "Invalid MFX Loader handle\n");
+return AVERROR(EINVAL);
+}
+
+while (1) {
+/* Enumerate all implementations */
+mfxImplDescription *impl_desc;
+
+sts = MFXEnumImplementations(loader, impl_idx,
+ MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
+ (mfxHDL *)&impl_desc);
+/* Failed to find an available implementation */
+if (sts == MFX_ERR_NOT_FOUND)
+break;
+else if (sts != MFX_ERR_NONE) {
+impl_idx++;
+continue;
+}
+
+sts = MFXCreateSession(loader, impl_idx, &session);
+MFXDispReleaseImplDescription(loader, impl_desc);
+if (sts == MFX_ERR_NONE)
+break;
+
+impl_idx++;
+}
+
+if (sts < 0)
+return ff_qsvvpp_print_error(ctx, sts,
+ "Error creating a MFX session");
+else if (sts > 0) {
+ff_qsvvpp_print_warning(ctx, sts,
+"Warning in MFX session creation");
+return AVERROR_UNKNOWN;
+}
+
+*psession = session;
+
+return 0;
+}
+
+#else
+
+int ff_qsvvpp_create_mfx_session(void *ctx,
+ void *loader,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession)
+{
+mfxSession session = NULL;
+mfxStatus sts;
+
+av_log(ctx, AV_LOG_VERBOSE,
+   "Use Intel(R) Media SDK to create MFX session, API version is "
+   "%d.%d, the required implementation version is %d.%d\n",
+   MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
+
+*psession = NULL;
+sts = MFXInit(implementation, pver, &session);
+if (sts < 0)
+return ff_qsvvpp_print_error(ctx, sts,
+ "Error initializing an MFX session");
+else if (sts > 0) {
+ff_qsvvpp_print_warning(ctx, sts, "Warning in MFX session 
initialization");
+return AVERROR_UNKNOWN;
+}
+
+*psession = session;
+
+return 0;
+}
+
+#endif
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 3e7d56021b..a8cfcc565a 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -28,6 +28,8 @@
 
 #include "avfilter.h"
 #include "libavutil/fifo.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_qsv.h"
 
 #define FF_INLINK

[FFmpeg-devel] [PATCH v10 11/13] lavc/qsv: create mfx session using oneVPL for decoding/encoding

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

If qsv hwdevice is available, use the mfxLoader handle in qsv hwdevice
to create mfx session. Otherwise create mfx session with a new mfxLoader
handle.

This is in preparation for oneVPL support
---
 libavcodec/qsv.c  | 226 +++---
 libavcodec/qsv_internal.h |   1 +
 libavcodec/qsvdec.c   |  11 ++
 libavcodec/qsvenc.h   |   3 +
 libavcodec/qsvenc_h264.c  |   1 -
 libavcodec/qsvenc_hevc.c  |   1 -
 libavcodec/qsvenc_jpeg.c  |   1 -
 libavcodec/qsvenc_mpeg2.c |   1 -
 libavcodec/qsvenc_vp9.c   |   1 -
 9 files changed, 223 insertions(+), 23 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 432675bccf..fe998c9649 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -45,6 +45,12 @@
 #include 
 #endif
 
+#if QSV_ONEVPL
+#include 
+#else
+#define MFXUnload(a) do { } while(0)
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -419,6 +425,193 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+static int qsv_new_mfx_loader(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  void **ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+
+loader = MFXLoad();
+if (!loader) {
+av_log(avctx, AV_LOG_ERROR, "Error creating a MFX loader\n");
+goto fail;
+}
+
+/* Create configurations for implementation */
+cfg = MFXCreateConfig(loader);
+if (!cfg) {
+av_log(avctx, AV_LOG_ERROR, "Error creating a MFX configurations\n");
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U32;
+impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
+MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 *)"mfxImplDescription.Impl", 
impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
+   "property: %d\n", sts);
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U32;
+impl_value.Data.U32 = pver->Version;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 
*)"mfxImplDescription.ApiVersion.Version",
+ impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
+   "property: %d\n", sts);
+goto fail;
+}
+
+*ploader = loader;
+
+return 0;
+
+fail:
+if (loader)
+MFXUnload(loader);
+
+*ploader = NULL;
+return AVERROR_UNKNOWN;
+}
+
+static int qsv_create_mfx_session_from_loader(void *ctx, mfxLoader loader, 
mfxSession *psession)
+{
+mfxStatus sts;
+mfxSession session = NULL;
+uint32_t impl_idx = 0;
+
+while (1) {
+/* Enumerate all implementations */
+mfxImplDescription *impl_desc;
+
+sts = MFXEnumImplementations(loader, impl_idx,
+ MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
+ (mfxHDL *)&impl_desc);
+/* Failed to find an available implementation */
+if (sts == MFX_ERR_NOT_FOUND)
+break;
+else if (sts != MFX_ERR_NONE) {
+impl_idx++;
+continue;
+}
+
+sts = MFXCreateSession(loader, impl_idx, &session);
+MFXDispReleaseImplDescription(loader, impl_desc);
+if (sts == MFX_ERR_NONE)
+break;
+
+impl_idx++;
+}
+
+if (sts != MFX_ERR_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", sts);
+goto fail;
+}
+
+*psession = session;
+
+return 0;
+
+fail:
+if (session)
+MFXClose(session);
+
+*psession = NULL;
+return AVERROR_UNKNOWN;
+}
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  void **ploader)
+{
+mfxLoader loader = NULL;
+
+/* Don't create a new MFX loader if the input loader is valid */
+if (*ploader == NULL) {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session, the required "
+   "implementation version is %d.%d\n",
+   pver->Major, pver->Minor);
+
+if (qsv_new_mfx_loader(avctx, implementation, pver, (void **)&loader))
+goto fail;
+
+av_assert0(loader);
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with th

[FFmpeg-devel] [PATCH v10 08/13] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 57 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index cc4b6cfd5d..432675bccf 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -81,10 +81,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 949955bda0..d52f0dcd15 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -66,6 +66,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index b75559f083..cd0a0f9cc1 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -187,7 +187,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
  &q->frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -300,10 +304,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 0d4d8b3347..86680b69a8 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1174,6 +1174,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1210,6 +1211,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1225,7 +1227,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
  &q->frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEM

[FFmpeg-devel] [PATCH v10 13/13] configure: add --enable-libvpl option

2022-07-11 Thread Xiang, Haihao
From: Haihao Xiang 

This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.6
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

Note the preferred child device type is d3d11va for libvpl on Windows.
The commands below will use d3d11va if d3d11va is available on Windows.
$ ffmpeg -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -qsv_device 0 -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0 -hwaccel qsv -c:v 
h264_qsv ...

User may use child_device_type option to specify child device type to
dxva2 or derive a qsv device from a dxva2 device
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0,child_device_type=dxva2 
-hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device dxva2=d3d9:0 -init_hw_device qsv=qsv@d3d9 -hwaccel qsv 
-c:v h264_qsv ...

[1] 
https://www.intel.com/content/www/us/en/develop/documentation/upgrading-from-msdk-to-onevpl/top.html
---
 configure | 29 ++---
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index 7bf652a874..c37ef962a1 100755
--- a/configure
+++ b/configure
@@ -341,6 +341,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1921,6 +1922,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6567,23 +6569,36 @@ enabled libjxl&& require_pkg_config libjxl 
"libjxl >= 0.7.0" jxl/dec
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx >= 1.28 libmfx < 2.0" "mfxvideo.h" 
MFXInit ||
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx >= 1.28 
libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } 
||
- { require libmfx "mfxvideo.h mfxdefs.h" 
MFXInit "-llibmfx $advapi32_extralibs" &&
-   { test_cpp_condition mfxdefs.h "MFX_VERSION 
>= 1028 && MFX_VERSION < 2000" || die "ERROR: libmfx version must be >= 1.28 
and < 2.0"; }  &&
- warn "using libmfx without pkg-config"; } 
} &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx >= 1.28 libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit && add_cflags -I${libmfx_incdir}/mfx; } ||
+  { require libmfx "mfxvideo.h mfxdefs.h" MFXInit "-llibmfx 
$advapi32_extralibs" &&
+{ test_cpp_condition mfxdefs.h "MFX_VERSION >= 1028 && MFX_VERSION < 
2000" || die "ERROR: libmfx version must be >= 1.28 and < 2.0"; }  &&
+warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still passed to 
check_pkg_config function for --