Re: [FFmpeg-devel] [FFmpeg-devel, RFC] lavfi: add opencl tonemap filter.

2018-05-08 Thread Song, Ruiling
Hello Niklas,

Thanks so much for your valuable feedback.

> -Original Message-
> From: Niklas Haas [mailto:ffm...@haasn.xyz]
> Sent: Saturday, May 5, 2018 2:00 AM
> To: Song, Ruiling 
> Cc: ffmpeg-devel@ffmpeg.org; s...@jkqxz.net
> Subject: Re: [FFmpeg-devel,RFC] lavfi: add opencl tonemap filter.
> 
> Hello Ruiling,
> 
> On Fri,  4 May 2018 15:32:58 +0800, Ruiling Song 
> wrote:
> > It basically does hdr to sdr conversion with tonemapping.
> >
> > Signed-off-by: Ruiling Song 
> > ---
> > This patch tries to add a filter to do hdr to sdr conversion with 
> > tonemapping.
> > The filter does all the job of tonemapping in one pass, which is quite 
> > different
> from the vf_tonemap.c
> > I choose this way because I think this would introduce less memory access.
> >
> > And I find that tonemaping shares lots of code with colorspace conversion.
> > So I move color space related code into seprated files (both OpenCL kernel 
> > and
> host code).
> >
> > I am not sure whether the design seems OK?
> > Is there anybody would like to give some comments on the overall design or
> implementation details?
> >
> >
> > Thanks!
> > Ruiling
> 
> As the original author of the tone mapping code that inspired vf_tonemap
> and (by proxy) vf_tonemap_opencl, I can provide a handful of comments.
> 
> > +float3 map_one_pixel_rgb(float3 rgb, float peak) {
> > +// de-saturate
> > +float luma = get_luma(rgb.x, rgb.y, rgb.z);
> > +float overbright = max(luma - 2.0f, 1e-6f) / max(luma, 1e-6f);
> > +rgb = mix(rgb, (float3)luma, (float3)overbright);
> > +
> > +float sig = max(max(rgb.x, max(rgb.y, rgb.z)), 1e-6f);
> > +float sig_old = sig;
> > +sig = TONE_FUNC(sig, peak);
> > +rgb *= (sig/sig_old);
> > +return rgb;
> > +}
> 
> I consider this desaturation algorithm outdated. It works, but I think
> it produces lower quality results than this one:
> 
>   float sig = max(max(rgb.x, max(rgb.y, rgb.z)), 1e-6f);
>   float luma = get_luma(rgb.x, rgb.y, rgb.z);
>   float coeff = max(sig - 0.18f, 1e-6f) / max(sig, 1e-6f);
> 
>   const float desaturation_coefficient = 0.5f; // or configurable!
>   coeff = pow(coeff, 10 / desaturation_coefficient;
>   rgb = mix(rgb, (float3)luma, coeff);
>   sig = mix(sig, luma, coeff);
> 
>   // do the rest of tone-mapping on `sig`
>   float sig_old = sig;
>   ...
> 
> Basically, I've done the following:
> 
> - Calculate the overbright coefficient on `sig` rather than `luma` alone
> - Instead of using an offset of 2.0f, use an offset of 0.18f
> - Take the coefficient to a high exponent (lower exponent = more
>   desaturation, which is why I invert the user-configurable parameter)
> 
> Since the new code needs to read `sig`, we also have to move up the
> `sig` calculation and then correctly adjust it afterwards as well.
I will try your suggestion.

> 
> 
> 
> More importantly, this algorithm is missing something that I now
> consider very important, and which would align well with OpenCL: source
> brightness detection. Just doing the tone-mapping "blind" like this
> works to some extent, but I think the best results require also
> adjusting the exposure in order to compensate for hollywood's tendency
> to ship poorly mastered, over-illuminated HDR material.
> 
> The basic premise is to calculate both the peak brightness as well as
> the average brightness on a frame-by-frame basis, and incorporate those
> measured values in the algorithm, in order to re-normalize overly bright
> scenes to correspond to a typical SDR average of around 0.25. In
> addition to this, calculating the peak explicitly allows us to exactly
> tailor the hable() function to this specific frame, even if the
> mastering metadata is missing or useless. (Which it almost always is)
> 
> Doing this in OpenCL would essentially require implementing a big
> map-reduce to keep track of respectively the sum and max of each pixel's
> brightness. In addition to this, I recommend averaging the results over
> a few frames (I like to use around one second), with the caveat that
> this is best paired with at least a naive scene change detection
> heuristic to make sure this averaging window gets reset on a scene
> change.
Thanks for sharing your idea with me. I basically also noticed some poor 
quality tone mapping result for some hdr stream.
I will try your suggestion to see whether I can make it in good state so I can 
include it in next version.
In fact I have not thought detecting scene change quite well. A question for 
your idea is:
is it possible that your scene detection heuristic may still failed to detect 
some particular scene change and lead to poor tone mapping quality?

> 
> > +static double determine_signal_peak(AVFrame *in)
> > +{
> > +AVFrameSideData *sd = av_frame_get_side_data(in,
> AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
> > +double peak = 0;
> > +
> > +if (sd) {
> > +AVContentLightMetadata *clm = (AVContentLightMetadata *)sd->data;
> > +peak = clm->MaxCLL;
> > +   

Re: [FFmpeg-devel] [PATCH v2 04/10] lavfi/nlmeans: add AArch64 SIMD for compute_safe_ssd_integral_image

2018-05-08 Thread Clément Bœsch
On Tue, May 08, 2018 at 04:06:26AM +0200, Michael Niedermayer wrote:
> On Mon, May 07, 2018 at 07:24:16PM +0200, Clément Bœsch wrote:
> > ssd_integral_image_c: 49204.6
> > ssd_integral_image_neon: 28346.8
> > ---
> >  libavfilter/aarch64/Makefile  |  3 +
> >  libavfilter/aarch64/vf_nlmeans_init.c | 33 +++
> >  libavfilter/aarch64/vf_nlmeans_neon.S | 80 +++
> >  libavfilter/vf_nlmeans.c  | 26 ++---
> >  libavfilter/vf_nlmeans.h  | 35 
> >  5 files changed, 170 insertions(+), 7 deletions(-)
> >  create mode 100644 libavfilter/aarch64/Makefile
> >  create mode 100644 libavfilter/aarch64/vf_nlmeans_init.c
> >  create mode 100644 libavfilter/aarch64/vf_nlmeans_neon.S
> >  create mode 100644 libavfilter/vf_nlmeans.h
> 
> seems to break make testprogs unless iam missing something
> 

oups, I forgot I added such a test. It's a bit redundant with the checkasm
test and now mostly useless due to the recently introduced 16B padding
constraint, but I fixed it anyway locally.

[...]

-- 
Clément B.


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


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

2018-05-08 Thread Oscar Amoros Huguet
Thank you so much!

We will test this hopefully today, and verify the expected behavior with NSIGHT.

By the way, I'm new to ffmpeg, so... I don't know if you use your fork to test 
things first, before adding the changes to the main ffmpeg project? Or may we 
consider to compile and use your fork?

Thanks!

-Original Message-
From: ffmpeg-devel  On Behalf Of Timo 
Rothenpieler
Sent: Tuesday, May 8, 2018 12:11 AM
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] Added the possibility to pass an externally 
created CUDA context to libavutil/hwcontext.c/av_hwdevice_ctx_create() for 
decoding with NVDEC

Am 07.05.2018 um 19:37 schrieb Oscar Amoros Huguet:
> I was looking at the NVIDIA Video codec sdk samples 
> (https://developer.nvidia.com/nvidia-video-codec-sdk#Download), where you can 
> find the header NvDecoder.h next to cuviddec.h where CUVIDPROCPARAMS is 
> defined.
> 
> Anyway, I should have looked at ffmpeg code directly, to see what’s being 
> used, sorry for that.
> 
> Great then! Having the same cuda stream (either default or custom) for 
> everything is the safest and most efficient way to go (in this case).
> 
> Thanks, and let me know if I can help with anything.
> 

You can find the mentioned changes on my personal github:
https://github.com/BtbN/FFmpeg

The cuMemcpy is entirely gone, not just Async. And the CUstream can be set and 
will be passed on to cuvid/nvdec.

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


Re: [FFmpeg-devel] Misc improvements in nlmeans filter [v2]

2018-05-08 Thread Clément Bœsch
On Mon, May 07, 2018 at 07:32:55PM +0200, Paul B Mahol wrote:
> On 5/7/18, Clement Boesch  wrote:
> > Changes since v1:
> >
> > - fixed float operation in double as pointed out by Moritz
> > - fix broken commit split as pointed out by Michael
> > - added patch 10: "use unsigned for the integral patch"
> > - misc instruction shuffling in AArch64 SIMD for better performances
> >
> > I plan to push this soon unless someone wants more time to review.
> >
> > BTW, x86 SIMD patch welcome, the filter badly needs some performance
> > improvements. Also, any suggestion on how not to make it spend 80% of
> > the time in nlmeans_slice() welcome.
> >
> > Regards,
> 
> LGTM

patchset applied

-- 
Clément B.


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


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

2018-05-08 Thread Timo Rothenpieler
On 08.05.2018 10:11, Oscar Amoros Huguet wrote:
> Thank you so much!
> 
> We will test this hopefully today, and verify the expected behavior with 
> NSIGHT.
> 
> By the way, I'm new to ffmpeg, so... I don't know if you use your fork to 
> test things first, before adding the changes to the main ffmpeg project? Or 
> may we consider to compile and use your fork?
> 
> Thanks!

I'm only using my github fork to stage new patches. Most of the times
it's notably behind ffmpeg master or contains half-broken WIP patches.
So I wouldn't recommend using it on a regular basis.



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


Re: [FFmpeg-devel] fate/hap : add test for hap encoding

2018-05-08 Thread Martin Vignali
>
> > Sorry, i missread the code before writing the test, and
> > didn't see it use float for one step.
> > I will send a patch to remove these tests.
>
> Or just commit.
>
>
Tests removed.

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-05-08 Thread Martin Vignali
2018-04-20 22:24 GMT+02:00 Moritz Barsnick :

> On Sun, Apr 08, 2018 at 17:28:24 +0200, Martin Vignali wrote:
>
> > - 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.
>
> Makes sense, since the option was already there.
>
> > - 002 : Add option to set the position of the window
> > the default behaviour doesn't change (set the position to undefined)
>
> A -window_size syntax such as 1024x768+100+100 would seem intuitive to
> me (old Unix/X11 user), but perhaps that's just me, and I guess
> AV_OPT_TYPE_IMAGE_SIZE doesn't support that.
>
> > Comments Welcome
>
> -window_size: works for me
> -window_enable_quit 0: works for me
> -window_pos_x/-window_pos_y: doesn't work for me, but I can only test
>  remote X11 (Xwayland) via ssh
>
>
>
Thanks for comments and testing.
Dropped the window_pos patch.

New patch in attach :
- 001 : Fix -window_size option --> Unchanged patch
- 002 : Add option to disable quit action : Add doc

Martin


0001-avdevice-sdl2output-fix-setting-window_size.patch
Description: Binary data


0002-avdevice-sdl2-add-option-to-define-if-the-window-qui.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/13] avformat/mxfenc: Correct KAG alignment of preface

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfenc.c|  1 +
>  tests/ref/fate/copy-trac4914|  4 ++--
>  tests/ref/fate/mxf-reel_name|  2 +-
>  tests/ref/fate/time_base|  2 +-
>  tests/ref/lavf/mxf  | 12 ++--
>  tests/ref/lavf/mxf_d10  |  4 ++--
>  tests/ref/lavf/mxf_dv25 |  4 ++--
>  tests/ref/lavf/mxf_dvcpro50 |  4 ++--
>  tests/ref/lavf/mxf_opatom   |  2 +-
>  tests/ref/lavf/mxf_opatom_audio |  4 ++--
>  10 files changed, 20 insertions(+), 19 deletions(-)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index 3bb70326fe..c0db10b3c2 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -1757,6 +1757,7 @@ static int mxf_write_partition(AVFormatContext
> *s, int bodysid,
>  mxf_write_klv_fill(s);
>  start = avio_tell(s->pb);
>  mxf_write_primer_pack(s);
> +mxf_write_klv_fill(s);
>  mxf_write_header_metadata_sets(s);
>  pos = avio_tell(s->pb);
>  header_byte_count = pos - start + klv_fill_size(pos);

Feels like such an elementary error. Probably OK, but it's been a while
since I read the specs

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


Re: [FFmpeg-devel] [PATCH 03/13] avformat/mxfenc: Add Product Version, Toolkit version and Platform

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
>  static void mxf_write_identification(AVFormatContext *s)
>  {
>  MXFContext *mxf = s->priv_data;
> @@ -790,7 +809,7 @@ static void mxf_write_identification(AVFormatContext *s)
>  
>  version = s->flags & AVFMT_FLAG_BITEXACT ?
>  "0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
> -length = 72 + mxf_utf16_local_tag_length(company) +
> +length = 100 +mxf_utf16_local_tag_length(company) +

I have mixed feelings about this style of computation. But not enough
to hold the patch up, which looks OK

/Tomas



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


[FFmpeg-devel] [PATCH v2 1/3] lavf/network: fix doxygen comments.

2018-05-08 Thread Jun Zhao
Signed-off-by: Jun Zhao 
---
 libavformat/network.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/network.h b/libavformat/network.h
index e3fda4d..efaa789 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -87,9 +87,9 @@ int ff_network_wait_fd(int fd, int write);
  * This works similarly to ff_network_wait_fd, but waits up to 'timeout' 
microseconds
  * Uses ff_network_wait_fd in a loop
  *
- * @fd Socket descriptor
- * @write Set 1 to wait for socket able to be read, 0 to be written
- * @timeout Timeout interval, in microseconds. Actual precision is 10 mcs, 
due to ff_network_wait_fd usage
+ * @param fd Socket descriptor
+ * @param write Set 1 to wait for socket able to be read, 0 to be written
+ * @param timeout Timeout interval, in microseconds. Actual precision is 
10 mcs, due to ff_network_wait_fd usage
  * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd 
call
  * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout 
expired, or negative error code
  */
@@ -98,7 +98,7 @@ int ff_network_wait_fd_timeout(int fd, int write, int64_t 
timeout, AVIOInterrupt
 /**
  * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and
  * triggered, return before that.
- * @timeout Timeout in microseconds. Maybe have lower actual precision.
+ * @param timeout Timeout in microseconds. Maybe have lower actual precision.
  * @param int_cb Interrupt callback, is checked regularly.
  * @return AVERROR(ETIMEDOUT) if timeout expirted, AVERROR_EXIT if interrupted 
by int_cb
  */
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 2/3] lavf/tcp: add option to setting Maximum Segment Size

2018-05-08 Thread Jun Zhao
This can change the the MSS value announced to the other end in
the initial TCP packet, it's can be used when failed Path MTU
discovery.

Signed-off-by: Jun Zhao 
---
 libavformat/tcp.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index b0289f8..499e365 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -42,6 +42,9 @@ typedef struct TCPContext {
 int recv_buffer_size;
 int send_buffer_size;
 int tcp_nodelay;
+#if !HAVE_WINSOCK2_H
+int tcp_mss;
+#endif /* !HAVE_WINSOCK2_H */
 } TCPContext;
 
 #define OFFSET(x) offsetof(TCPContext, x)
@@ -54,6 +57,9 @@ static const AVOption options[] = {
 { "send_buffer_size", "Socket send buffer size (in bytes)",
OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
 { "recv_buffer_size", "Socket receive buffer size (in bytes)", 
OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
 { "tcp_nodelay", "Use TCP_NODELAY to disable nagle's algorithm",   
OFFSET(tcp_nodelay), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
D|E },
+#if !HAVE_WINSOCK2_H
+{ "tcp_mss", "Maximum segment size for outgoing TCP packets",  
OFFSET(tcp_mss), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
+#endif /* !HAVE_WINSOCK2_H */
 { NULL }
 };
 
@@ -153,6 +159,11 @@ static int tcp_open(URLContext *h, const char *uri, int 
flags)
 if (s->tcp_nodelay > 0) {
 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof 
(s->tcp_nodelay));
 }
+#if !HAVE_WINSOCK2_H
+if (s->tcp_mss > 0) {
+setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &s->tcp_mss, sizeof 
(s->tcp_mss));
+}
+#endif /* !HAVE_WINSOCK2_H */
 
 if (s->listen == 2) {
 // multi-client
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 04/13] avformat/mxfenc: Add object model version

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 

>  mxf_write_metadata_key(pb, 0x012f00);
>  PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
> -klv_encode_ber_length(pb, 130 + 16LL * 
> DESCRIPTOR_COUNT(mxf->essence_container_count));
> +klv_encode_ber_length(pb, 138 + 16LL * 
> DESCRIPTOR_COUNT(mxf->essence_container_count));
>  
>  // write preface set uid
>  mxf_write_local_tag(pb, 16, 0x3C0A);
> @@ -696,6 +697,10 @@ static void mxf_write_preface(AVFormatContext *s)
>  mxf_write_local_tag(pb, 2, 0x3B05);
>  avio_wb16(pb, 259); // v1.2
>  
> +// Object Model Version
> +mxf_write_local_tag(pb, 4, 0x3B07);
> +avio_wb32(pb, 1);
> 

Not sure what use this is, but looks OK at least. S377m doesn't seem to
think it's necessary. Is there some program that needs this?

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


[FFmpeg-devel] [PATCH v2 3/3] doc/protocols: documents tcp_mss

2018-05-08 Thread Jun Zhao
Signed-off-by: Jun Zhao 
---
 doc/protocols.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index e19504d..e9091e0 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1397,6 +1397,9 @@ Set send buffer size, expressed bytes.
 
 @item tcp_nodelay=@var{1|0}
 Set TCP_NODELAY to disable Nagle's algorithm. Default value is 0.
+
+@item tcp_mss=@var{bytes}
+Set maximum segment size for outgoing TCP packets, expressed in bytes.
 @end table
 
 The following example shows how to setup a listening TCP connection
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 05/13] avformat/mxfenc: Fix stored width

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> This fixes the width to have computations matching the height
> 
> > Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfenc.c  |   3 +-
>  .../ref/fate/concat-demuxer-extended-lavf-mxf |   2 +-
>  .../fate/concat-demuxer-extended-lavf-mxf_d10 |   2 +-
>  .../ref/fate/concat-demuxer-simple1-lavf-mxf  | 242 +-
>  .../fate/concat-demuxer-simple1-lavf-mxf_d10  | 140 +-
>  tests/ref/seek/lavf-mxf   |  44 ++--
>  tests/ref/seek/lavf-mxf_d10   |  54 ++--
>  tests/ref/seek/lavf-mxf_dv25  |  54 ++--
>  tests/ref/seek/lavf-mxf_dvcpro50  |  54 ++--
>  tests/ref/seek/lavf-mxf_opatom_audio  |  54 ++--
>  10 files changed, 325 insertions(+), 324 deletions(-)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index f0fd406493..9140302b81 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -1131,6 +1131,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  {
>  MXFStreamContext *sc = st->priv_data;
>  AVIOContext *pb = s->pb;
> +int stored_width  = (st->codecpar->width +15)/16*16;
>  int stored_height = (st->codecpar->height+15)/16*16;

Should a muxer really do this kinds of computations? What happens if a
codec comes along that has larger or smaller macroblocks?

>  int display_height;
>  int f1, f2;
> @@ -1143,7 +1144,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  mxf_write_generic_desc(s, st, key, desc_size);
>  
>  mxf_write_local_tag(pb, 4, 0x3203);
> -avio_wb32(pb, st->codecpar->width);
> +avio_wb32(pb, stored_width);

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


Re: [FFmpeg-devel] [PATCH 06/13] avformat/mxfenc: Add Sample width/height/x offset/y offset, Display x offset and F2 offset

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> +if (sc->interlaced) {
> +//Display F2 Offset
> +mxf_write_local_tag(pb, 4, 0x3217);
> +avio_wb32(pb, -((st->codecpar->height - display_height)&1));

Negative values for DisplayF2Offset are not valid

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


Re: [FFmpeg-devel] [PATCH 07/13] avformat/mxfenc: Add vertical subsampling support

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> 
> @@ -1149,6 +1151,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  desc_size += 5;
>  if (sc->interlaced)
>  desc_size += 8;
> +if (sc->v_chroma_sub_sample)
> +desc_size += 8;
>  
>  mxf_write_generic_desc(s, st, key, desc_size);
>  
> @@ -1209,6 +1213,12 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  mxf_write_local_tag(pb, 4, 0x3302);
>  avio_wb32(pb, sc->h_chroma_sub_sample);
>  
> +// vertical subsampling
> +if (sc->v_chroma_sub_sample) {
> +mxf_write_local_tag(pb, 4, 0x3308);
> +avio_wb32(pb, sc->v_chroma_sub_sample);
> +}
> +
>  // color siting
>  mxf_write_local_tag(pb, 1, 0x3303);
>  avio_w8(pb, sc->color_siting);
> @@ -2273,6 +2283,7 @@ static int mxf_write_header(AVFormatContext *s)
>  if (pix_desc) {
>  sc->component_depth = pix_desc->comp[0].depth;
>  sc->h_chroma_sub_sample = 1 << pix_desc->log2_chroma_w;
> +sc->v_chroma_sub_sample = 1 << pix_desc->log2_chroma_h;

Looks OK. Had this confused for chrome siting for a while, but I see
that is actually handled correctly.

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


Re: [FFmpeg-devel] [PATCH 08/13] avformat/mxfenc: add white/black ref /color range

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> 
> +if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED) {
> +int black = 0,
> +white = (1 +color = (1 +if (st->codecpar->color_range == AVCOL_RANGE_MPEG) {
> +black = 1   << (sc->component_depth - 4);
> +white = 235 << (sc->component_depth - 8);
> +color = (14 << (sc->component_depth - 4)) + 1;
> +}

This feels like something that should be part of pix_fmt stuff or
something. But maybe someone can refactor that later. Looks OK
otherwise

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


[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to

2018-05-08 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying
This patch does not change component behaviour, 
it contains only restructurization for further patches with new amf components

---
sending patch one more time in May, since April's one wasn't commented/pushed.
previous April's link:
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/229051.html



 libavcodec/amfenc.c| 250 ---
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 329 +
 libavutil/hwcontext_amf.h  |  43 ++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 418 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..a8186c7b86 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#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"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,17 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+av_unused int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +98,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-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
- 

Re: [FFmpeg-devel] [PATCH 09/13] avformat/mxfenc: Add Padding Bits

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> @@ -1228,6 +1229,10 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  mxf_write_local_tag(pb, 1, 0x3303);
>  avio_w8(pb, sc->color_siting);
>  
> +// Padding Bits
> +mxf_write_local_tag(pb, 2, 0x3307);
> +avio_wb16(pb, 0);

I'm pretty sure there's ways of muxing v210 in mxf, so it might be
better to say nothing here unless we're entirely sure. Probably OK
since mxfenc can't mux raw video tho

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


[FFmpeg-devel] [PATCH v2 0/3] Add TCP MSS setting.

2018-05-08 Thread Jun Zhao
v2: - fix build fail in win32/mingw32/mingw64
- change the tcp_mss docments as Gyan's comments

Jun Zhao (3):
  lavf/network: fix doxygen comments.
  lavf/tcp: add option to setting Maximum Segment Size
  doc/protocols: documents tcp_mss

 doc/protocols.texi|  3 +++
 libavformat/network.h |  8 
 libavformat/tcp.c | 11 +++
 3 files changed, 18 insertions(+), 4 deletions(-)

-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 10/13] avformat/mxfenc: Set color siting to 0 for D10-MXF

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfenc.c  |   1 +
>  .../ref/fate/concat-demuxer-extended-lavf-mxf |   2 +-
>  .../fate/concat-demuxer-extended-lavf-mxf_d10 |   2 +-
>  .../ref/fate/concat-demuxer-simple1-lavf-mxf  | 242 +-
>  .../fate/concat-demuxer-simple1-lavf-mxf_d10  | 140 +-
>  tests/ref/seek/lavf-mxf   |  44 ++--
>  tests/ref/seek/lavf-mxf_d10   |  54 ++--
>  tests/ref/seek/lavf-mxf_dv25  |  54 ++--
>  tests/ref/seek/lavf-mxf_dvcpro50  |  54 ++--
>  tests/ref/seek/lavf-mxf_opatom|  54 ++--
>  tests/ref/seek/lavf-mxf_opatom_audio  |  54 ++--
>  11 files changed, 351 insertions(+), 350 deletions(-)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index f2be76cc86..adf5527534 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -2361,6 +2361,7 @@ static int mxf_write_header(AVFormatContext *s)
>  mxf->edit_unit_byte_count += 
> klv_fill_size(mxf->edit_unit_byte_count);
>  
>  sc->signal_standard = 1;
> +sc->color_siting = 0;
>  }

Can't find anything in my documents that says anything about this. I
don't remember what D-10 is actually specified in...

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


Re: [FFmpeg-devel] [PATCH 12/13] avformat/mxfenc: Add Stored F2 Offset / Image Start/End Offset for D10

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
>  desc_size += 8;
>  if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED)
>  desc_size += 8 * 3;
> +if (s->oformat == &ff_mxf_d10_muxer)
> +desc_size += 8 + 8 + 8;
>  
>  mxf_write_generic_desc(s, st, key, desc_size);
>  
> @@ -1169,6 +1173,20 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  mxf_write_local_tag(pb, 4, 0x3202);
>  avio_wb32(pb, stored_height>>sc->interlaced);
>  
> +if (s->oformat == &ff_mxf_d10_muxer) {
> +//Stored F2 Offset
> +mxf_write_local_tag(pb, 4, 0x3216);
> +avio_wb32(pb, 0);
> +
> +//Image Start Offset
> +mxf_write_local_tag(pb, 4, 0x3213);
> +avio_wb32(pb, 0);
> +
> +//Image End Offset
> +mxf_write_local_tag(pb, 4, 0x3214);
> +avio_wb32(pb, 0);
> +}

Looks OK, but of course I don't know what the spec says

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


[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-08 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
sending patch one more time in May, since April's one wasn't commented/pushed.
previous April's link:
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/229051.html



 libavcodec/amfenc.c| 250 ---
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 329 +
 libavutil/hwcontext_amf.h  |  43 ++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 418 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..a8186c7b86 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#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"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,17 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+av_unused int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +98,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-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
- 

Re: [FFmpeg-devel] [PATCH 13/13] avformat/mxfenc: Write transfer characteristic

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> 
> +static int get_trc(UID ul, enum AVColorTransferCharacteristic trc)
> +{
> +switch (trc){
> +case AVCOL_TRC_GAMMA28   :
> +case AVCOL_TRC_GAMMA22   :
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00},
>  16);
> +return 0;
> +case AVCOL_TRC_BT709 :
> +case AVCOL_TRC_SMPTE170M :
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00},
>  16);
> +return 0;
> +case AVCOL_TRC_SMPTE240M :
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x03,0x00,0x00},
>  16);
> +return 0;
> +case AVCOL_TRC_BT1361_ECG:
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x05,0x00,0x00},
>  16);
> +return 0;
> +case AVCOL_TRC_LINEAR:
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x06,0x00,0x00},
>  16);
> +return 0;
> +case AVCOL_TRC_SMPTE428  :
> +memcpy(ul, 
> (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x08,0x04,0x01,0x01,0x01,0x01,0x07,0x00,0x00},
>  16);
> +return 0;
> +default:
> +return -1;
> +}
> +}
> +
>  static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const 
> UID key, unsigned size)
>  {
>  MXFStreamContext *sc = st->priv_data;
> @@ -1152,6 +1181,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  int display_height;
>  int f1, f2;
>  unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5 + 5*8 + 6;
> +UID transfer_ul = {0};
> +
>  if (sc->interlaced && sc->field_dominance)
>  desc_size += 5;
>  if (sc->signal_standard)
> @@ -1164,6 +1195,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  desc_size += 8 * 3;
>  if (s->oformat == &ff_mxf_d10_muxer)
>  desc_size += 8 + 8 + 8;
> +if (get_trc(transfer_ul, st->codecpar->color_trc) >= 0)
> +desc_size += 20;
>  
>  mxf_write_generic_desc(s, st, key, desc_size);
>  
> @@ -1305,6 +1338,12 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  avio_wb32(pb, sc->aspect_ratio.num);
>  avio_wb32(pb, sc->aspect_ratio.den);
>  
> +//Transfer characteristic
> +if (transfer_ul[0]) {
> +mxf_write_local_tag(pb, 16, 0x3210);
> +avio_write(pb, transfer_ul, 16);
> +};

Looks OK, but I didn't check the ULs for correctness

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


Re: [FFmpeg-devel] [PATCH 11/13] avformat/mxfenc: Write Audio Ref Level for D10

2018-05-08 Thread Tomas Härdin
mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
>  // Generic Sound Essence Descriptor
>  { 0x3D02, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}},
>  /* Locked/Unlocked */
>  { 0x3D03, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}},
>  /* Audio sampling rate */
> +{ 0x3D04, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x02,0x01,0x01,0x03,0x00,0x00,0x00}},
>  /* Audio Ref Level */
>  { 0x3D07, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}},
>  /* ChannelCount */
>  { 0x3D01, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}},
>  /* Quantization bits */
>  { 0x3D06, 
> {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}},
>  /* Sound Essence Compression */
> @@ -1333,6 +1334,8 @@ static void 
> mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
>  
>  if (s->oformat == &ff_mxf_opatom_muxer)
>  duration_size = 12;
> +if (s->oformat == &ff_mxf_d10_muxer)
> +size += 5;
>  
>  mxf_write_generic_desc(s, st, key, size+duration_size+5+12+8+8);
>  
> @@ -1350,6 +1353,11 @@ static void 
> mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
>  avio_wb32(pb, st->codecpar->sample_rate);
>  avio_wb32(pb, 1);
>  
> +if (s->oformat == &ff_mxf_d10_muxer) {
> +mxf_write_local_tag(pb, 1, 0x3D04);
> +avio_w8(pb, 0);
> +}

