Re: [FFmpeg-devel] Blocking vs non-blocking modes in protocols

2019-09-02 Thread Andriy Gelman
Nicolas, thank you for clarifying  

On Mon, 02. Sep 17:21, Nicolas George wrote:
> Andriy Gelman (12019-09-01):
> > Below are my notes on blocking and non-blocking modes in protocols. Proposed
> > changes that I'd like to make are at the end. 
> > 
> > Thanks, 
> > Andriy
> > 
> > 
> > ---General notes--
> > -blocking mode-
> > - transfer_function deals with polling and timeout
> > - block inside transfer_function for max rw_timeout. 
> > - if rw_timeout expires the protocol designers have two options:  
> >(1) transfer_funciton returns AVERROR(ETIMEDOUT).  This will cause 
> > the
> >encoding/decoding to exit with timeout error.
> >(2) transfer_function returns AVERROR(EINTR).  Immediately retry the
> >transfer_function after checking interrupt callback.
> > 
> > -non-blocking mode-
> > - retry_transfer_wrapper deals with retries
> > - if read/writes are not available transfer_function should immediately
> >   return with AVERROR(EAGAIN)
> 
> > - retry transfer_function with 5 x fast_retry (no sleep). Then, retry 
> > with
> >   1ms sleep.  
> > - If rw_timeout expires, exit encoding/decoding with AVERROR(EIO) 
> > (Probably
> >   should be changed to AVERROR(ETIMEDOUT) to be consistent with blocking
> >   mdoe.
> 
> This looks like one of the reasons the non-blocking mode does not work.
> 
> > But overall, the two modes seem similar to me: 
> > - "Blocking" - blocks at the transfer_function
> > - "Non-blocking" - blocks in retry_transfer_function
> 
> The expected behaviour is: non-blocking does not block.
> 
> > Potential advantage of non-blocking over blocking mode
> > I'm trying to figure what would be the advantage of non-blocking over 
> > blocking
> > modes. The only reason I can think of: non-blocking mode gives more control 
> > to
> > the user rather than protocol designer. In non-blocking mode the user can 
> > force
> > an exit after rw_timeout expires. On the other hand, in blocking mode, the
> > protocol designer can force a retry by returing AVERROR(EINTR) after 
> > rw_timeout
> > expires instead of exiting the code (i.e. after AVERROR(ETIMEDOUT) is 
> > returned).
> > 
> > Any other reason someone would prefer non-blocking over blocking modes? 
> 
> I am not sure I read you correctly, I think you are saying that
> blocking/non-blocking mode is a design decision for protocol
> implementors. The difference between blocking and non-blocking mode is
> not meant for the internal design of FFmpeg but for applications.
> 
> An application that has several live inputs (network, device, GUI (a GUI
> is one big live input)) cannot be blocked reading on one of them,
> because it needs to react to the others immediately. The application
> design is then to have all live inputs in non-blocking mode, and walk
> over them, like this:
> 
> while (1) {
> wait_for_any_input();
> for (input)
> process_input_non_blocking(input);
> }
> 
> (If the application is CPU-bound rather than input-bound,
> wait_for_any_input() will need to be rather
> perform_a_slice_of_computation().)
> 
> (Some applications, including FFmpeg, will have wait_a_small_time()
> instead of wait_for_any_input(), but that is terrible design and a waste
> of energy that contributes to global warming.)
> 
> > Proposed changes
> > (1) At the moment, non-blocking mode immediately exits after 
> > AVERROR(EAGAIN)
> > is returned without doing any retries. I'm quite sure there is a bug on
> > avio.c:379. It should be changed to: if (!(h->flags & 
> > AVIO_FLAG_NONBLOCK))
> 
> In non-blocking mode, if no data is available, the flow must return to
> the application immediately with AVERROR(EAGAIN).

I assumed that the set of retries in retry_transfer_wrapper were aimed at the
non-blocking mode. But these retries are not called at the moment when the
AVIO_FLAG_NONBLOCK flag is set. 
As I understand from your reply this is the correct behaviour. 

> 
> > (3) Update avio.h/url.h to clarify difference between 
> > AVERROR(ETIMEDOUT) and
> > AVERROR(EINTR) in blocking mode.
> 
> The semantic of EINTR is "Unix sucks, signals are terribly badly
> designed". It should never be used in our code except to deal with that
> bad design.
> 
> > (4) Add non-blocking option to the cli. Something like -avioflags
> > nonblocking. But add a note that this may not be supported by a specific
> > protocol 
> 
> Working in blocking or non-blocking mode means a completely different
> design of the program, making it an option does not make sense.
> 
> > (5) If rw_timeout expires in non-blocking mode, return 
> > AVERROR(ETIMEDOUT)
> > instead of AVERROR(EIO) to be consistent with blocking mode.
> 
> In non-blocking mode, there can be no timeout because there can be no
> time. If there is, it is a bug.
> 
> Note: Currently, non-blocking mode works for a few cases but is
> completely broken in most of 

Re: [FFmpeg-devel] [PATCH 1/2] lavu/pixfmt: add AYUV pixel format

2019-09-02 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Carl Eugen Hoyos
> Sent: Sunday, September 1, 2019 01:57
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] lavu/pixfmt: add AYUV pixel format
> 
> Am Sa., 31. Aug. 2019 um 19:25 Uhr schrieb Fu, Linjie :
> >
> > > -Original Message-
> > > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf
> > > Of Mark Thompson
> > > Sent: Saturday, August 31, 2019 23:10
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH 1/2] lavu/pixfmt: add AYUV pixel
> format
> > >
> > > On 31/08/2019 05:22, Fu, Linjie wrote:
> > > >> -Original Message-
> > > >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> > > Behalf
> > > >> Of Carl Eugen Hoyos
> > > >> Sent: Friday, August 30, 2019 00:12
> > > >> To: FFmpeg development discussions and patches  > > >> de...@ffmpeg.org>
> > > >> Subject: Re: [FFmpeg-devel] [PATCH 1/2] lavu/pixfmt: add AYUV pixel
> > > format
> > > >>
> > > >> Am Do., 29. Aug. 2019 um 16:16 Uhr schrieb Fu, Linjie
> > > :
> > > >>
> > > >>> Thus AYUV will make more sense.
> > > >>
> > > >> If your hardware decoding does not produce valid alpha data (0xFF
> > > >> for opaque, 0x00 for completely transparent), you cannot use an
> > > >> FFmpeg pix_fmt that defines alpha for decoding.
> > > >> If you define a pix_fmt that does not contain alpha information (as
> > > >> needed for your hardware decoder), please do not use "A" in its
> > > >> name.
> > > >
> > > > The hardware decode output is in packed 4:4:4:4 8 bit(32 bits in total).
> Apart>
> > > from Y/U/V channel, there is an additional need for a channel to store the
> > > > zero byte in surfaces(nb_components = 4). And it is designed in
> > > hardware/driver
> > > > for VA_FourCC_AYUV and AYUV format.
> > > >
> > > > It's not quite proper to use something like "0YUV" directly which
> indicates
> > > that
> > > > there is no Alpha channel data like"RGB0" or "0RGB"(nb_components =
> 3).
> > > >
> > > > "0YUV": YUV0/YUV0/...
> > > > "RGB0":RGB/RGB/...
> > >
> > > I think you've misread what RGB0 is.  The component step is 4, not 3 (see
> > > libavutil/pixdesc.c) - the format with a step of 3 is RGB24.
> > >
> > > RGBA:  R G B A R G B A ...
> > > RGB0:  R G B 0 R G B 0 ...
> > > RGB24: R G B R G B R G ...
> >
> > Thanks for pointing out this.
> > Just took the nb_components into account and misread the step info at
> first.
> >
> > > Following the same pattern we would have:
> > >
> > > AYUV:  A Y U V A Y U V ...
> > > 0YUV:  0 Y U V 0 Y U V ...
> > >
> > > To me it looks like 0YUV is exactly what you want here.
> >
> > Will update the patch if 0YUV is more acceptable.
> 
> Could you double-check if there is no bug in the decoder?
> I ask because transparency is possible with hevc and the
> relevant Windows format does support transparency from
> how I read the specification.
> 

Double confirmed.
The alpha channel is configurable on HCP_SURFACE_STATE command,
currently driver(iHD) set zero as default value.

"0YUV" is good enough, "AYUV" could be hold on.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avcodec/videotoolboxenc: add H264 Extended profile and level

2019-09-02 Thread Limin Wang
On Mon, Sep 02, 2019 at 09:21:11PM -0400, Rick Kern wrote:
> On Mon, Sep 2, 2019 at 9:53 AM Limin Wang  wrote:
> 
> > On Tue, Aug 27, 2019 at 10:56:42AM -0400, Richard Kern wrote:
> >
> > > I’ll look at it this weekend.
> > ping
> >
> >
> It shows error kVTParameterErr when using the software encoder:
> 
> Error setting profile/level property: -12902
> 
> I used the following command for testing: ffmpeg -i "$mediaFile" -c:v
> h264_videotoolbox -profile:v extended -y -require_sw 1 h264.ts
> 
> 
> It defaults to High profile in the output.
> 
> 
> 
> The hardware encoder also fails to encode using Extended profile, but the
> OS complains the parameter isn't supported. It also defaults to High
> profile in the output, which seems like a good default.
> 
> 
> 
> Can you try both hardware and software encodes on your end? If you're
> seeing Extended profile using ffprobe on either output file, I'll push the
> changes.
> 
I'm adding the missing profile/level by the apple document:
https://developer.apple.com/documentation/videotoolbox/vtcompressionsession/compression_properties/profile_and_level_constants
My iMac/macpro can't support the extended profile for sw and hw, so I add 
patch#2 to check the error. 
If someone have ios hardware can try it. 

Thanks,
Limin
> 
> 
> >
> > > > On Aug 27, 2019, at 10:40 AM, Limin Wang 
> > wrote:
> > > >
> > > >
> > > > ping the patchset.
> > > >
> > > >> On Tue, Aug 20, 2019 at 07:04:29PM +0800, lance.lmw...@gmail.com
> > wrote:
> > > >> From: Limin Wang 
> > > >>
> > > >> Signed-off-by: Limin Wang 
> > > >> ---
> > > >> libavcodec/videotoolboxenc.c | 14 ++
> > > >> 1 file changed, 14 insertions(+)
> > > >>
> > > >> diff --git a/libavcodec/videotoolboxenc.c
> > b/libavcodec/videotoolboxenc.c
> > > >> index d76bb7f646..b16b056f6c 100644
> > > >> --- a/libavcodec/videotoolboxenc.c
> > > >> +++ b/libavcodec/videotoolboxenc.c
> > > >> @@ -80,6 +80,8 @@ static struct{
> > > >> CFStringRef kVTProfileLevel_H264_High_5_1;
> > > >> CFStringRef kVTProfileLevel_H264_High_5_2;
> > > >> CFStringRef kVTProfileLevel_H264_High_AutoLevel;
> > > >> +CFStringRef kVTProfileLevel_H264_Extended_5_0;
> > > >> +CFStringRef kVTProfileLevel_H264_Extended_AutoLevel;
> > > >>
> > > >> CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
> > > >> CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
> > > >> @@ -137,6 +139,8 @@ static void loadVTEncSymbols(){
> > > >> GET_SYM(kVTProfileLevel_H264_High_5_1,   "H264_High_5_1");
> > > >> GET_SYM(kVTProfileLevel_H264_High_5_2, "H264_High_5_2");
> > > >> GET_SYM(kVTProfileLevel_H264_High_AutoLevel,
> >  "H264_High_AutoLevel");
> > > >> +GET_SYM(kVTProfileLevel_H264_Extended_5_0,
> >  "H264_Extended_5_0");
> > > >> +GET_SYM(kVTProfileLevel_H264_Extended_AutoLevel,
> > "H264_Extended_AutoLevel");
> > > >>
> > > >> GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel,
> >  "HEVC_Main_AutoLevel");
> > > >> GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,
> >  "HEVC_Main10_AutoLevel");
> > > >> @@ -154,6 +158,7 @@ typedef enum VT_H264Profile {
> > > >> H264_PROF_BASELINE,
> > > >> H264_PROF_MAIN,
> > > >> H264_PROF_HIGH,
> > > >> +H264_PROF_EXTENDED,
> > > >> H264_PROF_COUNT
> > > >> } VT_H264Profile;
> > > >>
> > > >> @@ -704,6 +709,14 @@ static bool
> > get_vt_h264_profile_level(AVCodecContext *avctx,
> > > >>
> >  compat_keys.kVTProfileLevel_H264_High_5_2;   break;
> > > >> }
> > > >> break;
> > > >> +case H264_PROF_EXTENDED:
> > > >> +switch (vtctx->level) {
> > > >> +case  0: *profile_level_val =
> > > >> +
> > compat_keys.kVTProfileLevel_H264_Extended_AutoLevel; break;
> > > >> +case 50: *profile_level_val =
> > > >> +
> > compat_keys.kVTProfileLevel_H264_Extended_5_0;   break;
> > > >> +}
> > > >> +break;
> > > >> }
> > > >>
> > > >> if (!*profile_level_val) {
> > > >> @@ -2531,6 +2544,7 @@ static const AVOption h264_options[] = {
> > > >> { "baseline", "Baseline Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> > H264_PROF_BASELINE }, INT_MIN, INT_MAX, VE, "profile" },
> > > >> { "main", "Main Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> > H264_PROF_MAIN }, INT_MIN, INT_MAX, VE, "profile" },
> > > >> { "high", "High Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> > H264_PROF_HIGH }, INT_MIN, INT_MAX, VE, "profile" },
> > > >> +{ "extended", "Extend Profile",   0, AV_OPT_TYPE_CONST, { .i64 =
> > H264_PROF_EXTENDED }, INT_MIN, INT_MAX, VE, "profile" },
> > > >>
> > > >> { "level", "Level", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = 0 },
> > 0, 52, VE, "level" },
> > > >> { "1.3", "Level 1.3, only available with Baseline Profile", 0,
> > AV_OPT_TYPE_CONST, { .i64 = 13 }, INT_MIN, INT_MAX, VE, "level" },
> > > >> --
> > > >> 2.21.0
> > > >>
> > > > ___
> > > > ffmpeg-devel mailing list
> > > > 

[FFmpeg-devel] [PATCH] avformat/hls: mark the playlist is broken when the reload times is over

2019-09-02 Thread Steven Liu
when the playlist is master playlist, there have many playlist.
the workflow should continue if one of the playlist is broken.

Signed-off-by: Steven Liu 
---
 libavformat/hls.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 3aee7a19ae..d2fafe0302 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1408,8 +1408,11 @@ restart:
 
 reload:
 reload_count++;
-if (reload_count > c->max_reload)
+if (reload_count > c->max_reload) {
+v->broken = 1;
+v->needed = 0;
 return AVERROR_EOF;
+}
 if (!v->finished &&
 av_gettime_relative() - v->last_load_time >= reload_interval) {
 if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) {
@@ -1459,7 +1462,7 @@ reload:
 if (ret < 0) {
 if (ff_check_interrupt(c->interrupt_callback))
 return AVERROR_EXIT;
-av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %d of 
playlist %d\n",
+av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %d of 
playlist %d, will reload\n",
v->cur_seq_no,
v->index);
 v->cur_seq_no += 1;
@@ -1925,6 +1928,7 @@ static int hls_read_header(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", 
pls->segments[0]->url);
 avformat_free_context(pls->ctx);
 pls->ctx = NULL;
+if (c->n_playlists > 1) continue;
 goto fail;
 }
 pls->ctx->pb   = >pb;
-- 
2.17.2 (Apple Git-113)



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/hls: continue to play enabled playlist when have failed playlist

2019-09-02 Thread Steven Liu
fix ticket: 7811

Signed-off-by: Steven Liu 
---
 libavformat/hls.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 61b6759ef5..3aee7a19ae 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -116,6 +116,7 @@ struct playlist {
 int n_segments;
 struct segment **segments;
 int needed;
+int broken;
 int cur_seq_no;
 int64_t cur_seg_offset;
 int64_t last_load_time;
@@ -1815,15 +1816,21 @@ static int hls_read_header(AVFormatContext *s)
 if (c->n_playlists > 1 || c->playlists[0]->n_segments == 0) {
 for (i = 0; i < c->n_playlists; i++) {
 struct playlist *pls = c->playlists[i];
-if ((ret = parse_playlist(c, pls->url, pls, NULL)) < 0)
+if ((ret = parse_playlist(c, pls->url, pls, NULL)) < 0) {
+av_log(s, AV_LOG_WARNING, "parse_playlist error %s [%s]\n", 
av_err2str(ret), pls->url);
+pls->broken = 1;
+if (c->n_playlists > 1)
+continue;
 goto fail;
+}
 }
 }
 
-if (c->variants[0]->playlists[0]->n_segments == 0) {
-av_log(s, AV_LOG_WARNING, "Empty segment\n");
-ret = AVERROR_EOF;
-goto fail;
+for (i = 0; i < c->n_variants; i++) {
+if (c->variants[i]->playlists[0]->n_segments == 0) {
+av_log(s, AV_LOG_WARNING, "Empty segment [%s]\n", 
c->variants[i]->playlists[0]->url);
+c->variants[i]->playlists[0]->broken = 1;
+}
 }
 
 /* If this isn't a live stream, calculate the total duration of the
@@ -1993,6 +2000,9 @@ static int recheck_discard_flags(AVFormatContext *s, int 
first)
 
 cur_needed = playlist_needed(c->playlists[i]);
 
+if (pls->broken) {
+continue;
+}
 if (cur_needed && !pls->needed) {
 pls->needed = 1;
 changed = 1;
-- 
2.17.2 (Apple Git-113)



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avcodec/videotoolboxenc: add H264 Extended profile and level

2019-09-02 Thread Rick Kern
On Mon, Sep 2, 2019 at 9:53 AM Limin Wang  wrote:

> On Tue, Aug 27, 2019 at 10:56:42AM -0400, Richard Kern wrote:
>
> > I’ll look at it this weekend.
> ping
>
>
It shows error kVTParameterErr when using the software encoder:

Error setting profile/level property: -12902

I used the following command for testing: ffmpeg -i "$mediaFile" -c:v
h264_videotoolbox -profile:v extended -y -require_sw 1 h264.ts


It defaults to High profile in the output.



The hardware encoder also fails to encode using Extended profile, but the
OS complains the parameter isn't supported. It also defaults to High
profile in the output, which seems like a good default.



Can you try both hardware and software encodes on your end? If you're
seeing Extended profile using ffprobe on either output file, I'll push the
changes.



>
> > > On Aug 27, 2019, at 10:40 AM, Limin Wang 
> wrote:
> > >
> > >
> > > ping the patchset.
> > >
> > >> On Tue, Aug 20, 2019 at 07:04:29PM +0800, lance.lmw...@gmail.com
> wrote:
> > >> From: Limin Wang 
> > >>
> > >> Signed-off-by: Limin Wang 
> > >> ---
> > >> libavcodec/videotoolboxenc.c | 14 ++
> > >> 1 file changed, 14 insertions(+)
> > >>
> > >> diff --git a/libavcodec/videotoolboxenc.c
> b/libavcodec/videotoolboxenc.c
> > >> index d76bb7f646..b16b056f6c 100644
> > >> --- a/libavcodec/videotoolboxenc.c
> > >> +++ b/libavcodec/videotoolboxenc.c
> > >> @@ -80,6 +80,8 @@ static struct{
> > >> CFStringRef kVTProfileLevel_H264_High_5_1;
> > >> CFStringRef kVTProfileLevel_H264_High_5_2;
> > >> CFStringRef kVTProfileLevel_H264_High_AutoLevel;
> > >> +CFStringRef kVTProfileLevel_H264_Extended_5_0;
> > >> +CFStringRef kVTProfileLevel_H264_Extended_AutoLevel;
> > >>
> > >> CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
> > >> CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
> > >> @@ -137,6 +139,8 @@ static void loadVTEncSymbols(){
> > >> GET_SYM(kVTProfileLevel_H264_High_5_1,   "H264_High_5_1");
> > >> GET_SYM(kVTProfileLevel_H264_High_5_2, "H264_High_5_2");
> > >> GET_SYM(kVTProfileLevel_H264_High_AutoLevel,
>  "H264_High_AutoLevel");
> > >> +GET_SYM(kVTProfileLevel_H264_Extended_5_0,
>  "H264_Extended_5_0");
> > >> +GET_SYM(kVTProfileLevel_H264_Extended_AutoLevel,
> "H264_Extended_AutoLevel");
> > >>
> > >> GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel,
>  "HEVC_Main_AutoLevel");
> > >> GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,
>  "HEVC_Main10_AutoLevel");
> > >> @@ -154,6 +158,7 @@ typedef enum VT_H264Profile {
> > >> H264_PROF_BASELINE,
> > >> H264_PROF_MAIN,
> > >> H264_PROF_HIGH,
> > >> +H264_PROF_EXTENDED,
> > >> H264_PROF_COUNT
> > >> } VT_H264Profile;
> > >>
> > >> @@ -704,6 +709,14 @@ static bool
> get_vt_h264_profile_level(AVCodecContext *avctx,
> > >>
>  compat_keys.kVTProfileLevel_H264_High_5_2;   break;
> > >> }
> > >> break;
> > >> +case H264_PROF_EXTENDED:
> > >> +switch (vtctx->level) {
> > >> +case  0: *profile_level_val =
> > >> +
> compat_keys.kVTProfileLevel_H264_Extended_AutoLevel; break;
> > >> +case 50: *profile_level_val =
> > >> +
> compat_keys.kVTProfileLevel_H264_Extended_5_0;   break;
> > >> +}
> > >> +break;
> > >> }
> > >>
> > >> if (!*profile_level_val) {
> > >> @@ -2531,6 +2544,7 @@ static const AVOption h264_options[] = {
> > >> { "baseline", "Baseline Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> H264_PROF_BASELINE }, INT_MIN, INT_MAX, VE, "profile" },
> > >> { "main", "Main Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> H264_PROF_MAIN }, INT_MIN, INT_MAX, VE, "profile" },
> > >> { "high", "High Profile", 0, AV_OPT_TYPE_CONST, { .i64 =
> H264_PROF_HIGH }, INT_MIN, INT_MAX, VE, "profile" },
> > >> +{ "extended", "Extend Profile",   0, AV_OPT_TYPE_CONST, { .i64 =
> H264_PROF_EXTENDED }, INT_MIN, INT_MAX, VE, "profile" },
> > >>
> > >> { "level", "Level", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = 0 },
> 0, 52, VE, "level" },
> > >> { "1.3", "Level 1.3, only available with Baseline Profile", 0,
> AV_OPT_TYPE_CONST, { .i64 = 13 }, INT_MIN, INT_MAX, VE, "level" },
> > >> --
> > >> 2.21.0
> > >>
> > > ___
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, 

[FFmpeg-devel] [PATCH 05/25] avcodec/v4l2_buffers: teach ff_v4l2_buffer_avframe_to_buf about contiguous planar formats

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

This fixes h264_v4l2m2m encoding on the Raspberry Pi

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 61 ++-
 1 file changed, 53 insertions(+), 8 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 51b0d25cad..17228fe36d 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -29,6 +29,7 @@
 #include 
 #include "libavcodec/avcodec.h"
 #include "libavcodec/internal.h"
+#include "libavutil/pixdesc.h"
 #include "v4l2_context.h"
 #include "v4l2_buffers.h"
 #include "v4l2_m2m.h"
@@ -257,17 +258,17 @@ static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, 
AVBufferRef **buf)
 return 0;
 }
 
-static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, 
int size, AVBufferRef* bref)
+static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, 
int size, int offset, AVBufferRef* bref)
 {
 unsigned int bytesused, length;
 
 if (plane >= out->num_planes)
 return AVERROR(EINVAL);
 
-bytesused = FFMIN(size, out->plane_info[plane].length);
 length = out->plane_info[plane].length;
+bytesused = FFMIN(size+offset, length);
 
-memcpy(out->plane_info[plane].mm_addr, data, FFMIN(size, 
out->plane_info[plane].length));
+memcpy((uint8_t*)out->plane_info[plane].mm_addr+offset, data, FFMIN(size, 
length-offset));
 
 if (V4L2_TYPE_IS_MULTIPLANAR(out->buf.type)) {
 out->planes[plane].bytesused = bytesused;
@@ -289,15 +290,59 @@ static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, 
const uint8_t* data, i
 int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
 {
 int i, ret;
+struct v4l2_format fmt = out->context->format;
+int pixel_format = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
+   fmt.fmt.pix_mp.pixelformat : fmt.fmt.pix.pixelformat;
+int height   = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
+   fmt.fmt.pix_mp.height : fmt.fmt.pix.height;
+int is_planar_format = 0;
+
+switch (pixel_format) {
+case V4L2_PIX_FMT_YUV420M:
+case V4L2_PIX_FMT_YVU420M:
+case V4L2_PIX_FMT_YUV422M:
+case V4L2_PIX_FMT_YVU422M:
+case V4L2_PIX_FMT_YUV444M:
+case V4L2_PIX_FMT_YVU444M:
+case V4L2_PIX_FMT_NV12M:
+case V4L2_PIX_FMT_NV21M:
+case V4L2_PIX_FMT_NV12MT_16X16:
+case V4L2_PIX_FMT_NV12MT:
+case V4L2_PIX_FMT_NV16M:
+case V4L2_PIX_FMT_NV61M:
+is_planar_format = 1;
+}
+
+v4l2_set_pts(out, frame->pts);
+
+if (!is_planar_format) {
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+int planes_nb = 0;
+int offset = 0;
+
+for (i = 0; i < desc->nb_components; i++)
+planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);
+
+for (i = 0; i < planes_nb; i++) {
+int size, h = height;
+if (i == 1 || i == 2) {
+h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
+}
+size = frame->linesize[i] * h;
+ret = v4l2_bufref_to_buf(out, 0, frame->data[i], size, offset, 
frame->buf[i]);
+if (ret)
+return ret;
+offset += size;
+}
+return 0;
+}
 
-for(i = 0; i < out->num_planes; i++) {
-ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, 
frame->buf[i]->size, frame->buf[i]);
+for (i = 0; i < out->num_planes; i++) {
+ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, 
frame->buf[i]->size, 0, frame->buf[i]);
 if (ret)
 return ret;
 }
 
-v4l2_set_pts(out, frame->pts);
-
 return 0;
 }
 
@@ -381,7 +426,7 @@ int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, 
V4L2Buffer *out)
 {
 int ret;
 
-ret = v4l2_bufref_to_buf(out, 0, pkt->data, pkt->size, pkt->buf);
+ret = v4l2_bufref_to_buf(out, 0, pkt->data, pkt->size, 0, pkt->buf);
 if (ret)
 return ret;
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 06/25] avcodec/v4l2_buffers: Add handling for NV21 and YUV420P

2019-09-02 Thread Aman Gupta
From: Dave Stevenson 

The single planar support was for NV12 only.
Add NV21 and YUV420P support.

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 17228fe36d..e7234d3ca7 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -366,11 +366,20 @@ int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 /* 1.1 fixup special cases */
 switch (avbuf->context->av_pix_fmt) {
 case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_NV21:
 if (avbuf->num_planes > 1)
 break;
 frame->linesize[1] = avbuf->plane_info[0].bytesperline;
 frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
 break;
+case AV_PIX_FMT_YUV420P:
+if (avbuf->num_planes > 1)
+break;
+frame->linesize[1] = avbuf->plane_info[0].bytesperline >> 1;
+frame->linesize[2] = avbuf->plane_info[0].bytesperline >> 1;
+frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
+frame->data[2] = frame->data[1] + ((avbuf->plane_info[0].bytesperline 
* avbuf->context->format.fmt.pix_mp.height) >> 2);
+break;
 default:
 break;
 }
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 10/25] avcodec/v4l2_m2m_dec: set pkt_dts on decoded frames to NOPTS

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Without this ffmpeg will attempt to copy the dts from the
most recently enqueued packet into the most recently dequeued
frame, which does not account for the buffering inside v4l2
and is not accurate.

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 1 +
 libavcodec/v4l2_m2m_dec.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index e7234d3ca7..4982fc564e 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -392,6 +392,7 @@ int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 frame->color_range = v4l2_get_color_range(avbuf);
 frame->color_trc = v4l2_get_color_trc(avbuf);
 frame->pts = v4l2_get_pts(avbuf);
+frame->pkt_dts = AV_NOPTS_VALUE;
 
 /* these two values are updated also during re-init in 
v4l2_process_driver_event */
 frame->height = s->output.height;
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index fb2bfde714..a3744208f3 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -242,6 +242,7 @@ static const AVOption options[] = {
 .close  = v4l2_decode_close, \
 .bsfs   = bsf_name, \
 .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | 
AV_CODEC_CAP_AVOID_PROBING, \
+.caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS, \
 .wrapper_name   = "v4l2m2m", \
 };
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 01/25] avcodec/v4l2_context: ensure v4l2_dequeue does not hang in poll() when no buffers are pending

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_context.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 6924760840..070988b4c3 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -264,8 +264,8 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, 
int timeout)
 };
 int i, ret;
 
-/* if we are draining and there are no more capture buffers queued in the 
driver we are done */
-if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx_to_m2mctx(ctx)->draining) {
+/* if there are no more capture buffers queued in the driver, skip polling 
*/
+if (!V4L2_TYPE_IS_OUTPUT(ctx->type)) {
 for (i = 0; i < ctx->num_buffers; i++) {
 /* capture buffer initialization happens during decode hence
  * detection happens at runtime
@@ -276,7 +276,9 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, 
int timeout)
 if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER)
 goto start;
 }
-ctx->done = 1;
+/* if we were waiting to drain, all done! */
+if (ctx_to_m2mctx(ctx)->draining)
+ctx->done = 1;
 return NULL;
 }
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 03/25] avcodec/v4l2_m2m: fix av_pix_fmt changing when multiple /dev/video* devices are probed

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

On the RPI, three different /dev/video devices exist (decoder, scaler, encoder).

When probing the devices in order, the originally requested pix fmt
would be mutated causing the wrong one to be chosen when a matching
device was finally found.

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_context.c |  4 ++--
 libavcodec/v4l2_context.h |  3 ++-
 libavcodec/v4l2_m2m.c | 10 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 070988b4c3..90356bb740 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -623,7 +623,7 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, 
AVPacket* pkt)
 return ff_v4l2_buffer_buf_to_avpkt(pkt, avbuf);
 }
 
