Re: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb query functions

2018-06-27 Thread Moritz Barsnick
On Tue, Jun 26, 2018 at 23:01:16 +0200, Carl Eugen Hoyos wrote:
> 2018-06-26 17:42 GMT+02:00, Moritz Barsnick :
> > +fail:
> > +av_free(p);
> > +av_free(geo);
> 
> I suspect this is incorrect, if it is correct, it should be a separate patch.

I agree. There were two misconceptions of mine in there, and a further
buglet. Patch drop, V2 to follow.

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


[FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb query functions

2018-06-27 Thread Moritz Barsnick
xcb_query_pointer_reply() and xcb_get_geometry_reply() can return NULL
if e.g. the X server closes or the connection is lost. This needs to
be checked in order to cleanly exit, because the returned pointers are
dereferenced later.

Signed-off-by: Moritz Barsnick 
---
 libavdevice/xcbgrab.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 6d142abd4f..ccab777c6e 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -404,7 +404,16 @@ static int xcbgrab_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 pc  = xcb_query_pointer(c->conn, c->screen->root);
 gc  = xcb_get_geometry(c->conn, c->screen->root);
 p   = xcb_query_pointer_reply(c->conn, pc, NULL);
+if (!p) {
+av_log(c, AV_LOG_ERROR, "Cannot get xcb pointer\n");
+return AVERROR(EIO);
+}
 geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+if (!geo) {
+av_log(c, AV_LOG_ERROR, "Cannot get xcb geometry\n");
+free(p);
+return AVERROR(EIO);
+}
 }
 
 if (c->follow_mouse && p->same_screen)
@@ -537,6 +546,10 @@ static int create_stream(AVFormatContext *s)
 
 gc  = xcb_get_geometry(c->conn, c->screen->root);
 geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+if (!geo) {
+av_log(c, AV_LOG_ERROR, "Cannot get xcb geometry\n");
+return AVERROR(EIO);
+}
 
 if (c->x + c->width > geo->width ||
 c->y + c->height > geo->height) {
-- 
2.14.4

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


Re: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb query functions

2018-06-27 Thread Moritz Barsnick
On Wed, Jun 27, 2018 at 10:21:51 +0200, Moritz Barsnick wrote:
> Subject: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: check return values of xcb 
> query functions

Sorry, I had told git send-email to use [PATCH v2]. *shrug*

> +if (!p) {
> +av_log(c, AV_LOG_ERROR, "Cannot get xcb pointer\n");

The value of the messages is debatable. Feel free to discuss.

This gives such an error using ffmpeg command line with this patch:
> [xcbgrab indev @ 0xa156740] Cannot get xcb pointer
> :1: Input/output error

The last line may suffice.

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


[FFmpeg-devel] [PATCH] lavfi/minterpolate: fix blending calc issue.

2018-06-27 Thread Jun Zhao
the right blending calc is:
(alpha * Frame_2 + (MAX - alpha) * Frame_1 + 512) >> 10

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_minterpolate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
index d534315..c6a5e63 100644
--- a/libavfilter/vf_minterpolate.c
+++ b/libavfilter/vf_minterpolate.c
@@ -1122,8 +1122,8 @@ static void interpolate(AVFilterLink *inlink, AVFrame 
*avf_out)
 for (y = 0; y < height; y++) {
 for (x = 0; x < width; x++) {
 avf_out->data[plane][x + y * avf_out->linesize[plane]] 
=
-  alpha  * 
mi_ctx->frames[2].avf->data[plane][x + y * 
mi_ctx->frames[2].avf->linesize[plane]] +
-((ALPHA_MAX - alpha) * 
mi_ctx->frames[1].avf->data[plane][x + y * 
mi_ctx->frames[1].avf->linesize[plane]] + 512) >> 10;
+(alpha  * mi_ctx->frames[2].avf->data[plane][x + y 
* mi_ctx->frames[2].avf->linesize[plane]] +
+ (ALPHA_MAX - alpha) * 
mi_ctx->frames[1].avf->data[plane][x + y * 
mi_ctx->frames[1].avf->linesize[plane]] + 512) >> 10;
 }
 }
 }
-- 
2.7.4

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


Re: [FFmpeg-devel] [GSOC] [PATCH] ESPCN super-resolution

2018-06-27 Thread Michael Niedermayer
On Tue, Jun 26, 2018 at 06:48:47PM +0300, Sergey Lavrushkin wrote:
> Hello,
> 
> This patch adds ESPCN super-resolution model to the srcnn filter,
> renamed to sr filter. Scaling is now performed inside the sr filter,
> so it does not require call to scale before it. But for SRCNN model
> scaling factor should be specified.

>  b/configure|8 
>  b/libavfilter/Makefile |2 
>  b/libavfilter/allfilters.c |2 
>  b/libavfilter/dnn_backend_native.c |  283 
>  b/libavfilter/dnn_backend_tf.c |   74 
>  b/libavfilter/dnn_espcn.h  |12637 
> +
>  b/libavfilter/dnn_interface.h  |4 
>  b/libavfilter/dnn_srcnn.h  |   14 
>  b/libavfilter/vf_sr.c  |  354 +
>  libavfilter/vf_srcnn.c |  250 
>  10 files changed, 13249 insertions(+), 379 deletions(-)
> eb384c9682c7b731d215cac042f5c75b48943319  adds_espcn_model.patch
> From 9146726c52aa5c3a8c34b25a122a39910b5f4b0b Mon Sep 17 00:00:00 2001
> From: Sergey Lavrushkin 
> Date: Thu, 14 Jun 2018 00:37:12 +0300
> Subject: [PATCH] Adds ESPCN super resolution filter merged with SRCNN filter.

this produces some build warnings:
CC  libavfilter/vf_sr.o
libavfilter/vf_sr.c: In function ‘filter_frame’:
libavfilter/vf_sr.c:272:19: warning: passing argument 2 of ‘sws_scale’ from 
incompatible pointer type [enabled by default]
   0, sr_context->sws_slice_h, out->data, out->linesize);
   ^
In file included from libavfilter/vf_sr.c:33:0:
./libswscale/swscale.h:217:5: note: expected ‘const uint8_t * const*’ but 
argument is of type ‘uint8_t **’
 int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
 ^
libavfilter/vf_sr.c:281:23: warning: passing argument 2 of ‘sws_scale’ from 
incompatible pointer type [enabled by default]
   0, sr_context->sws_slice_h, out->data + 1, out->linesize 
+ 1);
   ^
In file included from libavfilter/vf_sr.c:33:0:
./libswscale/swscale.h:217:5: note: expected ‘const uint8_t * const*’ but 
argument is of type ‘uint8_t **’
 int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
 ^
libavfilter/vf_sr.c:283:23: warning: passing argument 2 of ‘sws_scale’ from 
incompatible pointer type [enabled by default]
   0, sr_context->sws_slice_h, out->data + 2, out->linesize 
+ 2);
   ^
In file included from libavfilter/vf_sr.c:33:0:
./libswscale/swscale.h:217:5: note: expected ‘const uint8_t * const*’ but 
argument is of type ‘uint8_t **’
 int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
 ^
[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- 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] avutil/encryption_info: Fix documentation problem.

2018-06-27 Thread Michael Niedermayer
On Tue, Jun 26, 2018 at 09:32:14AM -0700, Jacob Trimble wrote:
> Signed-off-by: Jacob Trimble 
> ---
>  libavutil/encryption_info.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

thx

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

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



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


Re: [FFmpeg-devel] [PATCH] avutil/gitignore: Ignore integer test binary.

2018-06-27 Thread Michael Niedermayer
On Tue, Jun 26, 2018 at 09:35:05AM -0700, Jacob Trimble wrote:
> Signed-off-by: Jacob Trimble 
> ---
>  libavutil/tests/.gitignore | 1 +
>  1 file changed, 1 insertion(+)

will apply

thx

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

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data


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


Re: [FFmpeg-devel] [PATCH] libavutil/encryption_info: Add unit tests.

