Re: [libav-devel] [PATCH] libaom: remove references to RGB pixfmts

2018-04-04 Thread Luca Barbato
On 05/04/2018 01:13, James Almer wrote:
> Support for it was apparently never in the codebase, and the enum
> values were recently removed from the public headers [1]
> 
> Fixes build with latest libaom build.
> 

Ok.

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

[libav-devel] [PATCH] libaom: remove references to RGB pixfmts

2018-04-04 Thread James Almer
Support for it was apparently never in the codebase, and the enum
values were recently removed from the public headers [1]

Fixes build with latest libaom build.

[1] 
https://aomedia.googlesource.com/aom/+/3f29cc20e3a4c348cb41a797c68de856ddb84e12

Signed-off-by: James Almer 
---
 libavcodec/libaom.c | 44 
 1 file changed, 44 deletions(-)

diff --git a/libavcodec/libaom.c b/libavcodec/libaom.c
index f083129f4..512095b33 100644
--- a/libavcodec/libaom.c
+++ b/libavcodec/libaom.c
@@ -38,28 +38,6 @@ case AOM_IMG_FMT_I ## fmt ## 16: \
 enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(aom_img_fmt_t img, int depth)
 {
 switch (img) {
-case AOM_IMG_FMT_RGB24:
-return AV_PIX_FMT_RGB24;
-case AOM_IMG_FMT_RGB565:
-return AV_PIX_FMT_RGB565BE;
-case AOM_IMG_FMT_RGB555:
-return AV_PIX_FMT_RGB555BE;
-case AOM_IMG_FMT_UYVY:
-return AV_PIX_FMT_UYVY422;
-case AOM_IMG_FMT_YUY2:
-return AV_PIX_FMT_YUYV422;
-case AOM_IMG_FMT_YVYU:
-return AV_PIX_FMT_YVYU422;
-case AOM_IMG_FMT_BGR24:
-return AV_PIX_FMT_BGR24;
-case AOM_IMG_FMT_ARGB:
-return AV_PIX_FMT_ARGB;
-case AOM_IMG_FMT_ARGB_LE:
-return AV_PIX_FMT_BGRA;
-case AOM_IMG_FMT_RGB565_LE:
-return AV_PIX_FMT_RGB565LE;
-case AOM_IMG_FMT_RGB555_LE:
-return AV_PIX_FMT_RGB555LE;
 case AOM_IMG_FMT_I420:
 return AV_PIX_FMT_YUV420P;
 case AOM_IMG_FMT_I422:
@@ -81,28 +59,6 @@ enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(aom_img_fmt_t 
img, int depth)
 aom_img_fmt_t ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix)
 {
 switch (pix) {
-case AV_PIX_FMT_RGB24:
-return AOM_IMG_FMT_RGB24;
-case AV_PIX_FMT_RGB565BE:
-return AOM_IMG_FMT_RGB565;
-case AV_PIX_FMT_RGB555BE:
-return AOM_IMG_FMT_RGB555;
-case AV_PIX_FMT_UYVY422:
-return AOM_IMG_FMT_UYVY;
-case AV_PIX_FMT_YUYV422:
-return AOM_IMG_FMT_YUY2;
-case AV_PIX_FMT_YVYU422:
-return AOM_IMG_FMT_YVYU;
-case AV_PIX_FMT_BGR24:
-return AOM_IMG_FMT_BGR24;
-case AV_PIX_FMT_ARGB:
-return AOM_IMG_FMT_ARGB;
-case AV_PIX_FMT_BGRA:
-return AOM_IMG_FMT_ARGB_LE;
-case AV_PIX_FMT_RGB565LE:
-return AOM_IMG_FMT_RGB565_LE;
-case AV_PIX_FMT_RGB555LE:
-return AOM_IMG_FMT_RGB555_LE;
 case AV_PIX_FMT_YUV420P:
 return AOM_IMG_FMT_I420;
 case AV_PIX_FMT_YUV422P:
-- 
2.16.2

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

Re: [libav-devel] [PATCH 2/6] avprobe: Print a user-friendly version of the display matrix

2018-04-04 Thread Luca Barbato
On 04/04/2018 17:29, Vittorio Giovara wrote:
> Shift fixed point numbers to be actual decimal numbers.
> ---
>  avtools/avprobe.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/avtools/avprobe.c b/avtools/avprobe.c
> index d6809042f7..0ea9ff46fd 100644
> --- a/avtools/avprobe.c
> +++ b/avtools/avprobe.c
> @@ -131,6 +131,7 @@ typedef struct PrintContext {
>  static AVIOContext *probe_out = NULL;
>  static PrintContext octx;
>  #define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
> +#define CONV_FP(x,fp) ((double) (x)) / (1 << fp)
>  
>  /*
>   * Default format, INI
> @@ -816,6 +817,15 @@ static void show_stream(InputFile *ifile, InputStream 
> *ist)
>  for (j = 0; j < 9; j++)
>  probe_int(NULL, ((int32_t *)sd->data)[j]);
>  probe_array_footer("matrix", 1);
> +probe_array_header("matrix_str", 1);
> +for (j = 0; j < 9; j++) {
> +char buf[32];
> +int fp = (j == 2 || j == 5 || j == 8) ? 30 : 16;
> +int32_t val = ((int32_t *)sd->data)[j];
> +value_string(buf, sizeof(buf), CONV_FP(val, fp), "");
> +probe_str(NULL, buf);
> +}
> +probe_array_footer("matrix_str", 1);
>  probe_int("rotation",
>av_display_rotation_get((int32_t *)sd->data));
>  probe_object_footer("displaymatrix");
> 

Ok.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 1/6] avprobe: Support printing strings with empty keys

2018-04-04 Thread Luca Barbato
On 04/04/2018 17:29, Vittorio Giovara wrote:
> ---
>  avtools/avprobe.c | 38 ++
>  1 file changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/avtools/avprobe.c b/avtools/avprobe.c
> index a9ca1934ca..d6809042f7 100644
> --- a/avtools/avprobe.c
> +++ b/avtools/avprobe.c
> @@ -235,10 +235,14 @@ static void ini_print_integer(const char *key, int64_t 
> value)
>  
>  static void ini_print_string(const char *key, const char *value)
>  {
> -ini_escape_print(key);
> -avio_printf(probe_out, "=");
> -ini_escape_print(value);
> -avio_w8(probe_out, '\n');
> +if (key) {
> +ini_escape_print(key);
> +avio_printf(probe_out, "=%s\n", value);
> +} else {
> +if (octx.prefix[octx.level -1].nb_elems)
> +avio_printf(probe_out, ",");
> +avio_printf(probe_out, "%s", value);
> +}
>  }
>  
>  /*
> @@ -329,14 +333,24 @@ static void json_escape_print(const char *s)
>  
>  static void json_print_string(const char *key, const char *value)
>  {
> -if (octx.prefix[octx.level -1].nb_elems)
> -avio_printf(probe_out, ",\n");
> -AVP_INDENT();
> -avio_w8(probe_out, '\"');
> -json_escape_print(key);
> -avio_printf(probe_out, "\" : \"");
> -json_escape_print(value);
> -avio_w8(probe_out, '\"');
> +if (key) {
> +if (octx.prefix[octx.level -1].nb_elems)
> +avio_printf(probe_out, ",\n");
> +AVP_INDENT();
> +avio_w8(probe_out, '\"');
> +json_escape_print(key);
> +avio_printf(probe_out, "\" : \"");
> +json_escape_print(value);
> +avio_w8(probe_out, '\"');
> +} else {
> +if (octx.prefix[octx.level -1].nb_elems)
> +avio_printf(probe_out, ", ");
> +else
> +AVP_INDENT();
> +avio_w8(probe_out, '\"');
> +json_escape_print(value);
> +avio_w8(probe_out, '\"');
> +}
>  }
>  
>  /*
> 

Ok.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 1/6] avprobe: Support printing strings with empty keys

2018-04-04 Thread Vittorio Giovara
---
 avtools/avprobe.c | 38 ++
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/avtools/avprobe.c b/avtools/avprobe.c
index a9ca1934ca..d6809042f7 100644
--- a/avtools/avprobe.c
+++ b/avtools/avprobe.c
@@ -235,10 +235,14 @@ static void ini_print_integer(const char *key, int64_t 
value)
 
 static void ini_print_string(const char *key, const char *value)
 {
-ini_escape_print(key);
-avio_printf(probe_out, "=");
-ini_escape_print(value);
-avio_w8(probe_out, '\n');
+if (key) {
+ini_escape_print(key);
+avio_printf(probe_out, "=%s\n", value);
+} else {
+if (octx.prefix[octx.level -1].nb_elems)
+avio_printf(probe_out, ",");
+avio_printf(probe_out, "%s", value);
+}
 }
 
 /*
@@ -329,14 +333,24 @@ static void json_escape_print(const char *s)
 
 static void json_print_string(const char *key, const char *value)
 {
-if (octx.prefix[octx.level -1].nb_elems)
-avio_printf(probe_out, ",\n");
-AVP_INDENT();
-avio_w8(probe_out, '\"');
-json_escape_print(key);
-avio_printf(probe_out, "\" : \"");
-json_escape_print(value);
-avio_w8(probe_out, '\"');
+if (key) {
+if (octx.prefix[octx.level -1].nb_elems)
+avio_printf(probe_out, ",\n");
+AVP_INDENT();
+avio_w8(probe_out, '\"');
+json_escape_print(key);
+avio_printf(probe_out, "\" : \"");
+json_escape_print(value);
+avio_w8(probe_out, '\"');
+} else {
+if (octx.prefix[octx.level -1].nb_elems)
+avio_printf(probe_out, ", ");
+else
+AVP_INDENT();
+avio_w8(probe_out, '\"');
+json_escape_print(value);
+avio_w8(probe_out, '\"');
+}
 }
 
 /*
-- 
2.16.2

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

[libav-devel] [PATCH 3/6] display: Add AVDisplayOrientation API

2018-04-04 Thread Vittorio Giovara
The transformation operations that can be described by a display matrix
are not limited to pure rotation, but include horizontal and vertical
flip, as well as transpose and antitranspose. Unfortunately the current
API can only return a rotation angle in degrees, and is not designed to
detect flip operations or a combination of rotation and flip.

So implement an additional API to analyze the display matrix and return
the most common rotation operations (multiples of 90º) as well flips or
a combination thereof. This function returns a bitfield mask composed of
AVDisplayOrientation elements that describe which rendering operations
should be performed on the frame. The existing API is still available
and useful in case of custom rotations.

Signed-off-by: Vittorio Giovara 
---
Note: the new operations describe a clockwise rotation, while the
old API provided a counterclockwise rotation. I always felt this was
a mistake as it's counterintuitive and suprising to new users, so I
didn't want to cargo-cult it to a new API. What do people think about it?

See also https://github.com/FFMS/ffms2/issues/317 for flipped samples, code,
and additional discussion.

Missing changelog entry and version bump.
Vittorio

 libavutil/display.c | 92 +
 libavutil/display.h | 53 ++
 2 files changed, 145 insertions(+)

diff --git a/libavutil/display.c b/libavutil/display.c
index f7500948ff..839961ec20 100644
--- a/libavutil/display.c
+++ b/libavutil/display.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 
+#include "avstring.h"
 #include "display.h"
 #include "mathematics.h"
 
@@ -73,3 +74,94 @@ void av_display_matrix_flip(int32_t matrix[9], int hflip, 
int vflip)
 for (i = 0; i < 9; i++)
 matrix[i] *= flip[i % 3];
 }
+
+uint32_t av_display_orientation_get(int32_t matrix_src[9])
+{
+int32_t matrix[9];
+uint32_t orientation = 0;
+int64_t det = (int64_t)matrix_src[0] * matrix_src[4] - 
(int64_t)matrix_src[1] * matrix_src[3];
+
+/* Duplicate matrix so that the input one is not modified in case of flip. 
*/
+memcpy(matrix, matrix_src, sizeof(*matrix_src) * 9);
+
+if (det < 0) {
+/* Always assume an horizontal flip for simplicity, it can be
+ * changed later if rotation is 180º. */
+orientation = AV_FLIP_HORIZONTAL;
+av_display_matrix_flip(matrix, 1, 0);
+}
+
+if (matrix[1] == (1 << 16) && matrix[3] == -(1 << 16)) {
+orientation |= AV_ROTATION_90;
+} else if (matrix[0] == -(1 << 16) && matrix[4] == -(1 << 16)) {
+if (det < 0)
+orientation = AV_FLIP_VERTICAL;
+else
+orientation |= AV_ROTATION_180;
+} else if (matrix[1] == -(1 << 16) && matrix[3] == (1 << 16)) {
+orientation |= AV_ROTATION_270;
+} else if (matrix[0] == (1 << 16) && matrix[4] == (1 << 16)) {
+orientation |= AV_IDENTITY;
+} else {
+orientation |= AV_ROTATION_CUSTOM;
+}
+
+return orientation;
+}
+
+void av_display_orientation_set(int32_t matrix[9], uint32_t orientation, 
double angle)
+{
+int hflip = !!(orientation & AV_FLIP_HORIZONTAL);
+int vflip = !!(orientation & AV_FLIP_VERTICAL);
+
+memset(matrix, 0, sizeof(*matrix) * 9);
+matrix[8] = 1 << 30;
+
+if (orientation & AV_IDENTITY) {
+matrix[0] = 1 << 16;
+matrix[4] = 1 << 16;
+} else if (orientation & AV_ROTATION_90) {
+matrix[1] = 1 << 16;
+matrix[3] = -(1 << 16);
+} else if (orientation & AV_ROTATION_180) {
+matrix[0] = -(1 << 16);
+matrix[4] = -(1 << 16);
+} else if (orientation & AV_ROTATION_270) {
+matrix[1] = -(1 << 16);
+matrix[3] = 1 << 16;
+} else if (orientation & AV_ROTATION_CUSTOM) {
+av_display_rotation_set(matrix, angle);
+}
+
+av_display_matrix_flip(matrix, hflip, vflip);
+}
+
+void av_display_orientation_name(uint32_t orientation, char *buf, size_t 
buf_size)
+{
+if (orientation == 0) {
+av_strlcpy(buf, "identity", buf_size);
+return;
+}
+
+if (orientation & AV_ROTATION_90)
+av_strlcpy(buf, "rotation_90", buf_size);
+else if (orientation & AV_ROTATION_180)
+av_strlcpy(buf, "rotation_180", buf_size);
+else if (orientation & AV_ROTATION_270)
+av_strlcpy(buf, "rotation_270", buf_size);
+else if (orientation & AV_ROTATION_CUSTOM)
+av_strlcpy(buf, "rotation_custom", buf_size);
+else
+buf[0] = '\0';
+
+if (orientation & AV_FLIP_HORIZONTAL) {
+if (buf[0] != '\0')
+av_strlcat(buf, "+", buf_size);
+av_strlcat(buf, "hflip", buf_size);
+}
+if (orientation & AV_FLIP_VERTICAL) {
+if (buf[0] != '\0')
+av_strlcat(buf, "+", buf_size);
+av_strlcat(buf, "vflip", buf_size);
+}
+}
diff --git a/libavutil/display.h b/libavutil/display.h
index 2d869fcd16..a057453b20 100644
--- 

[libav-devel] [PATCH 6/6] avconv: Support automatic horizontal and vertical flip

2018-04-04 Thread Vittorio Giovara
---
 avtools/avconv_filter.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/avtools/avconv_filter.c b/avtools/avconv_filter.c
index 858dc0409b..5a535a7ac1 100644
--- a/avtools/avconv_filter.c
+++ b/avtools/avconv_filter.c
@@ -551,6 +551,17 @@ static int configure_input_video_filter(FilterGraph *fg, 
InputFilter *ifilter,
 }
 if (ret < 0)
 return ret;
+
+if (orientation & AV_FLIP_HORIZONTAL) {
+ret = insert_filter(_filter, _idx, "hflip", NULL);
+if (ret < 0)
+return ret;
+}
+if (orientation & AV_FLIP_VERTICAL) {
+ret = insert_filter(_filter, _idx, "vflip", NULL);
+if (ret < 0)
+return ret;
+}
 }
 }
 
-- 
2.16.2

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

[libav-devel] [PATCH 2/6] avprobe: Print a user-friendly version of the display matrix

2018-04-04 Thread Vittorio Giovara
Shift fixed point numbers to be actual decimal numbers.
---
 avtools/avprobe.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/avtools/avprobe.c b/avtools/avprobe.c
index d6809042f7..0ea9ff46fd 100644
--- a/avtools/avprobe.c
+++ b/avtools/avprobe.c
@@ -131,6 +131,7 @@ typedef struct PrintContext {
 static AVIOContext *probe_out = NULL;
 static PrintContext octx;
 #define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
+#define CONV_FP(x,fp) ((double) (x)) / (1 << fp)
 
 /*
  * Default format, INI
@@ -816,6 +817,15 @@ static void show_stream(InputFile *ifile, InputStream *ist)
 for (j = 0; j < 9; j++)
 probe_int(NULL, ((int32_t *)sd->data)[j]);
 probe_array_footer("matrix", 1);
+probe_array_header("matrix_str", 1);
+for (j = 0; j < 9; j++) {
+char buf[32];
+int fp = (j == 2 || j == 5 || j == 8) ? 30 : 16;
+int32_t val = ((int32_t *)sd->data)[j];
+value_string(buf, sizeof(buf), CONV_FP(val, fp), "");
+probe_str(NULL, buf);
+}
+probe_array_footer("matrix_str", 1);
 probe_int("rotation",
   av_display_rotation_get((int32_t *)sd->data));
 probe_object_footer("displaymatrix");
-- 
2.16.2

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

[libav-devel] [PATCH 5/6] avconv: Port automatic rotation to the new orientation API

2018-04-04 Thread Vittorio Giovara
Needed to avoid conflicts with the upcoming automatic flip.
---
 avtools/avconv_filter.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/avtools/avconv_filter.c b/avtools/avconv_filter.c
index 884478da27..858dc0409b 100644
--- a/avtools/avconv_filter.c
+++ b/avtools/avconv_filter.c
@@ -538,15 +538,15 @@ static int configure_input_video_filter(FilterGraph *fg, 
InputFilter *ifilter,
 uint8_t* displaymatrix = av_stream_get_side_data(ist->st,
  
AV_PKT_DATA_DISPLAYMATRIX, NULL);
 if (displaymatrix) {
-double rot = av_display_rotation_get((int32_t*) displaymatrix);
-if (rot < -135 || rot > 135) {
+uint32_t orientation = av_display_orientation_get((int32_t*) 
displaymatrix);
+if (orientation & AV_ROTATION_180) {
 ret = insert_filter(_filter, _idx, "vflip", NULL);
 if (ret < 0)
 return ret;
 ret = insert_filter(_filter, _idx, "hflip", NULL);
-} else if (rot < -45) {
+} else if (orientation & AV_ROTATION_90) {
 ret = insert_filter(_filter, _idx, "transpose", 
"dir=clock");
-} else if (rot > 45) {
+} else if (orientation & AV_ROTATION_270) {
 ret = insert_filter(_filter, _idx, "transpose", 
"dir=cclock");
 }
 if (ret < 0)
-- 
2.16.2

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

[libav-devel] [PATCH 4/6] avprobe: Report the display orientation operations

2018-04-04 Thread Vittorio Giovara
---
 avtools/avprobe.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/avtools/avprobe.c b/avtools/avprobe.c
index 0ea9ff46fd..8ac8960014 100644
--- a/avtools/avprobe.c
+++ b/avtools/avprobe.c
@@ -809,6 +809,8 @@ static void show_stream(InputFile *ifile, InputStream *ist)
 const AVPacketSideData* sd = >side_data[i];
 AVStereo3D *stereo;
 AVSphericalMapping *spherical;
+uint32_t mask;
+char buf[64];
 
 switch (sd->type) {
 case AV_PKT_DATA_DISPLAYMATRIX:
@@ -828,6 +830,10 @@ static void show_stream(InputFile *ifile, InputStream *ist)
 probe_array_footer("matrix_str", 1);
 probe_int("rotation",
   av_display_rotation_get((int32_t *)sd->data));
+mask = av_display_orientation_get((int32_t *)sd->data);
+av_display_orientation_name(mask, [0], sizeof(buf));
+probe_str("orientation", buf);
+probe_int("orientation_mask", mask);
 probe_object_footer("displaymatrix");
 break;
 case AV_PKT_DATA_STEREO3D:
-- 
2.16.2

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

Re: [libav-devel] [PATCH v2] qsv: adding Multi Frame Encode support

2018-04-04 Thread Luca Barbato
On 02/04/2018 15:17, Maxym Dmytrychenko wrote:
> +if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {

Maybe use QSV_HAVE_MF ?

The rest looks fine to me.

lu
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH] lavc/qsvenc: fix the hard code of height aligment checking

2018-04-04 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f6b1a0d..fc9ace4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1048,7 +1048,7 @@ static int submit_frame(QSVEncContext *q, const AVFrame 
*frame,
 }
 } else {
 /* make a copy if the input is not padded as libmfx requires */
-if (frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) {
+if (frame->height & (q->height_align - 1) || frame->linesize[0] & 
(q->width_align - 1)) {
 qf->frame->height = FFALIGN(frame->height, q->height_align);
 qf->frame->width  = FFALIGN(frame->width, q->width_align);
 
-- 
1.8.3.1

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

[libav-devel] [PATCH] lavc/qsvdec: expose frame pic_type and key_frame

2018-04-04 Thread Zhong Li
Currently pict_type and key_frame are unset.
Add an extra param to fetch the picture type from qsv decoder

The judgement “key frame is equal to IDR frame” only suitable for H264.
For HEVC, all IRAP frames are key frames, and other codecs have no IDR
frame.

Signed-off-by: ChaoX A Liu 
Signed-off-by: Zhong Li 
---
 libavcodec/qsv.c  | 24 
 libavcodec/qsv_internal.h |  3 +++
 libavcodec/qsvdec.c   |  9 +
 3 files changed, 36 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e78633d..e578ab1 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -195,6 +195,30 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, 
QSVFrame *frame)
 return AVERROR_BUG;
 }
 
+enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
+{
+enum AVPictureType type;
+switch (mfx_pic_type & 0x7) {
+case MFX_FRAMETYPE_I:
+if (mfx_pic_type & MFX_FRAMETYPE_S)
+type = AV_PICTURE_TYPE_SI;
+else
+type = AV_PICTURE_TYPE_I;
+break;
+case MFX_FRAMETYPE_B:
+type = AV_PICTURE_TYPE_B;
+break;
+case MFX_FRAMETYPE_P:
+if (mfx_pic_type & MFX_FRAMETYPE_S)
+type = AV_PICTURE_TYPE_SP;
+else
+type = AV_PICTURE_TYPE_P;
+break;
+}
+
+return type;
+}
+
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 975c8de..07ddc59 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -48,6 +48,8 @@ typedef struct QSVMid {
 typedef struct QSVFrame {
 AVFrame *frame;
 mfxFrameSurface1 surface;
+mfxExtDecodedFrameInfo dec_info;
+mfxExtBuffer *ext_param;
 
 int queued;
 int used;
@@ -83,6 +85,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile);
 
 int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
+enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
 
 int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,
  const char *load_plugins);
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d05d48f..31cce2d 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -232,6 +232,11 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
 
 frame->surface.Data.MemId = >frames_ctx.mids[ret];
 }
+frame->surface.Data.ExtParam= >ext_param;
+frame->surface.Data.NumExtParam = 1;
+frame->ext_param= (mfxExtBuffer*)>dec_info;
+frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
+frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
 
 frame->used = 1;
 
@@ -418,6 +423,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
 frame->interlaced_frame =
 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
+frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
+//Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs 
are key frames.
+if (avctx->codec_id == AV_CODEC_ID_H264)
+frame->key_frame = !!(out_frame->dec_info.FrameType & 
MFX_FRAMETYPE_IDR);
 
 /* update the surface properties */
 if (avctx->pix_fmt == AV_PIX_FMT_QSV)
-- 
1.8.3.1

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

[libav-devel] [PATCH] lavf/qsvvpp: bypass vpp if not needed.

2018-04-04 Thread Zhong Li
Currently vpp pipeline is always created, even for the unnecessary
cases such as setting the option "vpp_qsv=w=1280:h=720" for an input
with native resolution 1280x720. Thus introduces unnecessary performance
dropping, so bypass vpp if not needed.

Signed-off-by: Zhong Li 
---
 libavfilter/vf_vpp_qsv.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 610e821..568dee5 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -27,6 +27,7 @@
 #include "libavutil/eval.h"
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/mathematics.h"
 
 #include "formats.h"
 #include "internal.h"
@@ -249,6 +250,7 @@ static int config_output(AVFilterLink *outlink)
 QSVVPPParam param = { NULL };
 QSVVPPCrop  crop  = { 0 };
 mfxExtBuffer*ext_buf[ENH_FILTERS_COUNT];
+AVFilterLink*inlink = ctx->inputs[0];
 
 outlink->w  = vpp->out_width;
 outlink->h  = vpp->out_height;
@@ -320,14 +322,34 @@ static int config_output(AVFilterLink *outlink)
 param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)>procamp_conf;
 }
 