-int ff_v4l2_context_get_format(V4L2Context* ctx)
+int ff_v4l2_context_get_format(V4L2Context* ctx, int probe)
 {
 struct v4l2_format_update fmt = { 0 };
 int ret;
@@ -633,7 +633,7 @@ int ff_v4l2_context_get_format(V4L2Context* ctx)
 if (ret)
 return ret;
 
-fmt.update_avfmt = 1;
+fmt.update_avfmt = !probe;
 v4l2_save_to_context(ctx, );
 
 /* format has been tried already */
diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h
index 632f1d0aac..ee08f3de41 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -113,9 +113,10 @@ int ff_v4l2_context_set_format(V4L2Context* ctx);
  * Queries the driver for a valid v4l2 format and copies it to the context.
  *
  * @param[in] ctx A pointer to a V4L2Context. See V4L2Context description for 
required variables.
+ * @param[in] probe Probe only and ignore changes to the format.
  * @return 0 in case of success, a negative value representing the error 
otherwise.
  */
-int ff_v4l2_context_get_format(V4L2Context* ctx);
+int ff_v4l2_context_get_format(V4L2Context* ctx, int probe);
 
 /**
  * Releases a V4L2Context.
diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 0cf5db284a..827662b9a5 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -108,13 +108,13 @@ static int v4l2_probe_driver(V4L2m2mContext* s)
 if (ret < 0)
 goto done;
 
-ret = ff_v4l2_context_get_format(>output);
+ret = ff_v4l2_context_get_format(>output, 1);
 if (ret) {
 av_log(s->avctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
 goto done;
 }
 
-ret = ff_v4l2_context_get_format(>capture);
+ret = ff_v4l2_context_get_format(>capture, 1);
 if (ret) {
 av_log(s->avctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
 goto done;
@@ -222,7 +222,7 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext* s)
 ff_v4l2_context_release(>capture);
 
 /* 3. get the new capture format */
-ret = ff_v4l2_context_get_format(>capture);
+ret = ff_v4l2_context_get_format(>capture, 0);
 if (ret) {
 av_log(s->avctx, AV_LOG_ERROR, "query the new capture format\n");
 return ret;
@@ -273,13 +273,13 @@ int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *s)
 s->draining = 0;
 s->reinit = 0;
 
-ret = ff_v4l2_context_get_format(>output);
+ret = ff_v4l2_context_get_format(>output, 0);
 if (ret) {
 av_log(log_ctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
 goto error;
 }
 
-ret = ff_v4l2_context_get_format(>capture);
+ret = ff_v4l2_context_get_format(>capture, 0);
 if (ret) {
 av_log(log_ctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
 goto error;
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 02/25] avcodec/v4l2_m2m: disable info logging during device probe

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 48104d01d2..0cf5db284a 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -60,7 +60,7 @@ static inline int v4l2_mplane_video(struct v4l2_capability 
*cap)
 return 0;
 }
 
-static int v4l2_prepare_contexts(V4L2m2mContext* s)
+static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 {
 struct v4l2_capability cap;
 int ret;
@@ -76,9 +76,10 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s)
 if (ret < 0)
 return ret;
 
-av_log(s->avctx, AV_LOG_INFO, "driver '%s' on card '%s' in %s mode\n", 
cap.driver, cap.card,
-   v4l2_mplane_video() ? "mplane" :
-   v4l2_splane_video() ? "splane" : 
"unknown");
+av_log(s->avctx, probe ? AV_LOG_DEBUG : AV_LOG_INFO,
+ "driver '%s' on card '%s' in %s mode\n", cap.driver, 
cap.card,
+ v4l2_mplane_video() ? "mplane" :
+ v4l2_splane_video() ? "splane" : "unknown");
 
 if (v4l2_mplane_video()) {
 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
@@ -103,7 +104,7 @@ static int v4l2_probe_driver(V4L2m2mContext* s)
 if (s->fd < 0)
 return AVERROR(errno);
 
-ret = v4l2_prepare_contexts(s);
+ret = v4l2_prepare_contexts(s, 1);
 if (ret < 0)
 goto done;
 
@@ -140,7 +141,7 @@ static int v4l2_configure_contexts(V4L2m2mContext* s)
 if (s->fd < 0)
 return AVERROR(errno);
 
-ret = v4l2_prepare_contexts(s);
+ret = v4l2_prepare_contexts(s, 0);
 if (ret < 0)
 goto error;
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 07/25] avcodec/v4l2_m2m: decouple v4l2_m2m helpers from AVCodecContext

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

This will allow re-use of the m2m backend with AVFilterContext

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_context.c |  9 +++
 libavcodec/v4l2_m2m.c | 50 +++
 libavcodec/v4l2_m2m.h | 18 +++---
 libavcodec/v4l2_m2m_dec.c | 14 +++
 libavcodec/v4l2_m2m_enc.c | 13 +++---
 5 files changed, 60 insertions(+), 44 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 90356bb740..b02142a5d6 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -48,9 +48,9 @@ static inline V4L2m2mContext *ctx_to_m2mctx(V4L2Context *ctx)
 container_of(ctx, V4L2m2mContext, capture);
 }
 
-static inline AVCodecContext *logger(V4L2Context *ctx)
+static inline AVClass *logger(V4L2Context *ctx)
 {
-return ctx_to_m2mctx(ctx)->avctx;
+return ctx_to_m2mctx(ctx)->priv;
 }
 
 static inline unsigned int v4l2_get_width(struct v4l2_format *fmt)
@@ -96,7 +96,7 @@ static inline int v4l2_get_framesize_compressed(V4L2Context* 
ctx, int width, int
 const int SZ_4K = 0x1000;
 int size;
 
-if (av_codec_is_decoder(s->avctx->codec))
+if (s->avctx && av_codec_is_decoder(s->avctx->codec))
 return ((width * height * 3 / 2) / 2) + 128;
 
 /* encoder */
@@ -193,7 +193,8 @@ static int v4l2_handle_event(V4L2Context *ctx)
 }
 
 if (reinit) {
-ret = ff_set_dimensions(s->avctx, s->capture.width, s->capture.height);
+if (s->avctx)
+ret = ff_set_dimensions(s->avctx, s->capture.width, 
s->capture.height);
 if (ret < 0)
 av_log(logger(ctx), AV_LOG_WARNING, "update avcodec height and 
width\n");
 
diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 827662b9a5..358f587797 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -63,6 +63,7 @@ static inline int v4l2_mplane_video(struct v4l2_capability 
*cap)
 static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 {
 struct v4l2_capability cap;
+void *log_ctx = s->priv;
 int ret;
 
 s->capture.done = s->output.done = 0;
@@ -76,7 +77,7 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 if (ret < 0)
 return ret;
 
-av_log(s->avctx, probe ? AV_LOG_DEBUG : AV_LOG_INFO,
+av_log(log_ctx, probe ? AV_LOG_DEBUG : AV_LOG_INFO,
  "driver '%s' on card '%s' in %s mode\n", cap.driver, 
cap.card,
  v4l2_mplane_video() ? "mplane" :
  v4l2_splane_video() ? "splane" : "unknown");
@@ -98,6 +99,7 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 
 static int v4l2_probe_driver(V4L2m2mContext* s)
 {
+void *log_ctx = s->priv;
 int ret;
 
 s->fd = open(s->devname, O_RDWR | O_NONBLOCK, 0);
@@ -110,20 +112,20 @@ static int v4l2_probe_driver(V4L2m2mContext* s)
 
 ret = ff_v4l2_context_get_format(>output, 1);
 if (ret) {
-av_log(s->avctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
+av_log(log_ctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
 goto done;
 }
 
 ret = ff_v4l2_context_get_format(>capture, 1);
 if (ret) {
-av_log(s->avctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
+av_log(log_ctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
 goto done;
 }
 
 done:
 if (close(s->fd) < 0) {
 ret = AVERROR(errno);
-av_log(s->avctx, AV_LOG_ERROR, "failure closing %s (%s)\n", 
s->devname, av_err2str(AVERROR(errno)));
+av_log(log_ctx, AV_LOG_ERROR, "failure closing %s (%s)\n", s->devname, 
av_err2str(AVERROR(errno)));
 }
 
 s->fd = -1;
@@ -133,7 +135,7 @@ done:
 
 static int v4l2_configure_contexts(V4L2m2mContext* s)
 {
-void *log_ctx = s->avctx;
+void *log_ctx = s->priv;
 int ret;
 struct v4l2_format ofmt, cfmt;
 
@@ -174,7 +176,7 @@ static int v4l2_configure_contexts(V4L2m2mContext* s)
 }
 
 /* decoder's buffers need to be updated at a later stage */
-if (!av_codec_is_decoder(s->avctx->codec)) {
+if (!s->avctx || !av_codec_is_decoder(s->avctx->codec)) {
 ret = ff_v4l2_context_init(>capture);
 if (ret) {
 av_log(log_ctx, AV_LOG_ERROR, "no v4l2 capture context's 
buffers\n");
@@ -202,20 +204,21 @@ error:
  
**/
 int ff_v4l2_m2m_codec_reinit(V4L2m2mContext* s)
 {
+void *log_ctx = s->priv;
 int ret;
 
-av_log(s->avctx, AV_LOG_DEBUG, "reinit context\n");
+av_log(log_ctx, AV_LOG_DEBUG, "reinit context\n");
 
 /* 1. streamoff */
 ret = ff_v4l2_context_set_status(>capture, VIDIOC_STREAMOFF);
 if (ret)
-av_log(s->avctx, AV_LOG_ERROR, "capture VIDIOC_STREAMOFF\n");
+av_log(log_ctx, AV_LOG_ERROR, "capture VIDIOC_STREAMOFF\n");
 
 /* 2. unmap the capture buffers (v4l2 and ffmpeg):
  *we must wait for all references to be 

[FFmpeg-devel] [PATCH 04/25] avcodec/v4l2_m2m_enc: add support for -force_key_frames

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m_enc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 27bb254fc1..a0d5bcf760 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -245,6 +245,9 @@ static int v4l2_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
 V4L2Context *const output = >output;
 
+if (frame && frame->pict_type == AV_PICTURE_TYPE_I)
+v4l2_set_ext_ctrl(s, MPEG_CID(FORCE_KEY_FRAME), 0, "force key frame");
+
 return ff_v4l2_context_enqueue_frame(output, frame);
 }
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 09/25] avcodec/v4l2_m2m_enc: fix indentation and add M2MENC_CLASS macro

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m_enc.c | 44 ---
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 8014e442a8..4849bc26c5 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -332,28 +332,30 @@ static const AVOption options[] = {
 { NULL },
 };
 
+#define M2MENC_CLASS(NAME) \
+static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
+.class_name = #NAME "_v4l2m2m_encoder", \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+};
+
 #define M2MENC(NAME, LONGNAME, CODEC) \
-static const AVClass v4l2_m2m_ ## NAME ## _enc_class = {\
-.class_name = #NAME "_v4l2_m2m_encoder",\
-.item_name  = av_default_item_name,\
-.option = options,\
-.version= LIBAVUTIL_VERSION_INT,\
-};\
-\
-AVCodec ff_ ## NAME ## _v4l2m2m_encoder = { \
-.name   = #NAME "_v4l2m2m" ,\
-.long_name  = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " encoder 
wrapper"),\
-.type   = AVMEDIA_TYPE_VIDEO,\
-.id = CODEC ,\
-.priv_data_size = sizeof(V4L2m2mPriv),\
-.priv_class = _m2m_ ## NAME ##_enc_class,\
-.init   = v4l2_encode_init,\
-.send_frame = v4l2_send_frame,\
-.receive_packet = v4l2_receive_packet,\
-.close  = v4l2_encode_close,\
-.capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
-.wrapper_name   = "v4l2m2m", \
-};
+M2MENC_CLASS(NAME) \
+AVCodec ff_ ## NAME ## _v4l2m2m_encoder = { \
+.name   = #NAME "_v4l2m2m" , \
+.long_name  = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " 
encoder wrapper"), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = CODEC , \
+.priv_data_size = sizeof(V4L2m2mPriv), \
+.priv_class = _m2m_ ## NAME ##_enc_class, \
+.init   = v4l2_encode_init, \
+.send_frame = v4l2_send_frame, \
+.receive_packet = v4l2_receive_packet, \
+.close  = v4l2_encode_close, \
+.capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
+.wrapper_name   = "v4l2m2m", \
+};
 
 M2MENC(mpeg4,"MPEG4", AV_CODEC_ID_MPEG4);
 M2MENC(h263, "H.263", AV_CODEC_ID_H263);
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 00/25] V4L2 support for DRM_PRIME

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

This patchset enables a zero-copy hardware accelerated
decode+scale+encode pipeline on the RPI4 via V4L2. It also
includes various patches submitted to ffmpeg-devel in the
past and from LibreELEC's ffmpeg fork.

The V4L2 decoders can either output software pixel formats,
or be used with `-hwaccel drm` to return AV_PIX_FMT_DRM_PRIME
frames. These drm_prime frames can be fed into both the new
vf_scale_v4l2m2m and the v4l2m2m encoders to achieve zero-copy
video pipelines which use very little CPU.

For example, when decoding h264 using the v4l2 hardware,
the decoder can either return a software nv12/yuv420p frame, or a
drm_prime frame (depending on whether the hwaccel has been activated):

  ./ffmpeg -c:v h264_v4l2m2m -i sample.mpg -map 0:v -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0x256d390] requesting formats: output=H264/none 
capture=NV12/nv12
  
  ./ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -c:v h264_v4l2m2m -i 
sample.mpg -map 0:v -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0xefb400] requesting formats: output=H264/none 
capture=NV12/drm_prime

When feeding the decoded frames into the hardware encoder,
a huge reduction in CPU usage is seen when using drm_prime to avoid
copying frame data back and forth:

  ./ffmpeg -c:v h264_v4l2m2m -i sample.mpg -map 0:v -c:v h264_v4l2m2m -b:v 
3000k -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0x2653800] requesting formats: output=H264/none 
capture=NV12/nv12
  [h264_v4l2m2m_encoder @ 0x2654410] requesting formats: output=NV12/nv12 
capture=H264/none
  FPS=80 CPU=75%
  
  ./ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -c:v h264_v4l2m2m -i 
sample.mpg -map 0:v -c:v h264_v4l2m2m -b:v 3000k -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0x19203f0] requesting formats: output=H264/none 
capture=NV12/drm_prime
  [h264_v4l2m2m_encoder @ 0x191f780] requesting formats: output=NV12/drm_prime 
capture=H264/none
  FPS=76 CPU=7%

Finally this patchset also adds a v4l2m2m scaler which takes
advantage of the broadcom ISP (Image Sensor Processor) available
on the RPI and exposed via v4l2. Again, using drm_prime references
between the scaler and encoder reduces CPU usage drastically:

  ./ffmpeg -c:v h264_v4l2m2m -i sample.mpg -map 0:v -vf scale_v4l2m2m=-2:480 
-c:v h264_v4l2m2m -b:v 3000k -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0x1ac73b0] requesting formats: output=H264/none 
capture=NV12/nv12
  [scale_v4l2m2m @ 0x1b802d0] requesting formats: output=NV12/nv12 
capture=NV12/nv12
  [h264_v4l2m2m_encoder @ 0x1ac7ce0] requesting formats: output=NV12/nv12 
capture=H264/none
  FPS=84 CPU=60%
  
  ./ffmpeg -hwaccel drm -init_hw_device drm=v4l2drm -filter_hw_device v4l2drm 
-hwaccel_output_format drm_prime -c:v h264_v4l2m2m -i sample.mpg -map 0:v -vf 
scale_v4l2m2m=-2:480 -c:v h264_v4l2m2m -b:v 3000k -f null -y /dev/null
  [h264_v4l2m2m_decoder @ 0x22f74f0] requesting formats: output=H264/none 
capture=NV12/drm_prime
  [scale_v4l2m2m @ 0x239b440] requesting formats: output=NV12/drm_prime 
capture=NV12/drm_prime
  [h264_v4l2m2m_encoder @ 0x22f7080] requesting formats: output=NV12/drm_prime 
capture=H264/none
  FPS=73 CPU=10%

I've tested this extensively on the RPI3+ and RPI4. I am also
awaiting the arrival of some AMLogic hardware to verify the
patchset works there as expected.

I'm fairly confident in most of this patchset, however the
HWContext integration could use a few more eyes. I'm still
not certain whether it makes sense reuse `-hwaccel drm` here
(by allowing null/dummy drm device creation via the last commit),
or if a new `-hwaccel v4l2m2m` would be better. Unfortunately
AFAIK there is no standard way to map frames into v4l2 hardware,
so the only way to end up with a drm_prime frame is by feeding
pixel data into the decoder or scaler first.





Aman Gupta (19):
  avcodec/v4l2_context: ensure v4l2_dequeue does not hang in poll() when
no buffers are pending
  avcodec/v4l2_m2m: disable info logging during device probe
  avcodec/v4l2_m2m: fix av_pix_fmt changing when multiple /dev/video*
devices are probed
  avcodec/v4l2_m2m_enc: add support for -force_key_frames
  avcodec/v4l2_buffers: teach ff_v4l2_buffer_avframe_to_buf about
contiguous planar formats
  avcodec/v4l2_m2m: decouple v4l2_m2m helpers from AVCodecContext
  avcodec/v4l2_m2m_enc: fix indentation and add M2MENC_CLASS macro
  avcodec/v4l2_m2m_dec: set pkt_dts on decoded frames to NOPTS
  avcodec/v4l2_buffers: split out AVFrame generation into helper method
  avcodec/v4l2_buffers: split out V4L2Buffer generation into helper
method
  avcodec/v4l2_buffers: read height/width from the proper context
  avcodec/v4l2_m2m: add support for AV_PIX_FMT_DRM_PRIME
  avcodec/v4l2_m2m_dec: add support for AV_PIX_FMT_DRM_PRIME
  avcodec/v4l2_m2m_enc: add support for AV_PIX_FMT_DRM_PRIME
  avcodec/v4l2_context: expose timeout for dequeue_frame
  avfilter/vf_scale_v4l2m2m: add V4L2 M2M scaler
  avcodec/v4l2m2m: clean up buffer options and pick sane defaults
  

[FFmpeg-devel] [PATCH 20/25] avfilter/vf_scale_v4l2m2m: add V4L2 M2M scaler

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

works on Raspberry Pi using /dev/video12 wrapper for OMX.broadcom.isp

Signed-off-by: Aman Gupta 
---
 configure  |   1 +
 libavcodec/v4l2_buffers.c  |  12 +-
 libavcodec/v4l2_m2m.h  |   4 +
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_scale_v4l2m2m.c | 343 +
 6 files changed, 360 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/vf_scale_v4l2m2m.c

diff --git a/configure b/configure
index c8a72e1760..7c25b82578 100755
--- a/configure
+++ b/configure
@@ -3564,6 +3564,7 @@ zmq_filter_deps="libzmq"
 zoompan_filter_deps="swscale"
 zscale_filter_deps="libzimg const_nan"
 scale_vaapi_filter_deps="vaapi"
+scale_v4l2m2m_filter_deps="v4l2_m2m"
 vpp_qsv_filter_deps="libmfx"
 vpp_qsv_filter_select="qsvvpp"
 yadif_cuda_filter_deps="ffnvcodec"
diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 2a1eac7a35..33439ddb64 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -59,13 +59,17 @@ static inline void v4l2_set_pts(V4L2Buffer *out, int64_t 
pts)
 {
 V4L2m2mContext *s = buf_to_m2mctx(out);
 AVRational v4l2_timebase = { 1, USEC_PER_SEC };
+AVRational timebase;
 int64_t v4l2_pts;
 
 if (pts == AV_NOPTS_VALUE)
 pts = 0;
 
+timebase = s->filterctx ? s->filterctx->inputs[0]->time_base
+: s->avctx->time_base;
+
 /* convert pts to v4l2 timebase */
-v4l2_pts = av_rescale_q(pts, s->avctx->time_base, v4l2_timebase);
+v4l2_pts = av_rescale_q(pts, timebase, v4l2_timebase);
 out->buf.timestamp.tv_usec = v4l2_pts % USEC_PER_SEC;
 out->buf.timestamp.tv_sec = v4l2_pts / USEC_PER_SEC;
 }
@@ -74,13 +78,17 @@ static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf)
 {
 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
 AVRational v4l2_timebase = { 1, USEC_PER_SEC };
+AVRational timebase;
 int64_t v4l2_pts;
 
+timebase = s->filterctx ? s->filterctx->inputs[0]->time_base
+: s->avctx->time_base;
+
 /* convert pts back to encoder timebase */
 v4l2_pts = (int64_t)avbuf->buf.timestamp.tv_sec * USEC_PER_SEC +
 avbuf->buf.timestamp.tv_usec;
 
-return av_rescale_q(v4l2_pts, v4l2_timebase, s->avctx->time_base);
+return av_rescale_q(v4l2_pts, v4l2_timebase, timebase);
 }
 
 static enum AVColorPrimaries v4l2_get_color_primaries(V4L2Buffer *buf)
diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h
index 662e682aa5..b94d724a93 100644
--- a/libavcodec/v4l2_m2m.h
+++ b/libavcodec/v4l2_m2m.h
@@ -30,6 +30,7 @@
 #include 
 
 #include "libavcodec/avcodec.h"
+#include "libavfilter/avfilter.h"
 #include "v4l2_context.h"
 
 #define container_of(ptr, type, member) ({ \
@@ -48,6 +49,9 @@ typedef struct V4L2m2mContext {
 V4L2Context capture;
 V4L2Context output;
 
+/* filter context */
+AVFilterContext *filterctx;
+
 /* dynamic stream reconfig */
 AVCodecContext *avctx;
 sem_t refsync;
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 3ef4191d9a..6d21e18a51 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -355,6 +355,7 @@ OBJS-$(CONFIG_SCALE_CUDA_FILTER) += 
vf_scale_cuda.o vf_scale_cuda.pt
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
 OBJS-$(CONFIG_SCALE_QSV_FILTER)  += vf_scale_qsv.o
 OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o scale.o 
vaapi_vpp.o
+OBJS-$(CONFIG_SCALE_V4L2M2M_FILTER)  += vf_scale_v4l2m2m.o scale.o
 OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
 OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
 OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b675c688ee..e914cff183 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -337,6 +337,7 @@ extern AVFilter ff_vf_scale_cuda;
 extern AVFilter ff_vf_scale_npp;
 extern AVFilter ff_vf_scale_qsv;
 extern AVFilter ff_vf_scale_vaapi;
+extern AVFilter ff_vf_scale_v4l2m2m;
 extern AVFilter ff_vf_scale2ref;
 extern AVFilter ff_vf_select;
 extern AVFilter ff_vf_selectivecolor;
diff --git a/libavfilter/vf_scale_v4l2m2m.c b/libavfilter/vf_scale_v4l2m2m.c
new file mode 100644
index 00..a5ffa9953e
--- /dev/null
+++ b/libavfilter/vf_scale_v4l2m2m.c
@@ -0,0 +1,343 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License 

[FFmpeg-devel] [PATCH 23/25] avcodec/v4l2_buffers: use correct timebase for encoder/decoder/filter

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 389b5dea8d..d8cec06cb3 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -55,40 +55,41 @@ static inline AVCodecContext *logger(V4L2Buffer *buf)
 return buf_to_m2mctx(buf)->avctx;
 }
 
+static inline AVRational v4l2_get_timebase(V4L2Buffer *avbuf)
+{
+V4L2m2mContext *s = buf_to_m2mctx(avbuf);
+
+if (s->filterctx)
+return s->filterctx->inputs[0]->time_base;
+if (s->avctx->pkt_timebase.num)
+return s->avctx->pkt_timebase;
+return s->avctx->time_base;
+}
+
 static inline void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
 {
-V4L2m2mContext *s = buf_to_m2mctx(out);
 AVRational v4l2_timebase = { 1, USEC_PER_SEC };
-AVRational timebase;
 int64_t v4l2_pts;
 
 if (pts == AV_NOPTS_VALUE)
 pts = 0;
 
-timebase = s->filterctx ? s->filterctx->inputs[0]->time_base
-: s->avctx->time_base;
-
 /* convert pts to v4l2 timebase */
-v4l2_pts = av_rescale_q(pts, timebase, v4l2_timebase);
+v4l2_pts = av_rescale_q(pts, v4l2_get_timebase(out), v4l2_timebase);
 out->buf.timestamp.tv_usec = v4l2_pts % USEC_PER_SEC;
 out->buf.timestamp.tv_sec = v4l2_pts / USEC_PER_SEC;
 }
 
 static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf)
 {
-V4L2m2mContext *s = buf_to_m2mctx(avbuf);
 AVRational v4l2_timebase = { 1, USEC_PER_SEC };
-AVRational timebase;
 int64_t v4l2_pts;
 
-timebase = s->filterctx ? s->filterctx->inputs[0]->time_base
-: s->avctx->time_base;
-
 /* convert pts back to encoder timebase */
 v4l2_pts = (int64_t)avbuf->buf.timestamp.tv_sec * USEC_PER_SEC +
 avbuf->buf.timestamp.tv_usec;
 
-return av_rescale_q(v4l2_pts, v4l2_timebase, timebase);
+return av_rescale_q(v4l2_pts, v4l2_timebase, v4l2_get_timebase(avbuf));
 }
 
 static enum AVColorPrimaries v4l2_get_color_primaries(V4L2Buffer *buf)
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 25/25] hwcontext_drm: do not require drm device

2019-09-02 Thread Aman Gupta
From: Jonas Karlman 

This allows the cli to create a dummy drm hwcontext
that can be shared between the v4l2 decoder/scaler/encoder.

This is especially useful on older RPI3 where /dev/dri devices
are not available in the default configuration.

Signed-off-by: Jonas Karlman 
Signed-off-by: Aman Gupta 
---
 libavutil/hwcontext_drm.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c
index 32cbde82eb..aa4794c5e6 100644
--- a/libavutil/hwcontext_drm.c
+++ b/libavutil/hwcontext_drm.c
@@ -43,6 +43,11 @@ static int drm_device_create(AVHWDeviceContext *hwdev, const 
char *device,
 AVDRMDeviceContext *hwctx = hwdev->hwctx;
 drmVersionPtr version;
 
+if (device == NULL) {
+  hwctx->fd = -1;
+  return 0;
+}
+
 hwctx->fd = open(device, O_RDWR);
 if (hwctx->fd < 0)
 return AVERROR(errno);
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 22/25] avcodec/v4l2_context: set frame SAR using VIDIOC_CROPCAP

2019-09-02 Thread Aman Gupta
From: Maxime Jourdan 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c |  3 ++-
 libavcodec/v4l2_context.c | 20 
 libavcodec/v4l2_context.h |  1 +
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 33439ddb64..389b5dea8d 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -585,9 +585,10 @@ int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 frame->pts = v4l2_get_pts(avbuf);
 frame->pkt_dts = AV_NOPTS_VALUE;
 
-/* these two values are updated also during re-init in 
v4l2_process_driver_event */
+/* these values are updated also during re-init in 
v4l2_process_driver_event */
 frame->height = avbuf->context->height;
 frame->width = avbuf->context->width;
+frame->sample_aspect_ratio = avbuf->context->sample_aspect_ratio;
 
 /* 3. report errors upstream */
 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 26e06273be..0461a9c7cf 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -64,6 +64,24 @@ static inline unsigned int v4l2_get_height(struct 
v4l2_format *fmt)
 return V4L2_TYPE_IS_MULTIPLANAR(fmt->type) ? fmt->fmt.pix_mp.height : 
fmt->fmt.pix.height;
 }
 
+static AVRational v4l2_get_sar(V4L2Context *ctx)
+{
+struct AVRational sar = { 1, 1 };
+struct v4l2_cropcap cropcap;
+int ret;
+
+memset(, 0, sizeof(cropcap));
+cropcap.type = ctx->type;
+
+ret = ioctl(ctx_to_m2mctx(ctx)->fd, VIDIOC_CROPCAP, );
+if (ret)
+return sar;
+
+sar.num = cropcap.pixelaspect.numerator;
+sar.den = cropcap.pixelaspect.denominator;
+return sar;
+}
+
 static inline unsigned int v4l2_resolution_changed(V4L2Context *ctx, struct 
v4l2_format *fmt2)
 {
 struct v4l2_format *fmt1 = >format;
@@ -177,12 +195,14 @@ static int v4l2_handle_event(V4L2Context *ctx)
 if (full_reinit) {
 s->output.height = v4l2_get_height(_fmt);
 s->output.width = v4l2_get_width(_fmt);
+s->output.sample_aspect_ratio = v4l2_get_sar(>output);
 }
 
 reinit = v4l2_resolution_changed(>capture, _fmt);
 if (reinit) {
 s->capture.height = v4l2_get_height(_fmt);
 s->capture.width = v4l2_get_width(_fmt);
+s->capture.sample_aspect_ratio = v4l2_get_sar(>capture);
 }
 
 if (full_reinit || reinit)
diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h
index 64c53d07b5..67ac36c8bf 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -70,6 +70,7 @@ typedef struct V4L2Context {
  * or accepts (in case of an output context, e.g. when encoding).
  */
 int width, height;
+AVRational sample_aspect_ratio;
 
 /**
  * Indexed array of V4L2Buffers
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 24/25] avcodec/v4l2_buffers: extract v4l2_timebase constant

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index d8cec06cb3..8424fbcd3e 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -42,6 +42,7 @@
 #include "v4l2_m2m.h"
 
 #define USEC_PER_SEC 100
+static AVRational v4l2_timebase = { 1, USEC_PER_SEC };
 
 static inline V4L2m2mContext *buf_to_m2mctx(V4L2Buffer *buf)
 {
@@ -68,7 +69,6 @@ static inline AVRational v4l2_get_timebase(V4L2Buffer *avbuf)
 
 static inline void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
 {
-AVRational v4l2_timebase = { 1, USEC_PER_SEC };
 int64_t v4l2_pts;
 
 if (pts == AV_NOPTS_VALUE)
@@ -82,7 +82,6 @@ static inline void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
 
 static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf)
 {
-AVRational v4l2_timebase = { 1, USEC_PER_SEC };
 int64_t v4l2_pts;
 
 /* convert pts back to encoder timebase */
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 21/25] avcodec/v4l2m2m: clean up buffer options and pick sane defaults

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Previously the default values for output/capture buffers were
quite high, causing a lot of memory usage on devices with limited
resources. On a default RPI3 installation, it is easy to run out of
kernel CMA memory without additional kernel boot flags.

Similar patches are being used in the LibreELEC ffmpeg fork for
AMLogic support.

I also reduced the minimum value for the buffering options so that users
can further reduce the number of buffers if required on their specific
platform.

Prior to this change, setting up a decode+scale+encode pipeline on
the RPI would fail with ENOMEM due to a total of 76 buffers being
pre-allocated.

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m.h  | 6 --
 libavcodec/v4l2_m2m_dec.c  | 4 +---
 libavcodec/v4l2_m2m_enc.c  | 4 +---
 libavfilter/vf_scale_v4l2m2m.c | 6 +-
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h
index b94d724a93..f60773d227 100644
--- a/libavcodec/v4l2_m2m.h
+++ b/libavcodec/v4l2_m2m.h
@@ -37,9 +37,11 @@
 const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
 (type *)((char *)__mptr - offsetof(type,member) );})
 
-#define V4L_M2M_DEFAULT_OPTS \
+#define V4L_M2M_DEFAULT_OPTS(output_bufs, capture_bufs) \
 { "num_output_buffers", "Number of buffers in the output context",\
-OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, 
INT_MAX, FLAGS }
+OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = output_bufs },  
1, INT_MAX, FLAGS }, \
+{ "num_capture_buffers", "Number of buffers in the capture context", \
+OFFSET(num_capture_buffers), AV_OPT_TYPE_INT, {.i64 = capture_bufs }, 
1, INT_MAX, FLAGS }
 
 typedef struct V4L2m2mContext {
 char devname[PATH_MAX];
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 71b2211594..36c2363eee 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -281,9 +281,7 @@ static void v4l2_flush(AVCodecContext *avctx)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
 static const AVOption options[] = {
-V4L_M2M_DEFAULT_OPTS,
-{ "num_capture_buffers", "Number of buffers in the capture context",
-OFFSET(num_capture_buffers), AV_OPT_TYPE_INT, {.i64 = 20}, 20, 
INT_MAX, FLAGS },
+V4L_M2M_DEFAULT_OPTS(8, 6),
 { NULL},
 };
 
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 4ccfe77322..ca433ac1ea 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -342,9 +342,7 @@ static av_cold int v4l2_encode_close(AVCodecContext *avctx)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
 static const AVOption options[] = {
-V4L_M2M_DEFAULT_OPTS,
-{ "num_capture_buffers", "Number of buffers in the capture context",
-OFFSET(num_capture_buffers), AV_OPT_TYPE_INT, {.i64 = 4 }, 4, INT_MAX, 
FLAGS },
+V4L_M2M_DEFAULT_OPTS(6, 8),
 { NULL },
 };
 
diff --git a/libavfilter/vf_scale_v4l2m2m.c b/libavfilter/vf_scale_v4l2m2m.c
index a5ffa9953e..03d9f6406c 100644
--- a/libavfilter/vf_scale_v4l2m2m.c
+++ b/libavfilter/vf_scale_v4l2m2m.c
@@ -301,11 +301,7 @@ static const AVOption scale_v4l2m2m_options[] = {
 
 #undef OFFSET
 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
-
-V4L_M2M_DEFAULT_OPTS,
-{ "num_capture_buffers", "Number of buffers in the capture context",
-OFFSET(num_capture_buffers), AV_OPT_TYPE_INT, {.i64 = 4 }, 4, INT_MAX, 
FLAGS },
-
+V4L_M2M_DEFAULT_OPTS(6, 6),
 { NULL },
 };
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 15/25] avcodec/v4l2_m2m: add support for AV_PIX_FMT_DRM_PRIME

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Based on patch originally developed by Lukas Rusak 

This allows for a zero-copy output by exporting the v4l2 buffer then 
wrapping that buffer
in the AVDRMFrameDescriptor like it is done in rkmpp.

This has been in use for quite some time with great success on many 
platforms including:
 - Amlogic S905
 - Raspberry Pi
 - i.MX6
 - Dragonboard 410c

This was developed in conjunction with Kodi to allow handling the zero-copy 
buffer rendering.
A simply utility for testing is also available here: 
https://github.com/BayLibre/ffmpeg-drm

Signed-off-by: Aman Gupta 
---
 configure |   1 +
 libavcodec/v4l2_buffers.c | 188 --
 libavcodec/v4l2_buffers.h |   4 +
 libavcodec/v4l2_context.c |  73 +--
 libavcodec/v4l2_context.h |   6 ++
 libavcodec/v4l2_m2m.c |  10 +-
 libavcodec/v4l2_m2m.h |   3 +
 7 files changed, 267 insertions(+), 18 deletions(-)

diff --git a/configure b/configure
index 4c77e1cab1..c8a72e1760 100755
--- a/configure
+++ b/configure
@@ -2995,6 +2995,7 @@ qsvenc_select="qsv"
 qsvvpp_select="qsv"
 vaapi_encode_deps="vaapi"
 v4l2_m2m_deps="linux_videodev2_h sem_timedwait"
+v4l2_m2m_suggest="libdrm"
 
 hwupload_cuda_filter_deps="ffnvcodec"
 scale_npp_filter_deps="ffnvcodec libnpp"
diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 46c9f11d7b..2a1eac7a35 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -21,6 +21,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+#if CONFIG_LIBDRM
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -29,6 +34,8 @@
 #include 
 #include "libavcodec/avcodec.h"
 #include "libavcodec/internal.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext.h"
 #include "libavutil/pixdesc.h"
 #include "v4l2_context.h"
 #include "v4l2_buffers.h"
@@ -248,6 +255,127 @@ static int v4l2_buf_increase_ref(V4L2Buffer *in)
 return 0;
 }
 
+#if CONFIG_LIBDRM
+static uint8_t *v4l2_get_drm_frame(V4L2Buffer *avbuf)
+{
+AVDRMFrameDescriptor *drm_desc = >drm_frame;
+AVDRMLayerDescriptor *layer;
+
+/* fill the DRM frame descriptor */
+drm_desc->nb_objects = avbuf->num_planes;
+drm_desc->nb_layers = 1;
+
+layer = _desc->layers[0];
+layer->nb_planes = avbuf->num_planes;
+
+for (int i = 0; i < avbuf->num_planes; i++) {
+layer->planes[i].object_index = i;
+layer->planes[i].offset = 0;
+layer->planes[i].pitch = avbuf->plane_info[i].bytesperline;
+}
+
+switch (avbuf->context->av_pix_fmt) {
+case AV_PIX_FMT_YUYV422:
+layer->format = DRM_FORMAT_YUYV;
+layer->nb_planes = 1;
+
+break;
+
+case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_NV21:
+layer->format = avbuf->context->av_pix_fmt == AV_PIX_FMT_NV12 ?
+DRM_FORMAT_NV12 : DRM_FORMAT_NV21;
+
+if (avbuf->num_planes > 1)
+break;
+
+layer->nb_planes = 2;
+
+layer->planes[1].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
+avbuf->context->format.fmt.pix.height;
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline;
+break;
+
+case AV_PIX_FMT_YUV420P:
+layer->format = DRM_FORMAT_YUV420;
+
+if (avbuf->num_planes > 1)
+break;
+
+layer->nb_planes = 3;
+
+layer->planes[1].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline *
+avbuf->context->format.fmt.pix.height;
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline >> 1;
+
+layer->planes[2].object_index = 0;
+layer->planes[2].offset = layer->planes[1].offset +
+((avbuf->plane_info[0].bytesperline *
+  avbuf->context->format.fmt.pix.height) >> 2);
+layer->planes[2].pitch = avbuf->plane_info[0].bytesperline >> 1;
+break;
+
+default:
+drm_desc->nb_layers = 0;
+break;
+}
+
+return (uint8_t *)drm_desc;
+}
+
+static int v4l2_buffer_export_drm(V4L2Buffer* avbuf)
+{
+struct v4l2_exportbuffer expbuf;
+int i, ret;
+
+for (i = 0; i < avbuf->num_planes; i++) {
+memset(, 0, sizeof(expbuf));
+
+expbuf.index = avbuf->buf.index;
+expbuf.type = avbuf->buf.type;
+expbuf.plane = i;
+
+ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_EXPBUF, );
+if (ret < 0)
+return AVERROR(errno);
+
+if (V4L2_TYPE_IS_MULTIPLANAR(avbuf->buf.type)) {
+/* drm frame */
+avbuf->drm_frame.objects[i].size = avbuf->buf.m.planes[i].length;
+avbuf->drm_frame.objects[i].fd = expbuf.fd;
+avbuf->drm_frame.objects[i].format_modifier = 
DRM_FORMAT_MOD_LINEAR;
+} else {
+/* drm frame */
+avbuf->drm_frame.objects[0].size = avbuf->buf.length;
+

[FFmpeg-devel] [PATCH 18/25] avcodec/v4l2_context: expose timeout for dequeue_frame

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_context.c | 6 +++---
 libavcodec/v4l2_context.h | 3 ++-
 libavcodec/v4l2_m2m_dec.c | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 32246cf564..26e06273be 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -616,16 +616,16 @@ int ff_v4l2_context_enqueue_packet(V4L2Context* ctx, 
const AVPacket* pkt)
 return ff_v4l2_buffer_enqueue(avbuf);
 }
 
-int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* frame)
+int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* frame, int 
timeout)
 {
 V4L2Buffer* avbuf = NULL;
 
 /*
- * blocks until:
+ * timeout=-1 blocks until:
  *  1. decoded frame available
  *  2. an input buffer is ready to be dequeued
  */
-avbuf = v4l2_dequeue_v4l2buf(ctx, -1);
+avbuf = v4l2_dequeue_v4l2buf(ctx, timeout);
 if (!avbuf) {
 if (ctx->done)
 return AVERROR_EOF;
diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h
index f9d02b748f..64c53d07b5 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -160,9 +160,10 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, 
AVPacket* pkt);
  * The frame must be non NULL.
  * @param[in] ctx The V4L2Context to dequeue from.
  * @param[inout] f The AVFrame to dequeue to.
+ * @param[in] timeout The timeout for dequeue (-1 to block, 0 to return 
immediately or milliseconds)
  * @return 0 in case of success, AVERROR(EAGAIN) if no buffer was ready, 
another negative error in case of error.
  */
-int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* f);
+int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* f, int timeout);
 
 /**
  * Enqueues a buffer to a V4L2Context from an AVPacket
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 6b73d2ffd9..b37b6ac7d9 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -172,7 +172,7 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 
 dequeue:
 av_packet_unref();
-return ff_v4l2_context_dequeue_frame(capture, frame);
+return ff_v4l2_context_dequeue_frame(capture, frame, -1);
 }
 
 static av_cold int v4l2_decode_init(AVCodecContext *avctx)
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 19/25] avcodec/v4l2_m2m_dec: fix dropped packets while decoding

2019-09-02 Thread Aman Gupta
From: Maxime Jourdan 

* FFmpeg retrieves a packet from the bitstream
* It attempts to get an input buffer (from its own list or by dequeuing one 
from the driver)
* If no input buffer is found, the bitstream packet is dropped instead of 
scheduled for trying again later

It's an issue that showed especially at high speeds (like using `-f null -` as 
output parameters).

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m.h |  1 +
 libavcodec/v4l2_m2m_dec.c | 21 -
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h
index 97848363ef..662e682aa5 100644
--- a/libavcodec/v4l2_m2m.h
+++ b/libavcodec/v4l2_m2m.h
@@ -56,6 +56,7 @@ typedef struct V4L2m2mContext {
 
 /* null frame/packet received */
 int draining;
+AVPacket buf_pkt;
 
 /* Reference to self; only valid while codec is active. */
 AVBufferRef *self_ref;
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index b37b6ac7d9..71b2211594 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -143,9 +143,14 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 AVPacket avpkt = {0};
 int ret;
 
-ret = ff_decode_get_packet(avctx, );
-if (ret < 0 && ret != AVERROR_EOF)
-return ret;
+if (s->buf_pkt.size) {
+avpkt = s->buf_pkt;
+memset(>buf_pkt, 0, sizeof(AVPacket));
+} else {
+ret = ff_decode_get_packet(avctx, );
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+}
 
 if (s->draining)
 goto dequeue;
@@ -154,6 +159,8 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN))
return ret;
+
+s->buf_pkt = avpkt;
 /* no input buffers available, continue dequeing */
 }
 
@@ -171,7 +178,8 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 }
 
 dequeue:
-av_packet_unref();
+if (!s->buf_pkt.size)
+av_packet_unref();
 return ff_v4l2_context_dequeue_frame(capture, frame, -1);
 }
 
@@ -244,7 +252,10 @@ static av_cold int v4l2_decode_init(AVCodecContext *avctx)
 
 static av_cold int v4l2_decode_close(AVCodecContext *avctx)
 {
-return ff_v4l2_m2m_codec_end(avctx->priv_data);
+V4L2m2mPriv *priv = avctx->priv_data;
+V4L2m2mContext* s = priv->context;
+av_packet_unref(>buf_pkt);
+return ff_v4l2_m2m_codec_end(priv);
 }
 
 static void v4l2_flush(AVCodecContext *avctx)
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 13/25] avcodec/v4l2_buffers: split out v4l2_buf_increase_ref helper

2019-09-02 Thread Aman Gupta
From: Lukas Rusak 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 36 +++-
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 721e01420b..f90c50db80 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -228,27 +228,17 @@ static void v4l2_free_buffer(void *opaque, uint8_t 
*unused)
 }
 }
 
-static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
+static int v4l2_buf_increase_ref(V4L2Buffer *in)
 {
 V4L2m2mContext *s = buf_to_m2mctx(in);
 
-if (plane >= in->num_planes)
-return AVERROR(EINVAL);
-
-/* even though most encoders return 0 in data_offset encoding vp8 does 
require this value */
-*buf = av_buffer_create((char *)in->plane_info[plane].mm_addr + 
in->planes[plane].data_offset,
-in->plane_info[plane].length, v4l2_free_buffer, 
in, 0);
-if (!*buf)
-return AVERROR(ENOMEM);
-
 if (in->context_ref)
 atomic_fetch_add(>context_refcount, 1);
 else {
 in->context_ref = av_buffer_ref(s->self_ref);
-if (!in->context_ref) {
-av_buffer_unref(buf);
+if (!in->context_ref)
 return AVERROR(ENOMEM);
-}
+
 in->context_refcount = 1;
 }
 
@@ -258,6 +248,26 @@ static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, 
AVBufferRef **buf)
 return 0;
 }
 
