[FFmpeg-devel] [PATCH] avformat/flacenc: support writing attached pictures

2018-04-14 Thread James Almer
From: Rodger Combs 

Signed-off-by: James Almer 
---
Changed to not try to mux any kind of video as cover art and instead
only bother with streams marked as attached pictures.
Also using each stream's priv_data to hold the picture instead of
an array in the format's priv_data now.

Will push tomorrow or Monday, as this has been rotting on the ml for
a while and has also been requested to be in the 4.0 release.

 libavformat/flacenc.c | 276 +++---
 1 file changed, 240 insertions(+), 36 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9ef61..6bbe4b8b3e 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -21,10 +21,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "flacenc.h"
+#include "id3v2.h"
+#include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
 
@@ -33,8 +36,15 @@ typedef struct FlacMuxerContext {
 const AVClass *class;
 int write_header;
 
+int audio_stream_idx;
+int waiting_pics;
+/* audio packets are queued here until we get all the attached pictures */
+AVPacketList *queue, *queue_end;
+
 /* updated streaminfo sent by the encoder at the end */
 uint8_t *streaminfo;
+
+unsigned attached_types;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -74,31 +84,161 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_write_picture(struct AVFormatContext *s, AVPacket *pkt)
 {
-int ret;
-int padding = s->metadata_header_padding;
-AVCodecParameters *par = s->streams[0]->codecpar;
-FlacMuxerContext *c   = s->priv_data;
-
-if (!c->write_header)
+FlacMuxerContext *c = s->priv_data;
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0;
+
+if (!pkt->data)
 return 0;
 
-if (s->nb_streams > 1) {
-av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
+return AVERROR(EINVAL);
+}
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if ((c->attached_types & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
 return AVERROR(EINVAL);
 }
-if (par->codec_id != AV_CODEC_ID_FLAC) {
-av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
 return AVERROR(EINVAL);
 }
 
+c->attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+avio_w8(pb, 0x06);
+avio_wb24(pb, 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + 
pkt->size);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+return 0;
+}
+
+static int flac_finish_header(struct AVFormatContext *s)
+{
+int i, ret, padding = s->metadata_header_padding;
 if (padding < 0)
 padding = 8192;
 /* The FLAC specification states that 24 bits are used to represent the
  * size of a metadata block so we must clip this value to 2^24-1. */
 padding = av_clip_uintp2(padding, 24);
 
+for (i = 0; i < 

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

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Saturday, April 14, 2018 6:54 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations
> 

Hi Mark,
I reviewed and tested all 5 patches in set all together.
Now the code looks cleaner.
My local tests passed for dx9 and dx11 with and without -hwaccel_output_format.

I am waiting patches to be applied to propose new patch with hwcontext_amf in 
libavutil.

Thanks,
Alexander

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


[FFmpeg-devel] [PATCH] avdevice/decklink_commmon: enhance error messages when iterator creation fails

2018-04-14 Thread Marton Balint
Show a more useful error message which specifies the required driver version
for the build, and use the correct context in the error message for WIN32.

Signed-off-by: Marton Balint 
---
 libavdevice/decklink_common.cpp | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index b889033cf8..d8cced7c74 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -53,25 +53,29 @@ extern "C" {
 
 #include "decklink_common.h"
 
-#ifdef _WIN32
-IDeckLinkIterator *CreateDeckLinkIteratorInstance(void)
+static IDeckLinkIterator *decklink_create_iterator(AVFormatContext *avctx)
 {
 IDeckLinkIterator *iter;
 
+#ifdef _WIN32
 if (CoInitialize(NULL) < 0) {
-av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n");
+av_log(avctx, AV_LOG_ERROR, "COM initialization failed.\n");
 return NULL;
 }
 
 if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
  IID_IDeckLinkIterator, (void**) ) != S_OK) {
-av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n");
-return NULL;
+iter = NULL;
 }
+#else
+iter = CreateDeckLinkIteratorInstance();
+#endif
+if (!iter)
+av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator. "
+"Make sure you have DeckLink drivers " 
BLACKMAGIC_DECKLINK_API_VERSION_STRING " or newer installed.\n");
 
 return iter;
 }
-#endif
 
 #ifdef _WIN32
 static char *dup_wchar_to_utf8(wchar_t *w)
@@ -285,13 +289,11 @@ int ff_decklink_list_devices(AVFormatContext *avctx,
  int show_inputs, int show_outputs)
 {
 IDeckLink *dl = NULL;
-IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
+IDeckLinkIterator *iter = decklink_create_iterator(avctx);
 int ret = 0;
 
-if (!iter) {
-av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
+if (!iter)
 return AVERROR(EIO);
-}
 
 while (ret == 0 && iter->Next() == S_OK) {
 IDeckLinkOutput *output_config;
@@ -442,11 +444,9 @@ int ff_decklink_init_device(AVFormatContext *avctx, const 
char* name)
 struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
 struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
 IDeckLink *dl = NULL;
-IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
-if (!iter) {
-av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
+IDeckLinkIterator *iter = decklink_create_iterator(avctx);
+if (!iter)
 return AVERROR_EXTERNAL;
-}
 
 while (iter->Next() == S_OK) {
 const char *displayName;
-- 
2.13.6

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


[FFmpeg-devel] [PATCH] swresample/arm: avoid conditional branch to PLT in THUMB-2.

2018-04-14 Thread Rahul Chaudhry
When compiling for THUMB-2, the conditional branch to PLT results in a
R_ARM_THM_JUMP19 relocation. Some linkers don't support this relocation
in THUMB-2 (ld.gold), while others can end up truncating the relocation
to fit (ld.bfd).

Adding an "it eq" before the branch converts it into an unconditional
branch, which uses R_ARM_THM_JUMP24 relocation that has a range of 16MB.

See https://github.com/android-ndk/ndk/issues/337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f
---
 libswresample/arm/audio_convert_neon.S | 1 +
 1 file changed, 1 insertion(+)

diff --git libswresample/arm/audio_convert_neon.S
libswresample/arm/audio_convert_neon.S
index 
1f88316ddec838dfe791b08cbe72533207994741..bc933fb4bd00071702f553cc0f3e74797c33ab12
100644
--- libswresample/arm/audio_convert_neon.S
+++ libswresample/arm/audio_convert_neon.S
@@ -134,6 +134,7 @@ function swri_oldapi_conv_fltp_to_s16_nch_neon, export=1
 itt lt
 ldrlt   r1,  [r1]
 blt X(swri_oldapi_conv_flt_to_s16_neon)
+it  eq
 beq X(swri_oldapi_conv_fltp_to_s16_2ch_neon)

 push{r4-r8, lr}
-- 
2.13.5
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] use bcrypt instead of the old wincrypt API

2018-04-14 Thread Michael Niedermayer
On Sat, Apr 14, 2018 at 07:10:40PM -0300, James Almer wrote:
> On 4/3/2018 8:49 PM, Michael Niedermayer wrote:
> > On Tue, Apr 03, 2018 at 11:44:25AM +0200, Steve Lhomme wrote:
> >> Remove the wincrypt API calls since we don't support XP anymore and bcrypt 
> >> is
> >> available since Vista, even on Windows Store builds.
> >> ---
> >>  configure   |  6 +++---
> >>  libavutil/random_seed.c | 19 ++-
> >>  2 files changed, 13 insertions(+), 12 deletions(-)
> > 
> > no build failures with this (compared to the last iteration)
> > 
> > thx
> 
> Applied then (Not idea if Steve can push himself, but since it hasn't
> been applied so far...)

he is in MAINTAINERs so he should have but maybe he doesnt, in which case
steve, if you have no access and want then send me your public ssh key

thx

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

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes


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


Re: [FFmpeg-devel] [PATCH] use bcrypt instead of the old wincrypt API

2018-04-14 Thread James Almer
On 4/3/2018 8:49 PM, Michael Niedermayer wrote:
> On Tue, Apr 03, 2018 at 11:44:25AM +0200, Steve Lhomme wrote:
>> Remove the wincrypt API calls since we don't support XP anymore and bcrypt is
>> available since Vista, even on Windows Store builds.
>> ---
>>  configure   |  6 +++---
>>  libavutil/random_seed.c | 19 ++-
>>  2 files changed, 13 insertions(+), 12 deletions(-)
> 
> no build failures with this (compared to the last iteration)
> 
> thx

Applied then (Not idea if Steve can push himself, but since it hasn't
been applied so far...)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avfilter/showvolume : add new options and minor clean

2018-04-14 Thread Paul B Mahol
On 4/14/18, Martin Vignali  wrote:
>>
>> Please use short name for options, max 2 characters.
>>
>> The log scale shows nothing even thought there is no silence. Perhaps
>> use ceil()?
>>
> Doesn't understand this part.
> Do you mean, you think the log scale display option is not a good idea ?
> Or doesn't work in some case ?
>
> In my test, the display log scale works ok, and more common way to check
> level
> (in linear scale, the level seems to be too low, when we usually see in log
> scale)

I dunno what music you do listen, but mine have very high
dynamic range, and when there is no silence i get completly empty display +
current volume in dB.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avfilter/showvolume : add new options and minor clean

2018-04-14 Thread Martin Vignali
>
> Please use short name for options, max 2 characters.
>
> The log scale shows nothing even thought there is no silence. Perhaps
> use ceil()?
>
Doesn't understand this part.
Do you mean, you think the log scale display option is not a good idea ?
Or doesn't work in some case ?

In my test, the display log scale works ok, and more common way to check
level
(in linear scale, the level seems to be too low, when we usually see in log
scale)




> The persistent max display color should be configurable.
>
> Ok will send a new patch for that.

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


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

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: Alexander Kravchenko [mailto:akravchenko...@gmail.com]
> Sent: Sunday, April 15, 2018 12:02 AM
> To: 'FFmpeg development discussions and patches' 
> Subject: RE: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 
> 
> > -Original Message-
> > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> > Of Mark Thompson
> > Sent: Saturday, April 14, 2018 7:15 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures
> > support implementation by AMF encoder
> >
> >
> > I've sent a new set containing this patch as 3 and 4 (I split out the
> > format check part, since that doesn't have anything to do with DXVA2), 
> > which hopefully makes the initialisation and surface mapping
> setup cleaner.  Would you like to look at that and comment?
> > Quite a bit of stuff got moved around in the merge.
> >
> 
> 
> Hi Mark,
> I briefly read the patches, they look good But I tried to apply them locally 
> The first one failed
> 1) I cloned ffmpeg
> 2) pasted patch text to file p1.patch
> 3) git apply p1.patch
> 
> error: patch failed: libavcodec/amfenc.c:152
> error: libavcodec/amfenc.c: patch does not apply
> 
> it look like patch expexts "amf_load_library(AVCodecContext *avctx)" at line 
> 152 @@ -152,10 +152,30 @@ static int
> amf_load_library(AVCodecContext *avctx)
> 
> In github
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/amfenc.c
> it is on line 155
> 
> did I miss something?
> 
> Thanks,
> Alexander
> 

I managed to apply patch, patch was broken by Far Manager Editor.
Pasting patch text to nano solved the applying problem.

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


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

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Saturday, April 14, 2018 7:15 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 
> I've sent a new set containing this patch as 3 and 4 (I split out the format 
> check part, since that doesn't have anything to do with
> DXVA2), which hopefully makes the initialisation and surface mapping setup 
> cleaner.  Would you like to look at that and comment?
> Quite a bit of stuff got moved around in the merge.
> 