-return ff_qsvvpp_create(ctx, >qsv, );
+if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise ||
+vpp->detail || vpp->procamp || inlink->w != outlink->w || inlink->h != 
outlink->h)
+return ff_qsvvpp_create(ctx, >qsv, );
+else {
+av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
+if (inlink->hw_frames_ctx)
+outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+}
+
+return 0;
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
 {
-VPPContext *vpp = inlink->dst->priv;
+int  ret = 0;
+AVFilterContext  *ctx = inlink->dst;
+VPPContext   *vpp = inlink->dst->priv;
+AVFilterLink *outlink = ctx->outputs[0];
+
+if (vpp->qsv)
+ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+else {
+if (picref->pts != AV_NOPTS_VALUE)
+picref->pts = av_rescale_q(picref->pts, inlink->time_base, 
outlink->time_base);
+ret = ff_filter_frame(outlink, picref);
+}
 
-return ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+return ret;
 }
 
 static int query_formats(AVFilterContext *ctx)
-- 
1.8.3.1

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

Re: [libav-devel] [PATCH v2] qsv: adding Multi Frame Encode support

2018-04-04 Thread Li, Zhong
LGTM

> -Original Message-
> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> Maxym Dmytrychenko
> Sent: Monday, April 2, 2018 9:17 PM
> To: libav-devel@libav.org
> Subject: [libav-devel] [PATCH v2] qsv: adding Multi Frame Encode support
> 
> Starting from API 1.25 helps to improve performance of the simultaneous
> encode, 1:N scenario, like:
> 
> ./avconv  -y -hwaccel qsv -c:v h264_qsv -r 3/1001 -i
> ~/bbb_sunflower_1080p_60fps_normal.mp4  -vframes 600 -an \
> -filter_complex "split=2[s1][s2]; [s1]scale_qsv=1280:720[o1];
> [s2]scale_qsv=960:540[o2]" \
> -map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f
> rawvideo /tmp/3200a.264 \
> -map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f
> rawvideo /tmp/1750a.264
> ---
>  libavcodec/qsv.c | 10 ++
>  libavcodec/qsv_internal.h|  4 
>  libavcodec/qsvenc.c  | 16 +++-
>  libavcodec/qsvenc.h  | 12 ++--
>  libavcodec/qsvenc_h264.c |  4 
>  libavfilter/qsvvpp.c |  9 ++---
>  libavfilter/qsvvpp.h |  8 
>  libavfilter/vf_deinterlace_qsv.c |  7 +++
>  libavfilter/vf_scale_qsv.c   |  7 +++
>  libavutil/hwcontext_qsv.c|  5 +
>  10 files changed, 72 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index e78633d62..bab32836e
> 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -593,10 +593,12 @@ int ff_qsv_init_session_device(AVCodecContext
> *avctx, mfxSession *psession,
>"Error setting a HW
> handle");
>  }
> 
> -err = MFXJoinSession(parent_session, session);
> -if (err != MFX_ERR_NONE)
> -return ff_qsv_print_error(avctx, err,
> -  "Error joining session");
> +if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> +err = MFXJoinSession(parent_session, session);
> +if (err != MFX_ERR_NONE)
> +return ff_qsv_print_error(avctx, err,
> +  "Error joining session");
> +}
> 
>  ret = qsv_load_plugins(session, load_plugins, avctx);
>  if (ret < 0) {
> diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index
> 975c8de44..d2a18eb06 100644
> --- a/libavcodec/qsv_internal.h
> +++ b/libavcodec/qsv_internal.h
> @@ -36,6 +36,10 @@
>  (MFX_VERSION_MAJOR > (MAJOR) || \
>   MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >=
> (MINOR))
> 
> +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR,
> MINOR) \
> +(MFX_VERSION.Major > (MAJOR)) ||   \
> +(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >=
> (MINOR))
> +
>  typedef struct QSVMid {
>  AVBufferRef *hw_frames_ref;
>  mfxHDL handle;
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> f6b1a0d67..a8b446c5b 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -135,7 +135,7 @@ static void dump_video_param(AVCodecContext
> *avctx, QSVEncContext *q,  #if QSV_HAVE_CO2
>  mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
>  #endif
> -#if QSV_HAVE_CO3
> +#if QSV_HAVE_CO3 && QSV_HAVE_QVBR
>  mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
>  #endif
> 
> @@ -656,6 +656,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
> 
>  q->extparam_internal[q->nb_extparam_internal++] =
> (mfxExtBuffer *)>extco2;
>  }
> +#endif
> +#if QSV_HAVE_MF
> +if (avctx->codec_id == AV_CODEC_ID_H264) {
> +mfxVersionver;
> +ret = MFXQueryVersion(q->session,);
> +if (ret >= MFX_ERR_NONE &&
> QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> +q->extmfp.Header.BufferId =
> MFX_EXTBUFF_MULTI_FRAME_PARAM;
> +q->extmfp.Header.BufferSz = sizeof(q->extmfp);
> +
> +q->extmfp.MFMode = q->mfmode;
> +av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n",
> q->extmfp.MFMode);
> +q->extparam_internal[q->nb_extparam_internal++] =
> (mfxExtBuffer *)>extmfp;
> +}
> +}
>  #endif
>  }
> 
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index
> ab5579595..a7fc57bb4 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -50,11 +50,13 @@
>  #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_VCMQSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 11)
> +#define QSV_HAVE_MF 0
>  #else
>  #define QSV_HAVE_AVBR   0
>  #define QSV_HAVE_ICQ0
>  #define QSV_HAVE_VCM0
>  #define QSV_HAVE_QVBR   0
> +#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
>  #endif
> 
>  #if !QSV_HAVE_LA_DS
> @@ -109,12 +111,15 @@ typedef struct QSVEncContext {  #if
> QSV_HAVE_CO2
>  mfxExtCodingOption2 extco2;
>  #endif
> -
> +#if QSV_HAVE_MF
> +mfxExtMultiFrameParam   extmfp;
> +mfxExtMultiFrameControl