Re: [FFmpeg-devel] [PATCH 1/2] cbs_h265: read/write HEVC PREFIX SEI

2018-04-22 Thread Xiang, Haihao

> On 20/04/18 08:27, Haihao Xiang wrote:
> > Similar to cbs_h264, cbs_h265_{read, write}_nal_unit() can handle HEVC
> > prefix SEI NAL units now. Currently mastering display colour volume SEI
> > message is added only, we may add more SEI message if needed later
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  libavcodec/cbs_h2645.c|  43 ++
> >  libavcodec/cbs_h265.h |  38 +
> >  libavcodec/cbs_h265_syntax_template.c | 150
> > ++
> >  3 files changed, 231 insertions(+)
> > 
> > diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> > index 5585831cf6..6fc5832966 100644
> > --- a/libavcodec/cbs_h2645.c
> > +++ b/libavcodec/cbs_h2645.c
> > @@ -29,6 +29,7 @@
> >  #include "h264_sei.h"
> >  #include "h2645_parse.h"
> >  #include "hevc.h"
> > +#include "hevc_sei.h"
> >  
> >  
> >  static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext
> > *gbc,
> > @@ -465,6 +466,26 @@ static void cbs_h265_free_slice(void *unit, uint8_t
> > *content)
> >  av_freep();
> >  }
> >  
> > +static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
> > +{
> > +switch (payload->payload_type) {
> > +case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
> > +break;
> > +default:
> > +av_buffer_unref(>payload.other.data_ref);
> > +break;
> > +}
> > +}
> > +
> > +static void cbs_h265_free_sei(void *unit, uint8_t *content)
> > +{
> > +H265RawSEI *sei = (H265RawSEI*)content;
> > +int i;
> > +for (i = 0; i < sei->payload_count; i++)
> > +cbs_h265_free_sei_payload(>payload[i]);
> > +av_freep();
> > +}
> > +
> >  static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
> > CodedBitstreamFragment *frag,
> > const H2645Packet *packet)
> > @@ -972,6 +993,20 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext
> > *ctx,
> >  }
> >  break;
> >  
> > +case HEVC_NAL_SEI_PREFIX:
> 
> I don't think it would be too hard to handling SEI_SUFFIX here too?  (The
> different set of valid payloads doesn't matter when we aren't checking that
> below.)
> 

I also don't think so. But it seems most pre-defined SEI types in hevc_sei.h are
SEI_PREFIX, hence my thought is we may add support for SEI_SUFFIX in the future
if SEI_SUFFIX is really needed.

> > +err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(H265RawSEI),
> > +_h265_free_sei);
> > +
> > +if (err < 0)
> > +return err;
> > +
> > +err = cbs_h265_read_sei(ctx, , unit->content);
> > +
> > +if (err < 0)
> > +return err;
> > +
> > +break;
> > +
> >  default:
> >  return AVERROR(ENOSYS);
> >  }
> > @@ -1212,6 +1247,14 @@ static int
> > cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
> >  }
> >  break;
> >  
> > +case HEVC_NAL_SEI_PREFIX:
> > +err = cbs_h265_write_sei(ctx, pbc, unit->content);
> > +
> > +if (err < 0)
> > +return err;
> > +
> > +break;
> > +
> 
> Please make these cases match the styling of the others.
> 

My original patch used the same coding style of the others, but patcheck in
FFmpeg reported a warning below:

{ should be on the same line as the related previous statement
0001-vaapi_encode_h265-Insert-SEI-if-needed.patch:24:+{

I will update it if you prefer the same coding style. 

> >  default:
> >  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
> > "NAL unit type %"PRIu32".\n", unit->type);
> > diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
> > index 33e71fc234..e37c1b8d94 100644
> > --- a/libavcodec/cbs_h265.h
> > +++ b/libavcodec/cbs_h265.h
> > @@ -25,6 +25,14 @@
> >  #include "cbs_h2645.h"
> >  #include "hevc.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).
> > +H265_MAX_SEI_PAYLOADS = 64,
> > +};
> >  
> >  typedef struct H265RawNALUnitHeader {
> >  uint8_t forbidden_zero_bit;
> > @@ -516,6 +524,36 @@ typedef struct H265RawSlice {
> >  AVBufferRef *data_ref;
> >  } H265RawSlice;
> >  
> > +typedef struct H265RawSEIMasteringDiplayColorVolume {
> 
> The H.265 standard uses English spelling of colour, not USAian.

Thanks, I will update it.

> 
> > +struct {
> > +uint16_t x;
> > +uint16_t y;
> > +} display_primaries[3];
> 
> Make it two arrays, display_primaries_x and display_primaries_y, so that it
> matches the standard.

Thanks, I will update it.

> 
> > +uint16_t 

Re: [FFmpeg-devel] [PATCH 10/26] vaapi_encode: Choose profiles dynamically

2018-04-22 Thread Michael Niedermayer
On Sun, Apr 22, 2018 at 04:29:05PM +0100, Mark Thompson wrote:
> Previously there was one fixed choice for each codec (e.g. H.265 -> Main
> profile), and using anything else then required an explicit option from
> the user.  This changes to selecting the profile based on the input format
> and the set of profiles actually supported by the driver (e.g. P010 input
> will choose Main 10 profile for H.265 if the driver supports it).
> 
> The entrypoint and render target format are also chosen dynamically in the
> same way, removing those explicit selections from the per-codec code.
> ---
>  doc/encoders.texi   |   3 +
>  libavcodec/vaapi_encode.c   | 261 
> +++-
>  libavcodec/vaapi_encode.h   |  41 +--
>  libavcodec/vaapi_encode_h264.c  |  45 ++-
>  libavcodec/vaapi_encode_h265.c  |  43 +++
>  libavcodec/vaapi_encode_mjpeg.c |  13 +-
>  libavcodec/vaapi_encode_mpeg2.c |  36 ++
>  libavcodec/vaapi_encode_vp8.c   |  11 +-
>  libavcodec/vaapi_encode_vp9.c   |  34 ++
>  9 files changed, 306 insertions(+), 181 deletions(-)

breaks build on linux x86-64 ubuntu

CC  libavcodec/vaapi_encode.o
libavcodec/vaapi_encode.c:1007:5: error: ‘VAEntrypointEncSliceLP’ undeclared 
here (not in a function)
 VAEntrypointEncSliceLP,
 ^
libavcodec/vaapi_encode.c:1011:5: error: initializer element is not constant
 VAEntrypointEncSliceLP,
 ^
libavcodec/vaapi_encode.c:1011:5: error: (near initialization for 
‘vaapi_encode_entrypoints_low_power[0]’)
make: *** [libavcodec/vaapi_encode.o] Error 1


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

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad


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


Re: [FFmpeg-devel] [PATCH 2/4] avfilter/avfiltergraph: fix has_alpha in pick_format

2018-04-22 Thread Marton Balint



On Mon, 23 Apr 2018, Michael Niedermayer wrote:


On Sun, Apr 22, 2018 at 01:44:19PM +0200, Marton Balint wrote:



On Fri, 20 Apr 2018, Michael Niedermayer wrote:


On Thu, Apr 19, 2018 at 09:32:19PM +0200, Marton Balint wrote:

A pixel format which has a palette also has alpha, without this patch the
format negotiation might have preferred formats without alpha even if the
source had alpha.

Signed-off-by: Marton Balint 
---
libavfilter/avfiltergraph.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 4cc6892404..e18f733e23 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -679,7 +679,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink 
*ref)

if (link->type == AVMEDIA_TYPE_VIDEO) {
if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
-int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 
== 0;
+int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0 || 
(av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_PAL);


This causes various output files to grow in size with a unused alpha plane

a random example: (there are likels better examples)
./ffmpeg -y -i ~/tickets/1116/1023.bmp -vf negate fileX.bmp

Iam not sure unconditionally treating all palettes as if they have
non fully opaque entries is a good idea.


Obviously not, but it is already treated this way in most places. Having a
bigger image with alpha is better than losing alpha. And the user can always
force losing alpha with a filter, and sometimes he has to do that anyway
because for example fre0r filters have no way of signalling if they use
alpha or not...


you can, the average user certainly doesnt have the knowledge to adjust
anything alpha by hand, the average user isnt even aware of that the issue
is alpha or pal8 related probably

also about "better", i saw a few cases that got bigger, i dont remember
seeing a case that was fixed.
Have you seen real usecases this fixes ?


A source file with a palette and alpha and a filter which supports formats 
with both alpha and without:


https://dab1nmslvvntp.cloudfront.net/images/blogs/design/8bit-trans.png

ffmpeg -i 8bit-trans.png -vf negate out.bmp

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


Re: [FFmpeg-devel] [PATCH v2 1/2] lavf: make overlay_qsv work based on framesync

2018-04-22 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Sunday, April 22, 2018 3:21 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] lavf: make overlay_qsv work
> based on framesync
> 
> On 03/04/18 02:50, Ruiling Song wrote:
> > The existing version which was cherry-picked from Libav does not work
> > with FFmpeg framework, because ff_request_frame() was totally
> > different between Libav (recursive) and FFmpeg (non-recursive).
> > The existing overlay_qsv implementation depends on the recursive
> > version of ff_request_frame to trigger immediate call to request_frame()
> on input pad.
> > But this has been removed in FFmpeg since "lavfi: make request_frame()
> non-recursive."
> > Now that we have handy framesync support in FFmpeg, so I make it work
> > based on framesync. Some other fixing which is also needed to make
> > overlay_qsv work are put in a separate patch.
> >
> > v2:
> > add .preinit field to initilize framesync options.
> > export more options like vf_overlay.c
> >
> > Signed-off-by: Ruiling Song 
> > ---
> >  libavfilter/Makefile |   2 +-
> >  libavfilter/vf_overlay_qsv.c | 213
> > ---
> >  2 files changed, 78 insertions(+), 137 deletions(-)
> >
> On 03/04/18 02:50, Ruiling Song wrote:
> > For filters based on framesync, the input frame was managed by
> > framesync, so we should not directly keep and destroy it, instead we
> > make a clone of it here, or else double-free will occur.
> > But for other filters not based on framesync, we still need to free
> > the input frame inside filter_frame. That's why I made this v2 to fix
> > the side-effect on normal filters.
> >
> > v2:
> > and one av_frame_free() in vf_vpp_qsv.c
> >
> > Signed-off-by: Ruiling Song 
> > ---
> >  libavfilter/qsvvpp.c | 4 ++--
> >  libavfilter/vf_vpp_qsv.c | 5 -
> >  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> Tested, LGTM, set applied with one minor merge fixup - it collided with the
> change to pass through unmodified frames directly.  (Apologies for the
> delay!)
> 
> Shall I apply this to the 4.0 branch as well?

Yes, merging it to 4.0 branch is a good idea (qsv_overly is declared but not 
workable now). 

> 
> Thanks,
> 
> - Mark

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


Re: [FFmpeg-devel] [V3 PATCH 0/3] Codec wrapper for librv11 and RMHD muxer/demuxer

2018-04-22 Thread James Almer
On 4/22/2018 6:43 PM, Paul B Mahol wrote:
> On 4/22/18, Thilo Borgmann  wrote:
>> Hi,
>>
>> V3 drops the MLTI part, no idea how it survived
>> 02fff499362daedcdcb0a9cdd517257843600563 on our side...
>> Also dropped audio override, could not get a sample requiring it.
>>
>> Adapted to current HEAD.
> 
> I'm strongly against applying this to our tree.

The de/muxing code can and should be applied as long as there are not
technical limitations. They are native code and depend on nothing external.

And regarding the decoder and encoder wrappers, you need to explain the
reasons for your hard NAK...
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/4] avfilter/avfiltergraph: fix has_alpha in pick_format

2018-04-22 Thread Michael Niedermayer
On Sun, Apr 22, 2018 at 01:44:19PM +0200, Marton Balint wrote:
> 
> 
> On Fri, 20 Apr 2018, Michael Niedermayer wrote:
> 
> >On Thu, Apr 19, 2018 at 09:32:19PM +0200, Marton Balint wrote:
> >>A pixel format which has a palette also has alpha, without this patch the
> >>format negotiation might have preferred formats without alpha even if the
> >>source had alpha.
> >>
> >>Signed-off-by: Marton Balint 
> >>---
> >> libavfilter/avfiltergraph.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >>diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> >>index 4cc6892404..e18f733e23 100644
> >>--- a/libavfilter/avfiltergraph.c
> >>+++ b/libavfilter/avfiltergraph.c
> >>@@ -679,7 +679,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink 
> >>*ref)
> >>
> >> if (link->type == AVMEDIA_TYPE_VIDEO) {
> >> if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
> >>-int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components 
> >>% 2 == 0;
> >>+int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components 
> >>% 2 == 0 || (av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_PAL);
> >
> >This causes various output files to grow in size with a unused alpha plane
> >
> >a random example: (there are likels better examples)
> >./ffmpeg -y -i ~/tickets/1116/1023.bmp -vf negate fileX.bmp
> >
> >Iam not sure unconditionally treating all palettes as if they have
> >non fully opaque entries is a good idea.
> 
> Obviously not, but it is already treated this way in most places. Having a
> bigger image with alpha is better than losing alpha. And the user can always
> force losing alpha with a filter, and sometimes he has to do that anyway
> because for example fre0r filters have no way of signalling if they use
> alpha or not...

you can, the average user certainly doesnt have the knowledge to adjust
anything alpha by hand, the average user isnt even aware of that the issue
is alpha or pal8 related probably

also about "better", i saw a few cases that got bigger, i dont remember
seeing a case that was fixed.
Have you seen real usecases this fixes ? 


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

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA


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


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Michael Niedermayer
On Sun, Apr 22, 2018 at 09:33:04AM +0200, Clément Bœsch wrote:
> On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
> [...]
> > I think av_thread_message_queue_elems would be a better name, had to think
> > for a good period of time what "nelem" meant.
> 
> I'm afraid of "queue_elems" implying "queuing elements" so I went for
> the more explicit av_thread_message_queue_nb_elems() instead.
> 

> Also fixed the problem raised by Michael.

confirmed

[...]
> diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
> index 8480a0a3db..7ebf03a8ac 100644
> --- a/libavutil/threadmessage.h
> +++ b/libavutil/threadmessage.h
> @@ -95,6 +95,11 @@ void 
> av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
>  void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
> void (*free_func)(void *msg));
>  
> +/**
> + * Return the current number of messages in the queue.
> + */

doesnt document the AVERROR case

should be ok otherwise, no more comments from me

thx
also welcome back !

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



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


[FFmpeg-devel] [PATCH] avcodec/vc1_block: simplify ac_val computation

2018-04-22 Thread Michael Niedermayer
also fixes: runtime error: index 1456 out of bounds for type 'int16_t [16]'

Found-by: durandal_1707

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vc1_block.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index f9f26f7e42..b06ee9fce7 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -594,7 +594,7 @@ static int vc1_decode_i_block(VC1Context *v, int16_t 
block[64], int n,
 scale = s->c_dc_scale;
 block[0] = dcdiff * scale;
 
-ac_val  = s->ac_val[0][0] + s->block_index[n] * 16;
+ac_val  = s->ac_val[0][s->block_index[n]];
 ac_val2 = ac_val;
 if (dc_pred_dir) // left
 ac_val -= 16;
@@ -745,7 +745,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t 
block[64], int n,
 
 scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);
 
-ac_val  = s->ac_val[0][0] + s->block_index[n] * 16;
+ac_val  = s->ac_val[0][s->block_index[n]];
 ac_val2 = ac_val;
 if (dc_pred_dir) // left
 ac_val -= 16;
@@ -946,7 +946,7 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t 
block[64], int n,
 if (!a_avail) dc_pred_dir = 1;
 if (!c_avail) dc_pred_dir = 0;
 if (!a_avail && !c_avail) use_pred = 0;
-ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ac_val = s->ac_val[0][s->block_index[n]];
 ac_val2 = ac_val;
 
 scale = mquant * 2 + v->halfpq;
-- 
2.17.0

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


Re: [FFmpeg-devel] [V3 PATCH 1/3] Add muxing/demuxing of RMHD

2018-04-22 Thread Paul B Mahol
On 4/22/18, Thilo Borgmann  wrote:
> -Thilo
>

To many changes, hard to track.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [V3 PATCH 0/3] Codec wrapper for librv11 and RMHD muxer/demuxer

2018-04-22 Thread Paul B Mahol
On 4/22/18, Thilo Borgmann  wrote:
> Hi,
>
> V3 drops the MLTI part, no idea how it survived
> 02fff499362daedcdcb0a9cdd517257843600563 on our side...
> Also dropped audio override, could not get a sample requiring it.
>
> Adapted to current HEAD.

I'm strongly against applying this to our tree.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] avdevice/decklink_dec: do not copy video data

2018-04-22 Thread Marton Balint
Create a buffer from the data instead and use the buffer destructor to free the
DeckLink frame. This avoids a memcpy of the frame data.

Signed-off-by: Marton Balint 
---
 libavdevice/decklink_dec.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index e97a4402ea..10535dc388 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -98,6 +98,14 @@ static VANCLineNumber vanc_line_numbers[] = {
 {bmdModeUnknown, 0, -1, -1, -1}
 };
 
+extern "C" {
+static void decklink_object_free(void *opaque, uint8_t *data)
+{
+IUnknown *obj = (class IUnknown *)opaque;
+obj->Release();
+}
+}
+
 static int get_vanc_line_idx(BMDDisplayMode mode)
 {
 unsigned int i;
@@ -797,6 +805,10 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 }
 }
 
+pkt.buf = av_buffer_create(pkt.data, pkt.size, decklink_object_free, 
videoFrame, 0);
+if (pkt.buf)
+videoFrame->AddRef();
+
 if (avpacket_queue_put(>queue, ) < 0) {
 ++ctx->dropped;
 }
-- 
2.13.6

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


[FFmpeg-devel] [PATCH 2/2] avdevice/decklink_dec: unref packets on avpacket_queue_put error

2018-04-22 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavdevice/decklink_dec.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 10535dc388..510637676c 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -475,16 +475,19 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket 
*pkt)
 
 // Drop Packet if queue size is > maximum queue size
 if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) {
+av_packet_unref(pkt);
 av_log(q->avctx, AV_LOG_WARNING,  "Decklink input buffer overrun!\n");
 return -1;
 }
 /* ensure the packet is reference counted */
 if (av_packet_make_refcounted(pkt) < 0) {
+av_packet_unref(pkt);
 return -1;
 }
 
 pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList));
 if (!pkt1) {
+av_packet_unref(pkt);
 return -1;
 }
 av_packet_move_ref(>pkt, pkt);
-- 
2.13.6

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


Re: [FFmpeg-devel] has_b_frames is larger in decoder than demuxer 1 > 0

2018-04-22 Thread Carl Eugen Hoyos
2018-04-21 7:59 GMT+02:00, Ruslan Baskou :
> [mpeg4 @ 0x14af5e0] has_b_frames is larger in decoder than demuxer 1 > 0.

This is ticket #6019.

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


[FFmpeg-devel] [V3 PATCH 3/3] Add docs and Changelog

2018-04-22 Thread Thilo Borgmann
-Thilo
From 49c6fa2051f2c1d2955405df938d930313b8f2a2 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Tue, 17 Apr 2018 22:55:29 +0200
Subject: [PATCH 3/3] Add docs and Changelog

---
 Changelog |  2 ++
 doc/encoders.texi | 92 +++
 doc/general.texi  |  7 +
 3 files changed, 101 insertions(+)

diff --git a/Changelog b/Changelog
index 7df4513..b740322 100644
--- a/Changelog
+++ b/Changelog
@@ -54,6 +54,8 @@ version :
 - Haivision SRT protocol via libsrt
 - segafilm muxer
 - vfrdet filter
+- RMHD Muxer/Demuxer
+- RealVideo 11 support via librv11
 
 
 version 3.4:
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7b09575..5818514 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1457,6 +1457,98 @@ Set maximum NAL size in bytes.
 Allow skipping frames to hit the target bitrate if set to 1.
 @end table
 