2018-06-27 Thread Michael Niedermayer
On Tue, Jun 26, 2018 at 09:28:01AM -0700, Jacob Trimble wrote:
> On Mon, Jun 25, 2018 at 5:30 PM Michael Niedermayer
>  wrote:
> >
> > On Fri, Jun 01, 2018 at 12:51:48PM -0700, Jacob Trimble wrote:
> > > Signed-off-by: Jacob Trimble 
> > > ---
> > >  libavutil/Makefile|   1 +
> > >  libavutil/encryption_info.h   |   2 +-
> > >  libavutil/tests/.gitignore|   2 +
> > >  libavutil/tests/encryption_info.c | 176 ++
> > >  tests/fate/libavutil.mak  |   4 +
> > >  tests/ref/fate/encryption-info|   0
> > >  6 files changed, 184 insertions(+), 1 deletion(-)
> > >  create mode 100644 libavutil/tests/encryption_info.c
> > >  create mode 100644 tests/ref/fate/encryption-info
> > >
> > > diff --git a/libavutil/Makefile b/libavutil/Makefile
> > > index d0632f16a6..9ed24cfc82 100644
> > > --- a/libavutil/Makefile
> > > +++ b/libavutil/Makefile
> > > @@ -200,6 +200,7 @@ TESTPROGS = adler32   
> > >   \
> > >  des \
> > >  dict\
> > >  display \
> > > +encryption_info \
> > >  error   \
> > >  eval\
> > >  file\
> >
> > > diff --git a/libavutil/encryption_info.h b/libavutil/encryption_info.h
> > > index 9140968fde..8fe7ebfe43 100644
> > > --- a/libavutil/encryption_info.h
> > > +++ b/libavutil/encryption_info.h
> > > @@ -129,7 +129,7 @@ typedef struct AVEncryptionInitInfo {
> > >   *
> > >   * @param subsample_count The number of subsamples.
> > >   * @param key_id_size The number of bytes in the key ID, should be 16.
> > > - * @param key_id_size The number of bytes in the IV, should be 16.
> > > + * @param iv_size The number of bytes in the IV, should be 16.
> > >   *
> > >   * @return The new AVEncryptionInfo structure, or NULL on error.
> > >   */
> >
> > How is this related to adding a test ?
> >
> 
> I guess it's unrelated, created a separate patch for it.
> 
> >
> >
> > > diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
> > > index 71f75a8ee9..9d90827954 100644
> > > --- a/libavutil/tests/.gitignore
> > > +++ b/libavutil/tests/.gitignore
> > > @@ -17,6 +17,7 @@
> > >  /dict
> > >  /display
> > >  /error
> > > +/encryption_info
> > >  /eval
> > >  /fifo
> > >  /file
> >
> > > @@ -24,6 +25,7 @@
> > >  /hmac
> > >  /hwdevice
> > >  /imgutils
> > > +/integer
> > >  /lfg
> > >  /lls
> > >  /log
> >
> > this also looks unrelated
> 
> Same.
> 
> >
> >
> > [...]
> > --
> > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Opposition brings concord. Out of discord comes the fairest harmony.
> > -- Heraclitus
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

>  libavutil/Makefile|1 
>  libavutil/tests/.gitignore|1 
>  libavutil/tests/encryption_info.c |  176 
> ++
>  tests/fate/libavutil.mak  |4 
>  tests/ref/fate/encryption-info|1 
>  5 files changed, 182 insertions(+), 1 deletion(-)
> 11d60eb571de4510ecbd313cacfaff2e6d89b16e  
> 0001-libavutil-encryption_info-Add-unit-tests-v2.patch
> From c97e44904020944e469faec18b9c279cb6d89b46 Mon Sep 17 00:00:00 2001
> From: Jacob Trimble 
> Date: Fri, 1 Jun 2018 11:38:05 -0700
> Subject: [PATCH] libavutil/encryption_info: Add unit tests.
> 
> Signed-off-by: Jacob Trimble 
> ---
>  libavutil/Makefile|   1 +
>  libavutil/tests/.gitignore|   1 +
>  libavutil/tests/encryption_info.c | 176 ++
>  tests/fate/libavutil.mak  |   4 +
>  tests/ref/fate/encryption-info|   0
>  5 files changed, 182 insertions(+)
>  create mode 100644 libavutil/tests/encryption_info.c
>  create mode 100644 tests/ref/fate/encryption-info

will apply

thx
[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data


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


Re: [FFmpeg-devel] [PATCH 4/5] avcodec/ra144: Fix integer overflow in ff_eval_refl()

2018-06-27 Thread Michael Niedermayer
On Fri, Jun 22, 2018 at 12:15:16AM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: -4096 * -524288 cannot be represented in type 
> 'int'
> Fixes: 
> 8650/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RA_144_fuzzer-5734816036159488
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ra144.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply

[...]
-- 
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 5/5] avcodec/dvbsubdec: Compute scoretab without iterating over pixels multiple times in compute_default_clut()

2018-06-27 Thread Michael Niedermayer
On Fri, Jun 22, 2018 at 12:15:17AM +0200, Michael Niedermayer wrote:
> Improves speed 102->2 sec
> Testcase: 
> 8655/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DVBSUB_fuzzer-6277869285146624
> Fixes: Timeout
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/dvbsubdec.c | 44 --
>  1 file changed, 25 insertions(+), 19 deletions(-)

will apply

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

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


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


Re: [FFmpeg-devel] [PATCH] avcodec/lagarith: Check that the range coded data stream is consistent when the probabilities indicate no data could have been coded.

2018-06-27 Thread Michael Niedermayer
On Thu, Jun 14, 2018 at 11:12:09PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 8638/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LAGARITH_fuzzer-5132046098759680
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/lagarith.c | 7 +++
>  1 file changed, 7 insertions(+)

will apply

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus


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


Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: add option to hide vsync warnings

2018-06-27 Thread Michael Niedermayer
On Wed, Jun 27, 2018 at 03:03:02AM +0200, Marton Balint wrote:
> 
> 
> On Wed, 27 Jun 2018, Michael Niedermayer wrote:
> 
> >On Tue, Jun 26, 2018 at 05:13:36PM +0530, Gyan Doshi wrote:
> >>
> >>
> >>On 26-06-2018 04:29 PM, Marton Balint wrote:
> >>
> Many users have queried/complained about the 'Past duration too large'
> messages.
> >>>
> >>>If the message is useless, then why not remove it entirely?
> >>
> >>Good question. Don't see the point but Michael added it (4e20e94921) so may
> >>have some use for it that I'm missing.
> >>
> >>Thoughts, Michael?
> >
> >I think, the condition shouldnt happen really
> 
> Why not? For CFR output frames are dropped if delta0 < -1.1, but an error is
> reported if delta0 < -0.6. So delta0 can remain indefinitely between -1.1
> and -0.6 spamming the console endlessly.
> 
> Or am I missing something?

well

if you have input like
timestamps: 1 2 4 5 7 9
durations:  1 2 1 2 1 1
then the warning should never trigger no matter what frame rate convertion is
used

It was intended IIRC to detect cases where the code misbeahves or where the
input/demuxer/parser is badly broken as in:

timestamps: 1 2 4  5 7  9
durations:  9 8 1 -3 7 99


Maybe the condition to display the warning is faulty


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

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


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


Re: [FFmpeg-devel] Fw: [PATCH] Refactor two near-identical clauses.

2018-06-27 Thread Shlomi Fish
On Sun, 17 Jun 2018 15:40:19 +0300
Shlomi Fish  wrote:

> On Sun, 17 Jun 2018 03:05:27 +0200
> Michael Niedermayer  wrote:
> 
> > On Tue, Jun 12, 2018 at 12:53:20PM +0300, Shlomi Fish wrote:  
> > > This message did not arrive to the list after three submissions.
> > > 
> > > Begin forwarded message:
> > > 
> > > Date: Tue, 12 Jun 2018 12:42:52 +0300
> > > From: Shlomi Fish 
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Shlomi Fish 
> > > Subject: [PATCH] Refactor two near-identical clauses.
> > > 
> > > 
> > > Placed under the Expat licence . All tests pass.
> > > ---
> > >  libavfilter/vf_weave.c | 33 ++---
> > >  1 file changed, 14 insertions(+), 19 deletions(-)
> > > 
> > > diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> > > index 037f5d1cf2..be371201e1 100644
> > > --- a/libavfilter/vf_weave.c
> > > +++ b/libavfilter/vf_weave.c
> > > @@ -23,6 +23,7 @@
> > >  #include "libavutil/pixdesc.h"
> > >  #include "avfilter.h"
> > >  #include "internal.h"
> > > +#include 
> > >  
> > >  typedef struct WeaveContext {
> > >  const AVClass *class;
> > > @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> > > *in) AVFilterLink *outlink = ctx->outputs[0];
> > >  AVFrame *out;
> > >  int i;
> > > +bool weave;
> > > +int field1, field2;
> > >  
> > >  if (!s->prev) {
> > >  s->prev = in;
> > > @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> > > *in) }
> > >  av_frame_copy_props(out, in);
> > >  
> > > +weave = (s->double_weave && !(inlink->frame_count_out & 1));
> > > +field1 = s->first_field * weave;
> > > +field2 = s->first_field * !weave;
> > >  for (i = 0; i < s->nb_planes; i++) {
> > > -if (s->double_weave && !(inlink->frame_count_out & 1)) {
> > > -av_image_copy_plane(out->data[i] + out->linesize[i] *
> > > s->first_field,
> > 
> > this seems to be corrupted by line breaks
> >   
> 
> Well, the git send-email email was silently dropped three times... See:
> 
> http://www.shlomifish.org/Files/files/code/0001-Refactor-two-near-identical-clauses.patch
> 
> also attached here. Email has sadly become unreliable.
> 

Ping! Please review.

> > [...]
> >   
> 
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

Every successful open source project will eventually spawn a sub‐project.
— http://www.shlomifish.org/humour/fortunes/osp_rules.html

Please reply to list if it's a mailing list post - http://shlom.in/reply .
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: add option to hide vsync warnings

2018-06-27 Thread Gyan Doshi

On 27-06-2018 05:13 PM, Michael Niedermayer wrote:



It was intended IIRC to detect cases where the code misbeahves or where the
input/demuxer/parser is badly broken as in:

timestamps: 1 2 4  5 7  9
durations:  9 8 1 -3 7 99


Maybe the condition to display the warning is faulty


It can be triggered by the following command form:

ffmpeg -f image2 -framerate X -i images -r Y -vsync vfr out

where 0.6*X < Y < X.

It always spams my console when I'm saving a live capture to MPEG-TS. 
This patch is less about the logic and more about a cleaner stderr.


Are you planning to revisit the logic? If not, I'd like to push this.

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


Re: [FFmpeg-devel] [PATCH] avcodec/qsvenc: fix version detection on cygwin

2018-06-27 Thread Timo Rothenpieler

applied



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] fftools/ffmpeg: add option to hide vsync warnings

2018-06-27 Thread Marton Balint



On Wed, 27 Jun 2018, Gyan Doshi wrote:


On 27-06-2018 05:13 PM, Michael Niedermayer wrote:



It was intended IIRC to detect cases where the code misbeahves or where the
input/demuxer/parser is badly broken as in:

timestamps: 1 2 4  5 7  9
durations:  9 8 1 -3 7 99


Maybe the condition to display the warning is faulty


It can be triggered by the following command form:

ffmpeg -f image2 -framerate X -i images -r Y -vsync vfr out

where 0.6*X < Y < X.

It always spams my console when I'm saving a live capture to MPEG-TS. 
This patch is less about the logic and more about a cleaner stderr.


Are you planning to revisit the logic? If not, I'd like to push this.


If we don't know why it spams the console or nobody is willing to fix it,
then decrease loglevel to verbose. I am strongly against adding a command
line option for this.

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


Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: add option to hide vsync warnings

2018-06-27 Thread Lou Logan
On Wed, Jun 27, 2018, at 10:00 AM, Marton Balint wrote:
>
> If we don't know why it spams the console or nobody is willing to fix it,
> then decrease loglevel to verbose. I am strongly against adding a command
> line option for this.

I was just about to give the same suggestion.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/8] avcodec/ac3dec: Check channel_map index

2018-06-27 Thread Michael Niedermayer
Fixes: out of array read
Fixes: 
8924/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_EAC3_fuzzer-5851861780267008

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

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index b1239a1845..eed8ce5b39 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1671,6 +1671,7 @@ dependent_frame:
 
 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
 uint64_t ich_layout = 
avpriv_ac3_channel_layout_tab[s->prev_output_mode & ~AC3_OUTPUT_LFEON];
+int channel_map_size = ff_ac3_channels_tab[s->output_mode & 
~AC3_OUTPUT_LFEON] + s->lfe_on;
 uint64_t channel_layout;
 int extend = 0;
 
@@ -1699,6 +1700,9 @@ dependent_frame:
 
ff_eac3_custom_channel_map_locations[ch][1]);
 if (index < 0)
 return AVERROR_INVALIDDATA;
+if (extend >= channel_map_size)
+return AVERROR_INVALIDDATA;
+
 extended_channel_map[index] = offset + 
channel_map[extend++];
 } else {
 int i;
@@ -1709,6 +1713,9 @@ dependent_frame:
 
1LL << i);
 if (index < 0)
 return AVERROR_INVALIDDATA;
+if (extend >= channel_map_size)
+return AVERROR_INVALIDDATA;
+
 extended_channel_map[index] = offset + 
channel_map[extend++];
 }
 }
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 3/8] avcodec/dpx: Check elements in 12bps planar path

2018-06-27 Thread Michael Niedermayer
Fixes: null pointer dereference
Fixes: 
8946/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DPX_fuzzer-5078915222601728

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

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index f75e2cbbca..cf23bb6ba1 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -395,12 +395,14 @@ static int decode_frame(AVCodecContext *avctx,
 if (elements == 4)
 *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
 } else {
-*dst[2]++ = read12in32(&buf, &rgbBuffer,
-   &n_datum, endian);
+if (elements >= 3)
+*dst[2]++ = read12in32(&buf, &rgbBuffer,
+   &n_datum, endian);
 *dst[0]++ = read12in32(&buf, &rgbBuffer,
&n_datum, endian);
-*dst[1]++ = read12in32(&buf, &rgbBuffer,
-   &n_datum, endian);
+if (elements >= 2)
+*dst[1]++ = read12in32(&buf, &rgbBuffer,
+   &n_datum, endian);
 if (elements == 4)
 *dst[3]++ = read12in32(&buf, &rgbBuffer,
&n_datum, endian);
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 1/8] avcodec/eac3dec: Check that channel_map does not contain more than EAC3_MAX_CHANNELS