Sizes and such look OK, but again I don't know what the D-10 spec says

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


[FFmpeg-devel] [PATCH] avfilter: add fftdnoiz filter

2018-05-08 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 configure |   2 +
 doc/filters.texi  |  32 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_fftdnoiz.c | 691 ++
 5 files changed, 727 insertions(+)
 create mode 100644 libavfilter/vf_fftdnoiz.c

diff --git a/configure b/configure
index 7c143238a8..093d854ef1 100755
--- a/configure
+++ b/configure
@@ -3325,6 +3325,8 @@ elbg_filter_deps="avcodec"
 eq_filter_deps="gpl"
 fftfilt_filter_deps="avcodec"
 fftfilt_filter_select="rdft"
+fftdnoiz_filter_deps="avcodec"
+fftdnoiz_filter_select="fft"
 find_rect_filter_deps="avcodec avformat gpl"
 firequalizer_filter_deps="avcodec"
 firequalizer_filter_select="rdft"
diff --git a/doc/filters.texi b/doc/filters.texi
index 33e27e10f3..8f48971e57 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8696,6 +8696,38 @@ fftfilt=dc_Y=0:weight_Y='exp(-4 * ((Y+X)/(W+H)))'
 
 @end itemize
 
+@section fftdnoiz
+Denoise frames using 3D FFT (frequency domain filtering).
+
+The filter accepts the following options:
+
+@table @option
+@item sigma
+Set the noise sigma constant. This sets denoising strength.
+Default value is 1. Allowed range is from 0 to 7.
+
+@item amount
+Set amount of denoising. By default all detected noise is removed.
+Default value is 1. Allowed range is from 0 to 1.
+
+@item block
+Set size of block, Default is 4, can be 4, 5 or 6.
+Actual size of block in pixels is 2 to power of @var{block}, so by default
+block size in pixels is 2^4 which is 16.
+
+@item overlap
+Set block overlap. Default is 0.5. Allowed range is from 0.2 to 0.8.
+
+@item prev
+Set number of previous frames to use for denoising. By default is set to 0.
+
+@item next
+Set number of next frames to to use for denoising. By default is set to 0.
+
+@item planes
+Set planes which will be filtered, by default are all available except alpha.
+@end table
+
 @section field
 
 Extract a single field from an interlaced image using stride
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index a416fa1fae..92f526a275 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -201,6 +201,7 @@ OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
 OBJS-$(CONFIG_EROSION_FILTER)+= vf_neighbor.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)  += vf_extractplanes.o
 OBJS-$(CONFIG_FADE_FILTER)   += vf_fade.o
+OBJS-$(CONFIG_FFTDNOIZ_FILTER)   += vf_fftdnoiz.o
 OBJS-$(CONFIG_FFTFILT_FILTER)+= vf_fftfilt.o
 OBJS-$(CONFIG_FIELD_FILTER)  += vf_field.o
 OBJS-$(CONFIG_FIELDHINT_FILTER)  += vf_fieldhint.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 42f956b3bf..f3a76c4652 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -193,6 +193,7 @@ extern AVFilter ff_vf_eq;
 extern AVFilter ff_vf_erosion;
 extern AVFilter ff_vf_extractplanes;
 extern AVFilter ff_vf_fade;
+extern AVFilter ff_vf_fftdnoiz;
 extern AVFilter ff_vf_fftfilt;
 extern AVFilter ff_vf_field;
 extern AVFilter ff_vf_fieldhint;
diff --git a/libavfilter/vf_fftdnoiz.c b/libavfilter/vf_fftdnoiz.c
new file mode 100644
index 00..272a37cd40
--- /dev/null
+++ b/libavfilter/vf_fftdnoiz.c
@@ -0,0 +1,691 @@
+/*
+ * 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/common.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "internal.h"
+#include "libavcodec/avfft.h"
+
+enum BufferTypes {
+CURRENT,
+PREV,
+NEXT,
+BSIZE
+};
+
+typedef struct PlaneContext {
+int planewidth, planeheight;
+int nox, noy;
+int b;
+int o;
+float n;
+
+float *buffer[BSIZE];
+FFTComplex *hdata, *vdata;
+int data_linesize;
+int buffer_linesize;
+
+FFTContext *fft, *ifft;
+} PlaneContext;
+
+typedef struct FFTdnoizContext {
+const AVClass *class;
+
+float sigma;
+float amount;
+int   block_bits;
+float overlap;
+int   nb_prev;
+int   nb_next;
+int   planesf;
+
+AVFrame *prev, *cur, *next;
+
+int depth;
+int nb_planes;
+PlaneContext planes[4];
+
+void (*import_row)(FFTComp

[FFmpeg-devel] [PATCH 5/6] avutil/hwcontext_cuda: explicitly synchronize cuMemcpy calls

2018-05-08 Thread Timo Rothenpieler
---
 libavutil/hwcontext_cuda.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 8024eec79d..7f55881ba5 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -267,13 +267,19 @@ static int cuda_transfer_data_from(AVHWFramesContext 
*ctx, AVFrame *dst,
 .Height= src->height >> (i ? priv->shift_height : 0),
 };
 
-err = cu->cuMemcpy2D(&cpy);
+err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
 if (err != CUDA_SUCCESS) {
 av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the 
CUDA frame\n");
 return AVERROR_UNKNOWN;
 }
 }
 
+err = cu->cuStreamSynchronize(device_hwctx->stream);
+if (err != CUDA_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+return AVERROR_UNKNOWN;
+}
+
 cu->cuCtxPopCurrent(&dummy);
 
 return 0;
@@ -306,13 +312,19 @@ static int cuda_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 .Height= src->height >> (i ? priv->shift_height : 0),
 };
 
-err = cu->cuMemcpy2D(&cpy);
+err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
 if (err != CUDA_SUCCESS) {
-av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the 
CUDA frame\n");
+av_log(ctx, AV_LOG_ERROR, "Error transferring the data to the CUDA 
frame\n");
 return AVERROR_UNKNOWN;
 }
 }
 
+err = cu->cuStreamSynchronize(device_hwctx->stream);
+if (err != CUDA_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+return AVERROR_UNKNOWN;
+}
+
 cu->cuCtxPopCurrent(&dummy);
 
 return 0;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 4/6] avcodec/nvdec: pass CUstream in vpp parameters

2018-05-08 Thread Timo Rothenpieler
---
 libavcodec/nvdec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index d98f9dd95e..c5c5c83dc7 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -39,6 +39,7 @@ typedef struct NVDECDecoder {
 
 AVBufferRef *hw_device_ref;
 CUcontextcuda_ctx;
+CUstream stream;
 
 CudaFunctions *cudl;
 CuvidFunctions *cvdl;
@@ -189,6 +190,7 @@ static int nvdec_decoder_create(AVBufferRef **out, 
AVBufferRef *hw_device_ref,
 }
 decoder->cuda_ctx = device_hwctx->cuda_ctx;
 decoder->cudl = device_hwctx->internal->cuda_dl;
+decoder->stream = device_hwctx->stream;
 
 ret = cuvid_load_functions(&decoder->cvdl, logctx);
 if (ret < 0) {
@@ -386,7 +388,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 NVDECFrame*cf = (NVDECFrame*)fdd->hwaccel_priv;
 NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
 
-CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
+CUVIDPROCPARAMS vpp = { 0 };
 NVDECFrame *unmap_data = NULL;
 
 CUresult err;
@@ -397,6 +399,9 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 unsigned int offset = 0;
 int ret = 0;
 
+vpp.progressive_frame = 1;
+vpp.output_stream = decoder->stream;
+
 err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
 if (err != CUDA_SUCCESS)
 return AVERROR_UNKNOWN;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/6] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags

2018-05-08 Thread Timo Rothenpieler
Frames can be mapped from nvdec/cuvid, not needing any actual memory
allocation, but all other features of the hw_frames_ctx.
Hence the dummy-mode, which does not allocate any (notable amounts of)
memory but otherwise behaves the exact same.
---
 doc/APIchanges |  3 +++
 libavutil/hwcontext_cuda.c | 12 +++-
 libavutil/hwcontext_cuda.h | 22 +-
 libavutil/version.h|  2 +-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index ede5b186ae..f8ae6b0433 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h
+  Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
+
 2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
 
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 37827a770c..b0b4bf24ae 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -161,6 +161,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
 
 static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
 {
+AVCUDAFramesContext *frctx = ctx->hwctx;
 int aligned_width;
 int width_in_bytes = ctx->width;
 
@@ -171,7 +172,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame 
*frame)
 }
 aligned_width = FFALIGN(width_in_bytes, CUDA_FRAME_ALIGNMENT);
 
-frame->buf[0] = av_buffer_pool_get(ctx->pool);
+if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
+frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0);
+else
+frame->buf[0] = av_buffer_pool_get(ctx->pool);
+
 if (!frame->buf[0])
 return AVERROR(ENOMEM);
 
@@ -210,6 +215,10 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame 
*frame)
 frame->width  = ctx->width;
 frame->height = ctx->height;
 
+// they're pointing to invalid memory, dangerous to leave set
+if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
+frame->data[0] = frame->data[1] = frame->data[2] = NULL;
+
 return 0;
 }
 
@@ -402,6 +411,7 @@ const HWContextType ff_hwcontext_type_cuda = {
 .name = "CUDA",
 
 .device_hwctx_size= sizeof(AVCUDADeviceContext),
+.frames_hwctx_size= sizeof(AVCUDAFramesContext),
 .frames_priv_size = sizeof(CUDAFramesContext),
 
 .device_create= cuda_device_create,
diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index 12dae8449e..19accbd9be 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -45,7 +45,27 @@ typedef struct AVCUDADeviceContext {
 } AVCUDADeviceContext;
 
 /**
- * AVHWFramesContext.hwctx is currently not used
+ * This struct is allocated as AVHWFramesContext.hwctx
  */
+typedef struct AVCUDAFramesContext {
+/**
+ * Special implementation-specific flags.
+ *
+ * May be set by the user before calling av_hwframe_ctx_init().
+ */
+int flags;
+} AVCUDAFramesContext;
+
+/**
+ * No actual allocation will happen, but otherwise behaves like normal.
+ *
+ * This is to be used if a AVHWFramesContext is required, but the actual
+ * allocation is happening outside of it.
+ *
+ * The resulting AVFrames will be identical to normal frames, except for
+ * their data[] pointers being NULL and the AVBufferRef in buf[0] being
+ * set but containing no notable allocation of memory.
+ */
+#define AV_CUDA_HWFRAMES_DUMMY_MODE (1 << 0)
 
 #endif /* AVUTIL_HWCONTEXT_CUDA_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 5185454d9b..84409b1d69 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  18
+#define LIBAVUTIL_VERSION_MINOR  19
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 6/6] avcodec/cuviddec: explicitly synchronize cuMemcpy calls

2018-05-08 Thread Timo Rothenpieler
---
 libavcodec/cuviddec.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 122c28f6e8..4d3caf924e 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -550,12 +550,16 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 .Height= avctx->height >> (i ? 1 : 0),
 };
 
-ret = CHECK_CU(ctx->cudl->cuMemcpy2D(&cpy));
+ret = CHECK_CU(ctx->cudl->cuMemcpy2DAsync(&cpy, 
device_hwctx->stream));
 if (ret < 0)
 goto error;
 
 offset += avctx->height;
 }
+
+ret = 
CHECK_CU(ctx->cudl->cuStreamSynchronize(device_hwctx->stream));
+if (ret < 0)
+goto error;
 } else if (avctx->pix_fmt == AV_PIX_FMT_NV12 ||
avctx->pix_fmt == AV_PIX_FMT_P010 ||
avctx->pix_fmt == AV_PIX_FMT_P016) {
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 2/6] avcodec/nvdec: avoid needless copy of output frame

2018-05-08 Thread Timo Rothenpieler
Replaces the data pointers with the mapped cuvid ones.
Adds buffer_refs to the frame to ensure the needed contexts stay alive
and the cuvid idx stays allocated.
Adds another buffer_ref to unmap the frame when it's unreferenced itself.
---
 libavcodec/nvdec.c | 83 +-
 1 file changed, 60 insertions(+), 23 deletions(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index ab3cb88b27..d98f9dd95e 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -308,7 +308,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 params.CodecType   = cuvid_codec_type;
 params.ChromaFormat= cuvid_chroma_format;
 params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
-params.ulNumOutputSurfaces = 1;
+params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
 
 ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, 
¶ms, avctx);
 if (ret < 0) {
@@ -354,6 +354,32 @@ static void nvdec_fdd_priv_free(void *priv)
 av_freep(&priv);
 }
 
+static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
+{
+NVDECFrame *unmap_data = (NVDECFrame*)data;
+NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
+CUdeviceptr devptr = (CUdeviceptr)opaque;
+CUresult err;
+CUcontext dummy;
+
+err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
+if (err != CUDA_SUCCESS) {
+av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
+goto finish;
+}
+
+err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (err != CUDA_SUCCESS)
+av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
+
+decoder->cudl->cuCtxPopCurrent(&dummy);
+
+finish:
+av_buffer_unref(&unmap_data->idx_ref);
+av_buffer_unref(&unmap_data->decoder_ref);
+av_free(unmap_data);
+}
+
 static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 {
 FrameDecodeData  *fdd = (FrameDecodeData*)frame->private_ref->data;
@@ -361,6 +387,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
 
 CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
+NVDECFrame *unmap_data = NULL;
 
 CUresult err;
 CUcontext dummy;
@@ -383,32 +410,39 @@ static int nvdec_retrieve_data(void *logctx, AVFrame 
*frame)
 goto finish;
 }
 
-for (i = 0; frame->data[i]; i++) {
-CUDA_MEMCPY2D cpy = {
-.srcMemoryType = CU_MEMORYTYPE_DEVICE,
-.dstMemoryType = CU_MEMORYTYPE_DEVICE,
-.srcDevice = devptr,
-.dstDevice = (CUdeviceptr)frame->data[i],
-.srcPitch  = pitch,
-.dstPitch  = frame->linesize[i],
-.srcY  = offset,
-.WidthInBytes  = FFMIN(pitch, frame->linesize[i]),
-.Height= frame->height >> (i ? 1 : 0),
-};
-
-err = decoder->cudl->cuMemcpy2D(&cpy);
-if (err != CUDA_SUCCESS) {
-av_log(logctx, AV_LOG_ERROR, "Error copying decoded frame: %d\n",
-   err);
-ret = AVERROR_UNKNOWN;
-goto copy_fail;
-}
+unmap_data = av_mallocz(sizeof(*unmap_data));
+if (!unmap_data) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
+}
 
-offset += cpy.Height;
+frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, 
sizeof(*unmap_data),
+ nvdec_unmap_mapped_frame, (void*)devptr,
+ AV_BUFFER_FLAG_READONLY);
+if (!frame->buf[1]) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
 }
 
+unmap_data->idx = cf->idx;
+unmap_data->idx_ref = av_buffer_ref(cf->idx_ref);
+unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref);
+
+for (i = 0; frame->linesize[i]; i++) {
+frame->data[i] = (uint8_t*)(devptr + offset);
+frame->linesize[i] = pitch;
+offset += pitch * (frame->height >> (i ? 1 : 0));
+}
+
+goto finish;
+
 copy_fail:
-decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (!frame->buf[1]) {
+decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+av_freep(&unmap_data);
+} else {
+av_buffer_unref(&frame->buf[1]);
+}
 
 finish:
 decoder->cudl->cuCtxPopCurrent(&dummy);
@@ -526,6 +560,7 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
   int dpb_size)
 {
 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
+AVCUDAFramesContext *hwctx = (AVCUDAFramesContext*)frames_ctx->hwctx;
 const AVPixFmtDescriptor *sw_desc;
 int cuvid_codec_type, cuvid_chroma_format;
 
@@ -550,6 +585,8 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
 frames_ctx->height= (avctx->coded_height + 1) & ~1;
 frames_ctx->initial_pool_size = dpb_size;
 
+hwctx->flags = AV_CUDA_HWFRAMES_DUMMY_M

[FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread Timo Rothenpieler
---
 configure  | 6 --
 doc/APIchanges | 3 ++-
 libavutil/hwcontext_cuda.c | 3 +++
 libavutil/hwcontext_cuda.h | 1 +
 libavutil/version.h| 2 +-
 5 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 7c143238a8..cae8a235a4 100755
--- a/configure
+++ b/configure
@@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
"VAEncPictureParameterBufferVP9"
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 
 if ! disabled ffnvcodec; then
-check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
-"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
+check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
+{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
 fi
 
 check_cpp_condition winrt windows.h 
"!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
diff --git a/doc/APIchanges b/doc/APIchanges
index f8ae6b0433..7a0a8522f9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,8 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
-2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h
+2018-05-xx - xx, xx - lavu 56.19.100/101 - hwcontext_cuda.h
   Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
+  Add AVCUDADeviceContext.stream.
 
 2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index b0b4bf24ae..8024eec79d 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -395,6 +395,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, const 
char *device,
 goto error;
 }
 
+// Setting stream to NULL will make functions automatically use the 
default CUstream
+hwctx->stream = NULL;
+
 cu->cuCtxPopCurrent(&dummy);
 
 hwctx->internal->is_allocated = 1;
diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index 19accbd9be..cd797ae920 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
AVCUDADeviceContextInternal;
  */
 typedef struct AVCUDADeviceContext {
 CUcontext cuda_ctx;
+CUstream stream;
 AVCUDADeviceContextInternal *internal;
 } AVCUDADeviceContext;
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 84409b1d69..f84ec89154 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  56
 #define LIBAVUTIL_VERSION_MINOR  19
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.17.0

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


Re: [FFmpeg-devel] [FFmpeg-devel, RFC] lavfi: add opencl tonemap filter.

2018-05-08 Thread Niklas Haas
Hello Ruiling,

> Thanks for sharing your idea with me. I basically also noticed some poor 
> quality tone mapping result for some hdr stream.
> I will try your suggestion to see whether I can make it in good state so I 
> can include it in next version.
> In fact I have not thought detecting scene change quite well. A question for 
> your idea is:
> is it possible that your scene detection heuristic may still failed to detect 
> some particular scene change and lead to poor tone mapping quality?

The way my scene change detection heuristic works like this: I trigger a
scene change (and therefore discard the frame averaging buffer) if the
distance between the current frame average brightness and the current
running average exceeds a threshold value, that threshold being (by
default) 20 cd/m².

So we can divide the failures of this algorithm into two categories:

1. False negative (scene change without resetting the buffer): This can
   only happen if there was an actual scene change but the average
   brightness change did not exceed 20 cd/m², i.e. the scenes are
   similar in brightness. I consider this a fairly harmful failure
   because that also means there's no visual discontinuity since the
   scenes are so similar to begin with.

2. False positive (buffer got reset without a scene change). This is the
   more worrying failure of the algorithm, since it can happen in the
   middle of a scene (e.g. as the result of a bright flash of light
   on-screen), which will manifest itself as a sudden decrease in the
   total frame brightness coinciding with the new source of light. (Or
   vice versa, a sudden increase in brightness coinciding with the
   sudden absence of a light source).

The scene change threshold is a trade-off. Lowering the value decreases
the likelihood of #1 but increases the likelihood of #2. Increasing the
value decreases the likelihood of #2, but increases the likelihood (and
apparent effect) of #1.

If you want to optimize or improve the algorithm, the case #2 is the one
I would be most interested in, i.e. reducing the rate of false
positives. This can surely be done in a smarter way, e.g. by comparing
more than just the scene average but also other easily obtained metrics.

If you have access to low-level frame information, you could do
something like increasing the threshold for non-keyframes significantly,
since keyframes are likely to coincide with scene changes or cuts this
might help the algorithm out.

> I just copy this piece of code from vf_tonemap.c. I think we need to fix it 
> there first if this is wrong.
> I guess the code was like this because we think that all video stream that 
> truly use ST. 2084 should
> Include the mastering display metadata, if it is absent, then transfer 
> function should be arib-std-b67.

Yeah, good point. And ideally, maybe those two should share this logic
to avoid code duplication.

> Basically I am targeting full gpu pipeline transcoding(gpu decoding + gpu 
> filtering + gpu encoding),
> Most video streams I have encountered are YUV stream.
> Could you show me what kind of use-case that need RGB support?
> So I will try to see whether adding it in this patch or do it later.

One particular use case I have in mind that would be good to support is
OpenEXR formats, which are typically RGB and high depth or floating point.

> In fact, I have not learned about HLG deeply. I still need some time to add 
> HLG support.

Well the one key thing that's interesting about HLG is that the OOTF
(which forms part of the EOTF) is parametrized by the peak brightness of
the display. So when tone mapping (which is done in display-referred
space) a HLG signal to a lower brightness, the inverse OOTF you need to
apply to go back to HLG afterwards needs to be done on the new peak
brightness, to reflect the changes made to the signal. As said I'm not
sure which component handles the OOTF in FFmpeg land, so if you
implement it yourself (which may be a necessary) that would be a thing
to keep in mind.

> Well, this is very useful reference for me. I need some time to digest it.
> Thanks a lot.

No problem,
Niklas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Revert "configure: check that the required header for Linux Perf is available"

2018-05-08 Thread Clément Bœsch
This reverts commit 234a5e08313c6b8b0774796dfa1f285a3f877d14.

Linux perf is not enabled if you set --target=android, which you are
supposed to when building for Android.
---
 configure | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/configure b/configure
index 7c143238a8..bdca93a9ee 100755
--- a/configure
+++ b/configure
@@ -2018,7 +2018,6 @@ HEADERS_LIST="
 ES2_gl_h
 gsm_h
 io_h
-linux_perf_event_h
 machine_ioctl_bt848_h
 machine_ioctl_meteor_h
 malloc_h
@@ -2483,7 +2482,6 @@ simd_align_32_if_any="avx"
 simd_align_64_if_any="avx512"
 
 # system capabilities
-linux_perf_deps="linux_perf_event_h"
 symver_if_any="symver_asm_label symver_gnu_asm"
 valgrind_backtrace_conflict="optimizations"
 valgrind_backtrace_deps="valgrind_valgrind_h"
@@ -5811,7 +5809,6 @@ check_header dxgidebug.h
 check_header dxva.h
 check_header dxva2api.h -D_WIN32_WINNT=0x0600
 check_header io.h
-check_header linux/perf_event.h
 check_header libcrystalhd/libcrystalhd_if.h
 check_header malloc.h
 check_header net/udplite.h
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH] Revert "configure: check that the required header for Linux Perf is available"