+static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
+{
+int ret;
+
+if (plane >= in->num_planes)
+return AVERROR(EINVAL);
+
+/* even though most encoders return 0 in data_offset encoding vp8 does 
require this value */
+*buf = av_buffer_create((char *)in->plane_info[plane].mm_addr + 
in->planes[plane].data_offset,
+in->plane_info[plane].length, v4l2_free_buffer, 
in, 0);
+if (!*buf)
+return AVERROR(ENOMEM);
+
+ret = v4l2_buf_increase_ref(in);
+if (ret)
+av_buffer_unref(buf);
+
+return ret;
+}
+
 static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, 
int size, int offset, AVBufferRef* bref)
 {
 unsigned int bytesused, length;
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 14/25] avcodec/v4l2_buffers: read height/width from the proper context

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Frames are generally dequeued into capture buffers, so using
the output properties here was incorrect. It happened to work
fine for decoding, since the output/capture buffers have the same
dimensions.

For the v4l2 scaler, the dimensions can be different between output
and capture. Using the buffer's associated context makes this code
work correctly regardless of where the frame is coming from.

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index f90c50db80..46c9f11d7b 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -404,7 +404,6 @@ int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 
 int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
 {
-V4L2m2mContext *s = buf_to_m2mctx(avbuf);
 int ret;
 
 av_frame_unref(frame);
@@ -424,8 +423,8 @@ int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 frame->pkt_dts = AV_NOPTS_VALUE;
 
 /* these two values are updated also during re-init in 
v4l2_process_driver_event */
-frame->height = s->output.height;
-frame->width = s->output.width;
+frame->height = avbuf->context->height;
+frame->width = avbuf->context->width;
 
 /* 3. report errors upstream */
 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 16/25] avcodec/v4l2_m2m_dec: add support for AV_PIX_FMT_DRM_PRIME

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Based on patchset submitted to ffmpeg-devel by Lukas Rusak 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_m2m_dec.c | 85 ---
 1 file changed, 80 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index a3744208f3..6b73d2ffd9 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -23,11 +23,16 @@
 
 #include 
 #include 
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_drm.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/decode.h"
+#include "libavcodec/hwaccel.h"
+#include "libavcodec/internal.h"
 
 #include "v4l2_context.h"
 #include "v4l2_m2m.h"
@@ -39,7 +44,7 @@ static int v4l2_try_start(AVCodecContext *avctx)
 V4L2Context *const capture = >capture;
 V4L2Context *const output = >output;
 struct v4l2_selection selection;
-int ret;
+int ret, pix_fmt;
 
 /* 1. start the output process */
 if (!output->streamon) {
@@ -62,8 +67,13 @@ static int v4l2_try_start(AVCodecContext *avctx)
 }
 
 /* 2.1 update the AVCodecContext */
-avctx->pix_fmt = 
ff_v4l2_format_v4l2_to_avfmt(capture->format.fmt.pix_mp.pixelformat, 
AV_CODEC_ID_RAWVIDEO);
+pix_fmt = 
ff_v4l2_format_v4l2_to_avfmt(capture->format.fmt.pix_mp.pixelformat, 
AV_CODEC_ID_RAWVIDEO);
+if (avctx->pix_fmt != AV_PIX_FMT_DRM_PRIME)
+avctx->pix_fmt = pix_fmt;
+else
+avctx->sw_pix_fmt = pix_fmt;
 capture->av_pix_fmt = avctx->pix_fmt;
+capture->sw_pix_fmt = avctx->sw_pix_fmt;
 
 /* 3. set the crop parameters */
 selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -189,15 +199,42 @@ static av_cold int v4l2_decode_init(AVCodecContext *avctx)
 output->av_codec_id = avctx->codec_id;
 output->av_pix_fmt  = AV_PIX_FMT_NONE;
 
+/* negotiate drm vs software pixel formats */
+avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
+switch (avctx->pix_fmt) {
+case AV_PIX_FMT_DRM_PRIME:
+avctx->sw_pix_fmt = AV_PIX_FMT_NV12;
+break;
+
+case AV_PIX_FMT_NONE:
+return 0;
+break;
+
+default:
+break;
+}
+
 capture->av_codec_id = AV_CODEC_ID_RAWVIDEO;
 capture->av_pix_fmt = avctx->pix_fmt;
+capture->sw_pix_fmt = avctx->sw_pix_fmt;
+
+if (avctx->hw_device_ctx) {
+s->device_ref = av_buffer_ref(avctx->hw_device_ctx);
+} else {
+s->device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DRM);
+if (!s->device_ref)
+return AVERROR(ENOMEM);
+
+ret = av_hwdevice_ctx_init(s->device_ref);
+if (ret < 0) {
+av_buffer_unref(>device_ref);
+return ret;
+}
+}
 
 ret = ff_v4l2_m2m_codec_init(priv);
 if (ret) {
 av_log(avctx, AV_LOG_ERROR, "can't configure decoder\n");
-s->self_ref = NULL;
-av_buffer_unref(>context_ref);
-
 return ret;
 }
 s->avctx = avctx;
@@ -210,6 +247,25 @@ static av_cold int v4l2_decode_close(AVCodecContext *avctx)
 return ff_v4l2_m2m_codec_end(avctx->priv_data);
 }
 
+static void v4l2_flush(AVCodecContext *avctx)
+{
+V4L2m2mPriv *priv = avctx->priv_data;
+V4L2m2mContext* s = priv->context;
+int ret;
+
+/* wait for pending buffer references */
+if (atomic_load(>refcount))
+while(sem_wait(>refsync) == -1 && errno == EINTR);
+
+ret = ff_v4l2_context_set_status(>output, VIDIOC_STREAMOFF);
+if (ret)
+av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->output.name);
+
+ret = ff_v4l2_context_set_status(>capture, VIDIOC_STREAMOFF);
+if (ret)
+av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->capture.name);
+}
+
 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
@@ -220,6 +276,19 @@ static const AVOption options[] = {
 { NULL},
 };
 
+static const AVCodecHWConfigInternal *v4l2_m2m_hw_configs[] = {
+&(const AVCodecHWConfigInternal) {
+.public = {
+.pix_fmt = AV_PIX_FMT_DRM_PRIME,
+.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX |
+   AV_CODEC_HW_CONFIG_METHOD_INTERNAL,
+.device_type = AV_HWDEVICE_TYPE_DRM
+},
+.hwaccel = NULL,
+},
+NULL
+};
+
 #define M2MDEC_CLASS(NAME) \
 static const AVClass v4l2_m2m_ ## NAME ## _dec_class = { \
 .class_name = #NAME "_v4l2m2m_decoder", \
@@ -240,7 +309,13 @@ static const AVOption options[] = {
 .init   = v4l2_decode_init, \
 .receive_frame  = v4l2_receive_frame, \
 .close  = v4l2_decode_close, \
+.flush  = v4l2_flush, \
+.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_DRM_PRIME, 
\
+ AV_PIX_FMT_NV12, \
+ 

[FFmpeg-devel] [PATCH 17/25] avcodec/v4l2_m2m_enc: add support for AV_PIX_FMT_DRM_PRIME

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

---
 libavcodec/v4l2_m2m_enc.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 4849bc26c5..4ccfe77322 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -302,11 +302,27 @@ static av_cold int v4l2_encode_init(AVCodecContext *avctx)
 /* output context */
 output->av_codec_id = AV_CODEC_ID_RAWVIDEO;
 output->av_pix_fmt = avctx->pix_fmt;
+if (output->av_pix_fmt == AV_PIX_FMT_DRM_PRIME)
+output->sw_pix_fmt = AV_PIX_FMT_NV12;
 
 /* capture context */
 capture->av_codec_id = avctx->codec_id;
 capture->av_pix_fmt = AV_PIX_FMT_NONE;
 
+if (avctx->hw_device_ctx) {
+s->device_ref = av_buffer_ref(avctx->hw_device_ctx);
+} else {
+s->device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DRM);
+if (!s->device_ref)
+return AVERROR(ENOMEM);
+
+ret = av_hwdevice_ctx_init(s->device_ref);
+if (ret < 0) {
+av_buffer_unref(>device_ref);
+return ret;
+}
+}
+
 ret = ff_v4l2_m2m_codec_init(priv);
 if (ret) {
 av_log(avctx, AV_LOG_ERROR, "can't configure encoder\n");
@@ -353,6 +369,10 @@ static const AVOption options[] = {
 .send_frame = v4l2_send_frame, \
 .receive_packet = v4l2_receive_packet, \
 .close  = v4l2_encode_close, \
+.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_NV12, \
+ AV_PIX_FMT_YUV420P, \
+ AV_PIX_FMT_DRM_PRIME, 
\
+ AV_PIX_FMT_NONE}, \
 .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
 .wrapper_name   = "v4l2m2m", \
 };
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 11/25] avcodec/v4l2_buffers: split out AVFrame generation into helper method

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 76 +++
 1 file changed, 45 insertions(+), 31 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 4982fc564e..784ea94d4c 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -281,6 +281,47 @@ static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, 
const uint8_t* data, i
 return 0;
 }
 
+static int v4l2_buffer_buf_to_swframe(AVFrame *frame, V4L2Buffer *avbuf)
+{
+int i, ret;
+
+frame->format = avbuf->context->av_pix_fmt;
+
+for (i = 0; i < avbuf->num_planes; i++) {
+ret = v4l2_buf_to_bufref(avbuf, i, >buf[i]);
+if (ret)
+return ret;
+
+frame->linesize[i] = avbuf->plane_info[i].bytesperline;
+frame->data[i] = frame->buf[i]->data;
+}
+
+/* fixup special cases */
+switch (avbuf->context->av_pix_fmt) {
+case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_NV21:
+if (avbuf->num_planes > 1)
+break;
+frame->linesize[1] = avbuf->plane_info[0].bytesperline;
+frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
+break;
+
+case AV_PIX_FMT_YUV420P:
+if (avbuf->num_planes > 1)
+break;
+frame->linesize[1] = avbuf->plane_info[0].bytesperline >> 1;
+frame->linesize[2] = avbuf->plane_info[0].bytesperline >> 1;
+frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
+frame->data[2] = frame->data[1] + ((avbuf->plane_info[0].bytesperline 
* avbuf->context->format.fmt.pix_mp.height) >> 2);
+break;
+
+default:
+break;
+}
+
+return 0;
+}
+
 /**
  *
  *  V4L2Buffer interface
@@ -349,44 +390,17 @@ int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
 {
 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
-int i, ret;
+int ret;
 
 av_frame_unref(frame);
 
 /* 1. get references to the actual data */
