[FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-27 Thread Jun Zhao
fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
[libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid parameter
[libaom-av1 @ 0x469f340]   Additional information: g_threads out of range 
[..MAX_NUM_THREADS]

Signed-off-by: Jun Zhao 
---
 libavcodec/libaomenc.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index cb31c55..ccb0cf9 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 enccfg.g_h= avctx->height;
 enccfg.g_timebase.num = avctx->time_base.num;
 enccfg.g_timebase.den = avctx->time_base.den;
-enccfg.g_threads  = avctx->thread_count ? avctx->thread_count : 
av_cpu_count();
+enccfg.g_threads  =
+   FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64);
 
 if (ctx->lag_in_frames >= 0)
 enccfg.g_lag_in_frames = ctx->lag_in_frames;
-- 
1.7.1

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


Re: [FFmpeg-devel] [PATCH, v3] lavc/qsvenc: add VDENC support for H264

2018-11-27 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Linjie Fu
> Sent: Tuesday, November 27, 2018 2:49 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Fu, Linjie 
> Subject: [FFmpeg-devel] [PATCH,v3] lavc/qsvenc: add VDENC support for
> H264
> 
> Add VDENC(lowpower mode) support for QSV H264.
> 
> It's an experimental function(like lowpower in vaapi) with some limitations:
> - CBR/VBR require HuC which should be explicitly loaded via i915 module
> parameter(i915.enable_guc=2 for linux kernel version >= 4.16)
> 
> use option "-low_power 1" to enable VDENC.
> 
> Signed-off-by: Linjie Fu 
> ---
> [v2]: modified the commit message and option comments, use
> AV_OPT_TYPE_BOOL to replace AV_OPT_TYPE_INT.
> [v3]: enable H264 VDENC separately.
> 
>  libavcodec/qsvenc.c  | 3 +++
>  libavcodec/qsvenc.h  | 2 ++
>  libavcodec/qsvenc_h264.c | 3 +++
>  3 files changed, 8 insertions(+)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> 948751daf4..7a031297fe 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -464,6 +464,9 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  }
>  }
> 
> +#if QSV_HAVE_VDENC
> +q->param.mfx.LowPower   = q->low_power ?
> MFX_CODINGOPTION_ON:MFX_CODINGOPTION_OFF;
> +#endif

Could add LowPower information in dump_video_param()? 
Then user can check whether it has been enabled at runtime log message.

>  q->param.mfx.CodecProfile   = q->profile;
>  q->param.mfx.TargetUsage= avctx->compression_level;
>  q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index
> 50cc4267e7..a396aa7d3f 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -44,6 +44,7 @@
>  #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
>  #define QSV_HAVE_LA_DS  QSV_VERSION_ATLEAST(1, 8)  #define
> QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
> +#define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
> 
>  #if defined(_WIN32) || defined(__CYGWIN__)
>  #define QSV_HAVE_AVBR   QSV_VERSION_ATLEAST(1, 3)
> @@ -162,6 +163,7 @@ typedef struct QSVEncContext {
>  int recovery_point_sei;
> 
>  int a53_cc;
> +int low_power;
> 
>  #if QSV_HAVE_MF
>  int mfmode;
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c index
> 07c9d64e6b..8857959d39 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -153,6 +153,9 @@ static const AVOption options[] = {
>  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_MF_DISABLED }, INT_MIN, INT_MAX, VE, "mfmode" },
>  { "auto"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_MF_AUTO }, INT_MIN, INT_MAX, VE, "mfmode" },
>  #endif
> +#if QSV_HAVE_VDENC
> +{ "low_power", "enable low power mode (experimental, 

Should be "experimental:" instead of "experimental,"
And please also refer Moritz Barsnick's comment in the patch V2. 

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


Re: [FFmpeg-devel] [PATCH 3/3] qsvdec: Fix running with assert_level > 0

2018-11-27 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Sunday, November 11, 2018 11:32 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 3/3] qsvdec: Fix running with assert_level >
> 0
> 
> Assertion avctx->codec_id != AV_CODEC_ID_NONE failed at
> src/libavcodec/parser.c:128
> 
> The setting on the internal AVCodecContext used for parsing only is
> otherwise irrelevant, so just set it to avoid the assert.
> ---
>  libavcodec/qsvdec.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> 6753e596a1..4a0be811fb 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -501,6 +501,8 @@ int ff_qsv_process_data(AVCodecContext *avctx,
> QSVContext *q,
>  if (!q->avctx_internal)
>  return AVERROR(ENOMEM);
> 
> +q->avctx_internal->codec_id = avctx->codec_id;
> +
>  q->parser = av_parser_init(avctx->codec_id);
>  if (!q->parser)
>  return AVERROR(ENOMEM);
> --
> 2.19.1
> 
LGTM (And I am surprised it get cached so late).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/libopusenc: allow encoding channel mapping 2

2018-11-27 Thread Felicia Lim
Friendly ping. Please let me know if there are any changes I should make to
this patch?

Thanks!
Felicia



On Thu, Aug 9, 2018 at 6:41 AM Felicia Lim  wrote:

> I've attached the patch with the updated description, please let me know
> if I should make any other changes.
>
> Thanks,
> Felicia
>
>
> On Mon, Jul 30, 2018 at 10:50 AM Felicia Lim  wrote:
>
>> On Sat, Jul 28, 2018 at 10:46 AM Rostislav Pehlivanov <
>> atomnu...@gmail.com> wrote:
>>
>>> On 27 July 2018 at 20:44, Felicia Lim 
>>> wrote:
>>>
>>> > ---
>>> >  libavcodec/libopusenc.c | 22 ++
>>> >  1 file changed, 22 insertions(+)
>>> >
>>> > diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
>>> > index 4ae81b0bb2..6b450ec317 100644
>>> > --- a/libavcodec/libopusenc.c
>>> > +++ b/libavcodec/libopusenc.c
>>> > @@ -27,6 +27,7 @@
>>> >  #include "bytestream.h"
>>> >  #include "internal.h"
>>> >  #include "libopus.h"
>>> > +#include "mathops.h"
>>> >  #include "vorbis.h"
>>> >  #include "audio_frame_queue.h"
>>> >
>>> > @@ -200,6 +201,21 @@ static int
>>> libopus_check_vorbis_layout(AVCodecContext
>>> > *avctx, int mapping_family
>>> >  return 0;
>>> >  }
>>> >
>>> > +static int libopus_check_ambisonics_channels(AVCodecContext *avctx) {
>>> > +int channels = avctx->channels;
>>> > +int ambisonic_order = ff_sqrt(channels) - 1;
>>> > +if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)) &&
>>> > +channels != ((ambisonic_order + 1) * (ambisonic_order + 1) +
>>> 2)) {
>>> > +av_log(avctx, AV_LOG_ERROR,
>>> > +   "Ambisonics coding is only specified for channel
>>> counts"
>>> > +   " which can be written as (n + 1)^2 or (n + 1)^2 + 2"
>>> > +   " for nonnegative integer n\n");
>>> > +return AVERROR_INVALIDDATA;
>>> > +}
>>> > +
>>> > +return 0;
>>> > +}
>>> > +
>>> >  static int libopus_validate_layout_and_get_channel_map(
>>> >  AVCodecContext *avctx,
>>> >  int mapping_family,
>>> > @@ -231,6 +247,12 @@ static int libopus_validate_layout_and_
>>> > get_channel_map(
>>> >  channel_map =
>>> ff_vorbis_channel_layout_offsets[avctx->channels
>>> > - 1];
>>> >  }
>>> >  break;
>>> > +case 2:
>>> > +ret = libopus_check_max_channels(avctx, 227);
>>> > +if (ret == 0) {
>>> > +ret = libopus_check_ambisonics_channels(avctx);
>>> > +}
>>> >
>>>
>>> No brackets needed, also if (ret) looks better imo.
>>>
>>
>> Thanks for reviewing. Would this change would break with the style
>> elsewhere in this function? I'm happy to change if you still think I should
>> do it.
>>
>> I also just realized the patch description should be "Remove warning when
>> trying to encode channel mapping 2": it already encodes even without this
>> patch. Will send an update after the above comment is resolved.
>>
>>
>>> Does libopus understand channel mapping 2 as ambisonics? What about the
>>> libopus_generic_encoder_() API? Doesn't that need to be used to encode
>>> ambisonics, like the patch by Drew did?
>>>
>>
>> Yes, libopus also understands channel mapping 2 as ambisonics by default
>> now.
>>
>> Ch map 2 uses the normal opus_multistream_encode(), so no further changes
>> are needed. On the other hand, ch map 3 uses the new
>> opus_projection_encode(), hence Drew's introduction of
>> libopus_generic_encoder_() to handle the switch as needed.
>>
>>
>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/diracdec: Check component quant

2018-11-27 Thread Michael Niedermayer
On Wed, Nov 14, 2018 at 10:37:08AM +0100, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 10708/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5730140957442048
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/diracdec.c | 5 +
>  1 file changed, 5 insertions(+)

will apply

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

If you drop bombs on a foreign country and kill a hundred thousand
innocent people, expect your government to call the consequence
"unprovoked inhuman terrorist attacks" and use it to justify dropping
more bombs and killing more people. The technology changed, the idea is old.


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


[FFmpeg-devel] [PATCH 2/2] avformat/mpegenc: extend muxing PCM-DVD to other depths

2018-11-27 Thread Paul B Mahol
Fixes #6783.

Signed-off-by: Paul B Mahol 
---
 libavformat/mpegenc.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 4c6fa67fb8..f2d6a898f2 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -364,12 +364,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
 stream->id = ac3_id++;
 } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) {
 stream->id = dts_id++;
-} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ||
-   st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
-if (st->codecpar->bits_per_coded_sample != 16) {
-av_log(ctx, AV_LOG_ERROR, "Only 16 bit LPCM streams can be 
muxed.\n");
-goto fail;
-}
+} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {
 stream->id = lpcm_id++;
 for (j = 0; j < 4; j++) {
 if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
@@ -392,6 +387,14 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
 stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 
4);
 stream->lpcm_header[2] = 0x80;
 stream->lpcm_align = st->codecpar->channels * 2;
+} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
+stream->lpcm_header[0] = 0x0c;
+stream->lpcm_header[1] = (((st->codecpar->sample_rate / 48000) 
- 1) << 4) |
+ 
(((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
+ st->codecpar->channels - 1;
+stream->lpcm_header[2] = 0x80;
+stream->id = lpcm_id++;
+stream->lpcm_align = st->codecpar->channels * 
st->codecpar->bits_per_coded_sample / 8;
 } else {
 stream->id = mpa_id++;
 }
-- 
2.17.1

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


[FFmpeg-devel] [PATCH 1/2] avcodec: add PCM-DVD encoder

2018-11-27 Thread Paul B Mahol
Fixes #6784.

Signed-off-by: Paul B Mahol 
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/pcm-dvdenc.c | 197 
 3 files changed, 199 insertions(+)
 create mode 100644 libavcodec/pcm-dvdenc.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2840a8069f..5feadac729 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -737,6 +737,7 @@ OBJS-$(CONFIG_PCM_ALAW_DECODER)   += pcm.o
 OBJS-$(CONFIG_PCM_ALAW_ENCODER)   += pcm.o
 OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
 OBJS-$(CONFIG_PCM_DVD_DECODER)+= pcm-dvd.o
+OBJS-$(CONFIG_PCM_DVD_ENCODER)+= pcm-dvdenc.o
 OBJS-$(CONFIG_PCM_F16LE_DECODER)  += pcm.o
 OBJS-$(CONFIG_PCM_F24LE_DECODER)  += pcm.o
 OBJS-$(CONFIG_PCM_F32BE_DECODER)  += pcm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2c17db5a70..d70646e91a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -494,6 +494,7 @@ extern AVCodec ff_xma2_decoder;
 extern AVCodec ff_pcm_alaw_encoder;
 extern AVCodec ff_pcm_alaw_decoder;
 extern AVCodec ff_pcm_bluray_decoder;
+extern AVCodec ff_pcm_dvd_encoder;
 extern AVCodec ff_pcm_dvd_decoder;
 extern AVCodec ff_pcm_f16le_decoder;
 extern AVCodec ff_pcm_f24le_decoder;
diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c
new file mode 100644
index 00..d26eaf071c
--- /dev/null
+++ b/libavcodec/pcm-dvdenc.c
@@ -0,0 +1,197 @@
+/*
+ * LPCM codecs for PCM formats found in Video DVD streams
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * 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 "bytestream.h"
+#include "internal.h"
+
+typedef struct PCMDVDContext {
+uint8_t header[3];   // Header added to every frame
+int block_size;  // Size of a block of samples in bytes
+int samples_per_block;   // Number of samples per channel per block
+int groups_per_block;// Number of 20/24-bit sample groups per block
+uint8_t *extra_samples;  // Pointer to leftover samples from a frame
+int extra_sample_count;  // Number of leftover samples in the buffer
+} PCMDVDContext;
+
+static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
+{
+PCMDVDContext *s = avctx->priv_data;
+int quant, freq, frame_size;
+
+switch (avctx->sample_rate) {
+case 48000:
+freq = 0;
+break;
+case 96000:
+freq = 1;
+break;
+}
+
+switch (avctx->sample_fmt) {
+case AV_SAMPLE_FMT_S16:
+avctx->bits_per_coded_sample = 16;
+quant = 0;
+break;
+case AV_SAMPLE_FMT_S32:
+avctx->bits_per_coded_sample = 24;
+quant = 2;
+break;
+}
+
+avctx->bits_per_coded_sample = 16 + quant * 4;
+avctx->block_align   = avctx->channels * 
avctx->bits_per_coded_sample / 8;
+avctx->bit_rate  = avctx->block_align * 8LL * 
avctx->sample_rate;
+if (avctx->bit_rate > 980) {
+av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, 
bitdepth or channels.\n");
+return AVERROR(EINVAL);
+}
+
+if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
+s->samples_per_block = 1;
+s->block_size= avctx->channels * 2;
+frame_size   = 2008 / s->block_size;
+} else {
+switch (avctx->channels) {
+case 1:
+case 2:
+case 4:
+/* one group has all the samples needed */
+s->block_size= 4 * avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 4 / avctx->channels;
+s->groups_per_block  = 1;
+break;
+case 8:
+/* two groups have all the samples needed */
+s->block_size= 8 * avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 1;
+s->groups_per_block  = 2;
+break;
+default:
+/* need avctx->channels groups */
+s->block_size= 4 * avctx->channels *
+   avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 4;
+s->groups_per_block  = avctx->channels;
+break;
+   

[FFmpeg-devel] [PATCH] avformat/ac3dec: always skip junk bytes before sync bytes

2018-11-27 Thread Paul B Mahol
Fixes #7278.

Signed-off-by: Paul B Mahol 
---
 libavcodec/ac3dec.c  | 20 +---
 libavformat/ac3dec.c |  2 +-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 43b22b7654..71419458fa 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1467,7 +1467,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void 
*data,
 int buf_size, full_buf_size = avpkt->size;
 AC3DecodeContext *s = avctx->priv_data;
 int blk, ch, err, offset, ret;
-int got_independent_frame = 0;
+int skip = 0, got_independent_frame = 0;
 const uint8_t *channel_map;
 uint8_t extended_channel_map[EAC3_MAX_CHANNELS];
 const SHORTFLOAT *output[AC3_MAX_CHANNELS];
@@ -1477,6 +1477,14 @@ static int ac3_decode_frame(AVCodecContext * avctx, void 
*data,
 s->superframe_size = 0;
 
 buf_size = full_buf_size;
+while (buf_size > 2) {
+if (AV_RB16(buf) != 0x770B && AV_RL16(buf) != 0x770B) {
+buf += 1;
+buf_size -= 1;
+continue;
+}
+break;
+}
 /* copy input buffer to decoder context to avoid reading past the end
of the buffer, which can be caused by a damaged input stream. */
 if (buf_size >= 2 && AV_RB16(buf) == 0x770B) {
@@ -1637,6 +1645,11 @@ dependent_frame:
 AC3HeaderInfo hdr;
 int err;
 
+if (buf_size - s->frame_size <= 16) {
+skip = buf_size - s->frame_size;
+goto skip;
+}
+
 if ((ret = init_get_bits8(&s->gbc, buf + s->frame_size, buf_size - 
s->frame_size)) < 0)
 return ret;
 
@@ -1657,6 +1670,7 @@ dependent_frame:
 }
 }
 }
+skip:
 
 frame->decode_error_flags = err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0;
 
@@ -1796,9 +1810,9 @@ dependent_frame:
 *got_frame_ptr = 1;
 
 if (!s->superframe_size)
-return FFMIN(full_buf_size, s->frame_size);
+return FFMIN(full_buf_size, s->frame_size + skip);
 
-return FFMIN(full_buf_size, s->superframe_size);
+return FFMIN(full_buf_size, s->superframe_size + skip);
 }
 
 /**
diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 6f423ff7eb..2718061bdc 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -47,7 +47,7 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID 
expected_codec_id)
 uint16_t frame_size;
 int i, ret;
 
-if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8)) {
+if(!memcmp(buf2, "\x1\x10", 2)) {
 if (buf2 + 16 > end)
 break;
 buf2+=16;
-- 
2.17.1

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


[FFmpeg-devel] [PATCH] lavc/hevc_parser: add 4 bytes startcode condition in hevc_find_frame_end

2018-11-27 Thread Linjie Fu
The startcode before VPS,SPS,PPS and the first NALU in an AU is 4 bytes.
Blindly taking the startcode as 3 bytes will leave 0x00 in last packet
and may lead to some warnings in parse_nal_units when s->flags is set to
PARSER_FLAG_COMPLETE_FRAMES.

Add 4 bytes startcode condition in hevc_find_frame_end.
Modify the code to print the buf_size like in H264 and reduce the duplication.

Signed-off-by: Linjie Fu 
---
 libavcodec/hevc_parser.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index 369d1338d0..aa216e3c8d 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -32,6 +32,7 @@
 #include "parser.h"
 
 #define START_CODE 0x01 ///< start_code_prefix_one_3bytes
+#define START_CODE_4 0x0001 ///< start_code_4bytes
 
 #define IS_IRAP_NAL(nal) (nal->type >= 16 && nal->type <= 23)
 #define IS_IDR_NAL(nal) (nal->type == HEVC_NAL_IDR_W_RADL || nal->type == 
HEVC_NAL_IDR_N_LP)
@@ -239,7 +240,7 @@ static int parse_nal_units(AVCodecParserContext *s, const 
uint8_t *buf,
 }
 }
 /* didn't find a picture! */
