Re: [FFmpeg-devel] [PATCH] ffmpeg: always init output stream before reaping filters

2017-10-08 Thread Marton Balint



On Sat, 7 Oct 2017, Hendrik Leppkes wrote:


On Wed, Oct 4, 2017 at 12:48 AM, Marton Balint  wrote:

Otherwise the frame size of the codec is not set in the buffersink.

Fixes ticket #6603 and the following simpler case:

ffmpeg -c aac -filter_complex "sine=d=0.1,asetnsamples=1025" out.aac

Signed-off-by: Marton Balint 
---
 fftools/ffmpeg.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1d248bc269..5be8788ea8 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4528,6 +4528,15 @@ static int transcode_step(void)
 }

 if (ost->filter && ost->filter->graph->graph) {
+if (!ost->initialized) {
+char error[1024] = {0};
+ret = init_output_stream(ost, error, sizeof(error));
+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d 
-- %s\n",
+   ost->file_index, ost->index, error);
+exit_program(1);
+}
+}
 if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0)
 return ret;
 if (!ist)


Doesn't this basically void all the work that was done to get proper
output frame information before initializing the output, so its
created with the proper info at all times?


To be frank, I am not entirely sure. Fate passes, so this can't be that 
bad. The original patch that caused the regression is 
af1761f7b5b1b72197dc40934953b775c2d951cc which in the commit message only 
mentions the delayed initialization of filters, this patch keeps that.


Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Gyan Doshi
OpenJPEG 2.3 was released a few days ago. Changelog reports "No API/ABI 
break compared to v2.2.0 but additional symbols for subset of components 
decoding"


This patch is adapted from an earlier patch which added support for 2.2.

Applied and tested locally.
From c42f0c4290170cb49dc00f7898bee31d2e8ee814 Mon Sep 17 00:00:00 2001
From: Gyan Doshi 
Date: Sun, 8 Oct 2017 14:59:23 +0530
Subject: [PATCH] lavc: add support for openjpeg 2.3

Signed-off-by: Gyan Doshi 
---
 configure   |  5 -
 libavcodec/libopenjpegdec.c |  8 +---
 libavcodec/libopenjpegenc.c | 10 ++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index 391c141e7a..3280e74f0f 100755
--- a/configure
+++ b/configure
@@ -1930,6 +1930,7 @@ HEADERS_LIST="
 machine_ioctl_meteor_h
 malloc_h
 opencv2_core_core_c_h
+openjpeg_2_3_openjpeg_h
 openjpeg_2_2_openjpeg_h
 openjpeg_2_1_openjpeg_h
 openjpeg_2_0_openjpeg_h
@@ -5950,7 +5951,9 @@ enabled libopencv && { check_header 
opencv2/core/core_c.h &&
  require opencv opencv2/core/core_c.h 
cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
require_pkg_config libopencv opencv 
opencv/cxcore.h cvCreateImageHeader; }
 enabled libopenh264   && require_pkg_config libopenh264 openh264 
wels/codec_api.h WelsGetCodecVersion
-enabled libopenjpeg   && { { check_lib libopenjpeg openjpeg-2.2/openjpeg.h 
opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
+enabled libopenjpeg   && { { check_lib libopenjpeg openjpeg-2.3/openjpeg.h 
opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
+   check_lib libopenjpeg openjpeg-2.3/openjpeg.h 
opj_version -lopenjp2 ||
+  { check_lib 
libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && 
add_cppflags -DOPJ_STATIC; } ||
check_lib libopenjpeg openjpeg-2.2/openjpeg.h 
opj_version -lopenjp2 ||
{ check_lib libopenjpeg openjpeg-2.1/openjpeg.h 
opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
check_lib libopenjpeg openjpeg-2.1/openjpeg.h 
opj_version -lopenjp2 ||
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 1210123265..67d47bd6a0 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -34,7 +34,9 @@
 #include "internal.h"
 #include "thread.h"
 
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H
+#  include 
+#elif HAVE_OPENJPEG_2_2_OPENJPEG_H
 #  include 
 #elif HAVE_OPENJPEG_2_1_OPENJPEG_H
 #  include 
@@ -46,7 +48,7 @@
 #  include 
 #endif
 
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H || 
HAVE_OPENJPEG_2_0_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || 
HAVE_OPENJPEG_2_1_OPENJPEG_H || HAVE_OPENJPEG_2_0_OPENJPEG_H
 #  define OPENJPEG_MAJOR_VERSION 2
 #  define OPJ(x) OPJ_##x
 #else
@@ -431,7 +433,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
 opj_stream_set_read_function(stream, stream_read);
 opj_stream_set_skip_function(stream, stream_skip);
 opj_stream_set_seek_function(stream, stream_seek);
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || 
HAVE_OPENJPEG_2_1_OPENJPEG_H
 opj_stream_set_user_data(stream, &reader, NULL);
 #elif HAVE_OPENJPEG_2_0_OPENJPEG_H
 opj_stream_set_user_data(stream, &reader);
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index b67e533d1d..92b4433b04 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -32,7 +32,9 @@
 #include "avcodec.h"
 #include "internal.h"
 
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H
+#  include 
+#elif HAVE_OPENJPEG_2_2_OPENJPEG_H
 #  include 
 #elif HAVE_OPENJPEG_2_1_OPENJPEG_H
 #  include 
@@ -44,7 +46,7 @@
 #  include 
 #endif
 
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H || 
HAVE_OPENJPEG_2_0_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || 
HAVE_OPENJPEG_2_1_OPENJPEG_H || HAVE_OPENJPEG_2_0_OPENJPEG_H
 #  define OPENJPEG_MAJOR_VERSION 2
 #  define OPJ(x) OPJ_##x
 #else
@@ -307,7 +309,7 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
*avctx)
 
 opj_set_default_encoder_parameters(&ctx->enc_params);
 
-#if HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H
+#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || 
HAVE_OPENJPEG_2_1_OPENJPEG_H
 switch (ctx->cinema_mode) {
 case OPJ_CINEMA2K_24:
 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_2K;
@@ -771,7 +773,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 opj_stream_set_write_function(stream, stream_

Re: [FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Clément Bœsch
On Sun, Oct 08, 2017 at 04:51:49PM +0530, Gyan Doshi wrote:
> OpenJPEG 2.3 was released a few days ago. Changelog reports "No API/ABI
> break compared to v2.2.0 but additional symbols for subset of components
> decoding"
> 
> This patch is adapted from an earlier patch which added support for 2.2.
> 
> Applied and tested locally.

> From c42f0c4290170cb49dc00f7898bee31d2e8ee814 Mon Sep 17 00:00:00 2001
> From: Gyan Doshi 
> Date: Sun, 8 Oct 2017 14:59:23 +0530
> Subject: [PATCH] lavc: add support for openjpeg 2.3
> 
> Signed-off-by: Gyan Doshi 
> ---
>  configure   |  5 -
>  libavcodec/libopenjpegdec.c |  8 +---
>  libavcodec/libopenjpegenc.c | 10 ++
>  3 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/configure b/configure
> index 391c141e7a..3280e74f0f 100755
> --- a/configure
> +++ b/configure
> @@ -1930,6 +1930,7 @@ HEADERS_LIST="
>  machine_ioctl_meteor_h
>  malloc_h
>  opencv2_core_core_c_h
> +openjpeg_2_3_openjpeg_h
>  openjpeg_2_2_openjpeg_h
>  openjpeg_2_1_openjpeg_h
>  openjpeg_2_0_openjpeg_h
> @@ -5950,7 +5951,9 @@ enabled libopencv && { check_header 
> opencv2/core/core_c.h &&
>   require opencv opencv2/core/core_c.h 
> cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
> require_pkg_config libopencv opencv 
> opencv/cxcore.h cvCreateImageHeader; }
>  enabled libopenh264   && require_pkg_config libopenh264 openh264 
> wels/codec_api.h WelsGetCodecVersion
> -enabled libopenjpeg   && { { check_lib libopenjpeg 
> openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags 
> -DOPJ_STATIC; } ||
> +enabled libopenjpeg   && { { check_lib libopenjpeg 
> openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags 
> -DOPJ_STATIC; } ||
> +   check_lib libopenjpeg openjpeg-2.3/openjpeg.h 
> opj_version -lopenjp2 ||
> +{ check_lib 
> libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && 
> add_cppflags -DOPJ_STATIC; } ||
> check_lib libopenjpeg openjpeg-2.2/openjpeg.h 
> opj_version -lopenjp2 ||
> { check_lib libopenjpeg 
> openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags 
> -DOPJ_STATIC; } ||
> check_lib libopenjpeg openjpeg-2.1/openjpeg.h 
> opj_version -lopenjp2 ||

I'm sorry but this needs to stop. Why the hell do we have to add a ton of
garbage to the configure every time there is a new openjpeg release?

Why is it the only project that pollutes the configure like this at every
release?

[...]
> -#if HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H || 
> HAVE_OPENJPEG_2_0_OPENJPEG_H
> +#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || 
> HAVE_OPENJPEG_2_1_OPENJPEG_H || HAVE_OPENJPEG_2_0_OPENJPEG_H

...and then this?

Yeah well, please put an end to this. This condition should be something
like #if OPENJPEG_MAJOR >= 2 or something like that.

[...]

-- 
Clément B.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] FFmpeg 3.4

2017-10-08 Thread Michael Niedermayer
On Sat, Oct 07, 2017 at 12:06:23AM +0200, wm4 wrote:
> On Fri, 6 Oct 2017 16:53:17 +0200
> Michael Niedermayer  wrote:
> 
> > Hi all
> > 
> > if there are no objections i will branch release/3.4 in the next days
> > and make the 3.4 release a few days after that
> > 
> > If people prefer a specific name, suggest one now, otherwise i will
> > pick a random one from past suggestions
> > 
> > If there are features you want in, please push them to
> > master before the release is branched
> > if there are bug fixes you want in please ensure they end in
> > release/3.4 (eiter via master before branching or backport after)
> 
> I want hardware decoding things in that release (frame pool info,
> cuvid). I vote the release until this has happened.

Iam not sure what you mean by "I vote the release ..."
please clarify

But i do not think that delaying the release further is what most
developers want. In case thats what you suggest.
The release is already several months behind shedule

Releases should be done "early and often", waiting for "in development"
features will delay a release forever, theres always another feature
on the horizon that someone wants in.

Of course if the majority wants me to wait with the release, its easy
to wait for as long as people want me to wait ...

Thanks

[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are best at talking, realize last or never when they are wrong.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] FFmpeg 3.4

2017-10-08 Thread Reto Kromer
Michael Niedermayer wrote:

>Of course if the majority wants me to wait with the release,
>its easy to wait for as long as people want me to wait ...

Form an user's perspective, I would be delighted to have a new
release. Thank you very much indeed! Reto

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


Re: [FFmpeg-devel] [PATCH 0/1] lavc: add support for OpenJPEG 2.3.0

2017-10-08 Thread Gyan Doshi

On 10/5/2017 7:15 PM, Michael Bradshaw wrote:

> This adds support for OpenJPEG 2.3.0, which was just released and 
contains many security-related fixes.


I missed this, and just submitted a patch for the same thing. So, ping 
for merge.


Thanks,
Gyan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Alexis Ballier
On Sun, 8 Oct 2017 13:43:45 +0200
Clément Bœsch  wrote:

> On Sun, Oct 08, 2017 at 04:51:49PM +0530, Gyan Doshi wrote:
> > OpenJPEG 2.3 was released a few days ago. Changelog reports "No
> > API/ABI break compared to v2.2.0 but additional symbols for subset
> > of components decoding"
> > 
> > This patch is adapted from an earlier patch which added support for
> > 2.2.
> > 
> > Applied and tested locally.  
> 
> > From c42f0c4290170cb49dc00f7898bee31d2e8ee814 Mon Sep 17 00:00:00
> > 2001 From: Gyan Doshi 
> > Date: Sun, 8 Oct 2017 14:59:23 +0530
> > Subject: [PATCH] lavc: add support for openjpeg 2.3
> > 
> > Signed-off-by: Gyan Doshi 
> > ---
> >  configure   |  5 -
> >  libavcodec/libopenjpegdec.c |  8 +---
> >  libavcodec/libopenjpegenc.c | 10 ++
> >  3 files changed, 15 insertions(+), 8 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index 391c141e7a..3280e74f0f 100755
> > --- a/configure
> > +++ b/configure
> > @@ -1930,6 +1930,7 @@ HEADERS_LIST="
> >  machine_ioctl_meteor_h
> >  malloc_h
> >  opencv2_core_core_c_h
> > +openjpeg_2_3_openjpeg_h
> >  openjpeg_2_2_openjpeg_h
> >  openjpeg_2_1_openjpeg_h
> >  openjpeg_2_0_openjpeg_h
> > @@ -5950,7 +5951,9 @@ enabled libopencv && { check_header
> > opencv2/core/core_c.h && require opencv opencv2/core/core_c.h
> > cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
> > require_pkg_config libopencv opencv opencv/cxcore.h
> > cvCreateImageHeader; } enabled libopenh264   &&
> > require_pkg_config libopenh264 openh264 wels/codec_api.h
> > WelsGetCodecVersion -enabled libopenjpeg   && { { check_lib
> > libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2
> > -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || +enabled
> > libopenjpeg   && { { check_lib libopenjpeg
> > openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC &&
> > add_cppflags -DOPJ_STATIC; } ||
> > +   check_lib libopenjpeg
> > openjpeg-2.3/openjpeg.h opj_version -lopenjp2 ||
> > +
> > { check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version
> > -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || check_lib
> > libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 ||
> > { check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version
> > -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || check_lib
> > libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 ||  
> 
> I'm sorry but this needs to stop. Why the hell do we have to add a
> ton of garbage to the configure every time there is a new openjpeg
> release?
> 
> Why is it the only project that pollutes the configure like this at
> every release?


openjpeg provides a pkg-config file here; from the look of it, it only
needs to require a recent enough version (>=2.1 I'd guess), use the
pkg-config reported cflags and libs, and #include  instead
of 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le sextidi 16 vendémiaire, an CCXXVI, Hendrik Leppkes a écrit :
> If there is a command line to write a stats file with similar
> information from this metadata - I don't think anyone would then
> object to that.

It was sarcastic: storing the stats in metadata is also a
quick-and-dirty solution that only works for a few use cases and has
many drawbacks. Suggesting it is sufficient is just a bad joke. An
accumulation of quick-and-dirty hacks will never amount to a clean
solution.

I think that we should refuse any new stats-gathering or similar filter
until a clean and working solution has been designed. Any alternative
proposition?

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le sextidi 16 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> Calm down guys, I said in the next sentence I'm open to alternatives.

The frustration in my message, if any, was not directed at you.

But I think you should not only be "open" to alternatives but more
"actively searching for" them.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Ronald S. Bultje
Hi,

On Sun, Oct 8, 2017 at 9:06 AM, Nicolas George  wrote:

> I think that we should refuse any new stats-gathering or similar filter
> until a clean and working solution has been designed.
>

I don't think that is fair. I don't agree with this approach.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le septidi 17 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> > I think that we should refuse any new stats-gathering or similar filter
> > until a clean and working solution has been designed.
> I don't think that is fair. I don't agree with this approach.

Your lack of alternative proposal has been noted.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Paul B Mahol
On 10/8/17, Nicolas George  wrote:
> Le septidi 17 vendemiaire, an CCXXVI, Ronald S. Bultje a ecrit :
>> > I think that we should refuse any new stats-gathering or similar filter
>> > until a clean and working solution has been designed.
>> I don't think that is fair. I don't agree with this approach.
>
> Your lack of alternative proposal has been noted.


Your lack of common sense have been noted.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le septidi 17 vendémiaire, an CCXXVI, Paul B Mahol a écrit :
> Your lack of common sense have been noted.

I want a clean solution. A solution that works for most uses. A solution
that works the same way for all filters. And, if possible, a solution
that is easy to secure.

Is that lack of common sense?

I do not like the "no, it's you" kind of answers, but in this case I am
afraid this is the only relevant answer to you.

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/6] hwcontext: Perform usual initialisation on derived device contexts

2017-10-08 Thread Mark Thompson
The initialisation should be common.  For libmfx, it was previously
happening in the derivation function and this moves it out.  For VAAPI,
it fixes some failures when deriving from a DRM device because this
initialisation did not run.
---
 libavutil/hwcontext.c |  4 
 libavutil/hwcontext_qsv.c | 10 --
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 2f4ee9661e..048e82126f 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -650,6 +650,10 @@ int av_hwdevice_ctx_create_derived(AVBufferRef 
**dst_ref_ptr,
 goto fail;
 
 done:
+ret = av_hwdevice_ctx_init(dst_ref);
+if (ret < 0)
+goto fail;
+
 *dst_ref_ptr = dst_ref;
 return 0;
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 75057f7d52..f1d16d8bf9 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1037,16 +1037,6 @@ static int 
qsv_device_derive_from_child(AVHWDeviceContext *ctx,
 goto fail;
 }
 
-ret = qsv_device_init(ctx);
-if (ret < 0)
-goto fail;
-if (s->handle_type != handle_type) {
-av_log(ctx, AV_LOG_ERROR, "Error in child device handle setup: "
-   "type mismatch (%d != %d).\n", s->handle_type, handle_type);
-err = AVERROR_UNKNOWN;
-goto fail;
-}
-
 return 0;
 
 fail:
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 2/6] vaapi: Remove H.264 baseline profile

2017-10-08 Thread Mark Thompson
This has been deprecated in libva2 because hardware does not and will not
support it.  Therefore never consider it for decode, and for encode assume
the user meant constrained baseline profile instead.
---
 libavcodec/vaapi_decode.c  |  1 -
 libavcodec/vaapi_encode_h264.c | 12 
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index cf58aae4c6..4f0ff84e01 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -246,7 +246,6 @@ static const struct {
 MAP(MPEG4,   MPEG4_MAIN,  MPEG4Main   ),
 MAP(H264,H264_CONSTRAINED_BASELINE,
H264ConstrainedBaseline),
-MAP(H264,H264_BASELINE,   H264Baseline),
 MAP(H264,H264_MAIN,   H264Main),
 MAP(H264,H264_HIGH,   H264High),
 #if VA_CHECK_VERSION(0, 37, 0)
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 549867ef3f..728c871d72 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1175,6 +1175,10 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 ctx->codec = &vaapi_encode_type_h264;
 
 switch (avctx->profile) {
+case FF_PROFILE_H264_BASELINE:
+// Baseline profile is not supported, assume the user meant
+// constrained baseline instead.
+avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
 case FF_PROFILE_H264_CONSTRAINED_BASELINE:
 ctx->va_profile = VAProfileH264ConstrainedBaseline;
 if (avctx->max_b_frames != 0) {
@@ -1183,14 +1187,6 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
"doesn't support encoding with B frames, disabling 
them.\n");
 }
 break;
-case FF_PROFILE_H264_BASELINE:
-ctx->va_profile = VAProfileH264Baseline;
-if (avctx->max_b_frames != 0) {
-avctx->max_b_frames = 0;
-av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile "
-   "doesn't support encoding with B frames, disabling 
them.\n");
-}
-break;
 case FF_PROFILE_H264_MAIN:
 ctx->va_profile = VAProfileH264Main;
 break;
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 6/6] hwcontext_vaapi: Add support for mapping to DRM objects

2017-10-08 Thread Mark Thompson
Uses vaExportSurfaceHandle() from libva2.
---
 libavutil/hwcontext_vaapi.c | 106 +++-
 1 file changed, 104 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index b2f2e376d8..3b4ca57d6f 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -884,8 +884,8 @@ fail:
 return err;
 }
 
-static int vaapi_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
-  const AVFrame *src, int flags)
+static int vaapi_map_to_memory(AVHWFramesContext *hwfc, AVFrame *dst,
+   const AVFrame *src, int flags)
 {
 int err;
 
@@ -1060,6 +1060,95 @@ static int vaapi_map_from_drm(AVHWFramesContext *src_fc, 
AVFrame *dst,
 
 return 0;
 }
+
+static void vaapi_unmap_to_drm(AVHWFramesContext *dst_fc,
+   HWMapDescriptor *hwmap)
+{
+AVDRMFrameDescriptor *drm_desc = hwmap->priv;
+int i;
+
+for (i = 0; i < drm_desc->nb_objects; i++)
+close(drm_desc->objects[i].fd);
+
+av_freep(&drm_desc);
+}
+
+static int vaapi_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
+const AVFrame *src, int flags)
+{
+#if CONFIG_VAAPI_1
+AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx;
+VASurfaceID surface_id;
+VAStatus vas;
+VADRMPRIMESurfaceDescriptor va_desc;
+AVDRMFrameDescriptor *drm_desc = NULL;
+int err, i, j;
+
+surface_id = (VASurfaceID)(uintptr_t)src->data[3];
+
+vas = vaExportSurfaceHandle(hwctx->display, surface_id,
+VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+VA_EXPORT_SURFACE_READ_ONLY |
+VA_EXPORT_SURFACE_SEPARATE_LAYERS,
+&va_desc);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(hwfc, AV_LOG_ERROR, "Failed to export surface %#x: "
+   "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
+return AVERROR(EIO);
+}
+
+drm_desc = av_mallocz(sizeof(*drm_desc));
+if (!drm_desc) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+
+// By some bizarre coincidence, these structures are very similar...
+drm_desc->nb_objects = va_desc.num_objects;
+for (i = 0; i < va_desc.num_objects; i++) {
+drm_desc->objects[i].fd   = va_desc.objects[i].fd;
+drm_desc->objects[i].size = va_desc.objects[i].size;
+drm_desc->objects[i].format_modifier =
+va_desc.objects[i].drm_format_modifier;
+}
+drm_desc->nb_layers = va_desc.num_layers;
+for (i = 0; i < va_desc.num_layers; i++) {
+drm_desc->layers[i].format= va_desc.layers[i].drm_format;
+drm_desc->layers[i].nb_planes = va_desc.layers[i].num_planes;
+for (j = 0; j < va_desc.layers[i].num_planes; j++) {
+drm_desc->layers[i].planes[j].object_index =
+va_desc.layers[i].object_index[j];
+drm_desc->layers[i].planes[j].offset =
+va_desc.layers[i].offset[j];
+drm_desc->layers[i].planes[j].pitch =
+va_desc.layers[i].pitch[j];
+}
+}
+
+err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
+&vaapi_unmap_to_drm, drm_desc);
+if (err < 0)
+goto fail;
+
+dst->width   = src->width;
+dst->height  = src->height;
+dst->data[0] = (uint8_t*)drm_desc;
+
+return 0;
+
+fail:
+for (i = 0; i < va_desc.num_objects; i++)
+close(va_desc.objects[i].fd);
+av_freep(&drm_desc);
+return err;
+#else
+// Older versions without vaExportSurfaceHandle() are not supported -
+// in theory this is possible with a combination of vaDeriveImage()
+// and vaAcquireBufferHandle(), but it doesn't carry enough metadata
+// to actually use the result in a generic way.
+return AVERROR(ENOSYS);
+#endif
+}
 #endif
 
 static int vaapi_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
@@ -1075,6 +1164,19 @@ static int vaapi_map_to(AVHWFramesContext *hwfc, AVFrame 
*dst,
 }
 }
 
+static int vaapi_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
+  const AVFrame *src, int flags)
+{
+switch (dst->format) {
+#if CONFIG_LIBDRM
+case AV_PIX_FMT_DRM_PRIME:
+return vaapi_map_to_drm(hwfc, dst, src, flags);
+#endif
+default:
+return vaapi_map_to_memory(hwfc, dst, src, flags);
+}
+}
+
 static void vaapi_device_free(AVHWDeviceContext *ctx)
 {
 AVVAAPIDeviceContext *hwctx = ctx->hwctx;
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 4/6] hwcontext_vaapi: Set message callbacks on internally-created devices

2017-10-08 Thread Mark Thompson
The message callbacks are library-safe in libva2, so we can now use
them.  Also factorise out the common connection code to avoid
duplicating this change.
---
 libavutil/hwcontext_vaapi.c | 74 +++--
 1 file changed, 45 insertions(+), 29 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 9214dc6e50..b2f2e376d8 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1094,14 +1094,53 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
 av_freep(&priv);
 }
 
+#if CONFIG_VAAPI_1
+static void vaapi_device_log_error(void *context, const char *message)
+{
+AVHWDeviceContext *ctx = context;
+
+av_log(ctx, AV_LOG_ERROR, "libva: %s", message);
+}
+
+static void vaapi_device_log_info(void *context, const char *message)
+{
+AVHWDeviceContext *ctx = context;
+
+av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
+}
+#endif
+
+static int vaapi_device_connect(AVHWDeviceContext *ctx,
+VADisplay display)
+{
+AVVAAPIDeviceContext *hwctx = ctx->hwctx;
+int major, minor;
+VAStatus vas;
+
+#if CONFIG_VAAPI_1
+vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
+vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
+#endif
+
+hwctx->display = display;
+
+vas = vaInitialize(display, &major, &minor);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
+   "connection: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR(EIO);
+}
+av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
+   "version %d.%d\n", major, minor);
+
+return 0;
+}
+
 static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
AVDictionary *opts, int flags)
 {
-AVVAAPIDeviceContext *hwctx = ctx->hwctx;
 VAAPIDevicePriv *priv;
-VADisplay display = 0;
-VAStatus vas;
-int major, minor;
+VADisplay display = NULL;
 
 priv = av_mallocz(sizeof(*priv));
 if (!priv)
@@ -1163,18 +1202,7 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 return AVERROR(EINVAL);
 }
 
-hwctx->display = display;
-
-vas = vaInitialize(display, &major, &minor);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
-   "connection: %d (%s).\n", vas, vaErrorStr(vas));
-return AVERROR(EIO);
-}
-av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
-   "version %d.%d\n", major, minor);
-
-return 0;
+return vaapi_device_connect(ctx, display);
 }
 
 static int vaapi_device_derive(AVHWDeviceContext *ctx,
@@ -1183,11 +1211,8 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
 #if CONFIG_LIBDRM
 if (src_ctx->type == AV_HWDEVICE_TYPE_DRM) {
 AVDRMDeviceContext *src_hwctx = src_ctx->hwctx;
-AVVAAPIDeviceContext   *hwctx = ctx->hwctx;
 VADisplay *display;
-VAStatus vas;
 VAAPIDevicePriv *priv;
-int major, minor;
 
 if (src_hwctx->fd < 0) {
 av_log(ctx, AV_LOG_ERROR, "DRM instance requires an associated "
@@ -1212,16 +1237,7 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
 return AVERROR(EIO);
 }
 
-hwctx->display = display;
-
-vas = vaInitialize(display, &major, &minor);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
-   "connection: %d (%s).\n", vas, vaErrorStr(vas));
-return AVERROR(EIO);
-}
-
-return 0;
+return vaapi_device_connect(ctx, display);
 }
 #endif
 return AVERROR(ENOSYS);
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/6] configure: Add config option for libva2 (VAAPI 1)