2018-05-08 Thread James Almer
On 5/8/2018 12:21 PM, Clément Bœsch wrote:
> This reverts commit 234a5e08313c6b8b0774796dfa1f285a3f877d14.
> 
> Linux perf is not enabled if you set --target=android, which you are

Isn't it --target-os=android?

> supposed to when building for Android.
> ---
>  configure | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 7c143238a8..bdca93a9ee 100755
> --- a/configure
> +++ b/configure
> @@ -2018,7 +2018,6 @@ HEADERS_LIST="
>  ES2_gl_h
>  gsm_h
>  io_h
> -linux_perf_event_h
>  machine_ioctl_bt848_h
>  machine_ioctl_meteor_h
>  malloc_h
> @@ -2483,7 +2482,6 @@ simd_align_32_if_any="avx"
>  simd_align_64_if_any="avx512"
>  
>  # system capabilities
> -linux_perf_deps="linux_perf_event_h"
>  symver_if_any="symver_asm_label symver_gnu_asm"
>  valgrind_backtrace_conflict="optimizations"
>  valgrind_backtrace_deps="valgrind_valgrind_h"
> @@ -5811,7 +5809,6 @@ check_header dxgidebug.h
>  check_header dxva.h
>  check_header dxva2api.h -D_WIN32_WINNT=0x0600
>  check_header io.h
> -check_header linux/perf_event.h
>  check_header libcrystalhd/libcrystalhd_if.h
>  check_header malloc.h
>  check_header net/udplite.h
> 

Assuming this is mentioned in the documentation (Our only Android fate
client doesn't set this for example, which prompted this "fix", but it
might have been an honest mistake) then this LGTM. Otherwise it
definitely needs a mention somewhere.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/6] avcodec/nvdec: avoid needless copy of output frame

2018-05-08 Thread wm4
On Tue,  8 May 2018 15:31:28 +0200
Timo Rothenpieler  wrote:

> Replaces the data pointers with the mapped cuvid ones.
> Adds buffer_refs to the frame to ensure the needed contexts stay alive
> and the cuvid idx stays allocated.
> Adds another buffer_ref to unmap the frame when it's unreferenced itself.
> ---
>  libavcodec/nvdec.c | 83 +-
>  1 file changed, 60 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
> index ab3cb88b27..d98f9dd95e 100644
> --- a/libavcodec/nvdec.c
> +++ b/libavcodec/nvdec.c
> @@ -308,7 +308,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
>  params.CodecType   = cuvid_codec_type;
>  params.ChromaFormat= cuvid_chroma_format;
>  params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
> -params.ulNumOutputSurfaces = 1;
> +params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
>  
>  ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, 
> ¶ms, avctx);
>  if (ret < 0) {
> @@ -354,6 +354,32 @@ static void nvdec_fdd_priv_free(void *priv)
>  av_freep(&priv);
>  }
>  
> +static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
> +{
> +NVDECFrame *unmap_data = (NVDECFrame*)data;
> +NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
> +CUdeviceptr devptr = (CUdeviceptr)opaque;
> +CUresult err;
> +CUcontext dummy;
> +
> +err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
> +if (err != CUDA_SUCCESS) {
> +av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
> +goto finish;
> +}
> +
> +err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
> +if (err != CUDA_SUCCESS)
> +av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
> +
> +decoder->cudl->cuCtxPopCurrent(&dummy);
> +
> +finish:
> +av_buffer_unref(&unmap_data->idx_ref);
> +av_buffer_unref(&unmap_data->decoder_ref);
> +av_free(unmap_data);
> +}
> +
>  static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
>  {
>  FrameDecodeData  *fdd = (FrameDecodeData*)frame->private_ref->data;
> @@ -361,6 +387,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame 
> *frame)
>  NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
>  
>  CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
> +NVDECFrame *unmap_data = NULL;
>  
>  CUresult err;
>  CUcontext dummy;
> @@ -383,32 +410,39 @@ static int nvdec_retrieve_data(void *logctx, AVFrame 
> *frame)
>  goto finish;
>  }
>  
> -for (i = 0; frame->data[i]; i++) {
> -CUDA_MEMCPY2D cpy = {
> -.srcMemoryType = CU_MEMORYTYPE_DEVICE,
> -.dstMemoryType = CU_MEMORYTYPE_DEVICE,
> -.srcDevice = devptr,
> -.dstDevice = (CUdeviceptr)frame->data[i],
> -.srcPitch  = pitch,
> -.dstPitch  = frame->linesize[i],
> -.srcY  = offset,
> -.WidthInBytes  = FFMIN(pitch, frame->linesize[i]),
> -.Height= frame->height >> (i ? 1 : 0),
> -};
> -
> -err = decoder->cudl->cuMemcpy2D(&cpy);
> -if (err != CUDA_SUCCESS) {
> -av_log(logctx, AV_LOG_ERROR, "Error copying decoded frame: %d\n",
> -   err);
> -ret = AVERROR_UNKNOWN;
> -goto copy_fail;
> -}
> +unmap_data = av_mallocz(sizeof(*unmap_data));
> +if (!unmap_data) {
> +ret = AVERROR(ENOMEM);
> +goto copy_fail;
> +}
>  
> -offset += cpy.Height;
> +frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, 
> sizeof(*unmap_data),
> + nvdec_unmap_mapped_frame, (void*)devptr,
> + AV_BUFFER_FLAG_READONLY);
> +if (!frame->buf[1]) {
> +ret = AVERROR(ENOMEM);
> +goto copy_fail;
>  }
>  
> +unmap_data->idx = cf->idx;
> +unmap_data->idx_ref = av_buffer_ref(cf->idx_ref);
> +unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref);
> +
> +for (i = 0; frame->linesize[i]; i++) {
> +frame->data[i] = (uint8_t*)(devptr + offset);
> +frame->linesize[i] = pitch;
> +offset += pitch * (frame->height >> (i ? 1 : 0));
> +}
> +
> +goto finish;
> +
>  copy_fail:
> -decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
> +if (!frame->buf[1]) {
> +decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
> +av_freep(&unmap_data);
> +} else {
> +av_buffer_unref(&frame->buf[1]);
> +}
>  
>  finish:
>  decoder->cudl->cuCtxPopCurrent(&dummy);
> @@ -526,6 +560,7 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
>int dpb_size)
>  {
>  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
> +AVCUDAFramesContext *hwctx = (AVCUDAFramesContext*)frames_ctx-

Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags

2018-05-08 Thread wm4
On Mon,  7 May 2018 23:46:48 +0200
Timo Rothenpieler  wrote:

> Frames can be mapped from nvdec/cuvid, not needing any actual memory
> allocation, but all other features of the hw_frames_ctx.
> Hence the dummy-mode, which does not allocate any (notable amounts of)
> memory but otherwise behaves the exact same.
> ---
>  doc/APIchanges |  3 +++
>  libavutil/hwcontext_cuda.c | 12 +++-
>  libavutil/hwcontext_cuda.h | 22 +-
>  libavutil/version.h|  2 +-
>  4 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ede5b186ae..82ec888fd8 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2018-05-xx - xx - lavu 56.19.100 - hwcontext.h
> +  Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
> +
>  2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
>Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
>  
> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> index 37827a770c..b0b4bf24ae 100644
> --- a/libavutil/hwcontext_cuda.c
> +++ b/libavutil/hwcontext_cuda.c
> @@ -161,6 +161,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
>  
>  static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
>  {
> +AVCUDAFramesContext *frctx = ctx->hwctx;
>  int aligned_width;
>  int width_in_bytes = ctx->width;
>  
> @@ -171,7 +172,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, 
> AVFrame *frame)
>  }
>  aligned_width = FFALIGN(width_in_bytes, CUDA_FRAME_ALIGNMENT);
>  
> -frame->buf[0] = av_buffer_pool_get(ctx->pool);
> +if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
> +frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0);
> +else
> +frame->buf[0] = av_buffer_pool_get(ctx->pool);
> +

Is this really needed? Because at least videotoolbox also lets the
decoder allocate frames, and allocates the "dummy" buffers outside of
the hwcontext. (I don't quite remember how it works.)

>  if (!frame->buf[0])
>  return AVERROR(ENOMEM);
>  
> @@ -210,6 +215,10 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, 
> AVFrame *frame)
>  frame->width  = ctx->width;
>  frame->height = ctx->height;
>  
> +// they're pointing to invalid memory, dangerous to leave set
> +if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
> +frame->data[0] = frame->data[1] = frame->data[2] = NULL;
> +
>  return 0;
>  }
>  
> @@ -402,6 +411,7 @@ const HWContextType ff_hwcontext_type_cuda = {
>  .name = "CUDA",
>  
>  .device_hwctx_size= sizeof(AVCUDADeviceContext),
> +.frames_hwctx_size= sizeof(AVCUDAFramesContext),
>  .frames_priv_size = sizeof(CUDAFramesContext),
>  
>  .device_create= cuda_device_create,
> diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
> index 12dae8449e..19accbd9be 100644
> --- a/libavutil/hwcontext_cuda.h
> +++ b/libavutil/hwcontext_cuda.h
> @@ -45,7 +45,27 @@ typedef struct AVCUDADeviceContext {
>  } AVCUDADeviceContext;
>  
>  /**
> - * AVHWFramesContext.hwctx is currently not used
> + * This struct is allocated as AVHWFramesContext.hwctx
>   */
> +typedef struct AVCUDAFramesContext {
> +/**
> + * Special implementation-specific flags.
> + *
> + * May be set by the user before calling av_hwframe_ctx_init().
> + */
> +int flags;
> +} AVCUDAFramesContext;
> +
> +/**
> + * No actual allocation will happen, but otherwise behaves like normal.
> + *
> + * This is to be used if a AVHWFramesContext is required, but the actual
> + * allocation is happening outside of it.
> + *
> + * The resulting AVFrames will be identical to normal frames, except for
> + * their data[] pointers being NULL and the AVBufferRef in buf[0] being
> + * set but containing no notable allocation of memory.
> + */
> +#define AV_CUDA_HWFRAMES_DUMMY_MODE (1 << 0)
>  
>  #endif /* AVUTIL_HWCONTEXT_CUDA_H */
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 5185454d9b..84409b1d69 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  56
> -#define LIBAVUTIL_VERSION_MINOR  18
> +#define LIBAVUTIL_VERSION_MINOR  19
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

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


Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread wm4
On Tue,  8 May 2018 15:31:29 +0200
Timo Rothenpieler  wrote:

> ---
>  configure  | 6 --
>  doc/APIchanges | 3 ++-
>  libavutil/hwcontext_cuda.c | 3 +++
>  libavutil/hwcontext_cuda.h | 1 +
>  libavutil/version.h| 2 +-
>  5 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/configure b/configure
> index 7c143238a8..cae8a235a4 100755
> --- a/configure
> +++ b/configure
> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
> "VAEncPictureParameterBufferVP9"
>  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>  
>  if ! disabled ffnvcodec; then
> -check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
> -"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
> +check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
> +{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
> check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
>  fi
>  
>  check_cpp_condition winrt windows.h 
> "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
> diff --git a/doc/APIchanges b/doc/APIchanges
> index f8ae6b0433..7a0a8522f9 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,8 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> -2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h
> +2018-05-xx - xx, xx - lavu 56.19.100/101 - hwcontext_cuda.h
>Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
> +  Add AVCUDADeviceContext.stream.
>  
>  2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
>Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> index b0b4bf24ae..8024eec79d 100644
> --- a/libavutil/hwcontext_cuda.c
> +++ b/libavutil/hwcontext_cuda.c
> @@ -395,6 +395,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, 
> const char *device,
>  goto error;
>  }
>  
> +// Setting stream to NULL will make functions automatically use the 
> default CUstream
> +hwctx->stream = NULL;
> +
>  cu->cuCtxPopCurrent(&dummy);
>  
>  hwctx->internal->is_allocated = 1;
> diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
> index 19accbd9be..cd797ae920 100644
> --- a/libavutil/hwcontext_cuda.h
> +++ b/libavutil/hwcontext_cuda.h
> @@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
> AVCUDADeviceContextInternal;
>   */
>  typedef struct AVCUDADeviceContext {
>  CUcontext cuda_ctx;
> +CUstream stream;
>  AVCUDADeviceContextInternal *internal;
>  } AVCUDADeviceContext;
>  
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 84409b1d69..f84ec89154 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -80,7 +80,7 @@
>  
>  #define LIBAVUTIL_VERSION_MAJOR  56
>  #define LIBAVUTIL_VERSION_MINOR  19
> -#define LIBAVUTIL_VERSION_MICRO 100
> +#define LIBAVUTIL_VERSION_MICRO 101
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> LIBAVUTIL_VERSION_MINOR, \

What is this?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/vf_srcnn: use avio_check instead of access

2018-05-08 Thread Hendrik Leppkes
The filter uses avio for file access already, and avio_check is
portable.

Fixes trac #7192.
---
 libavfilter/vf_srcnn.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
index dace2b99b5..edffebb278 100644
--- a/libavfilter/vf_srcnn.c
+++ b/libavfilter/vf_srcnn.c
@@ -28,9 +28,6 @@
 #include "formats.h"
 #include "internal.h"
 #include "libavutil/opt.h"
-#if HAVE_UNISTD_H
-#include 
-#endif
 #include "vf_srcnn.h"
 #include "libavformat/avio.h"
 
@@ -145,7 +142,7 @@ static av_cold int init(AVFilterContext* context)
 srcnn_context->conv3.size = 5;
 CHECK_ALLOCATION(allocate_copy_conv_data(&srcnn_context->conv3, 
conv3_kernel, conv3_biases), )
 }
-else if (access(srcnn_context->config_file_path, R_OK) != -1){
+else if (avio_check(srcnn_context->config_file_path, AVIO_FLAG_READ) > 0){
 if (avio_open(&config_file_context, srcnn_context->config_file_path, 
AVIO_FLAG_READ) < 0){
 av_log(context, AV_LOG_ERROR, "failed to open configuration 
file\n");
 return AVERROR(EIO);
-- 
2.17.0.windows.1

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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags

2018-05-08 Thread Timo Rothenpieler

-frame->buf[0] = av_buffer_pool_get(ctx->pool);
+if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
+frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0);
+else
+frame->buf[0] = av_buffer_pool_get(ctx->pool);
+


Is this really needed? Because at least videotoolbox also lets the
decoder allocate frames, and allocates the "dummy" buffers outside of
the hwcontext. (I don't quite remember how it works.)


You mean compared to just leaving buf[0] empty?



smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavfi/vf_srcnn: use avio_check instead of access

2018-05-08 Thread James Almer
On 5/8/2018 12:27 PM, Hendrik Leppkes wrote:
> The filter uses avio for file access already, and avio_check is
> portable.
> 
> Fixes trac #7192.

Remove the access dep in configure while at it.

LGTM is confirmed working.

> ---
>  libavfilter/vf_srcnn.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
> index dace2b99b5..edffebb278 100644
> --- a/libavfilter/vf_srcnn.c
> +++ b/libavfilter/vf_srcnn.c
> @@ -28,9 +28,6 @@
>  #include "formats.h"
>  #include "internal.h"
>  #include "libavutil/opt.h"
> -#if HAVE_UNISTD_H
> -#include 
> -#endif
>  #include "vf_srcnn.h"
>  #include "libavformat/avio.h"
>  
> @@ -145,7 +142,7 @@ static av_cold int init(AVFilterContext* context)
>  srcnn_context->conv3.size = 5;
>  CHECK_ALLOCATION(allocate_copy_conv_data(&srcnn_context->conv3, 
> conv3_kernel, conv3_biases), )
>  }
> -else if (access(srcnn_context->config_file_path, R_OK) != -1){
> +else if (avio_check(srcnn_context->config_file_path, AVIO_FLAG_READ) > 
> 0){
>  if (avio_open(&config_file_context, srcnn_context->config_file_path, 
> AVIO_FLAG_READ) < 0){
>  av_log(context, AV_LOG_ERROR, "failed to open configuration 
> file\n");
>  return AVERROR(EIO);
> 

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


Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread Timo Rothenpieler



Am 08.05.2018 um 17:26 schrieb wm4:

On Tue,  8 May 2018 15:31:29 +0200
Timo Rothenpieler  wrote:


---
  configure  | 6 --
  doc/APIchanges | 3 ++-
  libavutil/hwcontext_cuda.c | 3 +++
  libavutil/hwcontext_cuda.h | 1 +
  libavutil/version.h| 2 +-
  5 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 7c143238a8..cae8a235a4 100755
--- a/configure
+++ b/configure
@@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
"VAEncPictureParameterBufferVP9"
  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
  
  if ! disabled ffnvcodec; then

-check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
-"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h 
ffnvcodec/dynlink_nvcuvid.h" ""
+check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h 
ffnvcodec/dynlink_nvcuvid.h" "" || \
+{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config 
ffnvcodec "ffnvcodec >= 8.0.14.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h 
ffnvcodec/dynlink_nvcuvid.h" ""; }
  fi
  
  check_cpp_condition winrt windows.h "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"

diff --git a/doc/APIchanges b/doc/APIchanges
index f8ae6b0433..7a0a8522f9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,8 +15,9 @@ libavutil: 2017-10-21
  
  API changes, most recent first:
  
-2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h

+2018-05-xx - xx, xx - lavu 56.19.100/101 - hwcontext_cuda.h
Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
+  Add AVCUDADeviceContext.stream.
  
  2018-04-xx - xx - lavu 56.18.100 - pixdesc.h

Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index b0b4bf24ae..8024eec79d 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -395,6 +395,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, const 
char *device,
  goto error;
  }
  
+// Setting stream to NULL will make functions automatically use the default CUstream

+hwctx->stream = NULL;
+
  cu->cuCtxPopCurrent(&dummy);
  
  hwctx->internal->is_allocated = 1;

diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index 19accbd9be..cd797ae920 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
AVCUDADeviceContextInternal;
   */
  typedef struct AVCUDADeviceContext {
  CUcontext cuda_ctx;
+CUstream stream;
  AVCUDADeviceContextInternal *internal;
  } AVCUDADeviceContext;
  
diff --git a/libavutil/version.h b/libavutil/version.h

index 84409b1d69..f84ec89154 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
  
  #define LIBAVUTIL_VERSION_MAJOR  56

  #define LIBAVUTIL_VERSION_MINOR  19
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
  
  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

 LIBAVUTIL_VERSION_MINOR, \


What is this?


https://docs.nvidia.com/cuda/cuda-driver-api/stream-sync-behavior.html

It allows asynchronous processing of CUDA workloads. The next couple 
patches make use of it.
There's no change in behaviour if it remains unset/NULL, but if you set 
one, the workload won't block the main CUDA stream so you can do 
multiple transcode sessions in the same application without blocking one 
another.




smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 02/13] avformat/mxfenc: Bump minor versions for S377-1-2009

2018-05-08 Thread Michael Niedermayer
On Mon, May 07, 2018 at 06:27:37PM +0200, Carl Eugen Hoyos wrote:
> 2018-05-07 12:38 GMT+02:00, Michael Niedermayer :
> 
> > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > index c0db10b3c2..00dfce977b 100644
> > --- a/libavformat/mxfenc.c
> > +++ b/libavformat/mxfenc.c
> > @@ -691,7 +691,7 @@ static void mxf_write_preface(AVFormatContext *s)
> >
> >  // write version
> >  mxf_write_local_tag(pb, 2, 0x3B05);
> > -avio_wb16(pb, 258); // v1.2
> > +avio_wb16(pb, 259); // v1.2
> 
> I find it surprising that the comment doesn't change here.

will fix and apply

thx

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

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.


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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags

2018-05-08 Thread wm4
On Tue, 8 May 2018 17:43:49 +0200
Timo Rothenpieler  wrote:

> >> -frame->buf[0] = av_buffer_pool_get(ctx->pool);
> >> +if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
> >> +frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0);
> >> +else
> >> +frame->buf[0] = av_buffer_pool_get(ctx->pool);
> >> +  
> > 
> > Is this really needed? Because at least videotoolbox also lets the
> > decoder allocate frames, and allocates the "dummy" buffers outside of
> > the hwcontext. (I don't quite remember how it works.)  
> 
> You mean compared to just leaving buf[0] empty?
> 

No, compared to how the videotoolbox code does things.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/6] avcodec/nvdec: avoid needless copy of output frame

2018-05-08 Thread Timo Rothenpieler

Am 08.05.2018 um 17:25 schrieb wm4:

On Tue,  8 May 2018 15:31:28 +0200
Timo Rothenpieler  wrote:


Replaces the data pointers with the mapped cuvid ones.
Adds buffer_refs to the frame to ensure the needed contexts stay alive
and the cuvid idx stays allocated.
Adds another buffer_ref to unmap the frame when it's unreferenced itself.
---
  libavcodec/nvdec.c | 83 +-
  1 file changed, 60 insertions(+), 23 deletions(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index ab3cb88b27..d98f9dd95e 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -308,7 +308,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
  params.CodecType   = cuvid_codec_type;
  params.ChromaFormat= cuvid_chroma_format;
  params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
-params.ulNumOutputSurfaces = 1;
+params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
  
  ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, ¶ms, avctx);

  if (ret < 0) {
@@ -354,6 +354,32 @@ static void nvdec_fdd_priv_free(void *priv)
  av_freep(&priv);
  }
  
+static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)

+{
+NVDECFrame *unmap_data = (NVDECFrame*)data;
+NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
+CUdeviceptr devptr = (CUdeviceptr)opaque;
+CUresult err;
+CUcontext dummy;
+
+err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
+if (err != CUDA_SUCCESS) {
+av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
+goto finish;
+}
+
+err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (err != CUDA_SUCCESS)
+av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
+
+decoder->cudl->cuCtxPopCurrent(&dummy);
+
+finish:
+av_buffer_unref(&unmap_data->idx_ref);
+av_buffer_unref(&unmap_data->decoder_ref);
+av_free(unmap_data);
+}
+
  static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
  {
  FrameDecodeData  *fdd = (FrameDecodeData*)frame->private_ref->data;
@@ -361,6 +387,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
  NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
  
  CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };

+NVDECFrame *unmap_data = NULL;
  
  CUresult err;

  CUcontext dummy;
@@ -383,32 +410,39 @@ static int nvdec_retrieve_data(void *logctx, AVFrame 
*frame)
  goto finish;
  }
  
-for (i = 0; frame->data[i]; i++) {

-CUDA_MEMCPY2D cpy = {
-.srcMemoryType = CU_MEMORYTYPE_DEVICE,
-.dstMemoryType = CU_MEMORYTYPE_DEVICE,
-.srcDevice = devptr,
-.dstDevice = (CUdeviceptr)frame->data[i],
-.srcPitch  = pitch,
-.dstPitch  = frame->linesize[i],
-.srcY  = offset,
-.WidthInBytes  = FFMIN(pitch, frame->linesize[i]),
-.Height= frame->height >> (i ? 1 : 0),
-};
-
-err = decoder->cudl->cuMemcpy2D(&cpy);
-if (err != CUDA_SUCCESS) {
-av_log(logctx, AV_LOG_ERROR, "Error copying decoded frame: %d\n",
-   err);
-ret = AVERROR_UNKNOWN;
-goto copy_fail;
-}
+unmap_data = av_mallocz(sizeof(*unmap_data));
+if (!unmap_data) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
+}
  
-offset += cpy.Height;

+frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, 
sizeof(*unmap_data),
+ nvdec_unmap_mapped_frame, (void*)devptr,
+ AV_BUFFER_FLAG_READONLY);
+if (!frame->buf[1]) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
  }
  
+unmap_data->idx = cf->idx;