2018-06-27 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ac3dec.c  | 27 ---
 libavcodec/ac3tab.c  | 18 ++
 libavcodec/ac3tab.h  |  2 ++
 libavcodec/eac3dec.c | 14 --
 4 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index dfa025cbcc..b1239a1845 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -106,25 +106,6 @@ static const uint8_t ac3_default_coeffs[8][5][2] = {
 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
 };
 
-static const uint64_t custom_channel_map_locations[16][2] = {
-{ 1, AV_CH_FRONT_LEFT },
-{ 1, AV_CH_FRONT_CENTER },
-{ 1, AV_CH_FRONT_RIGHT },
-{ 1, AV_CH_SIDE_LEFT },
-{ 1, AV_CH_SIDE_RIGHT },
-{ 0, AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER },
-{ 0, AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT },
-{ 0, AV_CH_BACK_CENTER },
-{ 0, AV_CH_TOP_CENTER },
-{ 0, AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT },
-{ 0, AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT },
-{ 0, AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT},
-{ 0, AV_CH_TOP_FRONT_CENTER },
-{ 0, AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT },
-{ 0, AV_CH_LOW_FREQUENCY_2 },
-{ 1, AV_CH_LOW_FREQUENCY },
-};
-
 /**
  * Symmetrical Dequantization
  * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization
@@ -1699,7 +1680,7 @@ dependent_frame:
 channel_layout = ich_layout;
 for (ch = 0; ch < 16; ch++) {
 if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) {
-channel_layout |= custom_channel_map_locations[ch][1];
+channel_layout |= ff_eac3_custom_channel_map_locations[ch][1];
 }
 }
 if (av_get_channel_layout_nb_channels(channel_layout) > 
EAC3_MAX_CHANNELS) {
@@ -1713,9 +1694,9 @@ dependent_frame:
 
 for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) {
 if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) {
-if (custom_channel_map_locations[ch][0]) {
+if (ff_eac3_custom_channel_map_locations[ch][0]) {
 int index = 
av_get_channel_layout_channel_index(channel_layout,
-
custom_channel_map_locations[ch][1]);
+
ff_eac3_custom_channel_map_locations[ch][1]);
 if (index < 0)
 return AVERROR_INVALIDDATA;
 extended_channel_map[index] = offset + 
channel_map[extend++];
@@ -1723,7 +1704,7 @@ dependent_frame:
 int i;
 
 for (i = 0; i < 64; i++) {
-if ((1LL << i) & custom_channel_map_locations[ch][1]) {
+if ((1LL << i) & 
ff_eac3_custom_channel_map_locations[ch][1]) {
 int index = 
av_get_channel_layout_channel_index(channel_layout,
 
1LL << i);
 if (index < 0)
diff --git a/libavcodec/ac3tab.c b/libavcodec/ac3tab.c
index d62d8bfbf5..bd88f32d92 100644
--- a/libavcodec/ac3tab.c
+++ b/libavcodec/ac3tab.c
@@ -314,3 +314,21 @@ const uint16_t ff_eac3_default_chmap[8] = {
 AC3_CHMAP_L |   AC3_CHMAP_R | AC3_CHMAP_L_SUR |
  AC3_CHMAP_R_SUR,
 AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_L_SUR |
  AC3_CHMAP_R_SUR
 };
+const uint64_t ff_eac3_custom_channel_map_locations[16][2] = {
+{ 1, AV_CH_FRONT_LEFT },
+{ 1, AV_CH_FRONT_CENTER },
+{ 1, AV_CH_FRONT_RIGHT },
+{ 1, AV_CH_SIDE_LEFT },
+{ 1, AV_CH_SIDE_RIGHT },
+{ 0, AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER },
+{ 0, AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT },
+{ 0, AV_CH_BACK_CENTER },
+{ 0, AV_CH_TOP_CENTER },
+{ 0, AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT },
+{ 0, AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT },
+{ 0, AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT},
+{ 0, AV_CH_TOP_FRONT_CENTER },
+{ 0, AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT },
+{ 0, AV_CH_LOW_FREQUENCY_2 },
+{ 1, AV_CH_LOW_FREQUENCY },
+};
diff --git a/libavcodec/ac3tab.h b/libavcodec/ac3tab.h
index ade6fb15e7..aa71acbce1 100644
--- a/libavcodec/ac3tab.h
+++ b/libavcodec/ac3tab.h
@@ -50,6 +50,8 @@ extern const uint16_t ff_ac3_fast_gain_tab[8];
 extern const uint16_t ff_eac3_default_chmap[8];
 extern const uint8_t  ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
 extern const uint8_t  ff_ac3_bin_to_band_tab[253];
+extern const uint64_t ff_eac3_custom_channel_map_locations[16][2];
+
 
 /** Custom channel map locations bitmask
  *  Other channels described in documentation:
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index fe97d29032..73067ded9d 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -349,8 +349,18 @

[FFmpeg-devel] [PATCH 6/8] avformat/movenc: Do not pass AVCodecParameters in avpriv_request_sample

2018-06-27 Thread Michael Niedermayer
Fixes: out of array read
Fixes: ffmpeg_crash_8.avi

Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
Caciulescu with AFLSmart
Signed-off-by: Michael Niedermayer 
---
 libavformat/movenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 00567db586..2603b9c95f 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -429,7 +429,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 
 if (hdr->substreamid == info->num_ind_sub + 1) {
 //info->num_ind_sub++;
-avpriv_request_sample(track->par, "Multiple independent 
substreams");
+avpriv_request_sample(mov, "Multiple independent substreams");
 ret = AVERROR_PATCHWELCOME;
 goto end;
 } else if (hdr->substreamid < info->num_ind_sub ||
@@ -439,7 +439,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 }
 } else {
 if (hdr->substreamid != 0) {
-avpriv_request_sample(track->par, "Multiple dependent 
substreams");
+avpriv_request_sample(mov, "Multiple dependent substreams");
 ret = AVERROR_PATCHWELCOME;
 goto end;
 }
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 4/8] avformat/movenc: Check that frame_types other than EAC3_FRAME_TYPE_INDEPENDENT have a supported substream id

2018-06-27 Thread Michael Niedermayer
Fixes: out of array access
Fixes: ffmpeg_bof_1.avi

Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
Caciulescu with AFLSmart
Signed-off-by: Michael Niedermayer 
---
 libavformat/movenc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index e2c5613f98..00567db586 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -437,6 +437,12 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 info->ec3_done = 1;
 goto concatenate;
 }
+} else {
+if (hdr->substreamid != 0) {
+avpriv_request_sample(track->par, "Multiple dependent 
substreams");
+ret = AVERROR_PATCHWELCOME;
+goto end;
+}
 }
 
 /* fill the info needed for the "dec3" atom */
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 5/8] avcodec/ac3_parser: Check init_get_bits8() for failure

2018-06-27 Thread Michael Niedermayer
Fixes: null pointer dereference
Fixes: ffmpeg_crash_6.avi

Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
Caciulescu with AFLSmart
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ac3_parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index f4618bf215..1e203ae6ac 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -162,7 +162,9 @@ int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const 
uint8_t *buf,
 return AVERROR(ENOMEM);
 hdr = *phdr;
 
-init_get_bits8(&gb, buf, size);
+err = init_get_bits8(&gb, buf, size);
+if (err < 0)
+return AVERROR_INVALIDDATA;
 err = ff_ac3_parse_header(&gb, hdr);
 if (err < 0)
 return AVERROR_INVALIDDATA;
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 7/8] avcodec/mpeg4videodec: Check read profile before setting it

2018-06-27 Thread Michael Niedermayer
Fixes: null pointer dereference
Fixes: ffmpeg_crash_7.avi

Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
Caciulescu with AFLSmart
Signed-off-by: Michael Niedermayer 
---
 libavcodec/mpeg4videodec.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index d0ebaac6e8..54a8496244 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1980,15 +1980,15 @@ static int mpeg4_decode_gop_header(MpegEncContext *s, 
GetBitContext *gb)
 return 0;
 }
 