-av_log(avctx, AV_LOG_ERROR, "missing picture in access unit\n");
+av_log(avctx, AV_LOG_ERROR, "missing picture in access unit with size 
%d\n", buf_size);
 return -1;
 }
 
@@ -267,8 +268,7 @@ static int hevc_find_frame_end(AVCodecParserContext *s, 
const uint8_t *buf,
 if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_EOB_NUT) || nut == 
HEVC_NAL_SEI_PREFIX ||
 (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) {
 if (pc->frame_start_found) {
-pc->frame_start_found = 0;
-return i - 5;
+goto found;
 }
 } else if (nut <= HEVC_NAL_RASL_R ||
(nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) {
@@ -277,14 +277,19 @@ static int hevc_find_frame_end(AVCodecParserContext *s, 
const uint8_t *buf,
 if (!pc->frame_start_found) {
 pc->frame_start_found = 1;
 } else { // First slice of next frame found
-pc->frame_start_found = 0;
-return i - 5;
+goto found;
 }
 }
 }
 }
 
 return END_NOT_FOUND;
+
+found:
+pc->frame_start_found = 0;
+if (((pc->state64 >> 3 * 8) & 0x) == START_CODE_4)
+return i - 6;
+return i - 5;
 }
 
 static int hevc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
-- 
2.17.1

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


[FFmpeg-devel] [PATCH] swscale/output: VSX-optimize nbps yuv2plane1

2018-11-27 Thread Lauri Kasanen
./ffmpeg_g -f rawvideo -pix_fmt rgb24 -s hd1080 -i /dev/zero -pix_fmt 
yuv420p9le \
-f null -vframes 100 -v error -nostats -

Speedups:
yuv2plane1_9BE_vsx  11.2042
yuv2plane1_9LE_vsx  11.156
yuv2plane1_10BE_vsx 9.89428
yuv2plane1_10LE_vsx 10.3637
yuv2plane1_12BE_vsx 9.71923
yuv2plane1_12LE_vsx 11.0404
yuv2plane1_14BE_vsx 10.1763
yuv2plane1_14LE_vsx 11.2728

Fate passes, each format tested with an image to video conversion.

Depends on "swscale/ppc: Move VSX-using code to its own file". Only tested on 
LE.

Signed-off-by: Lauri Kasanen 
---
 libswscale/ppc/swscale_vsx.c | 83 
 1 file changed, 83 insertions(+)

diff --git a/libswscale/ppc/swscale_vsx.c b/libswscale/ppc/swscale_vsx.c
index 853b587..6462c11 100644
--- a/libswscale/ppc/swscale_vsx.c
+++ b/libswscale/ppc/swscale_vsx.c
@@ -131,6 +131,75 @@ static void yuv2plane1_8_vsx(const int16_t *src, uint8_t 
*dest, int dstW,
 yuv2plane1_8_u(src, dest, dstW, dither, offset, i);
 }
 
+#if !HAVE_BIGENDIAN
+
+#define output_pixel(pos, val) \
+if (big_endian) { \
+AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
+} else { \
+AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
+}
+
+static void yuv2plane1_nbps_u(const int16_t *src, uint16_t *dest, int dstW,
+  int big_endian, int output_bits, int start)
+{
+int i;
+int shift = 15 - output_bits;
+
+for (i = start; i < dstW; i++) {
+int val = src[i] + (1 << (shift - 1));
+output_pixel(&dest[i], val);
+}
+}
+
+static void yuv2plane1_nbps_vsx(const int16_t *src, uint16_t *dest, int dstW,
+   int big_endian, int output_bits)
+{
+const int dst_u = -(uintptr_t)dest & 7;
+const int shift = 15 - output_bits;
+const int add = (1 << (shift - 1));
+const int clip = (1 << output_bits) - 1;
+const vector uint16_t vadd = (vector uint16_t) {add, add, add, add, add, 
add, add, add};
+const vector uint16_t vswap = (vector uint16_t) vec_splat_u16(big_endian ? 
8 : 0);
+const vector uint16_t vshift = (vector uint16_t) vec_splat_u16(shift);
+const vector uint16_t vlargest = (vector uint16_t) {clip, clip, clip, 
clip, clip, clip, clip, clip};
+vector uint16_t v;
+int i;
+
+yuv2plane1_nbps_u(src, dest, dst_u, big_endian, output_bits, 0);
+
+for (i = dst_u; i < dstW - 7; i += 8) {
+v = vec_vsx_ld(0, (const uint16_t *) &src[i]);
+v = vec_add(v, vadd);
+v = vec_sr(v, vshift);
+v = vec_min(v, vlargest);
+v = vec_rl(v, vswap);
+vec_st(v, 0, &dest[i]);
+}
+
+yuv2plane1_nbps_u(src, dest, dstW, big_endian, output_bits, i);
+}
+
+#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
+static void yuv2plane1_ ## bits ## BE_LE ## _vsx(const int16_t *src, \
+ uint8_t *dest, int dstW, \
+ const uint8_t *dither, int offset) \
+{ \
+yuv2plane1_ ## template_size ## _vsx((const typeX_t *) src, \
+ (uint16_t *) dest, dstW, is_be, bits); \
+}
+
+yuv2NBPS( 9, BE, 1, nbps, int16_t)
+yuv2NBPS( 9, LE, 0, nbps, int16_t)
+yuv2NBPS(10, BE, 1, nbps, int16_t)
+yuv2NBPS(10, LE, 0, nbps, int16_t)
+yuv2NBPS(12, BE, 1, nbps, int16_t)
+yuv2NBPS(12, LE, 0, nbps, int16_t)
+yuv2NBPS(14, BE, 1, nbps, int16_t)
+yuv2NBPS(14, LE, 0, nbps, int16_t)
+
+#endif /* !HAVE_BIGENDIAN */
+
 #endif /* HAVE_VSX */
 
 av_cold void ff_sws_init_swscale_vsx(SwsContext *c)