-for (i = 0; i < avbuf->num_planes; i++) {
-ret = v4l2_buf_to_bufref(avbuf, i, >buf[i]);
-if (ret)
-return ret;
-
-frame->linesize[i] = avbuf->plane_info[i].bytesperline;
-frame->data[i] = frame->buf[i]->data;
-}
-
-/* 1.1 fixup special cases */
-switch (avbuf->context->av_pix_fmt) {
-case AV_PIX_FMT_NV12:
-case AV_PIX_FMT_NV21:
-if (avbuf->num_planes > 1)
-break;
-frame->linesize[1] = avbuf->plane_info[0].bytesperline;
-frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
-break;
-case AV_PIX_FMT_YUV420P:
-if (avbuf->num_planes > 1)
-break;
-frame->linesize[1] = avbuf->plane_info[0].bytesperline >> 1;
-frame->linesize[2] = avbuf->plane_info[0].bytesperline >> 1;
-frame->data[1] = frame->buf[0]->data + 
avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
-frame->data[2] = frame->data[1] + ((avbuf->plane_info[0].bytesperline 
* avbuf->context->format.fmt.pix_mp.height) >> 2);
-break;
-default:
-break;
-}
+ret = v4l2_buffer_buf_to_swframe(frame, avbuf);
+if (ret)
+return ret;
 
 /* 2. get frame information */
 frame->key_frame = !!(avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME);
-frame->format = avbuf->context->av_pix_fmt;
 frame->color_primaries = v4l2_get_color_primaries(avbuf);
 frame->colorspace = v4l2_get_color_space(avbuf);
 frame->color_range = v4l2_get_color_range(avbuf);
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 12/25] avcodec/v4l2_buffers: split out V4L2Buffer generation into helper method

2019-09-02 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 784ea94d4c..721e01420b 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -322,13 +322,7 @@ static int v4l2_buffer_buf_to_swframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 return 0;
 }
 
-/**
- *
- *  V4L2Buffer interface
- *
- 
**/
-
-int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
+static int v4l2_buffer_swframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
 {
 int i, ret;
 struct v4l2_format fmt = out->context->format;
@@ -354,8 +348,6 @@ int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 is_planar_format = 1;
 }
 
-v4l2_set_pts(out, frame->pts);
-
 if (!is_planar_format) {
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
 int planes_nb = 0;
@@ -387,6 +379,19 @@ int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 return 0;
 }
 
+/**
+ *
+ *  V4L2Buffer interface
+ *
+ 
**/
+
+int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
+{
+v4l2_set_pts(out, frame->pts);
+
+return v4l2_buffer_swframe_to_buf(frame, out);
+}
+
 int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
 {
 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 08/25] avcodec/v4l2_m2m_dec: fix indentation and add M2MDEC_CLASS macro

2019-09-02 Thread Aman Gupta
From: Lukas Rusak 

This just makes the M2MDEC_CLASS similar to how it is done in rkmpp. It looks
clean and has proper indentation
---
 libavcodec/v4l2_m2m_dec.c | 45 ---
 1 file changed, 23 insertions(+), 22 deletions(-)

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

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 5/5] avcodec/apedec: Check max_samples

2019-09-02 Thread James Almer
On 9/2/2019 9:14 PM, Michael Niedermayer wrote:
> Fixes: OOM
> Fixes: 
> 16627/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5638059583864832
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/apedec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> index e218f7c043..774ce18531 100644
> --- a/libavcodec/apedec.c
> +++ b/libavcodec/apedec.c
> @@ -1475,6 +1475,9 @@ static int ape_decode_frame(AVCodecContext *avctx, void 
> *data,
>  return AVERROR_INVALIDDATA;
>  }
>  
> +if (nblocks * (int64_t)avctx->channels > avctx->max_samples)
> +return AVERROR(EINVAL);
> +

Shouldn't this be checked in ff_get_buffer()? Same as max_pixels, but
checking "frame->nb_samples > avctx->max_samples" instead or
width/height. Otherwise it will barely be used.

>  /* Initialize the frame decoder */
>  if (init_frame_decoder(s) < 0) {
>  av_log(avctx, AV_LOG_ERROR, "Error reading frame header\n");
> 

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/5] avcodec/apedec: Fix several integer overflows in predictor_update_filter() and do_apply_filter()

2019-09-02 Thread Michael Niedermayer
Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an 
unsigned type to negate this value to itself
Fixes: signed integer overflow: -14527961 - 2147483425 cannot be represented in 
type 'int'
Fixes: 
16380/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5645957131141120

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

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index ed22f0f019..e218f7c043 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1121,7 +1121,7 @@ static av_always_inline int 
predictor_update_filter(APEPredictor *p,
 
 p->buf[delayA] = p->lastA[filter];
 p->buf[adaptA] = APESIGN(p->buf[delayA]);
-p->buf[delayA - 1] = p->buf[delayA] - p->buf[delayA - 1];
+p->buf[delayA - 1] = p->buf[delayA] - (unsigned)p->buf[delayA - 1];
 p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]);
 
 predictionA = p->buf[delayA] * p->coeffsA[filter][0] +
@@ -1132,7 +1132,7 @@ static av_always_inline int 
predictor_update_filter(APEPredictor *p,
 /*  Apply a scaled first-order filter compression */
 p->buf[delayB] = p->filterA[filter ^ 1] - ((int)(p->filterB[filter] * 
31U) >> 5);
 p->buf[adaptB] = APESIGN(p->buf[delayB]);
-p->buf[delayB - 1] = p->buf[delayB] - p->buf[delayB - 1];
+p->buf[delayB - 1] = p->buf[delayB] - (unsigned)p->buf[delayB - 1];
 p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]);
 p->filterB[filter] = p->filterA[filter ^ 1];
 
@@ -1282,7 +1282,7 @@ static void do_apply_filter(APEContext *ctx, int version, 
APEFilter *f,
 /* Version 3.98 and later files */
 
 /* Update the adaption coefficients */
-absres = FFABS(res);
+absres = res < 0 ? -(unsigned)res : res;
 if (absres)
 *f->adaptcoeffs = APESIGN(res) *
   (8 << ((absres > f->avg * 3) + (absres > 
f->avg * 4 / 3)));
-- 
2.23.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 3/5] avcodec: add max_samples

2019-09-02 Thread Michael Niedermayer
TODO: APIChanges, bump version

Signed-off-by: Michael Niedermayer 
---
 libavcodec/avcodec.h | 8 
 libavcodec/options_table.h   | 1 +
 tests/ref/fate/api-mjpeg-codec-param | 2 ++
 tests/ref/fate/api-png-codec-param   | 2 ++
 4 files changed, 13 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index de4feb6a65..4b771a6ae6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3371,6 +3371,14 @@ typedef struct AVCodecContext {
  * - encoding: unused
  */
 int discard_damaged_percentage;
+
+/**
+ * The number of samples per frame to maximally accept.
+ *
+ * - decoding: set by user
+ * - encoding: set by user
+ */
+int64_t max_samples;
 } AVCodecContext;
 
 #if FF_API_CODEC_GET_SET
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index c3a500a629..b56e653bf6 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -476,6 +476,7 @@ static const AVOption avcodec_options[] = {
 {"pixel_format", "set pixel format", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, 
{.i64=AV_PIX_FMT_NONE}, -1, INT_MAX, 0 },
 {"video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, 
{.str=NULL}, 0, INT_MAX, 0 },
 {"max_pixels", "Maximum number of pixels", OFFSET(max_pixels), 
AV_OPT_TYPE_INT64, {.i64 = INT_MAX }, 0, INT_MAX, A|V|S|D|E },
+{"max_samples", "Maximum number of samples", OFFSET(max_samples), 
AV_OPT_TYPE_INT64, {.i64 = INT_MAX }, 0, INT_MAX, A|D|E },
 {"hwaccel_flags", NULL, OFFSET(hwaccel_flags), AV_OPT_TYPE_FLAGS, {.i64 = 
AV_HWACCEL_FLAG_IGNORE_LEVEL }, 0, UINT_MAX, V|D, "hwaccel_flags"},
 {"ignore_level", "ignore level even if the codec level used is unknown or 
higher than the maximum supported level reported by the hardware driver", 0, 
AV_OPT_TYPE_CONST, { .i64 = AV_HWACCEL_FLAG_IGNORE_LEVEL }, INT_MIN, INT_MAX, V 
| D, "hwaccel_flags" },
 {"allow_high_depth", "allow to output YUV pixel formats with a different 
chroma sampling than 4:2:0 and/or other than 8 bits per component", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH }, INT_MIN, 
INT_MAX, V | D, "hwaccel_flags"},
diff --git a/tests/ref/fate/api-mjpeg-codec-param 
b/tests/ref/fate/api-mjpeg-codec-param
index 0815919d7d..e55cef0eb9 100644
--- a/tests/ref/fate/api-mjpeg-codec-param
+++ b/tests/ref/fate/api-mjpeg-codec-param
@@ -136,6 +136,7 @@ stream=0, decode=0
 pixel_format=yuvj422p
 video_size=400x225
 max_pixels=2147483647
+max_samples=2147483647
 hwaccel_flags=0x0001
 extra_hw_frames=-1
 discard_damaged_percentage=95
@@ -277,6 +278,7 @@ stream=0, decode=1
 pixel_format=yuvj422p
 video_size=400x225
 max_pixels=2147483647
+max_samples=2147483647
 hwaccel_flags=0x0001
 extra_hw_frames=-1
 discard_damaged_percentage=95
diff --git a/tests/ref/fate/api-png-codec-param 
b/tests/ref/fate/api-png-codec-param
index a47d0963da..c04c8cc7c1 100644
--- a/tests/ref/fate/api-png-codec-param
+++ b/tests/ref/fate/api-png-codec-param
@@ -136,6 +136,7 @@ stream=0, decode=0
 pixel_format=rgba
 video_size=128x128
 max_pixels=2147483647
+max_samples=2147483647
 hwaccel_flags=0x0001
 extra_hw_frames=-1
 discard_damaged_percentage=95
@@ -277,6 +278,7 @@ stream=0, decode=1
 pixel_format=rgba
 video_size=128x128
 max_pixels=2147483647
+max_samples=2147483647
 hwaccel_flags=0x0001
 extra_hw_frames=-1
 discard_damaged_percentage=95
-- 
2.23.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/5] avcodec/apedec: Fix 32bit int overflow in do_apply_filter()

2019-09-02 Thread Michael Niedermayer
Fixes: signed integer overflow: 2147480546 + 4096 cannot be represented in type 
'int'
Fixes: 
16280/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5123442566758400

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

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 490b11b94e..ed22f0f019 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1266,7 +1266,7 @@ static void do_apply_filter(APEContext *ctx, int version, 
APEFilter *f,
  f->delay - order,
  f->adaptcoeffs - order,
  order, APESIGN(*data));
-res = (res + (1 << (fracbits - 1))) >> fracbits;
+res = (int)(res + (1U << (fracbits - 1))) >> fracbits;
 res += *data;
 *data++ = res;
 
-- 
2.23.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 4/5] tools/target_dec_fuzzer: Set max_samples

2019-09-02 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index 3a19efd031..1e26ac738f 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -90,6 +90,8 @@ const uint32_t maxiteration = 8096;
 const uint64_t maxpixels_per_frame = 4096 * 4096;
 uint64_t maxpixels;
 
+const uint64_t maxsamples_per_frame = 256*1024*64;
+
 static const uint64_t FUZZ_TAG = 0x4741542D5A5A5546ULL;
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
@@ -152,6 +154,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 ctx->max_pixels = maxpixels_per_frame; //To reduce false positive OOM 
and hangs
 ctx->refcounted_frames = 1; //To reduce false positive timeouts and focus 
testing on the refcounted API
 
+ctx->max_samples = maxsamples_per_frame;
+
 if (size > 1024) {
 GetByteContext gbc;
 int extradata_size;
-- 
2.23.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 5/5] avcodec/apedec: Check max_samples

2019-09-02 Thread Michael Niedermayer
Fixes: OOM
Fixes: 
16627/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5638059583864832

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

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index e218f7c043..774ce18531 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1475,6 +1475,9 @@ static int ape_decode_frame(AVCodecContext *avctx, void 
*data,
 return AVERROR_INVALIDDATA;
 }
 
+if (nblocks * (int64_t)avctx->channels > avctx->max_samples)
+return AVERROR(EINVAL);
+
 /* Initialize the frame decoder */
 if (init_frame_decoder(s) < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error reading frame header\n");
-- 
2.23.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avfilter/vf_delogo: add auto set the area inside of the frame

2019-09-02 Thread Steven Liu
when the area outside of the frame, then use expr should
give user warning message and auto set to the area inside of the frame.

Signed-off-by: Steven Liu 
---
 libavfilter/vf_delogo.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 814575a36c..5521a29214 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -327,6 +327,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 s->w = av_expr_eval(s->w_pexpr, s->var_values, s);
 s->h = av_expr_eval(s->h_pexpr, s->var_values, s);
 
+if (s->x + (s->band - 1) < 0 || s->x + s->w - (s->band*2 - 2) > inlink->w 
||
+s->y + (s->band - 1) < 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) 
{
+av_log(s, AV_LOG_WARNING, "Logo area is outside of the frame,"
+   "auto set the area inside of the frame\n");
+}
+if (s->x + (s->band - 1) < 0)
+s->x = s->band;
+if (s->y + (s->band - 1) < 0)
+s->y = s->band;
+if (s->x + s->w - (s->band*2 - 2) > inlink->w)
+s->x = inlink->w - s->w + (s->band*2 - 2);
+if (s->y + s->h - (s->band*2 - 2) > inlink->h)
+s->y = inlink->h - s->h + (s->band*2 - 2);
+
 ret = config_input(inlink);
 if (ret < 0) {
 av_frame_free();
-- 
2.15.1



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] avfilter/vf_delogo: support expr in delogo filter

2019-09-02 Thread Steven Liu


> 在 2019年9月2日,21:43,Limin Wang  写道:
> 
> On Wed, Aug 28, 2019 at 05:01:13PM +0200, Michael Niedermayer wrote:
>> On Wed, Aug 28, 2019 at 05:39:32AM +0800, Steven Liu wrote:
>>> Signed-off-by: Steven Liu 
>>> ---
>>> libavfilter/vf_delogo.c | 83 
>>> ++---
>>> 1 file changed, 79 insertions(+), 4 deletions(-)
>> 
>> breaks fate
> 
> ping, the fate is broken for master
Ah,

That is fixed by Paul B Mahol.

expr for our user at scene:
a car from one position[x, y] to the other position[x1, y1],
then our user want blur or delgo it.

> 
>> 
>> --- ./tests/ref/fate/filter-delogo   2019-08-27 23:33:16.098044653 +0200
>> +++ tests/data/fate/filter-delogo2019-08-28 16:38:23.481781287 +0200
>> @@ -11,104 +11,104 @@
>> 0,  5,  5,1,   126720, 0x259af497
>> 0,  6,  6,1,   126720, 0x5e6ff4d7
>> 0,  7,  7,1,   126720, 0xcc10f4b7
>> -0,  8,  8,1,   126720, 0x2811b819
>> -0,  9,  9,1,   126720, 0x9b36b8d9
>> -0, 10, 10,1,   126720, 0x9488b919
>> -0, 11, 11,1,   126720, 0x316cb902
>> -0, 12, 12,1,   126720, 0xfd2ab949
>> -0, 13, 13,1,   126720, 0x7cc9bbb9
>> -0, 14, 14,1,   126720, 0xdb1bbc39
>> ...
>> 
>> [...]
>> -- 
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>> 
>> Elect your leaders based on what they did after the last election, not
>> based on what they say before an election.
>> 
> 
> 
> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Thanks
Steven





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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v6] Add ZeroMQ as protocol option

2019-09-02 Thread Marton Balint



On Sat, 31 Aug 2019, Andriy Gelman wrote:


Changes in v6:
   - Changed minimum required libzmq version from 4.3.1 to 4.2.1
   - Removed ff_ prefix from static functions
   - Use zmq_ctx_term function instead of zmq_ctx_destroy (since
 zmq_ctx_destroy is deprecated)



Thanks, applied.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avformat: Introduced `AVInputFormat.read_timestamp2` to fix keyframe seeking for formats that rely on `read_timestamp` for seeking

2019-09-02 Thread Darren Mo
Yup! I just wanted to do the migration in phases rather than all at once so 
that I can do one demuxer at a time while gathering feedback. At the end of the 
migration, I’ll rename `read_timestamp2` to `read_timestamp`.

> On Sep 2, 2019, at 1:07 PM, James Almer  wrote:
> 
> AVInputFormat.read_timestamp() is not a public field. There's no need to
> deprecate it and add a replacement. Just change it as you see fit,
> making sure to update all demuxers that may use it.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avformat: Introduced `AVInputFormat.read_timestamp2` to fix keyframe seeking for formats that rely on `read_timestamp` for seeking