+@section librv11
+
+RealVideo 11 (RV60) codec wrapper.
+
+Requires the presence of the librv11 SDK headers and
+libraries during configuration. The library is detected using
+@command{pkg-config}.
+
+For more information about the library see
+@url{http://www.rmhd.io/}.
+
+@subsection Options
+
+The following FFmpeg global options affect the configurations of the
+librv11 encoder.
+
+@table @option
+@item b
+Set the bitrate (as a number of bits per second).
+
+@item is_lossprotect
+Enable loss protection feature
+
+@item output_width
+Video encoded frame output width
+
+@item output_height
+Video encoded frame output height
+
+@item rc_strategy
+Which ratecontrol method to be used (default: bitrate)
+
+@table @samp
+@item bitrate
+@item quality
+@end table
+
+@item complexity
+Encoding complexity (default: medium)
+
+@table @samp
+@item verylow
+@item low
+@item medium
+@item high
+@end table
+
+@item framerate
+Max frame rate value
+
+@item resize_quality
+Video encoded frame resize quality (default: 1),
+
+@table @samp
+@item high
+@item fast
+@end table
+
+@item video_mode
+Motion quality (default: 50)
+
+@table @samp
+@item normal
+@item sharp
+@item smooth
+@end table
+
+@item max_keyint
+Max keyframe interval (default: 5),
+
+@item max_latency
+Max video latency on start (default: 4.0)
+
+@item vbrquality
+Vbr quality value (default: 60)
+
+@item passlogfile
+Filename for 2 pass encoding stats (default: rv11passstats.log)
+
+@item pon
+Picture order number (default: 0)
+
+@item vbr_opt (default: false)
+Vbr enabled
+
+@table @samp
+@item true
+@item false
+@end table
+
+@end table
+
 @section libtheora
 
 libtheora Theora encoder wrapper.
diff --git a/doc/general.texi b/doc/general.texi
index 2583006..5af6585 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -263,6 +263,12 @@ Create an @code{AMF/} directory in the system include path.
 Copy the contents of @code{AMF/amf/public/include/} into that directory.
 Then configure FFmpeg with @code{--enable-amf}.
 
+@section RealVideo11 (RV60)
+
+FFmpeg can make use of the RV11 codec libraries for encoding and decoding.
+
+Go to @url{http://www.rmhd.io/} and download the SDK installer.
+
 
 @chapter Supported File Formats, Codecs or Features
 
@@ -542,6 +548,7 @@ library:
 @item REDCODE R3D   @tab   @tab X
 @tab File format used by RED Digital cameras, contains JPEG 2000 frames 
and PCM audio.
 @item RealMedia @tab X @tab X
+@item RealMedia HD  @tab X @tab X
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-- 
2.9.3

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


[FFmpeg-devel] [V3 PATCH 2/3] Add codec wrapper for librv11

2018-04-22 Thread Thilo Borgmann
-Thilo
From 14d93400443457ea935d42cadf7bc7e2b2e4447f Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Tue, 17 Apr 2018 22:55:02 +0200
Subject: [PATCH 2/3] Add codec wrapper for librv11

---
 MAINTAINERS |   1 +
 configure   |   5 +
 fftools/ffmpeg_opt.c|   2 +-
 libavcodec/Makefile |   2 +
 libavcodec/allcodecs.c  |   2 +
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 libavcodec/librv11.h|  55 
 libavcodec/librv11dec.c | 296 ++
 libavcodec/librv11enc.c | 649 
 libavcodec/version.h|   2 +-
 11 files changed, 1020 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/librv11.h
 create mode 100644 libavcodec/librv11dec.c
 create mode 100644 libavcodec/librv11enc.c

diff --git a/MAINTAINERS b/MAINTAINERS
index b618562..8c05594 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -194,6 +194,7 @@ Codecs:
   libkvazaar.c  Arttu Ylä-Outinen
   libopenjpeg.c Jaikrishnan Menon
   libopenjpegenc.c  Michael Bradshaw
+  librv11*  Thilo Borgmann, Qiang Luo
   libtheoraenc.cDavid Conrad
   libvorbis.c   David Conrad
   libvpx*   James Zern
diff --git a/configure b/configure
index a6f32f8..c7dd3f3 100755
--- a/configure
+++ b/configure
@@ -252,6 +252,7 @@ External library support:
   --enable-librsvg enable SVG rasterization via librsvg [no]
   --enable-librubberband   enable rubberband needed for rubberband filter [no]
   --enable-librtmp enable RTMP[E] support via librtmp [no]
+  --enable-librv11 enable RV11 support via librv11 [no]
   --enable-libshineenable fixed-point MP3 encoding via libshine [no]
   --enable-libsmbclientenable Samba protocol via libsmbclient [no]
   --enable-libsnappy   enable Snappy compression, needed for hap encoding 
[no]
@@ -1645,6 +1646,7 @@ EXTERNAL_LIBRARY_NONFREE_LIST="
 libndi_newtek
 libfdk_aac
 openssl
+librv11
 libtls
 "
 
@@ -3060,6 +3062,8 @@ libopus_decoder_deps="libopus"
 libopus_encoder_deps="libopus"
 libopus_encoder_select="audio_frame_queue"
 librsvg_decoder_deps="librsvg"
+librv11_decoder_deps="librv11"
+librv11_encoder_deps="librv11"
 libshine_encoder_deps="libshine"
 libshine_encoder_select="audio_frame_queue"
 libspeex_decoder_deps="libspeex"
@@ -6024,6 +6028,7 @@ enabled libpulse  && require_pkg_config libpulse 
libpulse pulse/pulseaud
 enabled librsvg   && require_pkg_config librsvg librsvg-2.0 
librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
 enabled librtmp   && require_pkg_config librtmp librtmp librtmp/rtmp.h 
RTMP_Socket
 enabled librubberband && require_pkg_config librubberband "rubberband >= 
1.8.1" rubberband/rubberband-c.h rubberband_new -lstdc++ && append 
librubberband_extralibs "-lstdc++"
+enabled librv11   && require_pkg_config librv11 librv11 librv11_sdk.h 
RV60toYUV420Init
 enabled libshine  && require_pkg_config libshine shine shine/layer3.h 
shine_encode_buffer
 enabled libsmbclient  && { check_pkg_config libsmbclient smbclient 
libsmbclient.h smbc_init ||
require libsmbclient libsmbclient.h smbc_init 
-lsmbclient; }
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index d7a7eb0..1b6d8cf 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1747,7 +1747,7 @@ static OutputStream *new_video_stream(OptionsContext *o, 
AVFormatContext *oc, in
  ost->logfile_prefix ? ost->logfile_prefix :
DEFAULT_PASS_LOGFILENAME_PREFIX,
  i);
-if (!strcmp(ost->enc->name, "libx264")) {
+if (!strcmp(ost->enc->name, "libx264") || !strcmp(ost->enc->name, 
"librv11enc")) {
 av_dict_set(>encoder_opts, "stats", logfilename, 
AV_DICT_DONT_OVERWRITE);
 } else {
 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4b8ad12..11026af 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -965,6 +965,8 @@ OBJS-$(CONFIG_LIBOPUS_DECODER)+= libopusdec.o 
libopus.o \
  vorbis_data.o
 OBJS-$(CONFIG_LIBOPUS_ENCODER)+= libopusenc.o libopus.o \
  vorbis_data.o
+OBJS-$(CONFIG_LIBRV11_DECODER)+= librv11dec.o
+OBJS-$(CONFIG_LIBRV11_ENCODER)+= librv11enc.o
 OBJS-$(CONFIG_LIBSHINE_ENCODER)   += libshine.o
 OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
 OBJS-$(CONFIG_LIBSPEEX_ENCODER)   += libspeexenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4d4ef53..5789ac5 100644
--- a/libavcodec/allcodecs.c
+++ 

[FFmpeg-devel] [V3 PATCH 1/3] Add muxing/demuxing of RMHD

2018-04-22 Thread Thilo Borgmann
-Thilo
From a8d3f717d2e35f2b81cd05e5baf4a6dc5900ee34 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann 
Date: Tue, 17 Apr 2018 22:53:02 +0200
Subject: [PATCH 1/3] Add muxing/demuxing of RMHD

---
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/rm.c |   1 +
 libavformat/rm.h |   7 +
 libavformat/rmdec.c  |  50 --
 libavformat/rmenc.c  | 425 ++-
 libavformat/utils.c  |   5 +-
 7 files changed, 390 insertions(+), 100 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3eeca50..a579fc0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -421,6 +421,7 @@ OBJS-$(CONFIG_REDSPARK_DEMUXER)  += redspark.o
 OBJS-$(CONFIG_RL2_DEMUXER)   += rl2.o
 OBJS-$(CONFIG_RM_DEMUXER)+= rmdec.o rm.o rmsipr.o
 OBJS-$(CONFIG_RM_MUXER)  += rmenc.o rm.o
+OBJS-$(CONFIG_RMHD_MUXER)+= rmenc.o rm.o
 OBJS-$(CONFIG_ROQ_DEMUXER)   += idroqdec.o
 OBJS-$(CONFIG_ROQ_MUXER) += idroqenc.o rawenc.o
 OBJS-$(CONFIG_RSD_DEMUXER)   += rsd.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d582778..de31fd9 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -337,6 +337,7 @@ extern AVInputFormat  ff_redspark_demuxer;
 extern AVInputFormat  ff_rl2_demuxer;
 extern AVInputFormat  ff_rm_demuxer;
 extern AVOutputFormat ff_rm_muxer;
+extern AVOutputFormat ff_rmhd_muxer;
 extern AVInputFormat  ff_roq_demuxer;
 extern AVOutputFormat ff_roq_muxer;
 extern AVInputFormat  ff_rpl_demuxer;
diff --git a/libavformat/rm.c b/libavformat/rm.c
index 52c7ccc..a66c9b6 100644
--- a/libavformat/rm.c
+++ b/libavformat/rm.c
@@ -34,6 +34,7 @@ const AVCodecTag ff_rm_codec_tags[] = {
 { AV_CODEC_ID_RV20,   MKTAG('R','V','T','R') },
 { AV_CODEC_ID_RV30,   MKTAG('R','V','3','0') },
 { AV_CODEC_ID_RV40,   MKTAG('R','V','4','0') },
+{ AV_CODEC_ID_RV60,   MKTAG('R','V','6','0') },
 { AV_CODEC_ID_AC3,MKTAG('d','n','e','t') },
 { AV_CODEC_ID_RA_144, MKTAG('l','p','c','J') },
 { AV_CODEC_ID_RA_288, MKTAG('2','8','_','8') },
diff --git a/libavformat/rm.h b/libavformat/rm.h
index 7b080e2..eeb9862 100644
--- a/libavformat/rm.h
+++ b/libavformat/rm.h
@@ -25,6 +25,13 @@
 #include "avformat.h"
 #include "internal.h"
 
+#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
Cooker/ATRAC
+#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
+#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
+#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
+#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
+#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
+
 extern const char * const ff_rm_metadata[4];
 extern const AVCodecTag ff_rm_codec_tags[];
 
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index ac61723..302f12a 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -33,13 +33,6 @@
 #include "rmsipr.h"
 #include "rm.h"
 
-#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
Cooker/ATRAC
-#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
-#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
-#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
-#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
-#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
-
 struct RMStream {
 AVPacket pkt;  ///< place to store merged video frame / reordered 
audio data
 int videobufsize;  ///< current assembled frame size
@@ -420,7 +413,8 @@ skip:
 static int rm_read_index(AVFormatContext *s)
 {
 AVIOContext *pb = s->pb;
-unsigned int size, n_pkts, str_id, next_off, n, pos, pts;
+unsigned int size, n_pkts, str_id, n, pts, version;
+uint64_t next_off, pos;
 AVStream *st;
 
 do {
@@ -429,10 +423,10 @@ static int rm_read_index(AVFormatContext *s)
 size = avio_rb32(pb);
 if (size < 20)
 return -1;
-avio_skip(pb, 2);
+version  = avio_rb16(pb);
 n_pkts   = avio_rb32(pb);
 str_id   = avio_rb16(pb);
-next_off = avio_rb32(pb);
+next_off = (version == 2) ? avio_rb64(pb) : avio_rb32(pb);
 for (n = 0; n < s->nb_streams; n++)
 if (s->streams[n]->id == str_id) {
 st = s->streams[n];
@@ -455,7 +449,7 @@ static int rm_read_index(AVFormatContext *s)
 for (n = 0; n < n_pkts; n++) {
 avio_skip(pb, 2);
 pts = avio_rb32(pb);
-pos = avio_rb32(pb);
+pos = (version == 2) ? avio_rb64(pb) : avio_rb32(pb);
 avio_skip(pb, 4); /* packet no. */
 
 av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);
@@ -536,6 +530,7 @@ 

[FFmpeg-devel] [V3 PATCH 0/3] Codec wrapper for librv11 and RMHD muxer/demuxer

2018-04-22 Thread Thilo Borgmann
Hi,

V3 drops the MLTI part, no idea how it survived 
02fff499362daedcdcb0a9cdd517257843600563 on our side...
Also dropped audio override, could not get a sample requiring it.

Adapted to current HEAD.

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


[FFmpeg-devel] [PATCH 1/2] avcodec/h263dec: Check slice_ret in mspeg4 slice loop

2018-04-22 Thread Michael Niedermayer
Fixes infinite loop
Fixes: 
6858/clusterfuzz-testcase-ffmpeg_AV_CODEC_ID_MSMPEG4V3_fuzzer-4681563766784000
Fixes: 6890/clusterfuzz-testcase-ffmpeg_AV_CODEC_ID_WMV1_fuzzer-4756103142309888

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

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 484bf39578..eae29fa438 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -641,7 +641,7 @@ retry:
 slice_ret = decode_slice(s);
 while (s->mb_y < s->mb_height) {
 if (s->msmpeg4_version) {
-if (s->slice_height == 0 || s->mb_x != 0 ||
+if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 ||
 (s->mb_y % s->slice_height) != 0 || get_bits_left(>gb) < 0)
 break;
 } else {
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/error_resilience: Fix integer overflow in filter181()

2018-04-22 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: 197710 * 10923 cannot be 
represented in type 'int'
Fixes: 
7010/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5667127596941312

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

diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 25e54a535b..339042e206 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -107,7 +107,7 @@ static void filter181(int16_t *data, int width, int height, 
ptrdiff_t stride)
 dc = -prev_dc +
  data[x + y * stride] * 8 -
  data[x + 1 + y * stride];
-dc = (dc * 10923 + 32768) >> 16;
+dc = (av_clip(dc, INT_MIN/10923, INT_MAX/10923 - 32768) * 10923 + 
32768) >> 16;
 prev_dc = data[x + y * stride];
 data[x + y * stride] = dc;
 }
@@ -123,7 +123,7 @@ static void filter181(int16_t *data, int width, int height, 
ptrdiff_t stride)
 dc = -prev_dc +
  data[x +  y  * stride] * 8 -
  data[x + (y + 1) * stride];
-dc = (dc * 10923 + 32768) >> 16;
+dc = (av_clip(dc, INT_MIN/10923, INT_MAX/10923 - 32768) * 10923 + 
32768) >> 16;
 prev_dc = data[x + y * stride];
 data[x + y * stride] = dc;
 }
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/vpcc: add ff_isom_get_vpcc_features()

2018-04-22 Thread James Almer
On 4/18/2018 10:49 AM, James Almer wrote:
> Should be useful for muxers that require values as defined in the
> vpcc atom but don't need to write the atom itself.
> 
> Signed-off-by: James Almer 
> ---
>  libavformat/vpcc.c | 29 -
>  libavformat/vpcc.h | 11 +++
>  2 files changed, 35 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
> index df08de59a6..66d0df69e5 100644
> --- a/libavformat/vpcc.c
> +++ b/libavformat/vpcc.c
> @@ -67,8 +67,8 @@ static int get_vpx_video_full_range_flag(enum AVColorRange 
> color_range)
>  return color_range == AVCOL_RANGE_JPEG;
>  }
>  
> -int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
> -   AVCodecParameters *par)
> +int ff_isom_get_vpcc_features(AVFormatContext *s, AVCodecParameters *par,
> +  VPCC *vpcc)
>  {
>  int profile = par->profile;
>  int level = par->level == FF_LEVEL_UNKNOWN ? 0 : par->level;
> @@ -90,9 +90,28 @@ int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
>  }
>  }
>  
> -avio_w8(pb, profile);
> -avio_w8(pb, level);
> -avio_w8(pb, (bit_depth << 4) | (vpx_chroma_subsampling << 1) | 
> vpx_video_full_range_flag);
> +vpcc->profile= profile;
> +vpcc->level  = level;
> +vpcc->bitdepth   = bit_depth;
> +vpcc->chroma_subsampling = vpx_chroma_subsampling;
> +vpcc->full_range_flag= vpx_video_full_range_flag;
> +
> +return 0;
> +}
> +
> +int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
> +   AVCodecParameters *par)
> +{
> +VPCC vpcc;
> +int ret;
> +
> +ret = ff_isom_get_vpcc_features(s, par, );
> +if (ret < 0)
> +return ret;
> +
> +avio_w8(pb, vpcc.profile);
> +avio_w8(pb, vpcc.level);
> +avio_w8(pb, (vpcc.bitdepth << 4) | (vpcc.chroma_subsampling << 1) | 
> vpcc.full_range_flag);
>  avio_w8(pb, par->color_primaries);
>  avio_w8(pb, par->color_trc);
>  avio_w8(pb, par->color_space);
> diff --git a/libavformat/vpcc.h b/libavformat/vpcc.h
> index 184e8579f1..d71ba05105 100644
> --- a/libavformat/vpcc.h
> +++ b/libavformat/vpcc.h
> @@ -32,6 +32,14 @@
>  #include "avformat.h"
>  #include "libavcodec/avcodec.h"
>  
> +typedef struct VPCC {
> +int profile;
> +int level;
> +int bitdepth;
> +int chroma_subsampling;
> +int full_range_flag;
> +} VPCC;
> +
>  /**
>   * Writes VP codec configuration to the provided AVIOContext.
>   *
> @@ -44,4 +52,7 @@
>  int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
> AVCodecParameters *par);
>  
> +int ff_isom_get_vpcc_features(AVFormatContext *s, AVCodecParameters *par,
> +  VPCC *vpcc);
> +
>  #endif /* AVFORMAT_VPCC_H */

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


Re: [FFmpeg-devel] [PATCH] Added the possibility to pass an externally created CUDA context to libavutil/hwcontext.c/av_hwdevice_ctx_create() for decoding with NVDEC

2018-04-22 Thread Mark Thompson
On 19/04/18 17:00, Oscar Amoros Huguet wrote:
> 
> Hi!
> 
> We changed 4 files in ffmpeg, libavcodec/nvdec.c, libavutil/hwcontext.c, 
> libavutil/hwcontext_cuda.h, libavutil/hwcontext_cuda.c.
> 
> The purpose of this modification is very simple. We needed, for performance 
> reasons (per frame execution time), that nvdec.c used the same CUDA context 
> as we use in our software.
> 
> The reason for this is not so simple, and two fold:
> - We wanted to remove the overhead of having the GPU constantly switching 
> contexts, as we use up to 8 nvdec instances at the same time, plus a lot of 
> CUDA computations.
> - For video syncronization and buffering purposes, after decoding we need to 
> download the frame from GPU to CPU, but in a non blocking and overlapped 
> (with computation and other transfers) manner, so the impact of the transfer 
> is almost zero.
> 
> In order to do the later, we need to be able to synchronize our manually 
> created CUDA stream with the CUDA stream being used by ffmpeg, which by 
> default is the Legacy default stream. 
> To do so, we need to be in the same CUDA context, otherwise we don't have 
> access to the Legacy CUDA stream being used by ffmpeg.
> 
> The conseqüence is, that without changin ffmpeg code, the transfer of the 
> frame from GPU to CPU, could not be asynchronous, because if made 
> asynchronous, it overlapped with the device to device cuMemcpy made 
> internally by ffmpeg, and therefore, the resulting frames where (many times) 
> a mix of two frames.
> 
> So what did we change?
> 
> - Outside of the ffmpeg code, we allocate an AVBufferRef with 
> av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_CUDA), and we access the 
> AVCUDADeviceContext associated, to set the CUDA context (cuda_ctx).
> - We modified libavutil/hwcontext.c call av_hwdevice_ctx_create() so it 
> detects that the AVBufferRef being passed, was allocaded externally. We don't 
> check that AVHWDeviceType is AV_HWDEVICE_TYPE_CUDA. Let us know if you think 
> we should check that, otherwise go back to default behavior.
> - If the AVBufferRef was allocated, then we skip the allocation call, and 
> pass the data as AVHWDeviceContext type to cuda_device_create.
> - We modified libavutil/hwcontext_cuda.c in several parts:
> - cuda_device_create detects if there is a cuda context already present in 
> the AVCUDADeviceContext, and if so, sets the new parameter 
> AVCUDADeviceContext.is_ctx_externally_allocated to 1.
> - This way, all the succesive calls to this file, take into account that 
> ffmpeg is not responsible for either the creation, thread binding/unbinding 
> and destruction of the CUDA context.
> - Also, we skip context push and pop if the context was passed externally 
> (specially in non initialization calls), to reduce the number of calls to the 
> CUDA runtime, and improve the execution times of the CPU threads using ffmpeg.
> 
> With this, we managed to have all the CUDA calls in the aplication, in the 
> same CUDA context. Also, we use CUDA default stream per-thread, so in order 
> to synch with the CUDA stream used by ffmpeg, we only had to put the GPU to 
> CPU copy, to the globally accessible cudaStreamPerThread CUDA stream.
> 
> So, of 33ms of available time we have per frame, we save more than 6ms, that 
> where being used by the blocking copies from GPU to CPU.
> 
> We considered further optimizing the code, by changing ffmpeg so it can 
> internally access the cudaStreamPerThread, and cuMemcpyAsynch, so the 
> DevicetoDevice copies are aslo asynchronous and overlapped with the rest of 
> the computation, but the time saved is much lower, and we have other 
> optimizations to do in our code, that can save more time.
> 
> Nevetheless, if you find interesting this last optimization, let us know.
> 
> Also, please, let us know any thing we did wrong or missed.

You've missed that the main feature you are adding is already present.  Look at 
av_hwdevice_ctx_alloc() + av_hwdevice_ctx_init(), which uses an existing device 
supplied by the user; av_hwdevice_ctx_create() is only for creating new devices 
which will be managed internally.

I don't about how well the other part eliding context push/pop operations will 
work (someone with more Nvidia knowledge may wish to comment on that), but it 
shoudn't be dependent on whether the context was created externally.  If you 
want to add that flag then it should probably be called something like "single 
global context" to make clear what it actually means.  Also note that there are 
more push/pop pairs in the codebase (e.g. for NVENC and in libavfilter), and 
they may all need to be updated to respect this flag as well.

Thanks,

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


[FFmpeg-devel] has_b_frames is larger in decoder than demuxer 1 > 0

2018-04-22 Thread Ruslan Baskou
[mpeg4 @ 0x14af5e0] has_b_frames is larger in decoder than demuxer 1 > 0.

https://drive.google.com/open?id=1pwmlVi7GhHQmIh8UcL0_ZF1RyFOKGs82
ffmpeg version 2.8.14-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg 
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 
--build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu 
--incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl 
--enable-shared --disable-stripping --disable-decoder=libopenjpeg 
--disable-decoder=libschroedinger --enable-avresample --enable-avisynth 
--enable-gnutls --enable-ladspa --enable-libass --enable-libbluray 
--enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite 
--enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme 
--enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg 
--enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger 
--enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex 
--enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis 
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 
--enable-libxvid --enable-libzvbi --enable-openal --enable-opengl 
--enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq 
--enable-frei0r --enable-libx264 --enable-libopencv
  WARNING: library configuration mismatch
  avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 
--build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu 
--incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl 
--enable-shared --disable-stripping --disable-decoder=libopenjpeg 
--disable-decoder=libschroedinger --enable-avresample --enable-avisynth 
--enable-gnutls --enable-ladspa --enable-libass --enable-libbluray 
--enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite 
--enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme 
--enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg 
--enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger 
--enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex 
--enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis 
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 
--enable-libxvid --enable-libzvbi --enable-openal --enable-opengl 
--enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq 
--enable-frei0r --enable-libx264 --enable-libopencv --enable-version3 
--disable-doc --disable-programs --disable-avdevice --disable-avfilter 
--disable-avformat --disable-avresample --disable-postproc --disable-swscale 
--enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc 
--enable-libvo_amrwbenc
  libavutil  54. 31.100 / 54. 31.100
  libavcodec 56. 60.100 / 56. 60.100
  libavformat56. 40.101 / 56. 40.101
  libavdevice56.  4.100 / 56.  4.100
  libavfilter 5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale  3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc53.  3.100 / 53.  3.100
Input #0, avi, from '/home/ru5/Public/video/Мультфильм/Золотая коллекция 
Союзмультфильма/диск 14/04 - История одного преступления.avi':
  Metadata:
encoder : VirtualDubMod 1.5.10.2 (build 2542/release)
  Duration: 00:20:17.15, start: 0.00, bitrate: 1720 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (XVID / 0x44495658), yuv420p, 
640x480 [SAR 1:1 DAR 4:3], 1548 kb/s, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.98 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 160 
kb/s
x265 [info]: HEVC encoder version 1.9
x265 [info]: build info [Linux][GCC 5.3.1][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
x265 [info]: Main profile, Level-3 (Main tier)
x265 [info]: Thread pool created using 2 threads
x265 [info]: frame threads / pool features   : 1 / wpp(15 rows)
x265 [warning]: Source height < 720p; disabling lookahead-slices
x265 [info]: Coding QT: max CU size, min CU size : 32 / 16
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge : dia / 57 / 0 / 2
x265 [info]: Keyframe min / max / scenecut   : 25 / 250 / 0
x265 [info]: Lookahead / bframes / badapt: 5 / 3 / 0
x265 [info]: b-pyramid / weightp / weightb   : 1 / 0 / 0
x265 [info]: References / ref-limit  cu / depth  : 1 / 0 / 0
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 1 / 0.0 / 32 / 1
x265 [info]: Rate Control / qCompress: CRF-28.0 / 0.60
x265 [info]: tools: rd=2 psy-rd=2.00 early-skip tmvp fast-intra
x265 [info]: tools: strong-intra-smoothing deblock
Output #0, mp4, to '/home/ru5/Public/video/Мультфильм/Золотая коллекция 
Союзмультфильма/диск 14/04 - 

[FFmpeg-devel] Hi there, i have a couple of suggestion for FFMPEG-DEV

2018-04-22 Thread fred thompson
I have not reviewed the source code due to time constraints, but here I go:


Multidimensional arrays need be implemented, where every odd array is used
as some sort of a fallback thread (used for extra processing),
multithreading can help this


binary trees need to be implemented multidimensionally, where each node
head/tail/etc is its own dimension

a character array also needs to be implemented in some data structures
which can be used for hashes


I really hope all of this makes sense, I haven't had my coffee today =(



may the Schwartz be with you

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


Re: [FFmpeg-devel] [PATCH] libavformat: add mbedTLS based TLS

2018-04-22 Thread Carl Eugen Hoyos
2018-04-22 20:00 GMT+02:00, Nicolas George :
> Carl Eugen Hoyos (2018-04-22):
>> How do you detect that this is not the "current version" of mbed?
>
> Is it really our responsibility?

We try to always do it and I believe that allowing LGPL makes
more sense and less headache: Since we do the checks so
rigorously it makes sense to assume we did it as correctly
for this case.

I don't understand why we don't go the easy way that clearly
has advantages instead for the complicated way (with at
least some disadvantages).

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


Re: [FFmpeg-devel] [PATCH] libavformat: add mbedTLS based TLS

2018-04-22 Thread Nicolas George
Carl Eugen Hoyos (2018-04-22):
> How do you detect that this is not the "current version" of mbed?

Is it really our responsibility?

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] libavformat: add mbedTLS based TLS

2018-04-22 Thread Carl Eugen Hoyos
2018-04-22 14:47 GMT+02:00, Thomas Volkert :
> From: Thomas Volkert 

> @@ -1638,6 +1640,7 @@ EXTERNAL_LIBRARY_GPL_LIST="
>  libx265
>  libxavs
>  libxvid
> +mbedtls

How do you detect that this is not the "current version" of mbed?
And why is LGPLv3 not supported?
Please make this VERSION3 to make it as simple as possible.

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


Re: [FFmpeg-devel] swscale/swscale_unscaled : add X86_64 (SSE2, AVX) for uyvyto422

2018-04-22 Thread Martin Vignali
2018-04-08 22:21 GMT+02:00 Martin Vignali :

> Hello,
>
> New patch in attach,
> Remove the C part of the sse/avx func, and integrate all the process in
> the ASM func
>
> A little bit faster, and avoid the macro in x86/rgb2rgb.c.
>
>
> Remove the debug message in the checkasm test
and pushed

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


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Rostislav Pehlivanov
On 22 April 2018 at 17:59, Rostislav Pehlivanov  wrote:

>
>
> On 22 April 2018 at 17:51, Mark Thompson  wrote:
>
>> On 22/04/18 17:36, Mark Thompson wrote:
>> > On 22/04/18 17:28, Rostislav Pehlivanov wrote:
>> >> On 22 April 2018 at 17:21, Rostislav Pehlivanov 
>> wrote:
>> >>> On 22 April 2018 at 12:46, Mark Thompson  wrote:
>>  On 21/04/18 23:29, Carl Eugen Hoyos wrote:
>> > 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov <
>> atomnu...@gmail.com>:
>> >> On 21 April 2018 at 21:24, Carl Eugen Hoyos 
>>  wrote:
>> >>
>> >>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov <
>> atomnu...@gmail.com
>> > :
>> >>>
>>  +[AV_PIX_FMT_P010]  =
>>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
>> >>>
>>  +[AV_PIX_FMT_YUV420P10] =
>>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
>> >>>
>> >>> I don't think both can be correct (unless "PACK16" has no
>> meaning).
>> >
>> >> They're both correct and work.
>> >
>> > That's really strange...
>> > (Could this be a bug in the driver?)
>> 
>>  Sounds like it must be a bug somewhere.
>> 
>>  The Vulkan specification says:
>> 
>>  """
>>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a
>> unsigned
>>  normalized multi-planar format that has a 10-bit G component in the
>> top 10
>>  bits of each 16-bit word of plane 0, and a two-component, 32-bit BR
>> plane 1
>>  consisting of a 10-bit B component in the top 10 bits of the word in
>> bytes
>>  0..1, and a 10-bit R component in the top 10 bits of the word in
>> bytes
>>  2..3, the bottom 6 bits of each word set to 0.
>> 
>>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a
>>  unsigned normalized multi-planar format that has a 10-bit G
>> component in
>>  the top 10 bits of each 16-bit word of plane 0, a 10-bit B component
>> in the
>>  top 10 bits of each 16-bit word of plane 1, and a 10-bit R component
>> in the
>>  top 10 bits of each 16-bit word of plane 2, with the bottom 6 bits
>> of each
>>  word set to 0.
>>  """
>> 
>>  Which I think makes it pretty clear that
>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
>>  is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_3P
>> LANE_420_UNORM_3PACK16
>>  isn't YUV420P10 because they pack the 10 bits at different ends of
>> the
>>  16-bit value.  If a driver is getting that wrong then it should be
>> reported
>>  to the vendor.
>> 
>>  I don't see any formats at all in the Vulkan specification which put
>> the
>>  value at the low end of a containing word, but I might not be
>> looking in
>>  the right place?
>> 
>>  - Mark
>> 
>> 
>>  (Vaguely related, because it made me look it up, it appears that the
>>  device will always match host-endianness:
>> 
>>  After talking about the numeric types,
>>  """
>>  The representation and endianness of these types on the host must
>> match
>>  the representation and endianness of the same types on every physical
>>  device supported."
>>  """
>> 
>>  I don't know what that actually means for little-endian graphics
>> cards
>>  (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan
>> just
>>  doesn't support that, or maybe the driver can fix it up somehow -
>> but we
>>  don't need to think about it at all.)
>> >>>
>> >>> Something's weird:
>> >>>
>> >>>
>> >> Sorry, pushed the wrong button.
>> >>
>> >> For this filter chain:
>> >> format=,hwupload,scale_vulkan=w=1024:h=-1:format
>> =rgba,hwdownload,format=rgba
>> >>
>> >> This is what happens for each SRC_FORMAT:
>> >> NVIDIA 960M with binary drivers:
>> >> p010 - works fine
>> >> yuv420p10le - mostly green screen with some minor variations, enough to
>> >> make out the original video
>> >> yuv420p10be - works fine
>> >>
>> >> Intel 530:
>> >> p010 - works fine
>> >> yuv420p10le - works fine
>> >> yuv420p10be - works fine
>> >>
>> >> I'm not entirely sure what to make of that. How does the intel deal
>> with
>> >> formats with different endianess when there's no way to indicate
>> endianess
>> >> at all? Why does nvidia deal with big endian when you said its little
>> >> endian?
>> >
>> > hwupload checks the supported formats with get_constraints and only
>> exposes the supported ones to lavfi query_formats.  Probably some
>> auto-conversion is happening for the big-endian formats?  Maybe on Intel
>> the three-plane format also isn't supported, and so auto-conversion happens
>> there too?
>> >
>> > I think the green screen is what we would expect from the above
>> analysis, since all you would be getting is the high 4 bits of each
>> component in the low 4 bits of the output.
>>
>> Assuming that by Intel you mean Mesa rather than 

Re: [FFmpeg-devel] avcodec/prores_ks : use official quant matrix

2018-04-22 Thread Martin Vignali
2018-04-14 11:31 GMT+02:00 Martin Vignali :

>
> >
>> > For the proxy chroma version is also the same matrix use in prores_aw
>>
>> Patch is OK then, assumming FATE still passes.
>>
>>
>> Ok thanks for comments.
> It passes fate test for me (but prores_ks have few fate test !)
>
> I will wait few days, if someone else have comments, before apply.
>
> Martin
>
> Pushed, Thanks

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


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Rostislav Pehlivanov
On 22 April 2018 at 17:51, Mark Thompson  wrote:

> On 22/04/18 17:36, Mark Thompson wrote:
> > On 22/04/18 17:28, Rostislav Pehlivanov wrote:
> >> On 22 April 2018 at 17:21, Rostislav Pehlivanov 
> wrote:
> >>> On 22 April 2018 at 12:46, Mark Thompson  wrote:
>  On 21/04/18 23:29, Carl Eugen Hoyos wrote:
> > 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov <
> atomnu...@gmail.com>:
> >> On 21 April 2018 at 21:24, Carl Eugen Hoyos 
>  wrote:
> >>
> >>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov <
> atomnu...@gmail.com
> > :
> >>>
>  +[AV_PIX_FMT_P010]  =
>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
> >>>
>  +[AV_PIX_FMT_YUV420P10] =
>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
> >>>
> >>> I don't think both can be correct (unless "PACK16" has no meaning).
> >
> >> They're both correct and work.
> >
> > That's really strange...
> > (Could this be a bug in the driver?)
> 
>  Sounds like it must be a bug somewhere.
> 
>  The Vulkan specification says:
> 
>  """
>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a
> unsigned
>  normalized multi-planar format that has a 10-bit G component in the
> top 10
>  bits of each 16-bit word of plane 0, and a two-component, 32-bit BR
> plane 1
>  consisting of a 10-bit B component in the top 10 bits of the word in
> bytes
>  0..1, and a 10-bit R component in the top 10 bits of the word in bytes
>  2..3, the bottom 6 bits of each word set to 0.
> 
>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a
>  unsigned normalized multi-planar format that has a 10-bit G component
> in
>  the top 10 bits of each 16-bit word of plane 0, a 10-bit B component
> in the
>  top 10 bits of each 16-bit word of plane 1, and a 10-bit R component
> in the
>  top 10 bits of each 16-bit word of plane 2, with the bottom 6 bits of
> each
>  word set to 0.
>  """
> 
>  Which I think makes it pretty clear that VK_FORMAT_G10X6_B10X6R10X6_
> 2PLANE_420_UNORM_3PACK16
>  is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_
> 3PLANE_420_UNORM_3PACK16
>  isn't YUV420P10 because they pack the 10 bits at different ends of the
>  16-bit value.  If a driver is getting that wrong then it should be
> reported
>  to the vendor.
> 
>  I don't see any formats at all in the Vulkan specification which put
> the
>  value at the low end of a containing word, but I might not be looking
> in
>  the right place?
> 
>  - Mark
> 
> 
>  (Vaguely related, because it made me look it up, it appears that the
>  device will always match host-endianness:
> 
>  After talking about the numeric types,
>  """
>  The representation and endianness of these types on the host must
> match
>  the representation and endianness of the same types on every physical
>  device supported."
>  """
> 
>  I don't know what that actually means for little-endian graphics cards
>  (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan
> just
>  doesn't support that, or maybe the driver can fix it up somehow - but
> we
>  don't need to think about it at all.)
> >>>
> >>> Something's weird:
> >>>
> >>>
> >> Sorry, pushed the wrong button.
> >>
> >> For this filter chain:
> >> format=,hwupload,scale_vulkan=w=1024:h=-1:
> format=rgba,hwdownload,format=rgba
> >>
> >> This is what happens for each SRC_FORMAT:
> >> NVIDIA 960M with binary drivers:
> >> p010 - works fine
> >> yuv420p10le - mostly green screen with some minor variations, enough to
> >> make out the original video
> >> yuv420p10be - works fine
> >>
> >> Intel 530:
> >> p010 - works fine
> >> yuv420p10le - works fine
> >> yuv420p10be - works fine
> >>
> >> I'm not entirely sure what to make of that. How does the intel deal with
> >> formats with different endianess when there's no way to indicate
> endianess
> >> at all? Why does nvidia deal with big endian when you said its little
> >> endian?
> >
> > hwupload checks the supported formats with get_constraints and only
> exposes the supported ones to lavfi query_formats.  Probably some
> auto-conversion is happening for the big-endian formats?  Maybe on Intel
> the three-plane format also isn't supported, and so auto-conversion happens
> there too?
> >
> > I think the green screen is what we would expect from the above
> analysis, since all you would be getting is the high 4 bits of each
> component in the low 4 bits of the output.
>
> Assuming that by Intel you mean Mesa rather than Windows blob, <
> https://cgit.freedesktop.org/mesa/mesa/tree/src/intel/
> vulkan/anv_formats.c#n329> says that none of these formats are supported
> (P010 or YUV420P10).  On that driver it would be converting to something
> else in 

[FFmpeg-devel] [PATCH v2 7/8] lavfi: add a Vulkan scale filter

2018-04-22 Thread Rostislav Pehlivanov
Can convert to RGB using very fast fixed-function conversions.

Signed-off-by: Rostislav Pehlivanov 
---
 configure |   1 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_scale_vulkan.c | 386 ++
 4 files changed, 389 insertions(+)
 create mode 100644 libavfilter/vf_scale_vulkan.c

diff --git a/configure b/configure
index 85b6e4ba3c..19a231104e 100755
--- a/configure
+++ b/configure
@@ -3410,6 +3410,7 @@ zmq_filter_deps="libzmq"
 zoompan_filter_deps="swscale"
 zscale_filter_deps="libzimg const_nan"
 scale_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
+scale_vulkan_filter_deps="vulkan libshaderc"
 vpp_qsv_filter_deps="libmfx"
 vpp_qsv_filter_select="qsvvpp"
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 14438ef81a..83a42563f5 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -309,6 +309,7 @@ OBJS-$(CONFIG_SCALE_CUDA_FILTER) += 
vf_scale_cuda.o vf_scale_cuda.pt
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
 OBJS-$(CONFIG_SCALE_QSV_FILTER)  += vf_scale_qsv.o
 OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o scale.o 
vaapi_vpp.o
+OBJS-$(CONFIG_SCALE_VULKAN_FILTER)   += vf_scale_vulkan.o scale.o 
vulkan.o
 OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
 OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
 OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9e4fdedfda..31966e9a21 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -300,6 +300,7 @@ extern AVFilter ff_vf_scale_cuda;
 extern AVFilter ff_vf_scale_npp;
 extern AVFilter ff_vf_scale_qsv;
 extern AVFilter ff_vf_scale_vaapi;
+extern AVFilter ff_vf_scale_vulkan;
 extern AVFilter ff_vf_scale2ref;
 extern AVFilter ff_vf_select;
 extern AVFilter ff_vf_selectivecolor;
diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c
new file mode 100644
index 00..5bcdc0b3d8
--- /dev/null
+++ b/libavfilter/vf_scale_vulkan.c
@@ -0,0 +1,386 @@
+/*
+ * 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/opt.h"
+#include "vulkan.h"
+#include "scale.h"
+#include "internal.h"
+
+enum ScalerFunc {
+F_BILINEAR = 0,
+F_NEAREST,
+
+F_NB,
+};
+
+typedef struct ScaleVulkanContext {
+VulkanFilterContext vkctx;
+
+int initialized;
+FFVkExecContext exec;
+const VulkanSampler *sampler;
+
+/* Shader updators, must be in the main filter struct */
+VkDescriptorImageInfo input_images[3];
+VkDescriptorImageInfo output_images[3];
+
+enum ScalerFunc scaler;
+char *output_format_string;
+char *w_expr;
+char *h_expr;
+} ScaleVulkanContext;
+
+static const char scale_bilinear[] = {
+C(0, void scale_bilinear(int idx, ivec2 pos)   
)
+C(0, { 
)
+C(1, const vec2 npos = (vec2(pos) + 0.5f) / 
imageSize(output_img[idx]);)
+C(1, imageStore(output_img[idx], pos, texture(input_img[idx], npos));  
)
+C(0, } 
)
+};
+
+static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
+{
+int err;
+ScaleVulkanContext *s = ctx->priv;
+const int conv = s->vkctx.input_format != s->vkctx.output_format;
+VkFilter sampler_mode;
+
+switch (s->scaler) {
+case F_NEAREST:
+sampler_mode = VK_FILTER_NEAREST;
+break;
+case F_BILINEAR:
+sampler_mode = VK_FILTER_LINEAR;
+break;
+};
+
+/* Create a sampler */
+s->sampler = ff_vk_init_sampler(ctx, conv ? in : NULL, 0, sampler_mode);
+if (!s->sampler)
+return AVERROR_EXTERNAL;
+
+{ /* Create the shader */
+SPIRVShader *shd = ff_vk_init_shader(ctx, "scale_compute",
+ VK_SHADER_STAGE_COMPUTE_BIT);
+ff_vk_set_compute_shader_sizes(ctx, shd, (int [3]){ 16, 16, 1 });
+
+VulkanDescriptorSetBinding desc_i[2] = {
+{
+.name   = "input_img",

[FFmpeg-devel] [PATCH v2 5/8] lavfi: add a Vulkan avgblur filter

2018-04-22 Thread Rostislav Pehlivanov
Signed-off-by: Rostislav Pehlivanov 
---
 configure   |   1 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_avgblur_vulkan.c | 343 
 4 files changed, 346 insertions(+)
 create mode 100644 libavfilter/vf_avgblur_vulkan.c

diff --git a/configure b/configure
index b9bda095d3..3b41020a02 100755
--- a/configure
+++ b/configure
@@ -3299,6 +3299,7 @@ ass_filter_deps="libass"
 atempo_filter_deps="avcodec"
 atempo_filter_select="rdft"
 avgblur_opencl_filter_deps="opencl"
+avgblur_vulkan_filter_deps="vulkan libshaderc"
 azmq_filter_deps="libzmq"
 blackframe_filter_deps="gpl"
 boxblur_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index ed726d17bd..7bcbbac4a6 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -143,6 +143,7 @@ OBJS-$(CONFIG_ATADENOISE_FILTER) += 
vf_atadenoise.o
 OBJS-$(CONFIG_AVGBLUR_FILTER)+= vf_avgblur.o
 OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
 opencl/avgblur.o
+OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o
 OBJS-$(CONFIG_BBOX_FILTER)   += bbox.o vf_bbox.o
 OBJS-$(CONFIG_BENCH_FILTER)  += f_bench.o
 OBJS-$(CONFIG_BITPLANENOISE_FILTER)  += vf_bitplanenoise.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 643eec287d..bd09e74faa 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -136,6 +136,7 @@ extern AVFilter ff_vf_ass;
 extern AVFilter ff_vf_atadenoise;
 extern AVFilter ff_vf_avgblur;
 extern AVFilter ff_vf_avgblur_opencl;
+extern AVFilter ff_vf_avgblur_vulkan;
 extern AVFilter ff_vf_bbox;
 extern AVFilter ff_vf_bench;
 extern AVFilter ff_vf_bitplanenoise;
diff --git a/libavfilter/vf_avgblur_vulkan.c b/libavfilter/vf_avgblur_vulkan.c
new file mode 100644
index 00..dc913ed60f
--- /dev/null
+++ b/libavfilter/vf_avgblur_vulkan.c
@@ -0,0 +1,343 @@
+/*
+ * 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/opt.h"
+#include "vulkan.h"
+#include "internal.h"
+
+typedef struct AvgBlurVulkanContext {
+VulkanFilterContext vkctx;
+
+int initialized;
+FFVkExecContext exec;
+
+/* Shader updators, must be in the main filter struct */
+VkDescriptorImageInfo input_images[3];
+VkDescriptorImageInfo output_images[3];
+
+int size_x;
+int size_y;
+int planes;
+} AvgBlurVulkanContext;
+
+static const char blur_kernel[] = {
+C(0, #define CACHE_SIZE (ivec2(gl_WorkGroupSize) + FILTER_RADIUS*2)
)
+C(0, shared vec4 cache[AREA(CACHE_SIZE)];  
)
+C(0,   
)
+C(0, void blur_kernel(int idx, ivec2 pos)  
)
+C(0, { 
)
+C(1, ivec2 d;  
)
+C(1, const ivec2 s = CACHE_SIZE;   
)
+C(1, const ivec2 w = ivec2(gl_WorkGroupSize);  
)
+C(1, const ivec2 l = ivec2(gl_LocalInvocationID.xy);   
)
+C(1,   
)
+C(1, for (d.y = l.y; d.y < s.y; d.y += w.y) {  
)
+C(2, for (d.x = l.x; d.x < s.x; d.x += w.x) {  
)
+C(3, const ivec2 np = pos + d - l - FILTER_RADIUS; 
)
+C(3, cache[d.y*s.x + d.x] = imageLoad(input_img[idx], np); 
)
+C(2, } 
)
+C(1, } 
)
+C(0,   
)
+C(1, barrier();
)
+C(0,   
)
+C(1, vec4 avg = vec4(0.0f);
)
+

[FFmpeg-devel] [PATCH v2 8/8] lavfi: add a Vulkan overlay filter

2018-04-22 Thread Rostislav Pehlivanov
Could be done in-plane with the main image but framesync segfaults.

Signed-off-by: Rostislav Pehlivanov 
---
 configure   |   1 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_overlay_vulkan.c | 458 
 4 files changed, 461 insertions(+)
 create mode 100644 libavfilter/vf_overlay_vulkan.c

diff --git a/configure b/configure
index 19a231104e..93000a3a4c 100755
--- a/configure
+++ b/configure
@@ -3354,6 +3354,7 @@ ocr_filter_deps="libtesseract"
 ocv_filter_deps="libopencv"
 openclsrc_filter_deps="opencl"
 overlay_opencl_filter_deps="opencl"
+overlay_vulkan_filter_deps="vulkan libshaderc"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 owdenoise_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 83a42563f5..0b858ac917 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -272,6 +272,7 @@ OBJS-$(CONFIG_OSCILLOSCOPE_FILTER)   += 
vf_datascope.o
 OBJS-$(CONFIG_OVERLAY_FILTER)+= vf_overlay.o framesync.o
 OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \
 opencl/overlay.o framesync.o
+OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 31966e9a21..8016fed36c 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -263,6 +263,7 @@ extern AVFilter ff_vf_ocv;
 extern AVFilter ff_vf_oscilloscope;
 extern AVFilter ff_vf_overlay;
 extern AVFilter ff_vf_overlay_opencl;
+extern AVFilter ff_vf_overlay_vulkan;
 extern AVFilter ff_vf_overlay_qsv;
 extern AVFilter ff_vf_owdenoise;
 extern AVFilter ff_vf_pad;
diff --git a/libavfilter/vf_overlay_vulkan.c b/libavfilter/vf_overlay_vulkan.c
new file mode 100644
index 00..549e84e308
--- /dev/null
+++ b/libavfilter/vf_overlay_vulkan.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
+ * 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/opt.h"
+#include "vulkan.h"
+#include "internal.h"
+#include "framesync.h"
+
+typedef struct OverlayVulkanContext {
+VulkanFilterContext vkctx;
+
+int initialized;
+FFVkExecContext exec;
+FFFrameSync fs;
+FFVkBuffer params_buf;
+
+/* Shader updators, must be in the main filter struct */
+VkDescriptorImageInfo main_images[3];
+VkDescriptorImageInfo overlay_images[3];
+VkDescriptorImageInfo output_images[3];
+VkDescriptorBufferInfo params_desc;
+
+int overlay_x;
+int overlay_y;
+} OverlayVulkanContext;
+
+static const char overlay_noalpha[] = {
+C(0, void overlay_noalpha(int i, ivec2 pos)
)
+C(0, { 
)
+C(1, ivec2 overlay_size = imageSize(overlay_img[i]);   
)
+C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
+ (pos.x < (o_offset[i].x + overlay_size.x)) &&
+ (pos.y < (o_offset[i].y + overlay_size.y))) { 
)
+C(2, vec4 res = imageLoad(overlay_img[i], pos - o_offset[i]);  
)
+C(2, imageStore(output_img[i], pos, res);  
)
+C(1, } else {  
)
+C(2, vec4 res = imageLoad(main_img[i], pos);   
)
+C(2, imageStore(output_img[i], pos, res);  
)
+C(1, } 
)
+C(0, } 
)
+};
+
+static av_cold int init_filter(AVFilterContext *ctx)
+{
+int err;
+OverlayVulkanContext *s = ctx->priv;
+
+{ /* Create the shader */
+const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
+
+SPIRVShader *shd = ff_vk_init_shader(ctx, "overlay_compute",
+

[FFmpeg-devel] [PATCH v2 1/8] hwcontext_internal: add ff_hwframe_map_replace

2018-04-22 Thread Rostislav Pehlivanov
Used to fix unmapping when no direct interop exists between APIs.

Signed-off-by: Rostislav Pehlivanov 
---
 libavutil/hwcontext.c  | 7 +++
 libavutil/hwcontext_internal.h | 5 +
 2 files changed, 12 insertions(+)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 70c556ecac..f9ce2f5b13 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -871,3 +871,10 @@ fail:
 av_buffer_unref(_ref);
 return ret;
 }
+
+int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
+{
+HWMapDescriptor *hwmap = (HWMapDescriptor*)dst->buf[0]->data;
+av_frame_unref(hwmap->source);
+return av_frame_ref(hwmap->source, src);
+}
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 332062ddaa..77dc47ddd6 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -156,6 +156,11 @@ int ff_hwframe_map_create(AVBufferRef *hwframe_ref,
 HWMapDescriptor *hwmap),
   void *priv);
 
+/**
+ * Replace the current hwmap of dst with the one from src, used for indirect
+ * mappings like VAAPI->(DRM)->OpenCL/Vulkan where a direct interop is missing
+ */
+int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src);
 
 extern const HWContextType ff_hwcontext_type_cuda;
 extern const HWContextType ff_hwcontext_type_d3d11va;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH v2 4/8] lavfi: add common Vulkan filtering code

2018-04-22 Thread Rostislav Pehlivanov
This commit adds a common code for use in Vulkan filters. It attempts
to ease the burden of writing Vulkan image filtering to a minimum,
which is pretty much a requirement considering how verbose the API is.

It supports both compute and graphic pipelines and manages to abstract
the API to such a level there's no need to call any Vulkan functions
inside the init path of the code. Handling shader descriptors is probably
the bulk of the code, and despite the abstraction, it loses none of the
features for describing shader IO.

In order to produce linkable shaders, it depends on the libshaderc
library (and depends on the latest stable version of it). This allows
for greater performance and flexibility than static built-in shaders
and also eliminates the cumbersome process of interfacing with glslang
to compile GLSL to SPIR-V.

It's based off of the common opencl and provides similar interfaces for
filter pad init and config, with the addition that it also supports
in-place filtering.

Signed-off-by: Rostislav Pehlivanov 
---
 configure|   10 +-
 libavfilter/vulkan.c | 1450 ++
 libavfilter/vulkan.h |  234 +++
 3 files changed, 1693 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/vulkan.c
 create mode 100644 libavfilter/vulkan.h

diff --git a/configure b/configure
index 59dd3f85fc..b9bda095d3 100755
--- a/configure
+++ b/configure
@@ -252,6 +252,7 @@ External library support:
   --enable-librsvg enable SVG rasterization via librsvg [no]
   --enable-librubberband   enable rubberband needed for rubberband filter [no]
   --enable-librtmp enable RTMP[E] support via librtmp [no]
+  --enable-libshaderc  enable GLSL->SPIRV compilation via libshaderc [no]
   --enable-libshineenable fixed-point MP3 encoding via libshine [no]
   --enable-libsmbclientenable Samba protocol via libsmbclient [no]
   --enable-libsnappy   enable Snappy compression, needed for hap encoding 
[no]
@@ -1702,6 +1703,7 @@ EXTERNAL_LIBRARY_LIST="
 libpulse
 librsvg
 librtmp
+libshaderc
 libshine
 libsmbclient
 libsnappy
@@ -2219,6 +2221,7 @@ HAVE_LIST="
 opencl_dxva2
 opencl_vaapi_beignet
 opencl_vaapi_intel_media
+shaderc_opt_perf
 vulkan_drm_mod
 perl
 pod2man
@@ -3449,7 +3452,7 @@ avformat_deps="avcodec avutil"
 avformat_suggest="libm network zlib"
 avresample_deps="avutil"
 avresample_suggest="libm"
-avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi 
videotoolbox corefoundation corevideo coremedia bcrypt"
+avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl vulkan 
libshaderc user32 vaapi videotoolbox corefoundation corevideo coremedia bcrypt"
 postproc_deps="avutil gpl"
 postproc_suggest="libm"
 swresample_deps="avutil"
@@ -6029,6 +6032,7 @@ enabled libpulse  && require_pkg_config libpulse 
libpulse pulse/pulseaud
 enabled librsvg   && require_pkg_config librsvg librsvg-2.0 
librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
 enabled librtmp   && require_pkg_config librtmp librtmp librtmp/rtmp.h 
RTMP_Socket
 enabled librubberband && require_pkg_config librubberband "rubberband >= 
1.8.1" rubberband/rubberband-c.h rubberband_new -lstdc++ && append 
librubberband_extralibs "-lstdc++"
+enabled libshaderc&& require libshaderc shaderc/shaderc.h 
shaderc_compiler_initialize -lshaderc_shared
 enabled libshine  && require_pkg_config libshine shine shine/layer3.h 
shine_encode_buffer
 enabled libsmbclient  && { check_pkg_config libsmbclient smbclient 
libsmbclient.h smbc_init ||
require libsmbclient libsmbclient.h smbc_init 
-lsmbclient; }
@@ -6328,6 +6332,10 @@ enabled crystalhd && check_lib crystalhd "stdint.h 
libcrystalhd/libcrystalhd_if.
 enabled vulkan &&
 check_pkg_config vulkan "vulkan >= 1.1.73" "vulkan/vulkan.h" 
vkCreateInstance
 
+if enabled_all vulkan libshaderc ; then
+check_cc shaderc_opt_perf shaderc/shaderc.h "int t = 
shaderc_optimization_level_performance"
+fi
+
 if enabled_all vulkan libdrm ; then
 check_cpp_condition vulkan_drm_mod vulkan/vulkan.h "defined 
VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME"
 fi
diff --git a/libavfilter/vulkan.c b/libavfilter/vulkan.c
new file mode 100644
index 00..4266791618
--- /dev/null
+++ b/libavfilter/vulkan.c
@@ -0,0 +1,1450 @@
+/*
+ * Vulkan utilities
+ * Copyright (c) 2018 Rostislav Pehlivanov 
+ *
+ * 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 

[FFmpeg-devel] [PATCH v2 2/8] hwcontext_opencl: use ff_hwframe_map_replace()

2018-04-22 Thread Rostislav Pehlivanov
Signed-off-by: Rostislav Pehlivanov 
---
 libavutil/hwcontext_opencl.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 43b5c5ae0c..1d18da37bf 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -2171,10 +2171,7 @@ static int opencl_map_from_vaapi(AVHWFramesContext 
*dst_fc,
 if (err < 0)
 goto fail;
 
-// Adjust the map descriptor so that unmap works correctly.
-hwmap = (HWMapDescriptor*)dst->buf[0]->data;
-av_frame_unref(hwmap->source);
-err = av_frame_ref(hwmap->source, src);
+err = ff_hwframe_map_replace(dst, src);
 
 fail:
 av_frame_free();
-- 
2.17.0

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


[FFmpeg-devel] [PATCH v2 0/8] Vulkan mapping and filtering infrastructure

2018-04-22 Thread Rostislav Pehlivanov
The plan is to eventually be able to apply effects and encode entirely
on the GPU.

Rostislav Pehlivanov (8):
  hwcontext_internal: add ff_hwframe_map_replace
  hwcontext_opencl: use ff_hwframe_map_replace()
  lavu: add a Vulkan hwcontext
  lavfi: add common Vulkan filtering code
  lavfi: add a Vulkan avgblur filter
  lavfi: add a Vulkan chromatic aberration filter
  lavfi: add a Vulkan scale filter
  lavfi: add a Vulkan overlay filter

 configure   |   24 +-
 doc/APIchanges  |3 +
 libavfilter/Makefile|4 +
 libavfilter/allfilters.c|4 +
 libavfilter/vf_avgblur_vulkan.c |  343 +++
 libavfilter/vf_chromaticaberration_vulkan.c |  342 +++
 libavfilter/vf_overlay_vulkan.c |  458 
 libavfilter/vf_scale_vulkan.c   |  386 
 libavfilter/vulkan.c| 1450 +
 libavfilter/vulkan.h|  234 ++
 libavutil/Makefile  |3 +
 libavutil/hwcontext.c   |   11 +
 libavutil/hwcontext.h   |1 +
 libavutil/hwcontext_internal.h  |6 +
 libavutil/hwcontext_opencl.c|5 +-
 libavutil/hwcontext_vulkan.c| 2125 +++
 libavutil/hwcontext_vulkan.h|  133 ++
 libavutil/pixdesc.c |4 +
 libavutil/pixfmt.h  |4 +
 libavutil/version.h |2 +-
 20 files changed, 5536 insertions(+), 6 deletions(-)
 create mode 100644 libavfilter/vf_avgblur_vulkan.c
 create mode 100644 libavfilter/vf_chromaticaberration_vulkan.c
 create mode 100644 libavfilter/vf_overlay_vulkan.c
 create mode 100644 libavfilter/vf_scale_vulkan.c
 create mode 100644 libavfilter/vulkan.c
 create mode 100644 libavfilter/vulkan.h
 create mode 100644 libavutil/hwcontext_vulkan.c
 create mode 100644 libavutil/hwcontext_vulkan.h

-- 
2.17.0

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


[FFmpeg-devel] [PATCH v2 6/8] lavfi: add a Vulkan chromatic aberration filter

2018-04-22 Thread Rostislav Pehlivanov
It tries to do something similar to it with YUV images, but RGB images
are done properly.

Signed-off-by: Rostislav Pehlivanov 
---
 configure   |   1 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_chromaticaberration_vulkan.c | 342 
 4 files changed, 345 insertions(+)
 create mode 100644 libavfilter/vf_chromaticaberration_vulkan.c

diff --git a/configure b/configure
index 3b41020a02..85b6e4ba3c 100755
--- a/configure
+++ b/configure
@@ -3304,6 +3304,7 @@ azmq_filter_deps="libzmq"
 blackframe_filter_deps="gpl"
 boxblur_filter_deps="gpl"
 bs2b_filter_deps="libbs2b"
+chromaticaberration_vulkan_filter_deps="vulkan libshaderc"
 colormatrix_filter_deps="gpl"
 convolution_opencl_filter_deps="opencl"
 convolve_filter_deps="avcodec"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7bcbbac4a6..14438ef81a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -153,6 +153,7 @@ OBJS-$(CONFIG_BLEND_FILTER)  += vf_blend.o 
framesync.o
 OBJS-$(CONFIG_BOXBLUR_FILTER)+= vf_boxblur.o
 OBJS-$(CONFIG_BWDIF_FILTER)  += vf_bwdif.o
 OBJS-$(CONFIG_CHROMAKEY_FILTER)  += vf_chromakey.o
+OBJS-$(CONFIG_CHROMATICABERRATION_VULKAN_FILTER) += 
vf_chromaticaberration_vulkan.o vulkan.o
 OBJS-$(CONFIG_CIESCOPE_FILTER)   += vf_ciescope.o
 OBJS-$(CONFIG_CODECVIEW_FILTER)  += vf_codecview.o
 OBJS-$(CONFIG_COLORBALANCE_FILTER)   += vf_colorbalance.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index bd09e74faa..9e4fdedfda 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -146,6 +146,7 @@ extern AVFilter ff_vf_blend;
 extern AVFilter ff_vf_boxblur;
 extern AVFilter ff_vf_bwdif;
 extern AVFilter ff_vf_chromakey;
+extern AVFilter ff_vf_chromaticaberration_vulkan;
 extern AVFilter ff_vf_ciescope;
 extern AVFilter ff_vf_codecview;
 extern AVFilter ff_vf_colorbalance;
diff --git a/libavfilter/vf_chromaticaberration_vulkan.c 
b/libavfilter/vf_chromaticaberration_vulkan.c
new file mode 100644
index 00..e814d2442b
--- /dev/null
+++ b/libavfilter/vf_chromaticaberration_vulkan.c
@@ -0,0 +1,342 @@
+/*
+ * 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/opt.h"
+#include "vulkan.h"
+#include "internal.h"
+
+typedef struct ChromaticAberrationVulkanContext {
+VulkanFilterContext vkctx;
+
+int initialized;
+FFVkExecContext exec;
+
+/* Shader updators, must be in the main filter struct */
+VkDescriptorImageInfo input_images[3];
+VkDescriptorImageInfo output_images[3];
+
+float dist_x;
+float dist_y;
+} ChromaticAberrationVulkanContext;
+
+static const char distort_chroma_kernel[] = {
+C(0, void distort_rgb(ivec2 size, ivec2 pos)   
)
+C(0, { 
)
+C(1, const vec2 p = ((vec2(pos)/vec2(size)) - 0.5f)*2.0f;  
)
+C(1, const vec2 o = p * (FILTER_DIST - 1.0f);  
)
+C(0,   
)
+C(1, vec4 res; 
)
+C(1, res.r = texture(input_img[0], ((p - o)/2.0f) + 0.5f).r;   
)
+C(1, res.g = texture(input_img[0], ((p)/2.0f) + 0.5f).g;   
)
+C(1, res.b = texture(input_img[0], ((p + o)/2.0f) + 0.5f).b;   
)
+C(1, res.a = texture(input_img[0], ((p)/2.0f) + 0.5f).a;   
)
+C(1, imageStore(output_img[0], pos, res);  
)
+C(0, } 
)
+C(0,   
)
+C(0, void distort_chroma(int idx, ivec2 size, ivec2 pos)   
)
+C(0, { 
)
+C(1, vec2 p = ((vec2(pos)/vec2(size)) - 0.5f)*2.0f;
)
+C(1, float d = sqrt(p.x*p.x + p.y*p.y);
)
+C(1, p *= d 

[FFmpeg-devel] [PATCH v2 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Rostislav Pehlivanov
This commit adds a Vulkan hwcontext, currently capable of mapping DRM and
VAAPI frames but additional functionality can be added later to support
importing of D3D11 surfaces as well as exporting to various other APIs.

This context requires the newest stable version of the Vulkan API,
and once the new extension for DRM surfaces makes it in will also require
it (in order to properly and fully import them).

It makes use of every part of the Vulkan spec in order to ensure fastest
possible uploading, downloading and mapping of frames. On AMD, it will
also make use of mapping host memory frames in order to upload
very efficiently and with minimal CPU to hardware.

To be useful for non-RGB images an implementation with the YUV images
extension is needed. All current implementations support that with the
exception of AMD, though support is coming soon for Mesa.

Signed-off-by: Rostislav Pehlivanov 
---
 configure  |   10 +
 doc/APIchanges |3 +
 libavutil/Makefile |3 +
 libavutil/hwcontext.c  |4 +
 libavutil/hwcontext.h  |1 +
 libavutil/hwcontext_internal.h |1 +
 libavutil/hwcontext_vulkan.c   | 2125 
 libavutil/hwcontext_vulkan.h   |  133 ++
 libavutil/pixdesc.c|4 +
 libavutil/pixfmt.h |4 +
 libavutil/version.h|2 +-
 11 files changed, 2289 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_vulkan.c
 create mode 100644 libavutil/hwcontext_vulkan.h

diff --git a/configure b/configure
index dee507cb6a..59dd3f85fc 100755
--- a/configure
+++ b/configure
@@ -297,6 +297,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls or libtls is not used [no]
+  --enable-vulkan  enable Vulkan code [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1761,6 +1762,7 @@ HWACCEL_LIBRARY_LIST="
 mmal
 omx
 opencl
+vulkan
 "
 
 DOCUMENT_LIST="
@@ -2217,6 +2219,7 @@ HAVE_LIST="
 opencl_dxva2
 opencl_vaapi_beignet
 opencl_vaapi_intel_media
+vulkan_drm_mod
 perl
 pod2man
 texi2html
@@ -6322,6 +6325,13 @@ enabled vdpau &&
 
 enabled crystalhd && check_lib crystalhd "stdint.h 
libcrystalhd/libcrystalhd_if.h" DtsCrystalHDVersion -lcrystalhd
 
+enabled vulkan &&
+check_pkg_config vulkan "vulkan >= 1.1.73" "vulkan/vulkan.h" 
vkCreateInstance
+
+if enabled_all vulkan libdrm ; then
+check_cpp_condition vulkan_drm_mod vulkan/vulkan.h "defined 
VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME"
+fi
+
 if enabled x86; then
 case $target_os in
 mingw32*|mingw64*|win32|win64|linux|cygwin*)
diff --git a/doc/APIchanges b/doc/APIchanges
index 4f6ac2a031..05a28473d7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-04-xx - xx - lavu 56.16.100 - hwcontext.h
+  Add AV_HWDEVICE_TYPE_VULKAN and implementation.
+
  8< - FFmpeg 4.0 was cut here  8< -
 
 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
diff --git a/libavutil/Makefile b/libavutil/Makefile
index a63ba523c9..aa641d78ed 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -42,6 +42,7 @@ HEADERS = adler32.h   
  \
   hwcontext_vaapi.h \
   hwcontext_videotoolbox.h  \
   hwcontext_vdpau.h \
+  hwcontext_vulkan.h\
   imgutils.h\
   intfloat.h\
   intreadwrite.h\
@@ -168,6 +169,7 @@ OBJS-$(CONFIG_VAAPI)+= hwcontext_vaapi.o
 OBJS-$(CONFIG_VIDEOTOOLBOX) += hwcontext_videotoolbox.o
 OBJS-$(CONFIG_VDPAU)+= hwcontext_vdpau.o
 OBJS-$(CONFIG_MEDIACODEC)   += hwcontext_mediacodec.o
+OBJS-$(CONFIG_VULKAN)   += hwcontext_vulkan.o
 
 OBJS += $(COMPAT_OBJS:%=../compat/%)
 
@@ -183,6 +185,7 @@ SKIPHEADERS-$(CONFIG_OPENCL)   += hwcontext_opencl.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
 SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += hwcontext_videotoolbox.h
 SKIPHEADERS-$(CONFIG_VDPAU)+= hwcontext_vdpau.h
+SKIPHEADERS-$(CONFIG_VULKAN)   += hwcontext_vulkan.h
 
 TESTPROGS = adler32 \
 aes   

Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Mark Thompson
On 22/04/18 17:36, Mark Thompson wrote:
> On 22/04/18 17:28, Rostislav Pehlivanov wrote:
>> On 22 April 2018 at 17:21, Rostislav Pehlivanov  wrote:
>>> On 22 April 2018 at 12:46, Mark Thompson  wrote:
 On 21/04/18 23:29, Carl Eugen Hoyos wrote:
> 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov :
>> On 21 April 2018 at 21:24, Carl Eugen Hoyos 
 wrote:
>>
>>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov  :
>>>
 +[AV_PIX_FMT_P010]  =
 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
>>>
 +[AV_PIX_FMT_YUV420P10] =
 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
>>>
>>> I don't think both can be correct (unless "PACK16" has no meaning).
>
>> They're both correct and work.
>
> That's really strange...
> (Could this be a bug in the driver?)

 Sounds like it must be a bug somewhere.

 The Vulkan specification says:

 """
 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a unsigned
 normalized multi-planar format that has a 10-bit G component in the top 10
 bits of each 16-bit word of plane 0, and a two-component, 32-bit BR plane 1
 consisting of a 10-bit B component in the top 10 bits of the word in bytes
 0..1, and a 10-bit R component in the top 10 bits of the word in bytes
 2..3, the bottom 6 bits of each word set to 0.

 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a
 unsigned normalized multi-planar format that has a 10-bit G component in
 the top 10 bits of each 16-bit word of plane 0, a 10-bit B component in the
 top 10 bits of each 16-bit word of plane 1, and a 10-bit R component in the
 top 10 bits of each 16-bit word of plane 2, with the bottom 6 bits of each
 word set to 0.
 """

 Which I think makes it pretty clear that 
 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
 is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16
 isn't YUV420P10 because they pack the 10 bits at different ends of the
 16-bit value.  If a driver is getting that wrong then it should be reported
 to the vendor.

 I don't see any formats at all in the Vulkan specification which put the
 value at the low end of a containing word, but I might not be looking in
 the right place?

 - Mark


 (Vaguely related, because it made me look it up, it appears that the
 device will always match host-endianness:

 After talking about the numeric types,
 """
 The representation and endianness of these types on the host must match
 the representation and endianness of the same types on every physical
 device supported."
 """

 I don't know what that actually means for little-endian graphics cards
 (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan just
 doesn't support that, or maybe the driver can fix it up somehow - but we
 don't need to think about it at all.)
>>>
>>> Something's weird:
>>>
>>>
>> Sorry, pushed the wrong button.
>>
>> For this filter chain:
>> format=,hwupload,scale_vulkan=w=1024:h=-1:format=rgba,hwdownload,format=rgba
>>
>> This is what happens for each SRC_FORMAT:
>> NVIDIA 960M with binary drivers:
>> p010 - works fine
>> yuv420p10le - mostly green screen with some minor variations, enough to
>> make out the original video
>> yuv420p10be - works fine
>>
>> Intel 530:
>> p010 - works fine
>> yuv420p10le - works fine
>> yuv420p10be - works fine
>>
>> I'm not entirely sure what to make of that. How does the intel deal with
>> formats with different endianess when there's no way to indicate endianess
>> at all? Why does nvidia deal with big endian when you said its little
>> endian?
> 
> hwupload checks the supported formats with get_constraints and only exposes 
> the supported ones to lavfi query_formats.  Probably some auto-conversion is 
> happening for the big-endian formats?  Maybe on Intel the three-plane format 
> also isn't supported, and so auto-conversion happens there too?
> 
> I think the green screen is what we would expect from the above analysis, 
> since all you would be getting is the high 4 bits of each component in the 
> low 4 bits of the output.

Assuming that by Intel you mean Mesa rather than Windows blob, 

 says that none of these formats are supported (P010 or YUV420P10).  On that 
driver it would be converting to something else in software for all of them.

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


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Mark Thompson
On 22/04/18 17:28, Rostislav Pehlivanov wrote:
> On 22 April 2018 at 17:21, Rostislav Pehlivanov  wrote:
>> On 22 April 2018 at 12:46, Mark Thompson  wrote:
>>> On 21/04/18 23:29, Carl Eugen Hoyos wrote:
 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov :
> On 21 April 2018 at 21:24, Carl Eugen Hoyos 
>>> wrote:
>
>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov >
>>> +[AV_PIX_FMT_P010]  =
>>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
>>
>>> +[AV_PIX_FMT_YUV420P10] =
>>> VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
>>
>> I don't think both can be correct (unless "PACK16" has no meaning).

> They're both correct and work.

 That's really strange...
 (Could this be a bug in the driver?)
>>>
>>> Sounds like it must be a bug somewhere.
>>>
>>> The Vulkan specification says:
>>>
>>> """
>>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a unsigned
>>> normalized multi-planar format that has a 10-bit G component in the top 10
>>> bits of each 16-bit word of plane 0, and a two-component, 32-bit BR plane 1
>>> consisting of a 10-bit B component in the top 10 bits of the word in bytes
>>> 0..1, and a 10-bit R component in the top 10 bits of the word in bytes
>>> 2..3, the bottom 6 bits of each word set to 0.
>>>
>>> VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a
>>> unsigned normalized multi-planar format that has a 10-bit G component in
>>> the top 10 bits of each 16-bit word of plane 0, a 10-bit B component in the
>>> top 10 bits of each 16-bit word of plane 1, and a 10-bit R component in the
>>> top 10 bits of each 16-bit word of plane 2, with the bottom 6 bits of each
>>> word set to 0.
>>> """
>>>
>>> Which I think makes it pretty clear that 
>>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
>>> is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16
>>> isn't YUV420P10 because they pack the 10 bits at different ends of the
>>> 16-bit value.  If a driver is getting that wrong then it should be reported
>>> to the vendor.
>>>
>>> I don't see any formats at all in the Vulkan specification which put the
>>> value at the low end of a containing word, but I might not be looking in
>>> the right place?
>>>
>>> - Mark
>>>
>>>
>>> (Vaguely related, because it made me look it up, it appears that the
>>> device will always match host-endianness:
>>>
>>> After talking about the numeric types,
>>> """
>>> The representation and endianness of these types on the host must match
>>> the representation and endianness of the same types on every physical
>>> device supported."
>>> """
>>>
>>> I don't know what that actually means for little-endian graphics cards
>>> (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan just
>>> doesn't support that, or maybe the driver can fix it up somehow - but we
>>> don't need to think about it at all.)
>>
>> Something's weird:
>>
>>
> Sorry, pushed the wrong button.
> 
> For this filter chain:
> format=,hwupload,scale_vulkan=w=1024:h=-1:format=rgba,hwdownload,format=rgba
> 
> This is what happens for each SRC_FORMAT:
> NVIDIA 960M with binary drivers:
> p010 - works fine
> yuv420p10le - mostly green screen with some minor variations, enough to
> make out the original video
> yuv420p10be - works fine
> 
> Intel 530:
> p010 - works fine
> yuv420p10le - works fine
> yuv420p10be - works fine
> 
> I'm not entirely sure what to make of that. How does the intel deal with
> formats with different endianess when there's no way to indicate endianess
> at all? Why does nvidia deal with big endian when you said its little
> endian?

hwupload checks the supported formats with get_constraints and only exposes the 
supported ones to lavfi query_formats.  Probably some auto-conversion is 
happening for the big-endian formats?  Maybe on Intel the three-plane format 
also isn't supported, and so auto-conversion happens there too?

I think the green screen is what we would expect from the above analysis, since 
all you would be getting is the high 4 bits of each component in the low 4 bits 
of the output.

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


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Clément Bœsch
On Sun, Apr 22, 2018 at 12:33:14PM +0200, Marton Balint wrote:
> 
> 
> On Sun, 22 Apr 2018, Clément Bœsch wrote:
> 
> > On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
> > [...]
> > > I think av_thread_message_queue_elems would be a better name, had to think
> > > for a good period of time what "nelem" meant.
> > 
> > I'm afraid of "queue_elems" implying "queuing elements" so I went for
> > the more explicit av_thread_message_queue_nb_elems() instead.
> 
> I generally prefer nb_items instead of nb_elems. Use whichever you like.
> 

No personal opinion on this but the "element" semantic is already in use
in the API so I'd rather follow that.

-- 
Clément B.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Rostislav Pehlivanov
On 22 April 2018 at 17:21, Rostislav Pehlivanov  wrote:

>
>
> On 22 April 2018 at 12:46, Mark Thompson  wrote:
>
>> On 21/04/18 23:29, Carl Eugen Hoyos wrote:
>> > 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov :
>> >> On 21 April 2018 at 21:24, Carl Eugen Hoyos 
>> wrote:
>> >>
>> >>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov > >:
>> >>>
>>  +[AV_PIX_FMT_P010]  =
>>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
>> >>>
>>  +[AV_PIX_FMT_YUV420P10] =
>>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
>> >>>
>> >>> I don't think both can be correct (unless "PACK16" has no meaning).
>> >
>> >> They're both correct and work.
>> >
>> > That's really strange...
>> > (Could this be a bug in the driver?)
>>
>> Sounds like it must be a bug somewhere.
>>
>> The Vulkan specification says:
>>
>> """
>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a unsigned
>> normalized multi-planar format that has a 10-bit G component in the top 10
>> bits of each 16-bit word of plane 0, and a two-component, 32-bit BR plane 1
>> consisting of a 10-bit B component in the top 10 bits of the word in bytes
>> 0..1, and a 10-bit R component in the top 10 bits of the word in bytes
>> 2..3, the bottom 6 bits of each word set to 0.
>>
>> VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a
>> unsigned normalized multi-planar format that has a 10-bit G component in
>> the top 10 bits of each 16-bit word of plane 0, a 10-bit B component in the
>> top 10 bits of each 16-bit word of plane 1, and a 10-bit R component in the
>> top 10 bits of each 16-bit word of plane 2, with the bottom 6 bits of each
>> word set to 0.
>> """
>>
>> Which I think makes it pretty clear that 
>> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
>> is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16
>> isn't YUV420P10 because they pack the 10 bits at different ends of the
>> 16-bit value.  If a driver is getting that wrong then it should be reported
>> to the vendor.
>>
>> I don't see any formats at all in the Vulkan specification which put the
>> value at the low end of a containing word, but I might not be looking in
>> the right place?
>>
>> - Mark
>>
>>
>> (Vaguely related, because it made me look it up, it appears that the
>> device will always match host-endianness:
>>
>> After talking about the numeric types,
>> """
>> The representation and endianness of these types on the host must match
>> the representation and endianness of the same types on every physical
>> device supported."
>> """
>>
>> I don't know what that actually means for little-endian graphics cards
>> (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan just
>> doesn't support that, or maybe the driver can fix it up somehow - but we
>> don't need to think about it at all.)
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
> Something's weird:
>
>
Sorry, pushed the wrong button.

For this filter chain:
format=,hwupload,scale_vulkan=w=1024:h=-1:format=rgba,hwdownload,format=rgba

This is what happens for each SRC_FORMAT:
NVIDIA 960M with binary drivers:
p010 - works fine
yuv420p10le - mostly green screen with some minor variations, enough to
make out the original video
yuv420p10be - works fine

Intel 530:
p010 - works fine
yuv420p10le - works fine
yuv420p10be - works fine

I'm not entirely sure what to make of that. How does the intel deal with
formats with different endianess when there's no way to indicate endianess
at all? Why does nvidia deal with big endian when you said its little
endian?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Rostislav Pehlivanov
On 22 April 2018 at 12:46, Mark Thompson  wrote:

> On 21/04/18 23:29, Carl Eugen Hoyos wrote:
> > 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov :
> >> On 21 April 2018 at 21:24, Carl Eugen Hoyos  wrote:
> >>
> >>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov :
> >>>
>  +[AV_PIX_FMT_P010]  =
>  VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
> >>>
>  +[AV_PIX_FMT_YUV420P10] =
>  VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
> >>>
> >>> I don't think both can be correct (unless "PACK16" has no meaning).
> >
> >> They're both correct and work.
> >
> > That's really strange...
> > (Could this be a bug in the driver?)
>
> Sounds like it must be a bug somewhere.
>
> The Vulkan specification says:
>
> """
> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a unsigned
> normalized multi-planar format that has a 10-bit G component in the top 10
> bits of each 16-bit word of plane 0, and a two-component, 32-bit BR plane 1
> consisting of a 10-bit B component in the top 10 bits of the word in bytes
> 0..1, and a 10-bit R component in the top 10 bits of the word in bytes
> 2..3, the bottom 6 bits of each word set to 0.
>
> VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a unsigned
> normalized multi-planar format that has a 10-bit G component in the top 10
> bits of each 16-bit word of plane 0, a 10-bit B component in the top 10
> bits of each 16-bit word of plane 1, and a 10-bit R component in the top 10
> bits of each 16-bit word of plane 2, with the bottom 6 bits of each word
> set to 0.
> """
>
> Which I think makes it pretty clear that 
> VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
> is indeed P010 but VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16
> isn't YUV420P10 because they pack the 10 bits at different ends of the
> 16-bit value.  If a driver is getting that wrong then it should be reported
> to the vendor.
>
> I don't see any formats at all in the Vulkan specification which put the
> value at the low end of a containing word, but I might not be looking in
> the right place?
>
> - Mark
>
>
> (Vaguely related, because it made me look it up, it appears that the
> device will always match host-endianness:
>
> After talking about the numeric types,
> """
> The representation and endianness of these types on the host must match
> the representation and endianness of the same types on every physical
> device supported."
> """
>
> I don't know what that actually means for little-endian graphics cards
> (e.g. AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan just
> doesn't support that, or maybe the driver can fix it up somehow - but we
> don't need to think about it at all.)
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Something's weird:
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-22 Thread Mark Thompson
On 19/04/18 03:18, Song, Ruiling wrote:
>> Note that OpenCL <-> D3D11 won't work on AMD for normal video surfaces
>> (NV12) because there is no support for multiple-plane textures, so it's only 
>> going
>> to work with DXVA2 currently.  Intel has an extension
>> ("cl_intel_d3d11_nv12_media_sharing") which adds a simple hack overloading
>> the subresource index and therefore it is usable on Intel GPUs, but other 
>> vendors
>> don't have that.
> 
> For OpenCL NV12 support, I think we can use two separate images as arguments,
> one image for Y plane, and another image for UV plane.
> I think AMD OpenCL should support (CL_RG + CL_UNORM_INT8), right?
> So, we can get same behavior across different OpenCL vendors.

This is exactly what it does already, in a standard way with both DXVA2 and 
VAAPI - NV12 as R/UNORM_INT8 + RG/UNORM_INT8 is indeed usable for AMD on 
Windows with DXVA2 interop and via direct upload.

The problematic case is D3D11, because the standard cl_khr_d3d11_sharing 
extension does not support multiple-plane formats.  I would prefer that AMD has 
an OpenCL-only extension to do it like Intel does, but an alternative route 
using AMF to do the mapping isn't horrible (though it would be quite confusing 
if it isn't transparent to the user).

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


Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations

2018-04-22 Thread Mark Thompson
On 15/04/18 20:45, Alexander Kravchenko wrote:
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of 
>> Mark Thompson
>> Sent: Sunday, April 15, 2018 7:31 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious 
>> initialisations
>>
>>
>>> I am waiting patches to be applied to propose new patch with hwcontext_amf 
>>> in libavutil.
>>
>> Can you explain what you're intending to use that for?  It's not clear to me 
>> how an extra wrapper around the D3D(9|11) surfaces is
>> going to help, given that the support for them with AMF is already pretty 
>> good.  (Compare the Intel libmfx stuff (the misleadingly-
>> named "qsv") where the extra wrapping does help for some cases because the 
>> underlying library has weird constraints, but overall
>> adds a lot of complexity (and failure modes) for rather unclear benefit.  
>> It's also inconvenient in that it promotes the existence of
>> antifeatures like the "_qsv" decoders which are inferior to the builtin 
>> hwaccels in pretty much every respect.)
>>
> 
> Hi Mark,
> I am intending to create amf common helpers(tools) in libavutil. 
> They will be used in amfenc and vf_scaleamf. (vf_scaleamf is hw-accelerated 
> color-space converter and scaler)
> 
> amf helpers should provide:
> * amf_library: functions to load/unload amf dll based on reference count 
> mechanism
> * amf_context: functions to create AMFContext derived from DXVA2, D3D11, 
> opencl and Vulcan in future
> * av_frame <-> AMFSurface map functions (move from amfenc.c)
> 
> amfav_context can be implemented like hwdevice_ctx (AVAMFDeviceContext) and 
> can be managed by av_hwdevice_ctx_create_derived (in case of incoming hw 
> frames) and av_hwdevice_ctx_create or it can be implemented not using of 
> av_hwdevice_ctx* mechanism
> 
> I think don’t need AVAMFFrameContext, and amf components will send/receive 
> hwframes based on existing framecontexts (dxva/opencl...)
> 
> Could you recommend the best way how to do this fit in current architecture?

I agree that using a hwdevice context here makes sense, since it wraps all of 
the right properties (in particular, derivation from other devices).

It's less clear to me what to do with the frames.  A hwframes context could 
work just for derivation because you don't actually need to implement the 
allocation stuff (the existing DRM hwcontext does this, since it's only for 
interop).  What other approach would you think of taking?  Adding special 
external API to use internally between libraries is not nice and we try to 
avoid it quite strongly.

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


[FFmpeg-devel] [PATCH 25/26] lavc/h264: Add common code for level handling

2018-04-22 Thread Mark Thompson
Including a unit test.
---
 libavcodec/Makefile|   3 +-
 libavcodec/h264_levels.c   | 130 +
 libavcodec/h264_levels.h   |  53 
 libavcodec/tests/.gitignore|   1 +
 libavcodec/tests/h264_levels.c | 183 +
 tests/fate/libavcodec.mak  |   5 ++
 6 files changed, 374 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/h264_levels.c
 create mode 100644 libavcodec/h264_levels.h
 create mode 100644 libavcodec/tests/h264_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index be7466ce95..7241d08d52 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -352,7 +352,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
+OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += h264_levels.o 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
@@ -1128,6 +1128,7 @@ TESTPROGS-$(CONFIG_IDCTDSP)   += dct
 TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
 TESTPROGS-$(HAVE_MMX) += motion
 TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
+TESTPROGS-$(CONFIG_H264_VAAPI_ENCODER)+= h264_levels
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
new file mode 100644
index 00..594c8b50a0
--- /dev/null
+++ b/libavcodec/h264_levels.c
@@ -0,0 +1,130 @@
+/*
+ * 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 "avcodec.h"
+#include "h264_levels.h"
+
+// H.264 table A-1.
+static const H264LevelDescriptor h264_levels[] = {
+// Name  MaxMBPS   MaxBR  MinCR
+//  | level_idc |   MaxFS|MaxCPB| 
MaxMvsPer2Mb
+//  | | cs3f| |  MaxDpbMbs   |   |  MaxVmvR |   |
+{ "1.0", 10, 0, 1485, 99,396, 64,175,   64, 2,  0 },
+{ "1b",  10, 1, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1b",   9, 0, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1.1", 11, 0, 3000,396,900,192,500,  128, 2,  0 },
+{ "1.2", 12, 0, 6000,396,   2376,384,   1000,  128, 2,  0 },
+{ "1.3", 13, 0,11880,396,   2376,768,   2000,  128, 2,  0 },
+{ "2",   20, 0,11880,396,   2376,   2000,   2000,  128, 2,  0 },
+{ "2.1", 21, 0,19800,792,   4752,   4000,   4000,  256, 2,  0 },
+{ "2.2", 22, 0,20250,   1620,   8100,   4000,   4000,  256, 2,  0 },
+{ "3",   30, 0,40500,   1620,   8100,  1,  1,  256, 2, 32 },
+{ "3.1", 31, 0,   108000,   3600,  18000,  14000,  14000,  512, 4, 16 },
+{ "3.2", 32, 0,   216000,   5120,  20480,  2,  2,  512, 4, 16 },
+{ "4",   40, 0,   245760,   8192,  32768,  2,  25000,  512, 4, 16 },
+{ "4.1", 41, 0,   245760,   8192,  32768,  5,  62500,  512, 2, 16 },
+{ "4.2", 42, 0,   522240,   8704,  34816,  5,  62500,  512, 2, 16 },
+{ "5",   50, 0,   589824,  22080, 110400, 135000, 135000,  512, 2, 16 },
+{ "5.1", 51, 0,   983040,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "5.2", 52, 0,  2073600,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "6",   60, 0,  4177920, 139264, 696320, 24, 24, 8192, 2, 16 },
+{ "6.1", 61, 0,  8355840, 139264, 696320, 48, 48, 8192, 2, 16 },
+{ "6.2", 62, 0, 16711680, 139264, 696320, 80, 80, 8192, 2, 16 },
+};
+
+// H.264 table A-2 plus values from A-1.
+static const struct {
+int profile_idc;
+int cpb_br_vcl_factor;
+int cpb_br_nal_factor;
+} h264_br_factors[] = {
+{  66, 1000, 1200 },
+{  77, 1000, 1200 },
+{  88, 1000, 1200 },
+{ 100, 1250, 1500 },
+{ 110, 3000, 3600 },
+{ 122, 4000, 4800 },
+{ 244, 4000, 4800 },
+{  44, 4000, 4800 },
+};
+
+// 

[FFmpeg-devel] [PATCH 24/26] vaapi_encode_mjpeg: Use CBS to store parameters and write headers

2018-04-22 Thread Mark Thompson
Also adds 4:2:2, 4:4:4 and RGB support.
---
 doc/encoders.texi   |  17 +-
 libavcodec/vaapi_encode_mjpeg.c | 528 +---
 2 files changed, 345 insertions(+), 200 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index b451142cfb..ceddfdda64 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2662,8 +2662,21 @@ Include access unit delimiters in the stream (not 
included by default).
 @end table
 
 @item mjpeg_vaapi
-Always encodes using the standard quantisation and huffman tables -
-@option{global_quality} scales the standard quantisation table (range 1-100).
+Only baseline DCT encoding is supported.  The encoder always uses the standard
+quantisation and huffman tables - @option{global_quality} scales the standard
+quantisation table (range 1-100).
+
+For YUV, 4:2:0, 4:2:2 and 4:4:4 subsampling modes are supported.  RGB is also
+supported, and will create an RGB JPEG.
+
+@table @option
+@item jfif
+Include JFIF header in each frame (not included by default).
+@item huffman
+Include standard huffman tables (on by default).  Turning this off will save
+a few hundred bytes in each output frame, but may lose compatibility with some
+JPEG decoders which don't fully handle MJPEG.
+@end table
 
 @item mpeg2_vaapi
 @option{profile} and @option{level} set the value of 
@emph{profile_and_level_indication}.
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index f257ffc55b..d1325a69d2 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -23,9 +23,12 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
+#include "libavutil/pixdesc.h"
 
 #include "avcodec.h"
+#include "bytestream.h"
+#include "cbs.h"
+#include "cbs_jpeg.h"
 #include "internal.h"
 #include "jpegtables.h"
 #include "mjpeg.h"
@@ -58,253 +61,346 @@ static const unsigned char 
vaapi_encode_mjpeg_quant_chrominance[64] = {
 typedef struct VAAPIEncodeMJPEGContext {
 VAAPIEncodeContext common;
 
+// User options.
+int jfif;
+int huffman;
+
+// Derived settings.
 int quality;
-int component_subsample_h[3];
-int component_subsample_v[3];
+uint8_t jfif_data[14];
+
+// Writer structures.
+JPEGRawFrameHeader frame_header;
+JPEGRawScanscan;
+JPEGRawApplicationData jfif_header;
+JPEGRawQuantisationTableSpecification quant_tables;
+JPEGRawHuffmanTableSpecification  huffman_tables;
 
-VAQMatrixBufferJPEG quant_tables;
-VAHuffmanTableBufferJPEGBaseline huffman_tables;
+CodedBitstreamContext *cbc;
+CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMJPEGContext;
 
-static av_cold void vaapi_encode_mjpeg_copy_huffman(unsigned char *dst_lengths,
-unsigned char *dst_values,
-const unsigned char 
*src_lengths,
-const unsigned char 
*src_values)
+static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx,
+ VAAPIEncodePicture *pic,
+ VAAPIEncodeSlice *slice,
+ char *data, size_t *data_len)
 {
-int i, mt;
-
-++src_lengths;
-
-mt = 0;
-for (i = 0; i < 16; i++)
-mt += (dst_lengths[i] = src_lengths[i]);
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
+CodedBitstreamFragment  *frag = >current_fragment;
+int err;
+
+if (priv->jfif) {
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_APPN + 0,
+ >jfif_header, NULL);
+if (err < 0)
+goto fail;
+}
 
-for (i = 0; i < mt; i++)
-dst_values[i] = src_values[i];
-}
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_DQT,
+ >quant_tables, NULL);
+if (err < 0)
+goto fail;
+
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_SOF0,
+ >frame_header, NULL);
+if (err < 0)
+goto fail;
+
+if (priv->huffman) {
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_DHT,
+ >huffman_tables, NULL);
+if (err < 0)
+goto fail;
+}
 
-static av_cold void vaapi_encode_mjpeg_init_tables(AVCodecContext *avctx)
-{
-VAAPIEncodeMJPEGContext  *priv = avctx->priv_data;
-VAQMatrixBufferJPEG *quant = >quant_tables;
-VAHuffmanTableBufferJPEGBaseline *huff = >huffman_tables;
-int i;
+err = 

[FFmpeg-devel] [PATCH 26/26] vaapi_encode_h264: Set level based on stream if not set by user

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h264.c | 32 
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 899fbdbb99..7454611be9 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -30,6 +30,7 @@
 #include "cbs.h"
 #include "cbs_h264.h"
 #include "h264.h"
+#include "h264_levels.h"
 #include "h264_sei.h"
 #include "internal.h"
 #include "vaapi_encode.h"
@@ -292,6 +293,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 H264RawPPS*pps = >raw_pps;
 VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
 VAEncPictureParameterBufferH264  *vpic = ctx->codec_picture_params;
+int dpb_frames;
 
 memset(>current_access_unit, 0,
sizeof(priv->current_access_unit));
@@ -317,7 +319,30 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->constraint_set5_flag = ctx->b_per_p == 0;
 }
 
-sps->level_idc = avctx->level;
+if (ctx->gop_size == 1)
+dpb_frames = 0;
+else
+dpb_frames = 1 + (ctx->b_per_p > 0);
+
+if (avctx->level != FF_LEVEL_UNKNOWN) {
+sps->level_idc = avctx->level;
+} else {
+const H264LevelDescriptor *level;
+
+level = ff_h264_guess_level(sps->profile_idc,
+avctx->bit_rate,
+priv->mb_width  * 16,
+priv->mb_height * 16,
+dpb_frames);
+if (level) {
+if (level->constraint_set3_flag)
+sps->constraint_set3_flag = 1;
+sps->level_idc = level->level_idc;
+} else {
+// Doesn't conform to any level, just pick the highest.
+sps->level_idc = 62;
+}
+}
 
 sps->seq_parameter_set_id = 0;
 sps->chroma_format_idc= 1;
@@ -327,8 +352,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->log2_max_pic_order_cnt_lsb_minus4 =
 av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12);
 
-sps->max_num_ref_frames =
-ctx->gop_size == 1 ? 0 : 1 + (ctx->b_per_p > 0);
+sps->max_num_ref_frames = dpb_frames;
 
 sps->pic_width_in_mbs_minus1= priv->mb_width  - 1;
 sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
@@ -999,7 +1023,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "level", "Set level (level_idc)",
   OFFSET(level), AV_OPT_TYPE_INT,
-  { .i64 = 51 }, 0x00, 0xff, FLAGS, "level" },
+  { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
 
 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
   { .i64 = value }, 0, 0, FLAGS, "level"
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 23/26] lavc/cbs: Add JPEG support

2018-04-22 Thread Mark Thompson
---
 configure |   4 +-
 libavcodec/Makefile   |   1 +
 libavcodec/cbs.c  |   6 +
 libavcodec/cbs_internal.h |   1 +
 libavcodec/cbs_jpeg.c | 487 ++
 libavcodec/cbs_jpeg.h | 128 +
 libavcodec/cbs_jpeg_syntax_template.c | 191 +
 7 files changed, 817 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/cbs_jpeg.c
 create mode 100644 libavcodec/cbs_jpeg.h
 create mode 100644 libavcodec/cbs_jpeg_syntax_template.c

diff --git a/configure b/configure
index dee507cb6a..5bbeb83d13 100755
--- a/configure
+++ b/configure
@@ -2235,6 +2235,7 @@ CONFIG_EXTRA="
 cbs
 cbs_h264
 cbs_h265
+cbs_jpeg
 cbs_mpeg2
 dirac_parse
 dvprofile
@@ -2496,6 +2497,7 @@ threads_if_any="$THREADS_LIST"
 # subsystems
 cbs_h264_select="cbs golomb"
 cbs_h265_select="cbs golomb"
+cbs_jpeg_select="cbs"
 cbs_mpeg2_select="cbs"
 dct_select="rdft"
 dirac_parse_select="golomb"
@@ -2925,7 +2927,7 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
-mjpeg_vaapi_encoder_select="vaapi_encode jpegtables"
+mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mpeg1_cuvid_decoder_deps="cuvid"
 mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
 mpeg2_crystalhd_decoder_select="crystalhd"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4b8ad121db..be7466ce95 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -64,6 +64,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_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 897e0bb28e..e21a67f601 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -35,6 +35,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H265
 _cbs_type_h265,
 #endif
+#if CONFIG_CBS_JPEG
+_cbs_type_jpeg,
+#endif
 #if CONFIG_CBS_MPEG2
 _cbs_type_mpeg2,
 #endif
@@ -47,6 +50,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
 #if CONFIG_CBS_H265
 AV_CODEC_ID_H265,
 #endif
+#if CONFIG_CBS_JPEG
+AV_CODEC_ID_MJPEG,
+#endif
 #if CONFIG_CBS_MPEG2
 AV_CODEC_ID_MPEG2VIDEO,
 #endif
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index be540e2a44..a338b82ef3 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -86,6 +86,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_jpeg;
 extern const CodedBitstreamType ff_cbs_type_mpeg2;
 
 
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
new file mode 100644
index 00..89f27063da
--- /dev/null
+++ b/libavcodec/cbs_jpeg.c
@@ -0,0 +1,487 @@
+/*
+ * 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 "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_jpeg.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 READ
+#define READWRITE read
+#define RWContext GetBitContext
+#define FUNC(name) cbs_jpeg_read_ ## name
+
+#define u(width, name, range_min, range_max) do { \
+uint32_t value = range_min; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+   , range_min, range_max)); \
+current->name = value; \
+} while (0)
+
+#include "cbs_jpeg_syntax_template.c"
+
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef FUNC
+#undef u
+
+#define WRITE
+#define READWRITE write
+#define RWContext PutBitContext
+#define 

[FFmpeg-devel] [PATCH 22/26] hwcontext_vaapi: Improve logging around quirk detection

2018-04-22 Thread Mark Thompson
Clarify that the list is the naughty list, and therefore being on it is
not desirable.  The i965 driver does not need to be on the list after
version 2.0 (when the standard parameter buffer rendering behaviour was
changed).
---
 libavutil/hwcontext_vaapi.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 53a5b02822..89e4396901 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -279,11 +279,14 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
+#if !VA_CHECK_VERSION(1, 0, 0)
+// The i965 driver did not conform before version 2.0.
 {
 "Intel i965 (Quick Sync)",
 "i965",
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
 },
+#endif
 {
 "Intel iHD",
 "ubit",
@@ -344,29 +347,37 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
 }
 }
 
+vendor_string = vaQueryVendorString(hwctx->display);
+if (vendor_string)
+av_log(hwdev, AV_LOG_VERBOSE, "VAAPI driver: %s.\n", vendor_string);
+
 if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_USER_SET) {
-av_log(hwdev, AV_LOG_VERBOSE, "Not detecting driver: "
-   "quirks set by user.\n");
+av_log(hwdev, AV_LOG_VERBOSE, "Using quirks set by user (%#x).\n",
+   hwctx->driver_quirks);
 } else {
 // Detect the driver in use and set quirk flags if necessary.
-vendor_string = vaQueryVendorString(hwctx->display);
 hwctx->driver_quirks = 0;
 if (vendor_string) {
 for (i = 0; i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table); i++) {
 if (strstr(vendor_string,
vaapi_driver_quirks_table[i].match_string)) {
-av_log(hwdev, AV_LOG_VERBOSE, "Matched \"%s\" as known "
-   "driver \"%s\".\n", vendor_string,
-   vaapi_driver_quirks_table[i].friendly_name);
+av_log(hwdev, AV_LOG_VERBOSE, "Matched driver string "
+   "as known nonstandard driver \"%s\", setting "
+   "quirks (%#x).\n",
+   vaapi_driver_quirks_table[i].friendly_name,
+   vaapi_driver_quirks_table[i].quirks);
 hwctx->driver_quirks |=
 vaapi_driver_quirks_table[i].quirks;
 break;
 }
 }
 if (!(i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table))) {
-av_log(hwdev, AV_LOG_VERBOSE, "Unknown driver \"%s\", "
-   "assuming standard behaviour.\n", vendor_string);
+av_log(hwdev, AV_LOG_VERBOSE, "Driver not found in known "
+   "nonstandard list, using standard behaviour.\n");
 }
+} else {
+av_log(hwdev, AV_LOG_VERBOSE, "Driver has no vendor string, "
+   "assuming standard behaviour.\n");
 }
 }
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 19/26] vaapi_encode_h264: Properly set constraint flags

2018-04-22 Thread Mark Thompson
constraint_set1_flag should be set for constrained baseline and main
profiles, because the stream conforms to main profile.

constraint_set3_flag should be set for high profile when the stream
is intra-only.

constraint_set4_flag should always be set for main and high profiles
because interlaced encoding is not supported.

constraint_set5_flag should be set for main and high profiles when
B-frames are not used.

Also fix the setting of max_num_ref_frames - use the gop_size value
to check for intra-only rather than the constraint flag (which is not
necessarily set).
---
 libavcodec/vaapi_encode_h264.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 9943baaa76..018a843932 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -303,10 +303,19 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
 
 sps->profile_idc = avctx->profile & 0xff;
-sps->constraint_set1_flag =
-!!(avctx->profile & FF_PROFILE_H264_CONSTRAINED);
-sps->constraint_set3_flag =
-!!(avctx->profile & FF_PROFILE_H264_INTRA);
+
+if (avctx->profile == FF_PROFILE_H264_CONSTRAINED_BASELINE ||
+avctx->profile == FF_PROFILE_H264_MAIN)
+sps->constraint_set1_flag = 1;
+
+if (avctx->profile == FF_PROFILE_H264_HIGH)
+sps->constraint_set3_flag = ctx->gop_size == 1;
+
+if (avctx->profile == FF_PROFILE_H264_MAIN ||
+avctx->profile == FF_PROFILE_H264_HIGH) {
+sps->constraint_set4_flag = 1;
+sps->constraint_set5_flag = ctx->b_per_p == 0;
+}
 
 sps->level_idc = avctx->level;
 
@@ -319,8 +328,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12);
 
 sps->max_num_ref_frames =
-(avctx->profile & FF_PROFILE_H264_INTRA) ? 0 :
-1 + (ctx->b_per_p > 0);
+ctx->gop_size == 1 ? 0 : 1 + (ctx->b_per_p > 0);
 
 sps->pic_width_in_mbs_minus1= priv->mb_width  - 1;
 sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 18/26] vaapi_encode: Clean up the packed header configuration

2018-04-22 Thread Mark Thompson
Add a larger warning more clearly explaining the consequences of missing
packed header support in the driver.  Also only write the extradata if the
user actually requests it via the GLOBAL_HEADER flag.
---
 libavcodec/vaapi_encode.c   | 118 +---
 libavcodec/vaapi_encode.h   |   7 ++-
 libavcodec/vaapi_encode_h264.c  |   2 +-
 libavcodec/vaapi_encode_h265.c  |   2 +-
 libavcodec/vaapi_encode_mjpeg.c |   2 +-
 libavcodec/vaapi_encode_mpeg2.c |   4 +-
 libavcodec/vaapi_encode_vp8.c   |   6 +-
 libavcodec/vaapi_encode_vp9.c   |   6 +-
 8 files changed, 79 insertions(+), 68 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 024ccc9949..89e576357b 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1200,60 +1200,6 @@ fail:
 return err;
 }
 
-static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
-{
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAStatus vas;
-int i;
-
-VAConfigAttrib attr[] = {
-{ VAConfigAttribEncPackedHeaders },
-};
-
-vas = vaGetConfigAttributes(ctx->hwctx->display,
-ctx->va_profile, ctx->va_entrypoint,
-attr, FF_ARRAY_ELEMS(attr));
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to fetch config "
-   "attributes: %d (%s).\n", vas, vaErrorStr(vas));
-return AVERROR(EINVAL);
-}
-
-for (i = 0; i < FF_ARRAY_ELEMS(attr); i++) {
-if (attr[i].value == VA_ATTRIB_NOT_SUPPORTED) {
-// Unfortunately we have to treat this as "don't know" and hope
-// for the best, because the Intel MJPEG encoder returns this
-// for all the interesting attributes.
-av_log(avctx, AV_LOG_DEBUG, "Attribute (%d) is not supported.\n",
-   attr[i].type);
-continue;
-}
-switch (attr[i].type) {
-case VAConfigAttribEncPackedHeaders:
-if (ctx->va_packed_headers & ~attr[i].value) {
-// This isn't fatal, but packed headers are always
-// preferable because they are under our control.
-// When absent, the driver is generating them and some
-// features may not work (e.g. VUI or SEI in H.264).
-av_log(avctx, AV_LOG_WARNING, "Warning: some packed "
-   "headers are not supported (want %#x, got %#x).\n",
-   ctx->va_packed_headers, attr[i].value);
-ctx->va_packed_headers &= attr[i].value;
-}
-ctx->config_attributes[ctx->nb_config_attributes++] =
-(VAConfigAttrib) {
-.type  = VAConfigAttribEncPackedHeaders,
-.value = ctx->va_packed_headers,
-};
-break;
-default:
-av_assert0(0 && "Unexpected config attribute.");
-}
-}
-
-return 0;
-}
-
 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -1477,6 +1423,65 @@ static av_cold int 
vaapi_encode_init_gop_structure(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_packed_headers(AVCodecContext *avctx)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncPackedHeaders };
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query packed headers "
+   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+if (ctx->packed_headers) {
+av_log(avctx, AV_LOG_WARNING, "Driver does not support any "
+   "packed headers (wanted %#x).\n", ctx->packed_headers);
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "Driver does not support any "
+   "packed headers (none wanted).\n");
+}
+ctx->va_packed_headers = 0;
+} else {
+if (ctx->packed_headers & ~attr.value) {
+av_log(avctx, AV_LOG_WARNING, "Driver does not support some "
+   "wanted packed headers (wanted %#x, found %#x).\n",
+   ctx->packed_headers, attr.value);
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "All wanted packed headers "
+   "available (wanted %#x, found %#x).\n",
+   ctx->packed_headers, attr.value);
+}
+ctx->va_packed_headers = ctx->packed_headers & attr.value;
+}
+
+if (ctx->va_packed_headers) {
+ctx->config_attributes[ctx->nb_config_attributes++] =
+

[FFmpeg-devel] [PATCH 21/26] doc/encoders: Add missing options to VAAPI encoders

2018-04-22 Thread Mark Thompson
---
 doc/encoders.texi | 24 
 1 file changed, 24 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 861f9f4f1f..b451142cfb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2631,12 +2631,36 @@ Use CABAC.
 @item cavlc
 Use CAVLC.
 @end table
+
+@item aud
+Include access unit delimiters in the stream (not included by default).
+
+@item sei
+Set SEI message types to include.
+Some combination of the following values:
+@table @samp
+@item identifier
+Include a @emph{user_data_unregistered} message containing information about
+the encoder.
+@item timing
+Include picture timing parameters (@emph{buffering_period} and
+@emph{pic_timing} messages).
+@item recovery_point
+Include recovery points where appropriate (@emph{recovery_point} messages).
+@end table
+
 @end table
 
 @item hevc_vaapi
 @option{profile} and @option{level} set the values of
 @emph{general_profile_idc} and @emph{general_level_idc} respectively.
 
+@table @option
+@item aud
+Include access unit delimiters in the stream (not included by default).
+
+@end table
+
 @item mjpeg_vaapi
 Always encodes using the standard quantisation and huffman tables -
 @option{global_quality} scales the standard quantisation table (range 1-100).
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 20/26] vaapi_encode_h264: Make the AUD option a boolean

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h264.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 018a843932..899fbdbb99 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -970,7 +970,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "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 },
+  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 15/26] vaapi_encode: Clean up rate control configuration

2018-04-22 Thread Mark Thompson
Query which modes are supported and select between VBR and CBR based
on that.  Removes all of the codec-specific rate control mode selection
code.  Also ensures that target percentage and window size match the
target bitrate and RC buffer size in all cases where they are not
explicitly specified.
---
 doc/encoders.texi   |   2 -
 libavcodec/vaapi_encode.c   | 166 
 libavcodec/vaapi_encode.h   |   4 +-
 libavcodec/vaapi_encode_h264.c  |  12 ---
 libavcodec/vaapi_encode_h265.c  |  12 ---
 libavcodec/vaapi_encode_mjpeg.c |   3 +-
 libavcodec/vaapi_encode_mpeg2.c |   3 +-
 libavcodec/vaapi_encode_vp8.c   |  11 ---
 libavcodec/vaapi_encode_vp9.c   |  11 ---
 9 files changed, 119 insertions(+), 105 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 62a1509a96..0c0a307987 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2643,8 +2643,6 @@ Always encodes using the standard quantisation and 
huffman tables -
 @item mpeg2_vaapi
 @option{profile} and @option{level} set the value of 
@emph{profile_and_level_indication}.
 
-No rate control is supported.
-
 @item vp8_vaapi
 B-frames are not supported.
 
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index fc83d3db11..6188423935 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1207,7 +1207,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 int i;
 
 VAConfigAttrib attr[] = {
-{ VAConfigAttribRateControl  },
 { VAConfigAttribEncMaxRefFrames  },
 { VAConfigAttribEncPackedHeaders },
 };
@@ -1231,32 +1230,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 continue;
 }
 switch (attr[i].type) {
-case VAConfigAttribRateControl:
-// Hack for backward compatibility: CBR was the only
-// usable RC mode for a long time, so old drivers will
-// only have it.  Normal default options may now choose
-// VBR and then fail, however, so override it here with
-// CBR if that is the only supported mode.
-if (ctx->va_rc_mode == VA_RC_VBR &&
-!(attr[i].value & VA_RC_VBR) &&
-(attr[i].value & VA_RC_CBR)) {
-av_log(avctx, AV_LOG_WARNING, "VBR rate control is "
-   "not supported with this driver version; "
-   "using CBR instead.\n");
-ctx->va_rc_mode = VA_RC_CBR;
-}
-if (!(ctx->va_rc_mode & attr[i].value)) {
-av_log(avctx, AV_LOG_ERROR, "Rate control mode %#x "
-   "is not supported (mask: %#x).\n",
-   ctx->va_rc_mode, attr[i].value);
-return AVERROR(EINVAL);
-}
-ctx->config_attributes[ctx->nb_config_attributes++] =
-(VAConfigAttrib) {
-.type  = VAConfigAttribRateControl,
-.value = ctx->va_rc_mode,
-};
-break;
 case VAConfigAttribEncMaxRefFrames:
 {
 unsigned int ref_l0 = attr[i].value & 0x;
@@ -1303,16 +1276,46 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-int rc_bits_per_second;
-int rc_target_percentage;
-int rc_window_size;
-int hrd_buffer_size;
-int hrd_initial_buffer_fullness;
+int64_t rc_bits_per_second;
+int rc_target_percentage;
+int rc_window_size;
+int64_t hrd_buffer_size;
+int64_t hrd_initial_buffer_fullness;
 int fr_num, fr_den;
+VAConfigAttrib rc_attr = { VAConfigAttribRateControl };
+VAStatus vas;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile, ctx->va_entrypoint,
+_attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query rate control "
+   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
 
-if (avctx->bit_rate > INT32_MAX) {
-av_log(avctx, AV_LOG_ERROR, "Target bitrate of 2^31 bps or "
-   "higher is not supported.\n");
+if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any "
+   "supported rate control modes: assuming constant-quality.\n");
+ctx->va_rc_mode = VA_RC_CQP;
+return 0;
+}
+if (avctx->flags & AV_CODEC_FLAG_QSCALE ||
+avctx->bit_rate <= 0) {
+if (rc_attr.value & VA_RC_CQP) {
+av_log(avctx, AV_LOG_VERBOSE, "Using constant-quality mode.\n");
+ctx->va_rc_mode = VA_RC_CQP;
+return 0;
+} else {
+av_log(avctx, 

[FFmpeg-devel] [PATCH 08/26] vaapi_encode: Allocate picture-private data in generic code

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode.c | 15 ---
 libavcodec/vaapi_encode.h |  4 
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 609fc604c1..bb0f4c6fdf 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -528,14 +528,23 @@ static int vaapi_encode_discard(AVCodecContext *avctx,
 return 0;
 }
 
-static VAAPIEncodePicture *vaapi_encode_alloc(void)
+static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
 {
+VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodePicture *pic;
 
 pic = av_mallocz(sizeof(*pic));
 if (!pic)
 return NULL;
 
+if (ctx->codec->picture_priv_data_size > 0) {
+pic->priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
+if (!pic->priv_data) {
+av_freep();
+return NULL;
+}
+}
+
 pic->input_surface = VA_INVALID_ID;
 pic->recon_surface = VA_INVALID_ID;
 pic->output_buffer = VA_INVALID_ID;
@@ -668,7 +677,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 }
 }
 
-pic = vaapi_encode_alloc();
+pic = vaapi_encode_alloc(avctx);
 if (!pic)
 return AVERROR(ENOMEM);
 
@@ -697,7 +706,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 
 for (i = 0; i < ctx->b_per_p &&
  ctx->gop_counter < avctx->gop_size; i++) {
-pic = vaapi_encode_alloc();
+pic = vaapi_encode_alloc(avctx);
 if (!pic)
 goto fail;
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index c7370a17e2..54dc4a475e 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -211,6 +211,10 @@ typedef struct VAAPIEncodeType {
 // add any necessary global parameters).
 int (*configure)(AVCodecContext *avctx);
 
+// The size of any private data structure associated with each
+// picture (can be zero if not required).
+size_t picture_priv_data_size;
+
 // The size of the parameter structures:
 // sizeof(VAEnc{type}ParameterBuffer{codec}).
 size_t sequence_params_size;
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 13/26] vaapi_encode: Add quality level to common options

2018-04-22 Thread Mark Thompson
This was previously accessible only via AVCodecContext.compression_level
for all encoders except H.264 where it was also a private option.  This
makes it an explicit option everywhere.
---
 libavcodec/vaapi_encode.c  | 87 ++
 libavcodec/vaapi_encode.h  |  8 
 libavcodec/vaapi_encode_h264.c |  6 ---
 3 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 9c39bcdeff..a5eb072843 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1381,6 +1381,52 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
+{
+#if VA_CHECK_VERSION(0, 36, 0)
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query quality "
+   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+if (ctx->quality != 0) {
+av_log(avctx, AV_LOG_WARNING, "Quality attribute is not "
+   "supported: will use default quality level.\n");
+}
+} else {
+if (ctx->quality > attr.value) {
+av_log(avctx, AV_LOG_WARNING, "Invalid quality level: "
+   "valid range is 0-%d, using %d.\n",
+   attr.value, attr.value);
+ctx->quality = attr.value;
+}
+
+ctx->quality_params.misc.type =
+VAEncMiscParameterTypeQualityLevel;
+ctx->quality_params.quality.quality_level =
+ctx->quality;
+
+vaapi_encode_add_global_param(avctx, >quality_params.misc,
+  sizeof(ctx->quality_params));
+}
+#else
+av_log(avctx, AV_LOG_WARNING, "The encode quality option is "
+   "not supported with this VAAPI version.\n");
+#endif
+
+return 0;
+}
+
 static void vaapi_encode_free_output_buffer(void *opaque,
 uint8_t *data)
 {
@@ -1562,6 +1608,14 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 if (err < 0)
 goto fail;
 
+if (!ctx->quality)
+ctx->quality = avctx->compression_level;
+if (ctx->quality >= 0) {
+err = vaapi_encode_init_quality(avctx);
+if (err < 0)
+goto fail;
+}
+
 vas = vaCreateConfig(ctx->hwctx->display,
  ctx->va_profile, ctx->va_entrypoint,
  ctx->config_attributes, ctx->nb_config_attributes,
@@ -1611,39 +1665,6 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 goto fail;
 }
 
-if (avctx->compression_level >= 0) {
-#if VA_CHECK_VERSION(0, 36, 0)
-VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
-
-vas = vaGetConfigAttributes(ctx->hwctx->display,
-ctx->va_profile,
-ctx->va_entrypoint,
-, 1);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_WARNING, "Failed to query quality "
-   "attribute: will use default compression level.\n");
-} else {
-if (avctx->compression_level > attr.value) {
-av_log(avctx, AV_LOG_WARNING, "Invalid compression "
-   "level: valid range is 0-%d, using %d.\n",
-   attr.value, attr.value);
-avctx->compression_level = attr.value;
-}
-
-ctx->quality_params.misc.type =
-VAEncMiscParameterTypeQualityLevel;
-ctx->quality_params.quality.quality_level =
-avctx->compression_level;
-
-vaapi_encode_add_global_param(avctx, >quality_params.misc,
-  sizeof(ctx->quality_params));
-}
-#else
-av_log(avctx, AV_LOG_WARNING, "The encode compression level "
-   "option is not supported with this VAAPI version.\n");
-#endif
-}
-
 ctx->input_order  = 0;
 ctx->output_delay = avctx->max_b_frames;
 ctx->decode_delay = 1;
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 9e0826b30e..35d48eff2f 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -111,6 +111,10 @@ typedef struct VAAPIEncodeContext {
 
 // Global options.
 
+// Encoding quality level.
+// (Also exposed via AVCodecContext.compression_level.)
+int quality;
+
 // Use low power encoding mode.
 int 

[FFmpeg-devel] [PATCH 14/26] vaapi_encode: Always reapply global parameters after the sequence header

2018-04-22 Thread Mark Thompson
The codec sequence headers may contain fields which can overwrite the
fine parameters given in the specific settings (e.g. a crude bitrate
value vs. the max-rate / target-percentage / etc. values in
VAEncMiscParameterRateControl).  Always reapply all global parameters
after a sequence header to avoid this causing problems.
---
 libavcodec/vaapi_encode.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index a5eb072843..fc83d3db11 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -207,9 +207,16 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 pic->nb_param_buffers = 0;
 
-if (pic->encode_order == 0) {
-// Global parameter buffers are set on the first picture only.
+if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) {
+err = vaapi_encode_make_param_buffer(avctx, pic,
+ VAEncSequenceParameterBufferType,
+ ctx->codec_sequence_params,
+ ctx->codec->sequence_params_size);
+if (err < 0)
+goto fail;
+}
 
+if (pic->type == PICTURE_TYPE_IDR) {
 for (i = 0; i < ctx->nb_global_params; i++) {
 err = vaapi_encode_make_param_buffer(avctx, pic,
  VAEncMiscParameterBufferType,
@@ -220,15 +227,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }
 
-if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) {
-err = vaapi_encode_make_param_buffer(avctx, pic,
- VAEncSequenceParameterBufferType,
- ctx->codec_sequence_params,
- ctx->codec->sequence_params_size);
-if (err < 0)
-goto fail;
-}
-
 if (ctx->codec->init_picture_params) {
 err = ctx->codec->init_picture_params(avctx, pic);
 if (err < 0) {
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 16/26] vaapi_encode: Add support for max QP in rate control

2018-04-22 Thread Mark Thompson
This was added in libva 2.1.0 (VAAPI 1.1.0).  Use AVCodecContext.qmax,
matching the existing behaviour for qmin, and clean up the defaults so
that we only pass min/max when explicitly set.
---
 doc/encoders.texi   | 3 ++-
 libavcodec/vaapi_encode.c   | 3 +++
 libavcodec/vaapi_encode_h264.c  | 3 ++-
 libavcodec/vaapi_encode_h265.c  | 2 ++
 libavcodec/vaapi_encode_mpeg2.c | 2 ++
 libavcodec/vaapi_encode_vp8.c   | 2 ++
 libavcodec/vaapi_encode_vp9.c   | 2 ++
 7 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 0c0a307987..861f9f4f1f 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2588,7 +2588,8 @@ Speed / quality tradeoff: higher values are faster / 
worse quality.
 Size / quality tradeoff: higher values are smaller / worse quality.
 @item
 @option{qmin}
-(only: @option{qmax} is not supported)
+@item
+@option{qmax}
 @item
 @option{i_qfactor} / @option{i_quant_factor}
 @item
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6188423935..39c622dacc 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1415,6 +1415,9 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 .initial_qp= 0,
 .min_qp= (avctx->qmin > 0 ? avctx->qmin : 0),
 .basic_unit_size   = 0,
+#if VA_CHECK_VERSION(1, 1, 0)
+.max_qp= (avctx->qmax > 0 ? avctx->qmax : 0),
+#endif
 };
 vaapi_encode_add_global_param(avctx, >rc_params.misc,
   sizeof(ctx->rc_params));
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index e75b91eb55..514805d0c2 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1027,7 +1027,8 @@ static const AVCodecDefault vaapi_encode_h264_defaults[] 
= {
 { "i_qoffset",  "0"   },
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
-{ "qmin",   "0"   },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index fa9d838bdc..8a31a73148 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -992,6 +992,8 @@ static const AVCodecDefault vaapi_encode_h265_defaults[] = {
 { "i_qoffset",  "0"   },
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index b7189b2d67..42ddb0a284 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -673,6 +673,8 @@ static const AVCodecDefault vaapi_encode_mpeg2_defaults[] = 
{
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
 { "global_quality", "10"  },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index dd7943133e..2026e3276b 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -228,6 +228,8 @@ static const AVCodecDefault vaapi_encode_vp8_defaults[] = {
 { "bf", "0"   },
 { "g",  "120" },
 { "global_quality", "40"  },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 794b308fa5..fa77b9b298 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -253,6 +253,8 @@ static const AVCodecDefault vaapi_encode_vp9_defaults[] = {
 { "bf", "0"   },
 { "g",  "250" },
 { "global_quality", "100" },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 09/26] vaapi_encode: Factorise out adding global parameters

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode.c | 38 ++
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index bb0f4c6fdf..9c5cfc7a65 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -969,6 +969,20 @@ fail:
 return err;
 }
 
+static av_cold void vaapi_encode_add_global_param(AVCodecContext *avctx,
+  VAEncMiscParameterBuffer 
*buffer,
+  size_t size)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+
+av_assert0(ctx->nb_global_params < MAX_GLOBAL_PARAMS);
+
+ctx->global_params [ctx->nb_global_params] = buffer;
+ctx->global_params_size[ctx->nb_global_params] = size;
+
+++ctx->nb_global_params;
+}
+
 static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -1191,20 +1205,16 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 .min_qp= (avctx->qmin > 0 ? avctx->qmin : 0),
 .basic_unit_size   = 0,
 };
-ctx->global_params[ctx->nb_global_params] =
->rc_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->rc_params);
+vaapi_encode_add_global_param(avctx, >rc_params.misc,
+  sizeof(ctx->rc_params));
 
 ctx->hrd_params.misc.type = VAEncMiscParameterTypeHRD;
 ctx->hrd_params.hrd = (VAEncMiscParameterHRD) {
 .initial_buffer_fullness = hrd_initial_buffer_fullness,
 .buffer_size = hrd_buffer_size,
 };
-ctx->global_params[ctx->nb_global_params] =
->hrd_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->hrd_params);
+vaapi_encode_add_global_param(avctx, >hrd_params.misc,
+  sizeof(ctx->hrd_params));
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
 av_reduce(_num, _den,
@@ -1217,10 +1227,8 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 ctx->fr_params.fr.framerate = (unsigned int)fr_den << 16 | fr_num;
 
 #if VA_CHECK_VERSION(0, 40, 0)
-ctx->global_params[ctx->nb_global_params] =
->fr_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->fr_params);
+vaapi_encode_add_global_param(avctx, >fr_params.misc,
+  sizeof(ctx->fr_params));
 #endif
 
 return 0;
@@ -1476,10 +1484,8 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 ctx->quality_params.quality.quality_level =
 avctx->compression_level;
 
-ctx->global_params[ctx->nb_global_params] =
->quality_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->quality_params);
+vaapi_encode_add_global_param(avctx, >quality_params.misc,
+  sizeof(ctx->quality_params));
 }
 #else
 av_log(avctx, AV_LOG_WARNING, "The encode compression level "
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 17/26] vaapi_encode: Clean up the GOP structure configuration

2018-04-22 Thread Mark Thompson
Choose what types of reference frames will be used based on what types
are available, and make the intra-only mode explicit (GOP size one,
which must be used for MJPEG).
---
 libavcodec/vaapi_encode.c   | 83 +++--
 libavcodec/vaapi_encode.h   |  1 +
 libavcodec/vaapi_encode_h264.c  |  4 +-
 libavcodec/vaapi_encode_h265.c  |  4 +-
 libavcodec/vaapi_encode_mjpeg.c |  1 +
 libavcodec/vaapi_encode_mpeg2.c |  2 +-
 libavcodec/vaapi_encode_vp8.c   |  7 +---
 libavcodec/vaapi_encode_vp9.c   |  7 ++--
 8 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 39c622dacc..024ccc9949 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -680,7 +680,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 return AVERROR(ENOMEM);
 
 if (ctx->input_order == 0 || ctx->force_idr ||
-ctx->gop_counter >= avctx->gop_size) {
+ctx->gop_counter >= ctx->gop_size) {
 pic->type = PICTURE_TYPE_IDR;
 ctx->force_idr = 0;
 ctx->gop_counter = 1;
@@ -703,7 +703,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 // encode-after it, but not exceeding the GOP size.
 
 for (i = 0; i < ctx->b_per_p &&
- ctx->gop_counter < avctx->gop_size; i++) {
+ ctx->gop_counter < ctx->gop_size; i++) {
 pic = vaapi_encode_alloc(avctx);
 if (!pic)
 goto fail;
@@ -1207,7 +1207,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 int i;
 
 VAConfigAttrib attr[] = {
-{ VAConfigAttribEncMaxRefFrames  },
 { VAConfigAttribEncPackedHeaders },
 };
 
@@ -1230,24 +1229,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 continue;
 }
 switch (attr[i].type) {
-case VAConfigAttribEncMaxRefFrames:
-{
-unsigned int ref_l0 = attr[i].value & 0x;
-unsigned int ref_l1 = (attr[i].value >> 16) & 0x;
-
-if (avctx->gop_size > 1 && ref_l0 < 1) {
-av_log(avctx, AV_LOG_ERROR, "P frames are not "
-   "supported (%#x).\n", attr[i].value);
-return AVERROR(EINVAL);
-}
-if (avctx->max_b_frames > 0 && ref_l1 < 1) {
-av_log(avctx, AV_LOG_WARNING, "B frames are not "
-   "supported (%#x) by the underlying driver.\n",
-   attr[i].value);
-avctx->max_b_frames = 0;
-}
-}
-break;
 case VAConfigAttribEncPackedHeaders:
 if (ctx->va_packed_headers & ~attr[i].value) {
 // This isn't fatal, but packed headers are always
@@ -1448,6 +1429,54 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
+uint32_t ref_l0, ref_l1;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query reference frames "
+   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+ref_l0 = ref_l1 = 0;
+} else {
+ref_l0 = attr.value   & 0x;
+ref_l1 = attr.value >> 16 & 0x;
+}
+
+if (avctx->gop_size <= 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
+ctx->gop_size = 1;
+} else if (ref_l0 < 1) {
+av_log(avctx, AV_LOG_ERROR, "Driver does not support any "
+   "reference frames.\n");
+return AVERROR(EINVAL);
+} else if (ref_l1 < 1 || avctx->max_b_frames < 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
+   "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = 0;
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
+   "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = avctx->max_b_frames;
+}
+
+return 0;
+}
+
 static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
 {
 #if VA_CHECK_VERSION(0, 36, 0)
@@ -1620,7 +1649,7 @@ static av_cold int 
vaapi_encode_create_recon_frames(AVCodecContext *avctx)
 ctx->recon_frames->height= ctx->surface_height;
 // At most three IDR/I/P frames and 

[FFmpeg-devel] [PATCH 12/26] vaapi_encode_mpeg2: Add options

2018-04-22 Thread Mark Thompson
Include the common options, and also named options for setting the profile
and level.
---
 libavcodec/vaapi_encode_mpeg2.c | 53 +++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index b995a4b8b8..09c3663220 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -30,6 +30,10 @@
 typedef struct VAAPIEncodeMPEG2Context {
 VAAPIEncodeContext common;
 
+// User options.
+int profile;
+int level;
+
 // Derived settings.
 int mb_width;
 int mb_height;
@@ -581,10 +585,18 @@ static const VAAPIEncodeType vaapi_encode_type_mpeg2 = {
 
 static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 
 ctx->codec = _encode_type_mpeg2;
 
+if (avctx->profile == FF_PROFILE_UNKNOWN)
+avctx->profile = priv->profile;
+if (avctx->level == FF_LEVEL_UNKNOWN)
+avctx->level = priv->level;
+
+// Reject unknown levels (these are required to set f_code for
+// motion vector encoding).
 switch (avctx->level) {
 case 4: // High
 case 6: // High 1440
@@ -624,8 +636,37 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext 
*avctx)
 return ff_vaapi_encode_close(avctx);
 }
 
+#define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
+#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
+static const AVOption vaapi_encode_mpeg2_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
+
+{ "profile", "Set profile (in profile_and_level_indication)",
+  OFFSET(profile), AV_OPT_TYPE_INT,
+  { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 7, FLAGS, "profile" },
+
+#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST, \
+  { .i64 = value }, 0, 0, FLAGS, "profile"
+{ PROFILE("simple", FF_PROFILE_MPEG2_SIMPLE) },
+{ PROFILE("main",   FF_PROFILE_MPEG2_MAIN)   },
+#undef PROFILE
+
+{ "level", "Set level (in profile_and_level_indication)",
+  OFFSET(level), AV_OPT_TYPE_INT,
+  { .i64 = 4 }, 0, 15, FLAGS, "level" },
+
+#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+  { .i64 = value }, 0, 0, FLAGS, "level"
+{ LEVEL("low",   10) },
+{ LEVEL("main",   8) },
+{ LEVEL("high_1440",  6) },
+{ LEVEL("high",   4) },
+#undef LEVEL
+
+{ NULL },
+};
+
 static const AVCodecDefault vaapi_encode_mpeg2_defaults[] = {
-{ "level",  "4"   },
 { "bf", "1"   },
 { "g",  "120" },
 { "i_qfactor",  "1"   },
@@ -636,6 +677,13 @@ static const AVCodecDefault vaapi_encode_mpeg2_defaults[] 
= {
 { NULL },
 };
 
+static const AVClass vaapi_encode_mpeg2_class = {
+.class_name = "mpeg2_vaapi",
+.item_name  = av_default_item_name,
+.option = vaapi_encode_mpeg2_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_mpeg2_vaapi_encoder = {
 .name   = "mpeg2_vaapi",
 .long_name  = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"),
@@ -645,6 +693,7 @@ AVCodec ff_mpeg2_vaapi_encoder = {
 .init   = _encode_mpeg2_init,
 .encode2= _vaapi_encode2,
 .close  = _encode_mpeg2_close,
+.priv_class = _encode_mpeg2_class,
 .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
 .defaults   = vaapi_encode_mpeg2_defaults,
 .pix_fmts = (const enum AVPixelFormat[]) {
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 06/26] vaapi_encode_vp9: Move options and common structures into context

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_vp9.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 9108699ac3..6e62213bc9 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -33,21 +33,25 @@
 
 
 typedef struct VAAPIEncodeVP9Context {
+VAAPIEncodeContext common;
+
+// User options.
+int loop_filter_level;
+int loop_filter_sharpness;
+
+// Derived settings.
 int q_idx_idr;
 int q_idx_p;
 int q_idx_b;
 
+// Stream state.
+
 // Reference direction for B-like frames:
 // 0 - most recent P/IDR frame is last.
 // 1 - most recent P frame is golden.
 int last_ref_dir;
 } VAAPIEncodeVP9Context;
 
-typedef struct VAAPIEncodeVP9Options {
-int loop_filter_level;
-int loop_filter_sharpness;
-} VAAPIEncodeVP9Options;
-
 
 #define vseq_var(name) vseq->name, name
 #define vseq_field(name)   vseq->seq_fields.bits.name, name
@@ -82,10 +86,8 @@ static int 
vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeVP9Context  *priv = avctx->priv_data;
 VAEncPictureParameterBufferVP9 *vpic = pic->codec_picture_params;
-VAAPIEncodeVP9Context  *priv = ctx->priv_data;
-VAAPIEncodeVP9Options   *opt = ctx->codec_options;
 int i;
 
 vpic->reconstructed_frame = pic->recon_surface;
@@ -169,8 +171,8 @@ static int 
vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 vpic->chroma_ac_qindex_delta = 0;
 vpic->chroma_dc_qindex_delta = 0;
 
-vpic->filter_level= opt->loop_filter_level;
-vpic->sharpness_level = opt->loop_filter_sharpness;
+vpic->filter_level= priv->loop_filter_level;
+vpic->sharpness_level = priv->loop_filter_sharpness;
 
 if (avctx->max_b_frames > 0 && pic->type == PICTURE_TYPE_P)
 priv->last_ref_dir = !priv->last_ref_dir;
@@ -180,8 +182,7 @@ static int 
vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP9Context *priv = ctx->priv_data;
+VAAPIEncodeVP9Context *priv = avctx->priv_data;
 
 priv->q_idx_p = av_clip(avctx->global_quality, 0, VP9_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
@@ -266,8 +267,7 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext 
*avctx)
 return ff_vaapi_encode_init(avctx);
 }
 
-#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
-   offsetof(VAAPIEncodeVP9Options, x))
+#define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp9_options[] = {
 { "loop_filter_level", "Loop filter level",
@@ -298,8 +298,7 @@ AVCodec ff_vp9_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("VP9 (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_VP9,
-.priv_data_size = (sizeof(VAAPIEncodeContext) +
-   sizeof(VAAPIEncodeVP9Options)),
+.priv_data_size = sizeof(VAAPIEncodeVP9Context),
 .init   = _encode_vp9_init,
 .encode2= _vaapi_encode2,
 .close  = _vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 07/26] vaapi_encode: Remove common priv_data and options fields

2018-04-22 Thread Mark Thompson
The codec-specific context now contains both the common context and the
codec-specific options directly.
---
 libavcodec/vaapi_encode.c   | 10 --
 libavcodec/vaapi_encode.h   | 11 ---
 libavcodec/vaapi_encode_h264.c  |  2 --
 libavcodec/vaapi_encode_h265.c  |  2 --
 libavcodec/vaapi_encode_mjpeg.c |  2 --
 libavcodec/vaapi_encode_mpeg2.c |  2 --
 libavcodec/vaapi_encode_vp8.c   |  2 --
 libavcodec/vaapi_encode_vp9.c   |  2 --
 8 files changed, 33 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 36c85a3815..609fc604c1 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1372,17 +1372,9 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-ctx->codec_options = ctx->codec_options_data;
-
 ctx->va_config  = VA_INVALID_ID;
 ctx->va_context = VA_INVALID_ID;
 
-ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
-if (!ctx->priv_data) {
-err = AVERROR(ENOMEM);
-goto fail;
-}
-
 ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
 if (!ctx->input_frames_ref) {
 err = AVERROR(ENOMEM);
@@ -1583,7 +1575,5 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
 av_buffer_unref(>input_frames_ref);
 av_buffer_unref(>device_ref);
 
-av_freep(>priv_data);
-
 return 0;
 }
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index bcb9d57371..c7370a17e2 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -113,9 +113,6 @@ typedef struct VAAPIEncodeContext {
 // Everything above this point must be set before calling
 // ff_vaapi_encode_init().
 
-// Codec-specific state.
-void *priv_data;
-
 // Configuration attributes to use when creating va_config.
 VAConfigAttrib  config_attributes[MAX_CONFIG_ATTRIBUTES];
 int  nb_config_attributes;
@@ -205,18 +202,10 @@ typedef struct VAAPIEncodeContext {
 int gop_counter;
 int p_counter;
 int end_of_stream;
-
-// Codec-local options are allocated to follow this structure in
-// memory (in the AVCodec definition, set priv_data_size to
-// sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
-void *codec_options;
-char codec_options_data[0];
 } VAAPIEncodeContext;
 
 
 typedef struct VAAPIEncodeType {
-size_t priv_data_size;
-
 // Perform any extra codec-specific configuration after the
 // codec context is initialised (set up the private data and
 // add any necessary global parameters).
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index cc163151a6..8396683789 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -864,8 +864,6 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_h264 = {
-.priv_data_size= sizeof(VAAPIEncodeH264Context),
-
 .configure = _encode_h264_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferH264),
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index ba6b426eed..5529ee5a03 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -876,8 +876,6 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_h265 = {
-.priv_data_size= sizeof(VAAPIEncodeH265Context),
-
 .configure = _encode_h265_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferHEVC),
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 983c77d194..481981a71c 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -360,8 +360,6 @@ static av_cold int 
vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_mjpeg = {
-.priv_data_size= sizeof(VAAPIEncodeMJPEGContext),
-
 .configure = _encode_mjpeg_configure,
 
 .picture_params_size   = sizeof(VAEncPictureParameterBufferJPEG),
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 5dd1f39cbc..72c838d774 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -553,8 +553,6 @@ static av_cold int 
vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_mpeg2 = {
-.priv_data_size= sizeof(VAAPIEncodeMPEG2Context),
-
 .configure = _encode_mpeg2_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferMPEG2),
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index c182b6918a..05c9d03a38 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -176,8 +176,6 @@ static av_cold int 

[FFmpeg-devel] [PATCH 05/26] vaapi_encode_vp8: Move options and common structures into context

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_vp8.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index b4c5521d1f..c182b6918a 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -32,14 +32,16 @@
 
 
 typedef struct VAAPIEncodeVP8Context {
-int q_index_i;
-int q_index_p;
-} VAAPIEncodeVP8Context;
+VAAPIEncodeContext common;
 
-typedef struct VAAPIEncodeVP8Options {
+// User options.
 int loop_filter_level;
 int loop_filter_sharpness;
-} VAAPIEncodeVP8Options;
+
+// Derived settings.
+int q_index_i;
+int q_index_p;
+} VAAPIEncodeVP8Context;
 
 
 #define vseq_var(name) vseq->name, name
@@ -73,9 +75,8 @@ static int 
vaapi_encode_vp8_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeVP8Context  *priv = avctx->priv_data;
 VAEncPictureParameterBufferVP8 *vpic = pic->codec_picture_params;
-VAAPIEncodeVP8Options   *opt = ctx->codec_options;
 int i;
 
 vpic->reconstructed_frame = pic->recon_surface;
@@ -116,8 +117,8 @@ static int 
vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
 vpic->pic_flags.bits.version = 0;
 vpic->pic_flags.bits.loop_filter_type = 0;
 for (i = 0; i < 4; i++)
-vpic->loop_filter_level[i] = opt->loop_filter_level;
-vpic->sharpness_level = opt->loop_filter_sharpness;
+vpic->loop_filter_level[i] = priv->loop_filter_level;
+vpic->sharpness_level = priv->loop_filter_sharpness;
 
 vpic->clamp_qindex_low  = 0;
 vpic->clamp_qindex_high = 127;
@@ -130,8 +131,7 @@ static int 
vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
   int index, int *type,
   char *data, size_t *data_len)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP8Context *priv = ctx->priv_data;
+VAAPIEncodeVP8Context *priv = avctx->priv_data;
 VAQMatrixBufferVP8 quant;
 int i, q;
 
@@ -159,8 +159,7 @@ static int 
vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp8_configure(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP8Context *priv = ctx->priv_data;
+VAAPIEncodeVP8Context *priv = avctx->priv_data;
 
 priv->q_index_p = av_clip(avctx->global_quality, 0, VP8_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
@@ -223,8 +222,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext 
*avctx)
 return ff_vaapi_encode_init(avctx);
 }
 
-#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
-   offsetof(VAAPIEncodeVP8Options, x))
+#define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp8_options[] = {
 { "loop_filter_level", "Loop filter level",
@@ -254,8 +252,7 @@ AVCodec ff_vp8_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("VP8 (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_VP8,
-.priv_data_size = (sizeof(VAAPIEncodeContext) +
-   sizeof(VAAPIEncodeVP8Options)),
+.priv_data_size = sizeof(VAAPIEncodeVP8Context),
 .init   = _encode_vp8_init,
 .encode2= _vaapi_encode2,
 .close  = _vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 11/26] vaapi_encode: Add common options between all encoders

2018-04-22 Thread Mark Thompson
The only common option here is low_power - it was previously supported
for H.264 only, that specific option is removed.
---
 doc/encoders.texi  | 14 --
 libavcodec/vaapi_encode.h  |  9 +
 libavcodec/vaapi_encode_h264.c |  8 ++--
 libavcodec/vaapi_encode_h265.c |  2 ++
 libavcodec/vaapi_encode_vp8.c  |  1 +
 libavcodec/vaapi_encode_vp9.c  |  1 +
 6 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 16be6359b3..62a1509a96 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2599,6 +2599,18 @@ Size / quality tradeoff: higher values are smaller / 
worse quality.
 @option{b_qoffset} / @option{b_quant_offset}
 @end itemize
 
+All encoders support the following options:
+@itemize
+@item
+@option{low_power}
+
+Some drivers/platforms offer a second encoder for some codecs intended to use
+less power than the default encoder; setting this option will attempt to use
+that encoder.  Note that it may support a reduced feature set, so some other
+options may not be available in this mode.
+@end itemize
+
+Each encoder also has its own specific options:
 @table @option
 
 @item h264_vaapi
@@ -2606,8 +2618,6 @@ Size / quality tradeoff: higher values are smaller / 
worse quality.
 @option{level} sets the value of @emph{level_idc}.
 
 @table @option
-@item low_power
-Use low-power encoding mode.
 @item coder
 Set entropy encoder (default is @emph{cabac}).  Possible values:
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 2b909d4d6b..9e0826b30e 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -300,4 +300,13 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
 int ff_vaapi_encode_init(AVCodecContext *avctx);
 int ff_vaapi_encode_close(AVCodecContext *avctx);
 
+
+#define VAAPI_ENCODE_COMMON_OPTIONS \
+{ "low_power", \
+  "Use low-power encoding mode (only available on some platforms; " \
+  "may not support all encoding features)", \
+  OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
+  { .i64 = 0 }, 0, 1, FLAGS }
+
+
 #endif /* AVCODEC_VAAPI_ENCODE_H */
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 93dc51eb40..49dc5229b5 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -52,7 +52,6 @@ typedef struct VAAPIEncodeH264Context {
 // User options.
 int qp;
 int quality;
-int low_power;
 int coder;
 int aud;
 int sei;
@@ -933,8 +932,6 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 return AVERROR_PATCHWELCOME;
 }
 
-ctx->low_power = priv->low_power;
-
 if (avctx->bit_rate > 0) {
 if (avctx->rc_max_rate == avctx->bit_rate)
 ctx->va_rc_mode = VA_RC_CBR;
@@ -969,13 +966,12 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h264_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
+
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
 { "quality", "Set encode quality (trades off against speed, higher is 
faster)",
   OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, FLAGS },
-{ "low_power", "Use low-power encoding mode (experimental: only supported "
-  "on some platforms, does not support all features)",
-  OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
 { "coder", "Entropy coder type",
   OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
 { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index e01bdcf6b4..a818650811 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -954,6 +954,8 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h265_options[] = {
+VAAPI_ENCODE_COMMON_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 },
 
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index 2191e00ef4..d9c359a4e1 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -226,6 +226,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp8_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
 { "loop_filter_level", "Loop 

[FFmpeg-devel] [PATCH 10/26] vaapi_encode: Choose profiles dynamically

2018-04-22 Thread Mark Thompson
Previously there was one fixed choice for each codec (e.g. H.265 -> Main
profile), and using anything else then required an explicit option from
the user.  This changes to selecting the profile based on the input format
and the set of profiles actually supported by the driver (e.g. P010 input
will choose Main 10 profile for H.265 if the driver supports it).

The entrypoint and render target format are also chosen dynamically in the
same way, removing those explicit selections from the per-codec code.
---
 doc/encoders.texi   |   3 +
 libavcodec/vaapi_encode.c   | 261 +++-
 libavcodec/vaapi_encode.h   |  41 +--
 libavcodec/vaapi_encode_h264.c  |  45 ++-
 libavcodec/vaapi_encode_h265.c  |  43 +++
 libavcodec/vaapi_encode_mjpeg.c |  13 +-
 libavcodec/vaapi_encode_mpeg2.c |  36 ++
 libavcodec/vaapi_encode_vp8.c   |  11 +-
 libavcodec/vaapi_encode_vp9.c   |  34 ++
 9 files changed, 306 insertions(+), 181 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7b095754d1..16be6359b3 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2565,6 +2565,9 @@ The following standard libavcodec options are used:
 @option{bf} / @option{max_b_frames}
 @item
 @option{profile}
+
+If not set, this will be determined automatically from the format of the input
+frames and the profiles supported by the driver.
 @item
 @option{level}
 @item
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 9c5cfc7a65..9c39bcdeff 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -983,70 +983,237 @@ static av_cold void 
vaapi_encode_add_global_param(AVCodecContext *avctx,
 ++ctx->nb_global_params;
 }
 
-static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
+typedef struct VAAPIEncodeRTFormat {
+const char *name;
+unsigned int value;
+int depth;
+int log2_chroma_w;
+int log2_chroma_h;
+} VAAPIEncodeRTFormat;
+
+static const VAAPIEncodeRTFormat vaapi_encode_rt_formats[] = {
+{ "YUV420",VA_RT_FORMAT_YUV420,8, 1, 1 },
+{ "YUV422",VA_RT_FORMAT_YUV422,8, 1, 0 },
+{ "YUV444",VA_RT_FORMAT_YUV444,8, 0, 0 },
+{ "YUV411",VA_RT_FORMAT_YUV411,8, 2, 0 },
+#if VA_CHECK_VERSION(0, 38, 1)
+{ "YUV420_10", VA_RT_FORMAT_YUV420_10BPP, 10, 1, 1 },
+#endif
+};
+
+static const VAEntrypoint vaapi_encode_entrypoints_normal[] = {
+VAEntrypointEncSlice,
+VAEntrypointEncPicture,
+VAEntrypointEncSliceLP,
+0
+};
+static const VAEntrypoint vaapi_encode_entrypoints_low_power[] = {
+VAEntrypointEncSliceLP,
+0
+};
+
+static av_cold int vaapi_encode_profile_entrypoint(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAProfile*va_profiles= NULL;
+VAEntrypoint *va_entrypoints = NULL;
 VAStatus vas;
-int i, n, err;
-VAProfile*profiles= NULL;
-VAEntrypoint *entrypoints = NULL;
-VAConfigAttrib attr[] = {
-{ VAConfigAttribRTFormat },
-{ VAConfigAttribRateControl  },
-{ VAConfigAttribEncMaxRefFrames  },
-{ VAConfigAttribEncPackedHeaders },
-};
+const VAEntrypoint *usable_entrypoints;
+const VAAPIEncodeProfile *profile;
+const AVPixFmtDescriptor *desc;
+VAConfigAttrib rt_format_attr;
+const VAAPIEncodeRTFormat *rt_format;
+int i, j, n, depth, err;
+
+
+if (ctx->low_power) {
+#if VA_CHECK_VERSION(0, 39, 2)
+usable_entrypoints = vaapi_encode_entrypoints_low_power;
+#else
+av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
+   "supported with this VAAPI version.\n");
+return AVERROR(EINVAL);
+#endif
+} else {
+usable_entrypoints = vaapi_encode_entrypoints_normal;
+}
+
+desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
+if (!desc) {
+av_log(avctx, AV_LOG_ERROR, "Invalid input pixfmt (%d).\n",
+   ctx->input_frames->sw_format);
+return AVERROR(EINVAL);
+}
+depth = desc->comp[0].depth;
+for (i = 1; i < desc->nb_components; i++) {
+if (desc->comp[i].depth != depth) {
+av_log(avctx, AV_LOG_ERROR, "Invalid input pixfmt (%s).\n",
+   desc->name);
+return AVERROR(EINVAL);
+}
+}
+av_log(avctx, AV_LOG_VERBOSE, "Input surface format is %s.\n",
+   desc->name);
 
 n = vaMaxNumProfiles(ctx->hwctx->display);
-profiles = av_malloc_array(n, sizeof(VAProfile));
-if (!profiles) {
+va_profiles = av_malloc_array(n, sizeof(VAProfile));
+if (!va_profiles) {
 err = AVERROR(ENOMEM);
 goto fail;
 }
-vas = vaQueryConfigProfiles(ctx->hwctx->display, profiles, );
+vas = vaQueryConfigProfiles(ctx->hwctx->display, va_profiles, );
 if (vas != VA_STATUS_SUCCESS) {
-av_log(ctx, AV_LOG_ERROR, "Failed to query 

[FFmpeg-devel] [PATCH 04/26] vaapi_encode_mpeg2: Move common structure into context

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_mpeg2.c | 50 -
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 42df77ea49..5dd1f39cbc 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -28,6 +28,9 @@
 #include "vaapi_encode.h"
 
 typedef struct VAAPIEncodeMPEG2Context {
+VAAPIEncodeContext common;
+
+// Derived settings.
 int mb_width;
 int mb_height;
 
@@ -35,15 +38,6 @@ 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;
 
@@ -52,6 +46,17 @@ typedef struct VAAPIEncodeMPEG2Context {
 unsigned int f_code_horizontal;
 unsigned int f_code_vertical;
 
+// Stream state.
+int64_t last_i_frame;
+
+// Writer structures.
+MPEG2RawSequenceHeader sequence_header;
+MPEG2RawExtensionData  sequence_extension;
+MPEG2RawExtensionData  sequence_display_extension;
+MPEG2RawGroupOfPicturesHeader gop_header;
+MPEG2RawPictureHeader  picture_header;
+MPEG2RawExtensionData  picture_coding_extension;
+
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMPEG2Context;
@@ -61,8 +66,7 @@ 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;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, frag);
@@ -88,8 +92,7 @@ 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;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL);
@@ -105,8 +108,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext 
*avctx,
 static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
 char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 CodedBitstreamFragment  *frag = >current_fragment;
 int err;
 
@@ -140,8 +142,7 @@ static int 
vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 CodedBitstreamFragment  *frag = >current_fragment;
 int err;
 
@@ -164,7 +165,7 @@ fail:
 static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context   *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context   *priv = avctx->priv_data;
 MPEG2RawSequenceHeader  *sh = >sequence_header;
 MPEG2RawSequenceExtension   *se = 
>sequence_extension.data.sequence;
 MPEG2RawSequenceDisplayExtension   *sde = 
>sequence_display_extension.data.sequence_display;
@@ -416,8 +417,7 @@ static int 
vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
  VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext*ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context  *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context  *priv = avctx->priv_data;
 MPEG2RawPictureHeader  *ph = >picture_header;
 MPEG2RawPictureCodingExtension*pce = 
>picture_coding_extension.data.picture_coding;
 VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params;
@@ -482,9 +482,8 @@ static int 
vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
VAAPIEncodeSlice 

[FFmpeg-devel] [PATCH 03/26] vaapi_encode_mjpeg: Move common structure into context

2018-04-22 Thread Mark Thompson
---
 libavcodec/vaapi_encode_mjpeg.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index c949e89646..983c77d194 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -56,6 +56,8 @@ static const unsigned char 
vaapi_encode_mjpeg_quant_chrominance[64] = {
 };
 
 typedef struct VAAPIEncodeMJPEGContext {
+VAAPIEncodeContext common;
+
 int quality;
 int component_subsample_h[3];
 int component_subsample_v[3];
@@ -83,8 +85,7 @@ static av_cold void vaapi_encode_mjpeg_copy_huffman(unsigned 
char *dst_lengths,
 
 static av_cold void vaapi_encode_mjpeg_init_tables(AVCodecContext *avctx)
 {
-VAAPIEncodeContext*ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext  *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext  *priv = avctx->priv_data;
 VAQMatrixBufferJPEG *quant = >quant_tables;
 VAHuffmanTableBufferJPEGBaseline *huff = >huffman_tables;
 int i;
@@ -133,10 +134,9 @@ static int 
vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx,
  VAAPIEncodeSlice *slice,
  char *data, size_t *data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params;
 VAEncSliceParameterBufferJPEG *vslice = slice->codec_slice_params;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
 PutBitContext pbc;
 int t, i, quant_scale;
 
@@ -242,8 +242,7 @@ static int 
vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
  int index, int *type,
  char *data, size_t *data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 
 if (index == 0) {
 // Write quantisation tables.
@@ -270,9 +269,8 @@ static int 
vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
 static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
   VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
 
 vpic->reconstructed_picture = pic->recon_surface;
 vpic->coded_buf = pic->output_buffer;
@@ -336,7 +334,7 @@ static int 
vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx,
 static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 {
 VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 
 priv->quality = avctx->global_quality;
 if (priv->quality < 1 || priv->quality > 100) {
@@ -417,7 +415,7 @@ AVCodec ff_mjpeg_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("MJPEG (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_MJPEG,
-.priv_data_size = sizeof(VAAPIEncodeContext),
+.priv_data_size = sizeof(VAAPIEncodeMJPEGContext),
 .init   = _encode_mjpeg_init,
 .encode2= _vaapi_encode2,
 .close  = _vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 02/26] vaapi_encode_h265: Move options and common structures into context

2018-04-22 Thread Mark Thompson
Matching previous commit for H.264.
---
 libavcodec/vaapi_encode_h265.c | 114 +++--
 1 file changed, 54 insertions(+), 60 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 5203c6871d..ba6b426eed 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -35,6 +35,15 @@
 
 
 typedef struct VAAPIEncodeH265Context {
+VAAPIEncodeContext common;
+
+// User options.
+int qp;
+int aud;
+int profile;
+int level;
+
+// Derived settings.
 unsigned int ctu_width;
 unsigned int ctu_height;
 
@@ -42,12 +51,7 @@ typedef struct VAAPIEncodeH265Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
-H265RawAUD aud;
-H265RawVPS vps;
-H265RawSPS sps;
-H265RawPPS pps;
-H265RawSlice slice;
-
+// Stream state.
 int64_t last_idr_frame;
 int pic_order_cnt;
 
@@ -55,25 +59,24 @@ typedef struct VAAPIEncodeH265Context {
 int slice_type;
 int pic_type;
 
+// Writer structures.
+H265RawAUD   raw_aud;
+H265RawVPS   raw_vps;
+H265RawSPS   raw_sps;
+H265RawPPS   raw_pps;
+H265RawSlice raw_slice;
+
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
 int aud_needed;
 } VAAPIEncodeH265Context;
 
-typedef struct VAAPIEncodeH265Options {
-int qp;
-int aud;
-int profile;
-int level;
-} VAAPIEncodeH265Options;
-
 
 static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx,
char *data, size_t *data_len,
CodedBitstreamFragment *au)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, au);
@@ -99,8 +102,7 @@ static int vaapi_encode_h265_add_nal(AVCodecContext *avctx,
  CodedBitstreamFragment *au,
  void *nal_unit)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 H265RawNALUnitHeader *header = nal_unit;
 int err;
 
@@ -118,27 +120,26 @@ static int vaapi_encode_h265_add_nal(AVCodecContext 
*avctx,
 static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h265_add_nal(avctx, au, >aud);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h265_add_nal(avctx, au, >vps);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_vps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h265_add_nal(avctx, au, >sps);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_sps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h265_add_nal(avctx, au, >pps);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_pps);
 if (err < 0)
 goto fail;
 
@@ -153,19 +154,18 @@ static int 
vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
 VAAPIEncodeSlice *slice,
 char *data, size_t *data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h265_add_nal(avctx, au, >aud);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h265_add_nal(avctx, au, >slice);
+err = vaapi_encode_h265_add_nal(avctx, au, >raw_slice);
 if (err < 0)
 goto fail;
 
@@ -178,10 +178,10 @@ fail:
 static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 {
 VAAPIEncodeContext*ctx = avctx->priv_data;
-VAAPIEncodeH265Context   *priv = ctx->priv_data;
-H265RawVPS*vps = >vps;
-H265RawSPS*sps = >sps;
-H265RawPPS*pps = >pps;
+VAAPIEncodeH265Context   *priv = avctx->priv_data;
+H265RawVPS*vps = >raw_vps;
+H265RawSPS*sps = >raw_sps;
+H265RawPPS*pps 

[FFmpeg-devel] [PATCH 01/26] vaapi_encode_h264: Move options and common structures into context

2018-04-22 Thread Mark Thompson
This will make it easier to support options in common between different
encoders.  It also cleans up some of the field naming.
---
 libavcodec/vaapi_encode_h264.c | 228 +
 1 file changed, 115 insertions(+), 113 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 56ad217b4a..cc163151a6 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -47,6 +47,19 @@ static const uint8_t 
vaapi_encode_h264_sei_identifier_uuid[16] = {
 };
 
 typedef struct VAAPIEncodeH264Context {
+VAAPIEncodeContext common;
+
+// User options.
+int qp;
+int quality;
+int low_power;
+int coder;
+int aud;
+int sei;
+int profile;
+int level;
+
+// Derived settings.
 int mb_width;
 int mb_height;
 
@@ -54,18 +67,7 @@ typedef struct VAAPIEncodeH264Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
-H264RawAUD aud;
-H264RawSPS sps;
-H264RawPPS pps;
-H264RawSEI sei;
-H264RawSlice slice;
-
-H264RawSEIBufferingPeriod buffering_period;
-H264RawSEIPicTiming pic_timing;
-H264RawSEIRecoveryPoint recovery_point;
-H264RawSEIUserDataUnregistered identifier;
-char *identifier_string;
-
+// Stream state.
 int frame_num;
 int pic_order_cnt;
 int next_frame_num;
@@ -78,32 +80,33 @@ typedef struct VAAPIEncodeH264Context {
 int cpb_delay;
 int dpb_delay;
 
+// Writer structures.
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
+
+H264RawAUD   raw_aud;
+H264RawSPS   raw_sps;
+H264RawPPS   raw_pps;
+H264RawSEI   raw_sei;
+H264RawSlice raw_slice;
+
+H264RawSEIBufferingPeriod  sei_buffering_period;
+H264RawSEIPicTimingsei_pic_timing;
+H264RawSEIRecoveryPointsei_recovery_point;
+H264RawSEIUserDataUnregistered sei_identifier;
+char  *sei_identifier_string;
+
 int aud_needed;
 int sei_needed;
 int sei_cbr_workaround_needed;
 } VAAPIEncodeH264Context;
 
-typedef struct VAAPIEncodeH264Options {
-int qp;
-int quality;
-int low_power;
-// Entropy encoder type.
-int coder;
-int aud;
-int sei;
-int profile;
-int level;
-} VAAPIEncodeH264Options;
-
 
 static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx,
char *data, size_t *data_len,
CodedBitstreamFragment *au)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, au);
@@ -129,8 +132,7 @@ static int vaapi_encode_h264_add_nal(AVCodecContext *avctx,
  CodedBitstreamFragment *au,
  void *nal_unit)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 H264RawNALUnitHeader *header = nal_unit;
 int err;
 
@@ -148,23 +150,22 @@ static int vaapi_encode_h264_add_nal(AVCodecContext 
*avctx,
 static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h264_add_nal(avctx, au, >aud);
+err = vaapi_encode_h264_add_nal(avctx, au, >raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h264_add_nal(avctx, au, >sps);
+err = vaapi_encode_h264_add_nal(avctx, au, >raw_sps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h264_add_nal(avctx, au, >pps);
+err = vaapi_encode_h264_add_nal(avctx, au, >raw_pps);
 if (err < 0)
 goto fail;
 
@@ -179,19 +180,18 @@ static int 
vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
 VAAPIEncodeSlice *slice,
 char *data, size_t *data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h264_add_nal(avctx, au, >aud);
+err = vaapi_encode_h264_add_nal(avctx, au, >raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h264_add_nal(avctx, 

[FFmpeg-devel] [PATCH 00/26] VAAPI encode miscellaneous improvements

2018-04-22 Thread Mark Thompson
Stuff:
* Refactor to make the setup process and options generally more sensible.
* Dynamically choose profile (don't require that the user sets it for e.g. 
10-bit H.265).
* Cleaned rate control setup (better debug and fix overflows).
* Better explanation of packed header problems (for the Mesa encoder which 
can't do extradata).
* Enough CBS JPEG support to use it for VAAPI encode.
* Adds support for 4:2:2 and 4:4:4 JPEGs.
* H.264 level set automatically to a likely-correct value.
* Documentation for all of that.


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


Re: [FFmpeg-devel] [PATCH 1/2] lavu/opt: add AV_OPT_FLAG_DEPRECATED

2018-04-22 Thread wm4
On Sun, 22 Apr 2018 16:38:08 +0200
Clément Bœsch  wrote:

> ---
> TODO: APIChanges + lavu minor bump (not done yet because it will
> conflict with the threadmessage patch)
> ---
>  libavutil/opt.c | 6 ++
>  libavutil/opt.h | 1 +
>  2 files changed, 7 insertions(+)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 3b0aab4ee8..99282605f5 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -463,6 +463,9 @@ int av_opt_set(void *obj, const char *name, const char 
> *val, int search_flags)
>  if (o->flags & AV_OPT_FLAG_READONLY)
>  return AVERROR(EINVAL);
>  
> +if (o->flags & AV_OPT_FLAG_DEPRECATED)
> +av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", 
> name, o->help);
> +
>  dst = ((uint8_t *)target_obj) + o->offset;
>  switch (o->type) {
>  case AV_OPT_TYPE_BOOL:
> @@ -759,6 +762,9 @@ int av_opt_get(void *obj, const char *name, int 
> search_flags, uint8_t **out_val)
>  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
>  return AVERROR_OPTION_NOT_FOUND;
>  
> +if (o->flags & AV_OPT_FLAG_DEPRECATED)
> +av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", 
> name, o->help);
> +
>  dst = (uint8_t *)target_obj + o->offset;
>  
>  buf[0] = 0;
> diff --git a/libavutil/opt.h b/libavutil/opt.h
> index 07da68ea23..1352741fb6 100644
> --- a/libavutil/opt.h
> +++ b/libavutil/opt.h
> @@ -289,6 +289,7 @@ typedef struct AVOption {
>  #define AV_OPT_FLAG_READONLY128
>  #define AV_OPT_FLAG_BSF_PARAM   (1<<8) ///< a generic parameter which 
> can be set by the user for bit stream filtering
>  #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which 
> can be set by the user for filtering
> +#define AV_OPT_FLAG_DEPRECATED  (1<<17)
>  //FIXME think about enc-audio, ... style flags
>  
>  /**

Seems like a good idea.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] lavf/http: use AV_OPT_FLAG_DEPRECATED for user-agent option

2018-04-22 Thread Clément Bœsch
---
There are probably a bunch of other options and I don't plan to look for
them, I just needed at least one example of use.
---
 libavformat/http.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index aa6348f28b..3a35bc7eac 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -141,7 +141,7 @@ static const AVOption options[] = {
 { "user_agent", "override User-Agent header", OFFSET(user_agent), 
AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
 { "referer", "override referer header", OFFSET(referer), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 #if FF_API_HTTP_USER_AGENT
-{ "user-agent", "override User-Agent header", 
OFFSET(user_agent_deprecated), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT 
}, 0, 0, D },
+{ "user-agent", "use the \"user_agent\" option instead", 
OFFSET(user_agent_deprecated), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT 
}, 0, 0, D|AV_OPT_FLAG_DEPRECATED },
 #endif
 { "multiple_requests", "use persistent connections", 
OFFSET(multiple_requests), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D | E },
 { "post_data", "set custom HTTP post data", OFFSET(post_data), 
AV_OPT_TYPE_BINARY, .flags = D | E },
@@ -1193,7 +1193,6 @@ static int http_connect(URLContext *h, const char *path, 
const char *local_path,
 
 #if FF_API_HTTP_USER_AGENT
 if (strcmp(s->user_agent_deprecated, DEFAULT_USER_AGENT)) {
-av_log(s, AV_LOG_WARNING, "the user-agent option is deprecated, please 
use user_agent option\n");
 s->user_agent = av_strdup(s->user_agent_deprecated);
 }
 #endif
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/2] lavu/opt: add AV_OPT_FLAG_DEPRECATED

2018-04-22 Thread Clément Bœsch
---
TODO: APIChanges + lavu minor bump (not done yet because it will
conflict with the threadmessage patch)
---
 libavutil/opt.c | 6 ++
 libavutil/opt.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 3b0aab4ee8..99282605f5 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -463,6 +463,9 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 if (o->flags & AV_OPT_FLAG_READONLY)
 return AVERROR(EINVAL);
 
+if (o->flags & AV_OPT_FLAG_DEPRECATED)
+av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", 
name, o->help);
+
 dst = ((uint8_t *)target_obj) + o->offset;
 switch (o->type) {
 case AV_OPT_TYPE_BOOL:
@@ -759,6 +762,9 @@ int av_opt_get(void *obj, const char *name, int 
search_flags, uint8_t **out_val)
 if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
 return AVERROR_OPTION_NOT_FOUND;
 
+if (o->flags & AV_OPT_FLAG_DEPRECATED)
+av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", 
name, o->help);
+
 dst = (uint8_t *)target_obj + o->offset;
 
 buf[0] = 0;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 07da68ea23..1352741fb6 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -289,6 +289,7 @@ typedef struct AVOption {
 #define AV_OPT_FLAG_READONLY128
 #define AV_OPT_FLAG_BSF_PARAM   (1<<8) ///< a generic parameter which can 
be set by the user for bit stream filtering
 #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can 
be set by the user for filtering
+#define AV_OPT_FLAG_DEPRECATED  (1<<17)
 //FIXME think about enc-audio, ... style flags
 
 /**
-- 
2.17.0

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


[FFmpeg-devel] [PATCH] libavformat: add mbedTLS based TLS

2018-04-22 Thread Thomas Volkert
From: Thomas Volkert 

---
 Changelog |   1 +
 configure |  31 ++--
 libavformat/Makefile  |   1 +
 libavformat/rtmpdh.c  |  55 
 libavformat/rtmpdh.h  |   5 +
 libavformat/tls_mbedtls.c | 351 ++
 libavformat/version.h |   2 +-
 7 files changed, 436 insertions(+), 10 deletions(-)
 create mode 100644 libavformat/tls_mbedtls.c

diff --git a/Changelog b/Changelog
index 3ed4874..0a344f3 100644
--- a/Changelog
+++ b/Changelog
@@ -3,6 +3,7 @@ releases are sorted from youngest to oldest.
 
 version :
 - deblock filter
+- support mbedTLS based TLS
 
 
 version 4.0:
diff --git a/configure b/configure
index dee507c..6420c55 100755
--- a/configure
+++ b/configure
@@ -213,7 +213,7 @@ External library support:
   --enable-gmp enable gmp, needed for rtmp(t)e support
if openssl or librtmp is not used [no]
   --enable-gnutls  enable gnutls, needed for https support
-   if openssl or libtls is not used [no]
+   if openssl, libtls or mbedtls is not used [no]
   --disable-iconv  disable iconv [autodetect]
   --enable-jni enable JNI support [no]
   --enable-ladspa  enable LADSPA audio filtering [no]
@@ -262,7 +262,7 @@ External library support:
   --enable-libtesseractenable Tesseract, needed for ocr filter [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
   --enable-libtls  enable LibreSSL (via libtls), needed for https 
support
-   if openssl or gnutls is not used [no]
+   if openssl, gnutls or mbedtls is not used [no]
   --enable-libtwolame  enable MP2 encoding via libtwolame [no]
   --enable-libv4l2 enable libv4l2/v4l-utils [no]
   --enable-libvidstab  enable video stabilization using vid.stab [no]
@@ -290,13 +290,15 @@ External library support:
   --disable-lzma   disable lzma [autodetect]
   --enable-decklinkenable Blackmagic DeckLink I/O support [no]
   --enable-libndi_newtek   enable Newteck NDI I/O support [no]
+  --enable-mbedtls enable mbedTLS, needed for https support
+   if openssl, gnutls or libtls is not used [no]
   --enable-mediacodec  enable Android MediaCodec support [no]
   --enable-libmysofa   enable libmysofa, needed for sofalizer filter [no]
   --enable-openal  enable OpenAL 1.1 capture support [no]
   --enable-opencl  enable OpenCL processing [no]
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
-   if gnutls or libtls is not used [no]
+   if gnutls, libtls or mbedtls is not used [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1638,6 +1640,7 @@ EXTERNAL_LIBRARY_GPL_LIST="
 libx265
 libxavs
 libxvid
+mbedtls
 "
 
 EXTERNAL_LIBRARY_NONFREE_LIST="
@@ -3117,7 +3120,7 @@ fifo_muxer_deps="threads"
 flac_demuxer_select="flac_parser"
 hds_muxer_select="flv_muxer"
 hls_muxer_select="mpegts_muxer"
-hls_muxer_suggest="gcrypt openssl"
+hls_muxer_suggest="gcrypt openssl mbedtls"
 image2_alias_pix_demuxer_select="image2_demuxer"
 image2_brender_pix_demuxer_select="image2_demuxer"
 ipod_muxer_select="mov_muxer"
@@ -3229,7 +3232,7 @@ xv_outdev_extralibs="-lXv -lX11 -lXext"
 async_protocol_deps="threads"
 bluray_protocol_deps="libbluray"
 ffrtmpcrypt_protocol_conflict="librtmp_protocol"
-ffrtmpcrypt_protocol_deps_any="gcrypt gmp openssl"
+ffrtmpcrypt_protocol_deps_any="gcrypt gmp openssl mbedtls"
 ffrtmpcrypt_protocol_select="tcp_protocol"
 ffrtmphttp_protocol_conflict="librtmp_protocol"
 ffrtmphttp_protocol_select="http_protocol"
@@ -3249,7 +3252,7 @@ librtmpt_protocol_deps="librtmp"
 librtmpte_protocol_deps="librtmp"
 libsmbclient_protocol_deps="libsmbclient gplv3"
 libssh_protocol_deps="libssh"
-libtls_conflict="openssl gnutls"
+libtls_conflict="openssl gnutls mbedtls"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
 libsrt_protocol_deps="libsrt"
@@ -3269,13 +3272,13 @@ rtmpte_protocol_suggest="zlib"
 rtmpts_protocol_select="ffrtmphttp_protocol https_protocol"
 rtmpts_protocol_suggest="zlib"
 rtp_protocol_select="udp_protocol"
-schannel_conflict="openssl gnutls libtls"
+schannel_conflict="openssl gnutls libtls mbedtls"
 sctp_protocol_deps="struct_sctp_event_subscribe struct_msghdr_msg_flags"
 sctp_protocol_select="network"
-securetransport_conflict="openssl gnutls libtls"
+securetransport_conflict="openssl gnutls libtls mbedtls"
 srtp_protocol_select="rtp_protocol srtp"
 tcp_protocol_select="network"
-tls_protocol_deps_any="gnutls openssl schannel 

Re: [FFmpeg-devel] [PATCHv2 3/4] avutil/pixdesc: add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8

2018-04-22 Thread wm4
On Sun, 22 Apr 2018 13:24:11 +0200 (CEST)
Marton Balint  wrote:

> On Fri, 20 Apr 2018, wm4 wrote:
> 
> > On Thu, 19 Apr 2018 23:25:03 +0200
> > Marton Balint  wrote:
> >  
> >> Signed-off-by: Marton Balint 
> >> ---
> >>  doc/APIchanges| 3 +++
> >>  libavutil/pixdesc.c   | 3 +--
> >>  libavutil/pixdesc.h   | 8 ++--
> >>  libavutil/tests/pixdesc.c | 4 
> >>  libavutil/version.h   | 2 +-
> >>  5 files changed, 7 insertions(+), 13 deletions(-)
> >> 
> >> diff --git a/doc/APIchanges b/doc/APIchanges
> >> index 4f6ac2a031..d9b457e080 100644
> >> --- a/doc/APIchanges
> >> +++ b/doc/APIchanges
> >> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
> >>
> >>  API changes, most recent first:
> >> 
> >> +2018-04-xx - xx - lavu 56.16.100 - pixdesc.h
> >> +  Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
> >> +  
> 
> [..]
> 
> >
> > Probably fine. While I like it, we also have to be careful about the
> > consequences. Does it change FATE or the results of that pixfmt choosing
> > function, avcodec_find_best_pix_fmt_of_list()?  
> 
> Fate passes. I am not sure about avcodec_find_best_pix_fmt_of_list(), but 
> since pixdesc_has_alpha() in avutil/pixdesc.c already considered PAL8 as a 
> format with alpha, I don't think it changes.

Oh, interesting point. So this whole discussion is moot anyway, since
it always suggested RGBA when converting PAL8 to a non-paletted RGB
format?

> > Are there any formats
> > that decode to PAL8, but write garbage to the alpha component of the
> > palette?  
> 
> If there are, then those should be fixed. The damage was already done when 
> it was decided to consider PAL8 a format with alpha, so in some cases 
> garbage was already used...

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


Re: [FFmpeg-devel] [PATCH 2/4] avfilter/avfiltergraph: fix has_alpha in pick_format

2018-04-22 Thread wm4
On Sun, 22 Apr 2018 13:44:19 +0200 (CEST)
Marton Balint  wrote:

> On Fri, 20 Apr 2018, Michael Niedermayer wrote:
> 
> > On Thu, Apr 19, 2018 at 09:32:19PM +0200, Marton Balint wrote:  
> >> A pixel format which has a palette also has alpha, without this patch the
> >> format negotiation might have preferred formats without alpha even if the
> >> source had alpha.
> >>
> >> Signed-off-by: Marton Balint 
> >> ---
> >>  libavfilter/avfiltergraph.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> >> index 4cc6892404..e18f733e23 100644
> >> --- a/libavfilter/avfiltergraph.c
> >> +++ b/libavfilter/avfiltergraph.c
> >> @@ -679,7 +679,7 @@ static int pick_format(AVFilterLink *link, 
> >> AVFilterLink *ref)
> >>
> >>  if (link->type == AVMEDIA_TYPE_VIDEO) {
> >>  if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
> >> -int has_alpha= 
> >> av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
> >> +int has_alpha= 
> >> av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0 || 
> >> (av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_PAL);  
> >
> > This causes various output files to grow in size with a unused alpha plane
> >
> > a random example: (there are likels better examples)
> > ./ffmpeg -y -i ~/tickets/1116/1023.bmp -vf negate fileX.bmp
> >
> > Iam not sure unconditionally treating all palettes as if they have
> > non fully opaque entries is a good idea.  
> 
> Obviously not, but it is already treated this way in most places. Having a 
> bigger image with alpha is better than losing alpha. And the user can 
> always force losing alpha with a filter, and sometimes he has to do that 
> anyway because for example fre0r filters have no way of signalling if they 
> use alpha or not...
> 
> >
> > Doesnt this patchset replace a problem by another problem ?
> > It may be better to not rush this and find a complete solution
> >
> > a 2nd pixfmt and or scaning the 256 entries for their alpha values
> > is maybe the direction we could go  
> 
> I don't think scaning can work for anything other than still images, as 
> the palette can change per-frame AFAIK. Introducing a new pixel format 
> seems the better approach, however keeping in mind compatibility and 
> existing code, I'd rather make the newly introduced one the one without 
> alpha, and move things gradually to it. Still seems like a fair amount of 
> work...

PAL8 has the same problem as RGBA formats: you can't know whether it's
going to use alpha or not. (Indeed, there are codecs which can update
the palette, and who says filters won't change the palette?) With PAL8
it's just faster to verify for a particular frame. But in general, you
have to know in advance, and have to signal it in advance. I think that
works relatively well with PIXFMT_RGBA vs. PIXFMT_RGB0.

So I would argue it's fine to change PAL8 to having alpha, and if we
find cases that would really benefit from it, add PIXFMT_PAL8_RGB0. (Or
_RGBX or _NO_ALPHA or whatever.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/8] lavu: add a Vulkan hwcontext

2018-04-22 Thread Mark Thompson
On 21/04/18 23:29, Carl Eugen Hoyos wrote:
> 2018-04-21 23:33 GMT+02:00, Rostislav Pehlivanov :
>> On 21 April 2018 at 21:24, Carl Eugen Hoyos  wrote:
>>
>>> 2018-04-20 6:30 GMT+02:00, Rostislav Pehlivanov :
>>>
 +[AV_PIX_FMT_P010]  =
 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
>>>
 +[AV_PIX_FMT_YUV420P10] =
 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
>>>
>>> I don't think both can be correct (unless "PACK16" has no meaning).
> 
>> They're both correct and work.
> 
> That's really strange...
> (Could this be a bug in the driver?)

Sounds like it must be a bug somewhere.

The Vulkan specification says:

"""
VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 specifies a unsigned 
normalized multi-planar format that has a 10-bit G component in the top 10 bits 
of each 16-bit word of plane 0, and a two-component, 32-bit BR plane 1 
consisting of a 10-bit B component in the top 10 bits of the word in bytes 
0..1, and a 10-bit R component in the top 10 bits of the word in bytes 2..3, 
the bottom 6 bits of each word set to 0.

VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 specifies a unsigned 
normalized multi-planar format that has a 10-bit G component in the top 10 bits 
of each 16-bit word of plane 0, a 10-bit B component in the top 10 bits of each 
16-bit word of plane 1, and a 10-bit R component in the top 10 bits of each 
16-bit word of plane 2, with the bottom 6 bits of each word set to 0.
"""

Which I think makes it pretty clear that 
VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 is indeed P010 but 
VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 isn't YUV420P10 because 
they pack the 10 bits at different ends of the 16-bit value.  If a driver is 
getting that wrong then it should be reported to the vendor.

I don't see any formats at all in the Vulkan specification which put the value 
at the low end of a containing word, but I might not be looking in the right 
place?

- Mark


(Vaguely related, because it made me look it up, it appears that the device 
will always match host-endianness:

After talking about the numeric types,
"""
The representation and endianness of these types on the host must match the 
representation and endianness of the same types on every physical device 
supported."
"""

I don't know what that actually means for little-endian graphics cards (e.g. 
AMD/Nvidia) in big-endian machines (e.g. POWER) - maybe Vulkan just doesn't 
support that, or maybe the driver can fix it up somehow - but we don't need to 
think about it at all.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/4] avfilter/avfiltergraph: fix has_alpha in pick_format

2018-04-22 Thread Marton Balint



On Fri, 20 Apr 2018, Michael Niedermayer wrote:


On Thu, Apr 19, 2018 at 09:32:19PM +0200, Marton Balint wrote:

A pixel format which has a palette also has alpha, without this patch the
format negotiation might have preferred formats without alpha even if the
source had alpha.

Signed-off-by: Marton Balint 
---
 libavfilter/avfiltergraph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 4cc6892404..e18f733e23 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -679,7 +679,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink 
*ref)

 if (link->type == AVMEDIA_TYPE_VIDEO) {
 if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
-int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 
== 0;
+int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0 || 
(av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_PAL);


This causes various output files to grow in size with a unused alpha plane

a random example: (there are likels better examples)
./ffmpeg -y -i ~/tickets/1116/1023.bmp -vf negate fileX.bmp

Iam not sure unconditionally treating all palettes as if they have
non fully opaque entries is a good idea.


Obviously not, but it is already treated this way in most places. Having a 
bigger image with alpha is better than losing alpha. And the user can 
always force losing alpha with a filter, and sometimes he has to do that 
anyway because for example fre0r filters have no way of signalling if they 
use alpha or not...




Doesnt this patchset replace a problem by another problem ?
It may be better to not rush this and find a complete solution

a 2nd pixfmt and or scaning the 256 entries for their alpha values
is maybe the direction we could go


I don't think scaning can work for anything other than still images, as 
the palette can change per-frame AFAIK. Introducing a new pixel format 
seems the better approach, however keeping in mind compatibility and 
existing code, I'd rather make the newly introduced one the one without 
alpha, and move things gradually to it. Still seems like a fair amount of 
work...


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


Re: [FFmpeg-devel] [PATCHv2 3/4] avutil/pixdesc: add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8

2018-04-22 Thread Marton Balint



On Fri, 20 Apr 2018, wm4 wrote:


On Thu, 19 Apr 2018 23:25:03 +0200
Marton Balint  wrote:


Signed-off-by: Marton Balint 
---
 doc/APIchanges| 3 +++
 libavutil/pixdesc.c   | 3 +--
 libavutil/pixdesc.h   | 8 ++--
 libavutil/tests/pixdesc.c | 4 
 libavutil/version.h   | 2 +-
 5 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 4f6ac2a031..d9b457e080 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21

 API changes, most recent first:

+2018-04-xx - xx - lavu 56.16.100 - pixdesc.h
+  Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
+


[..]



Probably fine. While I like it, we also have to be careful about the
consequences. Does it change FATE or the results of that pixfmt choosing
function, avcodec_find_best_pix_fmt_of_list()?


Fate passes. I am not sure about avcodec_find_best_pix_fmt_of_list(), but 
since pixdesc_has_alpha() in avutil/pixdesc.c already considered PAL8 as a 
format with alpha, I don't think it changes.



Are there any formats
that decode to PAL8, but write garbage to the alpha component of the
palette?


If there are, then those should be fixed. The damage was already done when 
it was decided to consider PAL8 a format with alpha, so in some cases 
garbage was already used...


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


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Marton Balint



On Sun, 22 Apr 2018, Clément Bœsch wrote:


On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
[...]

I think av_thread_message_queue_elems would be a better name, had to think
for a good period of time what "nelem" meant.


I'm afraid of "queue_elems" implying "queuing elements" so I went for
the more explicit av_thread_message_queue_nb_elems() instead.


I generally prefer nb_items instead of nb_elems. Use whichever you like.

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


Re: [FFmpeg-devel] [PATCH]lavf/dashdec: Do not use memcpy() to copy a struct

2018-04-22 Thread wm4
On Sun, 22 Apr 2018 08:41:18 +0800
Liu Steven  wrote:

> > 在 2018年4月22日,上午5:23,wm4  写道:
> > 
> > On Sat, 21 Apr 2018 22:55:33 +0200
> > Carl Eugen Hoyos  wrote:
> >   
> >> 2018-04-19 4:45 GMT+02:00, Steven Liu :  
> >>> 
> >>>   
>  On 19 Apr 2018, at 03:20, wm4  wrote:
>  
>  On Wed, 18 Apr 2018 16:10:26 -0300
>  James Almer  wrote:
>    
> > On 4/18/2018 2:45 PM, Carl Eugen Hoyos wrote:
> >> Hi!
> >> 
> >> Attached patch is supposed to fix a warning (and a bug), is this the
> >> right and preferred fix?
> >> 
> >> Please comment, Carl Eugen
> >> 
> >> 
> >> 0001-lavf-dashdec-Do-not-use-memcpy-to-copy-a-struct.patch
> >> 
> >> 
> >> From cf7d2aefc1a3b3a2e9f578ede43906ed6ee96bfd Mon Sep 17 00:00:00 2001
> >> From: Carl Eugen Hoyos 
> >> Date: Wed, 18 Apr 2018 19:42:57 +0200
> >> Subject: [PATCH] lavf/dashdec: Do not use memcpy() to copy a struct.
> >> 
> >> Fixes a warning:
> >> libavformat/dashdec.c:1900:65: warning: argument to 'sizeof' in 
> >> 'memcpy'
> >> call is the same pointer type 'struct fragment *' as the destination;
> >> expected 'struct fragment' or an explicit length
> >> ---
> >> libavformat/dashdec.c |2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> >> index 6304ad9..917fb54 100644
> >> --- a/libavformat/dashdec.c
> >> +++ b/libavformat/dashdec.c
> >> @@ -1897,7 +1897,7 @@ static int init_section_compare_audio(DASHContext
> >> *c)
> >> 
> >> static void copy_init_section(struct representation *rep_dest, struct
> >> representation *rep_src)
> >> {
> >> -memcpy(rep_dest->init_section, rep_src->init_section,
> >> sizeof(rep_src->init_section));
> >> +rep_dest->init_section = rep_src->init_section;
> > 
> > This would only copy the pointer. The fact memcpy was used here makes me
> > think the intention was to copy the contents of the struct, so something
> > like
> > 
> > *rep_dest->init_section = *rep_src->init_section;
> > 
> > or
> > 
> > memcpy(rep_dest->init_section, rep_src->init_section,
> > sizeof(*rep_src->init_section));
> > 
> > Would be the correct fix.
>  
>  The first version would be preferable. But I think the original code
>  makes no sense and was never really tested. Looking slightly closer at
>  the code, init_section points to a struct that contains a further
>  pointer, which would require allocating and dup'ing the memory.
>  
>  Also the rep_dest->init_sec_buf allocation call isn't even checked. It
>  just memcpy's to a NULL pointer. This is some seriously shit code, and
>  all of dashdec.c is shit. I'd like to ask Steven Liu (who
>  reviewed/pushed the patch that added this copy_init_section code) to
>  _actually_ review the patches and to keep up the quality standards in
>  this project (which are slightly higher than this).
> >>> Yes, that is my mistake, patch welcome and welcome you to contribute code
> >>> for refine the dashdec
> > 
> > The problem was that you didn't actually review the patch. There's
> > really no excuse for the code that has been added. It's not even valid
> > C. It's sort of your responsibility to make sure this doesn't happen.
> > Sorry if my words were a bit too direct, but for very new code dashdec
> > has a bit too many issues than it should have. Reviewing means more
> > than just replying "LGTM" and pushing a patch.  
> The problem is how do you check i have not check the patch is ok or not?
> Only myself review the patch, where are the other guys when i response LGTM?
> you guys can objections the patch, but no, isn’t it?

You read it carefully, maybe apply the thing locally, and build and
test it. Reviewing basically means checking a patch for errors. Point
out the errors by replying to the patch, and ask the patch author to
fix them.

The more you can trust the patch author the more checks you can skip,
but generally you should at least skim the patch for things that look
wrong. In this case there were a bunch of obviously suspicious things,
including things we don't normally do (like the missing memory
allocation failure check). Looking whether a patch causes new compiler
warnings is also a thing worth to do.

And yes, this can be significant work, but it's all so to make sure bugs
are avoided, and that nobody has to fix the mess later.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat: add mbedTLS based TLS

2018-04-22 Thread Thomas Volkert

On 22.04.2018 01:48, Carl Eugen Hoyos wrote:
> 2018-04-22 1:30 GMT+02:00, Hendrik Leppkes :
>> On Sat, Apr 21, 2018 at 10:15 PM, Carl Eugen Hoyos 
>> wrote:
>>> 2018-04-21 21:59 GMT+02:00, Thomas Volkert :
 On 21.04.2018 21:46, Carl Eugen Hoyos wrote:

> 2018-04-21 21:37 GMT+02:00, Hendrik Leppkes :
>> Can you elaborate what you think the problem is?
> Given that we allow muxing against gpl and Apache, I believe
> the patch can be improved.
 Okay, what do you suggest  in detail?
>>> I believe the easiest solution is to "require version 3"
>>> as we do for other Apache libraries (libvmaf and
>>> libopencore).
>>>
>> mbedTLS is dual-licensed under GPLv2 as well, so why
>> not allow it with GPL version 2 as well?
I had the same thoughts today (put mbedtls in the
EXTERNAL_LIBRARY_GPL_LIST list).
Maybe I will wait for other opinions for about 2 hours and then resend
the patch.

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


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Clément Bœsch
On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
[...]
> I think av_thread_message_queue_elems would be a better name, had to think
> for a good period of time what "nelem" meant.

I'm afraid of "queue_elems" implying "queuing elements" so I went for
the more explicit av_thread_message_queue_nb_elems() instead.

Also fixed the problem raised by Michael.

-- 
Clément B.
From 6647c716a31481b2d1348d03616557a63a6a0cef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= 
Date: Sat, 21 Apr 2018 21:42:19 +0200
Subject: [PATCH] lavu/threadmessage: add av_thread_message_queue_nb_elems()

---
 doc/APIchanges |  3 +++
 libavutil/threadmessage.c  | 13 +
 libavutil/threadmessage.h  |  5 +
 libavutil/version.h|  2 +-
 tests/api/api-threadmessage-test.c |  4 +++-
 5 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 4f6ac2a031..8d305d5867 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-04-xx - xx - lavu 56.16.100 - threadmessage.h
+  Add av_thread_message_queue_nb_elems().
+
  8< - FFmpeg 4.0 was cut here  8< -
 
 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
index 872e9392b1..764b7fb813 100644
--- a/libavutil/threadmessage.c
+++ b/libavutil/threadmessage.c
@@ -102,6 +102,19 @@ void av_thread_message_queue_free(AVThreadMessageQueue 
**mq)
 #endif
 }
 
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq)
+{
+#if HAVE_THREADS
+int ret;
+pthread_mutex_lock(>lock);
+ret = av_fifo_size(mq->fifo);
+pthread_mutex_unlock(>lock);
+return ret / mq->elsize;
+#else
+return AVERROR(ENOSYS);
+#endif
+}
+
 #if HAVE_THREADS
 
 static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
index 8480a0a3db..7ebf03a8ac 100644
--- a/libavutil/threadmessage.h
+++ b/libavutil/threadmessage.h
@@ -95,6 +95,11 @@ void 
av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
 void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
void (*free_func)(void *msg));
 
+/**
+ * Return the current number of messages in the queue.
+ */
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
+
 /**
  * Flush the message queue
  *
diff --git a/libavutil/version.h b/libavutil/version.h
index 387421775f..23567000a3 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  15
+#define LIBAVUTIL_VERSION_MINOR  16
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tests/api/api-threadmessage-test.c 
b/tests/api/api-threadmessage-test.c
index 05a8062b8c..3c693a70d1 100644
--- a/tests/api/api-threadmessage-test.c
+++ b/tests/api/api-threadmessage-test.c
@@ -130,7 +130,9 @@ static void *receiver_thread(void *arg)
 
 for (i = 0; i < rd->workload; i++) {
 if (rand() % rd->workload < rd->workload / 10) {
-av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue\n", 
rd->id);
+av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
+   "discarding %d message(s)\n", rd->id,
+   av_thread_message_queue_nb_elems(rd->queue));
 av_thread_message_flush(rd->queue);
 } else {
 struct message msg;
-- 
2.17.0



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