2017-10-08 Thread Mark Thompson
---
 configure | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configure b/configure
index 391c141e7a..87722de226 100755
--- a/configure
+++ b/configure
@@ -2204,6 +2204,7 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
+vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -6237,6 +6238,10 @@ enabled vaapi &&
 enabled vaapi &&
 check_lib vaapi_x11 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 -lX11
 
+enabled vaapi &&
+check_cpp_condition "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" &&
+enable vaapi_1
+
 enabled vdpau &&
 check_cpp_condition vdpau/vdpau.h "defined 
VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
 disable vdpau
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 3/6] vaapi: Always free parameter buffers after vaEndPicture() with libva2

2017-10-08 Thread Mark Thompson
This is an ABI change in libva2: previously the Intel driver had this
behaviour and it was implemented as a driver quirk, but now it is part
of the specification so all drivers must do it.
---
 libavcodec/vaapi_decode.c  | 4 ++--
 libavcodec/vaapi_encode.c  | 4 ++--
 libavfilter/vf_deinterlace_vaapi.c | 2 +-
 libavfilter/vf_scale_vaapi.c   | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 4f0ff84e01..5a555b2bd3 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -188,14 +188,14 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
"issue: %d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
 goto fail;
 else
 goto fail_at_end;
 }
 
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
 ff_vaapi_decode_destroy_buffers(avctx, pic);
 
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e13e99587d..590f4be4ed 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -399,14 +399,14 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 err = AVERROR(EIO);
 // vaRenderPicture() has been called here, so we should not destroy
 // the parameter buffers unless separate destruction is required.
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
 goto fail;
 else
 goto fail_at_end;
 }
 
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
 for (i = 0; i < pic->nb_param_buffers; i++) {
 vas = vaDestroyBuffer(ctx->hwctx->display,
diff --git a/libavfilter/vf_deinterlace_vaapi.c 
b/libavfilter/vf_deinterlace_vaapi.c
index 838eb89c90..44c5ae7642 100644
--- a/libavfilter/vf_deinterlace_vaapi.c
+++ b/libavfilter/vf_deinterlace_vaapi.c
@@ -539,7 +539,7 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame)
 goto fail_after_render;
 }
 
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
 vas = vaDestroyBuffer(ctx->hwctx->display, params_id);
 if (vas != VA_STATUS_SUCCESS) {
diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index 5f049a5d7b..22e928c098 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -361,7 +361,7 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame)
 goto fail_after_render;
 }
 