@@ -158,6 +227,20 @@ av_cold void ff_sws_init_swscale_vsx(SwsContext *c)
 case 8:
 c->yuv2plane1 = yuv2plane1_8_vsx;
 break;
+#if !HAVE_BIGENDIAN
+case 9:
+c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_vsx  : 
yuv2plane1_9LE_vsx;
+break;
+case 10:
+c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_vsx  : 
yuv2plane1_10LE_vsx;
+break;
+case 12:
+c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_vsx  : 
yuv2plane1_12LE_vsx;
+break;
+case 14:
+c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_vsx  : 
yuv2plane1_14LE_vsx;
+break;
+#endif
 }
 }
 #endif /* HAVE_VSX */
-- 
2.6.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/hlsenc: Fix mixed declarations and code

2018-11-27 Thread Steven Liu


> On Oct 31, 2018, at 07:20, Mark Thompson  wrote:
> 
> ---
> libavformat/hlsenc.c | 13 +
> 1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f8f060d065..73282ed31a 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2348,26 +2348,31 @@ static int hls_write_trailer(struct AVFormatContext 
> *s)
> return AVERROR(ENOMEM);
> }
> if ( hls->segment_type == SEGMENT_TYPE_FMP4) {
> +int range_length;
> +
> if (!vs->init_range_length) {
> +uint8_t *buffer;
> +int byterange_mode;
> +
> av_write_frame(vs->avf, NULL); /* Flush any buffered data */
> avio_flush(oc->pb);
> 
> -uint8_t *buffer = NULL;
> -int range_length = avio_close_dyn_buf(oc->pb, &buffer);
> +buffer = NULL;
> +range_length = avio_close_dyn_buf(oc->pb, &buffer);
> avio_write(vs->out, buffer, range_length);
> av_free(buffer);
> vs->init_range_length = range_length;
> avio_open_dyn_buf(&oc->pb);
> vs->packets_written = 0;
> vs->start_pos = range_length;
> -int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || 
> (hls->max_seg_size > 0);
> +byterange_mode = (hls->flags & HLS_SINGLE_FILE) || 
> (hls->max_seg_size > 0);
> if (!byterange_mode) {
> ff_format_io_close(s, &vs->out);
> hlsenc_io_close(s, &vs->out, vs->base_output_dirname);
> }
> }
> 
> -int range_length = 0;
> +range_length = 0;
> if (!(hls->flags & HLS_SINGLE_FILE)) {
> ret = hlsenc_io_open(s, &vs->out, vs->avf->url, NULL);
> if (ret < 0) {
> -- 
> 2.19.1
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

LGTM

Thanks
Steven





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


[FFmpeg-devel] [PATCH] avcodec/opus: set skip_samples

2018-11-27 Thread Paul B Mahol
Fixes #5258.

Signed-off-by: Paul B Mahol 
---
 libavcodec/opus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index aa827b604c..22cda64801 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -31,6 +31,7 @@
 
 #include "opus_celt.h"
 #include "opustab.h"
+#include "internal.h"
 #include "vorbis.h"
 
 static const uint16_t opus_frame_duration[32] = {
@@ -325,7 +326,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 return AVERROR_PATCHWELCOME;
 }
 
-avctx->delay = AV_RL16(extradata + 10);
+avctx->delay = avctx->internal->skip_samples = AV_RL16(extradata + 10);
 
 channels = avctx->extradata ? extradata[9] : (avctx->channels == 1) ? 1 : 
2;
 if (!channels) {
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH 2/2] avformat/dashenc: Added an option to ignore io errors

2018-11-27 Thread Carl Eugen Hoyos
2018-11-26 11:25 GMT+01:00, Karthick J :
> When dashenc has to run for long duration(say 24x7 live stream), one can
> enable this option to ignore the io failure of few segment's upload due to
> an intermittent network issues.
> When the network connection recovers dashenc will continue with the upload
> of the current segments, leading to the recovery of the stream.

> -return ret;
> +if (c->ignore_io_errors)
> +return 0;
> +else
> +return ret;

Maybe: return c->ignore_io_errors ? 0 : ret;
but it's your code...

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


[FFmpeg-devel] [PATCH]lavf/rawdec: Do not mark raw subtitle streams as data streams

2018-11-27 Thread Carl Eugen Hoyos
Hi!

Attached patch improves the "ffmpeg -i" output for raw dvbsub files.

Please comment, Carl Eugen
From 6cddd293354c75a20ae54e0ea62898c128826601 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Tue, 27 Nov 2018 18:22:02 +0100
Subject: [PATCH] lavf/rawdec: Do not mark streams from raw subtitle demuxers
 as data streams.

Improves "ffmpeg -i" output for raw dvbsub files.
---
 libavformat/rawdec.c |   11 +++
 libavformat/rawdec.h |4 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index b38a4b5..6249352 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -91,6 +91,17 @@ fail:
 return ret;
 }
 
+int ff_raw_subtitle_read_header(AVFormatContext *s)
+{
+AVStream *st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+st->codecpar->codec_id = s->iformat->raw_codec_id;
+st->start_time = 0;
+return 0;
+}
+
 int ff_raw_data_read_header(AVFormatContext *s)
 {
 AVStream *st = avformat_new_stream(s, NULL);
diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h
index a464bbb..3eb416b 100644
--- a/libavformat/rawdec.h
+++ b/libavformat/rawdec.h
@@ -41,6 +41,8 @@ int ff_raw_audio_read_header(AVFormatContext *s);
 
 int ff_raw_video_read_header(AVFormatContext *s);
 
+int ff_raw_subtitle_read_header(AVFormatContext *s);
+
 int ff_raw_data_read_header(AVFormatContext *s);
 
 #define FF_RAWVIDEO_DEMUXER_CLASS(name)\
@@ -83,7 +85,7 @@ AVInputFormat ff_ ## shortname ## _demuxer = {\
 .name   = #shortname,\
 .long_name  = NULL_IF_CONFIG_SMALL(longname),\
 .read_probe = probe,\
-.read_header= ff_raw_data_read_header,\
+.read_header= ff_raw_subtitle_read_header,\
 .read_packet= ff_raw_read_partial_packet,\
 .extensions = ext,\
 .flags  = flag,\
-- 
1.7.10.4

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


Re: [FFmpeg-devel] [PATCH]Avoid duplicating Closed Captions when increasing frame rate

2018-11-27 Thread Carl Eugen Hoyos
2018-11-23 19:03 GMT+01:00, Carl Eugen Hoyos :

> Attached patches fix Closed Captions when increasing frame rate, both
> with "-r" and the fps filter, fixes ticket #7506.

Patches applied.

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


Re: [FFmpeg-devel] [PATCH] avcodec/pngdec: Check compression method

2018-11-27 Thread Carl Eugen Hoyos
2018-11-09 16:13 GMT+01:00, Carl Eugen Hoyos :
> 2018-11-09 10:31 GMT+01:00, Michael Niedermayer :
>> method 0 (inflate/deflate) is the only specified in the specification and
>> the only supported
>>
>> Fixes: Timeout
>> Fixes:
>> 10976/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-5729372588736512
>>
>> Found-by: continuous fuzzing process
>> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> Signed-off-by: Michael Niedermayer 
>> ---
>>  libavcodec/pngdec.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
>> index 01144680f2..189bb9a4c1 100644
>> --- a/libavcodec/pngdec.c
>> +++ b/libavcodec/pngdec.c
>> @@ -578,6 +578,10 @@ static int decode_ihdr_chunk(AVCodecContext *avctx,
>> PNGDecContext *s,
>>  }
>>  s->color_type   = bytestream2_get_byte(&s->gb);
>>  s->compression_type = bytestream2_get_byte(&s->gb);
>> +if (s->compression_type) {
>> +av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n",
>> s->compression_type);
>> +goto error;
>
> Would the native FFmpeg zlib decompression code - if merged -
> avoid this issue?

Ping.

It appears to me that if there is an issue, it cannot be fixed with the
suggested patch, except that the fuzzer needs a little longer to find
the final blocking sample.
Or do I misunderstand?

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


Re: [FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-27 Thread Carl Eugen Hoyos
2018-11-27 10:18 GMT+01:00, Jun Zhao :
> fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
> [libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid parameter
> [libaom-av1 @ 0x469f340]   Additional information: g_threads out of range
> [..MAX_NUM_THREADS]
>
> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/libaomenc.c |3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index cb31c55..ccb0cf9 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  enccfg.g_h= avctx->height;
>  enccfg.g_timebase.num = avctx->time_base.num;
>  enccfg.g_timebase.den = avctx->time_base.den;
> -enccfg.g_threads  = avctx->thread_count ? avctx->thread_count :
> av_cpu_count();
> +enccfg.g_threads  =
> + FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64);

Is there a limitation in libaom's api that requires users to never set
g_threads >64 that we missed so far?
Or is there a bug in libaom that you would like to fix in FFmpeg?

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


Re: [FFmpeg-devel] avcodec/proresdec : add 12b decoding support

2018-11-27 Thread Martin Vignali
Hello,

New patchs in attach

001 : add YUVA444P12 and YUVA422P12 to avcodec_dimensions2 (in order to
have height padding)
002 to 009 : unchanged
010 : mention ticket 7163 in commit msg (unchanged otherwise)

Martin


0002-avcodec-proresdsp-remove-unused-value.patch
Description: Binary data


0001-avcodec-utils-add-YUVA444P12-and-YUVA422P12-to-pixfm.patch
Description: Binary data


0004-avcodec-proresdec-rename-dsp-part-for-10b-and-check-.patch
Description: Binary data


0005-avcodec-proresdsp-indent-after-prev-commit.patch
Description: Binary data


0003-avcodec-proresdec-move-dsp-init-after-codec-tag-chec.patch
Description: Binary data


0010-avcodec-proresdec-add-12b-decoding.patch
Description: Binary data


0006-avcodec-proresdec-put-unpack-alpha-func-in-prores-ct.patch
Description: Binary data


0008-avcodec-proresdec-add-unpack-alpha-12-func.patch
Description: Binary data


0009-avcodec-proresdec-add-12b-prores-idct.patch
Description: Binary data


0007-avcodec-proresdec-make-inline-func-for-unpack-alpha.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension for NV12 and P010 textures - split planes

2018-11-27 Thread Mark Thompson
On 26/11/2018 15:32, Mironov, Mikhail wrote:
> You assume that device ID returned from regular enumeration is the same as 
> device ID returned from clGetDeviceIDsFromD3D11KHR. It is not guaranteed and 
> I didn't try this.

Ok, that's fair I suppose.  Fixing it hasn't changed anything, though.

> Also I would add tracing to ensure that CL_CONTEXT_D3D11_DEVICE_KHR is 
> actually set and clGetDeviceIDsFromD3D11KHR is called.

The first was always true (Intel requires it too), the second is now.

> In AMF code I always set CL_CONTEXT_INTEROP_USER_SYNC to true.

I'm not completely sure of the precise semantics of D3D11, but I don't think we 
want that here - the clEnqueueAcquireD3D11ObjectsKHR() call should be the first 
synchronisation point following the previous component (generally a decoder).

I tried setting it anyway, but the behaviour doesn't change - I still get 
CL_INVALID_D3D11_RESOURCE_KHR.

> Also I would trace other parameters to clCreateFromD3D11Texture2DKHR: memory 
> flags and texture descriptor.

For the flags, I tried all of CL_MEM_READ_WRITE / CL_MEM_WRITE_ONLY / 
CL_MEM_READ_ONLY, which are the only allowed values.  The texture descriptor is 
just the one created for the decoder.

> BTW: does the interop work for NV or Intel?

The D3D11 interop works on Intel, though not directly in the ffmpeg utility 
without a little change because it requires the textures to be created with 
D3D11_RESOURCE_MISC_FLAG (as described in the extension document 
).
  Intel doesn't care whether clGetDeviceIDsFromD3D11KHR() is used or not 
(though I've fixed that anyway), but it does require the 
CL_CONTEXT_D3D11_DEVICE_KHR option to clCreateContext() (fails with 
CL_INVALID_CONTEXT if it isn't).

It can't work on Nvidia because they don't offer any way to share NV12 textures.

The DXVA2/D3D9 interop works correctly on both AMD and Intel with only the 
common standard extension.  The one Nvidia device I can find easily doesn't 
have cl_khr_dx9_media_sharing at all, so that doesn't work.

Thanks,

- Mark


>> -Original Message-
>> From: ffmpeg-devel  On Behalf Of
>> Mark Thompson
>> Sent: November 25, 2018 5:22 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension
>> for NV12 and P010 textures - split planes
>>
>> On 25/11/2018 21:28, Mironov, Mikhail wrote:
>>> It seem that the failure is not in the new extension but before, in the
>> interop from D3D11 to OCL. It can happen in two cases: OCL device/context
>> are created without D3D11 device or format of the texture is not supported.
>> NV12 is supported. I went through the latest ffmpeg snapshot and found that
>> function opencl_enumerate_d3d11_devices() looks correct, pointer to the
>> function is set to OpenCLDeviceSelector::enumerate_devices member but I
>> cannot find a call to selector->enumerate_devices(). Instead
>> opencl_enumerate_devices() is called directly. So my guess is that created
>> OCL device is not created from D3D11.
>>
>> Hmm, right - patch just sent to fix the selection call.
>>
>> It doesn't actually make any difference to this case, though, since the 
>> filter
>> made it choose the right device anyway and
>> CL_CONTEXT_D3D11_DEVICE_KHR was always set when deriving from
>> D3D11.  (It could only have made a difference if there were other conflicting
>> D3D11 devices it could have picked incorrectly.)
>>
>>> Just in case OCL device creation sample:
>>> https://github.com/GPUOpen-
>> LibrariesAndSDKs/AMF/blob/master/amf/public
>>> /samples/CPPSamples/common/DeviceOpenCL.cpp
>>>
>>> Regarding the new split extension: here is a working snippet:
>>> cl_mem clImage2D = 0;
>>> cl_mem clImages[AMF_SURFACE_MAX_PLANES]; // index can be not 0 if
>>> texture is allocated as an array.
>>>  clImage2D = clCreateFromD3D11Texture2DKHR(m_clContext, memflags,
>>> pTexture, index, &clStatus);
>>
>> Where is the comment about index being nonzero coming from there?
>> Other callers to this definitely start from a zero index.  (I tried adding 
>> one to
>> my index values but it didn't change the result.)
>>
>>>
>>>  for(int i = 0; i < planesNumber; i++)
>>>   {
>>> clImages[i] = clGetPlaneFromImageAMD(m_clContext, clImage2D,
>>> (cl_uint)i, &clStatus);
>>>
>>> }
>>> // don’t forget to release clImages[i] and clImage2D
>>
>> Otherwise, that agrees with how I read the extension document.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] hwcontext_opencl: Only release command queue if it exists

2018-11-27 Thread Mark Thompson
On 26/11/2018 12:31, Song, Ruiling wrote:
> 
> 
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
>> Mark Thompson
>> Sent: Monday, November 26, 2018 3:16 AM
>> To: FFmpeg development discussions and patches 
>> Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Only release command
>> queue if it exists
>>
>> If the frames context creation fails then the command queue reference
>> need not exist when uninit is called.
>> ---
>>  libavutil/hwcontext_opencl.c | 11 +++
>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
>> index c745b91775..e6cef74269 100644
>> --- a/libavutil/hwcontext_opencl.c
>> +++ b/libavutil/hwcontext_opencl.c
>> @@ -1750,10 +1750,13 @@ static void
>> opencl_frames_uninit(AVHWFramesContext *hwfc)
>>  av_freep(&priv->mapped_frames);
>>  #endif
>>
>> -cle = clReleaseCommandQueue(priv->command_queue);
>> -if (cle != CL_SUCCESS) {
>> -av_log(hwfc, AV_LOG_ERROR, "Failed to release frame "
>> -   "command queue: %d.\n", cle);
>> +if (priv->command_queue) {
>> +cle = clReleaseCommandQueue(priv->command_queue);
>> +if (cle != CL_SUCCESS) {
>> +av_log(hwfc, AV_LOG_ERROR, "Failed to release frame "
>> +   "command queue: %d.\n", cle);
>> +}
>> +priv->command_queue = NULL;
> 
> Seems ok.

Applied.

Thanks!

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


[FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to enumerate devices

2018-11-27 Thread Mark Thompson
Also assert that all required functions are present.
---
On 26/11/2018 08:57, Song, Ruiling wrote:
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
>> Mark Thompson
>> Sent: Monday, November 26, 2018 6:08 AM
>> To: FFmpeg development discussions and patches 
>> Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to
>> enumerate devices
>>
>> ---
>>  libavutil/hwcontext_opencl.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
>> index e6cef74269..6a26354c87 100644
>> --- a/libavutil/hwcontext_opencl.c
>> +++ b/libavutil/hwcontext_opencl.c
>> @@ -542,9 +542,9 @@ static int
>> opencl_device_create_internal(AVHWDeviceContext *hwdev,
>>  continue;
>>  }
>>
>> -err = opencl_enumerate_devices(hwdev, platforms[p], platform_name,
>> -   &nb_devices, &devices,
>> -   selector->context);
>> +err = selector->enumerate_devices(hwdev, platforms[p], 
>> platform_name,
>> +  &nb_devices, &devices,
>> +  selector->context);
> I think it is better to check enumerate_devices  against null pointer before 
> calling it, although it should works well currently.

The two enumerate functions should always be set when entering the function, 
since they are always required.  (Unlike the filter, where "do nothing" is a 
reasonable case.)

How about an assert at the start of the function to check that, like this?

- Mark


 libavutil/hwcontext_opencl.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index be71c8323e..d3df6221c4 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -500,6 +500,9 @@ static int opencl_device_create_internal(AVHWDeviceContext 
*hwdev,
  *device_name_src   = NULL;
 int err, found, p, d;
 
+av_assert0(selector->enumerate_platforms &&
+   selector->enumerate_devices);
+
 err = selector->enumerate_platforms(hwdev, &nb_platforms, &platforms,
 selector->context);
 if (err)
@@ -531,9 +534,9 @@ static int opencl_device_create_internal(AVHWDeviceContext 
*hwdev,
 continue;
 }
 
-err = opencl_enumerate_devices(hwdev, platforms[p], platform_name,
-   &nb_devices, &devices,
-   selector->context);
+err = selector->enumerate_devices(hwdev, platforms[p], platform_name,
+  &nb_devices, &devices,
+  selector->context);
 if (err < 0)
 continue;
 
-- 
2.19.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 0/2] New version

2018-11-27 Thread Andreas Rheinhardt
I have incorporated your proposal and have added the buffer directly to
H2645RBSP. This allowed to simplify the uninit process, as you already
predicted.


Andreas Rheinhardt (2):
  h2645_parse: Make ff_h2645_packet_split reference-compatible
  cbs_h2645: Avoid memcpy when splitting fragment #2

 libavcodec/cbs_h2645.c | 33 +++
 libavcodec/extract_extradata_bsf.c |  2 +-
 libavcodec/h2645_parse.c   | 53 --
 libavcodec/h2645_parse.h   |  9 -
 libavcodec/h264_parse.c|  2 +-
 libavcodec/h264dec.c   |  4 +--
 libavcodec/hevc_parse.c|  3 +-
 libavcodec/hevc_parser.c   |  2 +-
 libavcodec/hevcdec.c   |  2 +-
 9 files changed, 77 insertions(+), 33 deletions(-)

-- 
2.19.1

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


[FFmpeg-devel] [PATCH 1/2] h2645_parse: Make ff_h2645_packet_split reference-compatible

2018-11-27 Thread Andreas Rheinhardt
This is in preparation for a patch for cbs_h2645. Now the packet's
rbsp_buffer can be owned by an AVBuffer.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_h2645.c |  8 ++---
 libavcodec/extract_extradata_bsf.c |  2 +-
 libavcodec/h2645_parse.c   | 53 --
 libavcodec/h2645_parse.h   |  9 -
 libavcodec/h264_parse.c|  2 +-
 libavcodec/h264dec.c   |  4 +--
 libavcodec/hevc_parse.c|  3 +-
 libavcodec/hevc_parser.c   |  2 +-
 libavcodec/hevcdec.c   |  2 +-
 9 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 666970ed03..574a53a60a 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -612,7 +612,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
0);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS 
array.\n");
 return err;
@@ -636,7 +636,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
0);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS 
array.\n");
 return err;
@@ -690,7 +690,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 
1);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 
1, 0);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
"HVCC array %d (%d NAL units of type %d).\n",
@@ -709,7 +709,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 frag->data, frag->data_size,
 ctx->log_ctx,
 priv->mp4, priv->nal_length_size,
-codec_id, 1);
+codec_id, 1, 0);
 if (err < 0)
 return err;
 
diff --git a/libavcodec/extract_extradata_bsf.c 
b/libavcodec/extract_extradata_bsf.c
index f37427c7e1..17e5deb96b 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -157,7 +157,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, 
AVPacket *pkt,
 }
 
 ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
-ctx, 0, 0, ctx->par_in->codec_id, 1);
+ctx, 0, 0, ctx->par_in->codec_id, 1, 0);
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index aaa4b8f443..942f2c5d71 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -343,9 +343,51 @@ static int find_next_start_code(const uint8_t *buf, const 
uint8_t *next_avc)
 return i + 3;
 }
 