Hi Mark,
I briefly read the patches, they look good
But I tried to apply them locally
The first one failed
1) I cloned ffmpeg
2) pasted patch text to file p1.patch
3) git apply p1.patch

error: patch failed: libavcodec/amfenc.c:152
error: libavcodec/amfenc.c: patch does not apply

it look like patch expexts "amf_load_library(AVCodecContext *avctx)" at line 152
@@ -152,10 +152,30 @@ static int amf_load_library(AVCodecContext *avctx)

In github
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/amfenc.c
it is on line 155

did I miss something?

Thanks,
Alexander
 

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


Re: [FFmpeg-devel] avfilter/showvolume : add new options and minor clean

2018-04-14 Thread Paul B Mahol
On 4/11/18, Martin Vignali  wrote:
> Hello,
>
> Thanks for the comments.
>
> New patchs in attach :
>
> 001 : Add display_scale volume
> Change since prev patch :
> - use enum for the value
> - move the max_draw calc part to an inline func (avoid code duplication).
>
> 002 : Add Persistent max display
> Change since prev patch
> - Use only one param (dm_duration), if set to 0. (the default), disabled
> display and calc
> - move some part in inline func, to reduce code duplication
> - offset line draw by 1 pixel (and use FFMAX to clip to 0). Fix display max
> line, when max is 0db in horizontal mode
> - add doc
>
> Martin
>

Please use short name for options, max 2 characters.

The log scale shows nothing even thought there is no silence. Perhaps
use ceil()?

The persistent max display color should be configurable.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode

2018-04-14 Thread Rostislav Pehlivanov
On 14 April 2018 at 20:46, Paul B Mahol  wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/dxv.c | 815 ++
> ++---
>  1 file changed, 780 insertions(+), 35 deletions(-)
>
> diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
> index 529e211258..101fe78481 100644
> --- a/libavcodec/dxv.c
> +++ b/libavcodec/dxv.c
> @@ -1,6 +1,7 @@
>  /*
>   * Resolume DXV decoder
>   * Copyright (C) 2015 Vittorio Giovara 
> + * Copyright (C) 2018 Paul B Mahol
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -23,6 +24,7 @@
>
>  #include "libavutil/imgutils.h"
>
> +#include "mathops.h"
>  #include "avcodec.h"
>  #include "bytestream.h"
>  #include "internal.h"
> @@ -34,50 +36,211 @@ typedef struct DXVContext {
>  TextureDSPContext texdsp;
>  GetByteContext gbc;
>
> -uint8_t *tex_data;  // Compressed texture
> -int tex_rat;// Compression ratio
> -int tex_step;   // Distance between blocks
> -int64_t tex_size;   // Texture size
> +uint8_t *tex_data;   // Compressed texture
> +uint8_t *ctex_data;  // Compressed texture
> +int tex_rat; // Compression ratio
> +int tex_step;// Distance between blocks
> +int ctex_step;   // Distance between blocks
> +int64_t tex_size;// Texture size
> +int64_t ctex_size;   // Texture size
>
>  /* Optimal number of slices for parallel decoding */
>  int slice_count;
>
> +uint8_t *op_data[4]; // Opcodes
> +int64_t op_size[4];  // Opcodes size
> +
> +int texture_block_w;
> +int texture_block_h;
> +
> +int ctexture_block_w;
> +int ctexture_block_h;
> +
>  /* Pointer to the selected decompression function */
>  int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t
> *block);
> +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
> +   uint8_t *plane1, ptrdiff_t stride1,
> +   const uint8_t *block);
>  } DXVContext;
>
> +static void decompress_indices(uint8_t *dst, const uint8_t *src)
> +{
> +int block, i;
> +
> +for (block = 0; block < 2; block++) {
> +int tmp = AV_RL24(src);
> +
> +/* Unpack 8x3 bit from last 3 byte block */
> +for (i = 0; i < 8; i++)
> +dst[i] = (tmp >> (i * 3)) & 0x7;
> +
> +src += 3;
> +dst += 8;
> +}
> +}
> +
> +static int extract_component(int yo0, int yo1, int code)
> +{
> +int yo;
> +
> +if (yo0 == yo1) {
> +yo = yo0;
> +} else if (code == 0) {
> +yo = yo0;
> +} else if (code == 1) {
> +yo = yo1;
> +} else {
> +if (yo0 > yo1) {
> +yo = (uint8_t) (((8 - code) * yo0 +
> + (code - 1) * yo1) / 7);
> +} else {
> +if (code == 6) {
> +yo = 0;
> +} else if (code == 7) {
> +yo = 255;
> +} else {
> +yo = (uint8_t) (((6 - code) * yo0 +
> + (code - 1) * yo1) / 5);
> +}
> +}
> +}
> +
> +return yo;
> +}
> +
> +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
> +  uint8_t *plane1, ptrdiff_t stride1,
> +  const uint8_t *block)
> +{
> +uint8_t co_indices[16];
> +uint8_t cg_indices[16];
> +uint8_t co0 = *(block);
> +uint8_t co1 = *(block + 1);
> +uint8_t cg0 = *(block + 8);
> +uint8_t cg1 = *(block + 9);
> +int x, y;
> +
> +decompress_indices(co_indices, block + 2);
> +decompress_indices(cg_indices, block + 10);
> +
> +for (y = 0; y < 4; y++) {
> +for (x = 0; x < 4; x++) {
> +int co_code = co_indices[x + y * 4];
> +int cg_code = cg_indices[x + y * 4];
> +
> +plane0[x] = extract_component(cg0, cg1, cg_code);
> +plane1[x] = extract_component(co0, co1, co_code);
> +}
> +plane0 += stride0;
> +plane1 += stride1;
> +}
> +
> +return 16;
> +}
> +
> +static void yao_subblock(uint8_t *dst, uint8_t *yo_indices,
> +ptrdiff_t stride, const uint8_t *block)
> +{
> +uint8_t yo0 = *(block);
> +uint8_t yo1 = *(block + 1);
> +int x, y;
> +
> +decompress_indices(yo_indices, block + 2);
> +
> +for (y = 0; y < 4; y++) {
> +for (x = 0; x < 4; x++) {
> +int yo_code = yo_indices[x + y * 4];
> +
> +dst[x] = extract_component(yo0, yo1, yo_code);
> +}
> +dst += stride;
> +}
> +}
> +
> +static int yo_block(uint8_t *dst, ptrdiff_t stride,
> +uint8_t *unused0, ptrdiff_t unused1,
> +const uint8_t *block)
> +{
> +uint8_t yo_indices[16];
> +
> +yao_subblock(dst,  yo_indices, stride, block);
> +yao_subblock(dst + 4,  yo_indices, stride, block + 8);
> +yao_subblock(dst + 8,  

Re: [FFmpeg-devel] [PATCH] ffprobe: report unavailable SAR correctly in stream info

2018-04-14 Thread Rostislav Pehlivanov
On 12 April 2018 at 09:07, Timo Teräs  wrote:

> av_guess_sample_aspect_ratio() will return undefined or missing
> value as {0,1}. This fixes show_stream() to check numerator to
> display 'N/A' when appropriate. show_frame() does this already
> correctly.
>
> Signed-off-by: Timo Teräs 
> ---
>  fftools/ffprobe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 82dfe4f58a..8b2a18b6b1 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -2521,7 +2521,7 @@ static int show_stream(WriterContext *w,
> AVFormatContext *fmt_ctx, int stream_id
>  #endif
>  print_int("has_b_frames", par->video_delay);
>  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
> -if (sar.den) {
> +if (sar.num) {
>  print_q("sample_aspect_ratio", sar, ':');
>  av_reduce(, ,
>par->width  * sar.num,
> --
> 2.17.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

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


[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode

2018-04-14 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dxv.c | 815 ---
 1 file changed, 780 insertions(+), 35 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 529e211258..101fe78481 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1,6 +1,7 @@
 /*
  * Resolume DXV decoder
  * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2018 Paul B Mahol
  *
  * This file is part of FFmpeg.
  *
@@ -23,6 +24,7 @@
 
 #include "libavutil/imgutils.h"
 
+#include "mathops.h"
 #include "avcodec.h"
 #include "bytestream.h"
 #include "internal.h"
@@ -34,50 +36,211 @@ typedef struct DXVContext {
 TextureDSPContext texdsp;
 GetByteContext gbc;
 
-uint8_t *tex_data;  // Compressed texture
-int tex_rat;// Compression ratio
-int tex_step;   // Distance between blocks
-int64_t tex_size;   // Texture size
+uint8_t *tex_data;   // Compressed texture
+uint8_t *ctex_data;  // Compressed texture
+int tex_rat; // Compression ratio
+int tex_step;// Distance between blocks
+int ctex_step;   // Distance between blocks
+int64_t tex_size;// Texture size
+int64_t ctex_size;   // Texture size
 
 /* Optimal number of slices for parallel decoding */
 int slice_count;
 
+uint8_t *op_data[4]; // Opcodes
+int64_t op_size[4];  // Opcodes size
+
+int texture_block_w;
+int texture_block_h;
+
+int ctexture_block_w;
+int ctexture_block_h;
+
 /* Pointer to the selected decompression function */
 int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
+   uint8_t *plane1, ptrdiff_t stride1,
+   const uint8_t *block);
 } DXVContext;
 
+static void decompress_indices(uint8_t *dst, const uint8_t *src)
+{
+int block, i;
+
+for (block = 0; block < 2; block++) {
+int tmp = AV_RL24(src);
+
+/* Unpack 8x3 bit from last 3 byte block */
+for (i = 0; i < 8; i++)
+dst[i] = (tmp >> (i * 3)) & 0x7;
+
+src += 3;
+dst += 8;
+}
+}
+
+static int extract_component(int yo0, int yo1, int code)
+{
+int yo;
+
+if (yo0 == yo1) {
+yo = yo0;
+} else if (code == 0) {
+yo = yo0;
+} else if (code == 1) {
+yo = yo1;
+} else {
+if (yo0 > yo1) {
+yo = (uint8_t) (((8 - code) * yo0 +
+ (code - 1) * yo1) / 7);
+} else {
+if (code == 6) {
+yo = 0;
+} else if (code == 7) {
+yo = 255;
+} else {
+yo = (uint8_t) (((6 - code) * yo0 +
+ (code - 1) * yo1) / 5);
+}
+}
+}
+
+return yo;
+}
+
+static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
+  uint8_t *plane1, ptrdiff_t stride1,
+  const uint8_t *block)
+{
+uint8_t co_indices[16];
+uint8_t cg_indices[16];
+uint8_t co0 = *(block);
+uint8_t co1 = *(block + 1);
+uint8_t cg0 = *(block + 8);
+uint8_t cg1 = *(block + 9);
+int x, y;
+
+decompress_indices(co_indices, block + 2);
+decompress_indices(cg_indices, block + 10);
+
+for (y = 0; y < 4; y++) {
+for (x = 0; x < 4; x++) {
+int co_code = co_indices[x + y * 4];
+int cg_code = cg_indices[x + y * 4];
+
+plane0[x] = extract_component(cg0, cg1, cg_code);
+plane1[x] = extract_component(co0, co1, co_code);
+}
+plane0 += stride0;
+plane1 += stride1;
+}
+
+return 16;
+}
+
+static void yao_subblock(uint8_t *dst, uint8_t *yo_indices,
+ptrdiff_t stride, const uint8_t *block)
+{
+uint8_t yo0 = *(block);
+uint8_t yo1 = *(block + 1);
+int x, y;
+
+decompress_indices(yo_indices, block + 2);
+
+for (y = 0; y < 4; y++) {
+for (x = 0; x < 4; x++) {
+int yo_code = yo_indices[x + y * 4];
+
+dst[x] = extract_component(yo0, yo1, yo_code);
+}
+dst += stride;
+}
+}
+
+static int yo_block(uint8_t *dst, ptrdiff_t stride,
+uint8_t *unused0, ptrdiff_t unused1,
+const uint8_t *block)
+{
+uint8_t yo_indices[16];
+
+yao_subblock(dst,  yo_indices, stride, block);
+yao_subblock(dst + 4,  yo_indices, stride, block + 8);
+yao_subblock(dst + 8,  yo_indices, stride, block + 16);
+yao_subblock(dst + 12, yo_indices, stride, block + 24);
+
+return 32;
+}
+
+static int yao_block(uint8_t *plane0, ptrdiff_t stride0,
+ uint8_t *plane3, ptrdiff_t stride1,
+ const uint8_t *block)
+{
+uint8_t yo_indices[16];
+uint8_t a_indices[16];
+
+yao_subblock(plane0,  yo_indices, stride0, 

Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode

2018-04-14 Thread Paul B Mahol
On 4/14/18, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/dxv.c | 815
> ---
>  1 file changed, 780 insertions(+), 35 deletions(-)
>

Ignore this one. It introduces artifacts.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode

2018-04-14 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dxv.c | 815 ---
 1 file changed, 780 insertions(+), 35 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 529e211258..a0a3ff0595 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1,6 +1,7 @@
 /*
  * Resolume DXV decoder
  * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2018 Paul B Mahol
  *
  * This file is part of FFmpeg.
  *
@@ -23,6 +24,7 @@
 
 #include "libavutil/imgutils.h"
 
+#include "mathops.h"
 #include "avcodec.h"
 #include "bytestream.h"
 #include "internal.h"
@@ -34,50 +36,211 @@ typedef struct DXVContext {
 TextureDSPContext texdsp;
 GetByteContext gbc;
 
-uint8_t *tex_data;  // Compressed texture
-int tex_rat;// Compression ratio
-int tex_step;   // Distance between blocks
-int64_t tex_size;   // Texture size
+uint8_t *tex_data;   // Compressed texture
+uint8_t *ctex_data;  // Compressed texture
+int tex_rat; // Compression ratio
+int tex_step;// Distance between blocks
+int ctex_step;   // Distance between blocks
+int64_t tex_size;// Texture size
+int64_t ctex_size;   // Texture size
 
 /* Optimal number of slices for parallel decoding */
 int slice_count;
 
+uint8_t *op_data[4]; // Opcodes
+int64_t op_size[4];  // Opcodes size
+
+int texture_block_w;
+int texture_block_h;
+
+int ctexture_block_w;
+int ctexture_block_h;
+
 /* Pointer to the selected decompression function */
 int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
+   uint8_t *plane1, ptrdiff_t stride1,
+   const uint8_t *block);
 } DXVContext;
 
+static void decompress_indices(uint8_t *dst, const uint8_t *src)
+{
+int block, i;
+
+for (block = 0; block < 2; block++) {
+int tmp = AV_RL24(src);
+
+/* Unpack 8x3 bit from last 3 byte block */
+for (i = 0; i < 8; i++)
+dst[i] = (tmp >> (i * 3)) & 0x7;
+
+src += 3;
+dst += 8;
+}
+}
+
+static int extract_component(int yo0, int yo1, int code)
+{
+int yo;
+
+if (yo0 == yo1) {
+yo = yo0;
+} else if (code == 0) {
+yo = yo0;
+} else if (code == 1) {
+yo = yo1;
+} else {
+if (yo0 > yo1) {
+yo = (uint8_t) (((8 - code) * yo0 +
+ (code - 1) * yo1) / 7);
+} else {
+if (code == 6) {
+yo = 0;
+} else if (code == 7) {
+yo = 255;
+} else {
+yo = (uint8_t) (((6 - code) * yo0 +
+ (code - 1) * yo1) / 5);
+}
+}
+}
+
+return yo;
+}
+
+static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
+  uint8_t *plane1, ptrdiff_t stride1,
+  const uint8_t *block)
+{
+uint8_t co_indices[16];
+uint8_t cg_indices[16];
+uint8_t co0 = *(block);
+uint8_t co1 = *(block + 1);
+uint8_t cg0 = *(block + 8);
+uint8_t cg1 = *(block + 9);
+int x, y;
+
+decompress_indices(co_indices, block + 2);
+decompress_indices(cg_indices, block + 10);
+
+for (y = 0; y < 4; y++) {
+for (x = 0; x < 4; x++) {
+int co_code = co_indices[x + y * 4];
+int cg_code = cg_indices[x + y * 4];
+
+plane0[x] = extract_component(cg0, cg1, cg_code);
+plane1[x] = extract_component(co0, co1, co_code);
+}
+plane0 += stride0;
+plane1 += stride1;
+}
+
+return 16;
+}
+
+static void yao_subblock(uint8_t *dst, uint8_t *yo_indices,
+ptrdiff_t stride, const uint8_t *block)
+{
+uint8_t yo0 = *(block);
+uint8_t yo1 = *(block + 1);
+int x, y;
+
+decompress_indices(yo_indices, block + 2);
+
+for (y = 0; y < 4; y++) {
+for (x = 0; x < 4; x++) {
+int yo_code = yo_indices[x + y * 4];
+
+dst[x] = extract_component(yo0, yo1, yo_code);
+}
+dst += stride;
+}
+}
+
+static int yo_block(uint8_t *dst, ptrdiff_t stride,
+uint8_t *unused0, ptrdiff_t unused1,
+const uint8_t *block)
+{
+uint8_t yo_indices[16];
+
+yao_subblock(dst,  yo_indices, stride, block);
+yao_subblock(dst + 4,  yo_indices, stride, block + 8);
+yao_subblock(dst + 8,  yo_indices, stride, block + 16);
+yao_subblock(dst + 12, yo_indices, stride, block + 24);
+
+return 32;
+}
+
+static int yao_block(uint8_t *plane0, ptrdiff_t stride0,
+ uint8_t *plane3, ptrdiff_t stride1,
+ const uint8_t *block)
+{
+uint8_t yo_indices[16];
+uint8_t a_indices[16];
+
+yao_subblock(plane0,  yo_indices, stride0, 

[FFmpeg-devel] [PATCH v2] avformat/movenc: support writing iTunes cover image

2018-04-14 Thread Timo Teräs
Fixes https://trac.ffmpeg.org/ticket/2798

This makes movenc handle AV_DISPOSITION_ATTACHED_PIC and write
the associated pictures in iTunes cover atom. This corresponds
to how 'mov' demuxer parses and exposes the cover images when
reading.

Most of the existing track handling loops properly ignore
these 'virtual streams' as MOVTrack->entry is never incremented
for them. However, additional tests are added as needed to ignore
them.

Tested to produce valid output with:
  ffmpeg -i movie.mp4 -i thumb.jpg -disposition:v:1 attached_pic \
 -map 0 -map 1 -c copy movie-with-cover.mp4

The cover image is also copied correctly with:
  ffmpeg -i movie-with-cover.mp4 -map 0 -c copy out.mp4

AtomicParseley says that the attached_pic stream is properly
not visible in the main tracks of the file.

Signed-off-by: Timo Teräs 
---
v2:
- Store the image in MOVTrack->cover_image instead of
  AVStream->attached_pic per review request

 libavformat/movenc.c | 88 +---
 libavformat/movenc.h |  1 +
 2 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index d03d7906a1..be5daa50c2 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -142,7 +142,9 @@ static int co64_required(const MOVTrack *track)
 
 static int rtp_hinting_needed(const AVStream *st)
 {
-/* Add hint tracks for each audio and video stream */
+/* Add hint tracks for each real audio and video stream */
+if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+return 0;
 return st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
 }
@@ -3420,6 +3422,51 @@ static int mov_write_int8_metadata(AVFormatContext *s, 
AVIOContext *pb,
 return size;
 }
 
+static int mov_write_covr(AVIOContext *pb, AVFormatContext *s)
+{
+MOVMuxContext *mov = s->priv_data;
+int64_t pos = 0;
+int i, type;
+
+for (i = 0; i < s->nb_streams; i++) {
+MOVTrack *trk = >tracks[i];
+AVStream *st = s->streams[i];
+
+if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC) ||
+trk->cover_image.size <= 0)
+continue;
+
+switch (st->codecpar->codec_id) {
+case AV_CODEC_ID_MJPEG:
+type = 0xD;
+break;
+case AV_CODEC_ID_PNG:
+type = 0xE;
+break;
+case AV_CODEC_ID_BMP:
+type = 0x1B;
+break;
+default:
+av_log(s, AV_LOG_ERROR, "unsupported codec_id (0x%x) for cover",
+   st->codecpar->codec_id);
+continue;
+}
+
+if (!pos) {
+pos = avio_tell(pb);
+avio_wb32(pb, 0);
+ffio_wfourcc(pb, "covr");
+}
+avio_wb32(pb, 16 + trk->cover_image.size);
+ffio_wfourcc(pb, "data");
+avio_wb32(pb, type);
+avio_wb32(pb , 0);
+avio_write(pb, trk->cover_image.data, trk->cover_image.size);
+}
+
+return pos ? update_size(pb, pos) : 0;
+}
+
 /* iTunes meta data list */
 static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov,
   AVFormatContext *s)
@@ -3454,6 +3501,7 @@ static int mov_write_ilst_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 mov_write_int8_metadata  (s, pb, "hdvd","hd_video",  1);
 mov_write_int8_metadata  (s, pb, "pgap","gapless_playback",1);
 mov_write_int8_metadata  (s, pb, "cpil","compilation", 1);
+mov_write_covr(pb, s);
 mov_write_trkn_tag(pb, mov, s, 0); // track number
 mov_write_trkn_tag(pb, mov, s, 1); // disc number
 mov_write_tmpo_tag(pb, s);
@@ -3951,6 +3999,8 @@ static int mov_write_isml_manifest(AVIOContext *pb, 
MOVMuxContext *mov, AVFormat
 } else {
 continue;
 }
+if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+continue;
 
 props = (AVCPBProperties*)av_stream_get_side_data(track->st, 
AV_PKT_DATA_CPB_PROPERTIES, NULL);
 
@@ -4564,6 +4614,8 @@ static int mov_write_ftyp_tag(AVIOContext *pb, 
AVFormatContext *s)
 
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
+if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+continue;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 has_video = 1;
 if (st->codecpar->codec_id == AV_CODEC_ID_H264)
@@ -4712,6 +4764,8 @@ static int mov_write_identification(AVIOContext *pb, 
AVFormatContext *s)
 int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
+if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+continue;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 video_streams_nb++;
 else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
@@ -4901,7 +4955,8 

Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode

2018-04-14 Thread Rostislav Pehlivanov
On 12 April 2018 at 17:00, Paul B Mahol  wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/dxv.c | 1038 ++
> ++--
>  1 file changed, 1003 insertions(+), 35 deletions(-)
>
> diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
> index 529e211258..af8038d377 100644
> --- a/libavcodec/dxv.c
> +++ b/libavcodec/dxv.c
> @@ -1,6 +1,7 @@
>  /*
>   * Resolume DXV decoder
>   * Copyright (C) 2015 Vittorio Giovara 
> + * Copyright (C) 2018 Paul B Mahol
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -23,6 +24,7 @@
>
>  #include "libavutil/imgutils.h"
>
> +#include "mathops.h"
>  #include "avcodec.h"
>  #include "bytestream.h"
>  #include "internal.h"
> @@ -34,50 +36,230 @@ typedef struct DXVContext {
>  TextureDSPContext texdsp;
>  GetByteContext gbc;
>
> -uint8_t *tex_data;  // Compressed texture
> -int tex_rat;// Compression ratio
> -int tex_step;   // Distance between blocks
> -int64_t tex_size;   // Texture size
> +uint8_t *tex_data;   // Compressed texture
> +uint8_t *ctex_data;  // Compressed texture
> +int tex_rat; // Compression ratio
> +int tex_step;// Distance between blocks
> +int ctex_step;   // Distance between blocks
> +int64_t tex_size;// Texture size
> +int64_t ctex_size;   // Texture size
>
>  /* Optimal number of slices for parallel decoding */
>  int slice_count;
>
> +uint8_t *op_data[4]; // Opcodes
> +int64_t op_size[4];  // Opcodes size
> +
> +int texture_block_w;
> +int texture_block_h;
> +
> +int ctexture_block_w;
> +int ctexture_block_h;
> +
>  /* Pointer to the selected decompression function */
>  int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t
> *block);
> +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
> +   uint8_t *plane1, ptrdiff_t stride1,
> +   const uint8_t *block);
>  } DXVContext;
>
> +static void decompress_indices(uint8_t *dst, const uint8_t *src)
> +{
> +int block, i;
> +
> +for (block = 0; block < 2; block++) {
> +int tmp = AV_RL24(src);
> +
> +/* Unpack 8x3 bit from last 3 byte block */
> +for (i = 0; i < 8; i++)
> +dst[i] = (tmp >> (i * 3)) & 0x7;
> +
> +src += 3;
> +dst += 8;
> +}
> +}
> +
> +static int extract_component(int yo0, int yo1, int code)
> +{
> +int yo;
>
+
> +if (yo0 == yo1) {
> +yo = yo0;
> +} else if (code == 0) {
> +yo = yo0;
> +} else if (code == 1) {
> +yo = yo1;
> +} else {
> +if (yo0 > yo1) {
> +yo = (uint8_t) (((8 - code) * yo0 +
> + (code - 1) * yo1) / 7);
> +} else {
> +if (code == 6) {
> +yo = 0;
> +} else if (code == 7) {
> +yo = 255;
> +} else {
> +yo = (uint8_t) (((6 - code) * yo0 +
> + (code - 1) * yo1) / 5);
> +}
> +}
> +}
> +
> +return yo;
> +}
> +
> +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
> +  uint8_t *plane1, ptrdiff_t stride1,
> +  const uint8_t *block)
> +{
> +uint8_t co_indices[16];
> +uint8_t cg_indices[16];
> +uint8_t co0 = *(block);
> +uint8_t co1 = *(block + 1);
> +uint8_t cg0 = *(block + 8);
> +uint8_t cg1 = *(block + 9);
> +int x, y;
> +
> +decompress_indices(co_indices, block + 2);
> +decompress_indices(cg_indices, block + 10);
> +
> +for (y = 0; y < 4; y++) {
> +for (x = 0; x < 4; x++) {
> +int co_code = co_indices[x + y * 4];
> +int cg_code = cg_indices[x + y * 4];
> +
> +plane0[x] = extract_component(cg0, cg1, cg_code);
> +plane1[x] = extract_component(co0, co1, co_code);
> +}
> +plane0 += stride0;
> +plane1 += stride1;
> +}
> +
> +return 16;
> +}
> +
> +static void yo_subblock(uint8_t *dst, uint8_t *yo_indices,
> +ptrdiff_t stride, const uint8_t *block)
> +{
> +uint8_t yo0 = *(block);
> +uint8_t yo1 = *(block + 1);
> +int x, y;
> +
> +decompress_indices(yo_indices, block + 2);
> +
> +for (y = 0; y < 4; y++) {
> +for (x = 0; x < 4; x++) {
> +int yo_code = yo_indices[x + y * 4];
> +
> +dst[x] = extract_component(yo0, yo1, yo_code);
> +}
> +dst += stride;
> +}
> +}
> +
> +static int yo_block(uint8_t *dst, ptrdiff_t stride,
> +uint8_t *unused0, ptrdiff_t unused1,
> +const uint8_t *block)
> +{
> +uint8_t yo_indices[16];
> +
> +yo_subblock(dst,  yo_indices, stride, block);
> +yo_subblock(dst + 4,  yo_indices, stride, block + 8);
> +yo_subblock(dst + 8,  

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

2018-04-14 Thread Mark Thompson
On 13/04/18 10:21, Alexander Kravchenko wrote:
> 
> This patch contains DXVA2 textures support implementation by AMF encoder (in 
> addition of D3D11 textures)
> 
> Samples of usage:
> DXVA2 decoder -> dxva2_vld texture -> AMF Encoder:
> ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -extra_hw_frames 16 -i 
> input.mp4 -an -c:v h264_amf out.mkv
> 
> D3D11va decoder -> d3d11 texture -> AMF Encoder:
> ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -extra_hw_frames 16 -i 
> input.mp4 -an -c:v h264_amf out.mkv
> 
> ---
> Sending updated patch (Fixes according Mark's review):
>>> ---
>>^
>> (When adding commentary which isn't part of the commit message to an email 
>> please place it after this line so that it doesn't end up in the commit 
>> message.)
> Done here, hopefully correctly
> 
>>>  { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
>>> +{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
>>
>> As with D3D11, this isn't necessarily true.  This was ignored before, but do 
>> you have any plan for how P010 (and others?) will be handled here?
> removed HW types from format map, and added logic reading pixel format from 
> avctx->sw_pix_fmt in case if avctx->pix_fmt is HWACCEL type
> 
>> +static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
>> IDirect3DDevice9 **device, void *avcl) {
>> ...
>> Might be cleaner using an error return rather than the null device?
> Fixed
> 
>> Everything using D3D9 types needs to be inside CONFIG_DXVA2
> Fixed
> 
>> Passing NULL here will make this case succeed in cases where it shouldn't, I 
>> think?
> Agree, fixed
> 
>> Tbh I don't think this fallback case should exist at all, it should just 
>> fail.
>> Is there any use-case for having it?  The user passed a DXVA2 frames context 
>> on a 
>> non-AMD device and expects it to work with that hardware input, this 
>> fallback makes 
>> it kindof work with at least two copies in a way which is likely to be very 
>> slow.  
>> Even if the user does want to do that, it would be better for them to do it 
>> explicitly 
>> to ensure that they aware of the problem.  (We don't automatically do this 
>> in any other case.)
> Agree, fixed
> 
>> Spurious whitespace.
> Fixed in changed blocks/functions

I've sent a new set containing this patch as 3 and 4 (I split out the format 
check part, since that doesn't have anything to do with DXVA2), which hopefully 
makes the initialisation and surface mapping setup cleaner.  Would you like to 
look at that and comment?  Quite a bit of stuff got moved around in the merge.

>> Tested on Windows 7, works well.  
>> Unlike with D3D11 the OpenCL interop works properly as well, 
>> so e.g. -vf 'hwmap=derive_device=opencl,convolution_opencl=0 1 0 1 -4 1 0 1 
>> 0,hwmap=derive_device=dxva2:reverse=1:extra_hw_frames=16' as encoder input 
>> works too.
> Could you send the samples (or link if they are published, I will add to my 
> tests and will check OpenCL interop with D3D11)

Use any OpenCL filter with mapping to/from DXVA2.  For example:

./ffmpeg_g -y -hwaccel dxva2 -hwaccel_output_format dxva2_vld -i input.mkv -an 
-vf 'hwmap=derive_device=opencl,convolution_opencl=0 1 0 1 -4 1 0 1 
0,hwmap=derive_device=dxva2:reverse=1:extra_hw_frames=16' -c:v h264_amf 
output.mkv

(Applies an edge-detect convolution on the luma plane.)

The source filter is also usable with a little trickiness to get the right 
setup:

./ffmpeg_g -y -init_hw_device dxva2=d3d -init_hw_device opencl=cl@d3d 
-filter_hw_device cl -filter_complex 
'openclsrc=source=sierpinski.cl:kernel=sierpinski_carpet:size=1920x1080:format=nv12,hwmap=derive_device=dxva2:reverse=1:extra_hw_frames=16'
 -c:v h264_amf output.mkv

(Using the sierpinski carpet example from the documentation.)

Note that OpenCL <-> D3D11 won't work on AMD for normal video surfaces (NV12) 
because there is no support for multiple-plane textures, so it's only going to 
work with DXVA2 currently.  Intel has an extension 
("cl_intel_d3d11_nv12_media_sharing") which adds a simple hack overloading the 
subresource index and therefore it is usable on Intel GPUs, but other vendors 
don't have that.

(There should probably be a wiki page on all of this.  I've never got around to 
writing it.)

Thanks,

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


[FFmpeg-devel] [PATCH 4/5] amfenc: Add DXVA2 hardware frame input support

2018-04-14 Thread Mark Thompson
From: Alexander Kravchenko 

Adds support for AMF initialisation from a DXVA2 (Direct3D9) device, and
then allows passing DXVA2 surfaces into an AMF encoder.

Signed-off-by: Mark Thompson 
---
 libavcodec/amfenc.c | 79 +
 1 file changed, 79 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b761cd74bf..e641048532 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,10 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#define COBJMACROS
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +54,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -162,6 +169,52 @@ static int amf_init_from_d3d11_device(AVCodecContext 
*avctx, AVD3D11VADeviceCont
 }
 #endif
 
+#if CONFIG_DXVA2
+static int amf_init_from_dxva2_device(AVCodecContext *avctx, 
AVDXVA2DeviceContext *hwctx)
+{
+AmfContext *ctx = avctx->priv_data;
+HANDLE device_handle;
+IDirect3DDevice9 *device;
+HRESULT hr;
+AMF_RESULT res;
+int ret;
+
+hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, 
_handle);
+if (FAILED(hr)) {
+av_log(avctx, AV_LOG_ERROR, "Failed to open device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+return AVERROR_EXTERNAL;
+}
+
+hr = IDirect3DDeviceManager9_LockDevice(hwctx->devmgr, device_handle, 
, FALSE);
+if (SUCCEEDED(hr)) {
+IDirect3DDeviceManager9_UnlockDevice(hwctx->devmgr, device_handle, 
FALSE);
+ret = 0;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Failed to lock device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+ret = AVERROR_EXTERNAL;
+}
+
+IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, device_handle);
+
+if (ret < 0)
+return ret;
+
+res = ctx->context->pVtbl->InitDX9(ctx->context, device);
+
+IDirect3DDevice9_Release(device);
+
+if (res != AMF_OK) {
+if (res == AMF_NOT_SUPPORTED)
+av_log(avctx, AV_LOG_ERROR, "AMF via D3D9 is not supported on the 
given device.\n");
+else
+av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on given 
D3D9 device: %d.\n", res);
+return AVERROR(ENODEV);
+}
+
+return 0;
+}
+#endif
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -205,6 +258,13 @@ static int amf_init_context(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 break;
+#endif
+#if CONFIG_DXVA2
+case AV_HWDEVICE_TYPE_DXVA2:
+ret = amf_init_from_dxva2_device(avctx, 
frames_ctx->device_ctx->hwctx);
+if (ret < 0)
+return ret;
+break;
 #endif
 default:
 av_log(avctx, AV_LOG_ERROR, "AMF initialisation from a %s frames 
context is not supported.\n",
@@ -229,6 +289,13 @@ static int amf_init_context(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 break;
+#endif
+#if CONFIG_DXVA2
+case AV_HWDEVICE_TYPE_DXVA2:
+ret = amf_init_from_dxva2_device(avctx, device_ctx->hwctx);
+if (ret < 0)
+return ret;
+break;
 #endif
 default:
 av_log(avctx, AV_LOG_ERROR, "AMF initialisation from a %s device 
is not supported.\n",
@@ -580,6 +647,18 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 hw_surface = 1;
 }
 break;
+#endif
+#if CONFIG_DXVA2
+case AV_PIX_FMT_DXVA2_VLD:
+{
+IDirect3DSurface9 *texture = (IDirect3DSurface9 
*)frame->data[3]; // actual texture
+
+res = 
ctx->context->pVtbl->CreateSurfaceFromDX9Native(ctx->context, texture, 
, NULL); // wrap to AMF surface
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"CreateSurfaceFromDX9Native() failed  with error %d\n", res);
+
+hw_surface = 1;
+}
+break;
 #endif
 default:
 {
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 1/5] amfenc: Fail to open if the user-supplied device is not usable

2018-04-14 Thread Mark Thompson
If the user supplies a device or frames context then it is an error
not to use it; this is consistent with other hardware components.

Also factorise out the D3D11 initialisation and improve error
messages.
---
 libavcodec/amfenc.c | 130 
 1 file changed, 81 insertions(+), 49 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..8a9d6884a4 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -152,10 +152,30 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+#if CONFIG_D3D11VA
+static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
+{
+AmfContext *ctx = avctx->priv_data;
+AMF_RESULT res;
+
+res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
+if (res != AMF_OK) {
+if (res == AMF_NOT_SUPPORTED)
+av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
+else
+av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given 
D3D11 device: %d.\n", res);
+return AVERROR(ENODEV);
+}
+
+return 0;
+}
+#endif
+
 static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT  res = AMF_OK;
+AmfContext *ctx = avctx->priv_data;
+AMF_RESULT  res;
+av_unused int ret;
 
 ctx->hwsurfaces_in_queue = 0;
 ctx->hwsurfaces_in_queue_max = 16;
@@ -176,59 +196,71 @@ static int amf_init_context(AVCodecContext *avctx)
 
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, >context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() 
failed with error %d\n", res);
-// try to reuse existing DX device
-#if CONFIG_D3D11VA
+
+// If a device was passed to the encoder, try to initialise from that.
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (amf_av_to_amf_format(device_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
-if (device_ctx->device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
-res = ctx->context->pVtbl->InitDX11(ctx->context, 
device_d3d11->device, AMF_DX11_1);
-if (res == AMF_OK) {
-ctx->hw_frames_ctx = 
av_buffer_ref(avctx->hw_frames_ctx);
-if (!ctx->hw_frames_ctx) {
-return AVERROR(ENOMEM);
-}
-if (device_ctx->initial_pool_size > 0)
-ctx->hwsurfaces_in_queue_max = 
device_ctx->initial_pool_size - 1;
-} else {
-if(res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has D3D11 device which doesn't have D3D11VA interface, switching to default\n");
-else
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has non-AMD device, switching to default\n");
-}
-}
-} else {
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format 
not uspported by AMF, switching to default\n");
-}
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+
+if (amf_av_to_amf_format(frames_ctx->sw_format) == 
AMF_SURFACE_UNKNOWN) {
+av_log(avctx, AV_LOG_ERROR, "Format of input frames context (%s) 
is not supported by AMF.\n",
+   av_get_pix_fmt_name(frames_ctx->sw_format));
+return AVERROR(EINVAL);
 }
-} else if (avctx->hw_device_ctx) {
-AVHWDeviceContext *device_ctx = 
(AVHWDeviceContext*)(avctx->hw_device_ctx->data);
-if (device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 = (AVD3D11VADeviceContext 
*)device_ctx->hwctx;
-res = ctx->context->pVtbl->InitDX11(ctx->context, 
device_d3d11->device, AMF_DX11_1);
-if (res == AMF_OK) {
-ctx->hw_device_ctx = av_buffer_ref(avctx->hw_device_ctx);
-if (!ctx->hw_device_ctx) {
-return AVERROR(ENOMEM);
-}
-} else {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_INFO, "avctx->hw_device_ctx has 
D3D11 device which doesn't have D3D11VA interface, switching to default\n");
-else
-av_log(avctx, AV_LOG_INFO, "avctx->hw_device_ctx has 
non-AMD device, switching to default\n");
-}
-}
+
+switch 

[FFmpeg-devel] [PATCH 3/5] amfenc: Ensure that the software format of hardware frames is valid

2018-04-14 Thread Mark Thompson
From: Alexander Kravchenko 

Signed-off-by: Mark Thompson 
---
 libavcodec/amfenc.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index d1a28f13e2..b761cd74bf 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -68,7 +68,6 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
-{ AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
 };
 
 static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
@@ -263,6 +262,7 @@ static int amf_init_encoder(AVCodecContext *avctx)
 AmfContext  *ctx = avctx->priv_data;
 const wchar_t   *codec_id = NULL;
 AMF_RESULT   res = AMF_OK;
+enum AVPixelFormat   pix_fmt;
 
 switch (avctx->codec->id) {
 case AV_CODEC_ID_H264:
@@ -276,8 +276,14 @@ static int amf_init_encoder(AVCodecContext *avctx)
 }
 AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is 
not supported\n", avctx->codec->id);
 
-ctx->format = amf_av_to_amf_format(avctx->pix_fmt);
-AMF_RETURN_IF_FALSE(ctx, ctx->format != AMF_SURFACE_UNKNOWN, 
AVERROR(EINVAL), "Format %d is not supported\n", avctx->pix_fmt);
+if (ctx->hw_frames_ctx)
+pix_fmt = ((AVHWFramesContext*)ctx->hw_frames_ctx->data)->sw_format;
+else
+pix_fmt = avctx->pix_fmt;
+
+ctx->format = amf_av_to_amf_format(pix_fmt);
+AMF_RETURN_IF_FALSE(ctx, ctx->format != AMF_SURFACE_UNKNOWN, 
AVERROR(EINVAL),
+"Format %s is not supported\n", 
av_get_pix_fmt_name(pix_fmt));
 
 res = ctx->factory->pVtbl->CreateComponent(ctx->factory, ctx->context, 
codec_id, >encoder);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, 
"CreateComponent(%ls) failed with error %d\n", codec_id, res);
-- 
2.16.3

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


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

2018-04-14 Thread Mark Thompson
Also minor cosmetics.
---
 libavcodec/amfenc.c | 70 -
 1 file changed, 26 insertions(+), 44 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index e641048532..93fcee9480 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -107,16 +107,11 @@ static AMFTraceWriterVtbl tracer_vtbl =
 
 static int amf_load_library(AVCodecContext *avctx)
 {
-AmfContext *ctx = avctx->priv_data;
-AMFInit_Fn  init_fun = NULL;
-AMFQueryVersion_Fn  version_fun = NULL;
-AMF_RESULT  res = AMF_OK;
+AmfContext*ctx = avctx->priv_data;
+AMFInit_Fn init_fun;
+AMFQueryVersion_Fn version_fun;
+AMF_RESULT res;
 
-ctx->eof = 0;
-ctx->delayed_drain = 0;
-ctx->hw_frames_ctx = NULL;
-ctx->hw_device_ctx = NULL;
-ctx->delayed_surface = NULL;
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
@@ -326,10 +321,10 @@ static int amf_init_context(AVCodecContext *avctx)
 
 static int amf_init_encoder(AVCodecContext *avctx)
 {
-AmfContext  *ctx = avctx->priv_data;
-const wchar_t   *codec_id = NULL;
-AMF_RESULT   res = AMF_OK;
-enum AVPixelFormat   pix_fmt;
+AmfContext*ctx = avctx->priv_data;
+const wchar_t *codec_id = NULL;
+AMF_RESULT res;
+enum AVPixelFormat pix_fmt;
 
 switch (avctx->codec->id) {
 case AV_CODEC_ID_H264:
@@ -360,9 +355,9 @@ static int amf_init_encoder(AVCodecContext *avctx)
 
 int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 {
-AmfContext  *ctx = avctx->priv_data;
-if (ctx->delayed_surface)
-{
+AmfContext *ctx = avctx->priv_data;
+
+if (ctx->delayed_surface) {
 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
 ctx->delayed_surface = NULL;
 }
@@ -402,11 +397,11 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
 AMFSurface* surface)
 {
-AMFPlane   *plane = NULL;
-uint8_t*dst_data[4];
-int dst_linesize[4];
-int planes;
-int i;
+AMFPlane *plane;
+uint8_t  *dst_data[4];
+int   dst_linesize[4];
+int   planes;
+int   i;
 
 planes = surface->pVtbl->GetPlanesCount(surface);
 av_assert0(planes < FF_ARRAY_ELEMS(dst_data));
@@ -437,11 +432,11 @@ static inline int timestamp_queue_enqueue(AVCodecContext 
*avctx, int64_t timesta
 
 static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer 
*buffer)
 {
-AmfContext *ctx = avctx->priv_data;
-int ret;
-AMFVariantStructvar = {0};
-int64_t timestamp = AV_NOPTS_VALUE;
-int64_t size = buffer->pVtbl->GetSize(buffer);
+AmfContext  *ctx = avctx->priv_data;
+int  ret;
+AMFVariantStruct var = {0};
+int64_t  timestamp = AV_NOPTS_VALUE;
+int64_t  size = buffer->pVtbl->GetSize(buffer);
 
 if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) {
 return ret;
@@ -497,20 +492,7 @@ static int amf_copy_buffer(AVCodecContext *avctx, AVPacket 
*pkt, AMFBuffer *buff
 // amfenc API implementation
 int ff_amf_encode_init(AVCodecContext *avctx)
 {
-AmfContext *ctx = avctx->priv_data;
-int ret;
-
-ctx->factory = NULL;
-ctx->debug = NULL;
-ctx->trace = NULL;
-ctx->context = NULL;
-ctx->encoder = NULL;
-ctx->library = NULL;
-ctx->version = 0;
-ctx->eof = 0;
-ctx->format = 0;
-ctx->tracer.vtbl = NULL;
-ctx->tracer.avctx = NULL;
+int ret;
 
 if ((ret = amf_load_library(avctx)) == 0) {
 if ((ret = amf_init_context(avctx)) == 0) {
@@ -595,10 +577,10 @@ static void amf_release_buffer_with_frame_ref(AMFBuffer 
*frame_ref_storage_buffe
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
-AMF_RESULT  res = AMF_OK;
-AmfContext *ctx = avctx->priv_data;
-AMFSurface *surface = NULL;
-int ret;
+AmfContext *ctx = avctx->priv_data;
+AMFSurface *surface;
+AMF_RESULT  res;
+int ret;
 
 if (!ctx->encoder)
 return AVERROR(EINVAL);
-- 
2.16.3

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


[FFmpeg-devel] [PATCH 2/5] amfenc: Do not automatically download/upload unknown hardware input frames

2018-04-14 Thread Mark Thompson
Supplying a hardware input frame which is not in the input hardware frames
context is not allowed by the API, so additional code to handle it is not
necessary.  Handling it automatically results in very low performance - it
is more appropriate to fail immediately so that the user can fix their
incorrect setup.
---
 libavcodec/amfenc.c | 88 +
 1 file changed, 35 insertions(+), 53 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 8a9d6884a4..d1a28f13e2 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -71,14 +71,6 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
 };
 
-
-static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
-{
-const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
-return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
-}
-
-
 static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
 {
 int i;
@@ -337,32 +329,14 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
 AMFSurface* surface)
 {
-AVFrame*sw_frame = NULL;
 AMFPlane   *plane = NULL;
 uint8_t*dst_data[4];
 int dst_linesize[4];
-int ret = 0;
 int planes;
 int i;
 
-if (frame->hw_frames_ctx && is_hwaccel_pix_fmt(frame->format)) {
-if (!(sw_frame = av_frame_alloc())) {
-av_log(avctx, AV_LOG_ERROR, "Can not alloc frame\n");
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error transferring the data to system 
memory\n");
-goto fail;
-}
-frame = sw_frame;
-}
-planes = (int)surface->pVtbl->GetPlanesCount(surface);
-if (planes > amf_countof(dst_data)) {
-av_log(avctx, AV_LOG_ERROR, "Invalid number of planes %d in 
surface\n", planes);
-ret = AVERROR(EINVAL);
-goto fail;
-}
+planes = surface->pVtbl->GetPlanesCount(surface);
+av_assert0(planes < FF_ARRAY_ELEMS(dst_data));
 
 for (i = 0; i < planes; i++) {
 plane = surface->pVtbl->GetPlaneAt(surface, i);
@@ -373,11 +347,7 @@ static int amf_copy_surface(AVCodecContext *avctx, const 
AVFrame *frame,
 (const uint8_t**)frame->data, frame->linesize, frame->format,
 avctx->width, avctx->height);
 
-fail:
-if (sw_frame) {
-av_frame_free(_frame);
-}
-return ret;
+return 0;
 }
 
 static inline int timestamp_queue_enqueue(AVCodecContext *avctx, int64_t 
timestamp)
@@ -579,31 +549,46 @@ int ff_amf_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 return AVERROR_EOF;
 }
 } else { // submit frame
+int hw_surface = 0;
+
 if (ctx->delayed_surface != NULL) {
 return AVERROR(EAGAIN); // should not happen when called from 
ffmpeg, other clients may resubmit
 }
 // prepare surface from frame
-if (frame->hw_frames_ctx && ( // HW frame detected
-// check if the same hw_frames_ctx as used in initialization
-(ctx->hw_frames_ctx && frame->hw_frames_ctx->data == 
ctx->hw_frames_ctx->data) ||
-// check if the same hw_device_ctx as used in initialization
-(ctx->hw_device_ctx && 
((AVHWFramesContext*)frame->hw_frames_ctx->data)->device_ctx ==
-(AVHWDeviceContext*)ctx->hw_device_ctx->data)
-)) {
-AMFBuffer *frame_ref_storage_buffer;
-
+switch (frame->format) {
 #if CONFIG_D3D11VA
-static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 
0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
-ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // 
actual texture
-int index = (int)(size_t)frame->data[1]; // index is a slice in 
texture array is - set to tell AMF which slice to use
-texture->lpVtbl->SetPrivateData(texture, 
, sizeof(index), );
+case AV_PIX_FMT_D3D11:
+{
+static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 
0xe7c3, 0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
+ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; 
// actual texture
+int index = (int)(size_t)frame->data[1]; // index is a slice 
in texture array is - set to tell AMF which slice to use
 
-res = 
ctx->context->pVtbl->CreateSurfaceFromDX11Native(ctx->context, texture, 
, NULL); // wrap to AMF surface
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"CreateSurfaceFromDX11Native() failed  with error %d\n", res);
+av_assert0(frame->hw_frames_ctx   && ctx->hw_frames_ctx &&
+   frame->hw_frames_ctx->data == 

Re: [FFmpeg-devel] [PATCH] tests/checkasm/checkasm: Provide verbose failure information on float_near_abs_eps() failures

2018-04-14 Thread James Almer
On 4/14/2018 9:21 AM, Michael Niedermayer wrote:
> On Fri, Apr 13, 2018 at 12:19:38AM -0300, James Almer wrote:
>> On 4/12/2018 9:34 PM, Michael Niedermayer wrote:
>>> This will make understanding failures and adjusting EPS easier
>>>
>>> Signed-off-by: Michael Niedermayer 
>>> ---
>>>  tests/checkasm/checkasm.c | 6 +-
>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
>>> index 20ce56932f..8a3e24f100 100644
>>> --- a/tests/checkasm/checkasm.c
>>> +++ b/tests/checkasm/checkasm.c
>>> @@ -294,8 +294,12 @@ int float_near_ulp_array(const float *a, const float 
>>> *b, unsigned max_ulp,
>>>  int float_near_abs_eps(float a, float b, float eps)
>>>  {
>>>  float abs_diff = fabsf(a - b);
>>> +if (abs_diff < eps)
>>> +return 1;
>>>  
>>> -return abs_diff < eps;
>>> +fprintf(stderr, "test failed comparing %f with %f (abs diff=%f with 
>>> EPS=%f)\n", a, b, abs_diff, eps);
>>
>> Maybe %g instead? I may be better to print small values, but I'm not
>> sure. LGTM in any case.
> 
> %g is a good idea, ill change it to that
> 
> 
>>
>> A few tests also output a custom log message like this one, so it may be
>> a good idea to remove them now that it's done in general.
> 
> agree, not sure which messages exactly you mean though
> 
> will apply so we can easily gather more information about some failures

The synth filter test prints a custom error message similar to the one
you're adding, and other modules probably do the same. I'll see about
removing them now that this is printed by float_near_abs_eps() itself.

> 
> thanks
> 
> [...]
> 
> 
> 
> ___
> 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] tests/checkasm/checkasm: Provide verbose failure information on float_near_abs_eps() failures

2018-04-14 Thread Michael Niedermayer
On Fri, Apr 13, 2018 at 12:19:38AM -0300, James Almer wrote:
> On 4/12/2018 9:34 PM, Michael Niedermayer wrote:
> > This will make understanding failures and adjusting EPS easier
> > 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  tests/checkasm/checkasm.c | 6 +-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
> > index 20ce56932f..8a3e24f100 100644
> > --- a/tests/checkasm/checkasm.c
> > +++ b/tests/checkasm/checkasm.c
> > @@ -294,8 +294,12 @@ int float_near_ulp_array(const float *a, const float 
> > *b, unsigned max_ulp,
> >  int float_near_abs_eps(float a, float b, float eps)
> >  {
> >  float abs_diff = fabsf(a - b);
> > +if (abs_diff < eps)
> > +return 1;
> >  
> > -return abs_diff < eps;
> > +fprintf(stderr, "test failed comparing %f with %f (abs diff=%f with 
> > EPS=%f)\n", a, b, abs_diff, eps);
> 
> Maybe %g instead? I may be better to print small values, but I'm not
> sure. LGTM in any case.

%g is a good idea, ill change it to that


> 
> A few tests also output a custom log message like this one, so it may be
> a good idea to remove them now that it's done in general.

agree, not sure which messages exactly you mean though

will apply so we can easily gather more information about some failures

thanks

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

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


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


Re: [FFmpeg-devel] FFmpeg 3.5 / 4.0

2018-04-14 Thread Michael Niedermayer
On Fri, Apr 13, 2018 at 12:53:08AM +0200, Michael Niedermayer wrote:
> On Mon, Feb 19, 2018 at 02:50:08AM +0100, Michael Niedermayer wrote:
> > Hi
> > 
> > Its 4 months since 3.4 was branched so its time for a new major release
> > 
> > Is 4.0 or 3.5 preferred ?
> > Any name suggestions ?
> > 
> > If there are no objections i will likely make that release in the next weeks
> 
> more time has passed than intended ...
> 
> what issues do remain that need to be fixed before the release ?
> I see fate.ffmpeg.org is not looking that well (compared to most
> releases in the past) i remember this being pretty much green longer ago
> do people want these to be fixed before the release ?

ok, so, my plan is to create a release/4.0 branch from master in the next
24-48 hours unless theres some issue brought to my attention (CC me just to
be sure if theres an issue)

then wait 2 days or so and backport any newly found bugfixes to release/4.0
and then make the release finally

delays at any point are possible due to issues, lack of time or other.

as name i think kierans suggestion of Wu would make sense. IIRC we had
no name suggested by more than 1 developer. Please correct me if i
miscounted i did only briefly re-check the mails in the thread.

Thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


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


Re: [FFmpeg-devel] [PATCH] avformat/utils: Stream specifier enhancement 2.

2018-04-14 Thread Michael Niedermayer
On Fri, Apr 13, 2018 at 10:03:18PM +0200, Bodecs Bela wrote:
> 
> 
> 2018.04.13. 20:54 keltezéssel, Michael Niedermayer írta:
> >On Fri, Apr 13, 2018 at 12:16:52PM +0200, Bodecs Bela wrote:
> >>Dear All,
> >>
> >>In some cases, mainly working with multiprogram mpeg-ts containers as
> >>input, it would be handy to select sub stream of a specific program by
> >>their metadata.
> >>This patch makes it possible to narrow the stream selection among
> >>streams of the specified program by stream metadata.
> >>
> >>Examples:
> >>p:601:m:language:hun  will select all sub streams of program with id 601
> >>where sub streams have metadata key named 'language' with value 'hun'.
> >>p:602:m:guide  will select all sub streams of program with id 602 where
> >>sub streams have metadata key named 'guide'.
> >>
> >>This syntax enhancement does not interfere in any way with
> >>current/existing syntax or working command lines.
> >>
> >>please review this patch.
> >>
> >>thank you in advance,
> >>
> >>best,
> >>
> >>Bela
> >>
> >>  doc/fftools-common-opts.texi |   10 --
> >>  libavformat/utils.c  |   28 
> >>  2 files changed, 36 insertions(+), 2 deletions(-)
> >>03f0760a24e25b89f4515e3fd860f3af1061ae23  
> >>0001-avformat-utils-Stream-specifier-enhancement-2.patch
> >> From fbec3c0c9b8189b1517f33394548c58c112a48ed Mon Sep 17 00:00:00 2001
> >>From: Bela Bodecs 
> >>Date: Fri, 13 Apr 2018 12:11:32 +0200
> >>Subject: [PATCH] avformat/utils: Stream specifier enhancement 2.
> >will apply
> >
> >can you also add a fate test ?
> >
> >thanks
> >
> >[...]
> I have searched but there is no mpeg-ts with metadata among test files.
> which is the preferred solution:
> a.) send a files into the fate-suite or b.) create on-the-fly for test?

if it can be created on the fly that is better as it would then also test
the codepathes for creating such files

thx

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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin


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


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

2018-04-14 Thread Martin Vignali
> >
> > For the proxy chroma version is also the same matrix use in prores_aw
>
> Patch is OK then, assumming FATE still passes.
>
>
> Ok thanks for comments.
It passes fate test for me (but prores_ks have few fate test !)

I will wait few days, if someone else have comments, before apply.

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


Re: [FFmpeg-devel] avdevice/sdl output : fix window_size and add new option (WIP)

2018-04-14 Thread Martin Vignali
2018-04-08 17:28 GMT+02:00 Martin Vignali :

> Hello,
>
> In attach patchs to improve SDL Output device
> (Missing doc update)
>
> - 001 : Fix -window_size option
> Before this patch, window_size is always set to the source size
> In other word, -window_size option have no effect.
>
> To test :
> ./ffmpeg -f lavfi -i smptehdbars=hd1080 -c:v rawvideo -pix_fmt yuv420p
> -window_size 1024x576 -f sdl "SDL output with Custom Size"
>
> - 002 : Add option to set the position of the window
> the default behaviour doesn't change (set the position to undefined)
>
> To test :
> ./ffmpeg -f lavfi -i smptehdbars=hd1080 -c:v rawvideo -pix_fmt yuv420p
> -window_size 1024x576 -window_pos_x 30 -window_pos_y 100 -f sdl "SDL output
> With Custom size pos"
>
> - 003 : Add option to disable quit action
> Without this patch, the window can be close by the user
> if this new option is set, the window can't be close (by "close" window
> btn, escape, or "q")
> The default behaviour doesn't change
>
> To test :
> ./ffmpeg -re -f lavfi -i smptehdbars=hd1080:duration=10 -c:v rawvideo
> -pix_fmt yuv420p -window_enable_quit 0 -f sdl "SDL output Without Quit"
>
>
>
Ping

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