-if (ctx->hwctx->driver_quirks &
+if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
 vas = vaDestroyBuffer(ctx->hwctx->display, params_id);
 if (vas != VA_STATUS_SUCCESS) {
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Michael Bradshaw
I can clean these up as part of the patch that drops OpenJPEG 1.x support,
which I plan on making after the next release (though of course someone
else is welcome to beat me to it; it seems there's a race for OpenJPEG
patches!).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/utvideo: Use "&" instead of "&&" in expressions with "~"

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 12:58 AM, Ronald S. Bultje wrote:
> I personally think the warning is dumb... But I guess that's just me.

I agree; I don't even count it as a valid warning. Maybe disable it?

That's only my opinion, of course.

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


Re: [FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:18 PM, Michael Bradshaw wrote:
> I can clean these up as part of the patch that drops OpenJPEG 1.x support,
> which I plan on making after the next release (though of course someone
> else is welcome to beat me to it; it seems there's a race for OpenJPEG
> patches!).

Is there anything that precludes switching 2.X to pkg-config and leaving
1.X as is?

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


Re: [FFmpeg-devel] [PATCH 2/6] vaapi: Remove H.264 baseline profile

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> +case FF_PROFILE_H264_BASELINE:
> +// Baseline profile is not supported, assume the user meant
> +// constrained baseline instead.
> +avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;

Trying to automatically (and silently!) guess what the user wanted
is never a good idea, IMO. At the very least, print a warning.

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


Re: [FFmpeg-devel] [PATCH 3/6] vaapi: Always free parameter buffers after vaEndPicture() with libva2

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> This is an ABI change in libva2: previously the Intel driver had this
> behaviour and it was implemented as a driver quirk, but now it is part
> of the specification so all drivers must do it.
> ---
>  libavcodec/vaapi_decode.c  | 4 ++--
>  libavcodec/vaapi_encode.c  | 4 ++--
>  libavfilter/vf_deinterlace_vaapi.c | 2 +-
>  libavfilter/vf_scale_vaapi.c   | 2 +-
>  4 files changed, 6 insertions(+), 6 deletions(-)

Seems correct to me.

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


[FFmpeg-devel] [PATCH 2/6] vaapi: Remove H.264 baseline profile

2017-10-08 Thread Mark Thompson
This has been deprecated in libva2 because hardware does not and will not
support it.  Therefore never consider it for decode, and for encode assume
the user meant constrained baseline profile instead.
---
On 08/10/17 16:44, Derek Buitenhuis wrote:
> On 10/8/2017 4:11 PM, Mark Thompson wrote:
>> +case FF_PROFILE_H264_BASELINE:
>> +// Baseline profile is not supported, assume the user meant
>> +// constrained baseline instead.
>> +avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
> 
> Trying to automatically (and silently!) guess what the user wanted
> is never a good idea, IMO. At the very least, print a warning.

Yeah, ok, I agree.  Patch changed as enclosing.


 libavcodec/vaapi_decode.c  |  1 -
 libavcodec/vaapi_encode_h264.c | 12 
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index cf58aae4c6..4f0ff84e01 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -246,7 +246,6 @@ static const struct {
 MAP(MPEG4,   MPEG4_MAIN,  MPEG4Main   ),
 MAP(H264,H264_CONSTRAINED_BASELINE,
H264ConstrainedBaseline),
-MAP(H264,H264_BASELINE,   H264Baseline),
 MAP(H264,H264_MAIN,   H264Main),
 MAP(H264,H264_HIGH,   H264High),
 #if VA_CHECK_VERSION(0, 37, 0)
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 549867ef3f..efde80b08e 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1175,6 +1175,10 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 ctx->codec = &vaapi_encode_type_h264;
 
 switch (avctx->profile) {
+case FF_PROFILE_H264_BASELINE:
+av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
+   "supported, using constrained baseline profile instead.\n");
+avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
 case FF_PROFILE_H264_CONSTRAINED_BASELINE:
 ctx->va_profile = VAProfileH264ConstrainedBaseline;
 if (avctx->max_b_frames != 0) {
@@ -1183,14 +1187,6 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
"doesn't support encoding with B frames, disabling 
them.\n");
 }
 break;
-case FF_PROFILE_H264_BASELINE:
-ctx->va_profile = VAProfileH264Baseline;
-if (avctx->max_b_frames != 0) {
-avctx->max_b_frames = 0;
-av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile "
-   "doesn't support encoding with B frames, disabling 
them.\n");
-}
-break;
 case FF_PROFILE_H264_MAIN:
 ctx->va_profile = VAProfileH264Main;
 break;
-- 
2.11.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/6] hwcontext: Perform usual initialisation on derived device contexts

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> -ret = qsv_device_init(ctx);
> -if (ret < 0)
> -goto fail;

From the patch context alone, this looks kinda iffy. I assume
qsv_device_init is now called via av_hwdevice_ctx_init?

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


Re: [FFmpeg-devel] [PATCH 4/6] hwcontext_vaapi: Set message callbacks on internally-created devices

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> The message callbacks are library-safe in libva2, so we can now use
> them.  Also factorise out the common connection code to avoid
> duplicating this change.
> ---
>  libavutil/hwcontext_vaapi.c | 74 
> +++--
>  1 file changed, 45 insertions(+), 29 deletions(-)

Would have preferred these be two separate patches, but I also don't
have strong feelings about it.

Looks OK, assuming libva2 guarantees NULL-termination of the message.

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


Re: [FFmpeg-devel] [PATCH 2/6] vaapi: Remove H.264 baseline profile

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:49 PM, Mark Thompson wrote:
> Yeah, ok, I agree.  Patch changed as enclosing.
> 
> 
>  libavcodec/vaapi_decode.c  |  1 -
>  libavcodec/vaapi_encode_h264.c | 12 
>  2 files changed, 4 insertions(+), 9 deletions(-)

Looks OK to me. I assume we don't care about the old lib
versions and hardware wanting to use the profile.

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


Re: [FFmpeg-devel] [PATCH 5/6] hwcontext: Perform usual initialisation on derived device contexts

2017-10-08 Thread Mark Thompson
On 08/10/17 16:49, Derek Buitenhuis wrote:
> On 10/8/2017 4:11 PM, Mark Thompson wrote:
>> -ret = qsv_device_init(ctx);
>> -if (ret < 0)
>> -goto fail;
> 
> From the patch context alone, this looks kinda iffy. I assume
> qsv_device_init is now called via av_hwdevice_ctx_init?

Yes.  It always was for the non-derived case, resulting in it being called 
twice (for qsv it doesn't actually do anything beyond some checks, so this was 
harmless).

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


Re: [FFmpeg-devel] [PATCH 5/6] hwcontext: Perform usual initialisation on derived device contexts

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:52 PM, Mark Thompson wrote:
> Yes.  It always was for the non-derived case, resulting in it being called 
> twice (for qsv it doesn't actually do anything beyond some checks, so this 
> was harmless).

Looks OK, then.

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


Re: [FFmpeg-devel] [PATCH 4/6] hwcontext_vaapi: Set message callbacks on internally-created devices

2017-10-08 Thread Mark Thompson
On 08/10/17 16:51, Derek Buitenhuis wrote:
> On 10/8/2017 4:11 PM, Mark Thompson wrote:
>> The message callbacks are library-safe in libva2, so we can now use
>> them.  Also factorise out the common connection code to avoid
>> duplicating this change.
>> ---
>>  libavutil/hwcontext_vaapi.c | 74 
>> +++--
>>  1 file changed, 45 insertions(+), 29 deletions(-)
> 
> Would have preferred these be two separate patches, but I also don't
> have strong feelings about it.

Easy enough to do.

Split as:

"""
hwcontext_vaapi: Factorise out common connection code

This was duplicated between normal device creation and creation by
derivation from a DRM device.
"""

and

"""
hwcontext_vaapi: Set message callbacks on internally-created devices

The message callbacks are library-safe in libva2, so we can now use
them.
"""

with the obvious change.

Thanks,

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


Re: [FFmpeg-devel] [PATCH 6/6] hwcontext_vaapi: Add support for mapping to DRM objects

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> Uses vaExportSurfaceHandle() from libva2.
> ---
>  libavutil/hwcontext_vaapi.c | 106 
> +++-
>  1 file changed, 104 insertions(+), 2 deletions(-)

[...]

> +for (i = 0; i < drm_desc->nb_objects; i++)
> +close(drm_desc->objects[i].fd);

Delightful API...

> +surface_id = (VASurfaceID)(uintptr_t)src->data[3];

Can you elaborate a bit on this part? Casting pointers to uintptr_t and storing
them is always a red flag to me... C standard issues, etc.

> +dst->data[0] = (uint8_t*)drm_desc;

This is also a bit wtf-looking... is it cast back at some point? That could be
problematic.

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


Re: [FFmpeg-devel] [PATCH 4/6] hwcontext_vaapi: Set message callbacks on internally-created devices

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 5:00 PM, Mark Thompson wrote:
> Easy enough to do.
> 
> Split as:
> 
> """
> hwcontext_vaapi: Factorise out common connection code
> 
> This was duplicated between normal device creation and creation by
> derivation from a DRM device.
> """
> 
> and
> 
> """
> hwcontext_vaapi: Set message callbacks on internally-created devices
> 
> The message callbacks are library-safe in libva2, so we can now use
> them.
> """
> 
> with the obvious change.

Sounds good.

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


Re: [FFmpeg-devel] [PATCH 6/6] hwcontext_vaapi: Add support for mapping to DRM objects

2017-10-08 Thread Mark Thompson
On 08/10/17 17:03, Derek Buitenhuis wrote:
> On 10/8/2017 4:11 PM, Mark Thompson wrote:
>> Uses vaExportSurfaceHandle() from libva2.
>> ---
>>  libavutil/hwcontext_vaapi.c | 106 
>> +++-
>>  1 file changed, 104 insertions(+), 2 deletions(-)
> 
> [...]
> 
>> +for (i = 0; i < drm_desc->nb_objects; i++)
>> +close(drm_desc->objects[i].fd);
> 
> Delightful API...
> 
>> +surface_id = (VASurfaceID)(uintptr_t)src->data[3];
> 
> Can you elaborate a bit on this part? Casting pointers to uintptr_t and 
> storing
> them is always a red flag to me... C standard issues, etc.
> 
>> +dst->data[0] = (uint8_t*)drm_desc;
> 
> This is also a bit wtf-looking... is it cast back at some point? That could be
> problematic.

This is just how hardware surfaces are stored in AVFrames - they have their own 
API-specific handles in the data[] pointers because that's the only place to 
put them.

See

and

(and others).

Thanks,

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


Re: [FFmpeg-devel] [PATCH 6/6] hwcontext_vaapi: Add support for mapping to DRM objects

2017-10-08 Thread Derek Buitenhuis
On 10/8/2017 5:11 PM, Mark Thompson wrote:
> This is just how hardware surfaces are stored in AVFrames - they have their 
> own API-specific handles in the data[] pointers because that's the only place 
> to put them.
> 
> See
> 
> and
> 
> (and others).
> 
> Thanks,

Eugh, well OK. That's arguably not exactly OK by the C standard. Oh well.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Hendrik Leppkes
On Sun, Oct 8, 2017 at 5:05 PM, Nicolas George  wrote:
> Le septidi 17 vendémiaire, an CCXXVI, Paul B Mahol a écrit :
>> Your lack of common sense have been noted.
>
> I want a clean solution. A solution that works for most uses. A solution
> that works the same way for all filters. And, if possible, a solution
> that is easy to secure.
>

Usually those not happy with an existing solution should also offer up
a replacement, even if only in concept (actual implementable concept,
not just a slogan)
Stating to block any future filters without even specifying how the
replacement should work does seem more like idealism then common
sense.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Ronald S. Bultje
Hi Nicolas,

On Sun, Oct 8, 2017 at 9:38 AM, Nicolas George  wrote:

> Le septidi 17 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> > > I think that we should refuse any new stats-gathering or similar filter
> > > until a clean and working solution has been designed.
> > I don't think that is fair. I don't agree with this approach.
>
> Your lack of alternative proposal has been noted.
>

Hm... Michael has proposed 3 solutions and I commented on each of them.
Maybe let's focus the discussion on which of these to move forward with.

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


Re: [FFmpeg-devel] [PATCH] Add support for libopenjpeg 2.3

2017-10-08 Thread Michael Bradshaw
On Sun, Oct 8, 2017 at 8:34 AM, Derek Buitenhuis  wrote:
>
> Is there anything that precludes switching 2.X to pkg-config and leaving
> 1.X as is?


No, switching 2.x to pkg-config isn't dependent on dropping 1.x. But since
I plan to do both, I figure I might as well do them together since they're
both clean-up work.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le septidi 17 vendémiaire, an CCXXVI, Hendrik Leppkes a écrit :
> Usually those not happy with an existing solution should also offer up
> a replacement, even if only in concept (actual implementable concept,
> not just a slogan)

That is the policy for enhancements, but not for flaws. When a flaw is
spotted in a patch, the burden of fixing has always belonged to the
person who proposes the patch, in principle before the patch is
accepted, but failing that it should be done quickly or the flawed code
should be removed.

I can accept that "working with other filters" is an enhancement, but
"increasing the attack surface" and "making sandboxing harder" are
definitely flaws.

Therefore it is not unreasonable to demand the people who want these
features to implement them in a way that does not raise security
concerns, and reject the patches if they do not.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le septidi 17 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> Hm... Michael has proposed 3 solutions and I commented on each of them.

I saw, but basically it amounts to agreeing with the solutions that
remove the file output. I am very fine with that, but other people have
disagreed.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf: add more beep options to sine asrc

2017-10-08 Thread Nicolas George
Thanks for the patch.

Le quintidi 15 vendémiaire, an CCXXVI, Michael Bradshaw a écrit :
> From: Michael Bradshaw 
> 
> Signed-off-by: Michael Bradshaw 
> ---
>  doc/filters.texi| 13 -
>  libavfilter/asrc_sine.c | 17 +
>  2 files changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 57189c77b0..ec1c335950 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -4624,7 +4624,18 @@ Set the carrier frequency. Default is 440 Hz.
>  
>  @item beep_factor, b
>  Enable a periodic beep every second with frequency @var{beep_factor} times
> -the carrier frequency. Default is 0, meaning the beep is disabled.
> +the carrier frequency. Default is 0, meaning the beep is disabled. If
> +@var{frequency} is 0, this value is interpreted as the beep frequency (in 
> Hertz)
> +(rather than a multiplier of the @var{frequency}).
> +
> +@item beep_delay
> +The delay for the first beep, in seconds. Default is 0.
> +
> +@item beep_period
> +The time beriod between two beeps, in seconds. Default is 1.
> +
> +@item beep_duration
> +The duration of a beep, in seconds. Default is 0.04.
>  
>  @item sample_rate, r
>  Specify the sample rate, default is 44100.
> diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c
> index 3a87210b4b..643952792f 100644
> --- a/libavfilter/asrc_sine.c
> +++ b/libavfilter/asrc_sine.c
> @@ -32,6 +32,9 @@ typedef struct SineContext {
>  const AVClass *class;
>  double frequency;
>  double beep_factor;
> +double beep_delay;
> +double beep_period_opt;
> +double beep_duration;
>  char *samples_per_frame;
>  AVExpr *samples_per_frame_expr;
>  int sample_rate;
> @@ -71,6 +74,9 @@ static const AVOption sine_options[] = {
>  OPT_DBL("f", frequency,440, 0, DBL_MAX,   
> "set the sine frequency",),
>  OPT_DBL("beep_factor",   beep_factor,0, 0, DBL_MAX,   
> "set the beep frequency factor",),
>  OPT_DBL("b", beep_factor,0, 0, DBL_MAX,   
> "set the beep frequency factor",),

> +OPT_DBL("beep_delay",beep_delay, 0, 0, DBL_MAX,   
> "set the delay for the first beep",),
> +OPT_DBL("beep_period",   beep_period_opt,1, DBL_MIN, 
> DBL_MAX, "set the gap between beeps",),
> +OPT_DBL("beep_duration", beep_duration,   0.04, DBL_MIN, 
> DBL_MAX, "set the duration of a beep",),

I think these should use OPT_DUR / AV_OPT_TYPE_DURATION rather than
doubles. Also, DBL_MIN seems strange: I do not think a negative value
makes sense.

>  OPT_INT("sample_rate",   sample_rate,44100, 1, INT_MAX,   
> "set the sample rate",),
>  OPT_INT("r", sample_rate,44100, 1, INT_MAX,   
> "set the sample rate",),
>  OPT_DUR("duration",  duration,   0, 0, INT64_MAX, 
> "set the audio duration",),
> @@ -152,10 +158,13 @@ static av_cold int init(AVFilterContext *ctx)
>  make_sin_table(sine->sin);
>  
>  if (sine->beep_factor) {
> -sine->beep_period = sine->sample_rate;
> -sine->beep_length = sine->beep_period / 25;
> -sine->dphi_beep = ldexp(sine->beep_factor * sine->frequency, 32) /
> -  sine->sample_rate + 0.5;
> +unsigned beep_start = sine->beep_delay * sine->sample_rate;
> +double beep_frequency = (sine->frequency ? sine->frequency : 1.0) *
> +sine->beep_factor;

> +sine->beep_period = sine->beep_period_opt * sine->sample_rate;

With integer durations, av_rescale() would be better.

> +sine->beep_index = (sine->beep_period - beep_start) % 
> sine->beep_period;

I think this will produce strange results if beep_start is greater than
beep_period. Maybe document the limitation, or adjust the arithmetic.

> +sine->beep_length = sine->beep_duration * sine->sample_rate;
> +sine->dphi_beep = ldexp(beep_frequency, 32) / sine->sample_rate + 
> 0.5;
>  }
>  
>  ret = av_expr_parse(&sine->samples_per_frame_expr,

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Ronald S. Bultje
Hi,

On Sun, Oct 8, 2017 at 2:04 PM, Nicolas George  wrote:

> Le septidi 17 vendémiaire, an CCXXVI, Hendrik Leppkes a écrit :
> > Usually those not happy with an existing solution should also offer up
> > a replacement, even if only in concept (actual implementable concept,
> > not just a slogan)
>
> That is the policy for enhancements, but not for flaws.
>

I think you're stretching the definition of "flaw" here.

Really.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Nicolas George
Le septidi 17 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> I think you're stretching the definition of "flaw" here.

I addressed that in the paragraph you snipped: I agree that the
usability considerations can be considered an enhancement, but the
security considerations must be considered a flaw.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Paul B Mahol
On 10/8/17, Nicolas George  wrote:
> Le septidi 17 vendemiaire, an CCXXVI, Ronald S. Bultje a ecrit :
>> I think you're stretching the definition of "flaw" here.
>
> I addressed that in the paragraph you snipped: I agree that the
> usability considerations can be considered an enhancement, but the
> security considerations must be considered a flaw.
>

Look -y option allows to remove any user's file its big security flaw.
Let's remove -y option as its security issue and flaw in your eyes.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter: add vmafmotion filter

2017-10-08 Thread Ronald S. Bultje
Hi,

On Sun, Oct 8, 2017 at 3:26 PM, Nicolas George  wrote:

> Le septidi 17 vendémiaire, an CCXXVI, Ronald S. Bultje a écrit :
> > I think you're stretching the definition of "flaw" here.
>
> I addressed that in the paragraph you snipped: I agree that the
> usability considerations can be considered an enhancement, but the
> security considerations must be considered a flaw.
>

Again, I disagree with the use of the word "must" here.

Let's not discuss this further, I feel that fixing this is not as difficult
as it may seem, Michael has said he's willing to do the effort, he's
proposed workable solutions, I've commented positively on them, can you
continue the conversation there so we can conclude this?

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


[FFmpeg-devel] [PATCH 00/20] Coded bitstream editing (v3)

2017-10-08 Thread Mark Thompson
Incorporating all review comments from last time:
* Change all CBS users to hold a pointer rather than the whole structure.
* Rearrange the MPEG-2 framerate stuff so that it doesn't add code and then 
remove it in the series.
* Add a type for the coded bitstream unit type.
* Miscellaneous fixups.

Thanks,

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


[FFmpeg-devel] [PATCH 03/20] lavc: Add coded bitstream read/write API

2017-10-08 Thread Mark Thompson
(cherry picked from commit 18f1706f331bf5dd565774eae680508c8d3a97ad)
(cherry picked from commit 44cde38c8acbef7d5250e6d1b52b1020871e093b)
---
 configure |   1 +
 libavcodec/Makefile   |   1 +
 libavcodec/cbs.c  | 479 ++
 libavcodec/cbs.h  | 283 +++
 libavcodec/cbs_internal.h |  86 +
 5 files changed, 850 insertions(+)
 create mode 100644 libavcodec/cbs.c
 create mode 100644 libavcodec/cbs.h
 create mode 100644 libavcodec/cbs_internal.h

diff --git a/configure b/configure
index 77c9a18c3c..b238293cc1 100755
--- a/configure
+++ b/configure
@@ -2142,6 +2142,7 @@ CONFIG_EXTRA="
 blockdsp
 bswapdsp
 cabac
+cbs
 dirac_parse
 dvprofile
 exif
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c4ec09b1c4..9680553c90 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -59,6 +59,7 @@ OBJS-$(CONFIG_AUDIODSP)+= audiodsp.o
 OBJS-$(CONFIG_BLOCKDSP)+= blockdsp.o
 OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
+OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
new file mode 100644
index 00..a3b487b529
--- /dev/null
+++ b/libavcodec/cbs.c
@@ -0,0 +1,479 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "config.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+
+
+static const CodedBitstreamType *cbs_type_table[] = {
+};
+
+int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
+enum AVCodecID codec_id, void *log_ctx)
+{
+CodedBitstreamContext *ctx;
+const CodedBitstreamType *type;
+int i;
+
+type = NULL;
+for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
+if (cbs_type_table[i]->codec_id == codec_id) {
+type = cbs_type_table[i];
+break;
+}
+}
+if (!type)
+return AVERROR(EINVAL);
+
+ctx = av_mallocz(sizeof(*ctx));
+if (!ctx)
+return AVERROR(ENOMEM);
+
+ctx->log_ctx = log_ctx;
+ctx->codec   = type;
+
+ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
+if (!ctx->priv_data) {
+av_freep(&ctx);
+return AVERROR(ENOMEM);
+}
+
+ctx->decompose_unit_types = NULL;
+
+ctx->trace_enable = 0;
+ctx->trace_level  = AV_LOG_TRACE;
+
+*ctx_ptr = ctx;
+return 0;
+}
+
+void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
+{
+CodedBitstreamContext *ctx = *ctx_ptr;
+
+if (ctx->codec && ctx->codec->close)
+ctx->codec->close(ctx);
+
+av_freep(&ctx->priv_data);
+av_freep(ctx_ptr);
+}
+
+static void cbs_unit_uninit(CodedBitstreamContext *ctx,
+CodedBitstreamUnit *unit)
+{
+if (ctx->codec->free_unit && unit->content && !unit->content_external)
+ctx->codec->free_unit(unit);
+
+av_freep(&unit->data);
+unit->data_size = 0;
+unit->data_bit_padding = 0;
+}
+
+void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
+CodedBitstreamFragment *frag)
+{
+int i;
+
+for (i = 0; i < frag->nb_units; i++)
+cbs_unit_uninit(ctx, &frag->units[i]);
+av_freep(&frag->units);
+frag->nb_units = 0;
+
+av_freep(&frag->data);
+frag->data_size= 0;
+frag->data_bit_padding = 0;
+}
+
+static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag)
+{
+int err, i, j;
+
+for (i = 0; i < frag->nb_units; i++) {
+if (ctx->decompose_unit_types) {
+for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
+if (ctx->decompose_unit_types[j] == frag->units[i].type)
+break;
+}
+if (j >= ctx->nb_decompose_unit_types)
+continue;
+}
+
+err = ctx->codec->read_unit(ctx, &frag->units[i]);
+if (err == AVER

[FFmpeg-devel] [PATCH 02/20] hevc: Improve stream constraint values in common header

2017-10-08 Thread Mark Thompson
Add comments to describe the sources of the constraint values expressed here,
and add some more related values which will be used in following patches.

Fix the incorrect values for SPS and PPS count (they are not the same as those
used for H.264), and remove HEVC_MAX_CU_SIZE because it is not used anywhere.

(cherry picked from commit b88da98b34809dedf8882d43ed543632ed233538)
---
 libavcodec/hevc.h| 65 ++--
 libavcodec/hevc_ps.c |  2 +-
 libavcodec/hevc_ps.h |  6 ++---
 libavformat/hevc.c   |  6 ++---
 4 files changed, 60 insertions(+), 19 deletions(-)

diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index f0fb919a7f..2f20db8285 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -74,19 +74,60 @@ enum HEVCSliceType {
 HEVC_SLICE_I = 2,
 };
 
-/**
- * 7.4.2.1
- */
-#define HEVC_MAX_SUB_LAYERS 7
-#define HEVC_MAX_VPS_COUNT 16
-#define HEVC_MAX_SPS_COUNT 32
-#define HEVC_MAX_PPS_COUNT 256
-#define HEVC_MAX_SHORT_TERM_RPS_COUNT 64
-#define HEVC_MAX_CU_SIZE 128
+enum {
+// 7.4.3.1: vps_max_layers_minus1 is in [0, 62].
+HEVC_MAX_LAYERS = 63,
+// 7.4.3.1: vps_max_sub_layers_minus1 is in [0, 6].
+HEVC_MAX_SUB_LAYERS = 7,
+// 7.4.3.1: vps_num_layer_sets_minus1 is in [0, 1023].
+HEVC_MAX_LAYER_SETS = 1024,
+
+// 7.4.2.1: vps_video_parameter_set_id is u(4).
+HEVC_MAX_VPS_COUNT = 16,
+// 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15].
+HEVC_MAX_SPS_COUNT = 16,
+// 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63].
+HEVC_MAX_PPS_COUNT = 64,
+
+// A.4.2: MaxDpbSize is bounded above by 16.
+HEVC_MAX_DPB_SIZE = 16,
+// 7.4.3.1: vps_max_dec_pic_buffering_minus1[i] is in [0, MaxDpbSize - 1].
+HEVC_MAX_REFS = HEVC_MAX_DPB_SIZE,
+
+// 7.4.3.2.1: num_short_term_ref_pic_sets is in [0, 64].
+HEVC_MAX_SHORT_TERM_REF_PIC_SETS = 64,
+// 7.4.3.2.1: num_long_term_ref_pics_sps is in [0, 32].
+HEVC_MAX_LONG_TERM_REF_PICS  = 32,
 
-#define HEVC_MAX_REFS 16
-#define HEVC_MAX_DPB_SIZE 16 // A.4.1
+// A.3: all profiles require that CtbLog2SizeY is in [4, 6].
+HEVC_MIN_LOG2_CTB_SIZE = 4,
+HEVC_MAX_LOG2_CTB_SIZE = 6,
+
+// E.3.2: cpb_cnt_minus1[i] is in [0, 31].
+HEVC_MAX_CPB_CNT = 32,
+
+// A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 651 584.
+HEVC_MAX_LUMA_PS = 35651584,
+// A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are
+// constrained to be not greater than sqrt(MaxLumaPs * 8).  Hence height/
+// width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
+HEVC_MAX_WIDTH  = 16888,
+HEVC_MAX_HEIGHT = 16888,
+
+// A.4.1: table A.6 allows at most 22 tile rows for any level.
+HEVC_MAX_TILE_ROWS= 22,
+// A.4.1: table A.6 allows at most 20 tile columns for any level.
+HEVC_MAX_TILE_COLUMNS = 20,
+
+// 7.4.7.1: in the worst case (tiles_enabled_flag and
+// entropy_coding_sync_enabled_flag are both set), entry points can be
+// placed at the beginning of every Ctb row in every tile, giving an
+// upper bound of (num_tile_columns_minus1 + 1) * PicHeightInCtbsY - 1.
+// Only a stream with very high resolution and perverse parameters could
+// get near that, though, so set a lower limit here with the maximum
+// possible value for 4K video (at most 135 16x16 Ctb rows).
+HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
+};
 
-#define HEVC_MAX_LOG2_CTB_SIZE 6
 
 #endif /* AVCODEC_HEVC_H */
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 902917d4dd..72d02c8372 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1061,7 +1061,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 }
 
 sps->nb_st_rps = get_ue_golomb_long(gb);
-if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_RPS_COUNT) {
+if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) {
 av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
sps->nb_st_rps);
 return AVERROR_INVALIDDATA;
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 76f8eb31e6..477ee4299a 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -254,14 +254,14 @@ typedef struct HEVCSPS {
 ScalingList scaling_list;
 
 unsigned int nb_st_rps;
-ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT];
+ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
 
 uint8_t amp_enabled_flag;
 uint8_t sao_enabled;
 
 uint8_t long_term_ref_pics_present_flag;
-uint16_t lt_ref_pic_poc_lsb_sps[32];
-uint8_t used_by_curr_pic_lt_sps_flag[32];
+uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS];
+uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS];
 uint8_t num_long_term_ref_pics_sps;
 
 struct {
diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 1a2d6cdd2b..e45d2c08d2 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -417,7 

[FFmpeg-devel] [PATCH 09/20] lavc: Add h264_redundant_pps bitstream filter

2017-10-08 Thread Mark Thompson
This applies a specific fixup to some Bluray streams which contain
redundant PPSs modifying irrelevant parameters of the stream which
confuse other transformations which require correct extradata.

A new single global PPS is created, and all of the redundant PPSs
within the stream are removed.

(cherry picked from commit e6874bc3af2f09af39b5d91b9c5f9ded67459696)
---
 configure   |   1 +
 doc/bitstream_filters.texi  |   9 ++
 libavcodec/Makefile |   1 +
 libavcodec/bitstream_filters.c  |   1 +
 libavcodec/h264_redundant_pps_bsf.c | 178 
 5 files changed, 190 insertions(+)
 create mode 100644 libavcodec/h264_redundant_pps_bsf.c

diff --git a/configure b/configure
index 93a3e44230..fd2b11611b 100755
--- a/configure
+++ b/configure
@@ -2906,6 +2906,7 @@ vc1_parser_select="vc1dsp"
 
 # bitstream_filters
 h264_metadata_bsf_select="cbs_h264"
+h264_redundant_pps_bsf_select="cbs_h264"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index f7dfa1f753..f9d17dc1b1 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -174,6 +174,15 @@ ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb 
OUTPUT.ts
 Please note that this filter is auto-inserted for MPEG-TS (muxer
 @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
 
+@section h264_redundant_pps
+
+This applies a specific fixup to some Bluray streams which contain
+redundant PPSs modifying irrelevant parameters of the stream which
+confuse other transformations which require correct extradata.
+
+A new single global PPS is created, and all of the redundant PPSs
+within the stream are removed.
+
 @section hevc_mp4toannexb
 
 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 25ad785dbe..a5b2b17cf3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1017,6 +1017,7 @@ OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += 
extract_extradata_bsf.o\
  h2645_parse.o
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
+OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
 OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 0e133b9036..5ab4f14642 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -31,6 +31,7 @@ extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
+extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
diff --git a/libavcodec/h264_redundant_pps_bsf.c 
b/libavcodec/h264_redundant_pps_bsf.c
new file mode 100644
index 00..26baca84e3
--- /dev/null
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -0,0 +1,178 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/mem.h"
+
+#include "bsf.h"
+#include "cbs.h"
+#include "cbs_h264.h"
+#include "h264.h"
+
+
+typedef struct H264RedundantPPSContext {
+CodedBitstreamContext *input;
+CodedBitstreamContext *output;
+
+CodedBitstreamFragment access_unit;
+
+int global_pic_init_qp;
+int current_pic_init_qp;
+} H264RedundantPPSContext;
+
+
+static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
+H264RawPPS *pps)
+{
+// Record the current value of pic_init_qp in order to fix up
+// following slices, then overwrite with the global value.
+ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26;
+pps->pic_init_qp_m

[FFmpeg-devel] [PATCH 01/20] h264: Add stream constraint values to the common header

2017-10-08 Thread Mark Thompson
With comments describing the derivation of each value.

(cherry picked from commit aaf441465080b9bc57f5ca8dea656f9b2c5dc821)
---
 libavcodec/h264.h | 45 +
 1 file changed, 45 insertions(+)

diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 86df5eb9b3..650580bf3a 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -44,4 +44,49 @@ enum {
 H264_NAL_AUXILIARY_SLICE = 19,
 };
 
+
+enum {
+// 7.4.2.1.1: seq_parameter_set_id is in [0, 31].
+H264_MAX_SPS_COUNT = 32,
+// 7.4.2.2: pic_parameter_set_id is in [0, 255].
+H264_MAX_PPS_COUNT = 256,
+
+// A.3: MaxDpbFrames is bounded above by 16.
+H264_MAX_DPB_FRAMES = 16,
+// 7.4.2.1.1: max_num_ref_frames is in [0, MaxDpbFrames], and
+// each reference frame can have two fields.
+H264_MAX_REFS   = 2 * H264_MAX_DPB_FRAMES,
+
+// 7.4.3.1: modification_of_pic_nums_idc is not equal to 3 at most
+// num_ref_idx_lN_active_minus1 + 1 times (that is, once for each
+// possible reference), then equal to 3 once.
+H264_MAX_RPLM_COUNT = H264_MAX_REFS + 1,
+
+// 7.4.3.3: in the worst case, we begin with a full short-term
+// reference picture list.  Each picture in turn is moved to the
+// long-term list (type 3) and then discarded from there (type 2).
+// Then, we set the length of the long-term list (type 4), mark
+// the current picture as long-term (type 6) and terminate the
+// process (type 0).
+H264_MAX_MMCO_COUNT = H264_MAX_REFS * 2 + 3,
+
+// A.2.1, A.2.3: profiles supporting FMO constrain
+// num_slice_groups_minus1 to be in [0, 7].
+H264_MAX_SLICE_GROUPS = 8,
+
+// E.2.2: cpb_cnt_minus1 is in [0, 31].
+H264_MAX_CPB_CNT = 32,
+
+// A.3: in table A-1 the highest level allows a MaxFS of 139264.
+H264_MAX_MB_PIC_SIZE = 139264,
+// A.3.1, A.3.2: PicWidthInMbs and PicHeightInMbs are constrained
+// to be not greater than sqrt(MaxFS * 8).  Hence height/width are
+// bounded above by sqrt(139264 * 8) = 1055.5 macroblocks.
+H264_MAX_MB_WIDTH= 1055,
+H264_MAX_MB_HEIGHT   = 1055,
+H264_MAX_WIDTH   = H264_MAX_MB_WIDTH  * 16,
+H264_MAX_HEIGHT  = H264_MAX_MB_HEIGHT * 16,
+};
+
+
 #endif /* AVCODEC_H264_H */
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 08/20] lavc: Add h264_metadata bitstream filter

2017-10-08 Thread Mark Thompson
This is able to modify some header metadata found in the SPS/VUI,
and can also add/remove AUDs and insert user data in SEI NAL units.

(cherry picked from commit 9e93001b6135a23fe4e200196c08fb4fbffed6fc)
(cherry picked from commit c42b62d1f9641f10ffc23cad9abbe47d8a4a165b)
---
 configure  |   1 +
 doc/bitstream_filters.texi |  63 +
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/h264_metadata_bsf.c | 520 +
 5 files changed, 586 insertions(+)
 create mode 100644 libavcodec/h264_metadata_bsf.c

diff --git a/configure b/configure
index 70402c03d0..93a3e44230 100755
--- a/configure
+++ b/configure
@@ -2905,6 +2905,7 @@ mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
 vc1_parser_select="vc1dsp"
 
 # bitstream_filters
+h264_metadata_bsf_select="cbs_h264"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 990b4f3c58..f7dfa1f753 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -92,6 +92,69 @@ When this option is enabled, the long-term headers are 
removed from the
 bitstream after extraction.
 @end table
 
+@section h264_metadata
+
+Modify metadata embedded in an H.264 stream.
+
+@table @option
+@item aud
+Insert or remove AUD NAL units in all access units of the stream.
+
+@table @samp
+@item insert
+@item remove
+@end table
+
+@item sample_aspect_ratio
+Set the sample aspect ratio of the stream in the VUI parameters.
+
+@item video_format
+@item video_full_range_flag
+Set the video format in the stream (see H.264 section E.2.1 and
+table E-2).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.264 section E.2.1
+and tables E-3, E-4 and E-5).
+
+@item chroma_sample_loc_type
+Set the chroma sample location in the stream (see H.264 section
+E.2.1 and figure E-1).
+
+@item tick_rate
+Set the tick rate (num_units_in_tick / time_scale) in the VUI
+parameters.  This is the smallest time unit representable in the
+stream, and in many cases represents the field rate of the stream
+(double the frame rate).
+@item fixed_frame_rate_flag
+Set whether the stream has fixed framerate - typically this indicates
+that the framerate is exactly half the tick rate, but the exact
+meaning is dependent on interlacing and the picture structure (see
+H.264 section E.2.1 and table E-6).
+
+@item crop_left
+@item crop_right
+@item crop_top
+@item crop_bottom
+Set the frame cropping offsets in the SPS.  These values will replace
+the current ones if the stream is already cropped.
+
+These fields are set in pixels.  Note that some sizes may not be
+representable if the chroma is subsampled or the stream is interlaced
+(see H.264 section 7.4.2.1.1).
+
+@item sei_user_data
+Insert a string as SEI unregistered user data.  The argument must
+be of the form @emph{UUID+string}, where the UUID is as hex digits
+possibly separated by hyphens, and the string can be anything.
+
+For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
+insert the string ``hello'' associated with the given UUID.
+
+@end table
+
 @section h264_mp4toannexb
 
 Convert an H.264 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5e09889bc6..25ad785dbe 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1015,6 +1015,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
+OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index dd0247182b..0e133b9036 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
+extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
new file mode 100644
index 00..81bf760c8b
--- /dev/null
+++ b/libavcodec/h264_metadata_bsf.c
@@ -0,0 +1,520 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it an

[FFmpeg-devel] [PATCH 04/20] lavc: Add coded bitstream read/write support for H.264

2017-10-08 Thread Mark Thompson
(cherry picked from commit acf06f45441be24c5cbae0920579cd69427326a1)
(cherry picked from commit 768eb9182e94a94bc2ef46f565a0dac7afef3b57)
(cherry picked from commit e7f64191b27bcf37cbf7006606f0f439c6cdc24f)
---
 configure |2 +
 libavcodec/Makefile   |1 +
 libavcodec/cbs.c  |3 +
 libavcodec/cbs.h  |2 +
 libavcodec/cbs_h264.h |  427 
 libavcodec/cbs_h2645.c| 1010 +++
 libavcodec/cbs_h2645.h|   43 ++
 libavcodec/cbs_h264_syntax_template.c | 1230 +
 libavcodec/cbs_internal.h |3 +
 9 files changed, 2721 insertions(+)
 create mode 100644 libavcodec/cbs_h264.h
 create mode 100644 libavcodec/cbs_h2645.c
 create mode 100644 libavcodec/cbs_h2645.h
 create mode 100644 libavcodec/cbs_h264_syntax_template.c

diff --git a/configure b/configure
index b238293cc1..ffb21f1a70 100755
--- a/configure
+++ b/configure
@@ -2143,6 +2143,7 @@ CONFIG_EXTRA="
 bswapdsp
 cabac
 cbs
+cbs_h264
 dirac_parse
 dvprofile
 exif
@@ -2395,6 +2396,7 @@ w32threads_deps="atomics_native"
 threads_if_any="$THREADS_LIST"
 
 # subsystems
+cbs_h264_select="cbs golomb"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9680553c90..245a44c7d5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -60,6 +60,7 @@ OBJS-$(CONFIG_BLOCKDSP)+= blockdsp.o
 OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
+OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index a3b487b529..2c52d898c0 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -28,6 +28,9 @@
 
 
 static const CodedBitstreamType *cbs_type_table[] = {
+#if CONFIG_CBS_H264
+&ff_cbs_type_h264,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index e35175fc74..79420cdadf 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -29,6 +29,8 @@ struct CodedBitstreamType;
 
 /**
  * The codec-specific type of a bitstream unit.
+ *
+ * H.264 / AVC: nal_unit_type
  */
 typedef uint32_t CodedBitstreamUnitType;
 
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
new file mode 100644
index 00..ab7dfd855f
--- /dev/null
+++ b/libavcodec/cbs_h264.h
@@ -0,0 +1,427 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_CBS_H264_H
+#define AVCODEC_CBS_H264_H
+
+#include 
+#include 
+
+#include "cbs_h2645.h"
+#include "h264.h"
+
+
+enum {
+// This limit is arbitrary - it is sufficient for one message of each
+// type plus some repeats, and will therefore easily cover all sane
+// streams.  However, it is possible to make technically-valid streams
+// for which it will fail (for example, by including a large number of
+// user-data-unregistered messages).
+H264_MAX_SEI_PAYLOADS = 64,
+};
+
+
+typedef struct H264RawNALUnitHeader {
+uint8_t forbidden_zero_bit;
+uint8_t nal_ref_idc;
+uint8_t nal_unit_type;
+
+uint8_t svc_extension_flag;
+uint8_t avc_3d_extension_flag;
+} H264RawNALUnitHeader;
+
+typedef struct H264RawScalingList {
+int8_t delta_scale[64];
+} H264RawScalingList;
+
+typedef struct H264RawHRD {
+uint8_t cpb_cnt_minus1;
+uint8_t bit_rate_scale;
+uint8_t cpb_size_scale;
+
+uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT];
+uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT];
+uint8_t cbr_flag[H264_MAX_CPB_CNT];
+
+uint8_t initial_cpb_removal_delay_length_minus1;
+uint8_t cpb_removal_delay_length_minus1;
+uint8_t dpb_output_delay_length_minus1;
+uint8_t time_offset_length;
+} H264RawHRD;
+
+typedef struct H264RawVUI {
+uint8_t aspect_ratio_info_present_flag;
+uint8_t aspect_ratio_i

[FFmpeg-devel] [PATCH 10/20] lavc: Add hevc_metadata bitstream filter

2017-10-08 Thread Mark Thompson
This is able to modify some header metadata found in the VPS/SPS/VUI,
and can also add/remove AUDs.

(cherry picked from commit b31a9eae0233325c4b382c657f4b687d5d8b0812)
---
 configure  |   1 +
 doc/bitstream_filters.texi |  54 +
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/h265_metadata_bsf.c | 458 +
 5 files changed, 515 insertions(+)
 create mode 100644 libavcodec/h265_metadata_bsf.c

diff --git a/configure b/configure
index fd2b11611b..f0e5150c40 100755
--- a/configure
+++ b/configure
@@ -2907,6 +2907,7 @@ vc1_parser_select="vc1dsp"
 # bitstream_filters
 h264_metadata_bsf_select="cbs_h264"
 h264_redundant_pps_bsf_select="cbs_h264"
+hevc_metadata_bsf_select="cbs_h265"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index f9d17dc1b1..71c307f2e2 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -183,6 +183,60 @@ confuse other transformations which require correct 
extradata.
 A new single global PPS is created, and all of the redundant PPSs
 within the stream are removed.
 
+@section hevc_metadata
+
+Modify metadata embedded in an HEVC stream.
+
+@table @option
+@item aud
+Insert or remove AUD NAL units in all access units of the stream.
+
+@table @samp
+@item insert
+@item remove
+@end table
+
+@item sample_aspect_ratio
+Set the sample aspect ratio in the stream in the VUI parameters.
+
+@item video_format
+@item video_full_range_flag
+Set the video format in the stream (see H.265 section E.3.1 and
+table E.2).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.265 section E.3.1
+and tables E.3, E.4 and E.5).
+
+@item chroma_sample_loc_type
+Set the chroma sample location in the stream (see H.265 section
+E.3.1 and figure E.1).
+
+@item tick_rate
+Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
+time_scale).  Combined with @option{num_ticks_poc_diff_one}, this can
+set a constant framerate in the stream.  Note that it is likely to be
+overridden by container parameters when the stream is in a container.
+
+@item num_ticks_poc_diff_one
+Set poc_proportional_to_timing_flag in VPS and VUI and use this value
+to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
+E.3.1).  Ignored if @option{tick_rate} is not also set.
+
+@item crop_left
+@item crop_right
+@item crop_top
+@item crop_bottom
+Set the conformance window cropping offsets in the SPS.  These values
+will replace the current ones if the stream is already cropped.
+
+These fields are set in pixels.  Note that some sizes may not be
+representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
+
+@end table
+
 @section hevc_mp4toannexb
 
 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a5b2b17cf3..8a68c1b929 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1018,6 +1018,7 @@ OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += 
extract_extradata_bsf.o\
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
+OBJS-$(CONFIG_HEVC_METADATA_BSF)  += h265_metadata_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
 OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 5ab4f14642..6e6b894e7f 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -32,6 +32,7 @@ extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
+extern const AVBitStreamFilter ff_hevc_metadata_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
new file mode 100644
index 00..9af5cc256f
--- /dev/null
+++ b/libavcodec/h265_metadata_bsf.c
@@ -0,0 +1,458 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABI

[FFmpeg-devel] [PATCH 11/20] mpeg12: Add a common function to find the best frame rate

2017-10-08 Thread Mark Thompson
This will be used later in both the mpeg2_metadata filter and the
VAAPI MPEG-2 encoder.  Also adds a unit test.

(cherry picked from commit b5859e0b04bdbe12c97cb12ac10a45d51d2d73c9)
---
 libavcodec/Makefile|  1 +
 libavcodec/mpeg12.h|  4 ++
 libavcodec/mpeg12framerate.c   | 64 
 libavcodec/tests/mpeg12framerate.c | 87 ++
 tests/fate/libavcodec.mak  |  5 +++
 5 files changed, 161 insertions(+)
 create mode 100644 libavcodec/tests/mpeg12framerate.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8a68c1b929..a0b23a794e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1090,6 +1090,7 @@ TESTPROGS-$(CONFIG_GOLOMB)+= golomb
 TESTPROGS-$(CONFIG_IDCTDSP)   += dct
 TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
 TESTPROGS-$(HAVE_MMX) += motion
+TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h
index f551504b8c..1ec99f17e1 100644
--- a/libavcodec/mpeg12.h
+++ b/libavcodec/mpeg12.h
@@ -73,4 +73,8 @@ void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t 
block[8][64],
 void ff_mpeg1_encode_init(MpegEncContext *s);
 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
 
+void ff_mpeg12_find_best_frame_rate(AVRational frame_rate,
+int *code, int *ext_n, int *ext_d,
+int nonstandard);
+
 #endif /* AVCODEC_MPEG12_H */
diff --git a/libavcodec/mpeg12framerate.c b/libavcodec/mpeg12framerate.c
index 094cd180a5..ab3d351173 100644
--- a/libavcodec/mpeg12framerate.c
+++ b/libavcodec/mpeg12framerate.c
@@ -18,6 +18,9 @@
 
 #include "libavutil/rational.h"
 
+#include "mpeg12.h"
+#include "mpeg12data.h"
+
 const AVRational ff_mpeg12_frame_rate_tab[16] = {
 {0,0},
 {24000, 1001},
@@ -37,3 +40,64 @@ const AVRational ff_mpeg12_frame_rate_tab[16] = {
 {   15,1},
 {0,0},
 };
+
+void ff_mpeg12_find_best_frame_rate(AVRational frame_rate,
+int *code, int *ext_n, int *ext_d,
+int nonstandard)
+{
+int mpeg2 = ext_n && ext_d;
+int max_code = nonstandard ? 12 : 8;
+int c, n, d, best_c, best_n, best_d;
+AVRational best_error = { INT_MAX, 1 };
+
+// Default to NTSC if the inputs make no sense.
+best_c = 4;
+best_n = best_d = 1;
+
+for (c = 1; c <= max_code; c++) {
+if (av_cmp_q(frame_rate, ff_mpeg12_frame_rate_tab[c]) == 0) {
+best_c = c;
+goto found;
+}
+}
+
+for (c = 1; c <= max_code; c++) {
+for (n = 1; n <= (mpeg2 ? 4 : 1); n++) {
+for (d = 1; d <= (mpeg2 ? 32 : 1); d++) {
+AVRational test, error;
+int cmp;
+
+test = av_mul_q(ff_mpeg12_frame_rate_tab[c],
+(AVRational) { n, d });
+
+cmp = av_cmp_q(test, frame_rate);
+if (cmp == 0) {
+best_c = c;
+best_n = n;
+best_d = d;
+goto found;
+}
+
+if (cmp < 0)
+error = av_div_q(frame_rate, test);
+else
+error = av_div_q(test, frame_rate);
+
+cmp = av_cmp_q(error, best_error);
+if (cmp < 0 || (cmp == 0 && n == 1 && d == 1)) {
+best_c = c;
+best_n = n;
+best_d = d;
+best_error = error;
+}
+}
+}
+}
+
+found:
+*code = best_c;
+if (mpeg2) {
+*ext_n = best_n - 1;
+*ext_d = best_d - 1;
+}
+}
diff --git a/libavcodec/tests/mpeg12framerate.c 
b/libavcodec/tests/mpeg12framerate.c
new file mode 100644
index 00..595bdb278a
--- /dev/null
+++ b/libavcodec/tests/mpeg12framerate.c
@@ -0,0 +1,87 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/mpeg12.h"
+#include "libavcodec/mpeg12

[FFmpeg-devel] [PATCH 06/20] lavc: Add coded bitstream read/write support for MPEG-2

2017-10-08 Thread Mark Thompson
(cherry picked from commit 2bc9ba8d3c41f3a8e56484bd67b05040c7909a01)
(cherry picked from commit a41b69b5eb950c10d8ede472bcc4e88ce4246db9)
---
 configure  |   2 +
 libavcodec/Makefile|   1 +
 libavcodec/cbs.c   |   3 +
 libavcodec/cbs.h   |   1 +
 libavcodec/cbs_internal.h  |   1 +
 libavcodec/cbs_mpeg2.c | 414 +
 libavcodec/cbs_mpeg2.h | 224 ++
 libavcodec/cbs_mpeg2_syntax_template.c | 384 ++
 8 files changed, 1030 insertions(+)
 create mode 100644 libavcodec/cbs_mpeg2.c
 create mode 100644 libavcodec/cbs_mpeg2.h
 create mode 100644 libavcodec/cbs_mpeg2_syntax_template.c

diff --git a/configure b/configure
index 60075352e2..37efffac86 100755
--- a/configure
+++ b/configure
@@ -2145,6 +2145,7 @@ CONFIG_EXTRA="
 cbs
 cbs_h264
 cbs_h265
+cbs_mpeg2
 dirac_parse
 dvprofile
 exif
@@ -2399,6 +2400,7 @@ threads_if_any="$THREADS_LIST"
 # subsystems
 cbs_h264_select="cbs golomb"
 cbs_h265_select="cbs golomb"
+cbs_mpeg2_select="cbs"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 39b7dd1e2f..0265c92130 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -62,6 +62,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index e37c0ea137..03356c2084 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -34,6 +34,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H265
 &ff_cbs_type_h265,
 #endif
+#if CONFIG_CBS_MPEG2
+&ff_cbs_type_mpeg2,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 78f2c5b8d7..462255d877 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -32,6 +32,7 @@ struct CodedBitstreamType;
  *
  * H.264 / AVC: nal_unit_type
  * H.265 / HEVC: nal_unit_type
+ * MPEG-2: start code value (without prefix)
  */
 typedef uint32_t CodedBitstreamUnitType;
 
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index f8263bef0a..ae0b417b43 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -85,6 +85,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
+extern const CodedBitstreamType ff_cbs_type_mpeg2;
 
 
 #endif /* AVCODEC_CBS_INTERNAL_H */
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
new file mode 100644
index 00..d137762227
--- /dev/null
+++ b/libavcodec/cbs_mpeg2.c
@@ -0,0 +1,414 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_mpeg2.h"
+#include "internal.h"
+
+
+#define HEADER(name) do { \
+ff_cbs_trace_header(ctx, name); \
+} while (0)
+
+#define CHECK(call) do { \
+err = (call); \
+if (err < 0) \
+return err; \
+} while (0)
+
+#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
+#define FUNC_MPEG2(rw, name) FUNC_NAME(rw, mpeg2, name)
+#define FUNC(name) FUNC_MPEG2(READWRITE, name)
+
+
+#define READ
+#define READWRITE read
+#define RWContext GetBitContext
+
+#define xui(width, name, var) do { \
+uint32_t value = 0; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+   &value, 0, (1 << width) - 1)); \
+var = value; \
+} while (0)
+
+#define ui(width, name) \
+xui(width, name, current->name)
+
+#define marker_bit() do { \
+av_unused int one = 1; \
+ 

[FFmpeg-devel] [PATCH 05/20] lavc: Add coded bitstream read/write support for H.265

2017-10-08 Thread Mark Thompson
(cherry picked from commit 867381b8b51fa21fa2b8f071f508f3d39cc9c1f0)
(cherry picked from commit f763489364416bb6866adc4f4a96012dd2ca1bd0)
(cherry picked from commit 067a9ddeb8feff1f724856f0054930c55219f76b)
---
 configure |2 +
 libavcodec/Makefile   |1 +
 libavcodec/cbs.c  |3 +
 libavcodec/cbs.h  |1 +
 libavcodec/cbs_h2645.c|  413 -
 libavcodec/cbs_h265.h |  537 
 libavcodec/cbs_h265_syntax_template.c | 1503 +
 libavcodec/cbs_internal.h |1 +
 8 files changed, 2458 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/cbs_h265.h
 create mode 100644 libavcodec/cbs_h265_syntax_template.c

diff --git a/configure b/configure
index ffb21f1a70..60075352e2 100755
--- a/configure
+++ b/configure
@@ -2144,6 +2144,7 @@ CONFIG_EXTRA="
 cabac
 cbs
 cbs_h264
+cbs_h265
 dirac_parse
 dvprofile
 exif
@@ -2397,6 +2398,7 @@ threads_if_any="$THREADS_LIST"
 
 # subsystems
 cbs_h264_select="cbs golomb"
+cbs_h265_select="cbs golomb"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 245a44c7d5..39b7dd1e2f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -61,6 +61,7 @@ OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 2c52d898c0..e37c0ea137 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -31,6 +31,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H264
 &ff_cbs_type_h264,
 #endif
+#if CONFIG_CBS_H265
+&ff_cbs_type_h265,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 79420cdadf..78f2c5b8d7 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -31,6 +31,7 @@ struct CodedBitstreamType;
  * The codec-specific type of a bitstream unit.
  *
  * H.264 / AVC: nal_unit_type
+ * H.265 / HEVC: nal_unit_type
  */
 typedef uint32_t CodedBitstreamUnitType;
 
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index f03fd3ce72..bd2b5cbbf2 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -23,10 +23,12 @@
 #include "cbs.h"
 #include "cbs_internal.h"
 #include "cbs_h264.h"
+#include "cbs_h265.h"
 #include "golomb.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
+#include "hevc.h"
 
 
 static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
@@ -235,6 +237,7 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 
 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
+#define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
 
 
 #define READ
@@ -297,6 +300,10 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #include "cbs_h264_syntax_template.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax_template.c"
+#undef FUNC
+
 #undef READ
 #undef READWRITE
 #undef RWContext
@@ -366,6 +373,10 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #include "cbs_h264_syntax_template.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax_template.c"
+#undef FUNC
+
 #undef WRITE
 #undef READWRITE
 #undef RWContext
@@ -426,6 +437,40 @@ static void cbs_h264_free_nal_unit(CodedBitstreamUnit 
*unit)
 av_freep(&unit->content);
 }
 