2019-09-02 Thread James Almer
On 8/31/2019 7:10 AM, fumoboy...@me.com wrote:
> From: fumoboy007 
> 
> If the user omits `AVSEEK_FLAG_ANY`, then the result of the seek should be a 
> keyframe. `ff_gen_search` did not respect that contract because it had no 
> good way to determine whether a timestamp returned by `read_timestamp` was 
> for a keyframe packet.
> 
> Therefore, we introduce `read_timestamp2`, which adds a new parameter named 
> `prefer_keyframe`. This new parameter tells the input format whether to skip 
> non-keyframe packets. The parameter is named `prefer_keyframe` instead of 
> something like `keyframe_only` because some formats do not distinguish 
> between keyframe and non-keyframe packets.
> 
> This commit adds the new function and deprecates the old function. Subsequent 
> commits will migrate input formats to the new function.
> 
> Signed-off-by: fumoboy007 
> ---
>  libavformat/avformat.h |  9 +++
>  libavformat/internal.h |  6 +++--
>  libavformat/nutdec.c   |  6 ++---
>  libavformat/utils.c| 56 +-
>  4 files changed, 60 insertions(+), 17 deletions(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 6eb329f13f..1db548663c 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -741,6 +741,7 @@ typedef struct AVInputFormat {
>   * Get the next timestamp in stream[stream_index].time_base units.
>   * @return the timestamp or AV_NOPTS_VALUE if an error occurred
>   */
> +attribute_deprecated
>  int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
>int64_t *pos, int64_t pos_limit);
>  
> @@ -781,6 +782,14 @@ typedef struct AVInputFormat {
>   * @see avdevice_capabilities_free() for more details.
>   */
>  int (*free_device_capabilities)(struct AVFormatContext *s, struct 
> AVDeviceCapabilitiesQuery *caps);
> +
> +/**
> + * Get the next timestamp in stream[stream_index].time_base units.
> + * @param prefer_keyframe Whether to skip over non-keyframe packets (if 
> possible).
> + * @return the timestamp or AV_NOPTS_VALUE if an error occurred
> + */
> +int64_t (*read_timestamp2)(struct AVFormatContext *s, int stream_index,
> +   int64_t *pos, int64_t pos_limit, int 
> prefer_keyframe);
>  } AVInputFormat;
>  /**
>   * @}
AVInputFormat.read_timestamp() is not a public field. There's no need to
deprecate it and add a replacement. Just change it as you see fit,
making sure to update all demuxers that may use it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] avformat/mpegtsenc: fix flushing of audio packets

2019-09-02 Thread Marton Balint



On Wed, 28 Aug 2019, Marton Balint wrote:




On Wed, 28 Aug 2019, Andreas Håkon wrote:


Hi Marton,


‐‐‐ Original Message ‐‐‐
On Tuesday, 27 de August de 2019 23:33, Marton Balint  

wrote:


> Please, note that the main problem at time with the mpegts muxer is that 

all PES packets are
> written sequentially. And this generates a lot of problems when the 

video PES packets are large,
> or when the audio packets aren't flushed at regular intervals. If you 

prefer to improve the
> current sequential mode before you do anything with the interleaved 

mode, then I give this
> suggestion: Use a PES SIZE INTERVAL for audio packets instead of 

calculating a TIME DELAY. With

> CBR audio steams, every audio PES packet has the same payload size.

I am not sure what you mean when you say PES size interval, but if you are
referring to the size of the PES packet - that is exactly what we had in
the very beginning, and it was not sufficent because for low bitrate
streams when combining small audio packets to a PES packet it took too
long time, and in order to generate a proper TS we have to make sure that
we don't delay the audio packets too much, becuase if we do, then it will
arrive at the destination later then the PCR which makes presentation
impossible.


The problem is that you're thinking of using the same pes_size for all 

audio packets!

For each audio stream you need to calculate the correct pes_size.


max_pes_size = max_audio_delay * audio_bitrate

it is the same thing for CBR, you calculate one from the other.

And the value is based on the bitrate. So for CBR audio streams the value 

is

fixed, and you only need to recalculate it for VBR audio streams.

Please, try to add some "pes_top_size" member at stream level, and use it 

for

audio streams. You can calculate the value when you know the bitrate, and
after that a simple "if ts_st->payload >= ts_st->pes_top_size" will be 

sufficient

to trigger the dispatch of the PES packet.


I don't see how calclating a max_pes_size is superior. It _only_ works for 
CBR, plus you don't really know the audio bitrate, you'd have to guess it 
from some frame sample count and audio packet size.


What is the disadvantage of always using a timestamp based contraint 
instead of a sized based? A timestamp based one works for both CBR and 
VBR, and you don't have to recalculate anything based on some bitrate 
guessing.


Applied this as well.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avformat: Introduced `AVInputFormat.read_timestamp2` to fix keyframe seeking for formats that rely on `read_timestamp` for seeking

2019-09-02 Thread Darren Mo
That’s true. However, I think your approach would produce incorrect results 
when `AVSEEK_FLAG_BACKWARD` is used.

The bisection would find the frame just before the target time and then we 
would search for the next keyframe, which would be after the target time. 
Instead, we want to return the keyframe just before the target time.

Any ideas on how to do that more efficiently?

> On Sep 2, 2019, at 7:33 AM, Michael Niedermayer  
> wrote:
> 
> i think this is the wrong way to fix the issue unless iam missing something
> 
> Bisecting on only keyframe packets needs to read 
> framesize * goplength * log(all frames) 
> Bisecting on any frame and only at the end searching for the next keyframe 
> needs  
> framesize * (log(all frames) + goplength)
> that is more than an order of magnitude less data to read even with
> small gop sizes
> 
> Thanks
> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> No human being will ever know the Truth, for even if they happen to say it
> by chance, they would not even known they had done so. -- Xenophanes
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] docs/formats: fix max_interleave_delta default

2019-09-02 Thread Marton Balint



On Sat, 31 Aug 2019, Gyan wrote:




On 31-08-2019 09:55 PM, Marton Balint wrote:



On Tue, 27 Aug 2019, Marton Balint wrote:


Signed-off-by: Marton Balint 
---
doc/formats.texi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/formats.texi b/doc/formats.texi
index 729c77b01d..d689fbadfa 100644
--- a/doc/formats.texi
+++ b/doc/formats.texi
@@ -139,7 +139,7 @@ Consider things that a sane encoder should not do 
as an error.


@item max_interleave_delta @var{integer} (@emph{output})
Set maximum buffering duration for interleaving. The duration is
-expressed in microseconds, and defaults to 100 (1 second).
+expressed in microseconds, and defaults to 1000 (10 seconds).

To ensure all the streams are interleaved correctly, libavformat will
wait until it has at least one packet for each stream before actually


Ping. Seems trivial, but an extra set of eyes would be appreciated to 
make sure.


LGTM.


Thanks, applied.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] Blocking vs non-blocking modes in protocols

2019-09-02 Thread Nicolas George
So, let us survey the state of blocking and non-blocking mode at this
date in FFmpeg.

First, why and how.

This is a question of how the program is designed. There are two big
classes of design: output-driven and input-driven. An output-driven
design decides it wants to produce some output and reads as much as
input to do it, waiting for it if necessary. An input-driven design
takes input as it comes, updates its internal state or buffers it, and
produces output as it can. There are obviously intermediate designs.

Output-driven design is easier because state can be kept in local
variables, including the instruction pointer. In input-driven design, if
the amount if input available does not allow to perform a full step of
processing, it must be fragmented or delayed somehow.

On the other hand, as soon as a program has several live inputs, input
that can receive data at any time and require immediate attention,
input-driven is the only solution. If you are old enough, you may
remember the time when web browsers would completely freeze when the DNS
was lagging, because the DNS was handled in an output-driven way,
without letting the browser react even to its GUI input.

Historically, Unix favors an output-driven design. FFmpeg closely
imitates Unix's design. When it became obvious that was not sustainable,
Unix first cut the problem like the Gordian knot: signals that bypass
the normal code paths and cause immediate action: ^C is how you provide
user "input" to a program that is blocked reading from its data input.

Since that is not sufficient for more modern applications, they
introduced non-blocking mode. In this mode, inputs do not wait for data,
they return immediately a special code that means "no data available
immediately". Programs need to be ready for that code and try other
inputs immediately and this one later.

This is not enough: trying the input later is bad, because it requires a
guess at how much later means. If later is long, the program is
unresponsive. If later is short, the program will wake often for
nothing. This last point is especially crucial for embedded application,
where unnecessary wake-ups can prevent the hardware from going into deep
sleep, causing a huge drain on the battery. (FFmpeg should be usable for
embedded applications.) To solve this issue, Unix introduced the
select() and then poll() functions, that block until one of the
specified inputs is ready.

With non-blocking mode and poll(), the normal structure of a program
with several inputs becomes a single loop, blocking waiting for any
input in a single poll() call, and then processing the ones that are
ready before starting again. This is called an event loop.

A few extra notes before starting with FFmpeg itself. I have only spoken
about inputs yet. Outputs are easier: just send the data. And take care
of flow control, which is my next point.

Flow control means that the program can stop an input from receiving
data. It may or may not be possible, depending on the input: TCP has
flow control, broadcast television does not. Plain files need flow
control, or they will flood your input.

There is another solution to handle several inputs in a program:
threads. They promise to make everything about handling several inputs
simpler: just have one thread per input. But the reality is not so
bright. If you need to stop a read operation from the network because
the user canceled it from the GUI, you need a way of controlling a
thread that is blocked in a system call. For this very simple and common
case, you can use pthread_cancel(), but we have seen how even a simple
function like that can cause no end of portability problems. For more
unusual cases, you will need to implement some kind of message passing
with the thread, and since message passing is not integrated with
blocking system calls, you will also need to implement an event loop in
the thread. An event loop in each thread.

Yet, threads can be a life-saving solution for a particular issue: they
allow to take an output-driven piece of code and run it as input-driven:
just leave the thread running when the code is blocked on an input, and
wake it when the input is received. Note that the ability of threads to
run concurrently is not necessary for this to work, only the ability to
switch context and back. But nowadays, threads are probably more tested
and portable than contexts.


Now, the state of non-blocking in current FFmpeg code. Most input APIs
of FFmpeg are output-driven: av_read_frame() will wait until input is
received. (For comparison, filters, codecs and bitstream filters are now
all input-driven.) Blocking mode is the default, and it works. On the
other hand, non-blocking often does not work.

There will be a lot of cases:

- Simple protocols, i.e. protocols that interact directly with a network
  API or a library, mostly work in both non-blocking mode, and can be
  integrated in a poll()/select() call using ffurl_get_file_handle(),
  internally but not 

Re: [FFmpeg-devel] [PATCH 2/6] avcodec/ralf: fix undefined shift in extend_code()

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 01:28:37AM +0200, Michael Niedermayer wrote:
> Fixes: left shift of negative value -3
> Fixes: 
> 16147/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RALF_fuzzer-5658392722407424
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ralf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

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

What does censorship reveal? It reveals fear. -- Julian Assange


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/6] avcodec/ralf: fix undefined shift

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 01:28:36AM +0200, Michael Niedermayer wrote:
> Fixes: left shift of negative value -2
> Fixes: 
> 16145/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RALF_fuzzer-5146671058518016
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ralf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply

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

Democracy is the form of government in which you can choose your dictator


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 4/6] avcodec/pngdec: Check amount decoded

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 11:04:20AM +0200, Paul B Mahol wrote:
> On Sun, Aug 18, 2019 at 10:25 AM Michael Niedermayer 
> wrote:
> 
> > On Sun, Aug 18, 2019 at 09:21:25AM +0200, Paul B Mahol wrote:
> > > NAK
> >
> > What problem do you see in this patch ?
> >
> > What change do you suggest ?
> > or what alternative fix for the issue do you suggest ?
> >
> > a DOS issue in png will have to be fixed, otherwise major
> > users would have to use different libraries for *png and
> > disable it in their libavcodec.
> >
> 
> What other png libraries do this thing?

which libraries do you want me to check ?
libpng seems to support incremental decoding of images so that pixels
"sparkle in" as they are decoded. I dont think it rejects based on a
user parameter.
such a sparkle in feature doesnt exist in libavcodecs API in this
form

Iam not sure how this information above helps us with this patch

We can reject every image that has any pixel missing, this would
break decoding of real files probably which are truncated

We can reject no image based on missing pixels, this would make
the decoder more vulnerable to DOS attacks. 

We can honor the user parameter intended for this purpose and
reject images missing most pixels, this is what the patch does

We can hardcode some arbitrary threshold of how much can be
missing before rejection

We could do something completely different, but i need to know what
exactly is preferred

What does the community prefer ?

Thanks

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

Never trust a computer, one day, it may think you are the virus. -- Compn


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/v4l2_m2m: don't close the file descriptor we don't own

2019-09-02 Thread Pavel Koshevoy
On Mon, Sep 2, 2019 at 10:40 AM Aman Gupta  wrote:
>
>
>
> On Mon, Sep 2, 2019 at 12:27 AM Pavel Koshevoy  wrote:
>>
>> ff_v4l2_m2m_create_context initialized V4L2m2mContext.fd to 0
>> which is a valid file descriptor value. Next ff_v4l2_m2m_codec_init
>> failed and v4l2_m2m_destroy_context closed file descriptor 0 even
>> though it didn't belong to V4L2m2mContext.
>> ---
>>  libavcodec/v4l2_m2m.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
>> index 427e165f58..ac583c811f 100644
>> --- a/libavcodec/v4l2_m2m.c
>> +++ b/libavcodec/v4l2_m2m.c
>> @@ -401,6 +401,7 @@ int ff_v4l2_m2m_create_context(AVCodecContext *avctx, 
>> V4L2m2mContext **s)
>>  priv->context->capture.num_buffers = priv->num_capture_buffers;
>>  priv->context->output.num_buffers  = priv->num_output_buffers;
>>  priv->context->self_ref = priv->context_ref;
>> +priv->context->fd = -1;
>
>
>
> LGTM. I ran into the same problem last week and have a similar change in my 
> tree.


Thanks, patch applied, pushed.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2] configure: Update libmysofa check with a new symbol.

2019-09-02 Thread Paul B Mahol
On 9/2/19, Andrey Semashev  wrote:
> Ping? I would like this to make it into 4.2 as well.
>

Applied to master.

> On Wed, Aug 28, 2019 at 11:16 PM Andrey Semashev
>  wrote:
>>
>> The current code in libavfilter/af_sofalizer.c requires
>> mysofa_neighborhood_init_withstepdefine function, which only appeared
>> in libmysofa 0.7. Use this function in configure script to bail out
>> early if a too old libmysofa is found in the system instead of failing
>> at compile time.
>> ---
>>  configure | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 51dc77c780..0d06ea6a02 100755
>> --- a/configure
>> +++ b/configure
>> @@ -6237,8 +6237,8 @@ enabled libmfx&& { check_pkg_config
>> libmfx libmfx "mfx/mfxvideo.h" M
>> { require libmfx "mfx/mfxvideo.h" MFXInit
>> "-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config";
>> } }
>>  enabled libmodplug&& require_pkg_config libmodplug libmodplug
>> libmodplug/modplug.h ModPlug_Load
>>  enabled libmp3lame&& require "libmp3lame >= 3.98.3" lame/lame.h
>> lame_set_VBR_quality -lmp3lame $libm_extralibs
>> -enabled libmysofa && { check_pkg_config libmysofa libmysofa
>> mysofa.h mysofa_load ||
>> -   require libmysofa mysofa.h mysofa_load
>> -lmysofa $zlib_extralibs; }
>> +enabled libmysofa && { check_pkg_config libmysofa libmysofa
>> mysofa.h mysofa_neighborhood_init_withstepdefine ||
>> +   require libmysofa mysofa.h
>> mysofa_neighborhood_init_withstepdefine -lmysofa $zlib_extralibs; }
>>  enabled libnpp&& { check_lib libnpp npp.h nppGetLibVersion
>> -lnppig -lnppicc -lnppc -lnppidei ||
>> check_lib libnpp npp.h nppGetLibVersion
>> -lnppi -lnppc -lnppidei ||
>> die "ERROR: libnpp not found"; }
>> --
>> 2.20.1
>>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2] configure: Update libmysofa check with a new symbol.

2019-09-02 Thread Andrey Semashev
Ping? I would like this to make it into 4.2 as well.

On Wed, Aug 28, 2019 at 11:16 PM Andrey Semashev
 wrote:
>
> The current code in libavfilter/af_sofalizer.c requires
> mysofa_neighborhood_init_withstepdefine function, which only appeared
> in libmysofa 0.7. Use this function in configure script to bail out
> early if a too old libmysofa is found in the system instead of failing
> at compile time.
> ---
>  configure | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 51dc77c780..0d06ea6a02 100755
> --- a/configure
> +++ b/configure
> @@ -6237,8 +6237,8 @@ enabled libmfx&& { check_pkg_config libmfx 
> libmfx "mfx/mfxvideo.h" M
> { require libmfx "mfx/mfxvideo.h" MFXInit 
> "-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
>  enabled libmodplug&& require_pkg_config libmodplug libmodplug 
> libmodplug/modplug.h ModPlug_Load
>  enabled libmp3lame&& require "libmp3lame >= 3.98.3" lame/lame.h 
> lame_set_VBR_quality -lmp3lame $libm_extralibs
> -enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h 
> mysofa_load ||
> -   require libmysofa mysofa.h mysofa_load 
> -lmysofa $zlib_extralibs; }
> +enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h 
> mysofa_neighborhood_init_withstepdefine ||
> +   require libmysofa mysofa.h 
> mysofa_neighborhood_init_withstepdefine -lmysofa $zlib_extralibs; }
>  enabled libnpp&& { check_lib libnpp npp.h nppGetLibVersion 
> -lnppig -lnppicc -lnppc -lnppidei ||
> check_lib libnpp npp.h nppGetLibVersion 
> -lnppi -lnppc -lnppidei ||
> die "ERROR: libnpp not found"; }
> --
> 2.20.1
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/pngdec: Optimize has_trns code

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 10:29:02AM +0200, Michael Niedermayer wrote:
> add inner loop specialisations for 2 bpp and 4 bpp
> These are all cases for which i found testsamples.
> 
> 30M cycles -> 5M cycles
> 
> Testcase: fate-rgbapng-4816
> Testcase: 
> 16097/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-5664690889293824
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/pngdec.c | 37 +
>  1 file changed, 29 insertions(+), 8 deletions(-)

will apply

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

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


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 5/6] avcodec/apedec: Fix integer overflow in filter_fast_3320()

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 01:28:40AM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: -1094994793 * 2 cannot be represented in type 
> 'int'
> Fixes: 
> 16139/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5663911036059648
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/apedec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

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

There will always be a question for which you do not know the correct answer.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 6/6] vcodec/apedec: Fix integer overflow in filter_3800()

2019-09-02 Thread Michael Niedermayer
On Sun, Aug 18, 2019 at 01:28:41AM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 2021654528 + 2032575680 cannot be represented 
> in type 'int'
> Fixes: 
> 16270/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5732438816325632
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/apedec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

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

What does censorship reveal? It reveals fear. -- Julian Assange


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/v4l2_m2m: don't close the file descriptor we don't own

2019-09-02 Thread Aman Gupta
On Mon, Sep 2, 2019 at 12:27 AM Pavel Koshevoy  wrote:

> ff_v4l2_m2m_create_context initialized V4L2m2mContext.fd to 0
> which is a valid file descriptor value. Next ff_v4l2_m2m_codec_init
> failed and v4l2_m2m_destroy_context closed file descriptor 0 even
> though it didn't belong to V4L2m2mContext.
> ---
>  libavcodec/v4l2_m2m.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
> index 427e165f58..ac583c811f 100644
> --- a/libavcodec/v4l2_m2m.c
> +++ b/libavcodec/v4l2_m2m.c
> @@ -401,6 +401,7 @@ int ff_v4l2_m2m_create_context(AVCodecContext *avctx,
> V4L2m2mContext **s)
>  priv->context->capture.num_buffers = priv->num_capture_buffers;
>  priv->context->output.num_buffers  = priv->num_output_buffers;
>  priv->context->self_ref = priv->context_ref;
> +priv->context->fd = -1;



LGTM. I ran into the same problem last week and have a similar change in my
tree.



>
>  return 0;
>  }
> --
> 2.16.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [REFUND-REQUEST] Packaging and Shipping cost AMD GPU

2019-09-02 Thread Timo Rothenpieler
I have sent one of my spare AMD GPUs to Rodger Combs for work on AMF and 
AMF/Vulkan integration.


Since there is personal information on the receipts, I won't post them 
here, but can send them to the responsible person on request easily.


Packaging:
PackSet M: 1.99€
Bubble-Wrap "Protection Kit": 4.99€

Shipping:
Insured shipping via DHL (DE->US): 37.99€

Total cost: 44.97€
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/1] avcodec/h264: Fix poc_lsb in open gop context

2019-09-02 Thread Kieran Kunhya
On Mon, 2 Sep 2019 at 09:01, Gaullier Nicolas 
wrote:

> >Envoyé : mardi 23 juillet 2019 14:09
> >When no IDR nor mmco_reset is found, prev_poc_lsb is undefined and shall
> not be assumed to be zero
> >---
> > libavcodec/h264_parse.c | 2 ++
> > libavcodec/h264dec.c| 2 +-
> > 2 files changed, 3 insertions(+), 1 deletion(-)
> I have not received any feeback, do you think this patch could be applied ?
> Thank you,
> Nicolas
>

Patch seems good.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] FFmpeg 4.2.1

2019-09-02 Thread Michael Niedermayer
Hi all

Its almost a month since 4.2, so its time to make 4.2.1, and i intend to
do that in the next days.
If you want some bugfix in it, dont forget to backport it. 

Thanks

-- 
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
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 4/4] avcodec/bgmc: Check input space in ff_bgmc_decode_init()

2019-09-02 Thread Michael Niedermayer
On Mon, Sep 02, 2019 at 09:47:04AM +0200, Thilo Borgmann wrote:
> Am 01.09.19 um 23:10 schrieb Michael Niedermayer:
> > Fixes: Infinite loop
> > Fixes: 
> > 16608/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5636229827133440
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/alsdec.c | 4 +++-
> >  libavcodec/bgmc.c   | 7 ++-
> >  libavcodec/bgmc.h   | 2 +-
> >  3 files changed, 10 insertions(+), 3 deletions(-)
> 
> LGTM

will apply

thx

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

I have often repented speaking, but never of holding my tongue.
-- Xenocrates


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] avcodec/vp3: Check for end of input in 2 places of vp4_unpack_macroblocks()

2019-09-02 Thread Michael Niedermayer
On Mon, Sep 02, 2019 at 06:33:43PM +1000, Peter Ross wrote:
> On Sun, Sep 01, 2019 at 11:10:25PM +0200, Michael Niedermayer wrote:
> > Fixes: Timeout (82sec -> 1sec)
> > Fixes: 
> > 16411/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-5166958151991296
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/vp3.c | 4 
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> > index 28ed0461c7..a2bd2ef07d 100644
> > --- a/libavcodec/vp3.c
> > +++ b/libavcodec/vp3.c
> > @@ -710,6 +710,8 @@ static int vp4_unpack_macroblocks(Vp3DecodeContext *s, 
> > GetBitContext *gb)
> >  has_partial = 0;
> >  bit = get_bits1(gb);
> >  for (i = 0; i < s->yuv_macroblock_count; i += current_run) {
> > +if (get_bits_left(gb) <= 0)
> > +return AVERROR_INVALIDDATA;
> >  current_run = vp4_get_mb_count(s, gb);
> >  if (current_run > s->yuv_macroblock_count - i)
> >  return -1;
> > @@ -719,6 +721,8 @@ static int vp4_unpack_macroblocks(Vp3DecodeContext *s, 
> > GetBitContext *gb)
> >  }
> >  
> >  if (has_partial) {
> > +if (get_bits_left(gb) <= 0)
> > +return AVERROR_INVALIDDATA;
> >  bit  = get_bits1(gb);
> >  current_run = vp4_get_mb_count(s, gb);
> >  for (i = 0; i < s->yuv_macroblock_count; i++) {
> > -- 
> > 2.23.0
> 
> approve.

will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

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


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: switch to avformat_seek_file for stream_loop

2019-09-02 Thread Michael Niedermayer
On Sat, Aug 31, 2019 at 08:28:51PM +0530, Gyan wrote:
> A user observed that stream_loop didn't work with very short FLV files.
> seek_to_start in ffmpeg.c calls av_seek_frame with no flags; FLV seek only
> works with RTMP protocol so lavf falls back on seek_frame_generic which
> searches forward, skipping a GOP. With files with two index entries in
> stream, the file doesn't loop at all.
> 
> I switched to avformat_seek_file which will set the BACKWARDS flag when
> seeking to start of file. stream_loop works and no frames are dropped.
> 
> FATE passes.
> 
> Gyan

>  ffmpeg.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> c79dc6d27a9c8c1bd0cffa2d251b2aa7caf23bf3  
> 0001-ffmpeg-switch-to-avformat_seek_file-for-stream_loop.patch
> From 4af64f612c65378f0a220284ca99ad033ece8cd3 Mon Sep 17 00:00:00 2001
> From: Gyan Doshi 
> Date: Sat, 31 Aug 2019 19:45:58 +0530
> Subject: [PATCH] ffmpeg: switch to avformat_seek_file for stream_loop
> 
> Fixes stream_loop with very short files where seeking is generic index
> search
> ---
>  fftools/ffmpeg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

probably ok

it also might make sense to add the testcase to fate as you mentioned "short"

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] Blocking vs non-blocking modes in protocols

2019-09-02 Thread Nicolas George
Andriy Gelman (12019-09-01):
> Below are my notes on blocking and non-blocking modes in protocols. Proposed
> changes that I'd like to make are at the end. 
> 
> Thanks, 
> Andriy
> 
> 
> ---General notes--
> -blocking mode-
> - transfer_function deals with polling and timeout
> - block inside transfer_function for max rw_timeout. 
> - if rw_timeout expires the protocol designers have two options:  
>(1) transfer_funciton returns AVERROR(ETIMEDOUT).  This will cause the
>encoding/decoding to exit with timeout error.
>(2) transfer_function returns AVERROR(EINTR).  Immediately retry the
>transfer_function after checking interrupt callback.
> 
> -non-blocking mode-
> - retry_transfer_wrapper deals with retries
> - if read/writes are not available transfer_function should immediately
>   return with AVERROR(EAGAIN)

> - retry transfer_function with 5 x fast_retry (no sleep). Then, retry with
>   1ms sleep.  
> - If rw_timeout expires, exit encoding/decoding with AVERROR(EIO) 
> (Probably
>   should be changed to AVERROR(ETIMEDOUT) to be consistent with blocking
>   mdoe.

This looks like one of the reasons the non-blocking mode does not work.

> But overall, the two modes seem similar to me: 
> - "Blocking" - blocks at the transfer_function
> - "Non-blocking" - blocks in retry_transfer_function

The expected behaviour is: non-blocking does not block.

> Potential advantage of non-blocking over blocking mode
> I'm trying to figure what would be the advantage of non-blocking over blocking
> modes. The only reason I can think of: non-blocking mode gives more control to
> the user rather than protocol designer. In non-blocking mode the user can 
> force
> an exit after rw_timeout expires. On the other hand, in blocking mode, the
> protocol designer can force a retry by returing AVERROR(EINTR) after 
> rw_timeout
> expires instead of exiting the code (i.e. after AVERROR(ETIMEDOUT) is 
> returned).
> 
> Any other reason someone would prefer non-blocking over blocking modes? 

I am not sure I read you correctly, I think you are saying that
blocking/non-blocking mode is a design decision for protocol
implementors. The difference between blocking and non-blocking mode is
not meant for the internal design of FFmpeg but for applications.

An application that has several live inputs (network, device, GUI (a GUI
is one big live input)) cannot be blocked reading on one of them,
because it needs to react to the others immediately. The application
design is then to have all live inputs in non-blocking mode, and walk
over them, like this:

while (1) {
wait_for_any_input();
for (input)
process_input_non_blocking(input);
}

(If the application is CPU-bound rather than input-bound,
wait_for_any_input() will need to be rather
perform_a_slice_of_computation().)

(Some applications, including FFmpeg, will have wait_a_small_time()
instead of wait_for_any_input(), but that is terrible design and a waste
of energy that contributes to global warming.)

> Proposed changes
> (1) At the moment, non-blocking mode immediately exits after 
> AVERROR(EAGAIN)
> is returned without doing any retries. I'm quite sure there is a bug on
> avio.c:379. It should be changed to: if (!(h->flags & AVIO_FLAG_NONBLOCK))

In non-blocking mode, if no data is available, the flow must return to
the application immediately with AVERROR(EAGAIN).

> (3) Update avio.h/url.h to clarify difference between AVERROR(ETIMEDOUT) 
> and
> AVERROR(EINTR) in blocking mode.

The semantic of EINTR is "Unix sucks, signals are terribly badly
designed". It should never be used in our code except to deal with that
bad design.

> (4) Add non-blocking option to the cli. Something like -avioflags
> nonblocking. But add a note that this may not be supported by a specific
> protocol 

Working in blocking or non-blocking mode means a completely different
design of the program, making it an option does not make sense.

> (5) If rw_timeout expires in non-blocking mode, return AVERROR(ETIMEDOUT)
> instead of AVERROR(EIO) to be consistent with blocking mode.

In non-blocking mode, there can be no timeout because there can be no
time. If there is, it is a bug.

Note: Currently, non-blocking mode works for a few cases but is
completely broken in most of FFmpeg's code base. In a subsequent mail I
will try to summarise the state of affairs and how it could be enhanced.

Regards,

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] Allow 'concat' filter to support inputs with different frame rates

2019-09-02 Thread Nicolas George
Calvin Walton (12019-08-30):
> Right now, the concat filter does not set the frame_rate value on any of
> the out links. As a result, the default ffmpeg behaviour kicks in - to
> copy the framerate from the first input to the outputs.
> 
> If a later input is higher framerate, this results in dropped frames; if
> a later input is lower framerate it might cause judder.
> 
> This patch checks if all of the video inputs have the same framerate, and
> if not it sets the out link to use '1/0' as the frame rate, the value
> meaning "unknown/vfr".
> 
> A test is added to verify the VFR behaviour. The existing test for CFR
> behaviour passes unchanged.
> ---
> Updated version of
> https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2017-March/208251.html
> 
> Fixes the missing concat-vfr filtergraph for tests, and adds a newline
> to the end of the log message.
> 
>  libavfilter/avf_concat.c |  15 ++-
>  tests/fate/filter-video.mak  |   4 +-
>  tests/filtergraphs/concat-vfr|   8 ++
>  tests/ref/fate/filter-concat-vfr | 224 +++
>  4 files changed, 249 insertions(+), 2 deletions(-)
>  create mode 100644 tests/filtergraphs/concat-vfr
>  create mode 100644 tests/ref/fate/filter-concat-vfr

Thanks for the patch, it looks ok to me and I intend to push it in a few
days to let somebody comment. Please do not hesitate to remind me if I
forget.

Regards,

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] avcodec/h264: fix draw_horiz_band with slice threads

2019-09-02 Thread James Darnley
From: Kieran Kunhya 

---
 libavcodec/h264_slice.c | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 5ceee107a0..fe2aa01ceb 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -2527,18 +2527,33 @@ static void predict_field_decoding_flag(const 
H264Context *h, H264SliceContext *
 /**
  * Draw edges and report progress for the last MB row.
  */
-static void decode_finish_row(const H264Context *h, H264SliceContext *sl)
+static void decode_finish_row(const H264Context *h, H264SliceContext *sl, int 
slice_end)
 {
 int top= 16 * (sl->mb_y  >> FIELD_PICTURE(h));
 int pic_height = 16 *  h->mb_height >> FIELD_PICTURE(h);
 int height =  16  << FRAME_MBAFF(h);
 int deblock_border = (16 + 4) << FRAME_MBAFF(h);
 
-if (sl->deblocking_filter) {
+/* Slice-threaded draw_horiz_band not useful in this situation */
+if (sl->deblocking_filter == 1) {
 if ((top + height) >= pic_height)
 height += deblock_border;
 top -= deblock_border;
 }
+else if (sl->deblocking_filter == 2) {
+int first_mb_y = sl->first_mb_addr / h->mb_width;
+
+/* Draw the whole slice if it's possible:
+ * - If the beginning of the slice is at the start of a row
+ * - If we are at the end of the slice
+ * Previous slice is guaranteed not be included. */
+if (!(sl->first_mb_addr % h->mb_width)) {
+if (slice_end) {
+top = 16 * (first_mb_y >> FIELD_PICTURE(h));
+height = (16 << FRAME_MBAFF(h)) * ((sl->mb_y+1) - first_mb_y);
+}
+}
+}
 
 if (top >= pic_height || (top + height) < 0)
 return;
@@ -2549,7 +2564,8 @@ static void decode_finish_row(const H264Context *h, 
H264SliceContext *sl)
 top= 0;
 }
 
-ff_h264_draw_horiz_band(h, sl, top, height);
+if (slice_end)
+ff_h264_draw_horiz_band(h, sl, top, height);
 
 if (h->droppable || sl->h264->slice_ctx[0].er.error_occurred)
 return;
@@ -2622,7 +2638,7 @@ static int decode_slice(struct AVCodecContext *avctx, 
void *arg)
 
 for (;;) {
 // START_TIMER
-int ret, eos;
+int ret, eos, slice_end;
 if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {
 av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at 
%d\n",
sl->next_slice_idx);
@@ -2669,10 +2685,11 @@ static int decode_slice(struct AVCodecContext *avctx, 
void *arg)
 return AVERROR_INVALIDDATA;
 }
 
+slice_end = eos || sl->mb_y >= h->mb_height;
 if (++sl->mb_x >= h->mb_width) {
 loop_filter(h, sl, lf_x_start, sl->mb_x);
 sl->mb_x = lf_x_start = 0;
-decode_finish_row(h, sl);
+decode_finish_row(h, sl, slice_end);
 ++sl->mb_y;
 if (FIELD_OR_MBAFF_PICTURE(h)) {
 ++sl->mb_y;
@@ -2729,7 +2746,7 @@ static int decode_slice(struct AVCodecContext *avctx, 
void *arg)
 if (++sl->mb_x >= h->mb_width) {
 loop_filter(h, sl, lf_x_start, sl->mb_x);
 sl->mb_x = lf_x_start = 0;
-decode_finish_row(h, sl);
+decode_finish_row(h, sl, 0);
 ++sl->mb_y;
 if (FIELD_OR_MBAFF_PICTURE(h)) {
 ++sl->mb_y;
-- 
2.22.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/v4l2_m2m: don't close the file descriptor we don't own

2019-09-02 Thread Nicolas George
Pavel Koshevoy (12019-09-02):
> ff_v4l2_m2m_create_context initialized V4L2m2mContext.fd to 0
> which is a valid file descriptor value. Next ff_v4l2_m2m_codec_init
> failed and v4l2_m2m_destroy_context closed file descriptor 0 even
> though it didn't belong to V4L2m2mContext.
> ---
>  libavcodec/v4l2_m2m.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
> index 427e165f58..ac583c811f 100644
> --- a/libavcodec/v4l2_m2m.c
> +++ b/libavcodec/v4l2_m2m.c
> @@ -401,6 +401,7 @@ int ff_v4l2_m2m_create_context(AVCodecContext *avctx, 
> V4L2m2mContext **s)
>  priv->context->capture.num_buffers = priv->num_capture_buffers;
>  priv->context->output.num_buffers  = priv->num_output_buffers;
>  priv->context->self_ref = priv->context_ref;
> +priv->context->fd = -1;
>  
>  return 0;
>  }

This change looks ok to me, but I do not maintain that file.

Regards,

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avcodec/h264: enable draw_horiz_band

2019-09-02 Thread James Darnley
---
 libavcodec/h264dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8d1bd16a8e..b9f304936c 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1056,7 +1056,7 @@ AVCodec ff_h264_decoder = {
 .init  = h264_decode_init,
 .close = h264_decode_end,
 .decode= h264_decode_frame,
-.capabilities  = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ 
AV_CODEC_CAP_DR1 |
+.capabilities  = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
  AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
  AV_CODEC_CAP_FRAME_THREADS,
 .hw_configs= (const AVCodecHWConfigInternal*[]) {
-- 
2.22.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 0/2] WIP: h264, slice threads, draw_horiz_band

2019-09-02 Thread James Darnley
Trying a combination of sliced threads, chunk decoding, and draw_horiz_band we
found that it didn't work with the current master code.  Modifying the
api-h264-slice fate test showed obvious errors with grey and green blocks and
more subtle ones that looked like misplaced macroblocks.

Kieran identified the cause and coded this quick fix.  He said that essentially
the code would give a region to draw_horiz_band which could include the previous
slice even if it hadn't been finished yet.

This corrects that problem and lets us decode exactly.  However it does cause
errors decoding B-frames in chunked mode.

Needs more work.

James Darnley (1):
  avcodec/h264: enable draw_horiz_band

Kieran Kunhya (1):
  avcodec/h264: fix draw_horiz_band with slice threads

 libavcodec/h264_slice.c | 29 +++--
 libavcodec/h264dec.c|  2 +-
 2 files changed, 24 insertions(+), 7 deletions(-)

-- 
2.22.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avformat: Introduced `AVInputFormat.read_timestamp2` to fix keyframe seeking for formats that rely on `read_timestamp` for seeking

2019-09-02 Thread Michael Niedermayer
On Sat, Aug 31, 2019 at 03:10:38AM -0700, fumoboy...@me.com wrote:
> From: fumoboy007 
> 
> If the user omits `AVSEEK_FLAG_ANY`, then the result of the seek should be a 
> keyframe. `ff_gen_search` did not respect that contract because it had no 
> good way to determine whether a timestamp returned by `read_timestamp` was 
> for a keyframe packet.
> 
> Therefore, we introduce `read_timestamp2`, which adds a new parameter named 
> `prefer_keyframe`. This new parameter tells the input format whether to skip 
> non-keyframe packets. The parameter is named `prefer_keyframe` instead of 
> something like `keyframe_only` because some formats do not distinguish 
> between keyframe and non-keyframe packets.
> 
> This commit adds the new function and deprecates the old function. Subsequent 
> commits will migrate input formats to the new function.
> 
> Signed-off-by: fumoboy007 
> ---
>  libavformat/avformat.h |  9 +++
>  libavformat/internal.h |  6 +++--
>  libavformat/nutdec.c   |  6 ++---
>  libavformat/utils.c| 56 +-
>  4 files changed, 60 insertions(+), 17 deletions(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 6eb329f13f..1db548663c 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -741,6 +741,7 @@ typedef struct AVInputFormat {
>   * Get the next timestamp in stream[stream_index].time_base units.
>   * @return the timestamp or AV_NOPTS_VALUE if an error occurred
>   */
> +attribute_deprecated
>  int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
>int64_t *pos, int64_t pos_limit);
>  
> @@ -781,6 +782,14 @@ typedef struct AVInputFormat {
>   * @see avdevice_capabilities_free() for more details.
>   */
>  int (*free_device_capabilities)(struct AVFormatContext *s, struct 
> AVDeviceCapabilitiesQuery *caps);
> +
> +/**
> + * Get the next timestamp in stream[stream_index].time_base units.
> + * @param prefer_keyframe Whether to skip over non-keyframe packets (if 
> possible).
> + * @return the timestamp or AV_NOPTS_VALUE if an error occurred
> + */
> +int64_t (*read_timestamp2)(struct AVFormatContext *s, int stream_index,
> +   int64_t *pos, int64_t pos_limit, int 
> prefer_keyframe);


>  } AVInputFormat;
>  /**
>   * @}
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index d6a039c497..a45c538b21 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -443,7 +443,8 @@ int ff_seek_frame_binary(AVFormatContext *s, int 
> stream_index,
>  void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t 
> timestamp);
>  
>  int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, 
> int64_t *pos,
> -int64_t (*read_timestamp)(struct AVFormatContext *, int 
> , int64_t *, int64_t ));
> +int64_t (*read_timestamp)(struct AVFormatContext *, int, 
> int64_t *, int64_t),
> +int64_t (*read_timestamp2)(struct AVFormatContext *, 
> int, int64_t *, int64_t, int));
>  
>  /**
>   * Perform a binary search using read_timestamp().
> @@ -456,7 +457,8 @@ int64_t ff_gen_search(AVFormatContext *s, int 
> stream_index,
>int64_t pos_max, int64_t pos_limit,
>int64_t ts_min, int64_t ts_max,
>int flags, int64_t *ts_ret,
> -  int64_t (*read_timestamp)(struct AVFormatContext *, 
> int , int64_t *, int64_t ));
> +  int64_t (*read_timestamp)(struct AVFormatContext *, 
> int, int64_t *, int64_t),
> +  int64_t (*read_timestamp2)(struct AVFormatContext *, 
> int, int64_t *, int64_t, int));
>  
>  /**
>   * Set the time base and wrapping info for a given stream. This will be used
> diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
> index 979cb9a031..f28fb2297e 100644
> --- a/libavformat/nutdec.c
> +++ b/libavformat/nutdec.c
> @@ -653,7 +653,7 @@ static int64_t find_duration(NUTContext *nut, int64_t 
> filesize)
>  AVFormatContext *s = nut->avf;
>  int64_t duration = 0;
>  
> -ff_find_last_ts(s, -1, , NULL, nut_read_timestamp);
> +ff_find_last_ts(s, -1, , NULL, nut_read_timestamp, NULL);
>  
>  if(duration > 0)
>  s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
> @@ -1251,7 +1251,7 @@ static int read_seek(AVFormatContext *s, int 
> stream_index,
>  pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
>  next_node[1]->pos, next_node[1]->pos,
>  next_node[0]->ts, next_node[1]->ts,
> -AVSEEK_FLAG_BACKWARD, , nut_read_timestamp);
> +AVSEEK_FLAG_BACKWARD, , nut_read_timestamp, 
> NULL);
>  if (pos < 0)
>  return pos;
>  
> @@ -1263,7 +1263,7 @@ static int read_seek(AVFormatContext *s, int 
> 

Re: [FFmpeg-devel] [PATCH v1 1/2] avcodec/videotoolboxenc: add H264 Extended profile and level

2019-09-02 Thread Limin Wang
On Tue, Aug 27, 2019 at 10:56:42AM -0400, Richard Kern wrote:

> I’ll look at it this weekend. 
ping

> 
> > On Aug 27, 2019, at 10:40 AM, Limin Wang  wrote:
> > 
> > 
> > ping the patchset.
> > 
> >> On Tue, Aug 20, 2019 at 07:04:29PM +0800, lance.lmw...@gmail.com wrote:
> >> From: Limin Wang 
> >> 
> >> Signed-off-by: Limin Wang 
> >> ---
> >> libavcodec/videotoolboxenc.c | 14 ++
> >> 1 file changed, 14 insertions(+)
> >> 
> >> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> >> index d76bb7f646..b16b056f6c 100644
> >> --- a/libavcodec/videotoolboxenc.c
> >> +++ b/libavcodec/videotoolboxenc.c
> >> @@ -80,6 +80,8 @@ static struct{
> >> CFStringRef kVTProfileLevel_H264_High_5_1;
> >> CFStringRef kVTProfileLevel_H264_High_5_2;
> >> CFStringRef kVTProfileLevel_H264_High_AutoLevel;
> >> +CFStringRef kVTProfileLevel_H264_Extended_5_0;
> >> +CFStringRef kVTProfileLevel_H264_Extended_AutoLevel;
> >> 
> >> CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
> >> CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
> >> @@ -137,6 +139,8 @@ static void loadVTEncSymbols(){
> >> GET_SYM(kVTProfileLevel_H264_High_5_1,   "H264_High_5_1");
> >> GET_SYM(kVTProfileLevel_H264_High_5_2, "H264_High_5_2");
> >> GET_SYM(kVTProfileLevel_H264_High_AutoLevel, 
> >> "H264_High_AutoLevel");
> >> +GET_SYM(kVTProfileLevel_H264_Extended_5_0,   "H264_Extended_5_0");
> >> +GET_SYM(kVTProfileLevel_H264_Extended_AutoLevel, 
> >> "H264_Extended_AutoLevel");
> >> 
> >> GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel, 
> >> "HEVC_Main_AutoLevel");
> >> GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,   
> >> "HEVC_Main10_AutoLevel");
> >> @@ -154,6 +158,7 @@ typedef enum VT_H264Profile {
> >> H264_PROF_BASELINE,
> >> H264_PROF_MAIN,
> >> H264_PROF_HIGH,
> >> +H264_PROF_EXTENDED,
> >> H264_PROF_COUNT
> >> } VT_H264Profile;
> >> 
> >> @@ -704,6 +709,14 @@ static bool get_vt_h264_profile_level(AVCodecContext 
> >> *avctx,
> >>   
> >> compat_keys.kVTProfileLevel_H264_High_5_2;   break;
> >> }
> >> break;
> >> +case H264_PROF_EXTENDED:
> >> +switch (vtctx->level) {
> >> +case  0: *profile_level_val =
> >> +  
> >> compat_keys.kVTProfileLevel_H264_Extended_AutoLevel; break;
> >> +case 50: *profile_level_val =
> >> +  
> >> compat_keys.kVTProfileLevel_H264_Extended_5_0;   break;
> >> +}
> >> +break;
> >> }
> >> 
> >> if (!*profile_level_val) {
> >> @@ -2531,6 +2544,7 @@ static const AVOption h264_options[] = {
> >> { "baseline", "Baseline Profile", 0, AV_OPT_TYPE_CONST, { .i64 = 
> >> H264_PROF_BASELINE }, INT_MIN, INT_MAX, VE, "profile" },
> >> { "main", "Main Profile", 0, AV_OPT_TYPE_CONST, { .i64 = 
> >> H264_PROF_MAIN }, INT_MIN, INT_MAX, VE, "profile" },
> >> { "high", "High Profile", 0, AV_OPT_TYPE_CONST, { .i64 = 
> >> H264_PROF_HIGH }, INT_MIN, INT_MAX, VE, "profile" },
> >> +{ "extended", "Extend Profile",   0, AV_OPT_TYPE_CONST, { .i64 = 
> >> H264_PROF_EXTENDED }, INT_MIN, INT_MAX, VE, "profile" },
> >> 
> >> { "level", "Level", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 
> >> 52, VE, "level" },
> >> { "1.3", "Level 1.3, only available with Baseline Profile", 0, 
> >> AV_OPT_TYPE_CONST, { .i64 = 13 }, INT_MIN, INT_MAX, VE, "level" },
> >> -- 
> >> 2.21.0
> >> 
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avfilter/vf_scale: split the scale_frame function from filter_frame for activate function support

2019-09-02 Thread Limin Wang

ping, although my frame thread code can't pass fate testing and can't
submit for review. The change is independent for that.

Thanks,
Limin
On Sat, Jul 27, 2019 at 08:18:16PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavfilter/vf_scale.c | 29 +
>  1 file changed, 25 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index 7aebf56..efb480d 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -400,7 +400,7 @@ static int scale_slice(AVFilterLink *link, AVFrame 
> *out_buf, AVFrame *cur_pic, s
>   out,out_stride);
>  }
>  
> -static int filter_frame(AVFilterLink *link, AVFrame *in)
> +static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out, 
> int *got_frame)
>  {
>  ScaleContext *scale = link->dst->priv;
>  AVFilterLink *outlink = link->dst->outputs[0];
> @@ -409,6 +409,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  char buf[32];
>  int in_range;
>  
> +*got_frame = 0;
>  if (in->colorspace == AVCOL_SPC_YCGCO)
>  av_log(link->dst, AV_LOG_WARNING, "Detected unsupported YCgCo 
> colorspace.\n");
>  
> @@ -437,8 +438,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  return ret;
>  }
>  
> -if (!scale->sws)
> -return ff_filter_frame(outlink, in);
> +if (!scale->sws) {
> +*got_frame = 1;
> +*frame_out = in;
> +return 0;
> +}
>  
>  scale->hsub = desc->log2_chroma_w;
>  scale->vsub = desc->log2_chroma_h;
> @@ -448,6 +452,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  av_frame_free();
>  return AVERROR(ENOMEM);
>  }
> +*frame_out = out;
>  
>  av_frame_copy_props(out, in);
>  out->width  = outlink->w;
> @@ -521,7 +526,23 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  }
>  
>  av_frame_free();
> -return ff_filter_frame(outlink, out);
> +*got_frame = 1;
> +return 0;
> +}
> +
> +static int filter_frame(AVFilterLink *link, AVFrame *in)
> +{
> +AVFilterContext *ctx = link->dst;
> +AVFilterLink *outlink = ctx->outputs[0];
> +int got_frame = 0;
> +AVFrame *out;
> +int ret;
> +
> +ret = scale_frame(link, in, , _frame);
> +if (got_frame)
> +return ff_filter_frame(outlink, out);
> +
> +return ret;
>  }
>  
>  static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
> -- 
> 2.6.4
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2] libavformat/avio: Fix for the unexpected file close which will cause fd 0 is closed

2019-09-02 Thread Limin Wang

ping, have test with the example code.

On Sat, Jul 13, 2019 at 10:22:57PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> By the code, is_connected is used to check file open or not, so after open_dir
> is done, we should not set is_connected to 1, it'll cause the function 
> ffurl_closep 
> will invoke the url_close and cause unexpected file close.
> 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/avio.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavformat/avio.c b/libavformat/avio.c
> index 663789e..8b52aa3 100644
> --- a/libavformat/avio.c
> +++ b/libavformat/avio.c
> @@ -560,7 +560,6 @@ int avio_open_dir(AVIODirContext **s, const char *url, 
> AVDictionary **options)
>  if (ret < 0)
>  goto fail;
>  
> -h->is_connected = 1;
>  ctx->url_context = h;
>  *s = ctx;
>  return 0;
> -- 
> 2.6.4
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] avfilter/vf_delogo: support expr in delogo filter

2019-09-02 Thread Limin Wang
On Wed, Aug 28, 2019 at 05:01:13PM +0200, Michael Niedermayer wrote:
> On Wed, Aug 28, 2019 at 05:39:32AM +0800, Steven Liu wrote:
> > Signed-off-by: Steven Liu 
> > ---
> >  libavfilter/vf_delogo.c | 83 
> > ++---
> >  1 file changed, 79 insertions(+), 4 deletions(-)
> 
> breaks fate

ping, the fate is broken for master

> 
> --- ./tests/ref/fate/filter-delogo2019-08-27 23:33:16.098044653 +0200
> +++ tests/data/fate/filter-delogo 2019-08-28 16:38:23.481781287 +0200
> @@ -11,104 +11,104 @@
>  0,  5,  5,1,   126720, 0x259af497
>  0,  6,  6,1,   126720, 0x5e6ff4d7
>  0,  7,  7,1,   126720, 0xcc10f4b7
> -0,  8,  8,1,   126720, 0x2811b819
> -0,  9,  9,1,   126720, 0x9b36b8d9
> -0, 10, 10,1,   126720, 0x9488b919
> -0, 11, 11,1,   126720, 0x316cb902
> -0, 12, 12,1,   126720, 0xfd2ab949
> -0, 13, 13,1,   126720, 0x7cc9bbb9
> -0, 14, 14,1,   126720, 0xdb1bbc39
> ...
> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Elect your leaders based on what they did after the last election, not
> based on what they say before an election.
> 



> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] Paid for, short term contract work.

2019-09-02 Thread Warwick New
Hey, I'm really sorry if this work isn't relevant to any of you guys.

But we're looking for a paid for, short term contractor to help us make our
web
streaming stack more stable.

We currently use Janus as a conferencing technology and are trying to
leverage
Wowza's one to many streaming potential to stream those conference rooms to
a
larger audience. To do this we're using ffmpeg as a spawned process managed
by
a node server. Which we use to forward an opus rtp endpoint created by
Janus to
a newly created Wowza entry point. We also generate our own sdp files for
describing the input ffmpeg stream and Wowza's own suggested parameters for
ffmpeg's stream output (https://tinyurl.com/y2fdppps).

This however, whilst appearing to be stable on receiving the Janus stream
seems to be pretty unstable when it comes to forwarding the stream to Wowza,
using a newly generated stream's entry point.

Stack we use:
- Janus webrtc gateway (To handle conference rooms)
- Wowza (To handle automatic scaling of streaming these conference
rooms to
  individuals)
- ffmpeg (To glue the previous two together)
- Node (To manage the entire process)
- React (As a user front end)
- Amazon AWS with terraform and packer for deployment

Our team consists mainly of junior developers with limited web development
experience.

Hopefully I'm not jumping the gun in asking you guys.

If you want more info about the job please contact us at d...@ramble.fm
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] tests: Fix bash errors in lavf_container tests.

2019-09-02 Thread Andrey Semashev

Ping?

On 2019-08-28 18:32, Andrey Semashev wrote:

Because lavf_container is sometimes called with only 2 arguments,
fate tests produce bash errors like this:

   tests/fate-run.sh: 299: test: =: unexpected operator

This commit fixes this.
---
  tests/fate-run.sh | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 2f1991da52..aec12c16a3 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -296,7 +296,7 @@ lavf_container(){
  outdir="tests/data/lavf"
  file=${outdir}/lavf.$t
  do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f 
s16le $1 -i $pcm_src "$ENC_OPTS -metadata title=lavftest" -b:a 64k -t 1 
-qscale:v 10 $2
-test $3 = "disable_crc" ||
+test "$3" = "disable_crc" ||
  do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3
  }
  



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] Add Timing Info to Log Lines

2019-09-02 Thread Thomas Volkert


On 02.09.19 12:26, Bodecs Bela wrote:


2019.09.02. 1:03 keltezéssel, Soft Works írta:

Hi,

I’m not sure whether this has been discussed, considered or
disregarded before.
I have some code ready for adding timestamps to the log output,
similar to this:

$ ffmpegd -loglevel +timing
ffmpeg version 4.2.git Copyright (c) 2000-2019 the FFmpeg developers….
    built with msvc
00:57:06.469 Hyper fast Audio and Video encoder
00:57:06.470 usage: ffmpeg [options] [[infile options] -i infile]...
{[outfile options] outfile}...
00:57:06.471
00:57:06.472 Use -h to get full help or, even better, run 'man ffmpeg'
00:57:06.474


When there’s interest in adding this, I could create a patch.


during streaming sometimes it would be very useful, so +1 vote,


+1 (activated by an option)




I suggest to put full date-time into log.


+1 (activated by an option)

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] Add Timing Info to Log Lines

2019-09-02 Thread Bodecs Bela


2019.09.02. 1:03 keltezéssel, Soft Works írta:

Hi,

I’m not sure whether this has been discussed, considered or disregarded before.
I have some code ready for adding timestamps to the log output, similar to this:

$ ffmpegd -loglevel +timing
ffmpeg version 4.2.git Copyright (c) 2000-2019 the FFmpeg developers….
built with msvc
00:57:06.469 Hyper fast Audio and Video encoder
00:57:06.470 usage: ffmpeg [options] [[infile options] -i infile]... {[outfile 
options] outfile}...
00:57:06.471
00:57:06.472 Use -h to get full help or, even better, run 'man ffmpeg'
00:57:06.474


When there’s interest in adding this, I could create a patch.


during streaming sometimes it would be very useful, so +1 vote,

I suggest to put full date-time into log.



softworkz

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



bb

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] hlsenc: flush segments to guarantuee atomic single file hls

2019-09-02 Thread Daniel Oberhoff
Hi all,

This makes sure segments published in the playlist of a single file hls 
recording are actually visible in the filesystem before the playlist entry. 
Otherwise there is a tiny race condition where a read to a piblished segment 
may fail.


from c309a535a865be70682885aa3b3bffcede41d85c Mon Sep 17 00:00:00 2001
From: Daniel Oberhoff 
Date: Wed, 16 Jan 2019 15:58:52 +0100
Subject: [PATCH] flush segments to guarantuee atomic single file hls

---
 libavformat/hlsenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d7a4cd2cc4..b0e0ce2300 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -461,6 +461,7 @@ static int flush_dynbuf(VariantStream *vs, int 
*range_length)
 *range_length = avio_close_dyn_buf(ctx->pb, );
 ctx->pb = NULL;
 avio_write(vs->out, buffer, *range_length);
+avio_flush(vs->out);
 av_free(buffer);

 // re-open buffer
--
2.22.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH/RFC] libavcodec/cinepak: Separate decoding from parsing

2019-09-02 Thread Tomas Härdin
sön 2019-09-01 klockan 23:07 +0200 skrev Carl Eugen Hoyos:
> Am So., 1. Sept. 2019 um 22:58 Uhr schrieb Tomas Härdin <
> tjop...@acc.umu.se>:
> 
> > Attached patch separates parsing from decoding in the Cinepak decoder.
> > It puts in some rather strict checks which are in line with how I've
> > figured the VfW 1.1 decoder works. Parsing is still intermixed with
> > validation, but the code should be much easier to read this way
> > compared to before. Some avpriv_request_sample()s should probably be
> > switched to outright rejection, I haven't decided yet
> 
> Your patch looks to me as if it would break decoding broken samples
> instead of returning as much decoded data as is possible with the
> input.

For some definitions of broken, yes. There is a contradiction between
safe, efficient parsing and just how broken bitstreams a particular
decoder will accept.

Until recently the definition of "not-broken" was "has enough bytes to
decode to a few lines of garbage"

Michael's recently suggested patch would define broken as "has too few
bytes to decode as an entire skip frame". This would change the
decoder's behavior for some class of files (gasp!)

My suggestion is that we should be very specific in what we accept,
backed up by samples in FATE. We should explicitly not worry about
files that someone somewhere might be able to generate which we
successfully reject. Else we cannot refactor with confidence.

/Tomas

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] avcodec/vp3: Check for end of input in 2 places of vp4_unpack_macroblocks()

2019-09-02 Thread Peter Ross
On Sun, Sep 01, 2019 at 11:10:25PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout (82sec -> 1sec)
> Fixes: 
> 16411/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-5166958151991296
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/vp3.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 28ed0461c7..a2bd2ef07d 100644
> --- a/libavcodec/vp3.c
> +++ b/libavcodec/vp3.c
> @@ -710,6 +710,8 @@ static int vp4_unpack_macroblocks(Vp3DecodeContext *s, 
> GetBitContext *gb)
>  has_partial = 0;
>  bit = get_bits1(gb);
>  for (i = 0; i < s->yuv_macroblock_count; i += current_run) {
> +if (get_bits_left(gb) <= 0)
> +return AVERROR_INVALIDDATA;
>  current_run = vp4_get_mb_count(s, gb);
>  if (current_run > s->yuv_macroblock_count - i)
>  return -1;
> @@ -719,6 +721,8 @@ static int vp4_unpack_macroblocks(Vp3DecodeContext *s, 
> GetBitContext *gb)
>  }
>  
>  if (has_partial) {
> +if (get_bits_left(gb) <= 0)
> +return AVERROR_INVALIDDATA;
>  bit  = get_bits1(gb);
>  current_run = vp4_get_mb_count(s, gb);
>  for (i = 0; i < s->yuv_macroblock_count; i++) {
> -- 
> 2.23.0

approve.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/1] avcodec/h264: Fix poc_lsb in open gop context

2019-09-02 Thread Gaullier Nicolas
>Envoyé : mardi 23 juillet 2019 14:09
>When no IDR nor mmco_reset is found, prev_poc_lsb is undefined and shall not 
>be assumed to be zero
>---
> libavcodec/h264_parse.c | 2 ++
> libavcodec/h264dec.c| 2 +-
> 2 files changed, 3 insertions(+), 1 deletion(-)
I have not received any feeback, do you think this patch could be applied ?
Thank you,
Nicolas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 4/4] avcodec/bgmc: Check input space in ff_bgmc_decode_init()

2019-09-02 Thread Thilo Borgmann
Am 01.09.19 um 23:10 schrieb Michael Niedermayer:
> Fixes: Infinite loop
> Fixes: 
> 16608/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5636229827133440
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/alsdec.c | 4 +++-
>  libavcodec/bgmc.c   | 7 ++-
>  libavcodec/bgmc.h   | 2 +-
>  3 files changed, 10 insertions(+), 3 deletions(-)

LGTM

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] nv-codec-headers: add functions and tidy up loader

2019-09-02 Thread Daniel Oberhoff
Hi all,

We use nv-codec-headers to talk to cuda since we use ffmpeg already and 
nv-codec-headers makes for a nice way to talk to the cuda libs. But we need a 
few more functions, so we added them and would like to push those changes back 
upstream. They may be very useful to other users of ffmpeg/cuda. We also took 
the liberty to clean up the loader macros a bit.


From daeffbc8bb41fd3baa9891839a1282b8f96fe604 Mon Sep 17 00:00:00 2001
From: Daniel Oberhoff 
Date: Mon, 2 Sep 2019 09:25:29 +0200
Subject: [PATCH] more functions and tidier loader

---
 ffnvcodec.pc.in|   2 +
 include/ffnvcodec/dynlink_cuda.h   |  51 ++-
 include/ffnvcodec/dynlink_loader.h | 227 ++---
 3 files changed, 197 insertions(+), 83 deletions(-)

diff --git a/ffnvcodec.pc.in b/ffnvcodec.pc.in
index 4d3723d..c25031f 100644
--- a/ffnvcodec.pc.in
+++ b/ffnvcodec.pc.in
@@ -5,3 +5,5 @@ Name: ffnvcodec
 Description: FFmpeg version of Nvidia Codec SDK headers
 Version: 9.0.18.2
 Cflags: -I${includedir}
+Libs: -ldl
+
diff --git a/include/ffnvcodec/dynlink_cuda.h b/include/ffnvcodec/dynlink_cuda.h
index ad5da7c..962d43f 100644
--- a/include/ffnvcodec/dynlink_cuda.h
+++ b/include/ffnvcodec/dynlink_cuda.h
@@ -47,6 +47,7 @@ typedef void* CUstream;
 typedef void* CUevent;
 typedef void* CUfunction;
 typedef void* CUmodule;
+typedef void* CUtexref;
 typedef void* CUtexObject;
 typedef void* CUmipmappedArray;
 typedef void* CUgraphicsResource;
@@ -238,6 +239,39 @@ typedef enum CUGLDeviceList_enum {
 CU_GL_DEVICE_LIST_NEXT_FRAME = 3,
 } CUGLDeviceList;
 
+typedef enum CUjit_option_enum {
+CU_JIT_MAX_REGISTERS = 0,
+CU_JIT_THREADS_PER_BLOCK,
+CU_JIT_WALL_TIME,
+CU_JIT_INFO_LOG_BUFFER,
+CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES,
+CU_JIT_ERROR_LOG_BUFFER,
+CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES,
+CU_JIT_OPTIMIZATION_LEVEL,
+CU_JIT_TARGET_FROM_CUCONTEXT,
+CU_JIT_TARGET,
+CU_JIT_FALLBACK_STRATEGY,
+CU_JIT_GENERATE_DEBUG_INFO,
+CU_JIT_LOG_VERBOSE,
+CU_JIT_GENERATE_LINE_INFO,
+CU_JIT_CACHE_MODE,
+CU_JIT_NEW_SM3X_OPT,
+CU_JIT_FAST_COMPILE,
+CU_JIT_NUM_OPTIONS
+} CUjit_option;
+
+/**
+ * Array descriptor
+ */
+typedef struct CUDA_ARRAY_DESCRIPTOR_st
+{
+size_t Width; /**< Width of array */
+size_t Height;/**< Height of array */
+
+CUarray_format Format;/**< Array format */
+unsigned int NumChannels; /**< Channels per array element */
+} CUDA_ARRAY_DESCRIPTOR;
+
 typedef struct CUDA_EXTERNAL_MEMORY_HANDLE_DESC_st {
 CUexternalMemoryHandleType type;
 union {
@@ -305,6 +339,7 @@ typedef struct CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC_st 
{
 #define CU_STREAM_NON_BLOCKING 1
 #define CU_EVENT_BLOCKING_SYNC 1
 #define CU_EVENT_DISABLE_TIMING 2
+#define CU_TRSA_OVERRIDE_FORMAT 1
 #define CU_TRSF_READ_AS_INTEGER 1
 
 typedef void CUDAAPI CUstreamCallback(CUstream hStream, CUresult status, void 
*userdata);
@@ -343,17 +378,31 @@ typedef CUresult CUDAAPI tcuEventRecord(CUevent hEvent, 
CUstream hStream);
 
 typedef CUresult CUDAAPI tcuLaunchKernel(CUfunction f, unsigned int gridDimX, 
unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned 
int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, CUstream 
hStream, void** kernelParams, void** extra);
 typedef CUresult CUDAAPI tcuModuleLoadData(CUmodule* module, const void* 
image);
-typedef CUresult CUDAAPI tcuModuleUnload(CUmodule hmod);
+typedef CUresult CUDAAPI tcuModuleLoadDataEx(CUmodule* module, const void* 
image, unsigned int numOptions, CUjit_option* options, void** optionValues);
+typedef CUresult CUDAAPI tcuModuleUnload(CUmodule module);
 typedef CUresult CUDAAPI tcuModuleGetFunction(CUfunction* hfunc, CUmodule 
hmod, const char* name);
+typedef CUresult CUDAAPI tcuModuleGetGlobal(CUdeviceptr* dptr, size_t* bytes, 
CUmodule hmod, const char* name);
+typedef CUresult CUDAAPI tcuModuleGetGlobal_v2(CUdeviceptr* dptr, size_t* 
bytes, CUmodule hmod, const char* name);
+typedef CUresult CUDAAPI tcuModuleGetTexRef(CUtexref* pTexRef, CUmodule hmod, 
const char* name);
 typedef CUresult CUDAAPI tcuTexObjectCreate(CUtexObject* pTexObject, const 
CUDA_RESOURCE_DESC* pResDesc, const CUDA_TEXTURE_DESC* pTexDesc, const 
CUDA_RESOURCE_VIEW_DESC* pResViewDesc);
 typedef CUresult CUDAAPI tcuTexObjectDestroy(CUtexObject texObject);
 
 typedef CUresult CUDAAPI tcuGLGetDevices_v2(unsigned int* pCudaDeviceCount, 
CUdevice* pCudaDevices, unsigned int cudaDeviceCount, CUGLDeviceList 
deviceList);
+typedef CUresult CUDAAPI tcuDeviceGetAttribute(int *pi, CUdevice_attribute 
attrib, CUdevice dev);
 typedef CUresult CUDAAPI tcuGraphicsGLRegisterImage(CUgraphicsResource* 
pCudaResource, GLuint image, GLenum target, unsigned int Flags);
 typedef CUresult CUDAAPI tcuGraphicsUnregisterResource(CUgraphicsResource 
resource);
 typedef CUresult CUDAAPI tcuGraphicsMapResources(unsigned int count, 
CUgraphicsResource* resources, CUstream 

[FFmpeg-devel] [PATCH] lavc/v4l2_m2m: don't close the file descriptor we don't own

2019-09-02 Thread Pavel Koshevoy
ff_v4l2_m2m_create_context initialized V4L2m2mContext.fd to 0
which is a valid file descriptor value. Next ff_v4l2_m2m_codec_init
failed and v4l2_m2m_destroy_context closed file descriptor 0 even
though it didn't belong to V4L2m2mContext.
---
 libavcodec/v4l2_m2m.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 427e165f58..ac583c811f 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -401,6 +401,7 @@ int ff_v4l2_m2m_create_context(AVCodecContext *avctx, 
V4L2m2mContext **s)
 priv->context->capture.num_buffers = priv->num_capture_buffers;
 priv->context->output.num_buffers  = priv->num_output_buffers;
 priv->context->self_ref = priv->context_ref;
+priv->context->fd = -1;
 
 return 0;
 }
-- 
2.16.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".