+unmap_data->idx_ref = av_buffer_ref(cf->idx_ref);
+unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref);
+
+for (i = 0; frame->linesize[i]; i++) {
+frame->data[i] = (uint8_t*)(devptr + offset);
+frame->linesize[i] = pitch;
+offset += pitch * (frame->height >> (i ? 1 : 0));
+}
+
+goto finish;
+
  copy_fail:
-decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (!frame->buf[1]) {
+decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+av_freep(&unmap_data);
+} else {
+av_buffer_unref(&frame->buf[1]);
+}
  
  finish:

  decoder->cudl->cuCtxPopCurrent(&dummy);
@@ -526,6 +560,7 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
int dpb_size)
  {
  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
+AVCUDAFramesContext *hwctx = (AVCUDAFramesContext*)frames_ctx->hwctx;
  const AVPixFmtDescriptor *sw_desc;
  int cuvid_codec_type, cuvid_chroma_format;
  
@@ -550,6 +585,8 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,

  frames_ctx-

Re: [FFmpeg-devel] [PATCH 03/13] avformat/mxfenc: Add Product Version, Toolkit version and Platform

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:28:48PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> >  static void mxf_write_identification(AVFormatContext *s)
> >  {
> >  MXFContext *mxf = s->priv_data;
> > @@ -790,7 +809,7 @@ static void mxf_write_identification(AVFormatContext *s)
> >  
> >  version = s->flags & AVFMT_FLAG_BITEXACT ?
> >  "0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
> > -length = 72 + mxf_utf16_local_tag_length(company) +
> > +length = 100 +mxf_utf16_local_tag_length(company) +
> 
> I have mixed feelings about this style of computation. But not enough
> to hold the patch up, which looks OK

ok, will apply

thx

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

You can kill me, but you cannot change the truth.


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


Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread wm4
On Tue, 8 May 2018 17:48:21 +0200
Timo Rothenpieler  wrote:

> Am 08.05.2018 um 17:26 schrieb wm4:
> > On Tue,  8 May 2018 15:31:29 +0200
> > Timo Rothenpieler  wrote:
> >   
> >> ---
> >>   configure  | 6 --
> >>   doc/APIchanges | 3 ++-
> >>   libavutil/hwcontext_cuda.c | 3 +++
> >>   libavutil/hwcontext_cuda.h | 1 +
> >>   libavutil/version.h| 2 +-
> >>   5 files changed, 11 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/configure b/configure
> >> index 7c143238a8..cae8a235a4 100755
> >> --- a/configure
> >> +++ b/configure
> >> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
> >> "VAEncPictureParameterBufferVP9"
> >>   check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
> >>   
> >>   if ! disabled ffnvcodec; then
> >> -check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
> >> -"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
> >> +check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> >> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
> >> +{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
> >> check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
> >> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
> >>   fi
> >>   
> >>   check_cpp_condition winrt windows.h 
> >> "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
> >> diff --git a/doc/APIchanges b/doc/APIchanges
> >> index f8ae6b0433..7a0a8522f9 100644
> >> --- a/doc/APIchanges
> >> +++ b/doc/APIchanges
> >> @@ -15,8 +15,9 @@ libavutil: 2017-10-21
> >>   
> >>   API changes, most recent first:
> >>   
> >> -2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h
> >> +2018-05-xx - xx, xx - lavu 56.19.100/101 - 
> >> hwcontext_cuda.h
> >> Add AVCUDAFramesContext and AVCUDAFramesContext.flags.
> >> +  Add AVCUDADeviceContext.stream.
> >>   
> >>   2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
> >> Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
> >> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> >> index b0b4bf24ae..8024eec79d 100644
> >> --- a/libavutil/hwcontext_cuda.c
> >> +++ b/libavutil/hwcontext_cuda.c
> >> @@ -395,6 +395,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, 
> >> const char *device,
> >>   goto error;
> >>   }
> >>   
> >> +// Setting stream to NULL will make functions automatically use the 
> >> default CUstream
> >> +hwctx->stream = NULL;
> >> +
> >>   cu->cuCtxPopCurrent(&dummy);
> >>   
> >>   hwctx->internal->is_allocated = 1;
> >> diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
> >> index 19accbd9be..cd797ae920 100644
> >> --- a/libavutil/hwcontext_cuda.h
> >> +++ b/libavutil/hwcontext_cuda.h
> >> @@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
> >> AVCUDADeviceContextInternal;
> >>*/
> >>   typedef struct AVCUDADeviceContext {
> >>   CUcontext cuda_ctx;
> >> +CUstream stream;
> >>   AVCUDADeviceContextInternal *internal;
> >>   } AVCUDADeviceContext;
> >>   
> >> diff --git a/libavutil/version.h b/libavutil/version.h
> >> index 84409b1d69..f84ec89154 100644
> >> --- a/libavutil/version.h
> >> +++ b/libavutil/version.h
> >> @@ -80,7 +80,7 @@
> >>   
> >>   #define LIBAVUTIL_VERSION_MAJOR  56
> >>   #define LIBAVUTIL_VERSION_MINOR  19
> >> -#define LIBAVUTIL_VERSION_MICRO 100
> >> +#define LIBAVUTIL_VERSION_MICRO 101
> >>   
> >>   #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> >>  LIBAVUTIL_VERSION_MINOR, 
> >> \  
> > 
> > What is this?  
> 
> https://docs.nvidia.com/cuda/cuda-driver-api/stream-sync-behavior.html
> 
> It allows asynchronous processing of CUDA workloads. The next couple 
> patches make use of it.
> There's no change in behaviour if it remains unset/NULL, but if you set 
> one, the workload won't block the main CUDA stream so you can do 
> multiple transcode sessions in the same application without blocking one 
> another.
> 

Could probably be documented.

It seems a bit strange that this is per device. Wouldn't it be per
operation?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 04/13] avformat/mxfenc: Add object model version

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:32:17PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> 
> >  mxf_write_metadata_key(pb, 0x012f00);
> >  PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
> > -klv_encode_ber_length(pb, 130 + 16LL * 
> > DESCRIPTOR_COUNT(mxf->essence_container_count));
> > +klv_encode_ber_length(pb, 138 + 16LL * 
> > DESCRIPTOR_COUNT(mxf->essence_container_count));
> >  
> >  // write preface set uid
> >  mxf_write_local_tag(pb, 16, 0x3C0A);
> > @@ -696,6 +697,10 @@ static void mxf_write_preface(AVFormatContext *s)
> >  mxf_write_local_tag(pb, 2, 0x3B05);
> >  avio_wb16(pb, 259); // v1.2
> >  
> > +// Object Model Version
> > +mxf_write_local_tag(pb, 4, 0x3B07);
> > +avio_wb32(pb, 1);
> > 
> 
> Not sure what use this is, but looks OK at least. S377m doesn't seem to
> think it's necessary. Is there some program that needs this?

Other tools (XFConvert at least) writes it. I think we should too.

will document this in the commit message and apply

thanks

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


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


Re: [FFmpeg-devel] [PATCH 01/13] avformat/mxfenc: Correct KAG alignment of preface

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:20:58PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/mxfenc.c|  1 +
> >  tests/ref/fate/copy-trac4914|  4 ++--
> >  tests/ref/fate/mxf-reel_name|  2 +-
> >  tests/ref/fate/time_base|  2 +-
> >  tests/ref/lavf/mxf  | 12 ++--
> >  tests/ref/lavf/mxf_d10  |  4 ++--
> >  tests/ref/lavf/mxf_dv25 |  4 ++--
> >  tests/ref/lavf/mxf_dvcpro50 |  4 ++--
> >  tests/ref/lavf/mxf_opatom   |  2 +-
> >  tests/ref/lavf/mxf_opatom_audio |  4 ++--
> >  10 files changed, 20 insertions(+), 19 deletions(-)
> > 
> > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > index 3bb70326fe..c0db10b3c2 100644
> > --- a/libavformat/mxfenc.c
> > +++ b/libavformat/mxfenc.c
> > @@ -1757,6 +1757,7 @@ static int mxf_write_partition(AVFormatContext
> > *s, int bodysid,
> >  mxf_write_klv_fill(s);
> >  start = avio_tell(s->pb);
> >  mxf_write_primer_pack(s);
> > +mxf_write_klv_fill(s);
> >  mxf_write_header_metadata_sets(s);
> >  pos = avio_tell(s->pb);
> >  header_byte_count = pos - start + klv_fill_size(pos);
> 
> Feels like such an elementary error. Probably OK, but it's been a while
> since I read the specs

will apply

thx

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

No snowflake in an avalanche ever feels responsible. -- Voltaire


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


Re: [FFmpeg-devel] [PATCH] lavfi/vf_srcnn: use avio_check instead of access

2018-05-08 Thread Hendrik Leppkes
On Tue, May 8, 2018 at 5:47 PM, James Almer  wrote:
> On 5/8/2018 12:27 PM, Hendrik Leppkes wrote:
>> The filter uses avio for file access already, and avio_check is
>> portable.
>>
>> Fixes trac #7192.
>
> Remove the access dep in configure while at it.
>
> LGTM is confirmed working.
>

Amended, tested and pushed. Builds have been broken long enough.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 05/13] avformat/mxfenc: Fix stored width

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:37:08PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > This fixes the width to have computations matching the height
> > 
> > > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/mxfenc.c  |   3 +-
> >  .../ref/fate/concat-demuxer-extended-lavf-mxf |   2 +-
> >  .../fate/concat-demuxer-extended-lavf-mxf_d10 |   2 +-
> >  .../ref/fate/concat-demuxer-simple1-lavf-mxf  | 242 +-
> >  .../fate/concat-demuxer-simple1-lavf-mxf_d10  | 140 +-
> >  tests/ref/seek/lavf-mxf   |  44 ++--
> >  tests/ref/seek/lavf-mxf_d10   |  54 ++--
> >  tests/ref/seek/lavf-mxf_dv25  |  54 ++--
> >  tests/ref/seek/lavf-mxf_dvcpro50  |  54 ++--
> >  tests/ref/seek/lavf-mxf_opatom_audio  |  54 ++--
> >  10 files changed, 325 insertions(+), 324 deletions(-)
> > 
> > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > index f0fd406493..9140302b81 100644
> > --- a/libavformat/mxfenc.c
> > +++ b/libavformat/mxfenc.c
> > @@ -1131,6 +1131,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> > AVStream *st, const UID ke
> >  {
> >  MXFStreamContext *sc = st->priv_data;
> >  AVIOContext *pb = s->pb;
> > +int stored_width  = (st->codecpar->width +15)/16*16;
> >  int stored_height = (st->codecpar->height+15)/16*16;
> 
> Should a muxer really do this kinds of computations? 

The specification lists these fields as "best effort" so litterally
yes, the muxer should do its best to do the computations and fill the
fields.


> What happens if a
> codec comes along that has larger or smaller macroblocks?

In this case we likely will have to check for this in the muxer

will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.



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


Re: [FFmpeg-devel] [PATCH 06/13] avformat/mxfenc: Add Sample width/height/x offset/y offset, Display x offset and F2 offset

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:40:49PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > +if (sc->interlaced) {
> > +//Display F2 Offset
> > +mxf_write_local_tag(pb, 4, 0x3217);
> > +avio_wb32(pb, -((st->codecpar->height - display_height)&1));
> 
> Negative values for DisplayF2Offset are not valid

The specification (SMPTE 377-1-2009) says:

The DisplayF2Offset Property adjusts the DisplayYOffset for the second field 
relative to that for the first field. Its
value shall be zero (0) or minus 1. A value of minus 1 shall invert the 
Displayed Topness relative to the Sampled
Topness.


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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable


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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags

2018-05-08 Thread Timo Rothenpieler

Am 08.05.2018 um 17:49 schrieb wm4:

On Tue, 8 May 2018 17:43:49 +0200
Timo Rothenpieler  wrote:


-frame->buf[0] = av_buffer_pool_get(ctx->pool);
+if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE)
+frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0);
+else
+frame->buf[0] = av_buffer_pool_get(ctx->pool);
+


Is this really needed? Because at least videotoolbox also lets the
decoder allocate frames, and allocates the "dummy" buffers outside of
the hwcontext. (I don't quite remember how it works.)


You mean compared to just leaving buf[0] empty?



No, compared to how the videotoolbox code does things.


videotoolbox seems to use an externally supplied AVHWFramesContext::pool.
Which should be possible to do for cuda as well, i.e. a custom buffer 
pool that returns mostly empty data, so the new API would be unneeded. 
I'll have a look if it works out.




smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread Timo Rothenpieler

What is this?


https://docs.nvidia.com/cuda/cuda-driver-api/stream-sync-behavior.html

It allows asynchronous processing of CUDA workloads. The next couple
patches make use of it.
There's no change in behaviour if it remains unset/NULL, but if you set
one, the workload won't block the main CUDA stream so you can do
multiple transcode sessions in the same application without blocking one
another.



Could probably be documented.

It seems a bit strange that this is per device. Wouldn't it be per
operation?


The whole streams thing and its various modes of operation are a bit 
strange. But it does make things faster in certain conditions.


See the whole thread with Oscar Amoros Huguet  
about some background on it.




smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3] avformat/mxfenc: add h264 profiles

2018-05-08 Thread Thomas Mundt
2018-05-07 10:40 GMT+02:00 Tomas Härdin :

> sön 2018-05-06 klockan 21:31 +0200 skrev Thomas Mundt:
> > 2018-05-06 13:32 GMT+02:00 Tomas Härdin :
> >
> > > fre 2018-05-04 klockan 01:52 +0200 skrev Thomas Mundt:
> > > > Hi,
> > > >
> > > > this is a better version of the patch.
> > > > 10 bit and TFF are mandatory for AVC Intra only. Other profiles
> > > > differ.
> > > >
> > > > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > > > index 3bb7032..81513dc 100644
> > > > --- a/libavformat/mxfenc.c
> > > > +++ b/libavformat/mxfenc.c
> > > > @@ -1947,22 +1947,31 @@ static const struct {
> > > >  int frame_size;
> > > >  int profile;
> > > >  uint8_t interlaced;
> > > > +int long_gop;
> > >
> > > A comment here explaining the difference between -1, 0 and 1 would
> > > be
> > > nice. The rest looks OK, but I didn't read the relevant specs to be
> > > 100% sure
> > > 
> > >
> >
> > New patch attached.
>
> Looks OK


Thanks,

can you or someone else push it please.

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


Re: [FFmpeg-devel] [PATCH 07/13] avformat/mxfenc: Add vertical subsampling support

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:45:18PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > 
> > @@ -1149,6 +1151,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> > AVStream *st, const UID ke
> >  desc_size += 5;
> >  if (sc->interlaced)
> >  desc_size += 8;
> > +if (sc->v_chroma_sub_sample)
> > +desc_size += 8;
> >  
> >  mxf_write_generic_desc(s, st, key, desc_size);
> >  
> > @@ -1209,6 +1213,12 @@ static void mxf_write_cdci_common(AVFormatContext 
> > *s, AVStream *st, const UID ke
> >  mxf_write_local_tag(pb, 4, 0x3302);
> >  avio_wb32(pb, sc->h_chroma_sub_sample);
> >  
> > +// vertical subsampling
> > +if (sc->v_chroma_sub_sample) {
> > +mxf_write_local_tag(pb, 4, 0x3308);
> > +avio_wb32(pb, sc->v_chroma_sub_sample);
> > +}
> > +
> >  // color siting
> >  mxf_write_local_tag(pb, 1, 0x3303);
> >  avio_w8(pb, sc->color_siting);
> > @@ -2273,6 +2283,7 @@ static int mxf_write_header(AVFormatContext *s)
> >  if (pix_desc) {
> >  sc->component_depth = pix_desc->comp[0].depth;
> >  sc->h_chroma_sub_sample = 1 << pix_desc->log2_chroma_w;
> > +sc->v_chroma_sub_sample = 1 << pix_desc->log2_chroma_h;
> 
> Looks OK. Had this confused for chrome siting for a while, but I see
> that is actually handled correctly.

will apply

thanks

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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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


Re: [FFmpeg-devel] [PATCH 08/13] avformat/mxfenc: add white/black ref /color range

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:47:35PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > 
> > +if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED) {
> > +int black = 0,
> > +white = (1 > +color = (1 > +if (st->codecpar->color_range == AVCOL_RANGE_MPEG) {
> > +black = 1   << (sc->component_depth - 4);
> > +white = 235 << (sc->component_depth - 8);
> > +color = (14 << (sc->component_depth - 4)) + 1;
> > +}
> 
> This feels like something that should be part of pix_fmt stuff or
> something. But maybe someone can refactor that later. Looks OK
> otherwise

ok, will apply

thanks

[...]
-- 
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] [PATCH 09/13] avformat/mxfenc: Add Padding Bits

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:50:16PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > @@ -1228,6 +1229,10 @@ static void mxf_write_cdci_common(AVFormatContext 
> > *s, AVStream *st, const UID ke
> >  mxf_write_local_tag(pb, 1, 0x3303);
> >  avio_w8(pb, sc->color_siting);
> >  
> > +// Padding Bits
> > +mxf_write_local_tag(pb, 2, 0x3307);
> > +avio_wb16(pb, 0);
> 
> I'm pretty sure there's ways of muxing v210 in mxf, so it might be
> better to say nothing here unless we're entirely sure. Probably OK
> since mxfenc can't mux raw video tho

IIUC we need this for SMPTE 386M (D-10). It lists "Padding Bits"

this needs to be updated in case rawvideo support is added with different
padding bits.

will apply

thanks


[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras


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


Re: [FFmpeg-devel] [PATCH 10/13] avformat/mxfenc: Set color siting to 0 for D10-MXF

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:55:18PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/mxfenc.c  |   1 +
> >  .../ref/fate/concat-demuxer-extended-lavf-mxf |   2 +-
> >  .../fate/concat-demuxer-extended-lavf-mxf_d10 |   2 +-
> >  .../ref/fate/concat-demuxer-simple1-lavf-mxf  | 242 +-
> >  .../fate/concat-demuxer-simple1-lavf-mxf_d10  | 140 +-
> >  tests/ref/seek/lavf-mxf   |  44 ++--
> >  tests/ref/seek/lavf-mxf_d10   |  54 ++--
> >  tests/ref/seek/lavf-mxf_dv25  |  54 ++--
> >  tests/ref/seek/lavf-mxf_dvcpro50  |  54 ++--
> >  tests/ref/seek/lavf-mxf_opatom|  54 ++--
> >  tests/ref/seek/lavf-mxf_opatom_audio  |  54 ++--
> >  11 files changed, 351 insertions(+), 350 deletions(-)
> > 
> > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > index f2be76cc86..adf5527534 100644
> > --- a/libavformat/mxfenc.c
> > +++ b/libavformat/mxfenc.c
> > @@ -2361,6 +2361,7 @@ static int mxf_write_header(AVFormatContext *s)
> >  mxf->edit_unit_byte_count += 
> > klv_fill_size(mxf->edit_unit_byte_count);
> >  
> >  sc->signal_standard = 1;
> > +sc->color_siting = 0;
> >  }
> 
> Can't find anything in my documents that says anything about this. I
> don't remember what D-10 is actually specified in...

SMPTE 386M (D-10) lists 4 as value to be used
SMPTE 377-1-2009 says 
"The definitions of 00h (coSiting) and 04h (Rec 601) are equivalent. The 
value of 04h is deprecated. New
 MXF encoders shall use the value of 00h instead."

I will add this to the commit message
 
[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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


Re: [FFmpeg-devel] [PATCH 11/13] avformat/mxfenc: Write Audio Ref Level for D10

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 01:02:19PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> >  // Generic Sound Essence Descriptor
> >  { 0x3D02, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}},
> >  /* Locked/Unlocked */
> >  { 0x3D03, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}},
> >  /* Audio sampling rate */
> > +{ 0x3D04, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x02,0x01,0x01,0x03,0x00,0x00,0x00}},
> >  /* Audio Ref Level */
> >  { 0x3D07, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}},
> >  /* ChannelCount */
> >  { 0x3D01, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}},
> >  /* Quantization bits */
> >  { 0x3D06, 
> > {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}},
> >  /* Sound Essence Compression */
> > @@ -1333,6 +1334,8 @@ static void 
> > mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
> >  
> >  if (s->oformat == &ff_mxf_opatom_muxer)
> >  duration_size = 12;
> > +if (s->oformat == &ff_mxf_d10_muxer)
> > +size += 5;
> >  
> >  mxf_write_generic_desc(s, st, key, size+duration_size+5+12+8+8);
> >  
> > @@ -1350,6 +1353,11 @@ static void 
> > mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
> >  avio_wb32(pb, st->codecpar->sample_rate);
> >  avio_wb32(pb, 1);
> >  
> > +if (s->oformat == &ff_mxf_d10_muxer) {
> > +mxf_write_local_tag(pb, 1, 0x3D04);
> > +avio_w8(pb, 0);
> > +}
> 
> Sizes and such look OK, but again I don't know what the D-10 spec says

double checked
Table A2 - Generic Sound Essence Descriptor in SMPTE 386M lists 0

will apply

thanks

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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


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


[FFmpeg-devel] [PATCH] lavd/v4l2: Add ARGB and XRGB packed pixel formats

2018-05-08 Thread Anton Leontiev
Formats ARGB32, XRGB32, ABGR32, and XBGR32 were added to V4L2 instead
of ill-defined deprecated RGB32/BGR32 pixel formats.

When pixel format is not specified explicitly FFmpeg tries formats in
order in which they are stored in the table. Therefore formats are
sorted as follows: BGR is preferred over RGB and XBGR is preferred
over ARGB, because it could give better performance by ignoring alpha
component.
---
 libavdevice/v4l2-common.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c
index 196c09b7fc..d48ae2efa1 100644
--- a/libavdevice/v4l2-common.c
+++ b/libavdevice/v4l2-common.c
@@ -34,6 +34,10 @@ const struct fmt_map ff_fmt_conversion_table[] = {
 { AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X },
 { AV_PIX_FMT_BGR24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24   },
 { AV_PIX_FMT_RGB24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24   },
+{ AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_XBGR32  },
+{ AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_XRGB32  },
+{ AV_PIX_FMT_BGRA,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_ABGR32  },
+{ AV_PIX_FMT_ARGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_ARGB32  },
 { AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32   },
 { AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32   },
 { AV_PIX_FMT_GRAY8,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY},
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH 12/13] avformat/mxfenc: Add Stored F2 Offset / Image Start/End Offset for D10

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 12:58:09PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> >  desc_size += 8;
> >  if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED)
> >  desc_size += 8 * 3;
> > +if (s->oformat == &ff_mxf_d10_muxer)
> > +desc_size += 8 + 8 + 8;
> >  
> >  mxf_write_generic_desc(s, st, key, desc_size);
> >  
> > @@ -1169,6 +1173,20 @@ static void mxf_write_cdci_common(AVFormatContext 
> > *s, AVStream *st, const UID ke
> >  mxf_write_local_tag(pb, 4, 0x3202);
> >  avio_wb32(pb, stored_height>>sc->interlaced);
> >  
> > +if (s->oformat == &ff_mxf_d10_muxer) {
> > +//Stored F2 Offset
> > +mxf_write_local_tag(pb, 4, 0x3216);
> > +avio_wb32(pb, 0);
> > +
> > +//Image Start Offset
> > +mxf_write_local_tag(pb, 4, 0x3213);
> > +avio_wb32(pb, 0);
> > +
> > +//Image End Offset
> > +mxf_write_local_tag(pb, 4, 0x3214);
> > +avio_wb32(pb, 0);
> > +}
> 
> Looks OK, but of course I don't know what the spec says

double checked, "Table A1- CDCI (Picture) Essence Descriptor" lists 0 for these

will apply

thanks

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

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety -- Benjamin Franklin


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


[FFmpeg-devel] [PATCH 2/3] libavcodec: v4l2m2m: output AVDRMFrameDescriptor

2018-05-08 Thread Lukas Rusak
This is V2 of my previous patch. I have worked together with Jorge to get this 
working properly.
We have made it so that AV_PIX_FMT_DRM_PRIME output can be selected by setting 
avctx->pix_fmt.
This allows v4l2 to export the buffer so we can use it for zero-copy. If 
AV_PIX_FMT_DRM_PRIME is
not selected then the standard pixel formats will be used and the buffers will 
not be exported.

---
 libavcodec/v4l2_buffers.c | 228 +++---
 libavcodec/v4l2_buffers.h |   5 +-
 libavcodec/v4l2_context.c |  40 ++-
 libavcodec/v4l2_m2m.c |   4 +-
 libavcodec/v4l2_m2m.h |   3 +
 libavcodec/v4l2_m2m_dec.c |  23 
 6 files changed, 257 insertions(+), 46 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index aef911f3bb..d715bc6a7c 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,7 @@
 #include 
 #include "libavcodec/avcodec.h"
 #include "libavcodec/internal.h"
+#include "libavutil/hwcontext.h"
 #include "v4l2_context.h"
 #include "v4l2_buffers.h"
 #include "v4l2_m2m.h"
@@ -203,7 +205,65 @@ static enum AVColorTransferCharacteristic 
v4l2_get_color_trc(V4L2Buffer *buf)
 return AVCOL_TRC_UNSPECIFIED;
 }
 
-static void v4l2_free_buffer(void *opaque, uint8_t *unused)
+static uint8_t * v4l2_get_drm_frame(V4L2Buffer *avbuf)
+{
+AVDRMFrameDescriptor *drm_desc = &avbuf->drm_frame;
+AVDRMLayerDescriptor *layer;
+
+/* fill the DRM frame descriptor */
+drm_desc->nb_objects = 1;
+drm_desc->nb_layers = 1;
+
+layer = &drm_desc->layers[0];
+layer->planes[0].object_index = 0;
+layer->planes[0].offset = 0;
+layer->planes[0].pitch = avbuf->plane_info[0].bytesperline;
+
+switch (avbuf->context->av_pix_fmt) {
+case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_NV21:
+
+if (avbuf->num_planes > 1)
+break;
+
+layer->format = avbuf->context->av_pix_fmt == AV_PIX_FMT_NV12 ?
+DRM_FORMAT_NV12 : DRM_FORMAT_NV21;
+layer->nb_planes = 2;
+
+layer->planes[1].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
+avbuf->context->format.fmt.pix_mp.height;
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline;
+break;
+
+case AV_PIX_FMT_YUV420P:
+
+if (avbuf->num_planes > 1)
+break;
+
+layer->format = DRM_FORMAT_YUV420;
+layer->nb_planes = 3;
+
+layer->planes[1].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
+avbuf->context->format.fmt.pix_mp.height;
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline >> 1;
+
+layer->planes[2].object_index = 0;
+layer->planes[2].offset = layer->planes[1].offset +
+((avbuf->plane_info[0].bytesperline *
+  avbuf->context->format.fmt.pix_mp.height) >> 2);
+layer->planes[2].pitch = avbuf->plane_info[0].bytesperline >> 1;
+break;
+
+default:
+break;
+}
+
+return (uint8_t *) drm_desc;
+}
+
+static void v4l2_free_buffer(void *opaque, uint8_t *data)
 {
 V4L2Buffer* avbuf = opaque;
 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
@@ -227,27 +287,49 @@ static void v4l2_free_buffer(void *opaque, uint8_t 
*unused)
 }
 }
 