+static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref)
+{
+if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
+goto fail;
+size += AV_INPUT_BUFFER_PADDING_SIZE;
+
+if (rbsp->rbsp_buffer_alloc_size >= size &&
+(!rbsp->rbsp_buffer_ref || 
av_buffer_is_writable(rbsp->rbsp_buffer_ref)))
+return;
+
+size = FFMIN(size + size / 16 + 32, INT_MAX);
+
+if (rbsp->rbsp_buffer_ref)
+av_buffer_unref(&rbsp->rbsp_buffer_ref);
+else
+av_free(rbsp->rbsp_buffer);
+
+rbsp->rbsp_buffer = av_malloc(size);
+if (!rbsp->rbsp_buffer)
+goto fail;
+rbsp->rbsp_buffer_alloc_size = size;
+
+if (use_ref) {
+rbsp->rbsp_buffer_ref = av_buffer_create(rbsp->rbsp_buffer, size,
+ NULL, NULL, 0);
+if (!rbsp->rbsp_buffer_ref)
+goto fail;
+}
+
+return;
+
+fail:
+rbsp->rbsp_buffer_alloc_size = 0;
+if (rbsp->rbsp_buffer_ref) {
+av_buffer_unref(&rbsp->rbsp_buffer_ref);
+rbsp->rbsp_buffer = NULL;
+} else
+av_freep(&rbsp->rbsp_buffer);
+
+return;
+}
+
 int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
   void *logctx, int is_nalff, int nal_length_size,
-  enum AVCodecID co

[FFmpeg-devel] [PATCH 2/2] cbs_h2645: Avoid memcpy when splitting fragment #2

2018-11-27 Thread Andreas Rheinhardt
Now memcpy can be avoided for NAL units containing escapes, too.

Particularly improves performance for files with hardcoded black bars.
For such a file, time spent in cbs_h2645_split_fragment went down from
369410 decicycles to 327677 decicycles. (It were 379114 decicycles when
every NAL unit was copied.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_h2645.c | 33 +++--
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 574a53a60a..e74f8dce81 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -531,6 +531,7 @@ static int 
cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
 
 for (i = 0; i < packet->nb_nals; i++) {
 const H2645NAL *nal = &packet->nals[i];
+AVBufferRef *ref;
 size_t size = nal->size;
 
 // Remove trailing zeroes.
@@ -538,25 +539,13 @@ static int 
cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
 --size;
 av_assert0(size > 0);
 
-if (nal->data == nal->raw_data) {
-err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type,
-(uint8_t*)nal->data, size, frag->data_ref);
-if (err < 0)
-return err;
-} else {
-uint8_t *data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
-if (!data)
-return AVERROR(ENOMEM);
-memcpy(data, nal->data, size);
-memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+ref = (nal->data == nal->raw_data) ? frag->data_ref
+   : packet->rbsp.rbsp_buffer_ref;
 
-err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type,
-  data, size, NULL);
-if (err < 0) {
-av_freep(&data);
-return err;
-}
-}
+err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type,
+(uint8_t*)nal->data, size, ref);
+if (err < 0)
+return err;
 }
 
 return 0;