-static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
+static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb, 
int *profile, int *level)
 {
 
-s->avctx->profile = get_bits(gb, 4);
-s->avctx->level   = get_bits(gb, 4);
+*profile = get_bits(gb, 4);
+*level   = get_bits(gb, 4);
 
 // for Simple profile, level 0
-if (s->avctx->profile == 0 && s->avctx->level == 8) {
-s->avctx->level = 0;
+if (*profile == 0 && *level == 8) {
+*level = 0;
 }
 
 return 0;
@@ -3211,13 +3211,19 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext 
*ctx, GetBitContext *gb)
 } else if (startcode == GOP_STARTCODE) {
 mpeg4_decode_gop_header(s, gb);
 } else if (startcode == VOS_STARTCODE) {
-mpeg4_decode_profile_level(s, gb);
-if (s->avctx->profile == FF_PROFILE_MPEG4_SIMPLE_STUDIO &&
-(s->avctx->level > 0 && s->avctx->level < 9)) {
+int profile, level;
+mpeg4_decode_profile_level(s, gb, &profile, &level);
+if (profile == FF_PROFILE_MPEG4_SIMPLE_STUDIO &&
+(level > 0 && level < 9)) {
 s->studio_profile = 1;
 next_start_code_studio(gb);
 extension_and_user_data(s, gb, 0);
+} else if (s->studio_profile) {
+avpriv_request_sample(s->avctx, "Mixes studio and non studio 
profile\n");
+return AVERROR_PATCHWELCOME;
 }
+s->avctx->profile = profile;
+s->avctx->level   = level;
 } else if (startcode == VISUAL_OBJ_STARTCODE) {
 if (s->studio_profile) {
 if ((ret = decode_studiovisualobject(ctx, gb)) < 0)
@@ -3238,6 +3244,7 @@ end:
 s->avctx->has_b_frames = !s->low_delay;
 
 if (s->studio_profile) {
+av_assert0(s->avctx->profile == FF_PROFILE_MPEG4_SIMPLE_STUDIO);
 if (!s->avctx->bits_per_raw_sample) {
 av_log(s->avctx, AV_LOG_ERROR, "Missing VOL header\n");
 return AVERROR_INVALIDDATA;
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 8/8] tools/target_dec_fuzzer: Also optionally fuzz with a parser

2018-06-27 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 42 ++-
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index a0e8943c82..ed9cbeaec8 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -140,6 +140,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 int (*decode_handler)(AVCodecContext *avctx, AVFrame *picture,
   int *got_picture_ptr,
   const AVPacket *avpkt) = NULL;
+AVCodecParserContext *parser = NULL;
+
 
 if (!c) {
 #ifdef FFMPEG_DECODER
@@ -164,7 +166,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 }
 
 AVCodecContext* ctx = avcodec_alloc_context3(NULL);
-if (!ctx)
+AVCodecContext* parser_avctx = avcodec_alloc_context3(NULL);
+if (!ctx || !parser_avctx)
 error("Failed memory allocation");
 
 ctx->max_pixels = 4096 * 4096; //To reduce false positive OOM and hangs
@@ -176,6 +179,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 ctx->height = bytestream2_get_le32(&gbc);
 ctx->bit_rate   = bytestream2_get_le64(&gbc);
 ctx->bits_per_coded_sample  = bytestream2_get_le32(&gbc);
+// Try to initialize a parser for this codec, note, this may fail 
which just means we test without one
+if (bytestream2_get_byte(&gbc) & 1)
+parser = av_parser_init(c->id);
 if (av_image_check_size(ctx->width, ctx->height, 0, ctx))
 ctx->width = ctx->height = 0;
 size -= 1024;
@@ -194,7 +200,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 error("Failed memory allocation");
 
 // Read very simple container
-AVPacket avpkt;
+AVPacket avpkt, parsepkt;
 while (data < end && it < maxiteration) {
 // Search for the TAG
 while (data + sizeof(fuzz_tag) < end) {
@@ -205,12 +211,34 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 if (data + sizeof(fuzz_tag) > end)
 data = end;
 
-FDBPrepare(&buffer, &avpkt, last, data - last);
+FDBPrepare(&buffer, &parsepkt, last, data - last);
 data += sizeof(fuzz_tag);
 last = data;
 
-// Iterate through all data
-while (avpkt.size > 0 && it++ < maxiteration) {
+while (parsepkt.size > 0) {
+
+if (parser) {
+av_init_packet(&avpkt);
+int ret = av_parser_parse2(parser, parser_avctx, &avpkt.data, 
&avpkt.size,
+   parsepkt.data, parsepkt.size,
+   parsepkt.pts, parsepkt.dts, 
parsepkt.pos);
+parsepkt.data += ret;
+parsepkt.size -= ret;
+parsepkt.pos  += ret;
+avpkt.pts = parser->pts;
+avpkt.dts = parser->dts;
+avpkt.pos = parser->pos;
+if ( parser->key_frame == 1 ||
+(parser->key_frame == -1 && parser->pict_type == 
AV_PICTURE_TYPE_I))
+avpkt.flags |= AV_PKT_FLAG_KEY;
+avpkt.flags |= parsepkt.flags & AV_PKT_FLAG_DISCARD;
+} else {
+avpkt = parsepkt;
+parsepkt.size = 0;
+}
+
+  // Iterate through all data
+  while (avpkt.size > 0 && it++ < maxiteration) {
 av_frame_unref(frame);
 int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
 
@@ -223,6 +251,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 ret = avpkt.size;
 avpkt.data += ret;
 avpkt.size -= ret;
+  }
 }
 }
 
@@ -238,6 +267,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 av_frame_free(&frame);
 avcodec_free_context(&ctx);
 av_freep(&ctx);
+avcodec_free_context(&parser_avctx);
+av_freep(&parser_avctx);
+av_parser_close(parser);
 FDBDesroy(&buffer);
 return 0;
 }
-- 
2.18.0

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


Re: [FFmpeg-devel] [PATCH 5/8] avcodec/ac3_parser: Check init_get_bits8() for failure

2018-06-27 Thread Paul B Mahol
On 6/27/18, Michael Niedermayer  wrote:
> Fixes: null pointer dereference
> Fixes: ffmpeg_crash_6.avi
>
> Found-by: Thuan Pham, Marcel Boehme, Andrew Santosa and Alexandru Razvan
> Caciulescu with AFLSmart
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ac3_parser.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>

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


Re: [FFmpeg-devel] [PATCH 6/8] avformat/movenc: Do not pass AVCodecParameters in avpriv_request_sample

2018-06-27 Thread James Almer
On 6/27/2018 3:11 PM, Michael Niedermayer wrote:
> Fixes: out of array read
> Fixes: ffmpeg_crash_8.avi
> 
> Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
> Caciulescu with AFLSmart
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/movenc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 00567db586..2603b9c95f 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -429,7 +429,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
> MOVTrack *track)
>  
>  if (hdr->substreamid == info->num_ind_sub + 1) {
>  //info->num_ind_sub++;
> -avpriv_request_sample(track->par, "Multiple independent 
> substreams");
> +avpriv_request_sample(mov, "Multiple independent 
> substreams");

mov->fc

>  ret = AVERROR_PATCHWELCOME;
>  goto end;
>  } else if (hdr->substreamid < info->num_ind_sub ||
> @@ -439,7 +439,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
> MOVTrack *track)
>  }
>  } else {
>  if (hdr->substreamid != 0) {
> -avpriv_request_sample(track->par, "Multiple dependent 
> substreams");
> +avpriv_request_sample(mov, "Multiple dependent substreams");

Same.

>  ret = AVERROR_PATCHWELCOME;
>  goto end;
>  }
> 

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


[FFmpeg-devel] [PATCH 1/2] ffmpeg: factorize input thread creation and destruction

2018-06-27 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 fftools/ffmpeg.c | 66 ++--
 1 file changed, 40 insertions(+), 26 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8d311a9ac8..8f94c5fff2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4053,49 +4053,63 @@ static void *input_thread(void *arg)
 return NULL;
 }
 
+static void free_input_thread(int i)
+{
+InputFile *f = input_files[i];
+AVPacket pkt;
+
+if (!f || !f->in_thread_queue)
+return;
+av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
+while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
+av_packet_unref(&pkt);
+
+pthread_join(f->thread, NULL);
+f->joined = 1;
+av_thread_message_queue_free(&f->in_thread_queue);
+}
+
 static void free_input_threads(void)
 {
 int i;
 
-for (i = 0; i < nb_input_files; i++) {
-InputFile *f = input_files[i];
-AVPacket pkt;
+for (i = 0; i < nb_input_files; i++)
+free_input_thread(i);
+}
 
-if (!f || !f->in_thread_queue)
-continue;
-av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
-while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
-av_packet_unref(&pkt);
+static int init_input_thread(int i)
+{
+int ret;
+InputFile *f = input_files[i];
 
-pthread_join(f->thread, NULL);
-f->joined = 1;
+if (nb_input_files == 1)
+return 0;
+
+if (f->ctx->pb ? !f->ctx->pb->seekable :
+strcmp(f->ctx->iformat->name, "lavfi"))
+f->non_blocking = 1;
+ret = av_thread_message_queue_alloc(&f->in_thread_queue,
+f->thread_queue_size, 
sizeof(AVPacket));
+if (ret < 0)
+return ret;
+
+if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
+av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase 
`ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
 av_thread_message_queue_free(&f->in_thread_queue);
+return AVERROR(ret);
 }
+
+return 0;
 }
 
 static int init_input_threads(void)
 {
 int i, ret;
 
-if (nb_input_files == 1)
-return 0;
-
 for (i = 0; i < nb_input_files; i++) {
-InputFile *f = input_files[i];
-
-if (f->ctx->pb ? !f->ctx->pb->seekable :
-strcmp(f->ctx->iformat->name, "lavfi"))
-f->non_blocking = 1;
-ret = av_thread_message_queue_alloc(&f->in_thread_queue,
-f->thread_queue_size, 
sizeof(AVPacket));
+ret = init_input_thread(i);
 if (ret < 0)
 return ret;
-
-if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
-av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to 
increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
-av_thread_message_queue_free(&f->in_thread_queue);
-return AVERROR(ret);
-}
 }
 return 0;
 }
-- 
2.16.4

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


[FFmpeg-devel] [PATCH 2/2] ffmpeg: fix -stream_loop with multiple inputs

2018-06-27 Thread Marton Balint
The input thread need to be properly cleaned up and re-initalized before we can
start reading again in threaded mode. (threaded input reading is used when
there are mode than one input file).

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

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8f94c5fff2..e2cd78fcd0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4251,7 +4251,7 @@ static int process_input(int file_index)
 AVFormatContext *is;
 InputStream *ist;
 AVPacket pkt;
-int ret, i, j;
+int ret, thread_ret, i, j;
 int64_t duration;
 int64_t pkt_dts;
 
@@ -4274,7 +4274,15 @@ static int process_input(int file_index)
 avcodec_flush_buffers(avctx);
 }
 }
+#if HAVE_THREADS
+free_input_thread(file_index);
+#endif
 ret = seek_to_start(ifile, is);
+#if HAVE_THREADS
+thread_ret = init_input_thread(file_index);
+if (thread_ret < 0)
+return thread_ret;
+#endif
 if (ret < 0)
 av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n");
 else
-- 
2.16.4

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


Re: [FFmpeg-devel] [PATCH 6/8] avformat/movenc: Do not pass AVCodecParameters in avpriv_request_sample

2018-06-27 Thread Michael Niedermayer
On Wed, Jun 27, 2018 at 03:54:06PM -0300, James Almer wrote:
> On 6/27/2018 3:11 PM, Michael Niedermayer wrote:
> > Fixes: out of array read
> > Fixes: ffmpeg_crash_8.avi
> > 
> > Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
> > Caciulescu with AFLSmart
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/movenc.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 00567db586..2603b9c95f 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -429,7 +429,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket 
> > *pkt, MOVTrack *track)
> >  
> >  if (hdr->substreamid == info->num_ind_sub + 1) {
> >  //info->num_ind_sub++;
> > -avpriv_request_sample(track->par, "Multiple independent 
> > substreams");
> > +avpriv_request_sample(mov, "Multiple independent 
> > substreams");
> 
> mov->fc
> 
> >  ret = AVERROR_PATCHWELCOME;
> >  goto end;
> >  } else if (hdr->substreamid < info->num_ind_sub ||
> > @@ -439,7 +439,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket 
> > *pkt, MOVTrack *track)
> >  }
> >  } else {
> >  if (hdr->substreamid != 0) {
> > -avpriv_request_sample(track->par, "Multiple dependent 
> > substreams");
> > +avpriv_request_sample(mov, "Multiple dependent 
> > substreams");
> 
> Same.

will change it but this function used mov before. ill change that too

thx


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

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato


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


[FFmpeg-devel] [PATCH] h264_slice: Fix return of incomplete frames from decoder

2018-06-27 Thread John Stebbins
When not using libavformat for demuxing, AVCodecContext.has_b_frames
gets set too late causing the recovery frame heuristic in h264_refs to
incorrectly flag an early frame as recovered.

This patch sets has_b_frames earlier to prevent improperly flagging the
frame as recovered.
---
 libavcodec/h264_slice.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index d71ddbe9ba..ede9a1a6ea 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1407,6 +1407,11 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
 
 sps = h->ps.sps;
 
+if (sps && sps->bitstream_restriction_flag &&
+h->avctx->has_b_frames < sps->num_reorder_frames) {
+h->avctx->has_b_frames = sps->num_reorder_frames;
+}
+
 last_pic_droppable   = h->droppable;
 last_pic_structure   = h->picture_structure;
 h->droppable = (nal->ref_idc == 0);
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH 3/8] avcodec/dpx: Check elements in 12bps planar path

2018-06-27 Thread Carl Eugen Hoyos
2018-06-27 20:11 GMT+02:00, Michael Niedermayer :
> Fixes: null pointer dereference
> Fixes:
> 8946/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DPX_fuzzer-5078915222601728
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/dpx.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
> index f75e2cbbca..cf23bb6ba1 100644
> --- a/libavcodec/dpx.c
> +++ b/libavcodec/dpx.c
> @@ -395,12 +395,14 @@ static int decode_frame(AVCodecContext *avctx,
>  if (elements == 4)
>  *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
>  } else {
> -*dst[2]++ = read12in32(&buf, &rgbBuffer,
> -   &n_datum, endian);
> +if (elements >= 3)
> +*dst[2]++ = read12in32(&buf, &rgbBuffer,
> +   &n_datum, endian);
>  *dst[0]++ = read12in32(&buf, &rgbBuffer,
> &n_datum, endian);
> -*dst[1]++ = read12in32(&buf, &rgbBuffer,
> -   &n_datum, endian);
> +if (elements >= 2)
> +*dst[1]++ = read12in32(&buf, &rgbBuffer,
> +   &n_datum, endian);
>  if (elements == 4)
>  *dst[3]++ = read12in32(&buf, &rgbBuffer,
> &n_datum, endian);

Looks good to me, please commit.

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


[FFmpeg-devel] [GSoC] FFserver: Add HLS and DASH

2018-06-27 Thread Stephan Holljes
This patchset took embarrassingly long to produce. I first took a few wrong
turns, but I think I'm now at a point where I reached the limits of the
public server API in libavformat. The main problem is that I cannot set
options on clients that are accepted through http_accept(), for example
a timeout on socket operations, as currently a client that disconnects while
being sent a file causes the sending thread to loop infintely in a poll()-call.
I wonder if adding a different library handling the http server (as planned for
the future) would be better done now rather than later. 

Another bug I cannot really explain so far (that may be because of my
unfamiliarity with DASH) is that with longer files the DASH stream starts to
repeat some fragments (at least in mpv) in weird ways. HLS does not have this
problem.

Another thing that is not yet handled are unmuxable codecs.

The patchset also includes some cleanup and other various fixes.


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


[FFmpeg-devel] [PATCH 04/17] configreader.c: Remove trailing whitespace

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 configreader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configreader.c b/configreader.c
index 88bba26..3f5b896 100644
--- a/configreader.c
+++ b/configreader.c
@@ -76,7 +76,7 @@ int configs_parse(lua_State *L)
 
 luaL_checktype(L, -1, LUA_TTABLE);
 lua_pushnil(L);
-
+
 // iterate servers
 while (lua_next(L, -2) != 0) {
 nb_configs++;
@@ -167,7 +167,7 @@ int configs_parse(lua_State *L)
 lua_pushnumber(L, ++index);
 }
 lua_pop(L, 1);
-
+
 } else {
 fprintf(stderr, "Warning unknown key (%s) in stream 
configuration.\n", key);
 }
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 03/17] lavfhttpd.c: Remove trailing whitespaces

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 lavfhttpd.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/lavfhttpd.c b/lavfhttpd.c
index bc856af..3f29ec4 100644
--- a/lavfhttpd.c
+++ b/lavfhttpd.c
@@ -15,7 +15,7 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
- 
+
 #ifndef LAVFHTTPD_H
 #define LAVFHTTPD_H
 
@@ -29,30 +29,30 @@ int lavfhttpd_init(void **server, struct HTTPDConfig config)
 int ret;
 AVDictionary *opts = NULL;
 AVIOContext *server_ctx = NULL;
-
+
 snprintf(out_uri, 1024, "http://%s:%d";, config.bind_address, config.port);
-
+
 avformat_network_init();
-
+
 if ((ret = av_dict_set(&opts, "listen", "2", 0)) < 0) {
 av_log(opts, AV_LOG_ERROR, "Failed to set listen mode for server: 
%s\n", av_err2str(ret));
 av_free(opts);
 return -1;
 }
-
+
 if ((ret = av_dict_set_int(&opts, "listen_timeout", config.accept_timeout, 
0)) < 0) {
 av_log(opts, AV_LOG_ERROR, "Failed to set listen_timeout for server: 
%s\n", av_err2str(ret));
 av_free(opts);
 return -1;
 }
-
+
 if ((ret = avio_open2(&server_ctx, out_uri, AVIO_FLAG_WRITE, NULL, &opts)) 
< 0) {
 av_log(server, AV_LOG_ERROR, "Failed to open server: %s\n", 
av_err2str(ret));
 av_free(opts);
 return -1;
 }
 av_free(opts);
-
+
 *server = server_ctx;
 return 0;
 }
@@ -106,11 +106,11 @@ int lavfhttpd_accept(void *server, struct HTTPClient 
**client, int reply_code)
 ret2 = HTTPD_CLIENT_ERROR;
 reply_code2 = 400;
 }
-
+
 if ((ret = av_opt_set_int(client_ctx, "reply_code", reply_code2, 
AV_OPT_SEARCH_CHILDREN)) < 0) {
 av_log(client_ctx, AV_LOG_WARNING, "Failed to set reply_code: %s.\n", 
av_err2str(ret));
 }
-
+
 *client = client_http;
 return ret2;
 }
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 09/17] ffserver.c: simplify cleanup in run_server()

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 ffserver.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index cc7dc6c..f128b55 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -646,18 +646,10 @@ end:
 }
 av_free(winfos_p[stream_index]);
 av_free(w_threads_p[stream_index]);
-// pubs[stream_index] could be null if the file could not be opened
+// pubs[stream_index] could be null if the file could not be opened or 
mkv was not requested
 if (pubs[stream_index])
 publisher_free(pubs[stream_index]);
 }
-av_free(rinfos);
-av_free(winfos_p);
-av_free(r_threads);
-av_free(w_threads_p);
-av_free(pubs);
-av_free(ifmt_ctxs);
-
-return NULL;
 
 error_cleanup:
 av_free(rinfos);
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 08/17] segment.c: set *seg_p to NULL earlier so it is NULL for every error condition.

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 segment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/segment.c b/segment.c
index 8b76510..9ec144f 100644
--- a/segment.c
+++ b/segment.c
@@ -114,9 +114,9 @@ void segment_init(struct Segment **seg_p, AVFormatContext 
*fmt)
 int i;
 AVStream *in_stream, *out_stream;
 struct Segment *seg = av_malloc(sizeof(struct Segment));
+*seg_p = NULL;
 if (!seg) {
 av_log(fmt, AV_LOG_ERROR, "Could not allocate segment.\n");
-*seg_p = NULL;
 return;
 }
 
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 02/17] ffserver.c: Remove trailing whitespace

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 ffserver.c | 64 +++---
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 0278bc8..cc7dc6c 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -86,12 +86,12 @@ void *read_thread(void *arg)
 AVStream *in_stream;
 AVRational tb = {1, AV_TIME_BASE};
 AVStream *stream;
-
+
 if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
 av_log(ifmt_ctx, AV_LOG_ERROR, "Could not get input stream info.\n");
 goto end;
 }
-
+
 av_log(ifmt_ctx, AV_LOG_INFO, "Finding video stream.\n");
 for (i = 0; i < ifmt_ctx->nb_streams; i++) {
 av_log(ifmt_ctx, AV_LOG_DEBUG, "Checking stream %d\n", i);
@@ -103,19 +103,19 @@ void *read_thread(void *arg)
 }
 if (video_idx == -1)
 audio_only = 1;
-
-
+
+
 // All information needed to start segmenting the file is gathered now.
 // start BUFFER_SECS seconds "in the past" to "catch up" to real-time. Has 
no effect on streamed sources.
 start = av_gettime_relative() - BUFFER_SECS * AV_TIME_BASE;
-
+
 // segmenting main-loop
-
+
 for (;;) {
 ret = av_read_frame(ifmt_ctx, &pkt);
 if (ret < 0)
 break;
-
+
 in_stream = ifmt_ctx->streams[pkt.stream_index];
 if (pkt.pts == AV_NOPTS_VALUE) {
 pkt.pts = 0;
@@ -123,15 +123,15 @@ void *read_thread(void *arg)
 if (pkt.dts == AV_NOPTS_VALUE) {
 pkt.dts = 0;
 }
-
+
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, tb);
 pkt.pos = -1;
-
+
 // current pts
 pts = pkt.pts;
-
+
 // current stream "uptime"
 now = av_gettime_relative() - start;
 
@@ -140,7 +140,7 @@ void *read_thread(void *arg)
 usleep(1000);
 now = av_gettime_relative() - start;
 }
-
+
 // keyframe or first Segment or audio_only and more than 
AUDIO_ONLY_SEGMENT_SECONDS passed since last cut
 if ((pkt.flags & AV_PKT_FLAG_KEY && pkt.stream_index == video_idx) || 
!seg ||
 (audio_only && pts - last_cut >= AUDIO_ONLY_SEGMENT_SECONDS * 
AV_TIME_BASE)) {
@@ -160,14 +160,14 @@ void *read_thread(void *arg)
 seg->id = id++;
 av_log(NULL, AV_LOG_DEBUG, "Starting new segment, id: %d\n", 
seg->id);
 }
-
+
 ts = av_dynarray2_add((void **)&seg->ts, &seg->ts_len, sizeof(int64_t),
   (const void *)&pkt.dts);
 if (!ts) {
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "could not write dts\n.");
 goto end;
 }
-
+
 ts = av_dynarray2_add((void **)&seg->ts, &seg->ts_len, sizeof(int64_t),
   (const void *)&pkt.pts);
 if (!ts) {
@@ -181,7 +181,7 @@ void *read_thread(void *arg)
 goto end;
 }
 }
-
+
 if (ret < 0 && ret != AVERROR_EOF) {
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "Error occurred during read: %s\n", 
av_err2str(ret));
 goto end;
@@ -211,19 +211,19 @@ void write_segment(struct Client *c)
 AVPacket pkt;
 struct SegmentReadInfo info;
 unsigned char *avio_buffer;
-
+
 av_fifo_generic_peek(c->buffer, &seg, sizeof(seg), NULL);
 pthread_mutex_unlock(&c->buffer_lock);
 c->current_segment_id = seg->id;
 info.buf = seg->buf;
 info.left = seg->size;
-
+
 if (!(fmt_ctx = avformat_alloc_context())) {
 av_log(NULL, AV_LOG_ERROR, "Could not allocate format context\n");
 client_disconnect(c, 0);
 return;
 }
-
+
 avio_buffer = av_malloc(AV_BUFSIZE);
 if (!avio_buffer) {
 av_log(fmt_ctx, AV_LOG_ERROR, "Could not allocate avio_buffer\n");
@@ -249,7 +249,7 @@ void write_segment(struct Client *c)
 client_disconnect(c, 0);
 return;
 }
-
+
 ret = avformat_find_stream_info(fmt_ctx, NULL);
 if (ret < 0) {
 av_log(fmt_ctx, AV_LOG_ERROR, "Could not find stream 
information\n");
@@ -259,14 +259,14 @@ void write_segment(struct Client *c)
 client_disconnect(c, 0);
 return;
 }
-
+
 av_log(fmt_ctx, AV_LOG_DEBUG, "Client: %d, Segment: %d\n", c->id, 
seg->id);
 
 for (;;) {
 ret = av_read_frame(fmt_ctx, &pkt);
 if (ret < 0)
 break;
-
+
 pkt.dts = av_rescale_q_rnd(seg->ts[pkt_count], tb,
 
c->ofmt_ctx->streams[pkt.stream_index]->time_base,
  

[FFmpeg-devel] [PATCH 05/17] segment.c: Remove trailing whitespace

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 segment.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/segment.c b/segment.c
index 6c74b72..2dba287 100644
--- a/segment.c
+++ b/segment.c
@@ -28,7 +28,7 @@ void segment_save(struct Segment *seg, const char *filename)
 {
 AVFormatContext *ofmt_ctx = NULL;
 int ret;
-
+
 avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, filename);
 if (!ofmt_ctx) {
 av_log(NULL, AV_LOG_ERROR, "Could not allocate output to save Segment 
%d.\n", seg->id);
@@ -40,7 +40,7 @@ void segment_save(struct Segment *seg, const char *filename)
 "Could not open output io context to save Segment %d: %s.\n", 
seg->id, av_err2str(ret));
 return;
 }
-
+
 avio_write(ofmt_ctx->pb, seg->buf, seg->size);
 avio_flush(ofmt_ctx->pb);
 avio_close(ofmt_ctx->pb);
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 12/17] ffserver.c: Add hls and dash and adapt to new httpd interface (stub)

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 ffserver.c | 248 +
 1 file changed, 210 insertions(+), 38 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index f128b55..4f42f74 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -27,6 +27,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -48,6 +51,7 @@ struct ReadInfo {
 struct PublisherContext *pub;
 AVFormatContext *ifmt_ctx;
 char *input_uri;
+char *server_name;
 };
 
 struct WriteInfo {
@@ -81,9 +85,12 @@ void *read_thread(void *arg)
 int id = 0;
 int64_t pts, now, start, last_cut = 0;
 int64_t *ts;
+char playlist_dirname[1024];
+char playlist_filename[1024];
+AVFormatContext *ofmt_ctx[FMT_NB] = { 0 }; // some may be left unused
 struct Segment *seg = NULL;
 AVPacket pkt;
-AVStream *in_stream;
+AVStream *in_stream, *out_stream;
 AVRational tb = {1, AV_TIME_BASE};
 AVStream *stream;
 
@@ -104,6 +111,95 @@ void *read_thread(void *arg)
 if (video_idx == -1)
 audio_only = 1;
 
+if (stream_formats[FMT_HLS] || stream_formats[FMT_DASH]) {
+snprintf(playlist_dirname, 1024, "%s/%s", info->server_name, 
info->config->stream_name);
+ret = mkdir(playlist_dirname, 0755);
+if (ret < 0 && errno != EEXIST) {
+av_log(NULL, AV_LOG_WARNING, "Could not create stream directory 
(%s) dropping hls/dash\n", strerror(errno));
+stream_formats[FMT_HLS] = 0;
+stream_formats[FMT_DASH] = 0;
+}
+}
+
+if (info->pub->stream_formats[FMT_HLS]) {
+snprintf(playlist_filename, 1024, "%s/%s/%s_hls.m3u8", 
info->server_name, info->pub->stream_name,
+   
   info->pub->stream_name);
+avformat_alloc_output_context2(&ofmt_ctx[FMT_HLS], NULL, "hls", 
playlist_filename);
+
+if (!ofmt_ctx[FMT_HLS]) {
+av_log(NULL, AV_LOG_ERROR, "Could not allocate hls output 
context.\n");
+goto end;
+}
+
+for (i = 0; i < ifmt_ctx->nb_streams; i++) {
+in_stream = ifmt_ctx->streams[i];
+out_stream = avformat_new_stream(ofmt_ctx[FMT_HLS], NULL);
+if (!out_stream) {
+av_log(ofmt_ctx[FMT_HLS], AV_LOG_WARNING, "Failed allocating 
output stream\n");
+continue;
+}
+ret = avcodec_parameters_copy(out_stream->codecpar, 
in_stream->codecpar);
+if (ret < 0) {
+av_log(ofmt_ctx[FMT_HLS], AV_LOG_WARNING, "Failed to copy 
context from input to output stream codec context\n");
+continue;
+}
+out_stream->codecpar->codec_tag = 0;
+if (out_stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (in_stream->sample_aspect_ratio.num)
+out_stream->sample_aspect_ratio = 
in_stream->sample_aspect_ratio;
+out_stream->avg_frame_rate = in_stream->avg_frame_rate;
+out_stream->r_frame_rate = in_stream->r_frame_rate;
+}
+av_dict_copy(&out_stream->metadata, in_stream->metadata, 0);
+}
+av_dict_copy(&ofmt_ctx[FMT_HLS]->metadata, ifmt_ctx->metadata, 0);
+ret = avformat_write_header(ofmt_ctx[FMT_HLS], NULL);
+if (ret < 0) {
+av_log(ofmt_ctx[FMT_HLS], AV_LOG_WARNING, "Error occured while 
writing header: %s\n", av_err2str(ret));
+}
+
+av_log(ofmt_ctx[FMT_HLS], AV_LOG_DEBUG, "Initialized hls.\n");
+}
+
+if (info->pub->stream_formats[FMT_DASH]) {
+snprintf(playlist_filename, 1024, "%s/%s/%s_dash.mpd", 
info->server_name, info->pub->stream_name,
+   
   info->pub->stream_name);
+avformat_alloc_output_context2(&ofmt_ctx[FMT_DASH], NULL, "dash", 
playlist_filename);
+
+if (!ofmt_ctx[FMT_DASH]) {
+av_log(NULL, AV_LOG_ERROR, "Could not allocate hls output 
context.\n");
+goto end;
+}
+
+for (i = 0; i < ifmt_ctx->nb_streams; i++) {
+in_stream = ifmt_ctx->streams[i];
+out_stream = avformat_new_stream(ofmt_ctx[FMT_DASH], NULL);
+if (!out_stream) {
+av_log(ofmt_ctx[FMT_DASH], AV_LOG_WARNING, "Failed allocating 
output stream\n");
+continue;
+}
+ret = avcodec_parameters_copy(out_stream->codecpar, 
in_stream->codecpar);
+if (ret < 0) {
+av_log(ofmt_ctx[FMT_DASH], AV_LOG_WARNING, "Failed to copy 
context from input to output stream codec context\n");
+continue;
+}
+out_stream->codecpar->codec_tag = 0;
+if (out_stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (in_stream->sample_aspect_ratio.num)
+out_stream->sample_

[FFmpeg-devel] [PATCH 13/17] move FFServerInfo from publisher.h to httpd.h

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 httpd.h | 9 +
 publisher.h | 9 -
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/httpd.h b/httpd.h
index a988916..1b2566e 100644
--- a/httpd.h
+++ b/httpd.h
@@ -72,6 +72,15 @@ struct HTTPDInterface {
 void (*shutdown)(void *server);
 };
 
+/* struct containing server and client info per client AVIOContext */
+
+struct FFServerInfo {
+struct HTTPDInterface *httpd;
+void *server;
+struct HTTPClient *client;
+};
+
+
 /** Current HTTPDInterface implementation using lavformat */
 extern struct HTTPDInterface lavfhttpd;
 #endif
diff --git a/publisher.h b/publisher.h
index e07cb10..a873d09 100644
--- a/publisher.h
+++ b/publisher.h
@@ -42,15 +42,6 @@ enum State {
 };
 
 
-/* struct containing server and client info per client AVIOContext */
-
-struct FFServerInfo {
-struct HTTPDInterface *httpd;
-void *server;
-struct HTTPClient *client;
-};
-
-
 struct Client {
 AVFormatContext *ofmt_ctx; // writable AVFormatContext, basically our tcp 
connection to the client
 AVFifoBuffer *buffer; // Client buffer of Segment references
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 15/17] ffserver.c: Improved timestamp handling.

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 ffserver.c | 37 +
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 91ad29a..38f10b7 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -86,7 +86,7 @@ void *read_thread(void *arg)
 int video_idx = -1;
 int audio_only = 0;
 int id = 0;
-int64_t pts, now, start, last_cut = 0;
+int64_t pts, pts_tmp, dts_tmp, now, start, last_cut = 0;
 int64_t *ts;
 char playlist_dirname[1024];
 char playlist_filename[1024];
@@ -223,13 +223,8 @@ void *read_thread(void *arg)
 pkt.dts = 0;
 }
 
-pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
-pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
-pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, tb);
-pkt.pos = -1;
-
-// current pts
-pts = pkt.pts;
+// current pts in AV_TIME_BASE
+pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 
 // current stream "uptime"
 now = av_gettime_relative() - start;
@@ -240,13 +235,6 @@ void *read_thread(void *arg)
 now = av_gettime_relative() - start;
 }
 
-if (info->pub->stream_formats[FMT_HLS]) {
-ret = av_write_frame(ofmt_ctx[FMT_HLS], &pkt);
-if (ret < 0) {
-fprintf(stderr, "Error muxing packet\n");
-break;
-}
-}
 if (info->pub->stream_formats[FMT_MATROSKA]) {
 // keyframe or first Segment or audio_only and more than 
AUDIO_ONLY_SEGMENT_SECONDS passed since last cut
 if ((pkt.flags & AV_PKT_FLAG_KEY && pkt.stream_index == video_idx) 
|| !seg ||
@@ -267,21 +255,27 @@ void *read_thread(void *arg)
 seg->id = id++;
 av_log(NULL, AV_LOG_DEBUG, "Starting new segment, id: %d\n", 
seg->id);
 }
-
+dts_tmp = av_rescale_q_rnd(pkt.dts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 ts = av_dynarray2_add((void **)&seg->ts, &seg->ts_len, 
sizeof(int64_t),
-(const void *)&pkt.dts);
+(const void *)&dts_tmp);
 if (!ts) {
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "could not write dts\n.");
 goto end;
 }
 
 ts = av_dynarray2_add((void **)&seg->ts, &seg->ts_len, 
sizeof(int64_t),
-(const void *)&pkt.pts);
+(const void *)&pts);
 if (!ts) {
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "could not write pts\n.");
 goto end;
 }
+pts_tmp = pkt.pts;
+dts_tmp = pkt.dts;
+pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, 
seg->fmt_ctx->streams[pkt.stream_index]->time_base, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, 
seg->fmt_ctx->streams[pkt.stream_index]->time_base, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 ret = av_write_frame(seg->fmt_ctx, &pkt);
+pkt.pts = pts_tmp;
+pkt.dts = dts_tmp;
 if (ret < 0) {
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "av_write_frame() 
failed.\n");
 goto end;
@@ -312,6 +306,8 @@ void *read_thread(void *arg)

AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, 
ofmt_ctx[FMT_HLS]->streams[pkt.stream_index]->time_base,

AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+pkt.duration = av_rescale_q_rnd(pkt.duration, 
in_stream->time_base, ofmt_ctx[FMT_HLS]->streams[pkt.stream_index]->time_base,
+   
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 
 ret = av_write_frame(ofmt_ctx[FMT_HLS], &pkt);
 if (ret < 0) {
@@ -419,10 +415,11 @@ void write_segment(struct Client *c)
 pkt.pts = av_rescale_q_rnd(seg->ts[pkt_count+1], tb,
 
c->ofmt_ctx->streams[pkt.stream_index]->time_base,

AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+
 pkt.pos = -1;
 pkt_count += 2;
-ret = av_write_frame(c->ofmt_ctx, &pkt);
-av_packet_unref(&pkt);
+ret = av_interleaved_write_frame(c->ofmt_ctx, &pkt);
+//av_packet_unref(&pkt);
 if (ret < 0) {
 av_log(fmt_ctx, AV_LOG_ERROR, "write_frame failed, 
disconnecting client: %d\n", c->id);

[FFmpeg-devel] [PATCH 11/17] lavfhttpd.c: Adapt to new interface (stub), fix includes

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 lavfhttpd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lavfhttpd.c b/lavfhttpd.c
index 3f29ec4..7c95001 100644
--- a/lavfhttpd.c
+++ b/lavfhttpd.c
@@ -21,6 +21,7 @@
 
 #include "httpd.h"
 #include 
+#include 
 
 
 int lavfhttpd_init(void **server, struct HTTPDConfig config)
@@ -57,13 +58,13 @@ int lavfhttpd_init(void **server, struct HTTPDConfig config)
 return 0;
 }
 
-int lavfhttpd_accept(void *server, struct HTTPClient **client, int reply_code)
+int lavfhttpd_accept(void *server, struct HTTPClient **client, const char 
**valid_files)
 {
 AVIOContext *server_ctx = (AVIOContext*) server;
 AVIOContext *client_ctx = NULL;
 struct HTTPClient *client_http = NULL;
 int ret, ret2, handshake;
-int reply_code2 = reply_code;
+int reply_code2 = 200; // = reply_code;
 char *method, *resource;
 if ((ret = avio_accept(server_ctx, &client_ctx)) < 0) {
 if (ret == AVERROR(ETIMEDOUT)) {
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 06/17] publisher.h: Remove trailing whitespace

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 publisher.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/publisher.h b/publisher.h
index e25c33d..e07cb10 100644
--- a/publisher.h
+++ b/publisher.h
@@ -115,7 +115,7 @@ void publisher_init(struct PublisherContext **pub, char 
*stream_name);
 void publisher_push_segment(struct PublisherContext *pub, struct Segment *seg);
 
 /**
- * Reserve a slot in the client struct of a PublisherContext. May fail if the 
number 
+ * Reserve a slot in the client struct of a PublisherContext. May fail if the 
number
  * of maximum clients has been reached.
  *
  * @param pub pointer to a PublisherContext
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 01/17] publisher.c: Redruce threads to 1 for now to avoid race conditions

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 publisher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/publisher.c b/publisher.c
index 56d1e24..fc3d804 100644
--- a/publisher.c
+++ b/publisher.c
@@ -101,7 +101,7 @@ void publisher_init(struct PublisherContext **pub, char 
*stream_name)
 av_log(NULL, AV_LOG_ERROR, "Could not allocate publisher context.\n");
 return;
 }
-pc->nb_threads = 8;
+pc->nb_threads = 1;
 pc->stream_name = stream_name;
 pc->current_segment_id = -1;
 pc->shutdown = 0;
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 10/17] configreader.c/.h/httpd.h: Add hls and dash, slightly change httpd interface, remove publisher.h include

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 configreader.c | 8 ++--
 configreader.h | 1 +
 httpd.h| 9 +
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/configreader.c b/configreader.c
index 3f5b896..966dc84 100644
--- a/configreader.c
+++ b/configreader.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-const char *stream_format_names[] = { "mkv" };
+const char *stream_format_names[] = { "mkv", "hls", "dash" };
 
 static struct HTTPDConfig *parsed_configs = NULL;
 
@@ -152,8 +152,12 @@ int configs_parse(lua_State *L)
 return luaL_error(L, "Error could not allocate 
stream formats");
 }
 key = lua_tostring(L, -1);
-if (!strncmp("mkv", key, 3)) {
+if (!strcmp("mkv", key)) {
 stream->formats[nb_formats++] = FMT_MATROSKA;
+} else if (!strcmp("hls", key)) {
+stream->formats[nb_formats++] = FMT_HLS;
+} else if (!strcmp("dash", key)) {
+stream->formats[nb_formats++] = FMT_DASH;
 } else {
 fprintf(stderr, "Warning unknown format (%s) 
in stream format configuration.\n",

key);
diff --git a/configreader.h b/configreader.h
index 38a3ea5..2e4 100644
--- a/configreader.h
+++ b/configreader.h
@@ -20,6 +20,7 @@
 #define CONFIGREADER_H
 
 #include "httpd.h"
+#include 
 
 /**
  * Read configurations from a file using the lua format. The configurations
diff --git a/httpd.h b/httpd.h
index 83535e0..a988916 100644
--- a/httpd.h
+++ b/httpd.h
@@ -24,11 +24,11 @@
 #define HTTPD_CLIENT_ERROR -2
 #define HTTPD_OTHER_ERROR -3
 
-#include "publisher.h"
-
-/** Supported stream formats, for now only matroska */
+/** Supported stream formats */
 enum StreamFormat {
 FMT_MATROSKA = 0,
+FMT_HLS,
+FMT_DASH,
 FMT_NB,
 };
 
@@ -60,11 +60,12 @@ struct HTTPClient {
 void *httpd_data;
 };
 
+
 /** HTTPDInterface that an httpd implementation must provide */
 struct HTTPDInterface {
 int (*init)  (void **server, struct HTTPDConfig config);
 int (*free)  (void *server);
-int (*accept)(void *server, struct HTTPClient **client, int reply_code);
+int (*accept)(void *server, struct HTTPClient **client, const char 
**valid_files);
 int (*write) (void *server, struct HTTPClient *client, const unsigned char 
*buf, int size);
 int (*read)  (void *server, struct HTTPClient *client, unsigned char *buf, 
int size);
 void (*close)(void *server, struct HTTPClient *client);
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 07/17] segment.c: Don't cast return value of av_malloc()

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 segment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/segment.c b/segment.c
index 2dba287..8b76510 100644
--- a/segment.c
+++ b/segment.c
@@ -113,7 +113,7 @@ void segment_init(struct Segment **seg_p, AVFormatContext 
*fmt)
 int ret;
 int i;
 AVStream *in_stream, *out_stream;
-struct Segment *seg = (struct Segment*) av_malloc(sizeof(struct Segment));
+struct Segment *seg = av_malloc(sizeof(struct Segment));
 if (!seg) {
 av_log(fmt, AV_LOG_ERROR, "Could not allocate segment.\n");
 *seg_p = NULL;
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 16/17] ffserver.c: Make fileserving independent of publisher to support streams that don't have mkv

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 ffserver.c | 70 +++---
 1 file changed, 45 insertions(+), 25 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 38f10b7..3b3451e 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -51,7 +51,9 @@
 
 struct ReadInfo {
 struct PublisherContext *pub;
+struct StreamConfig *config;
 AVFormatContext *ifmt_ctx;
+struct FileserverContext *fs;
 char *input_uri;
 char *server_name;
 };
@@ -96,6 +98,10 @@ void *read_thread(void *arg)
 AVStream *in_stream, *out_stream;
 AVRational tb = {1, AV_TIME_BASE};
 AVStream *stream;
+int stream_formats[FMT_NB] = { 0 };
+
+for (i = 0; i < info->config->nb_formats; i++)
+stream_formats[info->config->formats[i]] = 1;
 
 if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
 av_log(ifmt_ctx, AV_LOG_ERROR, "Could not get input stream info.\n");
@@ -124,9 +130,9 @@ void *read_thread(void *arg)
 }
 }
 
-if (info->pub->stream_formats[FMT_HLS]) {
-snprintf(playlist_filename, 1024, "%s/%s/%s_hls.m3u8", 
info->server_name, info->pub->stream_name,
-   
   info->pub->stream_name);
+if (stream_formats[FMT_HLS]) {
+snprintf(playlist_filename, 1024, "%s/%s/%s_hls.m3u8", 
info->server_name, info->config->stream_name,
+   
   info->config->stream_name);
 avformat_alloc_output_context2(&ofmt_ctx[FMT_HLS], NULL, "hls", 
playlist_filename);
 
 if (!ofmt_ctx[FMT_HLS]) {
@@ -164,9 +170,9 @@ void *read_thread(void *arg)
 av_log(ofmt_ctx[FMT_HLS], AV_LOG_DEBUG, "Initialized hls.\n");
 }
 
-if (info->pub->stream_formats[FMT_DASH]) {
-snprintf(playlist_filename, 1024, "%s/%s/%s_dash.mpd", 
info->server_name, info->pub->stream_name,
-   
   info->pub->stream_name);
+if (stream_formats[FMT_DASH]) {
+snprintf(playlist_filename, 1024, "%s/%s/%s_dash.mpd", 
info->server_name, info->config->stream_name,
+   
   info->config->stream_name);
 avformat_alloc_output_context2(&ofmt_ctx[FMT_DASH], NULL, "dash", 
playlist_filename);
 
 if (!ofmt_ctx[FMT_DASH]) {
@@ -235,7 +241,7 @@ void *read_thread(void *arg)
 now = av_gettime_relative() - start;
 }
 
-if (info->pub->stream_formats[FMT_MATROSKA]) {
+if (stream_formats[FMT_MATROSKA]) {
 // keyframe or first Segment or audio_only and more than 
AUDIO_ONLY_SEGMENT_SECONDS passed since last cut
 if ((pkt.flags & AV_PKT_FLAG_KEY && pkt.stream_index == video_idx) 
|| !seg ||
 (audio_only && pts - last_cut >= AUDIO_ONLY_SEGMENT_SECONDS * 
AV_TIME_BASE)) {
@@ -282,7 +288,7 @@ void *read_thread(void *arg)
 }
 }
 
-if (info->pub->stream_formats[FMT_DASH]) {
+if (stream_formats[FMT_DASH]) {
 pts_tmp = pkt.pts;
 dts_tmp = pkt.dts;
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, 
ofmt_ctx[FMT_DASH]->streams[pkt.stream_index]->time_base,
@@ -301,7 +307,7 @@ void *read_thread(void *arg)
 }
 }
 
-if (info->pub->stream_formats[FMT_HLS]) {
+if (stream_formats[FMT_HLS]) {
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, 
ofmt_ctx[FMT_HLS]->streams[pkt.stream_index]->time_base,

AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, 
ofmt_ctx[FMT_HLS]->streams[pkt.stream_index]->time_base,
@@ -322,21 +328,27 @@ void *read_thread(void *arg)
 av_log(seg->fmt_ctx, AV_LOG_ERROR, "Error occurred during read: %s\n", 
av_err2str(ret));
 goto end;
 }
-
-segment_close(seg);
-publisher_push_segment(info->pub, seg);
-publish(info->pub);
+if (stream_formats[FMT_MATROSKA]) {
+segment_close(seg);
+publisher_push_segment(info->pub, seg);
+publish(info->pub);
+}
 
 
 end:
 avformat_close_input(&ifmt_ctx);
-info->pub->shutdown = 1;
+if (info->pub)
+info->pub->shutdown = 1;
 for (i = 0; i < FMT_NB; i++) {
 if (ofmt_ctx[i]) {
 av_write_trailer(ofmt_ctx[i]);
 avformat_free_context(ofmt_ctx[i]);
 }
 }
+if (info->fs) {
+sleep(BUFFER_SECS);
+info->fs->shutdown = 1;
+}
 return NULL;
 }
 
@@ -471,11 +483,15 @@ void *accept_thread(void *arg)
 if (info->pubs[i] && !info->pubs[i]->shutdown)
 shutdown = 0;
 }
+if (info->fs && !info->fs->shutdown)
+shutdown = 0;
 if (shutdown)
 break;
 for (i =

[FFmpeg-devel] [PATCH 17/17] Update Documentation.txt

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 Documentation.txt | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/Documentation.txt b/Documentation.txt
index c8fef11..3eb52b8 100644
--- a/Documentation.txt
+++ b/Documentation.txt
@@ -12,13 +12,18 @@ the server is currently reading (including the short 
buffer).
 The stream received by the clients is simply an HTTP response to an HTTP
 request.
 
+HLS and DASH streaming are also supported. The corresponding files are written
+to directories corresponding to the server and stream name. A fileserver thread
+is started on a per-server basis depending on whether HLS or DASH was 
requested.
+
 
 Documentation
 -
 
-The current implementation has three different types of work that is done in
+The current implementation has four different types of work that is done in
 different threads. These types are: reading a stream, accepting HTTP
-connections and writing media data to clients.
+connections and writing media data to clients. This is split into serving
+static files and serving dynamic matroska content.
 
 The design tries to follow a Publisher-Subscriber-Pattern. The PublisherContext
 struct contains buffers of read media data and the list of clients. Clients
@@ -56,7 +61,7 @@ The HTTPDInterface struct takes the following function 
pointers:
 struct HTTPDInterface {
 int (*init)  (void **server, struct HTTPDConfig config);
 int (*free)  (void *server);
-int (*accept)(void *server, struct HTTPClient **client, int reply_code);
+int (*accept)(void *server, struct HTTPClient **client, const char 
**valid_files);
 int (*write) (void *server, struct HTTPClient *client, const unsigned char 
*buf, int size);
 int (*read)  (void *server, struct HTTPClient *client, unsigned char *buf, 
int size);
 void (*close)(void *server, struct HTTPClient *client);
@@ -72,9 +77,10 @@ read and where to serve them. A sample config is supplied as 
sample_config.lua.
 This sample config defines two servers with a total of three streams. The first
 server serves two streams on all interfaces on port 8080, while the second
 server serves one stream on 127.0.0.1. The streams can be received by
-requesting the configured stream name as the GET parameter in the HTTP request.
-In the sample config, this would be 
"http://:8080/default_stream"
-for the first stream.
+requesting the stream and the desired format as the GET parameter of the 
request
+in the form of: //
+In the sample config, this would be 
"http://:8080/default_stream/mkv"
+for the first stream. Other formats are "hls" and "dash".
 
 The stream is read in real time from whatever resource it is retrieved.
 Currently a maximum of 16 clients is implemented.
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 14/17] Add fileserver and add it to Makefile

2018-06-27 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 Makefile |   7 ++-
 ffserver.c   | 150 +++
 fileserver.c |  97 +
 fileserver.h |  63 ++
 4 files changed, 282 insertions(+), 35 deletions(-)
 create mode 100644 fileserver.c
 create mode 100644 fileserver.h

diff --git a/Makefile b/Makefile
index 83bc4e0..18f3ac3 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,8 @@ LUA_FLAGS = $(shell pkg-config --libs --cflags lua5.3)
 CFLAGS=-fsanitize=address -fsanitize=undefined
 # LAV_FLAGS = -L/usr/local/lib -lavcodec -lavformat -lavutil
 
-ffserver: segment.o publisher.o lavfhttpd.o configreader.o ffserver.c
-   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) $(LUA_FLAGS) -lpthread -o ffserver 
segment.o publisher.o lavfhttpd.o configreader.o ffserver.c
+ffserver: segment.o publisher.o fileserver.o lavfhttpd.o configreader.o 
ffserver.c
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) $(LUA_FLAGS) -lpthread -o ffserver 
segment.o publisher.o fileserver.o lavfhttpd.o configreader.o ffserver.c
 
 segment.o: segment.c segment.h
cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c segment.c
@@ -13,6 +13,9 @@ segment.o: segment.c segment.h
 publisher.o: publisher.c publisher.h
cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c publisher.c
 
+fileserver.o: fileserver.c fileserver.h
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c fileserver.c
+
 lavfhttpd.o: lavfhttpd.c httpd.h
cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c lavfhttpd.c
 
diff --git a/ffserver.c b/ffserver.c
index 4f42f74..91ad29a 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -37,9 +37,11 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "segment.h"
 #include "publisher.h"
+#include "fileserver.h"
 #include "httpd.h"
 #include "configreader.h"
 
@@ -64,6 +66,7 @@ struct AcceptInfo {
 struct HTTPDInterface *httpd;
 AVFormatContext **ifmt_ctxs;
 struct HTTPDConfig *config;
+struct FileserverContext *fs;
 int nb_pub; /** number of publishers (streams) equal to number of ifmt_ctx 
*/
 };
 
@@ -448,8 +451,8 @@ void *accept_thread(void *arg)
 struct AcceptInfo *info = (struct AcceptInfo*) arg;
 struct FFServerInfo *ffinfo = NULL;
 struct PublisherContext *pub;
-char status[4096];
-char *stream_name;
+char status[4096], requested_file[1024], sanitized_file[1024];
+char *stream_name, *resource;
 struct HTTPClient *client = NULL;
 void *server = NULL;
 AVIOContext *client_ctx = NULL;
@@ -493,6 +496,8 @@ void *accept_thread(void *arg)
 
 pub = NULL;
 ifmt_ctx = NULL;
+resource = client->resource;
+snprintf(requested_file, 1024, "%s", resource);
 for (i = 0; i < config->nb_streams; i++) {
 stream_name = info->pubs[i]->stream_name;
 //  skip leading '/'  ---v
@@ -515,7 +520,8 @@ void *accept_thread(void *arg)
 }
 }
 
-if (!pub || !ifmt_ctx) {
+
+if ((!pub || !ifmt_ctx) && !requested_file[0]) {
 av_log(client_ctx, AV_LOG_WARNING, "No suitable publisher found 
for resource: %s.\n",
 client->resource ? 
client->resource : "(null)");
 reply_code = 404;
@@ -534,13 +540,6 @@ void *accept_thread(void *arg)
 continue;
 }
 
-avio_buffer = av_malloc(AV_BUFSIZE);
-if (!avio_buffer) {
-av_log(client_ctx, AV_LOG_ERROR, "Could not allocate output format 
context.\n");
-publisher_cancel_reserve(pub);
-info->httpd->close(server, client);
-continue;
-}
 ffinfo = av_malloc(sizeof(*ffinfo));
 if (!ffinfo) {
 av_log(client_ctx, AV_LOG_ERROR, "Could not allocate FFServerInfo 
struct.\n");
@@ -551,6 +550,30 @@ void *accept_thread(void *arg)
 ffinfo->httpd = info->httpd;
 ffinfo->client = client;
 ffinfo->server = server;
+
+
+// try to serve file
+if (requested_file[0]) {
+snprintf(sanitized_file, 1024, "%s", requested_file);
+resource = requested_file;
+while(resource && *resource == '/') {
+resource++;
+}
+
+snprintf(sanitized_file, 1024, "%s", resource);
+fileserver_schedule(info->fs, ffinfo, sanitized_file);
+continue;
+}
+
+avio_buffer = av_malloc(AV_BUFSIZE);
+if (!avio_buffer) {
+av_log(client_ctx, AV_LOG_ERROR, "Could not allocate output format 
context.\n");
+publisher_cancel_reserve(pub);
+info->httpd->close(server, client);
+continue;
+}
+
+
 client_ctx = avio_alloc_context(avio_buffer, AV_BUFSIZE, 1, ffinfo, 
NULL, &ffserver_write, NULL);
 if (!client_ctx) {
 av_log(NULL, AV_LOG_ERROR, "Could not allocate output format 
context.\n");
@@ -676,16 +699,52 @@ void *write_thread(voi

Re: [FFmpeg-devel] Fw: [PATCH] Refactor two near-identical clauses.

2018-06-27 Thread Michael Niedermayer
On Sun, Jun 17, 2018 at 03:40:19PM +0300, Shlomi Fish wrote:
> On Sun, 17 Jun 2018 03:05:27 +0200
> Michael Niedermayer  wrote:
> 
> > On Tue, Jun 12, 2018 at 12:53:20PM +0300, Shlomi Fish wrote:
> > > This message did not arrive to the list after three submissions.
> > > 
> > > Begin forwarded message:
> > > 
> > > Date: Tue, 12 Jun 2018 12:42:52 +0300
> > > From: Shlomi Fish 
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Shlomi Fish 
> > > Subject: [PATCH] Refactor two near-identical clauses.
> > > 
> > > 
> > > Placed under the Expat licence . All tests pass.
> > > ---
> > >  libavfilter/vf_weave.c | 33 ++---
> > >  1 file changed, 14 insertions(+), 19 deletions(-)
> > > 
> > > diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> > > index 037f5d1cf2..be371201e1 100644
> > > --- a/libavfilter/vf_weave.c
> > > +++ b/libavfilter/vf_weave.c
> > > @@ -23,6 +23,7 @@
> > >  #include "libavutil/pixdesc.h"
> > >  #include "avfilter.h"
> > >  #include "internal.h"
> > > +#include 
> > >  
> > >  typedef struct WeaveContext {
> > >  const AVClass *class;
> > > @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
> > > *in)
> > >  AVFilterLink *outlink = ctx->outputs[0];
> > >  AVFrame *out;
> > >  int i;
> > > +bool weave;
> > > +int field1, field2;
> > >  
> > >  if (!s->prev) {
> > >  s->prev = in;
> > > @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> > > *in) }
> > >  av_frame_copy_props(out, in);
> > >  
> > > +weave = (s->double_weave && !(inlink->frame_count_out & 1));
> > > +field1 = s->first_field * weave;
> > > +field2 = s->first_field * !weave;
> > >  for (i = 0; i < s->nb_planes; i++) {
> > > -if (s->double_weave && !(inlink->frame_count_out & 1)) {
> > > -av_image_copy_plane(out->data[i] + out->linesize[i] *
> > > s->first_field,  
> > 
> > this seems to be corrupted by line breaks
> > 
> 
> Well, the git send-email email was silently dropped three times... See:
> 
> http://www.shlomifish.org/Files/files/code/0001-Refactor-two-near-identical-clauses.patch
> 
> also attached here. Email has sadly become unreliable.
> 
> > [...]
> > 
> 
> 

>  vf_weave.c |   33 ++---
>  1 file changed, 14 insertions(+), 19 deletions(-)
> f5a0afe735e322c2539a11dd7d8b28534d96c99c  
> 0001-Refactor-two-near-identical-clauses.patch
> From b6678799848297cd7079085035259baf6d8c54f0 Mon Sep 17 00:00:00 2001
> From: Shlomi Fish 
> Date: Fri, 25 May 2018 23:44:54 +0300
> Subject: [PATCH] Refactor two near-identical clauses.
> 
> Placed under the Expat licence . All tests pass.
> ---
>  libavfilter/vf_weave.c | 33 ++---
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> index 037f5d1cf2..be371201e1 100644
> --- a/libavfilter/vf_weave.c
> +++ b/libavfilter/vf_weave.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/pixdesc.h"
>  #include "avfilter.h"
>  #include "internal.h"
> +#include 
>  
>  typedef struct WeaveContext {
>  const AVClass *class;
> @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>  AVFilterLink *outlink = ctx->outputs[0];
>  AVFrame *out;
>  int i;
> +bool weave;
> +int field1, field2;
>  
>  if (!s->prev) {
>  s->prev = in;
> @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
> *in)
>  }
>  av_frame_copy_props(out, in);
>  
> +weave = (s->double_weave && !(inlink->frame_count_out & 1));
> +field1 = s->first_field * weave;
> +field2 = s->first_field * !weave;

if first_field is 0 both field1 and 2 are 0 while !s->first_field was not 0
but gets replaced by it
am i missing something ?

stdbool seems unneeded

and what is "Placed under the Expat licence" supposed to mean ?
the file is under LGPL


[...]


-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


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] ffmpeg: fix -stream_loop with multiple inputs

2018-06-27 Thread Gyan Doshi



On 28-06-2018 02:35 AM, Marton Balint wrote:

The input thread need to be properly cleaned up and re-initalized before we can
start reading again in threaded mode. (threaded input reading is used when
there are mode than one input file).


Commit message should reference tickets 6121 and 7043.

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


Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: add option to hide vsync warnings

2018-06-27 Thread Gyan Doshi



On 27-06-2018 11:30 PM, Marton Balint wrote:



If we don't know why it spams the console or nobody is willing to fix it,
then decrease loglevel to verbose.


Will do this instead.

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