+static void cbs_h265_free_nal_unit(CodedBitstreamUnit *unit)
+{
+switch (unit->type) {
+case HEVC_NAL_VPS:
+av_freep(&((H265RawVPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_SPS:
+av_freep(&((H265RawSPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_PPS:
+av_freep(&((H265RawPPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_TRAIL_N:
+case HEVC_NAL_TRAIL_R:
+case HEVC_NAL_TSA_N:
+case HEVC_NAL_TSA_R:
+case HEVC_NAL_STSA_N:
+case HEVC_NAL_STSA_R:
+case HEVC_NAL_RADL_N:
+case HEVC_NAL_RADL_R:
+case HEVC_NAL_RASL_N:
+case HEVC_NAL_RASL_R:
+case HEVC_NAL_BLA_W_LP:
+case HEVC_NAL_BLA_W_RADL:
+case HEVC_NAL_BLA_N_LP:
+case HEVC_NAL_IDR_W_RADL:
+case HEVC_NAL_IDR_N_LP:
+case HEVC_NAL_CRA_NUT:
+av_freep(&((H265RawSlice*)unit->content)->data);
+break;
+

[FFmpeg-devel] [PATCH 07/20] lavc: Add trace_headers bitstream filter

2017-10-08 Thread Mark Thompson
Supports all streams that the coded bitstream infrastructure does
(currently H.264, H.265 and MPEG-2).

(cherry picked from commit f11d8a5e8b185340cc50fcbc8a1437b0fbe7e931)
---
 configure  |   1 +
 doc/bitstream_filters.texi |   8 +++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/trace_headers_bsf.c | 126 +
 5 files changed, 137 insertions(+)
 create mode 100644 libavcodec/trace_headers_bsf.c

diff --git a/configure b/configure
index 37efffac86..70402c03d0 100755
--- a/configure
+++ b/configure
@@ -2906,6 +2906,7 @@ vc1_parser_select="vc1dsp"
 
 # bitstream_filters
 mjpeg2jpeg_bsf_select="jpegtables"
+trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
 # external libraries
 aac_at_decoder_deps="audiotoolbox"
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 2dffe021f9..990b4f3c58 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -275,6 +275,14 @@ codec) with metadata headers.
 
 See also the @ref{mov2textsub} filter.
 
+@section trace_headers
+
+Log trace output containing all syntax elements in the coded stream
+headers (everything above the level of individual coded blocks).
+This can be useful for debugging low-level stream issues.
+
+Supports H.264, H.265 and MPEG-2.
+
 @section vp9_superframe
 
 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0265c92130..5e09889bc6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1028,6 +1028,7 @@ OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
+OBJS-$(CONFIG_TRACE_HEADERS_BSF)  += trace_headers_bsf.o
 OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF)   += vp9_superframe_split_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index ce34de640d..dd0247182b 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -41,6 +41,7 @@ extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
+extern const AVBitStreamFilter ff_trace_headers_bsf;
 extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_split_bsf;
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
new file mode 100644
index 00..93d04cb509
--- /dev/null
+++ b/libavcodec/trace_headers_bsf.c
@@ -0,0 +1,126 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/log.h"
+
+#include "bsf.h"
+#include "cbs.h"
+
+
+typedef struct TraceHeadersContext {
+CodedBitstreamContext *cbc;
+} TraceHeadersContext;
+
+
+static int trace_headers_init(AVBSFContext *bsf)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+int err;
+
+err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
+if (err < 0)
+return err;
+
+ctx->cbc->trace_enable = 1;
+ctx->cbc->trace_level  = AV_LOG_INFO;
+
+if (bsf->par_in->extradata) {
+CodedBitstreamFragment ps;
+
+av_log(bsf, AV_LOG_INFO, "Extradata\n");
+
+err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
+return err;
+}
+
+ff_cbs_fragment_uninit(ctx->cbc, &ps);
+}
+
+return 0;
+}
+
+static void trace_headers_close(AVBSFContext *bsf)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+
+ff_cbs_close(&ctx->cbc);
+}
+
+static int trace_headers(AVBSFContext *bsf, AVPacket *out)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+CodedBitstreamFragment au;
+AVPacket *in;
+c

[FFmpeg-devel] [PATCH 12/20] lavc: Add mpeg2_metadata bitstream filter

2017-10-08 Thread Mark Thompson
(cherry picked from commit b78c30d7ec26af67c00ce2002709a189f6a87a7e)
---
 configure   |   1 +
 doc/bitstream_filters.texi  |  36 +
 libavcodec/Makefile |   1 +
 libavcodec/bitstream_filters.c  |   1 +
 libavcodec/mpeg2_metadata_bsf.c | 312 
 5 files changed, 351 insertions(+)
 create mode 100644 libavcodec/mpeg2_metadata_bsf.c

diff --git a/configure b/configure
index f0e5150c40..68c3243ce7 100755
--- a/configure
+++ b/configure
@@ -2909,6 +2909,7 @@ h264_metadata_bsf_select="cbs_h264"
 h264_redundant_pps_bsf_select="cbs_h264"
 hevc_metadata_bsf_select="cbs_h265"
 mjpeg2jpeg_bsf_select="jpegtables"
+mpeg2_metadata_bsf_select="cbs_mpeg2"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
 # external libraries
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 71c307f2e2..8a8756bdcc 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -324,6 +324,42 @@ See also the @ref{text2movsub} filter.
 
 Decompress non-standard compressed MP3 audio headers.
 
+@section mpeg2_metadata
+
+Modify metadata embedded in an MPEG-2 stream.
+
+@table @option
+@item display_aspect_ratio
+Set the display aspect ratio in the stream.
+
+The following fixed values are supported:
+@table @option
+@item 4/3
+@item 16/9
+@item 221/100
+@end table
+Any other value will result in square pixels being signalled instead
+(see H.262 section 6.3.3 and table 6-3).
+
+@item frame_rate
+Set the frame rate in the stream.  This is constructed from a table
+of known values combined with a small multiplier and divisor - if
+the supplied value is not exactly representable, the nearest
+representable value will be used instead (see H.262 section 6.3.3
+and table 6-4).
+
+@item video_format
+Set the video format in the stream (see H.262 section 6.3.6 and
+table 6-6).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.262 section 6.3.6
+and tables 6-7, 6-8 and 6-9).
+
+@end table
+
 @section mpeg4_unpack_bframes
 
 Unpack DivX-style packed B-frames.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a0b23a794e..6d6fc36f15 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1027,6 +1027,7 @@ OBJS-$(CONFIG_MPEG4_UNPACK_BFRAMES_BSF)   += 
mpeg4_unpack_bframes_bsf.o
 OBJS-$(CONFIG_MOV2TEXTSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
  mpegaudiodata.o
+OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6e6b894e7f..7b0cb5032a 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -38,6 +38,7 @@ extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
 extern const AVBitStreamFilter ff_mjpega_dump_header_bsf;
 extern const AVBitStreamFilter ff_mp3_header_decompress_bsf;
+extern const AVBitStreamFilter ff_mpeg2_metadata_bsf;
 extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
new file mode 100644
index 00..f1f84e6cd9
--- /dev/null
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -0,0 +1,312 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "bsf.h"
+#include "cbs.h"
+#include "cbs_mpeg2.h"
+#include "mpeg12.h"
+
+typedef struct MPEG2MetadataContext {
+const AVClass *class;
+
+CodedBitstreamContext *cbc;
+CodedBitstreamFragment fragment;
+
+MPEG2RawExtensionData sequence_display_extension;
+
+AVRational display_aspect_ratio;
+
+AVRational frame_rate;
+
+int video_format;
+int colour_primaries;
+int transfer_characteristics;
+  

[FFmpeg-devel] [PATCH 13/20] vaapi_h264: Convert to use coded bitstream infrastructure

2017-10-08 Thread Mark Thompson
(cherry picked from commit 7a4fac5e91789b73e07bd4ad20493cfde028df76)
---
 configure  |2 +-
 libavcodec/Makefile|2 +-
 libavcodec/vaapi_encode_h264.c | 1425 
 3 files changed, 551 insertions(+), 878 deletions(-)

diff --git a/configure b/configure
index 68c3243ce7..e5565f10aa 100755
--- a/configure
+++ b/configure
@@ -2818,7 +2818,7 @@ h264_qsv_encoder_select="qsvenc"
 h264_rkmpp_decoder_deps="rkmpp"
 h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
 h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
-h264_vaapi_encoder_select="vaapi_encode golomb"
+h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
 h264_vda_decoder_deps="vda"
 h264_vda_decoder_select="h264_decoder"
 h264_vdpau_decoder_deps="vdpau"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6d6fc36f15..7b6fcd7aa2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -346,7 +346,7 @@ OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
 OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
-OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o 
vaapi_encode_h26x.o
+OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_H264_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
 OBJS-$(CONFIG_H264_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 549867ef3f..e8d04efbc5 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -16,128 +16,36 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include 
 #include 
 
 #include "libavutil/avassert.h"
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
+#include "cbs.h"
+#include "cbs_h264.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "internal.h"
 #include "vaapi_encode.h"
-#include "vaapi_encode_h26x.h"
 
 enum {
-SLICE_TYPE_P  = 0,
-SLICE_TYPE_B  = 1,
-SLICE_TYPE_I  = 2,
-SLICE_TYPE_SP = 3,
-SLICE_TYPE_SI = 4,
+SEI_TIMING = 0x01,
+SEI_IDENTIFIER = 0x02,
 };
 
-// This structure contains all possibly-useful per-sequence syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH264MiscSequenceParams {
-unsigned int profile_idc;
-char constraint_set0_flag;
-char constraint_set1_flag;
-char constraint_set2_flag;
-char constraint_set3_flag;
-char constraint_set4_flag;
-char constraint_set5_flag;
-
-char separate_colour_plane_flag;
-char qpprime_y_zero_transform_bypass_flag;
-
-char gaps_in_frame_num_allowed_flag;
-char delta_pic_order_always_zero_flag;
-char bottom_field_pic_order_in_frame_present_flag;
-
-unsigned int num_slice_groups_minus1;
-unsigned int slice_group_map_type;
-
-int pic_init_qs_minus26;
-
-char overscan_info_present_flag;
-char overscan_appropriate_flag;
-
-char video_signal_type_present_flag;
-unsigned int video_format;
-char video_full_range_flag;
-char colour_description_present_flag;
-unsigned int colour_primaries;
-unsigned int transfer_characteristics;
-unsigned int matrix_coefficients;
-
-char chroma_loc_info_present_flag;
-unsigned int chroma_sample_loc_type_top_field;
-unsigned int chroma_sample_loc_type_bottom_field;
-
-// Some timing elements are in VAEncSequenceParameterBufferH264.
-char fixed_frame_rate_flag;
-
-char nal_hrd_parameters_present_flag;
-char vcl_hrd_parameters_present_flag;
-char low_delay_hrd_flag;
-char pic_struct_present_flag;
-
-char motion_vectors_over_pic_boundaries_flag;
-unsigned int max_bytes_per_pic_denom;
-unsigned int max_bits_per_mb_denom;
-unsigned int max_num_reorder_frames;
-unsigned int max_dec_pic_buffering;
-
-unsigned int cpb_cnt_minus1;
-unsigned int bit_rate_scale;
-unsigned int cpb_size_scale;
-unsigned int bit_rate_value_minus1[32];
-unsigned int cpb_size_value_minus1[32];
-char cbr_flag[32];
-unsigned int initial_cpb_removal_delay_length_minus1;
-unsigned int cpb_removal_delay_length_minus1;
-unsigned int dpb_output_delay_length_minus1;
-unsigned int time_offset_length;
-
-unsigned int initial_cpb_removal_delay;
-unsigned int initial_cpb_removal_delay_offset;
-
-unsigned int pic_struct;
-} VAAPIEncodeH264MiscSequenceParams;
-
-// This structure contains all possibly-useful per-slice syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH264MiscSliceParams {
-unsigned int nal_unit_type;
-unsigned int nal_ref_idc;
-
-unsigned int colour_plane_

[FFmpeg-devel] [PATCH 16/20] vaapi_h264: Fix CPB/DPB delays

2017-10-08 Thread Mark Thompson
This should be ticks, not time_scale steps - it was wrong for all
framerates not a multiple of 1/2.

(cherry picked from commit 30645174e333c7db1946ab09be769db9be9d7481)
---
 libavcodec/vaapi_encode_h264.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 8ca82df084..d87485d5f0 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -616,10 +616,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 if (opt->sei & SEI_TIMING) {
 memset(&priv->pic_timing, 0, sizeof(priv->pic_timing));
 
-priv->pic_timing.cpb_removal_delay =
-2 * sps->vui.num_units_in_tick * priv->cpb_delay;
-priv->pic_timing.dpb_output_delay =
-2 * sps->vui.num_units_in_tick * priv->dpb_delay;
+priv->pic_timing.cpb_removal_delay = 2 * priv->cpb_delay;
+priv->pic_timing.dpb_output_delay  = 2 * priv->dpb_delay;
 
 priv->sei_needed = 1;
 }
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 14/20] vaapi_h264: Add support for AUD NAL units

2017-10-08 Thread Mark Thompson
Adds a new private option to enable them (off by default).

(cherry picked from commit 820a4483af13cf6fd51f13638e57bcd1c3f629d4)
---
 libavcodec/vaapi_encode_h264.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index e8d04efbc5..5c043baabb 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -53,6 +53,7 @@ typedef struct VAAPIEncodeH264Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
+H264RawAUD aud;
 H264RawSPS sps;
 H264RawPPS pps;
 H264RawSEI sei;
@@ -77,6 +78,7 @@ typedef struct VAAPIEncodeH264Context {
 
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
+int aud_needed;
 int sei_needed;
 } VAAPIEncodeH264Context;
 
@@ -86,6 +88,7 @@ typedef struct VAAPIEncodeH264Options {
 int low_power;
 // Entropy encoder type.
 int coder;
+int aud;
 int sei;
 } VAAPIEncodeH264Options;
 
@@ -145,6 +148,13 @@ static int 
vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h264_add_nal(avctx, au, &priv->sps);
 if (err < 0)
 goto fail;
@@ -169,6 +179,13 @@ static int 
vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h264_add_nal(avctx, au, &priv->slice);
 if (err < 0)
 goto fail;
@@ -191,6 +208,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 int err, i;
 
 if (priv->sei_needed) {
+if (priv->aud_needed) {
+vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
+priv->aud_needed = 0;
+}
+
 memset(&priv->sei, 0, sizeof(priv->sei));
 priv->sei.nal_unit_header.nal_unit_type = H264_NAL_SEI;
 
@@ -573,6 +595,14 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
 priv->dpb_delay = pic->display_order - pic->encode_order + 1;
 
+if (opt->aud) {
+priv->aud_needed = 1;
+priv->aud.nal_unit_header.nal_unit_type = H264_NAL_AUD;
+priv->aud.primary_pic_type = priv->primary_pic_type;
+} else {
+priv->aud_needed = 0;
+}
+
 if (opt->sei & SEI_IDENTIFIER && pic->encode_order == 0)
 priv->sei_needed = 1;
 
@@ -935,6 +965,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "vlc",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
 { "ac",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
 
+{ "aud", "Include AUD",
+  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
   { .i64 = SEI_IDENTIFIER | SEI_TIMING },
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 15/20] vaapi_h264: Add support for SEI recovery points

2017-10-08 Thread Mark Thompson
Included by default with non-IDR intra frames.

(cherry picked from commit a49ee60d5fdbdae1706a44cfbb814abb9793815f)
---
 libavcodec/vaapi_encode_h264.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 5c043baabb..8ca82df084 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -37,6 +37,7 @@
 enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
+SEI_RECOVERY_POINT = 0x04,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -61,6 +62,7 @@ typedef struct VAAPIEncodeH264Context {
 
 H264RawSEIBufferingPeriod buffering_period;
 H264RawSEIPicTiming pic_timing;
+H264RawSEIRecoveryPoint recovery_point;
 H264RawSEIUserDataUnregistered identifier;
 char *identifier_string;
 
@@ -232,6 +234,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 priv->sei.payload[i].payload.pic_timing = priv->pic_timing;
 ++i;
 }
+if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
+priv->sei.payload[i].payload_type = H264_SEI_TYPE_RECOVERY_POINT;
+priv->sei.payload[i].payload.recovery_point = priv->recovery_point;
+++i;
+}
 
 priv->sei.payload_count = i;
 av_assert0(priv->sei.payload_count > 0);
@@ -617,6 +624,14 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed = 1;
 }
 
+if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
+priv->recovery_point.recovery_frame_cnt = 0;
+priv->recovery_point.exact_match_flag   = 1;
+priv->recovery_point.broken_link_flag   = ctx->b_per_p > 0;
+
+priv->sei_needed = 1;
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = priv->frame_num,
@@ -970,7 +985,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
-  { .i64 = SEI_IDENTIFIER | SEI_TIMING },
+  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
   0, INT_MAX, FLAGS, "sei" },
 { "identifier", "Include encoder version identifier",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -978,6 +993,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "timing", "Include timing parameters (buffering_period and pic_timing)",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
   INT_MIN, INT_MAX, FLAGS, "sei" },
+{ "recovery_point", "Include recovery points where appropriate",
+  0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
+  INT_MIN, INT_MAX, FLAGS, "sei" },
 { NULL },
 };
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 17/20] vaapi_h265: Convert to use coded bitstream infrastructure

2017-10-08 Thread Mark Thompson
Also improves the metadata and generally makes the configuration
a bit cleaner.

(cherry picked from commit ac12486714b48f9bd5d9167f90b77c936751d6ef)
---
 configure  |2 +-
 libavcodec/Makefile|2 +-
 libavcodec/vaapi_encode_h265.c | 1536 +++-
 libavcodec/vaapi_encode_h26x.c |   68 --
 libavcodec/vaapi_encode_h26x.h |   45 --
 5 files changed, 585 insertions(+), 1068 deletions(-)
 delete mode 100644 libavcodec/vaapi_encode_h26x.c
 delete mode 100644 libavcodec/vaapi_encode_h26x.h

diff --git a/configure b/configure
index e5565f10aa..2810741fc5 100755
--- a/configure
+++ b/configure
@@ -2837,7 +2837,7 @@ hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
 hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
-hevc_vaapi_encoder_select="vaapi_encode golomb"
+hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
 mjpeg_cuvid_decoder_deps="cuda cuvid"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7b6fcd7aa2..b52e5ada7a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -363,7 +363,7 @@ OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o   \
   hevc_data.o
 OBJS-$(CONFIG_HEVC_RKMPP_DECODER)  += rkmppdec.o
-OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o 
vaapi_encode_h26x.o
+OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o
 OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
 OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
 OBJS-$(CONFIG_HNM4_VIDEO_DECODER)  += hnm4video.o
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 971458db87..4edd53a73c 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -16,163 +16,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include 
 #include 
 
 #include "libavutil/avassert.h"
-#include "libavutil/internal.h"
+#include "libavutil/common.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
+#include "cbs.h"
+#include "cbs_h265.h"
 #include "hevc.h"
 #include "internal.h"
 #include "put_bits.h"
 #include "vaapi_encode.h"
-#include "vaapi_encode_h26x.h"
-
-
-#define MAX_ST_REF_PIC_SETS  32
-#define MAX_DPB_PICS 16
-#define MAX_LAYERS1
-
-
-typedef struct VAAPIEncodeH265STRPS {
-char inter_ref_pic_set_prediction_flag;
-
-unsigned int num_negative_pics;
-unsigned int num_positive_pics;
-
-unsigned int delta_poc_s0_minus1[MAX_DPB_PICS];
-char used_by_curr_pic_s0_flag[MAX_DPB_PICS];
-
-unsigned int delta_poc_s1_minus1[MAX_DPB_PICS];
-char used_by_curr_pic_s1_flag[MAX_DPB_PICS];
-} VAAPIEncodeH265STRPS;
-
-// This structure contains all possibly-useful per-sequence syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH265MiscSequenceParams {
-
-// Parameter set IDs.
-unsigned int video_parameter_set_id;
-unsigned int seq_parameter_set_id;
-
-// Layering.
-unsigned int vps_max_layers_minus1;
-unsigned int vps_max_sub_layers_minus1;
-char vps_temporal_id_nesting_flag;
-unsigned int vps_max_layer_id;
-unsigned int vps_num_layer_sets_minus1;
-unsigned int sps_max_sub_layers_minus1;
-char sps_temporal_id_nesting_flag;
-char layer_id_included_flag[MAX_LAYERS][64];
-
-// Profile/tier/level parameters.
-char general_profile_compatibility_flag[32];
-char general_progressive_source_flag;
-char general_interlaced_source_flag;
-char general_non_packed_constraint_flag;
-char general_frame_only_constraint_flag;
-char general_inbld_flag;
-
-// Decode/display ordering parameters.
-unsigned int log2_max_pic_order_cnt_lsb_minus4;
-char vps_sub_layer_ordering_info_present_flag;
-unsigned int vps_max_dec_pic_buffering_minus1[MAX_LAYERS];
-unsigned int vps_max_num_reorder_pics[MAX_LAYERS];
-unsigned int vps_max_latency_increase_plus1[MAX_LAYERS];
-char sps_sub_layer_ordering_info_present_flag;
-unsigned int sps_max_dec_pic_buffering_minus1[MAX_LAYERS];
-unsigned int sps_max_num_reorder_pics[MAX_LAYERS];
-unsigned int sps_max_latency_increase_plus1[MAX_LAYERS];
-
-// Timing information.
-char vps_timing_info_present_flag;
-unsigned int vps_num_units_in_tick;
-unsigned int vps_time_scale;
-char vps_poc_proportional_to_timing_flag;
-unsigned int vps_num_ticks_poc_diff_minus1;
-
-// Cropping information.
-char conformance_window_flag;
-unsigned int conf_win_left_offset;
-unsigned int conf_win_right_offset;
-unsigned int conf_win_top_offset;
-unsigned 

[FFmpeg-devel] [PATCH 18/20] vaapi_h265: Add support for AUD NAL units

2017-10-08 Thread Mark Thompson
Matching the H.264 encoder.

(cherry picked from commit e3e8eab359238486dc233f7aa89b7bb3cb19ec38)
---
 libavcodec/vaapi_encode_h265.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 4edd53a73c..3ae92a7a09 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -42,6 +42,7 @@ typedef struct VAAPIEncodeH265Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
+H265RawAUD aud;
 H265RawVPS vps;
 H265RawSPS sps;
 H265RawPPS pps;
@@ -52,13 +53,16 @@ typedef struct VAAPIEncodeH265Context {
 
 int slice_nal_unit;
 int slice_type;
+int pic_type;
 
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
+int aud_needed;
 } VAAPIEncodeH265Context;
 
 typedef struct VAAPIEncodeH265Options {
 int qp;
+int aud;
 } VAAPIEncodeH265Options;
 
 
@@ -117,6 +121,13 @@ static int 
vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h265_add_nal(avctx, au, &priv->vps);
 if (err < 0)
 goto fail;
@@ -145,6 +156,13 @@ static int 
vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h265_add_nal(avctx, au, &priv->slice);
 if (err < 0)
 goto fail;
@@ -519,6 +537,7 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 {
 VAAPIEncodeContext   *ctx = avctx->priv_data;
 VAAPIEncodeH265Context  *priv = ctx->priv_data;
+VAAPIEncodeH265Options   *opt = ctx->codec_options;
 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
 int i;
 
@@ -529,16 +548,19 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 
 priv->slice_nal_unit = HEVC_NAL_IDR_W_RADL;
 priv->slice_type = HEVC_SLICE_I;
+priv->pic_type   = 0;
 } else {
 av_assert0(pic->encode_order > priv->last_idr_frame);
 
 if (pic->type == PICTURE_TYPE_I) {
 priv->slice_nal_unit = HEVC_NAL_CRA_NUT;
 priv->slice_type = HEVC_SLICE_I;
+priv->pic_type   = 0;
 } else if (pic->type == PICTURE_TYPE_P) {
 av_assert0(pic->refs[0]);
 priv->slice_nal_unit = HEVC_NAL_TRAIL_R;
 priv->slice_type = HEVC_SLICE_P;
+priv->pic_type   = 1;
 } else {
 av_assert0(pic->refs[0] && pic->refs[1]);
 if (pic->refs[1]->type == PICTURE_TYPE_I)
@@ -546,10 +568,23 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 else
 priv->slice_nal_unit = HEVC_NAL_TRAIL_N;
 priv->slice_type = HEVC_SLICE_B;
+priv->pic_type   = 2;
 }
 }
 priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
 
+if (opt->aud) {
+priv->aud_needed = 1;
+priv->aud.nal_unit_header = (H265RawNALUnitHeader) {
+.nal_unit_type = HEVC_NAL_AUD,
+.nuh_layer_id  = 0,
+.nuh_temporal_id_plus1 = 1,
+};
+priv->aud.pic_type = priv->pic_type;
+} else {
+priv->aud_needed = 0;
+}
+
 vpic->decoded_curr_pic = (VAPictureHEVC) {
 .picture_id= pic->recon_surface,
 .pic_order_cnt = priv->pic_order_cnt,
@@ -907,6 +942,10 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext 
*avctx)
 static const AVOption vaapi_encode_h265_options[] = {
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
+
+{ "aud", "Include AUD",
+  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+
 { NULL },
 };
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 19/20] vaapi_mpeg2: Convert to use coded bitstream infrastructure

2017-10-08 Thread Mark Thompson
(cherry picked from commit 10eb496d9ae94df6f792b0e1d8750738eb3a0952)
---
 configure   |   2 +-
 libavcodec/vaapi_encode_mpeg2.c | 638 ++--
 2 files changed, 424 insertions(+), 216 deletions(-)

diff --git a/configure b/configure
index 2810741fc5..e84bbba2a1 100755
--- a/configure
+++ b/configure
@@ -2856,7 +2856,7 @@ mpeg2_qsv_decoder_select="qsvdec mpeg2_qsv_hwaccel"
 mpeg2_qsv_encoder_deps="libmfx"
 mpeg2_qsv_encoder_select="qsvenc"
 mpeg2_vaapi_encoder_deps="VAEncPictureParameterBufferMPEG2"
-mpeg2_vaapi_encoder_select="vaapi_encode"
+mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
 mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m"
 mpeg4_crystalhd_decoder_select="crystalhd"
 mpeg4_cuvid_decoder_deps="cuda cuvid"
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index dc918884e8..02eca30dc5 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -20,15 +20,11 @@
 #include 
 
 #include "libavutil/avassert.h"
-#include "libavutil/common.h"
-#include "libavutil/internal.h"
-#include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
-#include "internal.h"
-#include "mpegvideo.h"
-#include "put_bits.h"
+#include "cbs.h"
+#include "cbs_mpeg2.h"
+#include "mpeg12.h"
 #include "vaapi_encode.h"
 
 typedef struct VAAPIEncodeMPEG2Context {
@@ -39,79 +35,104 @@ typedef struct VAAPIEncodeMPEG2Context {
 int quant_p;
 int quant_b;
 
+MPEG2RawSequenceHeader sequence_header;
+MPEG2RawExtensionData  sequence_extension;
+MPEG2RawExtensionData  sequence_display_extension;
+MPEG2RawGroupOfPicturesHeader gop_header;
+MPEG2RawPictureHeader  picture_header;
+MPEG2RawExtensionData  picture_coding_extension;
+
 int64_t last_i_frame;
 
 unsigned int bit_rate;
 unsigned int vbv_buffer_size;
+
+AVRational frame_rate;
+
+unsigned int f_code_horizontal;
+unsigned int f_code_vertical;
+
+CodedBitstreamContext *cbc;
+CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMPEG2Context;
 
 
-#define vseq_var(name)  vseq->name, name
-#define vseqext_field(name) vseq->sequence_extension.bits.name, name
-#define vgop_field(name)vseq->gop_header.bits.name, name
-#define vpic_var(name)  vpic->name, name
-#define vpcext_field(name)  vpic->picture_coding_extension.bits.name, name
-#define vcomp_field(name)   vpic->composite_display.bits.name, name
+static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx,
+ char *data, size_t *data_len,
+ CodedBitstreamFragment *frag)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+int err;
+
+err = ff_cbs_write_fragment_data(priv->cbc, frag);
+if (err < 0) {
+av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
+return err;
+}
+
+if (*data_len < 8 * frag->data_size - frag->data_bit_padding) {
+av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
+   "%zu < %zu.\n", *data_len,
+   8 * frag->data_size - frag->data_bit_padding);
+return AVERROR(ENOSPC);
+}
+
+memcpy(data, frag->data, frag->data_size);
+*data_len = 8 * frag->data_size - frag->data_bit_padding;
+
+return 0;
+}
+
+static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx,
+ CodedBitstreamFragment *frag,
+ int type, void *header)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+int err;
+
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header);
+if (err < 0) {
+av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
+   "type = %d.\n", type);
+return err;
+}
 