@@ -612,7 +601,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
0);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
1);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS 
array.\n");
 return err;
@@ -636,7 +625,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
0);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 
1);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS 
array.\n");
 return err;
@@ -690,7 +679,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 err = ff_h2645_packet_split(&priv->read_packet,
 frag->data + start, end - start,
-ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 
1, 0);
+ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 
1, 1);
 if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
"HVCC array %d (%d NAL units of type %d).\n",
@@ -709,7 +698,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 frag->data, frag->data_size,
 ctx->log_ctx,
 priv->mp4, priv->nal_length_size,
-codec_id, 1, 0);
+codec_id, 1, 1);
 if (err < 0)
 return err;
 
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH] lavf: add tranpose_opencl filter

2018-11-27 Thread Mark Thompson
On 26/11/2018 07:05, Ruiling Song wrote:
> Signed-off-by: Ruiling Song 
> ---
>  configure |   1 +
>  libavfilter/Makefile  |   1 +
>  libavfilter/allfilters.c  |   1 +
>  libavfilter/opencl/transpose.cl   |  35 +
>  libavfilter/opencl_source.h   |   1 +
>  libavfilter/transpose.h   |  34 +
>  libavfilter/vf_transpose.c|  14 +-
>  libavfilter/vf_transpose_opencl.c | 294 
> ++
>  8 files changed, 368 insertions(+), 13 deletions(-)
>  create mode 100644 libavfilter/opencl/transpose.cl
>  create mode 100644 libavfilter/transpose.h
>  create mode 100644 libavfilter/vf_transpose_opencl.c
> 
> diff --git a/configure b/configure
> index b4f944c..dcb3f5f 100755
> --- a/configure
> +++ b/configure
> @@ -3479,6 +3479,7 @@ tinterlace_merge_test_deps="tinterlace_filter"
>  tinterlace_pad_test_deps="tinterlace_filter"
>  tonemap_filter_deps="const_nan"
>  tonemap_opencl_filter_deps="opencl const_nan"
> +transpose_opencl_filter_deps="opencl"
>  unsharp_opencl_filter_deps="opencl"
>  uspp_filter_deps="gpl avcodec"
>  vaguedenoiser_filter_deps="gpl"
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 1895fa2..6e26581 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -393,6 +393,7 @@ OBJS-$(CONFIG_TONEMAP_OPENCL_FILTER) += 
> vf_tonemap_opencl.o colorspace.o
>  OBJS-$(CONFIG_TPAD_FILTER)   += vf_tpad.o
>  OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
>  OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER)  += vf_transpose_npp.o 
> cuda_check.o
> +OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER)   += vf_transpose_opencl.o 
> opencl.o opencl/transpose.o
>  OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
>  OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o framesync.o
>  OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 837c99e..a600069 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -372,6 +372,7 @@ extern AVFilter ff_vf_tonemap_opencl;
>  extern AVFilter ff_vf_tpad;
>  extern AVFilter ff_vf_transpose;
>  extern AVFilter ff_vf_transpose_npp;
> +extern AVFilter ff_vf_transpose_opencl;
>  extern AVFilter ff_vf_trim;
>  extern AVFilter ff_vf_unpremultiply;
>  extern AVFilter ff_vf_unsharp;
> diff --git a/libavfilter/opencl/transpose.cl b/libavfilter/opencl/transpose.cl
> new file mode 100644
> index 000..e6388ab
> --- /dev/null
> +++ b/libavfilter/opencl/transpose.cl
> @@ -0,0 +1,35 @@
> +/*
> + * 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
> + */
> +kernel void transpose(__write_only image2d_t dst,
> +  __read_only image2d_t src,
> +  int dir) {
> +const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
> +   CLK_ADDRESS_CLAMP_TO_EDGE   |
> +   CLK_FILTER_NEAREST);
> +
> +int2 size = get_image_dim(dst);
> +int x = get_global_id(0);
> +int y = get_global_id(1);
> +
> +int xin = (dir & 2) ? (size.y - 1 - y) : y;
> +int yin = (dir & 1) ? (size.x - 1 - x) : x;
> +float4 data = read_imagef(src, sampler, (int2)(xin, yin));
> +
> +if (x < size.x && y < size.y)
> +write_imagef(dst, (int2)(x, y), data);
> +}

Does the dependency on dir have any effect on speed here?  Any call is only 
ever going to use one side of each of the dir cases, so it feels like it might 
be nicer to hard-code that so they aren't included in the compiled code at all.

> diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h
> index 2f67d89..4118138 100644
> --- a/libavfilter/opencl_source.h
> +++ b/libavfilter/opencl_source.h
> @@ -25,6 +25,7 @@ extern const char *ff_opencl_source_convolution;
>  extern const char *ff_opencl_source_neighbor;
>  extern const char *ff_opencl_source_overlay;
>  extern const char *ff_opencl_source_tonemap;
> +extern const char *ff_opencl_source_transpose;
>  extern const char *ff_opencl_source_unsharp;
>  
>  #endif /* AVFILTER_OPENCL_SOURCE_H */
> diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
> new file mode 100644
> in

[FFmpeg-devel] [PATCH 2/2] avcodec/wmv2dec: Skip I frame if its smaller than 1/8 of the minimal size

2018-11-27 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
11168/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMV2_fuzzer-573378203278

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

diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 4f97d9227c..1858dc15c6 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -181,6 +181,8 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext 
*s)
 }
 
 s->dc_table_index = get_bits1(&s->gb);
+if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * 
((s->height+15)/16))
+return AVERROR_INVALIDDATA;
 }
 s->inter_intra_pred = 0;
 s->no_rounding  = 1;
-- 
2.19.2

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


Re: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to enumerate devices

2018-11-27 Thread Song, Ruiling


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Mark Thompson
> Sent: Wednesday, November 28, 2018 8:17 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to
> enumerate devices
> 
> Also assert that all required functions are present.
> ---
> On 26/11/2018 08:57, Song, Ruiling wrote:
> >> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of
> >> Mark Thompson
> >> Sent: Monday, November 26, 2018 6:08 AM
> >> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> >> Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to
> >> enumerate devices
> >>
> >> ---
> >>  libavutil/hwcontext_opencl.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> >> index e6cef74269..6a26354c87 100644
> >> --- a/libavutil/hwcontext_opencl.c
> >> +++ b/libavutil/hwcontext_opencl.c
> >> @@ -542,9 +542,9 @@ static int
> >> opencl_device_create_internal(AVHWDeviceContext *hwdev,
> >>  continue;
> >>  }
> >>
> >> -err = opencl_enumerate_devices(hwdev, platforms[p], platform_name,
> >> -   &nb_devices, &devices,
> >> -   selector->context);
> >> +err = selector->enumerate_devices(hwdev, platforms[p],
> platform_name,
> >> +  &nb_devices, &devices,
> >> +  selector->context);
> > I think it is better to check enumerate_devices  against null pointer before
> calling it, although it should works well currently.
> 
> The two enumerate functions should always be set when entering the function,
> since they are always required.  (Unlike the filter, where "do nothing" is a
> reasonable case.)
> 
> How about an assert at the start of the function to check that, like this?
Yes, that's good. It is just helpful when somebody add new platform support but 
happened to forget to give a meaningful function pointer.

Ruiling
> 
> - Mark
> 
> 
>  libavutil/hwcontext_opencl.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index be71c8323e..d3df6221c4 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -500,6 +500,9 @@ static int
> opencl_device_create_internal(AVHWDeviceContext *hwdev,
>   *device_name_src   = NULL;
>  int err, found, p, d;
> 
> +av_assert0(selector->enumerate_platforms &&
> +   selector->enumerate_devices);
> +
>  err = selector->enumerate_platforms(hwdev, &nb_platforms, &platforms,
>  selector->context);
>  if (err)
> @@ -531,9 +534,9 @@ static int
> opencl_device_create_internal(AVHWDeviceContext *hwdev,
>  continue;
>  }
> 
> -err = opencl_enumerate_devices(hwdev, platforms[p], platform_name,
> -   &nb_devices, &devices,
> -   selector->context);
> +err = selector->enumerate_devices(hwdev, platforms[p], platform_name,
> +  &nb_devices, &devices,
> +  selector->context);
>  if (err < 0)
>  continue;
> 
> --
> 2.19.1
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] avcodec/msmpeg4dec: Skip frame if its smaller than 1/8 of the minimal size

2018-11-27 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
11318/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MSMPEG4V1_fuzzer-5710884555456512

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

diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 457a37e745..d278540ec2 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -412,6 +412,9 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
 {
 int code;
 
+if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
+return AVERROR_INVALIDDATA;
+
 if(s->msmpeg4_version==1){
 int start_code = get_bits_long(&s->gb, 32);
 if(start_code!=0x0100){
-- 
2.19.2

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


Re: [FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-27 Thread myp...@gmail.com
On Wed, Nov 28, 2018 at 4:47 AM Carl Eugen Hoyos  wrote:

> 2018-11-27 10:18 GMT+01:00, Jun Zhao :
> > fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
> > [libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid parameter
> > [libaom-av1 @ 0x469f340]   Additional information: g_threads out of range
> > [..MAX_NUM_THREADS]
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  libavcodec/libaomenc.c |3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> > index cb31c55..ccb0cf9 100644
> > --- a/libavcodec/libaomenc.c
> > +++ b/libavcodec/libaomenc.c
> > @@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
> >  enccfg.g_h= avctx->height;
> >  enccfg.g_timebase.num = avctx->time_base.num;
> >  enccfg.g_timebase.den = avctx->time_base.den;
> > -enccfg.g_threads  = avctx->thread_count ? avctx->thread_count :
> > av_cpu_count();
> > +enccfg.g_threads  =
> > + FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(),
> 64);
>
> Is there a limitation in libaom's api that requires users to never set
> g_threads >64 that we missed so far?
> Or is there a bug in libaom that you would like to fix in FFmpeg?
>
> Please explain, Carl Eugen
>
> I  belive this is a libaom's limitation and we missed the check in FFmpeg
part,
libvpx have the same issue and the commit d6b1248fc try to fix the same
issue.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-27 Thread Carl Eugen Hoyos
2018-11-28 1:54 GMT+01:00, myp...@gmail.com :
> On Wed, Nov 28, 2018 at 4:47 AM Carl Eugen Hoyos  wrote:
>
>> 2018-11-27 10:18 GMT+01:00, Jun Zhao :
>> > fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
>> > [libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid parameter
>> > [libaom-av1 @ 0x469f340]   Additional information: g_threads out of
>> > range
>> > [..MAX_NUM_THREADS]
>> >
>> > Signed-off-by: Jun Zhao 
>> > ---
>> >  libavcodec/libaomenc.c |3 ++-
>> >  1 files changed, 2 insertions(+), 1 deletions(-)
>> >
>> > diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
>> > index cb31c55..ccb0cf9 100644
>> > --- a/libavcodec/libaomenc.c
>> > +++ b/libavcodec/libaomenc.c
>> > @@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
>> >  enccfg.g_h= avctx->height;
>> >  enccfg.g_timebase.num = avctx->time_base.num;
>> >  enccfg.g_timebase.den = avctx->time_base.den;
>> > -enccfg.g_threads  = avctx->thread_count ? avctx->thread_count :
>> > av_cpu_count();
>> > +enccfg.g_threads  =
>> > + FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(),
>> 64);
>>
>> Is there a limitation in libaom's api that requires users to never set
>> g_threads >64 that we missed so far?
>> Or is there a bug in libaom that you would like to fix in FFmpeg?
>>
>> Please explain, Carl Eugen
>>
>> I  belive this is a libaom's limitation

Then why isn't the limitation fixed in libaom?
Or is it documented?

> and we missed the check in FFmpeg part,

In which way did we "miss" it, where is it defined that it is invalid
to pass large positive numbers to this option?

> libvpx have the same issue and the commit d6b1248fc
> try to fix the same issue.

Two wrong commits don't make a correct one;-)

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


[FFmpeg-devel] [PATCH] libavfilter/idet: fix double count and offset accuracy on progressive frame

2018-11-27 Thread pon pon
Hello,

I think idet duplicately counts and offsets accuracy of progressive frames,
as repoert in ticket #7565.
If this is corret, the below patch can fix it.

ponpon

diff --git a/libavfilter/vf_idet.c b/libavfilter/vf_idet.c
index 02ae2edcb9..8c355ee2f9 100644
--- a/libavfilter/vf_idet.c
+++ b/libavfilter/vf_idet.c
@@ -285,12 +285,14 @@ static int filter_frame(AVFilterLink *link, AVFrame
*picref)
 if (idet->cur->interlaced_frame) {
 idet->cur->interlaced_frame = 0;
 filter(ctx);
-if (idet->last_type == PROGRESSIVE) {
-idet->interlaced_flag_accuracy --;
-idet->analyze_interlaced_flag --;
-} else if (idet->last_type != UNDETERMINED) {
-idet->interlaced_flag_accuracy ++;
-idet->analyze_interlaced_flag --;
+if (idet->last_type != UNDETERMINED) {
+if (idet->last_type == PROGRESSIVE) {
+idet->interlaced_flag_accuracy --;
+idet->analyze_interlaced_flag --;
+} else {
+idet->interlaced_flag_accuracy ++;
+idet->analyze_interlaced_flag --;
+}
 }
 if (idet->analyze_interlaced_flag == 1) {
 ff_filter_frame(ctx->outputs[0],
av_frame_clone(idet->cur));
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf: add tranpose_opencl filter

2018-11-27 Thread Song, Ruiling
Thanks for your valuable comments, reply inline.

> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Mark Thompson
> Sent: Wednesday, November 28, 2018 8:41 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavf: add tranpose_opencl filter
> 
> On 26/11/2018 07:05, Ruiling Song wrote:
> > Signed-off-by: Ruiling Song 
> > ---
> >  configure |   1 +
> >  libavfilter/Makefile  |   1 +
> >  libavfilter/allfilters.c  |   1 +
> >  libavfilter/opencl/transpose.cl   |  35 +
> >  libavfilter/opencl_source.h   |   1 +
> >  libavfilter/transpose.h   |  34 +
> >  libavfilter/vf_transpose.c|  14 +-
> >  libavfilter/vf_transpose_opencl.c | 294
> ++
> >  8 files changed, 368 insertions(+), 13 deletions(-)
> >  create mode 100644 libavfilter/opencl/transpose.cl
> >  create mode 100644 libavfilter/transpose.h
> >  create mode 100644 libavfilter/vf_transpose_opencl.c
> >
> > diff --git a/configure b/configure
> > index b4f944c..dcb3f5f 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3479,6 +3479,7 @@ tinterlace_merge_test_deps="tinterlace_filter"
> >  tinterlace_pad_test_deps="tinterlace_filter"
> >  tonemap_filter_deps="const_nan"
> >  tonemap_opencl_filter_deps="opencl const_nan"
> > +transpose_opencl_filter_deps="opencl"
> >  unsharp_opencl_filter_deps="opencl"
> >  uspp_filter_deps="gpl avcodec"
> >  vaguedenoiser_filter_deps="gpl"
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index 1895fa2..6e26581 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -393,6 +393,7 @@ OBJS-$(CONFIG_TONEMAP_OPENCL_FILTER) +=
> vf_tonemap_opencl.o colorspace.o
> >  OBJS-$(CONFIG_TPAD_FILTER)   += vf_tpad.o
> >  OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
> >  OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER)  += vf_transpose_npp.o
> cuda_check.o
> > +OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER)   += vf_transpose_opencl.o
> opencl.o opencl/transpose.o
> >  OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
> >  OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o
> framesync.o
> >  OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
> > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> > index 837c99e..a600069 100644
> > --- a/libavfilter/allfilters.c
> > +++ b/libavfilter/allfilters.c
> > @@ -372,6 +372,7 @@ extern AVFilter ff_vf_tonemap_opencl;
> >  extern AVFilter ff_vf_tpad;
> >  extern AVFilter ff_vf_transpose;
> >  extern AVFilter ff_vf_transpose_npp;
> > +extern AVFilter ff_vf_transpose_opencl;
> >  extern AVFilter ff_vf_trim;
> >  extern AVFilter ff_vf_unpremultiply;
> >  extern AVFilter ff_vf_unsharp;
> > diff --git a/libavfilter/opencl/transpose.cl 
> > b/libavfilter/opencl/transpose.cl
> > new file mode 100644
> > index 000..e6388ab
> > --- /dev/null
> > +++ b/libavfilter/opencl/transpose.cl
> > @@ -0,0 +1,35 @@
> > +/*
> > + * 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
> > + */
> > +kernel void transpose(__write_only image2d_t dst,
> > +  __read_only image2d_t src,
> > +  int dir) {
> > +const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
> > +   CLK_ADDRESS_CLAMP_TO_EDGE   |
> > +   CLK_FILTER_NEAREST);
> > +
> > +int2 size = get_image_dim(dst);
> > +int x = get_global_id(0);
> > +int y = get_global_id(1);
> > +
> > +int xin = (dir & 2) ? (size.y - 1 - y) : y;
> > +int yin = (dir & 1) ? (size.x - 1 - x) : x;
> > +float4 data = read_imagef(src, sampler, (int2)(xin, yin));
> > +
> > +if (x < size.x && y < size.y)
> > +write_imagef(dst, (int2)(x, y), data);
> > +}
> 
> Does the dependency on dir have any effect on speed here?  Any call is only 
> ever
> going to use one side of each of the dir cases, so it feels like it might be 
> nicer to
> hard-code that so they aren't included in the compiled code at all.
For such memory bound OpenCL kernel, some little more arithmetic operation 
would not affect the overall perf

Re: [FFmpeg-devel] [PATCH] libavfilter/idet: fix double count and offset accuracy on progressive frame

2018-11-27 Thread Carl Eugen Hoyos
2018-11-28 3:01 GMT+01:00, pon pon :

> I think idet duplicately counts and offsets accuracy of progressive
> frames, as repoert in ticket #7565.

Unfortunately, this ticket is missing all necessary information including
the command line, the complete, uncut console output and a sample file.

For which sample is your patch supposed to make a difference?

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


[FFmpeg-devel] [PATCH V2] lavf: add transpose_opencl filter

2018-11-27 Thread Ruiling Song
Signed-off-by: Ruiling Song 
---
 configure |   1 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/opencl/transpose.cl   |  35 +
 libavfilter/opencl_source.h   |   1 +
 libavfilter/transpose.h   |  34 +
 libavfilter/vf_transpose.c|  14 +-
 libavfilter/vf_transpose_opencl.c | 288 ++
 8 files changed, 362 insertions(+), 13 deletions(-)
 create mode 100644 libavfilter/opencl/transpose.cl
 create mode 100644 libavfilter/transpose.h
 create mode 100644 libavfilter/vf_transpose_opencl.c

diff --git a/configure b/configure
index b4f944c..dcb3f5f 100755
--- a/configure
+++ b/configure
@@ -3479,6 +3479,7 @@ tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
 tonemap_filter_deps="const_nan"
 tonemap_opencl_filter_deps="opencl const_nan"
+transpose_opencl_filter_deps="opencl"
 unsharp_opencl_filter_deps="opencl"
 uspp_filter_deps="gpl avcodec"
 vaguedenoiser_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1895fa2..6e26581 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -393,6 +393,7 @@ OBJS-$(CONFIG_TONEMAP_OPENCL_FILTER) += 
vf_tonemap_opencl.o colorspace.o
 OBJS-$(CONFIG_TPAD_FILTER)   += vf_tpad.o
 OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
 OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER)  += vf_transpose_npp.o cuda_check.o
+OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER)   += vf_transpose_opencl.o opencl.o 
opencl/transpose.o
 OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
 OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o framesync.o
 OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 837c99e..a600069 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -372,6 +372,7 @@ extern AVFilter ff_vf_tonemap_opencl;
 extern AVFilter ff_vf_tpad;
 extern AVFilter ff_vf_transpose;
 extern AVFilter ff_vf_transpose_npp;
+extern AVFilter ff_vf_transpose_opencl;
 extern AVFilter ff_vf_trim;
 extern AVFilter ff_vf_unpremultiply;
 extern AVFilter ff_vf_unsharp;
diff --git a/libavfilter/opencl/transpose.cl b/libavfilter/opencl/transpose.cl
new file mode 100644
index 000..e6388ab
--- /dev/null
+++ b/libavfilter/opencl/transpose.cl
@@ -0,0 +1,35 @@
+/*
+ * 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
+ */
+kernel void transpose(__write_only image2d_t dst,
+  __read_only image2d_t src,
+  int dir) {
+const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+   CLK_ADDRESS_CLAMP_TO_EDGE   |
+   CLK_FILTER_NEAREST);
+
+int2 size = get_image_dim(dst);
+int x = get_global_id(0);
+int y = get_global_id(1);
+
+int xin = (dir & 2) ? (size.y - 1 - y) : y;
+int yin = (dir & 1) ? (size.x - 1 - x) : x;
+float4 data = read_imagef(src, sampler, (int2)(xin, yin));
+
+if (x < size.x && y < size.y)
+write_imagef(dst, (int2)(x, y), data);
+}
diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h
index 2f67d89..4118138 100644
--- a/libavfilter/opencl_source.h
+++ b/libavfilter/opencl_source.h
@@ -25,6 +25,7 @@ extern const char *ff_opencl_source_convolution;
 extern const char *ff_opencl_source_neighbor;
 extern const char *ff_opencl_source_overlay;
 extern const char *ff_opencl_source_tonemap;
+extern const char *ff_opencl_source_transpose;
 extern const char *ff_opencl_source_unsharp;
 
 #endif /* AVFILTER_OPENCL_SOURCE_H */
diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
new file mode 100644
index 000..d4bb4da
--- /dev/null
+++ b/libavfilter/transpose.h
@@ -0,0 +1,34 @@
+/*
+ * 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 warr

[FFmpeg-devel] [PATCH, v2] lavc/qsvenc: assert uninitialized pict_type

2018-11-27 Thread Linjie Fu
Assert in function ff_qsv_encode to avoid using uninitialized value:

FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pict_type = pict_type;
FF_ENABLE_DEPRECATION_WARNINGS

Signed-off-by: Linjie Fu 
---
[v2] assert instead of setting the pict_type to AV_PICTURE_TYPE_NONE;

 libavcodec/qsvenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7a031297fe..fd9f4f0934 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1333,6 +1333,8 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 pict_type = AV_PICTURE_TYPE_P;
 else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & 
MFX_FRAMETYPE_xB)
 pict_type = AV_PICTURE_TYPE_B;
+else
+av_assert0(!"Uninitialized pict_type!");
 
 #if FF_API_CODED_FRAME
 FF_DISABLE_DEPRECATION_WARNINGS
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-27 Thread myp...@gmail.com
On Wed, Nov 28, 2018 at 9:41 AM Carl Eugen Hoyos  wrote:

> 2018-11-28 1:54 GMT+01:00, myp...@gmail.com :
> > On Wed, Nov 28, 2018 at 4:47 AM Carl Eugen Hoyos 
> wrote:
> >
> >> 2018-11-27 10:18 GMT+01:00, Jun Zhao :
> >> > fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
> >> > [libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid
> parameter
> >> > [libaom-av1 @ 0x469f340]   Additional information: g_threads out of
> >> > range
> >> > [..MAX_NUM_THREADS]
> >> >
> >> > Signed-off-by: Jun Zhao 
> >> > ---
> >> >  libavcodec/libaomenc.c |3 ++-
> >> >  1 files changed, 2 insertions(+), 1 deletions(-)
> >> >
> >> > diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> >> > index cb31c55..ccb0cf9 100644
> >> > --- a/libavcodec/libaomenc.c
> >> > +++ b/libavcodec/libaomenc.c
> >> > @@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext
> *avctx,
> >> >  enccfg.g_h= avctx->height;
> >> >  enccfg.g_timebase.num = avctx->time_base.num;
> >> >  enccfg.g_timebase.den = avctx->time_base.den;
> >> > -enccfg.g_threads  = avctx->thread_count ? avctx
> ->thread_count :
> >> > av_cpu_count();
> >> > +enccfg.g_threads  =
> >> > + FFMIN(avctx->thread_count ? avctx->thread_count : a
> v_cpu_count(),
> >> 64);
> >>
> >> Is there a limitation in libaom's api that requires users to never set
> >> g_threads >64 that we missed so far?
> >> Or is there a bug in libaom that you would like to fix in FFmpeg?
> >>
> >> Please explain, Carl Eugen
> >>
> >> I  belive this is a libaom's limitation
>
> Then why isn't the limitation fixed in libaom?
> Or is it documented?
>
> This is the check in libaom:
https://aomedia.googlesource.com/aom/+/master/av1/av1_cx_iface.c#254

or you can grep "MAX_NUM_THREADS" in libaom :)



> > and we missed the check in FFmpeg part,
>
> In which way did we "miss" it, where is it defined that it is invalid
> to pass large positive numbers to this option?
>
I think we usually don't  setting the avctx->thread_count and av_cpu_count()
< 64 in most of the CPU, but in our test environment (Intel(R) Xeon(R) Gold
6152) av_cpu_count == 88, this is the reason we didn't find this issue
before this case.

>
> > libvpx have the same issue and the commit d6b1248fc
> > try to fix the same issue.
>
> Two wrong commits don't make a correct one;-)
>
> Carl Eugen
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH,v4] lavc/qsvenc: add VDENC support for H264

2018-11-27 Thread Linjie Fu
Add VDENC(lowpower mode) support for QSV H264

It's an experimental function(like lowpower in vaapi) with
some limitations:
- CBR/VBR require HuC which should be explicitly loaded via i915
module parameter(i915.enable_guc=2 for linux kernel version >= 4.16)

Use option "-low_power 1" to enable VDENC.
Add in dump_video_param() to show the status of VDENC in runtime log.

Signed-off-by: Linjie Fu 
---
[v2]: modified the commit message and option comments, use AV_OPT_TYPE_BOOL
to replace AV_OPT_TYPE_INT.
[v3]: enable H264 VDENC separately.
[v4]: Add in dump_video_param to show the status of VDENC in runtime
log.

 libavcodec/qsvenc.c  | 11 +++
 libavcodec/qsvenc.h  |  2 ++
 libavcodec/qsvenc_h264.c |  3 +++
 3 files changed, 16 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 948751daf4..42804e68af 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -226,6 +226,14 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 av_log(avctx, AV_LOG_VERBOSE, "\n");
 #endif
 
+#if QSV_HAVE_VDENC
+av_log(avctx, AV_LOG_VERBOSE, "VDENC: ");
+if (info->LowPower == MFX_CODINGOPTION_ON)
+av_log(avctx, AV_LOG_VERBOSE, "ON\n");
+else
+av_log(avctx, AV_LOG_VERBOSE, "OFF\n");
+#endif
+
 #if QSV_VERSION_ATLEAST(1, 8)
 av_log(avctx, AV_LOG_VERBOSE,
"RepeatPPS: %s; NumMbPerSlice: %"PRIu16"; LookAheadDS: ",
@@ -464,6 +472,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 }
 }
 
+#if QSV_HAVE_VDENC
+q->param.mfx.LowPower   = q->low_power ? 
MFX_CODINGOPTION_ON:MFX_CODINGOPTION_OFF;
+#endif
 q->param.mfx.CodecProfile   = q->profile;
 q->param.mfx.TargetUsage= avctx->compression_level;
 q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 50cc4267e7..a396aa7d3f 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -44,6 +44,7 @@
 #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
 #define QSV_HAVE_LA_DS  QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
+#define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
 
 #if defined(_WIN32) || defined(__CYGWIN__)
 #define QSV_HAVE_AVBR   QSV_VERSION_ATLEAST(1, 3)
@@ -162,6 +163,7 @@ typedef struct QSVEncContext {
 int recovery_point_sei;
 
 int a53_cc;
+int low_power;
 
 #if QSV_HAVE_MF
 int mfmode;
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 07c9d64e6b..40071d805a 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -153,6 +153,9 @@ static const AVOption options[] = {
 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_DISABLED }, 
INT_MIN, INT_MAX, VE, "mfmode" },
 { "auto"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_AUTO }, 
INT_MIN, INT_MAX, VE, "mfmode" },
 #endif
+#if QSV_HAVE_VDENC
+{ "low_power", "enable low power mode(experimental: many limitations by 
mfx version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 
=  0 }, 0, 1, VE},
+#endif
 
 { NULL },
 };
-- 
2.17.1

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


[FFmpeg-devel] [PATCH] lavfi/tonemap_opencl: reuse matrix calculation from vf_colorspace

2018-11-27 Thread Ruiling Song
As these functions are moved to shared file, other colorspace-related
filters could also leverage the code.

Signed-off-by: Ruiling Song 
---
 libavfilter/colorspace.c| 71 +
 libavfilter/colorspace.h|  4 ++
 libavfilter/opencl/colorspace_common.cl | 25 ---
 libavfilter/vf_colorspace.c | 80 ++---
 libavfilter/vf_tonemap_opencl.c | 62 +++--
 5 files changed, 106 insertions(+), 136 deletions(-)

diff --git a/libavfilter/colorspace.c b/libavfilter/colorspace.c
index c668221..19616e4 100644
--- a/libavfilter/colorspace.c
+++ b/libavfilter/colorspace.c
@@ -93,6 +93,77 @@ void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients 
*coeffs,
 rgb2xyz[2][1] *= sg;
 rgb2xyz[2][2] *= sb;
 }
+static const double ycgco_matrix[3][3] =
+{
+{  0.25, 0.5,  0.25 },
+{ -0.25, 0.5, -0.25 },
+{  0.5,  0,   -0.5  },
+};
+
+static const double gbr_matrix[3][3] =
+{
+{ 0,1,   0   },
+{ 0,   -0.5, 0.5 },
+{ 0.5, -0.5, 0   },
+};
+
+/*
+ * All constants explained in e.g. 
https://linuxtv.org/downloads/v4l-dvb-apis/ch02s06.html
+ * The older ones (bt470bg/m) are also explained in their respective ITU docs
+ * (e.g. 
https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf)
+ * whereas the newer ones can typically be copied directly from wikipedia :)
+ */
+static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB] = {
+[AVCOL_SPC_FCC]= { 0.30,   0.59,   0.11   },
+[AVCOL_SPC_BT470BG]= { 0.299,  0.587,  0.114  },
+[AVCOL_SPC_SMPTE170M]  = { 0.299,  0.587,  0.114  },
+[AVCOL_SPC_BT709]  = { 0.2126, 0.7152, 0.0722 },
+[AVCOL_SPC_SMPTE240M]  = { 0.212,  0.701,  0.087  },
+[AVCOL_SPC_YCOCG]  = { 0.25,   0.5,0.25   },
+[AVCOL_SPC_RGB]= { 1,  1,  1  },
+[AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 },
+[AVCOL_SPC_BT2020_CL]  = { 0.2627, 0.6780, 0.0593 },
+};
+
+const struct LumaCoefficients *ff_get_luma_coefficients(enum AVColorSpace csp)
+{
+const struct LumaCoefficients *coeffs;
+
+if (csp >= AVCOL_SPC_NB)
+return NULL;
+coeffs = &luma_coefficients[csp];
+if (!coeffs->cr)
+return NULL;
+
+return coeffs;
+}
+
+void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
+   double rgb2yuv[3][3])
+{
+double bscale, rscale;
+
+// special ycgco matrix
+if (coeffs->cr == 0.25 && coeffs->cg == 0.5 && coeffs->cb == 0.25) {
+memcpy(rgb2yuv, ycgco_matrix, sizeof(double) * 9);
+return;
+} else if (coeffs->cr == 1 && coeffs->cg == 1 && coeffs->cb == 1) {
+memcpy(rgb2yuv, gbr_matrix, sizeof(double) * 9);
+return;
+}
+
+rgb2yuv[0][0] = coeffs->cr;
+rgb2yuv[0][1] = coeffs->cg;
+rgb2yuv[0][2] = coeffs->cb;
+bscale = 0.5 / (coeffs->cb - 1.0);
+rscale = 0.5 / (coeffs->cr - 1.0);
+rgb2yuv[1][0] = bscale * coeffs->cr;
+rgb2yuv[1][1] = bscale * coeffs->cg;
+rgb2yuv[1][2] = 0.5;
+rgb2yuv[2][0] = 0.5;
+rgb2yuv[2][1] = rscale * coeffs->cg;
+rgb2yuv[2][2] = rscale * coeffs->cb;
+}
 
 double ff_determine_signal_peak(AVFrame *in)
 {
diff --git a/libavfilter/colorspace.h b/libavfilter/colorspace.h
index 9366818..459a5df 100644
--- a/libavfilter/colorspace.h
+++ b/libavfilter/colorspace.h
@@ -44,6 +44,10 @@ void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients 
*coeffs,
const struct WhitepointCoefficients *wp,
double rgb2xyz[3][3]);
 