-static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
+static int v4l2_buffer_export_drm(V4L2Buffer* avbuf)
 {
-V4L2m2mContext *s = buf_to_m2mctx(in);
+struct v4l2_exportbuffer expbuf;
+int i, ret;
 
-if (plane >= in->num_planes)
-return AVERROR(EINVAL);
+for (i = 0; i < avbuf->num_planes; i++) {
+memset(&expbuf, 0, sizeof(expbuf));
 
-/* even though most encoders return 0 in data_offset encoding vp8 does 
require this value */
-*buf = av_buffer_create((char *)in->plane_info[plane].mm_addr + 
in->planes[plane].data_offset,
-in->plane_info[plane].length, v4l2_free_buffer, 
in, 0);
-if (!*buf)
-return AVERROR(ENOMEM);
+expbuf.index = avbuf->buf.index;
+expbuf.type = avbuf->buf.type;
+expbuf.plane = i;
+
+ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_EXPBUF, &expbuf);
+if (ret < 0)
+return AVERROR(errno);
+
+if (V4L2_TYPE_IS_MULTIPLANAR(avbuf->buf.type)) {
+avbuf->buf.m.planes[i].m.fd = expbuf.fd;
+/* drm frame */
+avbuf->drm_frame.objects[i].size = avbuf->buf.m.planes[i].length;
+avbuf->drm_frame.objects[i].fd = expbuf.fd;
+} else {
+avbuf->buf.m.fd = expbuf.fd;
+/* drm frame */
+avbuf->drm_frame.objects[0].size = avbuf->buf.length;
+avbuf->drm_frame.objects[0].fd = expbuf.fd;
+}
+}
+
+return 0;
+}
+
+static int v4l2_buf_inc

[FFmpeg-devel] [PATCH 3/3] libavcodec: v4l2m2m: fix error handling during buffer init

2018-05-08 Thread Lukas Rusak
From: Jorge Ramirez-Ortiz 

Signed-off-by: Jorge Ramirez-Ortiz 
---
 libavcodec/v4l2_context.c | 19 ---
 libavcodec/v4l2_m2m_dec.c | 11 ---
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 9457fadb1e..fd3161ce2f 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -263,6 +263,12 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, 
int timeout)
 /* if we are draining and there are no more capture buffers queued in the 
driver we are done */
 if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx_to_m2mctx(ctx)->draining) {
 for (i = 0; i < ctx->num_buffers; i++) {
+/* catpture buffer initialization happens during decode hence
+ * detection happens at runtime
+ */
+if (!ctx->buffers)
+break;
+
 if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER)
 goto start;
 }
@@ -724,9 +730,8 @@ int ff_v4l2_context_init(V4L2Context* ctx)
 ctx->buffers[i].context = ctx;
 ret = ff_v4l2_buffer_initialize(&ctx->buffers[i], i);
 if (ret < 0) {
-av_log(logger(ctx), AV_LOG_ERROR, "%s buffer initialization 
(%s)\n", ctx->name, av_err2str(ret));
-av_free(ctx->buffers);
-return ret;
+av_log(logger(ctx), AV_LOG_ERROR, "%s buffer[%d] initialization 
(%s)\n", ctx->name, i, av_err2str(ret));
+goto error;
 }
 }
 
@@ -739,4 +744,12 @@ int ff_v4l2_context_init(V4L2Context* ctx)
 V4L2_TYPE_IS_MULTIPLANAR(ctx->type) ? 
ctx->format.fmt.pix_mp.plane_fmt[0].bytesperline : 
ctx->format.fmt.pix.bytesperline);
 
 return 0;
+
+error:
+v4l2_release_buffers(ctx);
+
+av_free(ctx->buffers);
+ctx->buffers = NULL;
+
+return ret;
 }
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 2b33badb08..1bfd11e216 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -92,8 +92,8 @@ static int v4l2_try_start(AVCodecContext *avctx)
 if (!capture->buffers) {
 ret = ff_v4l2_context_init(capture);
 if (ret) {
-av_log(avctx, AV_LOG_DEBUG, "can't request output buffers\n");
-return ret;
+av_log(avctx, AV_LOG_ERROR, "can't request capture buffers\n");
+return AVERROR(ENOMEM);
 }
 }
 
@@ -155,8 +155,13 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 
 if (avpkt.size) {
 ret = v4l2_try_start(avctx);
-if (ret)
+if (ret) {
+/* cant recover */
+if (ret == AVERROR(ENOMEM))
+return ret;
+
 return 0;
+}
 }
 
 dequeue:
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/3] libavcodec: v4l2m2m: fix indentation and add M2MDEC_CLASS

2018-05-08 Thread Lukas Rusak
This is just some formatting that is taken from the rkmpp decoder. I find that
this make is more readable.

---
 libavcodec/v4l2_m2m_dec.c | 44 ---
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index bca45be148..ed5193ecc1 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -202,28 +202,30 @@ static const AVOption options[] = {
 { NULL},
 };
 
+#define M2MDEC_CLASS(NAME) \
+static const AVClass v4l2_m2m_ ## NAME ## _dec_class = { \
+.class_name = #NAME "_v4l2_m2m_decoder", \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+};
+
 #define M2MDEC(NAME, LONGNAME, CODEC, bsf_name) \
-static const AVClass v4l2_m2m_ ## NAME ## _dec_class = {\
-.class_name = #NAME "_v4l2_m2m_decoder",\
-.item_name  = av_default_item_name,\
-.option = options,\
-.version= LIBAVUTIL_VERSION_INT,\
-};\
-\
-AVCodec ff_ ## NAME ## _v4l2m2m_decoder = { \
-.name   = #NAME "_v4l2m2m" ,\
-.long_name  = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " decoder 
wrapper"),\
-.type   = AVMEDIA_TYPE_VIDEO,\
-.id = CODEC ,\
-.priv_data_size = sizeof(V4L2m2mPriv),\
-.priv_class = &v4l2_m2m_ ## NAME ## _dec_class,\
-.init   = v4l2_decode_init,\
-.receive_frame  = v4l2_receive_frame,\
-.close  = ff_v4l2_m2m_codec_end,\
-.bsfs   = bsf_name, \
-.capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
-.wrapper_name   = "v4l2m2m", \
-};
+M2MDEC_CLASS(NAME) \
+AVCodec ff_ ## NAME ## _v4l2m2m_decoder = { \
+.name   = #NAME "_v4l2m2m" , \
+.long_name  = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " 
decoder wrapper"), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = CODEC , \
+.priv_data_size = sizeof(V4L2m2mPriv), \
+.priv_class = &v4l2_m2m_ ## NAME ## _dec_class, \
+.init   = v4l2_decode_init, \
+.receive_frame  = v4l2_receive_frame, \
+.close  = ff_v4l2_m2m_codec_end, \
+.bsfs   = bsf_name, \
+.capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
+.wrapper_name   = "v4l2m2m", \
+};
 
 M2MDEC(h264,  "H.264", AV_CODEC_ID_H264,   "h264_mp4toannexb");
 M2MDEC(hevc,  "HEVC",  AV_CODEC_ID_HEVC,   "hevc_mp4toannexb");
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/5] avcodec/nvdec: avoid needless copy of output frame

2018-05-08 Thread Timo Rothenpieler
Replaces the data pointers with the mapped cuvid ones.
Adds buffer_refs to the frame to ensure the needed contexts stay alive
and the cuvid idx stays allocated.
Adds another buffer_ref to unmap the frame when it's unreferenced itself.
---
 libavcodec/nvdec.c | 96 +++---
 1 file changed, 73 insertions(+), 23 deletions(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index ab3cb88b27..502747adfd 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -308,7 +308,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 params.CodecType   = cuvid_codec_type;
 params.ChromaFormat= cuvid_chroma_format;
 params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
-params.ulNumOutputSurfaces = 1;
+params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
 
 ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, 
¶ms, avctx);
 if (ret < 0) {
@@ -354,6 +354,32 @@ static void nvdec_fdd_priv_free(void *priv)
 av_freep(&priv);
 }
 
+static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
+{
+NVDECFrame *unmap_data = (NVDECFrame*)data;
+NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
+CUdeviceptr devptr = (CUdeviceptr)opaque;
+CUresult err;
+CUcontext dummy;
+
+err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
+if (err != CUDA_SUCCESS) {
+av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
+goto finish;
+}
+
+err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (err != CUDA_SUCCESS)
+av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
+
+decoder->cudl->cuCtxPopCurrent(&dummy);
+
+finish:
+av_buffer_unref(&unmap_data->idx_ref);
+av_buffer_unref(&unmap_data->decoder_ref);
+av_free(unmap_data);
+}
+
 static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 {
 FrameDecodeData  *fdd = (FrameDecodeData*)frame->private_ref->data;
@@ -361,6 +387,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
 
 CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
+NVDECFrame *unmap_data = NULL;
 
 CUresult err;
 CUcontext dummy;
@@ -383,32 +410,39 @@ static int nvdec_retrieve_data(void *logctx, AVFrame 
*frame)
 goto finish;
 }
 
-for (i = 0; frame->data[i]; i++) {
-CUDA_MEMCPY2D cpy = {
-.srcMemoryType = CU_MEMORYTYPE_DEVICE,
-.dstMemoryType = CU_MEMORYTYPE_DEVICE,
-.srcDevice = devptr,
-.dstDevice = (CUdeviceptr)frame->data[i],
-.srcPitch  = pitch,
-.dstPitch  = frame->linesize[i],
-.srcY  = offset,
-.WidthInBytes  = FFMIN(pitch, frame->linesize[i]),
-.Height= frame->height >> (i ? 1 : 0),
-};
-
-err = decoder->cudl->cuMemcpy2D(&cpy);
-if (err != CUDA_SUCCESS) {
-av_log(logctx, AV_LOG_ERROR, "Error copying decoded frame: %d\n",
-   err);
-ret = AVERROR_UNKNOWN;
-goto copy_fail;
-}
+unmap_data = av_mallocz(sizeof(*unmap_data));
+if (!unmap_data) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
+}
 
-offset += cpy.Height;
+frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, 
sizeof(*unmap_data),
+ nvdec_unmap_mapped_frame, (void*)devptr,
+ AV_BUFFER_FLAG_READONLY);
+if (!frame->buf[1]) {
+ret = AVERROR(ENOMEM);
+goto copy_fail;
 }
 
+unmap_data->idx = cf->idx;
+unmap_data->idx_ref = av_buffer_ref(cf->idx_ref);
+unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref);
+
+for (i = 0; frame->linesize[i]; i++) {
+frame->data[i] = (uint8_t*)(devptr + offset);
+frame->linesize[i] = pitch;
+offset += pitch * (frame->height >> (i ? 1 : 0));
+}
+
+goto finish;
+
 copy_fail:
-decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+if (!frame->buf[1]) {
+decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+av_freep(&unmap_data);
+} else {
+av_buffer_unref(&frame->buf[1]);
+}
 
 finish:
 decoder->cudl->cuCtxPopCurrent(&dummy);
@@ -521,6 +555,16 @@ int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer,
 return 0;
 }
 
+static void nvdec_free_dummy(struct AVHWFramesContext *ctx)
+{
+av_buffer_pool_uninit(&ctx->pool);
+}
+
+static AVBufferRef *nvdec_alloc_dummy(int size)
+{
+return av_buffer_create(NULL, 0, NULL, NULL, 0);
+}
+
 int ff_nvdec_frame_params(AVCodecContext *avctx,
   AVBufferRef *hw_frames_ctx,
   int dpb_size)
@@ -550,6 +594,12 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
 frames_ctx->height   

[FFmpeg-devel] [PATCH 2/5] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread Timo Rothenpieler
---
 configure  | 6 --
 doc/APIchanges | 3 +++
 libavutil/hwcontext_cuda.c | 3 +++
 libavutil/hwcontext_cuda.h | 1 +
 libavutil/version.h| 2 +-
 5 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 6626111ff2..9743de05d0 100755
--- a/configure
+++ b/configure
@@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
"VAEncPictureParameterBufferVP9"
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 
 if ! disabled ffnvcodec; then
-check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
-"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
+check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
+{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
+  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
 fi
 
 check_cpp_condition winrt windows.h 
"!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
diff --git a/doc/APIchanges b/doc/APIchanges
index ede5b186ae..bbefc8356e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-05-xx - xx - lavu 56.18.101 - hwcontext_cuda.h
+  Add AVCUDADeviceContext.stream.
+
 2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
 
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 37827a770c..f3e81680e9 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -386,6 +386,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, const 
char *device,
 goto error;
 }
 
+// Setting stream to NULL will make functions automatically use the 
default CUstream
+hwctx->stream = NULL;
+
 cu->cuCtxPopCurrent(&dummy);
 
 hwctx->internal->is_allocated = 1;
diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index 12dae8449e..81a0552cab 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
AVCUDADeviceContextInternal;
  */
 typedef struct AVCUDADeviceContext {
 CUcontext cuda_ctx;
+CUstream stream;
 AVCUDADeviceContextInternal *internal;
 } AVCUDADeviceContext;
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 5185454d9b..186fe0794d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  56
 #define LIBAVUTIL_VERSION_MINOR  18
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 4/5] avutil/hwcontext_cuda: explicitly synchronize cuMemcpy calls

2018-05-08 Thread Timo Rothenpieler
---
 libavutil/hwcontext_cuda.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index f3e81680e9..668293bffc 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -258,13 +258,19 @@ static int cuda_transfer_data_from(AVHWFramesContext 
*ctx, AVFrame *dst,
 .Height= src->height >> (i ? priv->shift_height : 0),
 };
 
-err = cu->cuMemcpy2D(&cpy);
+err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
 if (err != CUDA_SUCCESS) {
 av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the 
CUDA frame\n");
 return AVERROR_UNKNOWN;
 }
 }
 
+err = cu->cuStreamSynchronize(device_hwctx->stream);
+if (err != CUDA_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+return AVERROR_UNKNOWN;
+}
+
 cu->cuCtxPopCurrent(&dummy);
 
 return 0;
@@ -297,13 +303,19 @@ static int cuda_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 .Height= src->height >> (i ? priv->shift_height : 0),
 };
 
-err = cu->cuMemcpy2D(&cpy);
+err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
 if (err != CUDA_SUCCESS) {
-av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the 
CUDA frame\n");
+av_log(ctx, AV_LOG_ERROR, "Error transferring the data to the CUDA 
frame\n");
 return AVERROR_UNKNOWN;
 }
 }
 
+err = cu->cuStreamSynchronize(device_hwctx->stream);
+if (err != CUDA_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+return AVERROR_UNKNOWN;
+}
+
 cu->cuCtxPopCurrent(&dummy);
 
 return 0;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 5/5] avcodec/cuviddec: explicitly synchronize cuMemcpy calls

2018-05-08 Thread Timo Rothenpieler
---
 libavcodec/cuviddec.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 122c28f6e8..4d3caf924e 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -550,12 +550,16 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 .Height= avctx->height >> (i ? 1 : 0),
 };
 
-ret = CHECK_CU(ctx->cudl->cuMemcpy2D(&cpy));
+ret = CHECK_CU(ctx->cudl->cuMemcpy2DAsync(&cpy, 
device_hwctx->stream));
 if (ret < 0)
 goto error;
 
 offset += avctx->height;
 }
+
+ret = 
CHECK_CU(ctx->cudl->cuStreamSynchronize(device_hwctx->stream));
+if (ret < 0)
+goto error;
 } else if (avctx->pix_fmt == AV_PIX_FMT_NV12 ||
avctx->pix_fmt == AV_PIX_FMT_P010 ||
avctx->pix_fmt == AV_PIX_FMT_P016) {
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 3/5] avcodec/nvdec: pass CUstream in vpp parameters