-#define u2(width, value, name) put_bits(&pbc, width, value)
-#define u(width, ...) u2(width, __VA_ARGS__)
+return 0;
+}
 
 static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
 char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAEncSequenceParameterBufferMPEG2 *vseq = ctx->codec_sequence_params;
-VAAPIEncodeMPEG2Context   *priv = ctx->priv_data;
-PutBitContext pbc;
-
-init_put_bits(&pbc, data, 8 * *data_len);
-
-u(32, SEQ_START_CODE, sequence_header_code);
-
-u(12, vseq->picture_width,  horizontal_size_value);
-u(12, vseq->picture_height, vertical_size_value);
-u(4, vseq_var(aspect_ratio_information));
-u(4, 8, frame_rate_code);
-u(18, priv->bit_rate & 0x3fff, bit_rate_value);
-u(1, 1, marker_bit);
-u(10, priv->vbv_buffer_size & 0x3ff, vbv_buffer_size_value);
-u(1, 0, constrained_parameters_flag);
-u(1, 0, load_intra_quantiser_

[FFmpeg-devel] [PATCH 20/20] cbs: Add some read/write tests

2017-10-08 Thread Mark Thompson
Use the appropriate metadata filter for each codec - in the absence of any
options to modify the stream, the output bitstream should be identical to
the input (though the output file may differ in padding).

All tests use conformance bitstreams, the MPEG-2 streams are newly added
from the conformance test streams

---
 tests/Makefile|  1 +
 tests/fate/cbs.mak| 74 +++
 tests/ref/fate/cbs-h264-AUD_MW_E  |  1 +
 tests/ref/fate/cbs-h264-BASQP1_Sony_C |  1 +
 tests/ref/fate/cbs-h264-CABACI3_Sony_B|  1 +
 tests/ref/fate/cbs-h264-CVBS3_Sony_C  |  1 +
 tests/ref/fate/cbs-h264-CVFC1_Sony_C  |  1 +
 tests/ref/fate/cbs-h264-CVMANL1_TOSHIBA_B |  1 +
 tests/ref/fate/cbs-h264-CVNLFI1_Sony_C|  1 +
 tests/ref/fate/cbs-h264-CVSE2_Sony_B  |  1 +
 tests/ref/fate/cbs-h264-CVWP1_TOSHIBA_E   |  1 +
 tests/ref/fate/cbs-h264-FM1_BT_B  |  1 +
 tests/ref/fate/cbs-h264-MR1_BT_A  |  1 +
 tests/ref/fate/cbs-h264-SVA_Base_B|  1 +
 tests/ref/fate/cbs-h264-Sharp_MP_PAFF_1r2 |  1 +
 tests/ref/fate/cbs-h264-sp1_bt_a  |  1 +
 tests/ref/fate/cbs-hevc-CAINIT_E_SHARP_3  |  1 +
 tests/ref/fate/cbs-hevc-CAINIT_H_SHARP_3  |  1 +
 tests/ref/fate/cbs-hevc-CONFWIN_A_Sony_1  |  1 +
 tests/ref/fate/cbs-hevc-HRD_A_Fujitsu_2   |  1 +
 tests/ref/fate/cbs-hevc-LTRPSPS_A_Qualcomm_1  |  1 +
 tests/ref/fate/cbs-hevc-NUT_A_ericsson_5  |  1 +
 tests/ref/fate/cbs-hevc-PICSIZE_A_Bossen_1|  1 +
 tests/ref/fate/cbs-hevc-PICSIZE_B_Bossen_1|  1 +
 tests/ref/fate/cbs-hevc-RPLM_A_qualcomm_4 |  1 +
 tests/ref/fate/cbs-hevc-RPS_A_docomo_4|  1 +
 tests/ref/fate/cbs-hevc-RPS_E_qualcomm_5  |  1 +
 tests/ref/fate/cbs-hevc-SLIST_A_Sony_4|  1 +
 tests/ref/fate/cbs-hevc-SLIST_D_Sony_9|  1 +
 tests/ref/fate/cbs-hevc-STRUCT_A_Samsung_5|  1 +
 tests/ref/fate/cbs-hevc-TILES_B_Cisco_1   |  1 +
 tests/ref/fate/cbs-hevc-WPP_A_ericsson_MAIN_2 |  1 +
 tests/ref/fate/cbs-hevc-WPP_F_ericsson_MAIN_2 |  1 +
 tests/ref/fate/cbs-hevc-WP_A_Toshiba_3|  1 +
 tests/ref/fate/cbs-hevc-ipcm_E_NEC_2  |  1 +
 tests/ref/fate/cbs-mpeg2-hhi_burst_422_short  |  1 +
 tests/ref/fate/cbs-mpeg2-sony-ct3 |  1 +
 tests/ref/fate/cbs-mpeg2-tcela-6  |  1 +
 38 files changed, 111 insertions(+)
 create mode 100644 tests/fate/cbs.mak
 create mode 100644 tests/ref/fate/cbs-h264-AUD_MW_E
 create mode 100644 tests/ref/fate/cbs-h264-BASQP1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CABACI3_Sony_B
 create mode 100644 tests/ref/fate/cbs-h264-CVBS3_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVFC1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVMANL1_TOSHIBA_B
 create mode 100644 tests/ref/fate/cbs-h264-CVNLFI1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVSE2_Sony_B
 create mode 100644 tests/ref/fate/cbs-h264-CVWP1_TOSHIBA_E
 create mode 100644 tests/ref/fate/cbs-h264-FM1_BT_B
 create mode 100644 tests/ref/fate/cbs-h264-MR1_BT_A
 create mode 100644 tests/ref/fate/cbs-h264-SVA_Base_B
 create mode 100644 tests/ref/fate/cbs-h264-Sharp_MP_PAFF_1r2
 create mode 100644 tests/ref/fate/cbs-h264-sp1_bt_a
 create mode 100644 tests/ref/fate/cbs-hevc-CAINIT_E_SHARP_3
 create mode 100644 tests/ref/fate/cbs-hevc-CAINIT_H_SHARP_3
 create mode 100644 tests/ref/fate/cbs-hevc-CONFWIN_A_Sony_1
 create mode 100644 tests/ref/fate/cbs-hevc-HRD_A_Fujitsu_2
 create mode 100644 tests/ref/fate/cbs-hevc-LTRPSPS_A_Qualcomm_1
 create mode 100644 tests/ref/fate/cbs-hevc-NUT_A_ericsson_5
 create mode 100644 tests/ref/fate/cbs-hevc-PICSIZE_A_Bossen_1
 create mode 100644 tests/ref/fate/cbs-hevc-PICSIZE_B_Bossen_1
 create mode 100644 tests/ref/fate/cbs-hevc-RPLM_A_qualcomm_4
 create mode 100644 tests/ref/fate/cbs-hevc-RPS_A_docomo_4
 create mode 100644 tests/ref/fate/cbs-hevc-RPS_E_qualcomm_5
 create mode 100644 tests/ref/fate/cbs-hevc-SLIST_A_Sony_4
 create mode 100644 tests/ref/fate/cbs-hevc-SLIST_D_Sony_9
 create mode 100644 tests/ref/fate/cbs-hevc-STRUCT_A_Samsung_5
 create mode 100644 tests/ref/fate/cbs-hevc-TILES_B_Cisco_1
 create mode 100644 tests/ref/fate/cbs-hevc-WPP_A_ericsson_MAIN_2
 create mode 100644 tests/ref/fate/cbs-hevc-WPP_F_ericsson_MAIN_2
 create mode 100644 tests/ref/fate/cbs-hevc-WP_A_Toshiba_3
 create mode 100644 tests/ref/fate/cbs-hevc-ipcm_E_NEC_2
 create mode 100644 tests/ref/fate/cbs-mpeg2-hhi_burst_422_short
 create mode 100644 tests/ref/fate/cbs-mpeg2-sony-ct3
 create mode 100644 tests/ref/fate/cbs-mpeg2-tcela-6

diff --git a/tests/Makefile b/tests/Makefile
index 278be24ccb..0cb9568617 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -114,6 +114,7 @@ include $(SRC_PATH)/tests/fate/atrac.mak
 include $(SRC_PATH)/tests/fate/audio.mak
 include $(SRC_PATH)/tests/fate/bmp.mak
 include $(SRC_P

[FFmpeg-devel] [PATCH] build: prevent SDL2 from polluting global cflags and extralibs

2017-10-08 Thread James Almer
Remove the SDL_main define from the global cflags but not from the
ffplay cflags, and the -mwindows linker option from extralibs instead
of overriding it with the addition of -mconsole.

Signed-off-by: James Almer 
---
 configure   | 4 ++--
 ffbuild/library.mak | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 77c9a18c3c..0fdf4bcbe3 100755
--- a/configure
+++ b/configure
@@ -6107,10 +6107,10 @@ if enabled sdl2; then
 enable sdl2
 fi
 if test $target_os = "mingw32"; then
-sdl2_extralibs="$sdl2_extralibs -mconsole"
+sdl2_extralibs=$(filter_out '-mwindows' $sdl2_extralibs)
 fi
 fi
-enabled sdl2 && add_cflags $sdl2_cflags && add_extralibs $sdl2_extralibs
+enabled sdl2 && add_cflags $(filter_out '-Dmain=SDL_main' $sdl2_cflags) && 
add_extralibs $sdl2_extralibs
 
 if enabled decklink; then
 case $target_os in
diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index ee19c3c797..4191edcf9c 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -16,7 +16,6 @@ all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) 
$(SUBDIR)lib$(FULLNAME).pc
 
 LIBOBJS := $(OBJS) $(SUBDIR)%.h.o $(TESTOBJS)
 $(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i):   CPPFLAGS += -DHAVE_AV_CONFIG_H
-$(TESTOBJS) $(TESTOBJS:.o=.i): CFLAGS += -Umain
 
 $(SUBDIR)$(LIBNAME): $(OBJS)
$(RM) $@
-- 
2.14.2

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


[FFmpeg-devel] [PATCH 08/20] lavc: Add h264_metadata bitstream filter

2017-10-08 Thread Mark Thompson
This is able to modify some header metadata found in the SPS/VUI,
and can also add/remove AUDs and insert user data in SEI NAL units.

(cherry picked from commit 9e93001b6135a23fe4e200196c08fb4fbffed6fc)
(cherry picked from commit c42b62d1f9641f10ffc23cad9abbe47d8a4a165b)
---
Updated to always add the user data SEI to the first access unit seen, even if 
it doesn't contain any parameter sets.

This allows it to be used to fix samples like that in 
, with:

./ffmpeg_g -y -i in.mkv -c copy -bsf:v 
'h264_metadata=sei_user_data=dc45e9bde6d948b7962cd820d923eeef+x264 - core 150' 
out.mkv


 configure  |   1 +
 doc/bitstream_filters.texi |  63 +
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/h264_metadata_bsf.c | 524 +
 5 files changed, 590 insertions(+)
 create mode 100644 libavcodec/h264_metadata_bsf.c

diff --git a/configure b/configure
index 70402c03d0..93a3e44230 100755
--- a/configure
+++ b/configure
@@ -2905,6 +2905,7 @@ mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
 vc1_parser_select="vc1dsp"
 
 # bitstream_filters
+h264_metadata_bsf_select="cbs_h264"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 990b4f3c58..f7dfa1f753 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -92,6 +92,69 @@ When this option is enabled, the long-term headers are 
removed from the
 bitstream after extraction.
 @end table
 
+@section h264_metadata
+
+Modify metadata embedded in an H.264 stream.
+
+@table @option
+@item aud
+Insert or remove AUD NAL units in all access units of the stream.
+
+@table @samp
+@item insert
+@item remove
+@end table
+
+@item sample_aspect_ratio
+Set the sample aspect ratio of the stream in the VUI parameters.
+
+@item video_format
+@item video_full_range_flag
+Set the video format in the stream (see H.264 section E.2.1 and
+table E-2).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.264 section E.2.1
+and tables E-3, E-4 and E-5).
+
+@item chroma_sample_loc_type
+Set the chroma sample location in the stream (see H.264 section
+E.2.1 and figure E-1).
+
+@item tick_rate
+Set the tick rate (num_units_in_tick / time_scale) in the VUI
+parameters.  This is the smallest time unit representable in the
+stream, and in many cases represents the field rate of the stream
+(double the frame rate).
+@item fixed_frame_rate_flag
+Set whether the stream has fixed framerate - typically this indicates
+that the framerate is exactly half the tick rate, but the exact
+meaning is dependent on interlacing and the picture structure (see
+H.264 section E.2.1 and table E-6).
+
+@item crop_left
+@item crop_right
+@item crop_top
+@item crop_bottom
+Set the frame cropping offsets in the SPS.  These values will replace
+the current ones if the stream is already cropped.
+
+These fields are set in pixels.  Note that some sizes may not be
+representable if the chroma is subsampled or the stream is interlaced
+(see H.264 section 7.4.2.1.1).
+
+@item sei_user_data
+Insert a string as SEI unregistered user data.  The argument must
+be of the form @emph{UUID+string}, where the UUID is as hex digits
+possibly separated by hyphens, and the string can be anything.
+
+For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
+insert the string ``hello'' associated with the given UUID.
+
+@end table
+
 @section h264_mp4toannexb
 
 Convert an H.264 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5e09889bc6..25ad785dbe 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1015,6 +1015,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
+OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index dd0247182b..0e133b9036 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
+extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bs

Re: [FFmpeg-devel] [PATCH] ffmpeg: always use single threaded decoding for attached pictures

2017-10-08 Thread Marton Balint


On Fri, 6 Oct 2017, Hendrik Leppkes wrote:


On Fri, Oct 6, 2017 at 10:14 PM, Marton Balint  wrote:

Since af1761f7b5b1b72197dc40934953b775c2d951cc ffmpeg waits for a frame in each
stream before writing the output header. If we are using threaded decoding for
attached pictures, we have to read till EOF to be able to finally flush the
decoder and output the decoded frame. This essentially makes ffmpeg buffer all
non-attached picture packets, which will cause a "Too many packets buffered for
output stream" eventually.

By forcing single threaded decoding, we get a frame from a single packet as
well and we can avoid the error.

Fixes part of ticket #6375:
ffmpeg -i 46564100.mp3 -acodec libmp3lame -ab 128k -ac 2 out.mp3

Signed-off-by: Marton Balint 
---
 fftools/ffmpeg.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5be8788ea8..6eb7bf9d84 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2909,6 +2909,9 @@ static int init_input_stream(int ist_index, char *error, 
int error_len)

 if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
 av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
+/* Attached pics are sparse, therefore we would not want to delay 
their decoding till EOF. */
+if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+av_dict_set(&ist->decoder_opts, "threads", "1", 0);



LGTM.


Thanks, applied.

Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavd/decklink_dec: Do not claim to output transparency information

2017-10-08 Thread Carl Eugen Hoyos
2017-09-28 23:20 GMT+02:00 Carl Eugen Hoyos :

> I don't have decklink hardware but I assume it never outputs actual
> transparency.

I have applied this patch.

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/utvideo: Use "&" instead of "&&" in expressions with "~"

2017-10-08 Thread Carl Eugen Hoyos
2017-10-08 1:58 GMT+02:00 Ronald S. Bultje :
> Hi,
>
> On Sat, Oct 7, 2017 at 7:05 PM, Carl Eugen Hoyos  wrote:
>
>> Hi!
>>
>> Attached patch silences two warnings when compiling with gcc-7:
>> libavcodec/utvideodec.c:242:107: warning: ‘~’ on a boolean expression
>> [-Wbool-operation]
>>  const int cmask = c->interlaced ? ~(1 + 2 * (!plane_no &&
>> c->avctx->pix_fmt == AV_PIX_FMT_YUV420P)) : ~(!plane_no &&
>> c->avctx->pix_fmt == AV_PIX_FMT_YUV420P);