+const struct LumaCoefficients *ff_get_luma_coefficients(enum AVColorSpace csp);
+void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
+   double rgb2yuv[3][3]);
+
 double ff_determine_signal_peak(AVFrame *in);
 void ff_update_hdr_metadata(AVFrame *in, double peak);
 
diff --git a/libavfilter/opencl/colorspace_common.cl 
b/libavfilter/opencl/colorspace_common.cl
index 94a4dd0..1d68a54 100644
--- a/libavfilter/opencl/colorspace_common.cl
+++ b/libavfilter/opencl/colorspace_common.cl
@@ -39,31 +39,6 @@ constant const float ST2084_C1 = 0.8359375f;
 constant const float ST2084_C2 = 18.8515625f;
 constant const float ST2084_C3 = 18.6875f;
 
-__constant float yuv2rgb_bt2020[] = {
-1.0f, 0.0f, 1.4746f,
-1.0f, -0.16455f, -0.57135f,
-1.0f, 1.8814f, 0.0f
-};
-
-__constant float yuv2rgb_bt709[] = {
-1.0f, 0.0f, 1.5748f,
-1.0f, -0.18732f, -0.46812f,
-1.0f, 1.8556f, 0.0f
-};
-
-__constant float rgb2yuv_bt709[] = {
-0.2126f, 0.7152f, 0.0722f,
--0.11457f, -0.38543f, 0.5f,
-0.5f, -0.45415f, -0.04585f
-};
-
-__constant float rgb2yuv_bt2020[] ={
-0.2627f, 0.678f, 0.0593f,
--0.1396f, -0.36037f, 0.5f,
-0.5f, -0.4598f, -0.0402f,
-};
-
-
 float get_luma_dst(float3 c) {
 return luma_dst.x * c.x + luma_dst.y * c.y + luma_dst.z * c.z;
 }
diff --git a/libavfilter/vf_colors

Re: [FFmpeg-devel] [PATCH] libavfilter/idet: fix double count and offset accuracy on progressive frame

2018-11-27 Thread pon pon
I have attached logs in tichet #7565.
idet before patch (72.6x) is far faster than after (62.2x).
I think it means processes terminate by double counts than expeccted.
How do you thinnk about it?

ponpon

2018年11月28日(水) 11:24 Carl Eugen Hoyos :

> 2018-11-28 3:01 GMT+01:00, pon pon :
>
> > I think idet duplicately counts and offsets accuracy of progressive
> > frames, as repoert in ticket #7565.
>
> Unfortunately, this ticket is missing all necessary information including
> the command line, the complete, uncut console output and a sample file.
>
> For which sample is your patch supposed to make a difference?
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v3] libavfilter: add transpose_vaapi filter