2018-05-08 Thread Timo Rothenpieler
---
 libavcodec/nvdec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index 502747adfd..e779be3a45 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -39,6 +39,7 @@ typedef struct NVDECDecoder {
 
 AVBufferRef *hw_device_ref;
 CUcontextcuda_ctx;
+CUstream stream;
 
 CudaFunctions *cudl;
 CuvidFunctions *cvdl;
@@ -189,6 +190,7 @@ static int nvdec_decoder_create(AVBufferRef **out, 
AVBufferRef *hw_device_ref,
 }
 decoder->cuda_ctx = device_hwctx->cuda_ctx;
 decoder->cudl = device_hwctx->internal->cuda_dl;
+decoder->stream = device_hwctx->stream;
 
 ret = cuvid_load_functions(&decoder->cvdl, logctx);
 if (ret < 0) {
@@ -386,7 +388,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 NVDECFrame*cf = (NVDECFrame*)fdd->hwaccel_priv;
 NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
 
-CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
+CUVIDPROCPARAMS vpp = { 0 };
 NVDECFrame *unmap_data = NULL;
 
 CUresult err;
@@ -397,6 +399,9 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
 unsigned int offset = 0;
 int ret = 0;
 
+vpp.progressive_frame = 1;
+vpp.output_stream = decoder->stream;
+
 err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
 if (err != CUDA_SUCCESS)
 return AVERROR_UNKNOWN;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH] avformat/mpegts: add skip_unknown_pids option

2018-05-08 Thread Aman Gupta
From: Aman Gupta 

Allows the user to skip streams that are not advertised in the PMT.
---
 libavformat/mpegts.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 629631f60a..5464f48a8d 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -143,6 +143,7 @@ struct MpegTSContext {
 
 int skip_changes;
 int skip_clear;
+int skip_unknown_pids;
 
 int scan_all_pmts;
 
@@ -176,6 +177,8 @@ static const AVOption options[] = {
  {.i64 = 0}, 0, 1, 0 },
 {"skip_clear", "skip clearing programs", offsetof(MpegTSContext, 
skip_clear), AV_OPT_TYPE_BOOL,
  {.i64 = 0}, 0, 1, 0 },
+{"skip_unknown_pids", "skip streams not advertised in PMT", 
offsetof(MpegTSContext, skip_unknown_pids), AV_OPT_TYPE_BOOL,
+ {.i64 = 0}, 0, 1, 0 },
 { NULL },
 };
 
@@ -1058,7 +1061,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
 
 /* stream not present in PMT */
 if (!pes->st) {
-if (ts->skip_changes)
+if (ts->skip_changes || ts->skip_unknown_pids)
 goto skip;
 
 pes->st = avformat_new_stream(ts->stream, NULL);
@@ -2011,6 +2014,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 if (!ts->scan_all_pmts && ts->skip_changes)
 return;
 
+if (ts->skip_unknown_pids && !get_program(ts, h->id))
+return;
 if (!ts->skip_clear)
 clear_program(ts, h->id);
 
-- 
2.14.2

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


[FFmpeg-devel] [PATCH] ffprobe: fix SEGV when new streams are added

2018-05-08 Thread Aman Gupta
From: Aman Gupta 

---
 fftools/ffprobe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 8b2a18b6b1..544786ec72 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2371,11 +2371,11 @@ static int read_interval_packets(WriterContext *w, 
InputFile *ifile,
 goto end;
 }
 while (!av_read_frame(fmt_ctx, &pkt)) {
-if (ifile->nb_streams > nb_streams) {
+if (fmt_ctx->nb_streams > nb_streams) {
 REALLOCZ_ARRAY_STREAM(nb_streams_frames,  nb_streams, 
fmt_ctx->nb_streams);
 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, 
fmt_ctx->nb_streams);
 REALLOCZ_ARRAY_STREAM(selected_streams,   nb_streams, 
fmt_ctx->nb_streams);
-nb_streams = ifile->nb_streams;
+nb_streams = fmt_ctx->nb_streams;
 }
 if (selected_streams[pkt.stream_index]) {
 AVRational tb = ifile->streams[pkt.stream_index].st->time_base;
-- 
2.14.2

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


Re: [FFmpeg-devel] [PATCH 1/5] avcodec/nvdec: avoid needless copy of output frame

2018-05-08 Thread Philip Langdale

On 2018-05-08 11:36, Timo Rothenpieler wrote:

Replaces the data pointers with the mapped cuvid ones.
Adds buffer_refs to the frame to ensure the needed contexts stay alive
and the cuvid idx stays allocated.
Adds another buffer_ref to unmap the frame when it's unreferenced 
itself.

---
 libavcodec/nvdec.c | 96 +++---
 1 file changed, 73 insertions(+), 23 deletions(-)


This and the rest of the changeset look good to me.

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


[FFmpeg-devel] [PATCH 1/2] avcodec/cbs_h2645: use simple data buffers for some parameter set extensions

2018-05-08 Thread James Almer
There's no gain from using AVBufferRef for these, as no copies or
references are ever made.

Signed-off-by: James Almer 
---
There is however a raw copy of the struct storing these buffers,
which is dangerous and fragile.
This patch is in preparation to change how the above is handled.

 libavcodec/cbs_h264.h  |  1 -
 libavcodec/cbs_h2645.c | 13 ++---
 libavcodec/cbs_h265.h  |  1 -
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 2219d9da8d..becea3adfe 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -197,7 +197,6 @@ typedef struct H264RawPPS {
 uint16_t pic_size_in_map_units_minus1;
 
 uint8_t *slice_group_id;
-AVBufferRef *slice_group_id_ref;
 
 uint8_t num_ref_idx_l0_default_active_minus1;
 uint8_t num_ref_idx_l1_default_active_minus1;
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 64a1a2d1ee..580ca09f63 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -318,10 +318,9 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #define byte_alignment(rw) (get_bits_count(rw) % 8)
 
 #define allocate(name, size) do { \
-name ## _ref = av_buffer_allocz(size); \
-if (!name ## _ref) \
+name = av_mallocz(size); \
+if (!name) \
 return AVERROR(ENOMEM); \
-name = name ## _ref->data; \
 } while (0)
 
 #define FUNC(name) FUNC_H264(READWRITE, name)
@@ -415,7 +414,7 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
 static void cbs_h264_free_pps(void *unit, uint8_t *content)
 {
 H264RawPPS *pps = (H264RawPPS*)content;
-av_buffer_unref(&pps->slice_group_id_ref);
+av_free(pps->slice_group_id);
 av_freep(&content);
 }
 
@@ -458,21 +457,21 @@ static void cbs_h264_free_slice(void *unit, uint8_t 
*content)
 static void cbs_h265_free_vps(void *unit, uint8_t *content)
 {
 H265RawVPS *vps = (H265RawVPS*)content;
-av_buffer_unref(&vps->extension_data.data_ref);
+av_free(vps->extension_data.data);
 av_freep(&content);
 }
 
 static void cbs_h265_free_sps(void *unit, uint8_t *content)
 {
 H265RawSPS *sps = (H265RawSPS*)content;
-av_buffer_unref(&sps->extension_data.data_ref);
+av_free(sps->extension_data.data);
 av_freep(&content);
 }
 
 static void cbs_h265_free_pps(void *unit, uint8_t *content)
 {
 H265RawPPS *pps = (H265RawPPS*)content;
-av_buffer_unref(&pps->extension_data.data_ref);
+av_free(pps->extension_data.data);
 av_freep(&content);
 }
 
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index 33e71fc234..1b357293ab 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -154,7 +154,6 @@ typedef struct H265RawVUI {
 typedef struct H265RawPSExtensionData {
 uint8_t *data;
 size_t bit_length;
-AVBufferRef *data_ref;
 } H265RawPSExtensionData;
 
 typedef struct H265RawVPS {
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread James Almer
This is more in line to how h264_ps handles it.

Signed-off-by: James Almer 
---
Not really going to make much of a difference seeing parameter sets
rarely show up in-band even in raw streams, but it's one less memcpy
anyway.

 libavcodec/cbs_h264.h |  4 +--
 libavcodec/cbs_h2645.c| 41 ++-
 libavcodec/cbs_h264_syntax_template.c | 19 ++---
 libavcodec/cbs_h265.h |  6 ++--
 libavcodec/cbs_h265_syntax_template.c | 21 +++---
 5 files changed, 44 insertions(+), 47 deletions(-)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index becea3adfe..239f3b6b90 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -420,8 +420,8 @@ typedef struct CodedBitstreamH264Context {
 
 // All currently available parameter sets.  These are updated when
 // any parameter set NAL unit is read/written with this context.
-H264RawSPS *sps[H264_MAX_SPS_COUNT];
-H264RawPPS *pps[H264_MAX_PPS_COUNT];
+AVBufferRef *sps[H264_MAX_SPS_COUNT];
+AVBufferRef *pps[H264_MAX_PPS_COUNT];
 
 // The currently active parameter sets.  These are updated when any
 // NAL unit refers to the relevant parameter set.  These pointers
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 580ca09f63..6c81a2e1b3 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -676,22 +676,23 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
-  const H26 ## h26n ## Raw ## 
ps_name *ps_var)  \
+  CodedBitstreamUnit *unit)  \
 { \
 CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
+H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
 unsigned int id = ps_var->id_element; \
 if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
" id : %d.\n", id); \
 return AVERROR_INVALIDDATA; \
 } \
-if (priv->ps_var[id] == priv->active_ ## ps_var) \
+if (priv->ps_var[id] && \
+(H26 ## h26n ## Raw ## ps_name *) priv->ps_var[id]->data == 
priv->active_ ## ps_var) \
 priv->active_ ## ps_var = NULL ; \
-av_freep(&priv->ps_var[id]); \
-priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
+av_buffer_unref(&priv->ps_var[id]); \
+priv->ps_var[id] = av_buffer_ref(unit->content_ref); \
 if (!priv->ps_var[id]) \
 return AVERROR(ENOMEM); \
-memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
 return 0; \
 }
 
@@ -725,7 +726,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -759,7 +760,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -872,7 +873,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_vps(ctx, vps);
+err = cbs_h265_replace_vps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -891,7 +892,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_sps(ctx, sps);
+err = cbs_h265_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -911,7 +912,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_pps(ctx, pps);
+err = cbs_h265_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1001,7 +1002,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1025,7 +1026,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1122,7 +1123,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamC

Re: [FFmpeg-devel] [PATCH 2/5] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread James Almer
On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
> ---
>  configure  | 6 --
>  doc/APIchanges | 3 +++
>  libavutil/hwcontext_cuda.c | 3 +++
>  libavutil/hwcontext_cuda.h | 1 +
>  libavutil/version.h| 2 +-
>  5 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 6626111ff2..9743de05d0 100755
> --- a/configure
> +++ b/configure
> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
> "VAEncPictureParameterBufferVP9"
>  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>  
>  if ! disabled ffnvcodec; then
> -check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
> -"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
> +check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
> +{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
> check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }

ffnvcodec_tmp?

>  fi
>  
>  check_cpp_condition winrt windows.h 
> "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ede5b186ae..bbefc8356e 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2018-05-xx - xx - lavu 56.18.101 - hwcontext_cuda.h
> +  Add AVCUDADeviceContext.stream.
> +
>  2018-04-xx - xx - lavu 56.18.100 - pixdesc.h
>Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
>  
> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> index 37827a770c..f3e81680e9 100644
> --- a/libavutil/hwcontext_cuda.c
> +++ b/libavutil/hwcontext_cuda.c
> @@ -386,6 +386,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, 
> const char *device,
>  goto error;
>  }
>  
> +// Setting stream to NULL will make functions automatically use the 
> default CUstream
> +hwctx->stream = NULL;
> +
>  cu->cuCtxPopCurrent(&dummy);
>  
>  hwctx->internal->is_allocated = 1;
> diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
> index 12dae8449e..81a0552cab 100644
> --- a/libavutil/hwcontext_cuda.h
> +++ b/libavutil/hwcontext_cuda.h
> @@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal 
> AVCUDADeviceContextInternal;
>   */
>  typedef struct AVCUDADeviceContext {
>  CUcontext cuda_ctx;
> +CUstream stream;
>  AVCUDADeviceContextInternal *internal;
>  } AVCUDADeviceContext;
>  
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 5185454d9b..186fe0794d 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -80,7 +80,7 @@
>  
>  #define LIBAVUTIL_VERSION_MAJOR  56
>  #define LIBAVUTIL_VERSION_MINOR  18
> -#define LIBAVUTIL_VERSION_MICRO 100
> +#define LIBAVUTIL_VERSION_MICRO 101
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> LIBAVUTIL_VERSION_MINOR, \
> 

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


Re: [FFmpeg-devel] [PATCH 13/13] avformat/mxfenc: Write transfer characteristic

2018-05-08 Thread Michael Niedermayer
On Tue, May 08, 2018 at 01:00:51PM +0200, Tomas Härdin wrote:
> mån 2018-05-07 klockan 12:38 +0200 skrev Michael Niedermayer:
> > > Signed-off-by: Michael Niedermayer 
> > 
> > +static int get_trc(UID ul, enum AVColorTransferCharacteristic trc)
> > +{
> > +switch (trc){
> > +case AVCOL_TRC_GAMMA28   :
> > +case AVCOL_TRC_GAMMA22   :
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00},
> >  16);
> > +return 0;
> > +case AVCOL_TRC_BT709 :
> > +case AVCOL_TRC_SMPTE170M :
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00},
> >  16);
> > +return 0;
> > +case AVCOL_TRC_SMPTE240M :
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x03,0x00,0x00},
> >  16);
> > +return 0;
> > +case AVCOL_TRC_BT1361_ECG:
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x05,0x00,0x00},
> >  16);
> > +return 0;
> > +case AVCOL_TRC_LINEAR:
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x06,0x00,0x00},
> >  16);
> > +return 0;
> > +case AVCOL_TRC_SMPTE428  :
> > +memcpy(ul, 
> > (UID){0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x08,0x04,0x01,0x01,0x01,0x01,0x07,0x00,0x00},
> >  16);
> > +return 0;
> > +default:
> > +return -1;
> > +}
> > +}
> > +
> >  static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const 
> > UID key, unsigned size)
> >  {
> >  MXFStreamContext *sc = st->priv_data;
> > @@ -1152,6 +1181,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> > AVStream *st, const UID ke
> >  int display_height;
> >  int f1, f2;
> >  unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5 + 5*8 + 6;
> > +UID transfer_ul = {0};
> > +
> >  if (sc->interlaced && sc->field_dominance)
> >  desc_size += 5;
> >  if (sc->signal_standard)
> > @@ -1164,6 +1195,8 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> > AVStream *st, const UID ke
> >  desc_size += 8 * 3;
> >  if (s->oformat == &ff_mxf_d10_muxer)
> >  desc_size += 8 + 8 + 8;
> > +if (get_trc(transfer_ul, st->codecpar->color_trc) >= 0)
> > +desc_size += 20;
> >  
> >  mxf_write_generic_desc(s, st, key, desc_size);
> >  
> > @@ -1305,6 +1338,12 @@ static void mxf_write_cdci_common(AVFormatContext 
> > *s, AVStream *st, const UID ke
> >  avio_wb32(pb, sc->aspect_ratio.num);
> >  avio_wb32(pb, sc->aspect_ratio.den);
> >  
> > +//Transfer characteristic
> > +if (transfer_ul[0]) {
> > +mxf_write_local_tag(pb, 16, 0x3210);
> > +avio_write(pb, transfer_ul, 16);
> > +};
> 
> Looks OK, but I didn't check the ULs for correctness

will apply

thx

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

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"


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


Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in cuda hwctx

2018-05-08 Thread Oscar Amoros Huguet
Hi!

Responding the per device question (sorry I can't make it shorter, the topic is 
quite dense).

A typical CUDA application uses a single cuda context, and multiple cuda 
streams to allow asynchronicity between cuda tasks (memory transfers, kernels, 
memsets) and make overlapping between those tasks possible, to save potentially 
a lot to execution time.

Even with Timo's changes, by default the behaviour of ffmpeg is the same. Each 
ffmpeg decoding instance creates a new cuda context by calling 
cuda_device_create.

The result of this, can be seen with (for instance) NVIDIA NSIGHT Visual Studio 
plugin timeline. Basically, the GPU changes it's cuda context every frame, as 
many times as videos you are decoding. This is less optimal than what is 
possible with Timo's additions.

The reason for the un-efficiency is partly because of the time the GPU needs to 
change between contexts (very small in recent hardware), but also and more 
importantly, because any cuda task executing in a cuda context, will never 
overlap with tasks in other cuda contexts. And this can imply a huge waste of 
time, specially if you need to download each frame from GPU to CPU.

Before Timo's changes, I could already use the same cuda contex for all 
decoding instances, using a CPU thread per video, that will not call 
cuda_device_create. Instead, each thread will allocate an ffmpeg hw_ctx, and 
manually set the cuda contex that already exists in the application. This way 
you solve the problem of switching contexts, and another problem. All cuda 
tasks enqueued by nvdec and ffmpeg for the decoding task, now are using the 
default stream of the same cuda context, so now I can synchronize this default 
stream, with another non-default stream in my aplication, making all the 
following cuda tasks to be asynchronous and able to overlap. Before, I had to 
copy the data from GPU to CPU in a blocking way, indirectly using the context 
created by ffmpeg. But still, the cuda tasks enqueued by nvdec and ffmpeg are 
not overlapping because they are not asynchronous, because they use the default 
cuda stream.

So now, we are using the same "device" or cuda context for all decoding feeds 
in the application.

Thanks to Timo's changes, besides the removal of some memory copies (very 
nice), now additionally to being able to manually set the cuda context, I can 
set a non-default cuda stream in the ffmpeg cuda hw_ctx struct, so all cuda 
tasks performed by ffmpeg and nvdec will use this stream, and can overlap with 
all my other cuda tasks, instead of blocking the gpu until they finish.

I our use case, this is a very relevant execution time improvement, and we are 
going to use this. So I hope this, or something similar can go into the master 
branch of the project.

Hope my explanation is useful.

Oscar

De: ffmpeg-devel  en nombre de wm4 

Enviado: martes, 8 de mayo de 2018 17:55
Para: ffmpeg-devel@ffmpeg.org
Asunto: Re: [FFmpeg-devel] [PATCH 3/6] avutil/hwcontext_cuda: add CUstream in 
cuda hwctx

On Tue, 8 May 2018 17:48:21 +0200
Timo Rothenpieler  wrote:

> Am 08.05.2018 um 17:26 schrieb wm4:
> > On Tue,  8 May 2018 15:31:29 +0200
> > Timo Rothenpieler  wrote:
> >
> >> ---
> >>   configure  | 6 --
> >>   doc/APIchanges | 3 ++-
> >>   libavutil/hwcontext_cuda.c | 3 +++
> >>   libavutil/hwcontext_cuda.h | 1 +
> >>   libavutil/version.h| 2 +-
> >>   5 files changed, 11 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/configure b/configure
> >> index 7c143238a8..cae8a235a4 100755
> >> --- a/configure
> >> +++ b/configure
> >> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  
> >> "VAEncPictureParameterBufferVP9"
> >>   check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
> >>
> >>   if ! disabled ffnvcodec; then
> >> -check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
> >> -"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
> >> +check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> >> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
> >> +{ test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && 
> >> check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
> >> +  "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
> >> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
> >>   fi
> >>
> >>   check_cpp_condition winrt windows.h 
> >> "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
> >> diff --git a/doc/APIchanges b/doc/APIchanges
> >> index f8ae6b0433..7a0a8522f9 100644
> >> --- a/doc/APIchanges
> >> +++ b/doc/APIchanges
> >> @@ -15,8 +15,9 @@ libavutil: 2017-10-21
> >>
> >>   API changes, most recent first:
> >>
> >> -2018-05-xx - xx - lavu 56.19.100 - hwcontext_cuda.h
> >> +2018-05-xx - xx, xx - lavu 56.19.100/101 - 
> >> hwc

Re: [FFmpeg-devel] [PATCH 1/3] vaapi_encode: Initialize the pointer

2018-05-08 Thread Mark Thompson
On 08/05/18 03:35, Xiang, Haihao wrote:
> On Mon, 2018-05-07 at 21:46 +0100, Mark Thompson wrote:
>> On 04/05/18 15:41, Haihao Xiang wrote:
>>> Otherwise it might use unitialized last_pic in av_assert0(last_pic)
>>>
>>> Signed-off-by: Haihao Xiang 
>>> ---
>>>  libavcodec/vaapi_encode.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
>>> index 36c85a3815..141e50c8ad 100644
>>> --- a/libavcodec/vaapi_encode.c
>>> +++ b/libavcodec/vaapi_encode.c
>>> @@ -760,7 +760,7 @@ fail:
>>>  static int vaapi_encode_truncate_gop(AVCodecContext *avctx)
>>>  {
>>>  VAAPIEncodeContext *ctx = avctx->priv_data;
>>> -VAAPIEncodePicture *pic, *last_pic, *next;
>>> +VAAPIEncodePicture *pic, *last_pic = NULL, *next;
>>>  
>>>  // Find the last picture we actually have input for.
>>>  for (pic = ctx->pic_start; pic; pic = pic->next) {
>>>
>>
>> How do you hit this?  last_pic should always get set.
>>
> 
> It was reported by some static analysis tools, but I agree with you that
> last_pic should get set in the code path, however if we consider
> vaapi_encode_truncate_gop() only,  last_pic will be uninitialized if ctx-
>> pic_start is non-NULL but ctx->pic_start->input_available is not set. How 
>> about
> to add av_assert0(!ctx->pic_start || ctx->pic_start->input_available) before 
> the
>  for () statement and remove av_assert0(last_pic)?

I think you mean "av_assert0(ctx->pic_start && 
ctx->pic_start->input_available)"?

But yes, that would be sensible.  I guess it's the assert on last_pic which is 
confusing the static analysis, since it kindof implies that it could be null.

- Mark


(I'm currently looking at refactoring all of this logic to assign picture types 
at encode time rather than input time - the current method makes it very hard 
to implement more complex reference structures.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] hwcontext_vaapi: Return error if can not find a VA RT format

2018-05-08 Thread Mark Thompson
On 08/05/18 03:53, Xiang, Haihao wrote:
> On Mon, 2018-05-07 at 21:48 +0100, Mark Thompson wrote:
>> On 04/05/18 15:41, Haihao Xiang wrote:
>>> Otherwise va_rt_format might be unitialized
>>>
>>> Signed-off-by: Haihao Xiang 
>>> ---
>>>  libavutil/hwcontext_vaapi.c | 5 +
>>>  1 file changed, 5 insertions(+)
>>>
>>> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
>>> index 7daaa951cc..e59042487d 100644
>>> --- a/libavutil/hwcontext_vaapi.c
>>> +++ b/libavutil/hwcontext_vaapi.c
>>> @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext
>>> *src_fc, AVFrame *dst,
>>>  va_rt_format = vaapi_format_map[i].rt_format;
>>>  }
>>>  
>>> +if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
>>> +av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");
>>> +return AVERROR(EINVAL);
>>> +}
>>> +
>>>  buffer_handle = desc->objects[0].fd;
>>>  buffer_desc.pixel_format = va_fourcc;
>>>  buffer_desc.width= src_fc->width;
>>>
>>
>> How would you hit this case?  Every fourcc in vaapi_drm_format_map is also
>> present in vaapi_format_map.
> 
> It is reported by static analysis tool as well. I think adding a check here 
> make
> s sure the relationship between vaapi_drm_format_map and vaapi_format_map. or
> how about av_assert0(i < FF_ARRAY_ELEMS(vaapi_format_map)) if you don't want 
> to
> add the if()?

An assert feels better to me - it's our bug if a fourcc in vaapi_drm_format_map 
isn't in vaapi_format_map, returning an error to the user is not helpful.

Thanks,

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


Re: [FFmpeg-devel] [PATCH 2/4] vaapi_encode_h265: Insert mastering display colour colume if needed

2018-05-08 Thread Mark Thompson
On 08/05/18 04:54, Xiang, Haihao wrote:
> On Mon, 2018-05-07 at 22:03 +0100, Mark Thompson wrote:
>> On 04/05/18 09:54, Xiang, Haihao wrote:
>>> On Thu, 2018-05-03 at 22:43 +0100, Mark Thompson wrote:
 On 03/05/18 04:07, Haihao Xiang wrote:
> '-sei xxx' is added to control SEI insertion, so far only mastering
> display colour colume is available for testing.

 Typo: "colume" (also in the commit title).

>>>
>>> Thanks for catching the typo, I will correct it in the new version of patch.
>>>
> v2: use the mastering display parameters from
> AVMasteringDisplayMetadata, set SEI_MASTERING_DISPLAY to 8 to match
> the H.264 part and take VAAPIEncodeH265Context::sei_needed as a ORed
> value so that we needn't check the correspoding SEI message again when
> writting the header.
>
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_encode_h265.c | 128
> -
>  1 file changed, 127 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/vaapi_encode_h265.c
> b/libavcodec/vaapi_encode_h265.c
> index 5203c6871d..326fe4fe66 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -24,15 +24,20 @@
>  #include "libavutil/avassert.h"
>  #include "libavutil/common.h"
>  #include "libavutil/opt.h"
> +#include "libavutil/mastering_display_metadata.h"
>  
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h265.h"
>  #include "hevc.h"
> +#include "hevc_sei.h"
>  #include "internal.h"
>  #include "put_bits.h"
>  #include "vaapi_encode.h"
>  
> +enum {
> +SEI_MASTERING_DISPLAY   = 0x08,
> +};
>  
>  typedef struct VAAPIEncodeH265Context {
>  unsigned int ctu_width;
> @@ -47,6 +52,9 @@ typedef struct VAAPIEncodeH265Context {
>  H265RawSPS sps;
>  H265RawPPS pps;
>  H265RawSlice slice;
> +H265RawSEI sei;
> +
> +H265RawSEIMasteringDiplayColourVolume mastering_display;
>  
>  int64_t last_idr_frame;
>  int pic_order_cnt;
> @@ -58,6 +66,7 @@ typedef struct VAAPIEncodeH265Context {
>  CodedBitstreamContext *cbc;
>  CodedBitstreamFragment current_access_unit;
>  int aud_needed;
> +int sei_needed;
>  } VAAPIEncodeH265Context;
>  
>  typedef struct VAAPIEncodeH265Options {
> @@ -65,6 +74,7 @@ typedef struct VAAPIEncodeH265Options {
>  int aud;
>  int profile;
>  int level;
> +int sei;
>  } VAAPIEncodeH265Options;
>  
>  
> @@ -175,6 +185,64 @@ fail:
>  return err;
>  }
>  
> +static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
> +VAAPIEncodePicture
> *pic,
> +int index, int *type,
> +char *data, size_t
> *data_len)
> +{
> +VAAPIEncodeContext  *ctx = avctx->priv_data;
> +VAAPIEncodeH265Context *priv = ctx->priv_data;
> +CodedBitstreamFragment   *au = &priv->current_access_unit;
> +int err, i;
> +
> +if (priv->sei_needed) {
> +if (priv->aud_needed) {
> +err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
> +if (err < 0)
> +goto fail;
> +priv->aud_needed = 0;
> +}
> +
> +memset(&priv->sei, 0, sizeof(priv->sei));
> +priv->sei.nal_unit_header  = (H265RawNALUnitHeader) {
> +.nal_unit_type = HEVC_NAL_SEI_PREFIX,
> +.nuh_layer_id  = 0,
> +.nuh_temporal_id_plus1 = 1,
> +};
> +
> +i = 0;
> +
> +if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
> +priv->sei.payload[i].payload_type =
> HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO;
> +priv->sei.payload[i].payload.mastering_display = priv-
>> mastering_display;
>
> +++i;
> +}
> +
> +priv->sei.payload_count = i;
> +av_assert0(priv->sei.payload_count > 0);
> +
> +err = vaapi_encode_h265_add_nal(avctx, au, &priv->sei);
> +if (err < 0)
> +goto fail;
> +priv->sei_needed = 0;
> +
> +err = vaapi_encode_h265_write_access_unit(avctx, data,
> data_len,
> au);
> +if (err < 0)
> +goto fail;
> +
> +ff_cbs_fragment_uninit(priv->cbc, au);
> +
> +*type = VAEncPackedHeaderRawData;
> +return 0;
> +} else {
> +return AVERROR_EOF;
> +}
> +
> +fail:
> +ff_cbs_fragment_uninit(priv->cbc, au);
> +return err;
> +}
> +

Re: [FFmpeg-devel] [PATCH] lavd/v4l2: Add ARGB and XRGB packed pixel formats

2018-05-08 Thread Carl Eugen Hoyos
2018-05-08 15:11 GMT+02:00, Anton Leontiev :
> Formats ARGB32, XRGB32, ABGR32, and XBGR32 were added to
> V4L2 instead of ill-defined deprecated RGB32/BGR32 pixel formats.

Just curious because I am quite sure I tested them:
Why / how are they ill-defined?

[...]

> diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c
> index 196c09b7fc..d48ae2efa1 100644
> --- a/libavdevice/v4l2-common.c
> +++ b/libavdevice/v4l2-common.c
> @@ -34,6 +34,10 @@ const struct fmt_map ff_fmt_conversion_table[] = {
>  { AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X },
>  { AV_PIX_FMT_BGR24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24   },
>  { AV_PIX_FMT_RGB24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24   },
> +{ AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_XBGR32  },
> +{ AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_XRGB32  },
> +{ AV_PIX_FMT_BGRA,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_ABGR32  },
> +{ AV_PIX_FMT_ARGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_ARGB32  },

Needs an "#ifdef" guard like below.

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


Re: [FFmpeg-devel] fate/hap : add test for hap encoding

2018-05-08 Thread Carl Eugen Hoyos
2018-05-08 11:45 GMT+02:00, Martin Vignali :
>>
>> > Sorry, i missread the code before writing the test, and
>> > didn't see it use float for one step.
>> > I will send a patch to remove these tests.
>>
>> Or just commit.
>>
>>
> Tests removed.

Thank you!

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_h2645: use simple data buffers for some parameter set extensions

2018-05-08 Thread Mark Thompson
On 08/05/18 21:48, James Almer wrote:
> There's no gain from using AVBufferRef for these, as no copies or
> references are ever made.
> 
> Signed-off-by: James Almer 
> ---
> There is however a raw copy of the struct storing these buffers,
> which is dangerous and fragile.
> This patch is in preparation to change how the above is handled.
> 
>  libavcodec/cbs_h264.h  |  1 -
>  libavcodec/cbs_h2645.c | 13 ++---
>  libavcodec/cbs_h265.h  |  1 -
>  3 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index 2219d9da8d..becea3adfe 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -197,7 +197,6 @@ typedef struct H264RawPPS {
>  uint16_t pic_size_in_map_units_minus1;
>  
>  uint8_t *slice_group_id;
> -AVBufferRef *slice_group_id_ref;
>  
>  uint8_t num_ref_idx_l0_default_active_minus1;
>  uint8_t num_ref_idx_l1_default_active_minus1;
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 64a1a2d1ee..580ca09f63 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -318,10 +318,9 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
> *gbc)
>  #define byte_alignment(rw) (get_bits_count(rw) % 8)
>  
>  #define allocate(name, size) do { \
> -name ## _ref = av_buffer_allocz(size); \
> -if (!name ## _ref) \
> +name = av_mallocz(size); \
> +if (!name) \
>  return AVERROR(ENOMEM); \
> -name = name ## _ref->data; \
>  } while (0)

This breaks other users of this macro (H.264 SEI).

The reason for using the bufferref here is not really that you might want to 
make more references to it.  Rather, it is for the alloc/free properties which 
give control to the user - for example, they can set one of these pointers to 
some internal static buffer they hold while setting _ref to null, and the free 
code still does the right thing (i.e. nothing).

I don't think that argument will necessarily apply to any of the values changed 
here - I doubt anyone will ever touch the FMO slice_group_id, and the H.265 PS 
extension data bits will need to have defined meanings (and therefore moved out 
of the "unknown future stuff" case) before they gets used.  Still, I'm not sure 
how you've gained anything - since the PS objects are refcounted in the 
following patch, how does this change actually help?

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


[FFmpeg-devel] [PATCH] avformat/mpegts: skip non-PMT tids earlier

2018-05-08 Thread Aman Gupta
From: Aman Gupta 

This mimics the logic flow in all the other callbacks
(pat_cb, sdt_cb, m4sl_cb), and avoids calling skip_identical()
for non PMT_TID packets.

Since skip_identical modifies internal state like
MpegTSSectionFilter.last_ver, this change prevents unnecessary
reprocessing on some streams which contain multiple tables in
the PMT pid. This can be observed with streams from certain US
cable providers, which include both tid=0x2 and another unspecified
tid=0xc0.
---
 libavformat/mpegts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 629631f60a..5c9ff73133 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2000,14 +2000,14 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 p = section;
 if (parse_section_header(h, &p, p_end) < 0)
 return;
+if (h->tid != PMT_TID)
+return;
 if (skip_identical(h, tssf))
 return;
 
 av_log(ts->stream, AV_LOG_TRACE, "sid=0x%x sec_num=%d/%d version=%d 
tid=%d\n",
 h->id, h->sec_num, h->last_sec_num, h->version, h->tid);
 
-if (h->tid != PMT_TID)
-return;
 if (!ts->scan_all_pmts && ts->skip_changes)
 return;
 
-- 
2.14.2

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_h2645: use simple data buffers for some parameter set extensions

2018-05-08 Thread James Almer
On 5/8/2018 7:17 PM, Mark Thompson wrote:
> On 08/05/18 21:48, James Almer wrote:
>> There's no gain from using AVBufferRef for these, as no copies or
>> references are ever made.
>>
>> Signed-off-by: James Almer 
>> ---
>> There is however a raw copy of the struct storing these buffers,
>> which is dangerous and fragile.
>> This patch is in preparation to change how the above is handled.
>>
>>  libavcodec/cbs_h264.h  |  1 -
>>  libavcodec/cbs_h2645.c | 13 ++---
>>  libavcodec/cbs_h265.h  |  1 -
>>  3 files changed, 6 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
>> index 2219d9da8d..becea3adfe 100644
>> --- a/libavcodec/cbs_h264.h
>> +++ b/libavcodec/cbs_h264.h
>> @@ -197,7 +197,6 @@ typedef struct H264RawPPS {
>>  uint16_t pic_size_in_map_units_minus1;
>>  
>>  uint8_t *slice_group_id;
>> -AVBufferRef *slice_group_id_ref;
>>  
>>  uint8_t num_ref_idx_l0_default_active_minus1;
>>  uint8_t num_ref_idx_l1_default_active_minus1;
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 64a1a2d1ee..580ca09f63 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -318,10 +318,9 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
>> *gbc)
>>  #define byte_alignment(rw) (get_bits_count(rw) % 8)
>>  
>>  #define allocate(name, size) do { \
>> -name ## _ref = av_buffer_allocz(size); \
>> -if (!name ## _ref) \
>> +name = av_mallocz(size); \
>> +if (!name) \
>>  return AVERROR(ENOMEM); \
>> -name = name ## _ref->data; \
>>  } while (0)
> 
> This breaks other users of this macro (H.264 SEI).
> 
> The reason for using the bufferref here is not really that you might want to 
> make more references to it.  Rather, it is for the alloc/free properties 
> which give control to the user - for example, they can set one of these 
> pointers to some internal static buffer they hold while setting _ref to null, 
> and the free code still does the right thing (i.e. nothing).
> 
> I don't think that argument will necessarily apply to any of the values 
> changed here - I doubt anyone will ever touch the FMO slice_group_id, and the 
> H.265 PS extension data bits will need to have defined meanings (and 
> therefore moved out of the "unknown future stuff" case) before they gets 
> used.  Still, I'm not sure how you've gained anything - since the PS objects 
> are refcounted in the following patch, how does this change actually help?

Removing the overhead of having these be AVBufferRef instead of a simple
malloc'ed array, since at least after a quick glance i couldn't find any
reason for it.

If you think keeping them as AVBufferRef is better/future proof then we
can drop this. The next patch works around the issue of memcpy'ing them
anyway.

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

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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread Mark Thompson
On 08/05/18 21:48, James Almer wrote:
> This is more in line to how h264_ps handles it.
> 
> Signed-off-by: James Almer 
> ---
> Not really going to make much of a difference seeing parameter sets
> rarely show up in-band even in raw streams, but it's one less memcpy
> anyway.
> 
>  libavcodec/cbs_h264.h |  4 +--
>  libavcodec/cbs_h2645.c| 41 ++-
>  libavcodec/cbs_h264_syntax_template.c | 19 ++---
>  libavcodec/cbs_h265.h |  6 ++--
>  libavcodec/cbs_h265_syntax_template.c | 21 +++---
>  5 files changed, 44 insertions(+), 47 deletions(-)
> 
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index becea3adfe..239f3b6b90 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -420,8 +420,8 @@ typedef struct CodedBitstreamH264Context {
>  
>  // All currently available parameter sets.  These are updated when
>  // any parameter set NAL unit is read/written with this context.
> -H264RawSPS *sps[H264_MAX_SPS_COUNT];
> -H264RawPPS *pps[H264_MAX_PPS_COUNT];
> +AVBufferRef *sps[H264_MAX_SPS_COUNT];
> +AVBufferRef *pps[H264_MAX_PPS_COUNT];

Can we keep the current xps variables as they are and add a separate xps_ref?  
That doesn't significantly increase the complexity of the replacement 
functions, and would avoid the ugly casting in the read/write templated code 
(indeed, I think it removes all changes there entirely).

>  
>  // The currently active parameter sets.  These are updated when any
>  // NAL unit refers to the relevant parameter set.  These pointers
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 580ca09f63..6c81a2e1b3 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -676,22 +676,23 @@ static int 
> cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
>  
>  #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
>  static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext 
> *ctx, \
> -  const H26 ## h26n ## Raw 
> ## ps_name *ps_var)  \
> +  CodedBitstreamUnit *unit)  
> \
>  { \
>  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
> +H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
>  unsigned int id = ps_var->id_element; \
>  if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
>  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
> " id : %d.\n", id); \
>  return AVERROR_INVALIDDATA; \
>  } \
> -if (priv->ps_var[id] == priv->active_ ## ps_var) \
> +if (priv->ps_var[id] && \
> +(H26 ## h26n ## Raw ## ps_name *) priv->ps_var[id]->data == 
> priv->active_ ## ps_var) \
>  priv->active_ ## ps_var = NULL ; \
> -av_freep(&priv->ps_var[id]); \
> -priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
> +av_buffer_unref(&priv->ps_var[id]); \
> +priv->ps_var[id] = av_buffer_ref(unit->content_ref); \
>  if (!priv->ps_var[id]) \
>  return AVERROR(ENOMEM); \
> -memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
>  return 0; \
>  }
>  
> @@ -725,7 +726,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_sps(ctx, sps);
> +err = cbs_h264_replace_sps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -759,7 +760,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_pps(ctx, pps);
> +err = cbs_h264_replace_pps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -872,7 +873,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_vps(ctx, vps);
> +err = cbs_h265_replace_vps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -891,7 +892,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_sps(ctx, sps);
> +err = cbs_h265_replace_sps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -911,7 +912,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_pps(ctx, pps);
> +err = cbs_h265_replace_pps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -1001,7 +1002,7 @@ static int 
> cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
>  if (err < 0)
> 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_h2645: use simple data buffers for some parameter set extensions

2018-05-08 Thread Mark Thompson
On 08/05/18 23:36, James Almer wrote:
> On 5/8/2018 7:17 PM, Mark Thompson wrote:
>> On 08/05/18 21:48, James Almer wrote:
>>> There's no gain from using AVBufferRef for these, as no copies or
>>> references are ever made.
>>>
>>> Signed-off-by: James Almer 
>>> ---
>>> There is however a raw copy of the struct storing these buffers,
>>> which is dangerous and fragile.
>>> This patch is in preparation to change how the above is handled.
>>>
>>>  libavcodec/cbs_h264.h  |  1 -
>>>  libavcodec/cbs_h2645.c | 13 ++---
>>>  libavcodec/cbs_h265.h  |  1 -
>>>  3 files changed, 6 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
>>> index 2219d9da8d..becea3adfe 100644
>>> --- a/libavcodec/cbs_h264.h
>>> +++ b/libavcodec/cbs_h264.h
>>> @@ -197,7 +197,6 @@ typedef struct H264RawPPS {
>>>  uint16_t pic_size_in_map_units_minus1;
>>>  
>>>  uint8_t *slice_group_id;
>>> -AVBufferRef *slice_group_id_ref;
>>>  
>>>  uint8_t num_ref_idx_l0_default_active_minus1;
>>>  uint8_t num_ref_idx_l1_default_active_minus1;
>>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>>> index 64a1a2d1ee..580ca09f63 100644
>>> --- a/libavcodec/cbs_h2645.c
>>> +++ b/libavcodec/cbs_h2645.c
>>> @@ -318,10 +318,9 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
>>> *gbc)
>>>  #define byte_alignment(rw) (get_bits_count(rw) % 8)
>>>  
>>>  #define allocate(name, size) do { \
>>> -name ## _ref = av_buffer_allocz(size); \
>>> -if (!name ## _ref) \
>>> +name = av_mallocz(size); \
>>> +if (!name) \
>>>  return AVERROR(ENOMEM); \
>>> -name = name ## _ref->data; \
>>>  } while (0)
>>
>> This breaks other users of this macro (H.264 SEI).
>>
>> The reason for using the bufferref here is not really that you might want to 
>> make more references to it.  Rather, it is for the alloc/free properties 
>> which give control to the user - for example, they can set one of these 
>> pointers to some internal static buffer they hold while setting _ref to 
>> null, and the free code still does the right thing (i.e. nothing).
>>
>> I don't think that argument will necessarily apply to any of the values 
>> changed here - I doubt anyone will ever touch the FMO slice_group_id, and 
>> the H.265 PS extension data bits will need to have defined meanings (and 
>> therefore moved out of the "unknown future stuff" case) before they gets 
>> used.  Still, I'm not sure how you've gained anything - since the PS objects 
>> are refcounted in the following patch, how does this change actually help?
> 
> Removing the overhead of having these be AVBufferRef instead of a simple
> malloc'ed array, since at least after a quick glance i couldn't find any
> reason for it.

The overhead will almost always be zero - none of these fields will ever appear 
in a "normal" stream (nobody uses FMO except to catch out people who think they 
support H.264 baseline profile, and as further H.265 parameter set extension 
bits are defined we will want to add them to be parsed explicitly).

> If you think keeping them as AVBufferRef is better/future proof then we
> can drop this. The next patch works around the issue of memcpy'ing them
> anyway.

So, unless you feel strongly I think it would be easier to keep treating them 
in the same way as the SEI data buffers, which do want this behaviour.

Thanks,

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


Re: [FFmpeg-devel] libavutil/encryption_info: Allow multiple init info.

2018-05-08 Thread Michael Niedermayer
On Mon, May 07, 2018 at 04:59:33PM -0700, Jacob Trimble wrote:
> On Mon, May 7, 2018 at 3:18 PM, Michael Niedermayer
>  wrote:
> > On Mon, Apr 23, 2018 at 11:03:57AM -0700, Jacob Trimble wrote:
> >> While integrating my encryption info changes, I noticed a problem with
> >> the init info structs.  I implemented them as side-data on the Stream.
> >> But this means there can only be one per stream.  However, there can
> >> be multiple 'pssh' atoms in a single stream (e.g. for key rotation or
> >> multiple key systems). (sorry for not noticing sooner)
> >>
> >> Attached is a patch to fix this by making the init info a
> >> singly-linked-list.  It is ABI compatible and is still easy to use and
> >> understand.  The alternative would be to break ABI and have the
> >> side-data methods return an array of pointers.  I could do that
> >> instead if that is preferable.
> >
> >>  encryption_info.c |  154 
> >> +++---
> >>  encryption_info.h |5 +
> >>  2 files changed, 106 insertions(+), 53 deletions(-)
> >> e5eecc73a6997bbd11541771372d38ea9c3972a7  
> >> 0001-libavutil-encryption_info-Allow-multiple-init-info.patch
> >> From bb941a77e882e93629d63d63059d0063b9519e29 Mon Sep 17 00:00:00 2001
> >> From: Jacob Trimble 
> >> Date: Mon, 23 Apr 2018 10:33:58 -0700
> >> Subject: [PATCH] libavutil/encryption_info: Allow multiple init info.
> >>
> >> It is possible for there to be multiple encryption init info structure.
> >> For example, to support multiple key systems or in key rotation.  This
> >> changes the AVEncryptionInitInfo struct to be a linked list so there
> >> can be multiple structs without breaking ABI.
> >>
> >> Signed-off-by: Jacob Trimble 
> >> ---
> >>  libavutil/encryption_info.c | 154 +++-
> >>  libavutil/encryption_info.h |   5 ++
> >>  2 files changed, 106 insertions(+), 53 deletions(-)
> >>
> >> diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c
> >> index 20a752d6b4..9935c10d74 100644
> >> --- a/libavutil/encryption_info.c
> >> +++ b/libavutil/encryption_info.c
> >> @@ -160,13 +160,16 @@ uint8_t *av_encryption_info_add_side_data(const 
> >> AVEncryptionInfo *info, size_t *
> >>  }
> >>
> >>  // The format of the AVEncryptionInitInfo side data:
> >> -// u32be system_id_size
> >> -// u32be num_key_ids
> >> -// u32be key_id_size
> >> -// u32be data_size
> >> -// u8[system_id_size] system_id
> >> -// u8[key_id_size][num_key_id] key_ids
> >> -// u8[data_size] data
> >> +// u32be init_info_count
> >> +// {
> >> +//   u32be system_id_size
> >> +//   u32be num_key_ids
> >> +//   u32be key_id_size
> >> +//   u32be data_size
> >> +//   u8[system_id_size] system_id
> >> +//   u8[key_id_size][num_key_id] key_ids
> >> +//   u8[data_size] data
> >> +// }[init_info_count]
> >>
> >>  #define FF_ENCRYPTION_INIT_INFO_EXTRA 16
> >>
> >> @@ -215,6 +218,7 @@ void av_encryption_init_info_free(AVEncryptionInitInfo 
> >> *info)
> >>  for (i = 0; i < info->num_key_ids; i++) {
> >>  av_free(info->key_ids[i]);
> >>  }
> >> +av_encryption_init_info_free(info->next);
> >>  av_free(info->system_id);
> >>  av_free(info->key_ids);
> >>  av_free(info->data);
> >> @@ -225,71 +229,115 @@ void 
> >> av_encryption_init_info_free(AVEncryptionInitInfo *info)
> >>  AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
> >>  const uint8_t *side_data, size_t side_data_size)
> >>  {
> >> -AVEncryptionInitInfo *info;
> >> +AVEncryptionInitInfo *ret = NULL, *info;
> >>  uint64_t system_id_size, num_key_ids, key_id_size, data_size, i;
> >> +uint64_t init_info_count;
> >>
> >> -if (!side_data || side_data_size < FF_ENCRYPTION_INIT_INFO_EXTRA)
> >> -return NULL;
> >> -
> >> -system_id_size = AV_RB32(side_data);
> > [...]
> >> +init_info_count = AV_RB32(side_data);
> >
> > i may be missing something but this looks like the meaning of the first
> > field changes, this thus doesnt look compatible to me
> 
> It changes the binary format of the side-data, but that was explicitly
> not part of ABI.  The fields in the structs are unchanged.  This would
> only cause a problem if the side data bytes were stored out-of-band
> from a different version of FFmpeg.

yes, right.
its side data that is neighter a C struct nor a well defined byte stream
its a opaque block that can only be passed to libavutil which then translates
it into a C struct.
its not new but it still feels clumsy to use this as means to pass data around


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

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread James Almer
On 5/8/2018 7:37 PM, Mark Thompson wrote:
> On 08/05/18 21:48, James Almer wrote:
>> This is more in line to how h264_ps handles it.
>>
>> Signed-off-by: James Almer 
>> ---
>> Not really going to make much of a difference seeing parameter sets
>> rarely show up in-band even in raw streams, but it's one less memcpy
>> anyway.
>>
>>  libavcodec/cbs_h264.h |  4 +--
>>  libavcodec/cbs_h2645.c| 41 ++-
>>  libavcodec/cbs_h264_syntax_template.c | 19 ++---
>>  libavcodec/cbs_h265.h |  6 ++--
>>  libavcodec/cbs_h265_syntax_template.c | 21 +++---
>>  5 files changed, 44 insertions(+), 47 deletions(-)
>>
>> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
>> index becea3adfe..239f3b6b90 100644
>> --- a/libavcodec/cbs_h264.h
>> +++ b/libavcodec/cbs_h264.h
>> @@ -420,8 +420,8 @@ typedef struct CodedBitstreamH264Context {
>>  
>>  // All currently available parameter sets.  These are updated when
>>  // any parameter set NAL unit is read/written with this context.
>> -H264RawSPS *sps[H264_MAX_SPS_COUNT];
>> -H264RawPPS *pps[H264_MAX_PPS_COUNT];
>> +AVBufferRef *sps[H264_MAX_SPS_COUNT];
>> +AVBufferRef *pps[H264_MAX_PPS_COUNT];
> 
> Can we keep the current xps variables as they are and add a separate xps_ref? 
>  That doesn't significantly increase the complexity of the replacement 
> functions, and would avoid the ugly casting in the read/write templated code 
> (indeed, I think it removes all changes there entirely).

If you mean making it

AVBufferRef *sps_ref[H264_MAX_SPS_COUNT];
AVBufferRef *pps_ref[H264_MAX_PPS_COUNT];
H264RawSPS *sps[H264_MAX_SPS_COUNT];
H264RawPPS *pps[H264_MAX_PPS_COUNT];

Then sure, it indeed simplifies the patch a lot. Will send an updated
version in a moment.

> 
>>  
>>  // The currently active parameter sets.  These are updated when any
>>  // NAL unit refers to the relevant parameter set.  These pointers
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 580ca09f63..6c81a2e1b3 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -676,22 +676,23 @@ static int 
>> cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
>>  
>>  #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
>>  static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext 
>> *ctx, \
>> -  const H26 ## h26n ## Raw 
>> ## ps_name *ps_var)  \
>> +  CodedBitstreamUnit *unit) 
>>  \
>>  { \
>>  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
>> +H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
>>  unsigned int id = ps_var->id_element; \
>>  if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
>>  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
>> " id : %d.\n", id); \
>>  return AVERROR_INVALIDDATA; \
>>  } \
>> -if (priv->ps_var[id] == priv->active_ ## ps_var) \
>> +if (priv->ps_var[id] && \
>> +(H26 ## h26n ## Raw ## ps_name *) priv->ps_var[id]->data == 
>> priv->active_ ## ps_var) \
>>  priv->active_ ## ps_var = NULL ; \
>> -av_freep(&priv->ps_var[id]); \
>> -priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
>> +av_buffer_unref(&priv->ps_var[id]); \
>> +priv->ps_var[id] = av_buffer_ref(unit->content_ref); \
>>  if (!priv->ps_var[id]) \
>>  return AVERROR(ENOMEM); \
>> -memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
>>  return 0; \
>>  }
>>  
>> @@ -725,7 +726,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
>> *ctx,
>>  if (err < 0)
>>  return err;
>>  
>> -err = cbs_h264_replace_sps(ctx, sps);
>> +err = cbs_h264_replace_sps(ctx, unit);
>>  if (err < 0)
>>  return err;
>>  }
>> @@ -759,7 +760,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
>> *ctx,
>>  if (err < 0)
>>  return err;
>>  
>> -err = cbs_h264_replace_pps(ctx, pps);
>> +err = cbs_h264_replace_pps(ctx, unit);
>>  if (err < 0)
>>  return err;
>>  }
>> @@ -872,7 +873,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
>> *ctx,
>>  if (err < 0)
>>  return err;
>>  
>> -err = cbs_h265_replace_vps(ctx, vps);
>> +err = cbs_h265_replace_vps(ctx, unit);
>>  if (err < 0)
>>  return err;
>>  }
>> @@ -891,7 +892,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
>> *ctx,
>>  if (err < 0)
>>  return err;
>>  
>> -err = cbs_h265_replace_sps(ctx, sps);
>> +err = cbs_h265_replace_sps(ctx, unit);
>>  if (err < 0)
>>  return err;
>>  }
>> @@ -91