> I personally think the warning is dumb...

I am less convinced but disabled the warning.

Thank you both, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Bump major versions of all libraries

2017-10-08 Thread Ivan Kalvachev
On 9/10/17, James Almer  wrote:
> On 9/10/2017 2:55 PM, Ivan Kalvachev wrote:
>> On 9/2/17, James Almer  wrote:
>> [...]
>>> Notes:
>>> I have no way to test what effect the removal of XVMC truly has.
>>> The decoders are removed but unlike libav we have hwaccels that are not
>>> removed by this. Similarly, the pixfmt is also not removed in our case.
>>> Commit dcc39ee10e82833ce24aa57926c00ffeb1948198 does a thorough removal
>>> of the remnants of this functionality, but given the above i don't know
>>> if that applies to us the same way.
>>> I assume the hwaccels are meant to stay and work after this, so someone
>>> that knows this code and functionality and has a system where it can be
>>> tested should ideally look at this.
>>
>> I assume that the above commit is from libav?
>> If so yes, it is the wrong thing to do.
>>
>> The code has been reworked so player
>> uses pix_fmt to select acceleration,
>> thus no special decoders are needed.
>> It's like other hwaccel formats.
>>
>> If you want I can send a patch that removes the disabled
>> XvMC functionality and leaves the enabled one.
>> If you do it instead, be careful, there are both #ifdef and #ifdef !not's,
>> afair.
>
> I'd very much prefer if you can do it. Adapt the codebase in a way that
> simply flipping the FF_API_XVMC define from 1 to 0 disables the
> deprecated code (and potentially enables new code in necessary, like the
> stuff in pixfmt.h).
> I have no way to test this functionality so anything i could do would be
> just a wild guess.

I just built it with FF_API_XVMC 0 and it works just as well as before.

The hwaccel changes were done after libav deprecation merges,
so it has always been OK.

There is however unrelated bug that affects both new and old api.
It seems related to idct permutations. I'll try to find a fix asap.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [RFC]lavu/opt: Use && instead of * in boolean expression

2017-10-08 Thread Carl Eugen Hoyos
2017-10-08 1:55 GMT+02:00 Ronald S. Bultje :
> Hi,
>
> On Sat, Oct 7, 2017 at 7:14 PM, Carl Eugen Hoyos  wrote:
>
>> 2017-05-05 1:32 GMT+02:00 Carl Eugen Hoyos :
>> > Hi!
>> >
>> > It may be better to disable the warning.
>>
>> Ping, one of the two patches should be applied,
>> we currently have one vote for each.
>>
>
> I'd go for && since it's boolean. No strong opinion though.

Patch applied.

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH]lavf/adp: Fix probe function on systems with signed char

2017-10-08 Thread Carl Eugen Hoyos
Hi!

Attached patch fixes the adp probe function, it currently fires for
repeated values.

I will probably apply soon, Carl Eugen
From 33d39f5199bacbbbafdb9885c72c3c6898dded81 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sun, 8 Oct 2017 23:41:14 +0200
Subject: [PATCH] lavf/adp: Fix the probe function on systems with signed
 char.

---
 libavformat/adp.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/adp.c b/libavformat/adp.c
index 7355503..3914857 100644
--- a/libavformat/adp.c
+++ b/libavformat/adp.c
@@ -27,7 +27,7 @@
 static int adp_probe(AVProbeData *p)
 {
 int i, changes = 0;
-char last = 0;
+uint8_t last = 0;
 
 if (p->buf_size < 32)
 return 0;
-- 
1.7.10.4

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] configure: disable libxcb dependent features if libxcb is not enabled

2017-10-08 Thread James Almer
On 10/4/2017 12:29 PM, James Almer wrote:
> On 9/28/2017 7:56 PM, James Almer wrote:
>> Signed-off-by: James Almer 
>> ---
>>  configure | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/configure b/configure
>> index c2f5fc2c98..ebcf48de20 100755
>> --- a/configure
>> +++ b/configure
>> @@ -6215,6 +6215,8 @@ if enabled libxcb; then
>>  
>>  add_cflags $xcb_cflags $xcb_shm_cflags $xcb_xfixes_cflags 
>> $xcb_shape_cflags
>>  add_extralibs $xcb_extralibs $xcb_shm_extralibs $xcb_xfixes_extralibs 
>> $xcb_shape_extralibs
>> +else
>> +disable libxcb_shm libxcb_shape libxcb_xfixes
>>  fi
>>  
>>  check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
> 
> Ping for set.

Pushed patch 1/2.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavf/amr: Add amrnb and amrwb demuxers

2017-10-08 Thread Carl Eugen Hoyos
2017-10-07 16:51 GMT+02:00 Carl Eugen Hoyos :
> 2017-10-01 18:23 GMT+02:00 Carl Eugen Hoyos :
>> 2017-09-27 18:08 GMT+02:00 Carl Eugen Hoyos :
>>
>>> The existing amr demuxer does not allow reading streams,
>>> it requires the 3GPP-conforming file header.
>>> Attached patch allows reading amrnb and amrwb from (live)
>>> streams, fixes ticket #6678.
>>
>> New patch with auto-detection attached, passes probecheck.
>
> Simplified patch attached that does not duplicate two small arrays
> in the object file that are already duplicated in the source code.
> The uninitialized variable is also fixed.

The last version triggered for repeated bytes (like adp),
new version attached.

Please comment, Carl Eugen
From f3697957b54bef4a7718144df07877394bd5d941 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Mon, 9 Oct 2017 00:21:23 +0200
Subject: [PATCH] lavf/amr: Add amrnb and amrwb demuxers.

Fixes ticket #6678.
---
 Changelog|1 +
 libavformat/Makefile |2 +
 libavformat/allformats.c |2 +
 libavformat/amr.c|  134 ++
 libavformat/version.h|4 +-
 5 files changed, 131 insertions(+), 12 deletions(-)

diff --git a/Changelog b/Changelog
index d6ec4ad..94e33a2 100644
--- a/Changelog
+++ b/Changelog
@@ -53,6 +53,7 @@ version :
 - Rockchip MPP hardware decoding
 - vmafmotion video filter
 - use MIME type "G726" for little-endian G.726, "AAL2-G726" for big-endian G.726
+- auto-detect amr-nb and amr-wb streams
 
 
 version 3.3:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index df709c29..c4c8713 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -87,6 +87,8 @@ OBJS-$(CONFIG_AIFF_MUXER)+= aiffenc.o id3v2enc.o
 OBJS-$(CONFIG_AIX_DEMUXER)   += aixdec.o
 OBJS-$(CONFIG_AMR_DEMUXER)   += amr.o
 OBJS-$(CONFIG_AMR_MUXER) += amr.o
+OBJS-$(CONFIG_AMRNB_DEMUXER) += amr.o
+OBJS-$(CONFIG_AMRWB_DEMUXER) += amr.o
 OBJS-$(CONFIG_ANM_DEMUXER)   += anm.o
 OBJS-$(CONFIG_APC_DEMUXER)   += apc.o
 OBJS-$(CONFIG_APE_DEMUXER)   += ape.o apetag.o img2.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 405ddb5..dc8984e 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -63,6 +63,8 @@ static void register_all(void)
 REGISTER_MUXDEMUX(AIFF, aiff);
 REGISTER_DEMUXER (AIX,  aix);
 REGISTER_MUXDEMUX(AMR,  amr);
+REGISTER_DEMUXER (AMRNB,amrnb);
+REGISTER_DEMUXER (AMRWB,amrwb);
 REGISTER_DEMUXER (ANM,  anm);
 REGISTER_DEMUXER (APC,  apc);
 REGISTER_DEMUXER (APE,  ape);
diff --git a/libavformat/amr.c b/libavformat/amr.c
index b5194a2..0043faf 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -38,6 +38,14 @@ typedef struct {
 static const char AMR_header[]   = "#!AMR\n";
 static const char AMRWB_header[] = "#!AMR-WB\n";
 
+static const uint8_t amrnb_packed_size[16] = {
+13, 14, 16, 18, 20, 21, 27, 32, 6, 1, 1, 1, 1, 1, 1, 1
+};
+static const uint8_t amrwb_packed_size[16] = {
+18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 1, 1, 1, 1, 1, 1
+};
+
+
 #if CONFIG_AMR_MUXER
 static int amr_write_header(AVFormatContext *s)
 {
@@ -126,17 +134,9 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt)
 mode = (toc >> 3) & 0x0F;
 
 if (par->codec_id == AV_CODEC_ID_AMR_NB) {
-static const uint8_t packed_size[16] = {
-12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0
-};
-
-size = packed_size[mode] + 1;
+size = amrnb_packed_size[mode];
 } else if (par->codec_id == AV_CODEC_ID_AMR_WB) {
-static const uint8_t packed_size[16] = {
-18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1
-};
-
-size = packed_size[mode];
+size = amrwb_packed_size[mode];
 }
 
 if (!size || av_new_packet(pkt, size))
@@ -176,6 +176,120 @@ AVInputFormat ff_amr_demuxer = {
 };
 #endif
 
+#if CONFIG_AMRNB_DEMUXER
+static int amrnb_probe(AVProbeData *p)
+{
+int mode, i = 0, valid = 0;
+const uint8_t *b = p->buf;
+
+while (i < p->buf_size) {
+mode = b[i] >> 3 & 0x0F;
+if (mode < 9 && (b[i] & 0x4) == 0x4) {
+uint8_t last = mode;
+int size = amrnb_packed_size[mode];
+while (size--) {
+if (b[++i] != last)
+break;
+last = b[i];
+}
+if (size > 0) {
+valid++;
+i += size;
+}
+} else {
+valid = 0;
+i++;
+}
+}
+if (valid > 100)
+return AVPROBE_SCORE_EXTENSION / 2 + 1;
+return 0;
+}
+
+static int amrnb_read_header(AVFormatContext *s)
+{
+AVStream *st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar

[FFmpeg-devel] [PATCH] Fix visual glitch with XvMC, caused by wrong idct permutation.

2017-10-08 Thread Ivan Kalvachev
In the past XvMC forced simple_idct since
it was using FF_IDCT_PERM_NONE.
However now we have SIMD variants of simple_idct that
are using FF_IDCT_PERM_TRANSPOSE and if they are selected
XvMC would get coefficients in the wrong order.

The patch creates new FF_IDCT_NONE that
is used only for this kind of hardware decoding
and that fallbacks to the old C only simple idct.

BTW,
If you have idea for a better name, tell me, I might change it.
I thought of FF_IDCT_HWACCEL_PASSTHROUGHT but it is too huge and ugly.
For some reason mpeg12 vdpau also uses the same idct, so using XVMC in
the name doesn't seem right. (I'm not sure why vdpau needs it...)

I also was thinking of using "-1" number for the define, but ...
I didn't want to risk with it.

Best Regards
   Ivan Kalvachev.
From 88a5f15f8ea04a5fb4eb135e1e773f92bb56a6e0 Mon Sep 17 00:00:00 2001
From: Ivan Kalvachev 
Date: Mon, 9 Oct 2017 01:25:00 +0300
Subject: [PATCH] Fix visual glitch with XvMC, caused by wrong idct
 permutation.

In the past XvMC forced simple_idct since
it was using FF_IDCT_PERM_NONE.
However now we have SIMD variants of simple_idct that
are using FF_IDCT_PERM_TRANSPOSE and if they are selected
XvMC would get coefficients in the wrong order.

The patch creates new FF_IDCT_NONE that
is used only for this kind of hardware decoding
and that fallbacks to the old C only simple idct.

Signed-off-by: Ivan Kalvachev 
---
 libavcodec/avcodec.h   | 1 +
 libavcodec/idctdsp.c   | 1 +
 libavcodec/mpeg12dec.c | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 52cc5b0ca..ca0cac501 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3147,6 +3147,7 @@ typedef struct AVCodecContext {
 #define FF_IDCT_SIMPLEALPHA   23
 #endif
 #define FF_IDCT_SIMPLEAUTO128
+#define FF_IDCT_NONE  129 /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */
 
 /**
  * bits per sample/pixel from the demuxer (needed for huffyuv).
diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index d596aed1a..45b29d6b7 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -279,6 +279,7 @@ av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
 c->perm_type = FF_IDCT_PERM_NONE;
 #endif /* CONFIG_FAANIDCT */
 } else { // accurate/default
+/* Be sure FF_IDCT_NONE will select this one, since it uses FF_IDCT_PERM_NONE */
 c->idct_put  = ff_simple_idct_put_8;
 c->idct_add  = ff_simple_idct_add_8;
 c->idct  = ff_simple_idct_8;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 22c29c150..4e68be27f 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1217,7 +1217,7 @@ static void setup_hwaccel_for_pixfmt(AVCodecContext *avctx)
 #endif
 )
 if (avctx->idct_algo == FF_IDCT_AUTO)
-avctx->idct_algo = FF_IDCT_SIMPLE;
+avctx->idct_algo = FF_IDCT_NONE;
 
 if (avctx->hwaccel && avctx->pix_fmt == AV_PIX_FMT_XVMC) {
 Mpeg1Context *s1 = avctx->priv_data;
-- 
2.14.1

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] configure: Disable -Wbool-operation.

2017-10-08 Thread Mark Thompson
On 08/10/17 22:08, Carl Eugen Hoyos wrote:
> ffmpeg | branch: master | Carl Eugen Hoyos  | Sun Oct  8 
> 23:08:09 2017 +0200| [c2d155e11ee5ec732d471982f2dee43703bcd5a7] | committer: 
> Carl Eugen Hoyos
> 
> configure: Disable -Wbool-operation.
> 
> Requested-by: Ronald and Derek
> 
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c2d155e11ee5ec732d471982f2dee43703bcd5a7
> ---
> 
>  configure | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configure b/configure
> index 77c9a18c3c..d5e96e95e1 100755
> --- a/configure
> +++ b/configure
> @@ -6291,6 +6291,7 @@ check_cflags -Wmissing-prototypes
>  check_cflags -Wno-pointer-to-int-cast
>  check_cflags -Wstrict-prototypes
>  check_cflags -Wempty-body
> +check_cflags -Wno-bool-operation
>  
>  if enabled extra_warnings; then
>  check_cflags -Wcast-qual
> 

Following this I am now getting a lot of:

src/libavformat/dump.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-bool-operation’

for every file which has other warnings.

$ gcc --version
gcc (Debian 6.3.0-18) 6.3.0 20170516

The test in configure passes, I think because:

:
"""
When an unrecognized warning option is requested (e.g., -Wunknown-warning), GCC 
emits a diagnostic stating that the option is not recognized. However, if the 
-Wno- form is used, the behavior is slightly different: no diagnostic is 
produced for -Wno-unknown-warning unless other diagnostics are being produced. 
This allows the use of new -Wno- options with old compilers, but if something 
goes wrong, the compiler warns that an unrecognized option is present. 
"""

Not sure exactly how to fix that.  Could we replace the check with something 
like "-Werror=bool-operation", which does error out when it doesn't find the 
warning option, and only add the "-Wno-bool-operation" if that works?

Thanks,

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] configure: Disable -Wbool-operation.

2017-10-08 Thread Carl Eugen Hoyos
2017-10-09 1:26 GMT+02:00 Mark Thompson :
> On 08/10/17 22:08, Carl Eugen Hoyos wrote:
>> ffmpeg | branch: master | Carl Eugen Hoyos  | Sun Oct  8 
>> 23:08:09 2017 +0200| [c2d155e11ee5ec732d471982f2dee43703bcd5a7] | committer: 
>> Carl Eugen Hoyos
>>
>> configure: Disable -Wbool-operation.
>>
>> Requested-by: Ronald and Derek
>>
>>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c2d155e11ee5ec732d471982f2dee43703bcd5a7
>> ---
>>
>>  configure | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/configure b/configure
>> index 77c9a18c3c..d5e96e95e1 100755
>> --- a/configure
>> +++ b/configure
>> @@ -6291,6 +6291,7 @@ check_cflags -Wmissing-prototypes
>>  check_cflags -Wno-pointer-to-int-cast
>>  check_cflags -Wstrict-prototypes
>>  check_cflags -Wempty-body
>> +check_cflags -Wno-bool-operation
>>
>>  if enabled extra_warnings; then
>>  check_cflags -Wcast-qual
>>
>
> Following this I am now getting a lot of:
>
> src/libavformat/dump.c: At top level:
> cc1: warning: unrecognized command line option ‘-Wno-bool-operation’

Please revert, sorry for the mess!

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] configure: Disable -Wbool-operation.

2017-10-08 Thread Mark Thompson
On 09/10/17 00:34, Carl Eugen Hoyos wrote:
> 2017-10-09 1:26 GMT+02:00 Mark Thompson :
>> On 08/10/17 22:08, Carl Eugen Hoyos wrote:
>>> ffmpeg | branch: master | Carl Eugen Hoyos  | Sun Oct  
>>> 8 23:08:09 2017 +0200| [c2d155e11ee5ec732d471982f2dee43703bcd5a7] | 
>>> committer: Carl Eugen Hoyos
>>>
>>> configure: Disable -Wbool-operation.
>>>
>>> Requested-by: Ronald and Derek
>>>
 http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c2d155e11ee5ec732d471982f2dee43703bcd5a7
>>> ---
>>>
>>>  configure | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/configure b/configure
>>> index 77c9a18c3c..d5e96e95e1 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -6291,6 +6291,7 @@ check_cflags -Wmissing-prototypes
>>>  check_cflags -Wno-pointer-to-int-cast
>>>  check_cflags -Wstrict-prototypes
>>>  check_cflags -Wempty-body
>>> +check_cflags -Wno-bool-operation
>>>
>>>  if enabled extra_warnings; then
>>>  check_cflags -Wcast-qual
>>>
>>
>> Following this I am now getting a lot of:
>>
>> src/libavformat/dump.c: At top level:
>> cc1: warning: unrecognized command line option ‘-Wno-bool-operation’
> 
> Please revert, sorry for the mess!

Ok, reverted for now.

I do agree with the intent of the patch, though, so we should fix this.  It 
looks like it will affect all future warnings with GCC, so it probably needs a 
new function in configure to do the warning test in a different way somehow.

Thanks,

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


[FFmpeg-devel] [PATCH] Fix crash if av_vdpau_bind_context() is not used.

2017-10-08 Thread Ivan Kalvachev
The public functions av_alloc_vdpaucontext() and
av_vdpau_alloc_context() are allocating AVVDPAUContext
structure that is supposed to be placed in avctx->hwaccel_context.

However the rest of libavcodec/vdpau.c uses avctx->hwaccel_context
as struct VDPAUHWContext, that is bigger and does contain
AVVDPAUContext as first member.

The usage includes write to the new variables in the bigger stuct,
without checking for block size.

Fix by always allocating the bigger structure.

BTW,
I have no idea why the new fields haven't simply been added to the
existing struct...
It seems that the programmer who wrote this has been aware of the problem,
because av_vdpau_bind_context reallocates the structure.

It might be good idea to check the other usages of this reallocation function.

Best Regards
   Ivan Kalvachev
From c9dafbf5402ebf8c68bf8648ecea7a74282113a8 Mon Sep 17 00:00:00 2001
From: Ivan Kalvachev 
Date: Mon, 9 Oct 2017 02:40:26 +0300
Subject: [PATCH] Fix crash if av_vdpau_bind_context() is not used.

The public functions av_alloc_vdpaucontext() and
av_vdpau_alloc_context() are allocating AVVDPAUContext
structure that is supposed to be placed in avctx->hwaccel_context.

However the rest of libavcodec/vdpau.c uses avctx->hwaccel_context
as struct VDPAUHWContext, that is bigger and does contain
AVVDPAUContext as first member.

The usage includes write to the new variables in the bigger stuct,
without checking for block size.

Fix by always allocating the bigger structure.

Signed-off-by: Ivan Kalvachev 
---
 libavcodec/vdpau.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 42ebddbee..4cc51cb79 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -816,7 +816,7 @@ do {   \
 
 AVVDPAUContext *av_vdpau_alloc_context(void)
 {
-return av_mallocz(sizeof(AVVDPAUContext));
+return av_mallocz(sizeof(VDPAUHWContext));
 }
 
 int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,
-- 
2.14.1

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] configure: Disable -Wbool-operation.

2017-10-08 Thread James Almer
On 10/8/2017 9:02 PM, Mark Thompson wrote:
> On 09/10/17 00:34, Carl Eugen Hoyos wrote:
>> 2017-10-09 1:26 GMT+02:00 Mark Thompson :
>>> On 08/10/17 22:08, Carl Eugen Hoyos wrote:
 ffmpeg | branch: master | Carl Eugen Hoyos  | Sun Oct  
 8 23:08:09 2017 +0200| [c2d155e11ee5ec732d471982f2dee43703bcd5a7] | 
 committer: Carl Eugen Hoyos

 configure: Disable -Wbool-operation.

 Requested-by: Ronald and Derek

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c2d155e11ee5ec732d471982f2dee43703bcd5a7
 ---

  configure | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/configure b/configure
 index 77c9a18c3c..d5e96e95e1 100755
 --- a/configure
 +++ b/configure
 @@ -6291,6 +6291,7 @@ check_cflags -Wmissing-prototypes
  check_cflags -Wno-pointer-to-int-cast
  check_cflags -Wstrict-prototypes
  check_cflags -Wempty-body
 +check_cflags -Wno-bool-operation

  if enabled extra_warnings; then
  check_cflags -Wcast-qual

>>>
>>> Following this I am now getting a lot of:
>>>
>>> src/libavformat/dump.c: At top level:
>>> cc1: warning: unrecognized command line option ‘-Wno-bool-operation’
>>
>> Please revert, sorry for the mess!
> 
> Ok, reverted for now.
> 
> I do agree with the intent of the patch, though, so we should fix this.  It 
> looks like it will affect all future warnings with GCC, so it probably needs 
> a new function in configure to do the warning test in a different way somehow.
> 
> Thanks,
> 
> - Mark