2018-11-27 Thread Zachary Zhou
Swap width and height when do clock/cclock rotation
Add 180/180_flip options

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128
-hwaccel_output_format vaapi -i input.264 -vf "transpose_vaapi=clock_flip"
-c:v h264_vaapi output.h264

Signed-off-by: Zachary Zhou 
---
 configure|   2 +
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_transpose_vaapi.c | 356 +++
 4 files changed, 360 insertions(+)
 create mode 100644 libavfilter/vf_transpose_vaapi.c

diff --git a/configure b/configure
index ab3144e459..6e711bd9c6 100755
--- a/configure
+++ b/configure
@@ -3451,6 +3451,7 @@ scale_filter_deps="swscale"
 scale_qsv_filter_deps="libmfx"
 select_filter_select="scene_sad"
 sharpness_vaapi_filter_deps="vaapi"
+transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags"
 showcqt_filter_deps="avcodec avformat swscale"
 showcqt_filter_suggest="libfontconfig libfreetype"
 showcqt_filter_select="fft"
@@ -5975,6 +5976,7 @@ check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode 
-D_WIN32_WINNT=0x0602
 
 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
 check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
+check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1895fa2b0d..97e1786071 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -356,6 +356,7 @@ OBJS-$(CONFIG_SETRANGE_FILTER)   += 
vf_setparams.o
 OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o
 OBJS-$(CONFIG_SETTB_FILTER)  += settb.o
 OBJS-$(CONFIG_SHARPNESS_VAAPI_FILTER)+= vf_misc_vaapi.o vaapi_vpp.o
+OBJS-$(CONFIG_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_vaapi.o 
vaapi_vpp.o
 OBJS-$(CONFIG_SHOWINFO_FILTER)   += vf_showinfo.o
 OBJS-$(CONFIG_SHOWPALETTE_FILTER)+= vf_showpalette.o
 OBJS-$(CONFIG_SHUFFLEFRAMES_FILTER)  += vf_shuffleframes.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 837c99eb75..f0c69e9c67 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -338,6 +338,7 @@ extern AVFilter ff_vf_setrange;
 extern AVFilter ff_vf_setsar;
 extern AVFilter ff_vf_settb;
 extern AVFilter ff_vf_sharpness_vaapi;
+extern AVFilter ff_vf_transpose_vaapi;
 extern AVFilter ff_vf_showinfo;
 extern AVFilter ff_vf_showpalette;
 extern AVFilter ff_vf_shuffleframes;
diff --git a/libavfilter/vf_transpose_vaapi.c b/libavfilter/vf_transpose_vaapi.c
new file mode 100644
index 00..ca7203e880
--- /dev/null
+++ b/libavfilter/vf_transpose_vaapi.c
@@ -0,0 +1,356 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "vaapi_vpp.h"
+
+typedef enum {
+TRANSPOSE_PT_TYPE_NONE,
+TRANSPOSE_PT_TYPE_LANDSCAPE,
+TRANSPOSE_PT_TYPE_PORTRAIT,
+} PassthroughType;
+
+enum TransposeDir {
+TRANSPOSE_CCLOCK_FLIP,
+TRANSPOSE_CLOCK,
+TRANSPOSE_CCLOCK,
+TRANSPOSE_CLOCK_FLIP,
+TRANSPOSE_180,
+TRANSPOSE_180_FLIP,
+};
+
+typedef struct TransposeVAAPIContext {
+VAAPIVPPContext vpp_ctx; // must be the first field
+int passthrough; // PassthroughType, landscape passthrough mode 
enabled
+int dir; // TransposeDir
+
+int rotation_state;
+int mirror_state;
+} TransposeVAAPIContext;
+
+static int transpose_vaapi_build_filter_params(AVFilterContext *avctx)
+{
+VAAPIVPPContext *vpp_ctx   = avctx->priv;
+TransposeVAAPIContext *ctx = avctx->priv;
+VAStatus vas;
+int support_flag;
+VAProcPipelineCaps pipeline_caps;
+
+memset(&pipeline_caps, 0, sizeof(pipeline_caps));
+vas = vaQueryVideoProcPipelineCaps(vpp_ctx->hwctx->display,
+   vpp_ctx->va_context,
+ 

[FFmpeg-devel] [PATCH 2/3] lavf/avidec: don't treat I/O errors as EOF

2018-11-27 Thread Rodger Combs
---
 libavformat/avidec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 3f074795a7..1d131b299c 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1383,8 +1383,8 @@ static int ni_prepare_read(AVFormatContext *s)
 if (i >= 0) {
 int64_t pos = best_st->index_entries[i].pos;
 pos += best_ast->packet_size - best_ast->remaining;
-if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
-  return AVERROR_EOF;
+if ((pos = avio_seek(s->pb, pos + 8, SEEK_SET)) < 0)
+  return pos;
 
 av_assert0(best_ast->remaining <= best_ast->packet_size);
 
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 1/3] lavf/matroskadec: don't treat I/O errors as EOF

2018-11-27 Thread Rodger Combs
pb->eof_reached is set on error, so we need to check pb->error,
even after checking pb->eof_reached or avio_feof(pb), or else we
can end up returning AVERROR_EOF instead of the actual error code.
---
 libavformat/matroskadec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d3c9c33720..2774ccabb2 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -789,7 +789,7 @@ static int matroska_resync(MatroskaDemuxContext *matroska, 
int64_t last_pos)
 }
 
 matroska->done = 1;
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 /*
@@ -836,7 +836,7 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, 
AVIOContext *pb,
pos, pos);
 return pb->error ? pb->error : AVERROR(EIO);
 }
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 /* get the length of the EBML number */
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 3/3] lavf/movdec: don't treat I/O errors as EOF

2018-11-27 Thread Rodger Combs
---
 libavformat/mov.c | 42 +-
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 542e92ec00..607ce30178 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -645,7 +645,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 for (type = 0; type != -1 && avio_tell(pb) < next; ) {
 if(avio_feof(pb))
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 type = avio_rb16(pb);
 len = avio_rb16(pb);
 av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);
@@ -2001,9 +2001,9 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 sc->chunk_count = i;
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STCO atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2535,9 +2535,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext 
*pb, int entries)
 sc->stsd_count++;
 }
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STSD atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2669,9 +2669,9 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 }
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STSC atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2723,9 +2723,9 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 sc->stps_count = i;
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STPS atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2772,9 +2772,9 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 sc->keyframe_count = i;
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STSS atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2860,9 +2860,9 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 av_free(buf);
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STSZ atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -2938,9 +2938,9 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 sc->nb_frames_for_fps += total_sample_count;
 }
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STTS atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 st->nb_frames= total_sample_count;
@@ -3017,7 +3017,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 sc->ctts_count = ctts_count;
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted CTTS atom\n");
 return AVERROR_EOF;
 }
@@ -3066,9 +3066,9 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 sc->rap_group_count = i;
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SBGP atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 return 0;
@@ -4912,9 +4912,9 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 fix_frag_index_entries(&c->frag_index, next_frag_index,
frag->track_id, entries);
 
-if (pb->eof_reached) {
+if (avio_feof(pb)) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted TRUN atom\n");
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 }
 
 frag->implicit_offset = offset;
@@ -7627,7 +7627,7 @@ static int mov_switch_root(AVFormatContext *s, int64_t 
target, int index)
 if (ret < 0)
 return ret;
 if (avio_feof(s->pb))
-return AVERROR_EOF;
+return pb->error ? pb->error : AVERROR_EOF;
 av_log(s, AV_LOG_TRACE, "read fragments, offset 0x%"PRIx64"\n", 
avio_tell(s->pb));
 
 return 1;
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH V6] Add a filter implementing HDR image generation from a single exposure using deep CNNs

2018-11-27 Thread Guo, Yejun
thanks for the reviews, let me summarize the unfixed issues and my plan.

- more resolutions support besides 1080p. (comment from Vittorio Giovara, Liu 
Steven, Li Zhong)
I've sent an issue to tensorflow to explain the issue and provide a possible 
solution, 
see https://github.com/tensorflow/tensorflow/issues/2118#issuecomment-441146241.
Before it is finally fixed by tensorflow, as a workaround, I'll prepare more 
model files
for typical resolutions, one model file for one resolution. And the user need 
to choose
the correct model file for the given resolution.

- native mode support.   (comment from Pedro Arthur, Liu Steven)
There are 16 ops not supported now,  I plan to add them one by one. And there 
is 
another thing to add a tool to write the native model file directly or convert
from TF model file.

- metadata for HDR video encoding. (comment from Vittorio Giovara, Li Zhong)
will figure out a method for it.


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Guo, Yejun
> Sent: Friday, November 16, 2018 10:30 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH V6] Add a filter implementing HDR image
> generation from a single exposure using deep CNNs
> 
> see the algorithm's paper and code below.
> 
> the filter's parameter looks like:
> sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l
> e
> 
> The input of the deep CNN model is RGB24 while the output is float for each
> color channel. This is the filter's default behavior to output format with
> gbrpf32le. And gbrp10le is also supported as the output, so we can see the
> rendering result in a player, as a reference.
> 
> To generate the model file, we need modify the original script a little.
> - set name='y' for y_final within script at
> https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py
> - add the following code to the script at
> https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict.py
> 
> graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def,
> ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False)
> 
> And I also uploaded the model file under
> https://drive.google.com/drive/folders/1URsRY5g-VdE-kHlP5vQoLoimMIZ-
> SX00?usp=sharing.
> 
> The filter only works when tensorflow C api is supported in the system,
> native backend is not supported since there are some different types of
> layers in the deep CNN model, besides CONV and DEPTH_TO_SPACE.
> 
> https://arxiv.org/pdf/1710.07480.pdf:
>   author   = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy 
> and
> Mantiuk, Rafał and Unger, Jonas",
>   title= "HDR image reconstruction from a single exposure using deep
> CNNs",
>   journal  = "ACM Transactions on Graphics (TOG)",
>   number   = "6",
>   volume   = "36",
>   articleno= "178",
>   year = "2017"
> 
> https://github.com/gabrieleilertsen/hdrcnn
> 
> btw, as a whole solution, metadata should also be generated from the sdr
> video, so to be encoded as a HDR video. Not supported yet.
> This patch just focuses on this paper.
> 
> This filter accepts 8bit frame (RGB24) and outputs 10bit/float frame, and
> there's no reference image, so it is not feasible to use criteria such as 
> PNSR,
> SSIM.
> 
> I choose the same method described in the paper to demo the filter effect,
> that means the frames before/after the filter are reduced by 3 stops.
> 
> The native video (test.native.mp4) is created from 7 png files at
> https://github.com/gabrieleilertsen/hdrcnn/tree/master/data (the size of
> the image is enlarged to 1920*1080 with extra area filled with white) with
> command line:
> ffmpeg -f image2 -i ./img_%03d.png -c:v libx264 -preset veryslow -crf 1
> test.native.mp4.
> 
> And two rgb24 videos are generated before/after the filter with -3 stops by
> modifying the code a little, see in the video folder at the google drive (the
> same place as where the model file locates).
> 
> For your convenient, I also dump png files from generated videos and
> combine the before/after pngs into one file, see in png folder at the google
> drive.
> 
> Signed-off-by: Guo, Yejun 
> ---
>  configure|   1 +
>  doc/filters.texi |  38 +++
>  libavfilter/Makefile |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vf_sdr2hdr.c | 270
> +++
>  5 files changed, 311 insertions(+)
>  create mode 100644 libavfilter/vf_sdr2hdr.c
> 
> diff --git a/configure b/configure
> index 9bc4cf3..08db4eb 100755
> --- a/configure
> +++ b/configure
> @@ -3447,6 +3447,7 @@ sab_filter_deps="gpl swscale"
>  scale2ref_filter_deps="swscale"
>  scale_filter_deps="swscale"
>  scale_qsv_filter_deps="libmfx"
> +sdr2hdr_filter_deps="libtensorflow"
>  select_filter_select="scene_sad"
>  sharpness_vaapi_filter_deps="vaapi"
>  showcqt_filter_deps="avcodec avformat swscale"
> diff --git a/doc/filters.texi b/doc/filters.texi