[FFmpeg-devel] [PATCH v2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread James Almer
Removes unnecessary data copies, and fixes potential issues with
dangling references held in said lists.

Signed-off-by: James Almer 
---
 libavcodec/cbs_h264.h  |  2 ++
 libavcodec/cbs_h2645.c | 41 +
 libavcodec/cbs_h265.h  |  3 +++
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 2219d9da8d..d953c1f66b 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -421,6 +421,8 @@ typedef struct CodedBitstreamH264Context {
 
 // All currently available parameter sets.  These are updated when
 // any parameter set NAL unit is read/written with this context.
+AVBufferRef *sps_ref[H264_MAX_SPS_COUNT];
+AVBufferRef *pps_ref[H264_MAX_PPS_COUNT];
 H264RawSPS *sps[H264_MAX_SPS_COUNT];
 H264RawPPS *pps[H264_MAX_PPS_COUNT];
 
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 64a1a2d1ee..c391988b58 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -677,9 +677,10 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
-  const H26 ## h26n ## Raw ## 
ps_name *ps_var)  \
+  CodedBitstreamUnit *unit)  \
 { \
 CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
+H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
 unsigned int id = ps_var->id_element; \
 if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
@@ -688,11 +689,11 @@ static int cbs_h26 ## h26n ## _replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
 } \
 if (priv->ps_var[id] == priv->active_ ## ps_var) \
 priv->active_ ## ps_var = NULL ; \
-av_freep(&priv->ps_var[id]); \
-priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
-if (!priv->ps_var[id]) \
+av_buffer_unref(&priv->ps_var ## _ref[id]); \
+priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
+if (!priv->ps_var ## _ref[id]) \
 return AVERROR(ENOMEM); \
-memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
+priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## 
_ref[id]->data; \
 return 0; \
 }
 
@@ -726,7 +727,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -760,7 +761,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -873,7 +874,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_vps(ctx, vps);
+err = cbs_h265_replace_vps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -892,7 +893,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_sps(ctx, sps);
+err = cbs_h265_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -912,7 +913,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_pps(ctx, pps);
+err = cbs_h265_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1002,7 +1003,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1026,7 +1027,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1123,7 +1124,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_vps(ctx, vps);
+err = cbs_h265_replace_vps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1137,7 +1138,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext 
*ctx,
  

Re: [FFmpeg-devel] [PATCH 2/3] libavcodec: v4l2m2m: output AVDRMFrameDescriptor

2018-05-08 Thread Mark Thompson
On 08/05/18 19:24, Lukas Rusak wrote:
> This is V2 of my previous patch. I have worked together with Jorge to get 
> this working properly.
> We have made it so that AV_PIX_FMT_DRM_PRIME output can be selected by 
> setting avctx->pix_fmt.

This isn't how format selection in libavcodec works.  Look at 
AVCodecContext.get_format.

> This allows v4l2 to export the buffer so we can use it for zero-copy. If 
> AV_PIX_FMT_DRM_PRIME is
> not selected then the standard pixel formats will be used and the buffers 
> will not be exported.
> 
> ---
>  libavcodec/v4l2_buffers.c | 228 +++---
>  libavcodec/v4l2_buffers.h |   5 +-
>  libavcodec/v4l2_context.c |  40 ++-
>  libavcodec/v4l2_m2m.c |   4 +-
>  libavcodec/v4l2_m2m.h |   3 +
>  libavcodec/v4l2_m2m_dec.c |  23 
>  6 files changed, 257 insertions(+), 46 deletions(-)
> 
> diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
> index aef911f3bb..d715bc6a7c 100644
> --- a/libavcodec/v4l2_buffers.c
> +++ b/libavcodec/v4l2_buffers.c
> @@ -21,6 +21,7 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>  
> +#include 

Just  - the path is not fixed, so it needs to come from pkgconfig 
(in particular, this will fail with a libdrm default install which goes in 
"$PREFIX/include/libdrm").

This will also need v4l2 to depend on libdrm in configure.

>  #include 
>  #include 
>  #include 
> @@ -29,6 +30,7 @@
>  #include 
>  #include "libavcodec/avcodec.h"
>  #include "libavcodec/internal.h"
> +#include "libavutil/hwcontext.h"
>  #include "v4l2_context.h"
>  #include "v4l2_buffers.h"
>  #include "v4l2_m2m.h"
> @@ -203,7 +205,65 @@ static enum AVColorTransferCharacteristic 
> v4l2_get_color_trc(V4L2Buffer *buf)
>  return AVCOL_TRC_UNSPECIFIED;
>  }
>  
> -static void v4l2_free_buffer(void *opaque, uint8_t *unused)
> +static uint8_t * v4l2_get_drm_frame(V4L2Buffer *avbuf)
> +{
> +AVDRMFrameDescriptor *drm_desc = &avbuf->drm_frame;
> +AVDRMLayerDescriptor *layer;
> +
> +/* fill the DRM frame descriptor */
> +drm_desc->nb_objects = 1;
> +drm_desc->nb_layers = 1;
> +
> +layer = &drm_desc->layers[0];
> +layer->planes[0].object_index = 0;
> +layer->planes[0].offset = 0;
> +layer->planes[0].pitch = avbuf->plane_info[0].bytesperline;
> +
> +switch (avbuf->context->av_pix_fmt) {
> +case AV_PIX_FMT_NV12:
> +case AV_PIX_FMT_NV21:
> +
> +if (avbuf->num_planes > 1)
> +break;

What is this trying to test?  I think you're going to return something very 
invalid if it's true.

> +
> +layer->format = avbuf->context->av_pix_fmt == AV_PIX_FMT_NV12 ?
> +DRM_FORMAT_NV12 : DRM_FORMAT_NV21;
> +layer->nb_planes = 2;
> +
> +layer->planes[1].object_index = 0;
> +layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
> +avbuf->context->format.fmt.pix_mp.height;

Is that always true?  I would expect that some driver might want more vertical 
alignment (especially with tiled formats) and would provide this number 
somewhere else.

> +layer->planes[1].pitch = avbuf->plane_info[0].bytesperline;
> +break;
> +
> +case AV_PIX_FMT_YUV420P:
> +
> +if (avbuf->num_planes > 1)
> +break;
> +
> +layer->format = DRM_FORMAT_YUV420;
> +layer->nb_planes = 3;
> +
> +layer->planes[1].object_index = 0;
> +layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
> +avbuf->context->format.fmt.pix_mp.height;
> +layer->planes[1].pitch = avbuf->plane_info[0].bytesperline >> 1;
> +
> +layer->planes[2].object_index = 0;
> +layer->planes[2].offset = layer->planes[1].offset +
> +((avbuf->plane_info[0].bytesperline *
> +  avbuf->context->format.fmt.pix_mp.height) >> 2);
> +layer->planes[2].pitch = avbuf->plane_info[0].bytesperline >> 1;

Similarly here, and the pitch feels dubious as well.  Is 
plane_info[n].bytesperline set for n > 0?

> +break;
> +
> +default:

Probably want a more explicit failure in other cases.  Is there any 10-bit 
handling here yet (P010, I guess)?

> +break;
> +}
> +
> +return (uint8_t *) drm_desc;
> +}
> +
> +static void v4l2_free_buffer(void *opaque, uint8_t *data)
>  {
>  V4L2Buffer* avbuf = opaque;
>  V4L2m2mContext *s = buf_to_m2mctx(avbuf);
> @@ -227,27 +287,49 @@ static void v4l2_free_buffer(void *opaque, uint8_t 
> *unused)
>  }
>  }
>  
> -static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
> +static int v4l2_buffer_export_drm(V4L2Buffer* avbuf)
>  {
> -V4L2m2mContext *s = buf_to_m2mctx(in);
> +struct v4l2_exportbuffer expbuf;
> +int i, ret;
>  
> -if (plane >= in->num_planes)
> -return AVERROR(EINVAL);
> +for (i = 0; i < avbuf->num_planes; i++) {
> +memset(&expbuf, 0, sizeof(expbuf));
>  
> -/* even though most encoder

Re: [FFmpeg-devel] [PATCH v2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread Mark Thompson
On 09/05/18 00:12, James Almer wrote:
> Removes unnecessary data copies, and fixes potential issues with
> dangling references held in said lists.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/cbs_h264.h  |  2 ++
>  libavcodec/cbs_h2645.c | 41 +
>  libavcodec/cbs_h265.h  |  3 +++
>  3 files changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index 2219d9da8d..d953c1f66b 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -421,6 +421,8 @@ typedef struct CodedBitstreamH264Context {
>  
>  // All currently available parameter sets.  These are updated when
>  // any parameter set NAL unit is read/written with this context.
> +AVBufferRef *sps_ref[H264_MAX_SPS_COUNT];
> +AVBufferRef *pps_ref[H264_MAX_PPS_COUNT];
>  H264RawSPS *sps[H264_MAX_SPS_COUNT];
>  H264RawPPS *pps[H264_MAX_PPS_COUNT];
>  
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 64a1a2d1ee..c391988b58 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -677,9 +677,10 @@ static int 
> cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
>  
>  #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
>  static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext 
> *ctx, \
> -  const H26 ## h26n ## Raw 
> ## ps_name *ps_var)  \
> +  CodedBitstreamUnit *unit)  
> \
>  { \
>  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
> +H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
>  unsigned int id = ps_var->id_element; \
>  if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
>  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
> @@ -688,11 +689,11 @@ static int cbs_h26 ## h26n ## _replace_ ## 
> ps_var(CodedBitstreamContext *ctx, \
>  } \
>  if (priv->ps_var[id] == priv->active_ ## ps_var) \
>  priv->active_ ## ps_var = NULL ; \
> -av_freep(&priv->ps_var[id]); \
> -priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
> -if (!priv->ps_var[id]) \
> +av_buffer_unref(&priv->ps_var ## _ref[id]); \
> +priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
> +if (!priv->ps_var ## _ref[id]) \
>  return AVERROR(ENOMEM); \
> -memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
> +priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## 
> _ref[id]->data; \
>  return 0; \
>  }
>  
> @@ -726,7 +727,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_sps(ctx, sps);
> +err = cbs_h264_replace_sps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -760,7 +761,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_pps(ctx, pps);
> +err = cbs_h264_replace_pps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -873,7 +874,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_vps(ctx, vps);
> +err = cbs_h265_replace_vps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -892,7 +893,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_sps(ctx, sps);
> +err = cbs_h265_replace_sps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -912,7 +913,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h265_replace_pps(ctx, pps);
> +err = cbs_h265_replace_pps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -1002,7 +1003,7 @@ static int 
> cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_sps(ctx, sps);
> +err = cbs_h264_replace_sps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -1026,7 +1027,7 @@ static int 
> cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
>  if (err < 0)
>  return err;
>  
> -err = cbs_h264_replace_pps(ctx, pps);
> +err = cbs_h264_replace_pps(ctx, unit);
>  if (err < 0)
>  return err;
>  }
> @@ -1123,7 +1124,7 @@ static int 
> cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
>   

Re: [FFmpeg-devel] [PATCH v2] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread James Almer
On 5/8/2018 8:49 PM, Mark Thompson wrote:
> Ah.  I should have thought of this problem earlier - testing this patch, it 
> this breaks the VAAPI encoders because the parameter set structures there are 
> not reference counted (and shouldn't be - they are pointers to substructures 
> of the encoder context).
> 
> $ gdb --args ./ffmpeg_g -y -i in.mp4 -an -vaapi_device /dev/dri/renderD128 
> -vf 'format=nv12,hwupload' -c:v h264_vaapi out.h264
> ...
> Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
> 0x569bf65a in av_buffer_ref (buf=0x0) at src/libavutil/buffer.c:100
> 100 *ret = *buf;
> (gdb) bt
> #0  0x569bf65a in av_buffer_ref (buf=0x0) at 
> src/libavutil/buffer.c:100
> #1  0x564cd2ec in cbs_h264_replace_sps (ctx=0x58dbee40, 
> unit=0x58dbde40) at src/libavcodec/cbs_h2645.c:700
> #2  0x564ce12f in cbs_h264_write_nal_unit (ctx=0x58dbee40, 
> unit=0x58dbde40, pbc=0x7fffcf90) at src/libavcodec/cbs_h2645.c:1006
> #3  0x564ce943 in cbs_h2645_write_nal_unit (ctx=0x58dbee40, 
> unit=0x58dbde40) at src/libavcodec/cbs_h2645.c:1258
> #4  0x5649fd96 in ff_cbs_write_fragment_data (ctx=0x58dbee40, 
> frag=0x590da450) at src/libavcodec/cbs.c:284
> #5  0x56016784 in vaapi_encode_h264_write_access_unit 
> (avctx=0x581ce800, data=0x7fffd0c0 "\020\321\377\377\377\177", 
> data_len=0x7fffd4c0, au=0x590da450) at 
> src/libavcodec/vaapi_encode_h264.c:109
> #6  0x560169f8 in vaapi_encode_h264_write_sequence_header 
> (avctx=0x581ce800, data=0x7fffd0c0 "\020\321\377\377\377\177", 
> data_len=0x7fffd4c0) at src/libavcodec/vaapi_encode_h264.c:171
> #7  0x566e87e3 in ff_vaapi_encode_init (avctx=0x581ce800) at 
> src/libavcodec/vaapi_encode.c:1533
> #8  0x560194f1 in vaapi_encode_h264_init (avctx=0x581ce800) at 
> src/libavcodec/vaapi_encode_h264.c:971
> #9  0x56006218 in avcodec_open2 (avctx=0x581ce800, 
> codec=0x57937300 , options=0x581d0a18) at 
> src/libavcodec/utils.c:923
> #10 0x5567a655 in init_output_stream (ost=0x581d08c0, 
> error=0x7fffd8c0 "", error_len=1024) at src/fftools/ffmpeg.c:3485
> #11 0x5567269e in reap_filters (flush=0) at src/fftools/ffmpeg.c:1442
> #12 0x5567e88e in transcode_step () at src/fftools/ffmpeg.c:4587
> #13 0x5567e955 in transcode () at src/fftools/ffmpeg.c:4631
> #14 0x5567f1e5 in main (argc=12, argv=0x7fffe498) at 
> src/fftools/ffmpeg.c:4838
> 
> 
> Maybe if content_ref isn't set inside cbs_h26n_replace_xps() then make a new 
> buffer with that reference?  That still has the dangling pointer problem, 
> though no current user will set any of those fields.

Figures. I knew content_ref could technically be NULL, but i couldn't
find any such case within cbs or the bsfs, nor test vaapi.

I'll implement your suggestion, then.

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

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


[FFmpeg-devel] [PATCH v3] avcodec/cbs_h2645: use AVBufferRef to store list of active parameter sets

2018-05-08 Thread James Almer
Removes unnecessary data copies, and partially fixes potential issues
with dangling references held in said lists.

Signed-off-by: James Almer 
---
 libavcodec/cbs_h264.h  |  2 ++
 libavcodec/cbs_h2645.c | 46 --
 libavcodec/cbs_h265.h  |  3 +++
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 2219d9da8d..d953c1f66b 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -421,6 +421,8 @@ typedef struct CodedBitstreamH264Context {
 
 // All currently available parameter sets.  These are updated when
 // any parameter set NAL unit is read/written with this context.
+AVBufferRef *sps_ref[H264_MAX_SPS_COUNT];
+AVBufferRef *pps_ref[H264_MAX_PPS_COUNT];
 H264RawSPS *sps[H264_MAX_SPS_COUNT];
 H264RawPPS *pps[H264_MAX_PPS_COUNT];
 
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 64a1a2d1ee..1ce42c6950 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -677,9 +677,10 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
 
 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
-  const H26 ## h26n ## Raw ## 
ps_name *ps_var)  \
+  CodedBitstreamUnit *unit)  \
 { \
 CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
+H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
 unsigned int id = ps_var->id_element; \
 if (id > FF_ARRAY_ELEMS(priv->ps_var)) { \
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
@@ -688,11 +689,16 @@ static int cbs_h26 ## h26n ## _replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
 } \
 if (priv->ps_var[id] == priv->active_ ## ps_var) \
 priv->active_ ## ps_var = NULL ; \
-av_freep(&priv->ps_var[id]); \
-priv->ps_var[id] = av_malloc(sizeof(*ps_var)); \
-if (!priv->ps_var[id]) \
+av_buffer_unref(&priv->ps_var ## _ref[id]); \
+if (unit->content_ref) \
+priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
+else \
+priv->ps_var ## _ref[id] = av_buffer_alloc(sizeof(*ps_var)); \
+if (!priv->ps_var ## _ref[id]) \
 return AVERROR(ENOMEM); \
-memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
+priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## 
_ref[id]->data; \
+if (!unit->content_ref) \
+memcpy(priv->ps_var[id], ps_var, sizeof(*ps_var)); \
 return 0; \
 }
 
@@ -726,7 +732,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -760,7 +766,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -873,7 +879,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_vps(ctx, vps);
+err = cbs_h265_replace_vps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -892,7 +898,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_sps(ctx, sps);
+err = cbs_h265_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -912,7 +918,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_pps(ctx, pps);
+err = cbs_h265_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1002,7 +1008,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_sps(ctx, sps);
+err = cbs_h264_replace_sps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1026,7 +1032,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h264_replace_pps(ctx, pps);
+err = cbs_h264_replace_pps(ctx, unit);
 if (err < 0)
 return err;
 }
@@ -1123,7 +1129,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_replace_vps

Re: [FFmpeg-devel] [PATCH] avformat/mpegts: add skip_unknown_pids option

2018-05-08 Thread Aman Gupta
On Tue, May 8, 2018 at 12:54 PM, Aman Gupta  wrote:

> From: Aman Gupta 
>
> Allows the user to skip streams that are not advertised in the PMT.
>

Disregard this patch. It combines two different things (skip pmt, skip
streams without pmt) into one badly named option.

Aman


> ---
>  libavformat/mpegts.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 629631f60a..5464f48a8d 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -143,6 +143,7 @@ struct MpegTSContext {
>
>  int skip_changes;
>  int skip_clear;
> +int skip_unknown_pids;
>
>  int scan_all_pmts;
>
> @@ -176,6 +177,8 @@ static const AVOption options[] = {
>   {.i64 = 0}, 0, 1, 0 },
>  {"skip_clear", "skip clearing programs", offsetof(MpegTSContext,
> skip_clear), AV_OPT_TYPE_BOOL,
>   {.i64 = 0}, 0, 1, 0 },
> +{"skip_unknown_pids", "skip streams not advertised in PMT",
> offsetof(MpegTSContext, skip_unknown_pids), AV_OPT_TYPE_BOOL,
> + {.i64 = 0}, 0, 1, 0 },
>  { NULL },
>  };
>
> @@ -1058,7 +1061,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
>
>  /* stream not present in PMT */
>  if (!pes->st) {
> -if (ts->skip_changes)
> +if (ts->skip_changes || ts->skip_unknown_pids)
>  goto skip;
>
>  pes->st = avformat_new_stream(ts->stream, NULL);
> @@ -2011,6 +2014,8 @@ static void pmt_cb(MpegTSFilter *filter, const
> uint8_t *section, int section_len
>  if (!ts->scan_all_pmts && ts->skip_changes)
>  return;
>
> +if (ts->skip_unknown_pids && !get_program(ts, h->id))
> +return;
>  if (!ts->skip_clear)
>  clear_program(ts, h->id);
>
> --
> 2.14.2
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] vaapi_encode: Initialize the pointer

2018-05-08 Thread Xiang, Haihao
On Tue, 2018-05-08 at 22:34 +0100, Mark Thompson wrote:
> On 08/05/18 03:35, Xiang, Haihao wrote:
> > On Mon, 2018-05-07 at 21:46 +0100, Mark Thompson wrote:
> > > On 04/05/18 15:41, Haihao Xiang wrote:
> > > > Otherwise it might use unitialized last_pic in av_assert0(last_pic)
> > > > 
> > > > Signed-off-by: Haihao Xiang 
> > > > ---
> > > >  libavcodec/vaapi_encode.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > > > index 36c85a3815..141e50c8ad 100644
> > > > --- a/libavcodec/vaapi_encode.c
> > > > +++ b/libavcodec/vaapi_encode.c
> > > > @@ -760,7 +760,7 @@ fail:
> > > >  static int vaapi_encode_truncate_gop(AVCodecContext *avctx)
> > > >  {
> > > >  VAAPIEncodeContext *ctx = avctx->priv_data;
> > > > -VAAPIEncodePicture *pic, *last_pic, *next;
> > > > +VAAPIEncodePicture *pic, *last_pic = NULL, *next;
> > > >  
> > > >  // Find the last picture we actually have input for.
> > > >  for (pic = ctx->pic_start; pic; pic = pic->next) {
> > > > 
> > > 
> > > How do you hit this?  last_pic should always get set.
> > > 
> > 
> > It was reported by some static analysis tools, but I agree with you that
> > last_pic should get set in the code path, however if we consider
> > vaapi_encode_truncate_gop() only,  last_pic will be uninitialized if ctx-
> > > pic_start is non-NULL but ctx->pic_start->input_available is not set. How
> > > about
> > 
> > to add av_assert0(!ctx->pic_start || ctx->pic_start->input_available) before
> > the
> >  for () statement and remove av_assert0(last_pic)?
> 
> I think you mean "av_assert0(ctx->pic_start && ctx->pic_start-
> >input_available)"?
> 

No. I meant "av_assert0(!ctx->pic_start || ctx->pic_start->input_available)". I
thought ctx->pic_start might be NULL when vaapi_encode_truncate_gop() is called
in vaapi_encode.c, line 865. 

However testing a simple transcode of H265 showed input_image->pict_type is
always AV_PICTURE_TYPE_NONE (a bug?), which means vaapi_encode_truncate_gop() in
vaapi_encode.c, line 865 is never called. This piece of code was added in commit
c667c0979cbc2e04d1d00964b82ac49746caa43c to support forcing IDR frame. How do I
set a forced IDR via AVFrame.pict_type?

> But yes, that would be sensible.  I guess it's the assert on last_pic which is
> confusing the static analysis, since it kindof implies that it could be null.
> 
> - Mark
> 
> 
> (I'm currently looking at refactoring all of this logic to assign picture
> types at encode time rather than input time - the current method makes it very
> hard to implement more complex reference structures.)
> ___
> 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 2/3] hwcontext_vaapi: Return error if can not find a VA RT format

2018-05-08 Thread Xiang, Haihao
On Tue, 2018-05-08 at 22:37 +0100, Mark Thompson wrote:
> On 08/05/18 03:53, Xiang, Haihao wrote:
> > On Mon, 2018-05-07 at 21:48 +0100, Mark Thompson wrote:
> > > On 04/05/18 15:41, Haihao Xiang wrote:
> > > > Otherwise va_rt_format might be unitialized
> > > > 
> > > > Signed-off-by: Haihao Xiang 
> > > > ---
> > > >  libavutil/hwcontext_vaapi.c | 5 +
> > > >  1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> > > > index 7daaa951cc..e59042487d 100644
> > > > --- a/libavutil/hwcontext_vaapi.c
> > > > +++ b/libavutil/hwcontext_vaapi.c
> > > > @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext
> > > > *src_fc, AVFrame *dst,
> > > >  va_rt_format = vaapi_format_map[i].rt_format;
> > > >  }
> > > >  
> > > > +if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
> > > > +av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");
> > > > +return AVERROR(EINVAL);
> > > > +}
> > > > +
> > > >  buffer_handle = desc->objects[0].fd;
> > > >  buffer_desc.pixel_format = va_fourcc;
> > > >  buffer_desc.width= src_fc->width;
> > > > 
> > > 
> > > How would you hit this case?  Every fourcc in vaapi_drm_format_map is also
> > > present in vaapi_format_map.
> > 
> > It is reported by static analysis tool as well. I think adding a check here
> > make
> > s sure the relationship between vaapi_drm_format_map and vaapi_format_map.
> > or
> > how about av_assert0(i < FF_ARRAY_ELEMS(vaapi_format_map)) if you don't want
> > to
> > add the if()?
> 
> An assert feels better to me - it's our bug if a fourcc in
> vaapi_drm_format_map isn't in vaapi_format_map, returning an error to the user
> is not helpful.

Agree, I will update the patch.

Thanks
Haihao

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


Re: [FFmpeg-devel] [PATCH 2/4] vaapi_encode_h265: Insert mastering display colour colume if needed

2018-05-08 Thread Xiang, Haihao
On Tue, 2018-05-08 at 22:51 +0100, Mark Thompson wrote:
> On 08/05/18 04:54, Xiang, Haihao wrote:
> > On Mon, 2018-05-07 at 22:03 +0100, Mark Thompson wrote:
> > > On 04/05/18 09:54, Xiang, Haihao wrote:
> > > > On Thu, 2018-05-03 at 22:43 +0100, Mark Thompson wrote:
> > > > > On 03/05/18 04:07, Haihao Xiang wrote:
> > > > > > '-sei xxx' is added to control SEI insertion, so far only mastering
> > > > > > display colour colume is available for testing.
> > > > > 
> > > > > Typo: "colume" (also in the commit title).
> > > > > 
> > > > 
> > > > Thanks for catching the typo, I will correct it in the new version of
> > > > patch.
> > > > 
> > > > > > v2: use the mastering display parameters from
> > > > > > AVMasteringDisplayMetadata, set SEI_MASTERING_DISPLAY to 8 to match
> > > > > > the H.264 part and take VAAPIEncodeH265Context::sei_needed as a ORed
> > > > > > value so that we needn't check the correspoding SEI message again
> > > > > > when
> > > > > > writting the header.
> > > > > > 
> > > > > > Signed-off-by: Haihao Xiang 
> > > > > > ---
> > > > > >  libavcodec/vaapi_encode_h265.c | 128
> > > > > > -
> > > > > >  1 file changed, 127 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/libavcodec/vaapi_encode_h265.c
> > > > > > b/libavcodec/vaapi_encode_h265.c
> > > > > > index 5203c6871d..326fe4fe66 100644
> > > > > > --- a/libavcodec/vaapi_encode_h265.c
> > > > > > +++ b/libavcodec/vaapi_encode_h265.c
> > > > > > @@ -24,15 +24,20 @@
> > > > > >  #include "libavutil/avassert.h"
> > > > > >  #include "libavutil/common.h"
> > > > > >  #include "libavutil/opt.h"
> > > > > > +#include "libavutil/mastering_display_metadata.h"
> > > > > >  
> > > > > >  #include "avcodec.h"
> > > > > >  #include "cbs.h"
> > > > > >  #include "cbs_h265.h"
> > > > > >  #include "hevc.h"
> > > > > > +#include "hevc_sei.h"
> > > > > >  #include "internal.h"
> > > > > >  #include "put_bits.h"
> > > > > >  #include "vaapi_encode.h"
> > > > > >  
> > > > > > +enum {
> > > > > > +SEI_MASTERING_DISPLAY   = 0x08,
> > > > > > +};
> > > > > >  
> > > > > >  typedef struct VAAPIEncodeH265Context {
> > > > > >  unsigned int ctu_width;
> > > > > > @@ -47,6 +52,9 @@ typedef struct VAAPIEncodeH265Context {
> > > > > >  H265RawSPS sps;
> > > > > >  H265RawPPS pps;
> > > > > >  H265RawSlice slice;
> > > > > > +H265RawSEI sei;
> > > > > > +
> > > > > > +H265RawSEIMasteringDiplayColourVolume mastering_display;
> > > > > >  
> > > > > >  int64_t last_idr_frame;
> > > > > >  int pic_order_cnt;
> > > > > > @@ -58,6 +66,7 @@ typedef struct VAAPIEncodeH265Context {
> > > > > >  CodedBitstreamContext *cbc;
> > > > > >  CodedBitstreamFragment current_access_unit;
> > > > > >  int aud_needed;
> > > > > > +int sei_needed;
> > > > > >  } VAAPIEncodeH265Context;
> > > > > >  
> > > > > >  typedef struct VAAPIEncodeH265Options {
> > > > > > @@ -65,6 +74,7 @@ typedef struct VAAPIEncodeH265Options {
> > > > > >  int aud;
> > > > > >  int profile;
> > > > > >  int level;
> > > > > > +int sei;
> > > > > >  } VAAPIEncodeH265Options;
> > > > > >  
> > > > > >  
> > > > > > @@ -175,6 +185,64 @@ fail:
> > > > > >  return err;
> > > > > >  }
> > > > > >  
> > > > > > +static int vaapi_encode_h265_write_extra_header(AVCodecContext
> > > > > > *avctx,
> > > > > > +VAAPIEncodePicture
> > > > > > *pic,
> > > > > > +int index, int
> > > > > > *type,
> > > > > > +char *data, size_t
> > > > > > *data_len)
> > > > > > +{
> > > > > > +VAAPIEncodeContext  *ctx = avctx->priv_data;
> > > > > > +VAAPIEncodeH265Context *priv = ctx->priv_data;
> > > > > > +CodedBitstreamFragment   *au = &priv->current_access_unit;
> > > > > > +int err, i;
> > > > > > +
> > > > > > +if (priv->sei_needed) {
> > > > > > +if (priv->aud_needed) {
> > > > > > +err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
> > > > > > +if (err < 0)
> > > > > > +goto fail;
> > > > > > +priv->aud_needed = 0;
> > > > > > +}
> > > > > > +
> > > > > > +memset(&priv->sei, 0, sizeof(priv->sei));
> > > > > > +priv->sei.nal_unit_header  = (H265RawNALUnitHeader) {
> > > > > > +.nal_unit_type = HEVC_NAL_SEI_PREFIX,
> > > > > > +.nuh_layer_id  = 0,
> > > > > > +.nuh_temporal_id_plus1 = 1,
> > > > > > +};
> > > > > > +
> > > > > > +i = 0;
> > > > > > +
> > > > > > +if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
> > > > > > +priv->sei.payload[i].payload_type =
> > > > > > HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO;
> > > > > > +priv->sei.payload[i].payload.mastering_display = priv-
> > > > > > > mastering_display;
> > > > > > 
> > > > > > +++i

[FFmpeg-devel] [PATCH 1/2] avcodec/vaapi: slice_vertical_position starts from zero for the second field

2018-05-08 Thread Jerome Borsboom
Contrary to VC-1 spec, VAAPI expects the row address of the first
macroblock row in the first slice to start from zero for the second
field in a field interlaced picture.

Signed-off-by: Jerome Borsboom 
---
This patch set adds support for hardware decoding multi-slice field interlaced
pictures. With this patch set, the SA10180 test file decodes correctly with
VAAPI hardware acceleration. This was succesfully tested on Intel Haswell 
platform.

 libavcodec/vaapi_vc1.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index bdb5e24cc5..921ca6391b 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -467,6 +467,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer,
 const MpegEncContext *s = &v->s;
 VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private;
 VASliceParameterBufferVC1 slice_param;
+int mb_height;
 int err;
 
 /* Current bit buffer is beyond any marker for VC-1, so skip it */
@@ -475,12 +476,17 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer,
 size -= 4;
 }
 
+if (v->fcm == ILACE_FIELD)
+mb_height = avctx->coded_height + 31 >> 5;
+else
+mb_height = avctx->coded_height + 15 >> 4;
+
 slice_param = (VASliceParameterBufferVC1) {
 .slice_data_size = size,
 .slice_data_offset   = 0,
 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
 .macroblock_offset   = get_bits_count(&s->gb),
-.slice_vertical_position = s->mb_y,
+.slice_vertical_position = s->mb_y % mb_height,
 };
 
 err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-- 
2.13.6


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


  1   2   >