This test should probably use check_disable_warning() instead of
check_cflags().
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Fix visual glitch with XvMC, caused by wrong idct permutation.

2017-10-08 Thread Ronald S. Bultje
Hi,

On Sun, Oct 8, 2017 at 6:52 PM, Ivan Kalvachev  wrote:
[..]

Indentation is off in the second hunk, can you fix that?

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] configure: Disable -Wbool-operation.

2017-10-08 Thread Carl Eugen Hoyos
2017-10-09 2:02 GMT+02:00 James Almer :
> On 10/8/2017 9:02 PM, Mark Thompson wrote:
>> On 09/10/17 00:34, Carl Eugen Hoyos wrote:
>>> 2017-10-09 1:26 GMT+02:00 Mark Thompson :
 On 08/10/17 22:08, Carl Eugen Hoyos wrote:
> ffmpeg | branch: master | Carl Eugen Hoyos  | Sun Oct 
>  8 23:08:09 2017 +0200| [c2d155e11ee5ec732d471982f2dee43703bcd5a7] | 
> committer: Carl Eugen Hoyos
>
> configure: Disable -Wbool-operation.
>
> Requested-by: Ronald and Derek
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c2d155e11ee5ec732d471982f2dee43703bcd5a7
> ---
>
>  configure | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/configure b/configure
> index 77c9a18c3c..d5e96e95e1 100755
> --- a/configure
> +++ b/configure
> @@ -6291,6 +6291,7 @@ check_cflags -Wmissing-prototypes
>  check_cflags -Wno-pointer-to-int-cast
>  check_cflags -Wstrict-prototypes
>  check_cflags -Wempty-body
> +check_cflags -Wno-bool-operation
>
>  if enabled extra_warnings; then
>  check_cflags -Wcast-qual
>

 Following this I am now getting a lot of:

 src/libavformat/dump.c: At top level:
 cc1: warning: unrecognized command line option ‘-Wno-bool-operation’
>>>
>>> Please revert, sorry for the mess!
>>
>> Ok, reverted for now.
>>
>> I do agree with the intent of the patch, though, so we should fix this.  It 
>> looks like it will affect all future warnings with GCC, so it probably needs 
>> a new function in configure to do the warning test in a different way 
>> somehow.
>>
>> Thanks,
>>
>> - Mark
>
> This test should probably use check_disable_warning() instead of
> check_cflags().

Done.

Thank you both, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/3] avcodec/mpeg4videodec: Use 64 bit intermediates for sprite delta

2017-10-08 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: -104713 * 65536 cannot be 
represented in type 'int'
Fixes: 3453/clusterfuzz-testcase-minimized-554657239040
Fixes: 3528/clusterfuzz-testcase-minimized-6283628420005888

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

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 8f85e9362d..cd39131d55 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -179,6 +179,7 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
 int sprite_ref[4][2];
 int virtual_ref[2][2];
 int64_t sprite_offset[2][2];
+int64_t sprite_delta[2][2];
 
 // only true for rectangle shapes
 const int vop_ref[4][2] = { { 0, 0 }, { s->width, 0 },
@@ -262,10 +263,10 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
 sprite_offset[0][1]=
 sprite_offset[1][0]=
 sprite_offset[1][1]= 0;
-s->sprite_delta[0][0]  = a;
-s->sprite_delta[0][1]  =
-s->sprite_delta[1][0]  = 0;
-s->sprite_delta[1][1]  = a;
+sprite_delta[0][0] = a;
+sprite_delta[0][1] =
+sprite_delta[1][0] = 0;
+sprite_delta[1][1] = a;
 ctx->sprite_shift[0]   =
 ctx->sprite_shift[1]   = 0;
 break;
@@ -276,10 +277,10 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
  a * (vop_ref[0][0] / 2);
 sprite_offset[1][1]= ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] 
& 1)) -
  a * (vop_ref[0][1] / 2);
-s->sprite_delta[0][0]  = a;
-s->sprite_delta[0][1]  =
-s->sprite_delta[1][0]  = 0;
-s->sprite_delta[1][1]  = a;
+sprite_delta[0][0] = a;
+sprite_delta[0][1] =
+sprite_delta[1][0] = 0;
+sprite_delta[1][1] = a;
 ctx->sprite_shift[0]   =
 ctx->sprite_shift[1]   = 0;
 break;
@@ -304,10 +305,10 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
   ((int64_t)-r * sprite_ref[0][0] + 
virtual_ref[0][0]) *
   ((int64_t)-2 *vop_ref[0][1] + 1) + 2 * 
w2 * r *
   (int64_t)  sprite_ref[0][1] - 16 * w2 + 
(1 << (alpha + rho + 1)));
-s->sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
-s->sprite_delta[0][1] = (+r * sprite_ref[0][1] - virtual_ref[0][1]);
-s->sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]);
-s->sprite_delta[1][1] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
+sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
+sprite_delta[0][1] = (+r * sprite_ref[0][1] - virtual_ref[0][1]);
+sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]);
+sprite_delta[1][1] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
 
 ctx->sprite_shift[0]  = alpha + rho;
 ctx->sprite_shift[1]  = alpha + rho + 2;
@@ -332,28 +333,28 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
  ((int64_t)-r * sprite_ref[0][1] + 
virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
   (int64_t)2 * w2 * h3 * r * sprite_ref[0][1] 
- 16 * w2 * h3 +
  ((int64_t)1 << (alpha + beta + rho - min_ab + 
1));
-s->sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) * 
h3;
-s->sprite_delta[0][1] = (-r * sprite_ref[0][0] + virtual_ref[1][0]) * 
w3;
-s->sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) * 
h3;
-s->sprite_delta[1][1] = (-r * sprite_ref[0][1] + virtual_ref[1][1]) * 
w3;
+sprite_delta[0][0] = (-r * (int64_t)sprite_ref[0][0] + 
virtual_ref[0][0]) * h3;
+sprite_delta[0][1] = (-r * (int64_t)sprite_ref[0][0] + 
virtual_ref[1][0]) * w3;
+sprite_delta[1][0] = (-r * (int64_t)sprite_ref[0][1] + 
virtual_ref[0][1]) * h3;
+sprite_delta[1][1] = (-r * (int64_t)sprite_ref[0][1] + 
virtual_ref[1][1]) * w3;
 
 ctx->sprite_shift[0]  = alpha + beta + rho - min_ab;
 ctx->sprite_shift[1]  = alpha + beta + rho - min_ab + 2;
 break;
 }
 /* try to simplify the situation */
-if (s->sprite_delta[0][0] == a << ctx->sprite_shift[0] &&
-s->sprite_delta[0][1] == 0 &&
-s->sprite_delta[1][0] == 0 &&
-s->sprite_delta[1][1] == a << ctx->sprite_shift[0]) {
+if (sprite_delta[0][0] == a << ctx->sprite_shift[0] &&
+sprite_delta[0][1] == 0 &&
+sprite_delta[1][0] =

[FFmpeg-devel] [PATCH 3/3] avcodec/dirac_dwt: Fix integer overflow in COMPOSE_53iL0()

2017-10-08 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: 2147483646 + 2 cannot be 
represented in type 'int'
Fixes: 3485/clusterfuzz-testcase-minimized-4940429332054016

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/dirac_dwt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dirac_dwt.h b/libavcodec/dirac_dwt.h
index 755d5e5d2d..35ed8857e9 100644
--- a/libavcodec/dirac_dwt.h
+++ b/libavcodec/dirac_dwt.h
@@ -93,10 +93,10 @@ void ff_spatial_idwt_slice2(DWTContext *d, int y);
 
 // shared stuff for simd optimizations
 #define COMPOSE_53iL0(b0, b1, b2)\
-(b1 - ((b0 + b2 + 2) >> 2))
+(b1 - ((int)(b0 + (unsigned)(b2) + 2) >> 2))
 
 #define COMPOSE_DIRAC53iH0(b0, b1, b2)\
-(b1 + ((b0 + b2 + 1) >> 1))
+(b1 + ((int)(b0 + (unsigned)(b2) + 1) >> 1))
 
 #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
 (b2 + ((int)(-b0 + 9U*b1 + 9U*b3 - b4 + 8) >> 4))
-- 
2.14.2

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


[FFmpeg-devel] [PATCH 2/3] avcodec/mpeg_er: Clear mcsel in mpeg_er_decode_mb()

2017-10-08 Thread Michael Niedermayer
Fixes out of array read
Should fix: 3516/clusterfuzz-testcase-minimized-4608518562775040 (not 
reprodoceable)

Found-by: Insu Yun, Georgia Tech.
Signed-off-by: Michael Niedermayer 
---
 libavcodec/mpeg_er.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index 5eca834072..ada1a1692f 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -71,6 +71,7 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int 
mv_dir, int mv_type,
 s->mb_skipped = mb_skipped;
 s->mb_x   = mb_x;
 s->mb_y   = mb_y;
+s->mcsel  = 0;
 memcpy(s->mv, mv, sizeof(*mv));
 
 ff_init_block_index(s);
-- 
2.14.2

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


Re: [FFmpeg-devel] [PATCH]lavf/adp: Fix probe function on systems with signed char

2017-10-08 Thread Carl Eugen Hoyos
2017-10-08 23:42 GMT+02:00 Carl Eugen Hoyos :
> Hi!
>
> Attached patch fixes the adp probe function, it currently fires for
> repeated values.

Pushed, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH V2 2/2] lavc/vaapi_decode: fix profile search when disable exact profile match.

2017-10-08 Thread Jun Zhao


On 2017/10/1 23:47, Mark Thompson wrote:
> On 29/09/17 02:58, Jun Zhao wrote:
>> From 94604d623de1fec6f363dcda4d61712865257a0a Mon Sep 17 00:00:00 2001
>> From: Jun Zhao 
>> Date: Thu, 21 Sep 2017 02:44:42 -0400
>> Subject: [PATCH V2 2/2] lavc/vaapi_decode: fix profile search when disable
>>  exact profile match.
>>
>> when disable exact profile, use the alt_profile for VAAPI HWAccel
>> decoder.
>>
>> Signed-off-by: Jun Zhao 
>> ---
>>  libavcodec/vaapi_decode.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
>> index cf58aae4c6..f0dccf481b 100644
>> --- a/libavcodec/vaapi_decode.c
>> +++ b/libavcodec/vaapi_decode.c
>> @@ -328,7 +328,7 @@ static int vaapi_decode_make_config(AVCodecContext 
>> *avctx)
>>  if (j < profile_count) {
>>  if (exact_match)
>>  break;
>> -alt_profile = vaapi_profile_map[i].codec_profile;
>> +alt_profile = vaapi_profile_map[i].va_profile;
>>  }
>>  }
>>  av_freep(&profile_list);
>> @@ -348,6 +348,7 @@ static int vaapi_decode_make_config(AVCodecContext 
>> *avctx)
>>  av_log(avctx, AV_LOG_WARNING, "Using possibly-"
>> "incompatible profile %d instead.\n",
>> alt_profile);
>> +profile = alt_profile;
>>  } else {
>>  av_log(avctx, AV_LOG_VERBOSE, "Codec %s profile %d not "
>> "supported for hardware decode.\n",
>> -- 
>> 2.11.0
>>
> Yeah, that looks right to me now.
>
> The message comes out a bit strange, though, because the two profile values 
> are in different namespaces?  One is an FF_PROFILE_*, the other is a 
> VAProfile* - I think it's better to use the FF_PROFILE_* values in messages, 
> because they match what is actually in the stream (profile_idc, etc.).  Maybe 
> the first of the paired messages should also be WARNING too, so that it makes 
> more sense with default level (info) output.
>
> Thanks,
Will add a WARNING as the comments, Tks
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH V2 1/2] ffmpeg: re-enable hwaccel_lax_profile_check use hwaccel_flags.

2017-10-08 Thread Jun Zhao


On 2017/10/1 23:20, Mark Thompson wrote:
> On 29/09/17 02:58, Jun Zhao wrote:
>> From e2a7cce88d2a47c7e598b59d24258fea8d809c22 Mon Sep 17 00:00:00 2001
>> From: Jun Zhao 
>> Date: Thu, 21 Sep 2017 02:41:29 -0400
>> Subject: [PATCH V2 1/2] ffmpeg: re-enable hwaccel_lax_profile_check use
>>  hwaccel_flags.
>>
>> re-enable hwaccel_lax_profile_check option use hwaccel_flags.
>>
>> Signed-off-by: Jun Zhao 
>> ---
>>  ffmpeg.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/ffmpeg.c b/ffmpeg.c
>> index 1d248bc269..4f2b9d69d9 100644
>> --- a/ffmpeg.c
>> +++ b/ffmpeg.c
>> @@ -2859,6 +2859,9 @@ static enum AVPixelFormat get_format(AVCodecContext 
>> *s, const enum AVPixelFormat
>>  
>>  ist->active_hwaccel_id = hwaccel->id;
>>  ist->hwaccel_pix_fmt   = *p;
>> +
>> +if (hwaccel_lax_profile_check)
>> +s->hwaccel_flags |= AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH;
>>  break;
>>  }
>>  
>> -- 
>> 2.11.0
>>
> I'm inclined to say we should just remove the ad-hoc global lax_profile_check 
> option (which was previously implemented only in ffmpeg.c code for VAAPI) and 
> add a per-stream -hwaccel_flags option to set AVCodecContext.hwaccel_flags 
> directly instead.  That can contain "ignore_level" and 
> "allow_profile_mismatch" together, and maybe future flags if appropriate.
>
> What do you think?
>
> - Mark
I agree, will re-submit with the new option/flags.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] doc/filters: Add note on Flite thread safety and update URL

2017-10-08 Thread Gyan Doshi
Version 2 of Flite, a speech synthesis library, was released towards the 
end of 2014. Among the notes at the project site: "Thread safe (really 
this time)".


Docs and project URL updated accordingly.
From 8f0de211aaa9e100cbec2b12b4a1668541a76217 Mon Sep 17 00:00:00 2001
From: Gyan Doshi 
Date: Mon, 9 Oct 2017 11:06:10 +0530
Subject: [PATCH] doc/filters: add note on flite thread safety and update URL

Signed-off-by: Gyan Doshi 
---
 doc/filters.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 57189c77b0..ad2a01bb2e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4512,7 +4512,7 @@ Synthesize a voice utterance using the libflite library.
 To enable compilation of this filter you need to configure FFmpeg with
 @code{--enable-libflite}.
 
-Note that the flite library is not thread-safe.
+Note that versions of the flite library prior to 2.0 are not thread-safe.
 
 The filter accepts the following options:
 
@@ -4567,7 +4567,7 @@ ffplay -f lavfi flite=text='No more be grieved for which 
that thou hast done.'
 @end itemize
 
 For more information about libflite, check:
-@url{http://www.speech.cs.cmu.edu/flite/}
+@url{http://www.festvox.org/flite/}
 
 @section anoisesrc
 
-- 
2.12.2.windows.2___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/mips: preload data in hevc sao edge 135 degree filter msa functions

2017-10-08 Thread kaustubh.raste
From: Kaustubh Raste 

Signed-off-by: Kaustubh Raste 
---
 libavcodec/mips/hevc_lpf_sao_msa.c |  194 
 1 file changed, 132 insertions(+), 62 deletions(-)

diff --git a/libavcodec/mips/hevc_lpf_sao_msa.c 
b/libavcodec/mips/hevc_lpf_sao_msa.c
index c192265..5b5537a 100644
--- a/libavcodec/mips/hevc_lpf_sao_msa.c
+++ b/libavcodec/mips/hevc_lpf_sao_msa.c
@@ -2226,23 +2226,24 @@ static void 
hevc_sao_edge_filter_135degree_4width_msa(uint8_t *dst,
   int32_t height)
 {
 uint8_t *src_orig;
-int32_t h_cnt;
 uint32_t dst_val0, dst_val1;
-v8i16 edge_idx = { 1, 2, 0, 3, 4, 0, 0, 0 };
+v16i8 edge_idx = { 1, 2, 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 v16u8 const1 = (v16u8) __msa_ldi_b(1);
-v16i8 zero = { 0 };
+v16i8 offset, sao_offset = LD_SB(sao_offset_val);
 v16i8 src_zero0, src_zero1, dst0;
 v16u8 cmp_minus10, diff_minus10, cmp_minus11, diff_minus11;
 v16u8 src_minus10, src10, src_minus11, src11;
-v8i16 offset_mask0, offset_mask1, sao_offset, src00, src01;
+v8i16 offset_mask0, offset_mask1;
 
-sao_offset = LD_SH(sao_offset_val);
+sao_offset = __msa_pckev_b(sao_offset, sao_offset);
 src_orig = src - 1;
 
+/* load in advance */
 LD_UB2(src_orig - src_stride, src_stride, src_minus10, src_minus11);
+LD_UB2(src_orig + src_stride, src_stride, src10, src11);
 
-for (h_cnt = (height >> 1); h_cnt--;) {
-LD_UB2(src_orig + src_stride, src_stride, src10, src11);
+for (height -= 2; height; height -= 2) {
+src_orig += (src_stride << 1);
 
 SLDI_B2_0_SB(src_minus11, src10, src_zero0, src_zero1, 1);
 SLDI_B2_0_UB(src_minus10, src_minus11, src_minus10, src_minus11, 2);
@@ -2265,19 +2266,22 @@ static void 
hevc_sao_edge_filter_135degree_4width_msa(uint8_t *dst,
 offset_mask0 = (v8i16) (__msa_hadd_u_h(diff_minus10, diff_minus10) + 
2);
 offset_mask1 = (v8i16) (__msa_hadd_u_h(diff_minus11, diff_minus11) + 
2);
 
-VSHF_H2_SH(edge_idx, edge_idx, sao_offset, sao_offset, offset_mask0,
-   offset_mask0, offset_mask0, offset_mask0);
-VSHF_H2_SH(edge_idx, edge_idx, sao_offset, sao_offset, offset_mask1,
-   offset_mask1, offset_mask1, offset_mask1);
-ILVEV_B2_SH(src_zero0, zero, src_zero1, zero, src00, src01);
-ADD2(offset_mask0, src00, offset_mask1, src01, offset_mask0,
- offset_mask1);
-CLIP_SH2_0_255(offset_mask0, offset_mask1);
-dst0 = __msa_pckev_b((v16i8) offset_mask1, (v16i8) offset_mask0);
+offset = __msa_pckev_b((v16i8) offset_mask1, (v16i8) offset_mask0);
+dst0 = __msa_pckev_b((v16i8) src_zero1, (v16i8) src_zero0);
+
+VSHF_B2_SB(edge_idx, edge_idx, sao_offset, sao_offset, offset, offset,
+   offset, offset);
+
+dst0 = (v16i8) __msa_xori_b((v16u8) dst0, 128);
+dst0 = __msa_adds_s_b(dst0, offset);
+dst0 = (v16i8) __msa_xori_b((v16u8) dst0, 128);
 
 src_minus10 = src10;
 src_minus11 = src11;
 
+/* load in advance */
+LD_UB2(src_orig + src_stride, src_stride, src10, src11);
+
 dst_val0 = __msa_copy_u_w((v4i32) dst0, 0);
 dst_val1 = __msa_copy_u_w((v4i32) dst0, 2);
 
@@ -2286,8 +2290,46 @@ static void 
hevc_sao_edge_filter_135degree_4width_msa(uint8_t *dst,
 SW(dst_val1, dst);
 
 dst += dst_stride;
-src_orig += (src_stride << 1);
 }
+
+SLDI_B2_0_SB(src_minus11, src10, src_zero0, src_zero1, 1);
+SLDI_B2_0_UB(src_minus10, src_minus11, src_minus10, src_minus11, 2);
+
+ILVR_B2_UB(src10, src_minus10, src11, src_minus11, src_minus10,
+   src_minus11);
+ILVR_B2_SB(src_zero0, src_zero0, src_zero1, src_zero1, src_zero0,
+   src_zero1);
+
+cmp_minus10 = ((v16u8) src_zero0 == src_minus10);
+diff_minus10 = __msa_nor_v(cmp_minus10, cmp_minus10);
+cmp_minus10 = (src_minus10 < (v16u8) src_zero0);
+diff_minus10 = __msa_bmnz_v(diff_minus10, const1, cmp_minus10);
+
+cmp_minus11 = ((v16u8) src_zero1 == src_minus11);
+diff_minus11 = __msa_nor_v(cmp_minus11, cmp_minus11);
+cmp_minus11 = (src_minus11 < (v16u8) src_zero1);
+diff_minus11 = __msa_bmnz_v(diff_minus11, const1, cmp_minus11);
+
+offset_mask0 = (v8i16) (__msa_hadd_u_h(diff_minus10, diff_minus10) + 2);
+offset_mask1 = (v8i16) (__msa_hadd_u_h(diff_minus11, diff_minus11) + 2);
+
+offset = __msa_pckev_b((v16i8) offset_mask1, (v16i8) offset_mask0);
+dst0 = __msa_pckev_b((v16i8) src_zero1, (v16i8) src_zero0);
+
+VSHF_B2_SB(edge_idx, edge_idx, sao_offset, sao_offset, offset, offset,
+   offset, offset);
+
+dst0 = (v16i8) __msa_xori_b((v16u8) dst0, 128);
+dst0 = __msa_adds_s_b(dst0, offset);
+dst0 = (v16i8) __msa_xori_b((v16u8) dst0, 128);
+
+dst_val0 = __msa_copy_u_w((v4i32) dst0, 0);
+dst_val1 = __msa_copy_u_w((v4i32) dst0, 2);
+
+SW