[FFmpeg-devel] [PATCH] avformat/utils: use AVIOContext.read_seek for seeks if available

2019-04-03 Thread Aman Gupta
From: Aman Gupta 

Currently only flv and asf decoders attempt to use pb->read_seek,
by calling avio_read_seek() expliclity.

This change allows avformat users to specify a custom AVIOContext
with a read_seek callback, and have it be used with any format
whenever av_seek_frame() is invoked.

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

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9b3f0d28e6..b38727b3ed 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2487,6 +2487,9 @@ static int seek_frame_internal(AVFormatContext *s, int 
stream_index,
 if (s->iformat->read_seek) {
 ff_read_frame_flush(s);
 ret = s->iformat->read_seek(s, stream_index, timestamp, flags);
+} else if (s->pb->read_seek) {
+ff_read_frame_flush(s);
+ret = s->pb->read_seek(s->pb->opaque, stream_index, timestamp, flags);
 } else
 ret = -1;
 if (ret >= 0)
-- 
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] [RFC PATCH] avformat/utils: always seek back after avformat_find_stream_info()

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

Previously, the initial seek position was recorded into
old_offset at the beginning of avformat_find_stream_info(),
and passed into estimate_timings(). In the case of mpegts
with a known filesize, it was further passed into
estimate_timings_from_pts() which called avio_seek(SEEK_SET)
after doing its timing related seeks. (Interestingly, this
seeked all the way back to the initial position before
the probe, rather than only back before the timing
related seeks to the end of the file).

With this commit, we pull the avio_seek() out of the mpegts
specific code-path and unconditionally seek all streams back
to their original position after probing is complete.

This effectively prevents data that is consumed during
avformat_find_stream_info() from being discarded, so packets
contained at the beginning of a file are still passed back
to the user for playback.

Signed-off-by: Aman Gupta 
---
 libavformat/utils.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9b3f0d28e6..94d166869a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2786,7 +2786,7 @@ static void 
estimate_timings_from_bit_rate(AVFormatContext *ic)
 #define DURATION_MAX_RETRY 6
 
 /* only usable for MPEG-PS streams */
-static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
+static void estimate_timings_from_pts(AVFormatContext *ic)
 {
 AVPacket pkt1, *pkt = &pkt1;
 AVStream *st;
@@ -2905,7 +2905,6 @@ static void estimate_timings_from_pts(AVFormatContext 
*ic, int64_t old_offset)
 skip_duration_calc:
 fill_all_stream_timings(ic);
 
-avio_seek(ic->pb, old_offset, SEEK_SET);
 for (i = 0; i < ic->nb_streams; i++) {
 int j;
 
@@ -2918,7 +2917,7 @@ skip_duration_calc:
 }
 }
 
-static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
+static void estimate_timings(AVFormatContext *ic)
 {
 int64_t file_size;
 
@@ -2934,7 +2933,7 @@ static void estimate_timings(AVFormatContext *ic, int64_t 
old_offset)
  !strcmp(ic->iformat->name, "mpegts")) &&
 file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
 /* get accurate estimate from the PTSes */
-estimate_timings_from_pts(ic, old_offset);
+estimate_timings_from_pts(ic);
 ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
 } else if (has_duration(ic)) {
 /* at least one component has timings - we use them for all
@@ -4053,7 +4052,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 
 if (probesize)
-estimate_timings(ic, old_offset);
+estimate_timings(ic);
+if ((ic->pb->seekable & AVIO_SEEKABLE_NORMAL))
+avio_seek(ic->pb, old_offset, SEEK_SET);
 
 av_opt_set(ic, "skip_clear", "0", AV_OPT_SEARCH_CHILDREN);
 
-- 
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] [RFC PATCH] avformat/utils: always seek back after avformat_find_stream_info()

2019-04-10 Thread Aman Gupta
On Tue, Apr 9, 2019 at 9:49 PM Hendrik Leppkes  wrote:

> On Wed, Apr 10, 2019 at 2:21 AM Aman Gupta  wrote:
> >
> > From: Aman Gupta 
> >
> > Previously, the initial seek position was recorded into
> > old_offset at the beginning of avformat_find_stream_info(),
> > and passed into estimate_timings(). In the case of mpegts
> > with a known filesize, it was further passed into
> > estimate_timings_from_pts() which called avio_seek(SEEK_SET)
> > after doing its timing related seeks. (Interestingly, this
> > seeked all the way back to the initial position before
> > the probe, rather than only back before the timing
> > related seeks to the end of the file).
> >
> > With this commit, we pull the avio_seek() out of the mpegts
> > specific code-path and unconditionally seek all streams back
> > to their original position after probing is complete.
> >
> > This effectively prevents data that is consumed during
> > avformat_find_stream_info() from being discarded, so packets
> > contained at the beginning of a file are still passed back
> > to the user for playback.
> >
>
> I don't think I ever had a case where data was apparently lost from
> the beginning of the stream. Can you give examples of what this fixes?


Perhaps I'm missing something.

If I see the debug log message "After avformat_find_stream_info() pos:
100 bytes  seeks:0", are the packets from the first megabyte of the
file still returned from API? Maybe they are being cached somewhere and I
did not notice.

This patch was based mostly on a reading of the code. I will run some more
detailed tests and provide an example/test of the new expected behavior.

Aman


>
> - Hendrik
> ___
> 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] [RFC PATCH] avformat/utils: always seek back after avformat_find_stream_info()

2019-04-10 Thread Aman Gupta
On Wed, Apr 10, 2019 at 1:00 AM Hendrik Leppkes  wrote:

> On Wed, Apr 10, 2019 at 9:55 AM Aman Gupta  wrote:
> >
> > On Tue, Apr 9, 2019 at 9:49 PM Hendrik Leppkes 
> wrote:
> >
> > > On Wed, Apr 10, 2019 at 2:21 AM Aman Gupta  wrote:
> > > >
> > > > From: Aman Gupta 
> > > >
> > > > Previously, the initial seek position was recorded into
> > > > old_offset at the beginning of avformat_find_stream_info(),
> > > > and passed into estimate_timings(). In the case of mpegts
> > > > with a known filesize, it was further passed into
> > > > estimate_timings_from_pts() which called avio_seek(SEEK_SET)
> > > > after doing its timing related seeks. (Interestingly, this
> > > > seeked all the way back to the initial position before
> > > > the probe, rather than only back before the timing
> > > > related seeks to the end of the file).
> > > >
> > > > With this commit, we pull the avio_seek() out of the mpegts
> > > > specific code-path and unconditionally seek all streams back
> > > > to their original position after probing is complete.
> > > >
> > > > This effectively prevents data that is consumed during
> > > > avformat_find_stream_info() from being discarded, so packets
> > > > contained at the beginning of a file are still passed back
> > > > to the user for playback.
> > > >
> > >
> > > I don't think I ever had a case where data was apparently lost from
> > > the beginning of the stream. Can you give examples of what this fixes?
> >
> >
> > Perhaps I'm missing something.
> >
> > If I see the debug log message "After avformat_find_stream_info() pos:
> > 100 bytes  seeks:0", are the packets from the first megabyte of the
> > file still returned from API? Maybe they are being cached somewhere and I
> > did not notice.
> >
>
> As far as I know, the packets read during stream info probing are
> being cached in a buffer and returned to the caller on av_read_frame.


Okay that seems to be the missing piece. If someone can point me to where
this buffer is in the code, that would be helpful.

In that case, it makes sense the only seek happens in the mpegts
estimate_by_pts case since that seeks all the way to the end. I'm still not
sure why it seeks back to the beginning (before probe start) position
though, and why that wouldn't cause packets to get doubled up.

Aman


>
> - Hendrik
> ___
> 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 1/2] avcodec/videotoolbox: add support for 10bit pixel format

2019-04-13 Thread Aman Gupta
On Sat, Apr 13, 2019 at 3:25 AM der richter  wrote:

> From: fumoboy007 
>
> this patch was originally posted on issue #7704 and was slightly
> adjusted to check for the availability of the pixel format.
> ---
>  configure  |  2 ++
>  fftools/ffmpeg_videotoolbox.c  |  3 +++
>  libavcodec/videotoolbox.c  | 32 +-
>  libavutil/hwcontext_videotoolbox.c |  3 +++
>  4 files changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/configure b/configure
> index 331393f8d5..a89da70aab 100755
> --- a/configure
> +++ b/configure
> @@ -2253,6 +2253,7 @@ TOOLCHAIN_FEATURES="
>
>  TYPES_LIST="
>  kCMVideoCodecType_HEVC
> +kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
>  socklen_t
>  struct_addrinfo
>  struct_group_source_req
> @@ -6012,6 +6013,7 @@ enabled avfoundation && {
>  enabled videotoolbox && {
>  check_lib coreservices CoreServices/CoreServices.h
> UTGetOSTypeFromString "-framework CoreServices"
>  check_func_headers CoreMedia/CMFormatDescription.h
> kCMVideoCodecType_HEVC "-framework CoreMedia"
> +check_func_headers CoreVideo/CVPixelBuffer.h
> kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange "-framework CoreVideo"
>  }
>
>  check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
> diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
> index b820aec017..ad6174d3c7 100644
> --- a/fftools/ffmpeg_videotoolbox.c
> +++ b/fftools/ffmpeg_videotoolbox.c
> @@ -52,6 +52,9 @@ static int videotoolbox_retrieve_data(AVCodecContext *s,
> AVFrame *frame)
>  case kCVPixelFormatType_32BGRA:   vt->tmp_frame->format =
> AV_PIX_FMT_BGRA; break;
>  #ifdef kCFCoreFoundationVersionNumber10_7
>  case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
> vt->tmp_frame->format = AV_PIX_FMT_NV12; break;
> +#endif
> +#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
> +case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
> vt->tmp_frame->format = AV_PIX_FMT_P010; break;
>  #endif
>  default:
>  av_log(NULL, AV_LOG_ERROR,
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index fb3501f413..021afd411b 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -26,6 +26,7 @@
>  #include "vt_internal.h"
>  #include "libavutil/avutil.h"
>  #include "libavutil/hwcontext.h"
> +#include "libavutil/pixdesc.h"
>  #include "bytestream.h"
>  #include "decode.h"
>  #include "h264dec.h"
> @@ -1020,6 +1021,17 @@ static int videotoolbox_uninit(AVCodecContext
> *avctx)
>  return 0;
>  }
>
> +static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext
> *avctx) {
> +const AVPixFmtDescriptor *descriptor =
> av_pix_fmt_desc_get(avctx->pix_fmt);
> +if (!descriptor)
> +return AV_PIX_FMT_NV12; // same as av_videotoolbox_alloc_context()
> +
> +int depth = descriptor->comp[0].depth;
> +if (depth > 8) {
> +return AV_PIX_FMT_P010;
> +}


Need a final fall-through return before the end of the function.


> +}
> +
>  static int videotoolbox_common_init(AVCodecContext *avctx)
>  {
>  VTContext *vtctx = avctx->internal->hwaccel_priv_data;
> @@ -1053,7 +1065,7 @@ static int videotoolbox_common_init(AVCodecContext
> *avctx)
>
>  hw_frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
>  hw_frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
> -hw_frames->sw_format = AV_PIX_FMT_NV12; // same as
> av_videotoolbox_alloc_context()
> +hw_frames->sw_format = videotoolbox_best_pixel_format(avctx);
>  hw_frames->width = avctx->width;
>  hw_frames->height = avctx->height;
>
> @@ -1097,7 +1109,7 @@ static int videotoolbox_frame_params(AVCodecContext
> *avctx,
>  frames_ctx->format= AV_PIX_FMT_VIDEOTOOLBOX;
>  frames_ctx->width = avctx->coded_width;
>  frames_ctx->height= avctx->coded_height;
> -frames_ctx->sw_format = AV_PIX_FMT_NV12;
> +frames_ctx->sw_format = videotoolbox_best_pixel_format(avctx);
>
>  return 0;
>  }
> @@ -1194,18 +1206,28 @@ const AVHWAccel ff_mpeg4_videotoolbox_hwaccel = {
>  .priv_data_size = sizeof(VTContext),
>  };
>
> -AVVideotoolboxContext *av_videotoolbox_alloc_context(void)
> +static AVVideotoolboxContext
> *av_videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt)
>  {
>  AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret));
>
>  if (ret) {
>  ret->output_callback = videotoolbox_decoder_callback;
> -ret->cv_pix_fmt_type =
> kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
> +
> +OSType cv_pix_fmt_type =
> av_map_videotoolbox_format_from_pixfmt(pix_fmt);
> +if (cv_pix_fmt_type == 0) {
> +cv_pix_fmt_type =
> kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
> +}
> +ret->cv_pix_fmt_type = cv_pix_fmt_type;
>  }
>
>  return ret;
>  }
>
> +AVVideotoolboxContext *av_videotoolbox_alloc_con

[FFmpeg-devel] [PATCH] avformat/mpegts: index only keyframes to ensure accurate seeks

2019-05-06 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavformat/mpegts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 8a84e5cc19..49e282903c 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -3198,9 +3198,9 @@ static int64_t mpegts_get_dts(AVFormatContext *s, int 
stream_index,
 ret = av_read_frame(s, &pkt);
 if (ret < 0)
 return AV_NOPTS_VALUE;
-if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0) {
+if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0 && (pkt.flags & 
AV_PKT_FLAG_KEY)) {
 ff_reduce_index(s, pkt.stream_index);
-av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 
0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
+av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 
0, 0, AVINDEX_KEYFRAME);
 if (pkt.stream_index == stream_index && pkt.pos >= *ppos) {
 int64_t dts = pkt.dts;
 *ppos = pkt.pos;
-- 
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] avformat/mpegts: apply -merge_pmt_versions only when versions change

2019-05-06 Thread Aman Gupta
From: Aman Gupta 

Previously the code assumed that stream_identifier was unique per stream
in the PMT, as suggested by the spec. However, I found some samples from
Finland MTV3 where this is not the case.

PID 0231 ( 561) -> Stream type 04 (  4) 13818-3 audio (MPEG-2)
ES info (17 bytes): 0a 04 66 69 6e 00 52 01 29 03 01 67 0e 03 c0 01 f6
Languages: fin
Stream Identifier (82) (1 byte): 29
Audio stream (3) (1 byte): 67
Maximum bitrate (14) (3 bytes): c0 01 f6
PID 0234 ( 564) -> Stream type 04 (  4) 13818-3 audio (MPEG-2)
ES info (17 bytes): 0a 04 64 75 74 03 52 01 29 03 01 67 0e 03 c0 01 59
Languages: dut/visual impaired commentary
Stream Identifier (82) (1 byte): 29
Audio stream (3) (1 byte): 67
Maximum bitrate (14) (3 bytes): c0 01 59

This patch updates the logic to merge streams only when they appear in
different versions of the PMT.

Signed-off-by: Aman Gupta 
---
 libavformat/mpegts.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 8a84e5cc19..9928959025 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2130,7 +2130,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 return 0;
 }
 
-static AVStream *find_matching_stream(MpegTSContext *ts, int pid,
+static AVStream *find_matching_stream(MpegTSContext *ts, int pid, int 
pmt_version,
   int stream_identifier, int 
pmt_stream_idx)
 {
 AVFormatContext *s = ts->stream;
@@ -2139,6 +2139,9 @@ static AVStream *find_matching_stream(MpegTSContext *ts, 
int pid,
 
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
+if (st->pmt_version == pmt_version) { /* only merge across pmt version 
changes */
+continue;
+}
 if (stream_identifier != -1) { /* match based on "stream identifier 
descriptor" if present */
 if (st->stream_identifier == stream_identifier+1) {
 found = st;
@@ -2309,7 +2312,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
 pes = ts->pids[pid]->u.pes_filter.opaque;
 if (ts->merge_pmt_versions && !pes->st) {
-st = find_matching_stream(ts, pid, stream_identifier, i);
+st = find_matching_stream(ts, pid, h->version, 
stream_identifier, i);
 if (st) {
 pes->st = st;
 pes->stream_type = stream_type;
@@ -2331,7 +2334,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt 
filter probably
 pes = add_pes_stream(ts, pid, pcr_pid);
 if (ts->merge_pmt_versions && pes && !pes->st) {
-st = find_matching_stream(ts, pid, stream_identifier, i);
+st = find_matching_stream(ts, pid, h->version, 
stream_identifier, i);
 if (st) {
 pes->st = st;
 pes->stream_type = stream_type;
@@ -2353,7 +2356,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 st = ts->stream->streams[idx];
 }
 if (ts->merge_pmt_versions && !st) {
-st = find_matching_stream(ts, pid, stream_identifier, i);
+st = find_matching_stream(ts, pid, h->version, 
stream_identifier, i);
 }
 if (!st) {
 st = avformat_new_stream(ts->stream, 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".

Re: [FFmpeg-devel] [PATCH 1/3] avcodec/mediacodecdec: try to receive a frame after signaling EOF to the codec

2019-05-07 Thread Aman Gupta
On Thu, May 2, 2019 at 1:20 AM Matthieu Bouron 
wrote:

> On Wed, Apr 24, 2019 at 09:59:28AM +0200, Matthieu Bouron wrote:
> > Avoids returning EAGAIN after signaling EOF to the codec in
> > ff_mediacodec_dec_send() so we can try to receive a frame before
> > returning in mediacodec_receive_frame().
> >
> > This helps avoiding an extra round-trip between avcodec_send_frame() and
> > avcodec_receive_frame() while draining the remaining frames.
> > ---
> >  libavcodec/mediacodecdec.c| 1 +
> >  libavcodec/mediacodecdec_common.c | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > index 3a4240aa95..e353e34bd5 100644
> > --- a/libavcodec/mediacodecdec.c
> > +++ b/libavcodec/mediacodecdec.c
> > @@ -461,6 +461,7 @@ static int mediacodec_receive_frame(AVCodecContext
> *avctx, AVFrame *frame)
> >  ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt,
> true);
> >  if (ret < 0)
> >  return ret;
> > +return ff_mediacodec_dec_receive(avctx, s->ctx, frame,
> true);
> >  } else if (ret == AVERROR(EAGAIN) &&
> s->ctx->current_input_buffer < 0) {
> >  return ff_mediacodec_dec_receive(avctx, s->ctx, frame,
> true);
> >  } else if (ret < 0) {
> > diff --git a/libavcodec/mediacodecdec_common.c
> b/libavcodec/mediacodecdec_common.c
> > index 7c2661f672..f7a06cdc6d 100644
> > --- a/libavcodec/mediacodecdec_common.c
> > +++ b/libavcodec/mediacodecdec_common.c
> > @@ -631,7 +631,7 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx,
> MediaCodecDecContext *s,
> > "Queued input buffer %zd size=%zd ts=%"PRIi64"\n",
> index, size, pts);
> >
> >  s->draining = 1;
> > -break;
> > +return 0;
> >  } else {
> >  size = FFMIN(pkt->size - offset, size);
> >  memcpy(data, pkt->data + offset, size);
> > --
> > 2.21.0
> >
>
> Ping.
>

Did not test, but the diffs look reasonable to me.


>
> --
> Matthieu B.
> ___
> 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] avformat/mpegts: respect program number when merging streams

2019-07-09 Thread Aman Gupta
On Tue, Jul 9, 2019 at 2:07 PM Marton Balint  wrote:

> merge_pmt_versions was not usable if multiple programs were present because
> when it was searching for candidate streams it did not make sure that the
> PMT was
> of the same program. This caused the streams of all programs to get merged
> into
> a single (garbled) program.
>
> This patch makes sure that the program number (service ID) is also matching
> with the old streams when parsing the PMT making the feature useful for
> multi
> program streams.
>
> This change might cause issues for single program streams if the program
> number
> changes as well, but I think it is acceptable because the goal of the
> option is
> to make the parsing resilient to PID changes, and that is still working as
> expected.
>

Patch looks good to me. Thanks for catching this!

Aman


>
> Signed-off-by: Marton Balint 
> ---
>  libavformat/mpegts.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 8a84e5cc19..47d8d5f877 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -2130,7 +2130,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc,
> AVStream *st, int stream_type
>  return 0;
>  }
>
> -static AVStream *find_matching_stream(MpegTSContext *ts, int pid,
> +static AVStream *find_matching_stream(MpegTSContext *ts, int pid,
> unsigned int programid,
>int stream_identifier, int
> pmt_stream_idx)
>  {
>  AVFormatContext *s = ts->stream;
> @@ -2139,6 +2139,8 @@ static AVStream *find_matching_stream(MpegTSContext
> *ts, int pid,
>
>  for (i = 0; i < s->nb_streams; i++) {
>  AVStream *st = s->streams[i];
> +if (st->program_num != programid)
> +continue;
>  if (stream_identifier != -1) { /* match based on "stream
> identifier descriptor" if present */
>  if (st->stream_identifier == stream_identifier+1) {
>  found = st;
> @@ -2309,7 +2311,7 @@ static void pmt_cb(MpegTSFilter *filter, const
> uint8_t *section, int section_len
>  if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
>  pes = ts->pids[pid]->u.pes_filter.opaque;
>  if (ts->merge_pmt_versions && !pes->st) {
> -st = find_matching_stream(ts, pid, stream_identifier, i);
> +st = find_matching_stream(ts, pid, h->id,
> stream_identifier, i);
>  if (st) {
>  pes->st = st;
>  pes->stream_type = stream_type;
> @@ -2331,7 +2333,7 @@ static void pmt_cb(MpegTSFilter *filter, const
> uint8_t *section, int section_len
>  mpegts_close_filter(ts, ts->pids[pid]); // wrongly added
> sdt filter probably
>  pes = add_pes_stream(ts, pid, pcr_pid);
>  if (ts->merge_pmt_versions && pes && !pes->st) {
> -st = find_matching_stream(ts, pid, stream_identifier, i);
> +st = find_matching_stream(ts, pid, h->id,
> stream_identifier, i);
>  if (st) {
>  pes->st = st;
>  pes->stream_type = stream_type;
> @@ -2353,7 +2355,7 @@ static void pmt_cb(MpegTSFilter *filter, const
> uint8_t *section, int section_len
>  st = ts->stream->streams[idx];
>  }
>  if (ts->merge_pmt_versions && !st) {
> -st = find_matching_stream(ts, pid, stream_identifier, i);
> +st = find_matching_stream(ts, pid, h->id,
> stream_identifier, i);
>  }
>  if (!st) {
>  st = avformat_new_stream(ts->stream, NULL);
> --
> 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".

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: add hdr10, linear, hlg color transfer function for videotoolboxenc

2019-07-09 Thread Aman Gupta
On Wed, Jun 26, 2019 at 4:25 AM  wrote:

> From: Limin Wang 
>
> Below is the testing ffmpeg command for the setting:
> ./ffmpeg -i input.ts -c:v hevc_videotoolbox -color_primaries bt2020
> -colorspace bt2020_ncl -color_trc smpte2084 smpte2048.ts
> ./ffmpeg -i input.ts -c:v hevc_videotoolbox -color_primaries bt2020
> -colorspace bt2020_ncl -color_trc linear linear.ts
> ./ffmpeg -i input.ts -c:v hevc_videotoolbox -color_primaries bt2020
> -colorspace bt2020_ncl -color_trc arib-std-b67 hlg.ts
>

Patch looks reasonable to me. Will commit in a few days if no one else
comments.

Aman


>
> Signed-off-by: Limin Wang 
> ---
>  configure|  6 ++
>  libavcodec/videotoolboxenc.c | 16 
>  2 files changed, 22 insertions(+)
>
> diff --git a/configure b/configure
> index 7cea9d4d73..0a5e940c0c 100755
> --- a/configure
> +++ b/configure
> @@ -2260,6 +2260,9 @@ TOOLCHAIN_FEATURES="
>  TYPES_LIST="
>  kCMVideoCodecType_HEVC
>  kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
> +kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ
> +kCVImageBufferTransferFunction_ITU_R_2100_HLG
> +kCVImageBufferTransferFunction_Linear
>  socklen_t
>  struct_addrinfo
>  struct_group_source_req
> @@ -6044,6 +6047,9 @@ enabled videotoolbox && {
>  check_lib coreservices CoreServices/CoreServices.h
> UTGetOSTypeFromString "-framework CoreServices"
>  check_func_headers CoreMedia/CMFormatDescription.h
> kCMVideoCodecType_HEVC "-framework CoreMedia"
>  check_func_headers CoreVideo/CVPixelBuffer.h
> kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange "-framework CoreVideo"
> +check_func_headers CoreVideo/CVImageBuffer.h
> kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ "-framework CoreVideo"
> +check_func_headers CoreVideo/CVImageBuffer.h
> kCVImageBufferTransferFunction_ITU_R_2100_HLG "-framework CoreVideo"
> +check_func_headers CoreVideo/CVImageBuffer.h
> kCVImageBufferTransferFunction_Linear "-framework CoreVideo"
>  }
>
>  check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index f8ccdea52d..0dc6eb4cf4 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -915,6 +915,22 @@ static int get_cv_transfer_function(AVCodecContext
> *avctx,
>  *transfer_fnc =
> kCVImageBufferTransferFunction_SMPTE_240M_1995;
>  break;
>
> +#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ
> +case AVCOL_TRC_SMPTE2084:
> +*transfer_fnc =
> kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
> +break;
> +#endif
> +#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_LINEAR
> +case AVCOL_TRC_LINEAR:
> +*transfer_fnc = kCVImageBufferTransferFunction_Linear;
> +break;
> +#endif
> +#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
> +case AVCOL_TRC_ARIB_STD_B67:
> +*transfer_fnc = kCVImageBufferTransferFunction_ITU_R_2100_HLG;
> +break;
> +#endif
> +
>  case AVCOL_TRC_GAMMA22:
>  gamma = 2.2;
>  *transfer_fnc = kCVImageBufferTransferFunction_UseGamma;
> --
> 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] [PATCH] fftools/ffprobe: process show_frame/show_packets last

2019-07-18 Thread Aman Gupta
From: Aman Gupta 

When using `ffprobe -show_format -show_streams -show_packets`,
it makes more sense to omit static data about the file format
and streams before the long list of packets instead of at the
end.

Signed-off-by: Aman Gupta 
---
 fftools/ffprobe.c | 38 --
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 5aaddb0308..c9c10b143d 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3003,6 +3003,26 @@ static int probe_file(WriterContext *wctx, const char 
*filename)
 ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
 }
 
+if (do_show_format) {
+ret = show_format(wctx, &ifile);
+CHECK_END;
+}
+
+if (do_show_streams) {
+ret = show_streams(wctx, &ifile);
+CHECK_END;
+}
+
+if (do_show_programs) {
+ret = show_programs(wctx, &ifile);
+CHECK_END;
+}
+
+if (do_show_chapters) {
+ret = show_chapters(wctx, &ifile);
+CHECK_END;
+}
+
 if (do_read_frames || do_read_packets) {
 if (do_show_frames && do_show_packets &&
 wctx->writer->flags & 
WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER)
@@ -3019,24 +3039,6 @@ static int probe_file(WriterContext *wctx, const char 
*filename)
 CHECK_END;
 }
 
-if (do_show_programs) {
-ret = show_programs(wctx, &ifile);
-CHECK_END;
-}
-
-if (do_show_streams) {
-ret = show_streams(wctx, &ifile);
-CHECK_END;
-}
-if (do_show_chapters) {
-ret = show_chapters(wctx, &ifile);
-CHECK_END;
-}
-if (do_show_format) {
-ret = show_format(wctx, &ifile);
-CHECK_END;
-}
-
 end:
 if (ifile.fmt_ctx)
 close_input_file(&ifile);
-- 
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 1/5] cbs: Add some common code for read/write of miscellaneous user data

2019-07-26 Thread Aman Gupta
On Sun, Mar 25, 2018 at 10:41 AM Mark Thompson  wrote:

> Supports closed captions, active format and bar data as defined by
> SCTE 128 part 1 or A/53 part 4, suitable for use with both MPEG-2
> and H.264.
> ---
>  libavcodec/cbs_misc.c | 216
> ++
>  libavcodec/cbs_misc.h | 109 +
>  libavcodec/cbs_misc_syntax_template.c | 150 +++
>  3 files changed, 475 insertions(+)
>  create mode 100644 libavcodec/cbs_misc.c
>  create mode 100644 libavcodec/cbs_misc.h
>  create mode 100644 libavcodec/cbs_misc_syntax_template.c
>
> diff --git a/libavcodec/cbs_misc.c b/libavcodec/cbs_misc.c
> new file mode 100644
> index 00..cdf01fe229
> --- /dev/null
> +++ b/libavcodec/cbs_misc.c
> @@ -0,0 +1,216 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include "libavutil/attributes.h"
> +#include "libavutil/avassert.h"
> +
> +#include "cbs.h"
> +#include "cbs_internal.h"
> +#include "cbs_misc.h"
> +
> +#define CHECK(call) do { \
> +err = (call); \
> +if (err < 0) \
> +return err; \
> +} while (0)
> +
> +#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
> +#define FUNC_MISC(rw, name) FUNC_NAME(rw, misc, name)
> +#define FUNC(name) FUNC_MISC(READWRITE, name)
> +
> +
> +#define READWRITE read
> +#define RWContext GetBitContext
> +
> +#define xui(width, name, var) do { \
> +uint32_t value = 0; \
> +CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
> +   &value, 0, MAX_UINT_BITS(width))); \
> +var = value; \
> +} while (0)
> +
> +#define ui(width, name) \
> +xui(width, name, current->name)
> +
> +#define fixed(width, name, expected) do { \
> +av_unused uint32_t value; \
> +CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, &value, \
> +   expected, expected)); \
> +} while (0)
> +
> +#include "cbs_misc_syntax_template.c"
> +
> +#undef READWRITE
> +#undef RWContext
> +#undef xui
> +#undef ui
> +#undef fixed
> +
> +
> +#define READWRITE write
> +#define RWContext PutBitContext
> +
> +#define xui(width, name, var) do { \
> +CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
> +var, 0, MAX_UINT_BITS(width))); \
> +} while (0)
> +
> +#define ui(width, name) \
> +xui(width, name, current->name)
> +
> +#define fixed(width, name, value) do { \
> +CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, value, \
> +value, value)); \
> +} while (0)
> +
> +#include "cbs_misc_syntax_template.c"
> +
> +#undef READWRITE
> +#undef RWContext
> +#undef xui
> +#undef ui
> +#undef fixed
> +
> +
> +int ff_cbs_read_a53_user_data(CodedBitstreamContext *ctx,
> +  A53UserData *data,
> +  const uint8_t *read_buffer, size_t length)
> +{
> +GetBitContext gbc;
> +int err;
> +
> +err = init_get_bits(&gbc, read_buffer, 8 * length);
> +if (err < 0)
> +return err;
> +
> +return cbs_misc_read_a53_user_data(ctx, &gbc, data);
> +}
> +
> +int ff_cbs_write_a53_user_data(CodedBitstreamContext *ctx,
> +   uint8_t *write_buffer, size_t *length,
> +   A53UserData *data)
> +{
> +PutBitContext pbc;
> +int err;
> +
> +init_put_bits(&pbc, write_buffer, *length);
> +
> +err = cbs_misc_write_a53_user_data(ctx, &pbc, data);
> +if (err < 0) {
> +// Includes AVERROR(ENOSPC).
> +return err;
> +}
> +
> +// That output must be aligned.
> +av_assert0(put_bits_count(&pbc) % 8 == 0);
> +
> +*length = put_bits_count(&pbc) / 8;
> +
> +flush_put_bits(&pbc);
> +
> +return 0;
> +}
> +
> +int ff_cbs_read_a53_cc_side_data(CodedBitstreamContext *ctx,
> + A53UserData *data,
> + const uint8_t *side_data,
> + size_t side_data_size)
> +{
> +GetBitContext gbc;
> +CEA708CCData *cc;
> +int err, i, cc_count;
> +
> +if (side_data_size % 3) {
> +av_log(c

[FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h264: add support for a/53 closed caption sei

2019-08-01 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/vaapi_encode_h264.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index f4965d8b09..f66e483b7f 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -39,6 +39,7 @@ enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
 SEI_RECOVERY_POINT = 0x04,
+SEI_A53_CC = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -96,6 +97,7 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIBufferingPeriod  sei_buffering_period;
 H264RawSEIPicTimingsei_pic_timing;
 H264RawSEIRecoveryPointsei_recovery_point;
+H264RawSEIUserDataRegistered   sei_a53_cc;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
 
@@ -251,6 +253,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_A53_CC) {
+sei->payload[i].payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED;
+sei->payload[i].payload.user_data_registered = priv->sei_a53_cc;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -626,7 +633,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture  *prev = pic->prev;
 VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
 VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
-int i;
+AVFrameSideData *side_data = NULL;
+int i, err;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -700,6 +708,27 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+side_data = av_frame_get_side_data(pic->input_image, AV_FRAME_DATA_A53_CC);
+if (side_data && side_data->size) {
+priv->sei_a53_cc.itu_t_t35_country_code = 181;
+priv->sei_a53_cc.data_length = side_data->size + 9;
+err = av_reallocp(&priv->sei_a53_cc.data, 
priv->sei_a53_cc.data_length);
+if (err < 0)
+return err;
+priv->sei_a53_cc.data[0] = 0;
+priv->sei_a53_cc.data[1] = 49;
+priv->sei_a53_cc.data[2] = 'G';
+priv->sei_a53_cc.data[3] = 'A';
+priv->sei_a53_cc.data[4] = '9';
+priv->sei_a53_cc.data[5] = '4';
+priv->sei_a53_cc.data[6] = 3;
+priv->sei_a53_cc.data[7] = 0xc0 | (side_data->size/3);
+priv->sei_a53_cc.data[8] = 255;
+memcpy(priv->sei_a53_cc.data+9, side_data->data, side_data->size);
+
+priv->sei_needed |= SEI_A53_CC;
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1245,6 +1274,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit);
 ff_cbs_close(&priv->cbc);
 av_freep(&priv->sei_identifier_string);
+av_freep(&priv->sei_a53_cc.data);
 
 return ff_vaapi_encode_close(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 v2] avcodec/vaapi_encode_h264: add support for a/53 closed caption sei

2019-08-01 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/vaapi_encode_h264.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index f4965d8b09..9860bacb91 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -39,6 +39,7 @@ enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
 SEI_RECOVERY_POINT = 0x04,
+SEI_A53_CC = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -98,6 +99,8 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIRecoveryPointsei_recovery_point;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
+H264RawSEIUserDataRegistered   sei_a53cc;
+void  *sei_a53cc_data;
 
 int aud_needed;
 int sei_needed;
@@ -251,6 +254,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_A53_CC) {
+sei->payload[i].payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED;
+sei->payload[i].payload.user_data_registered = priv->sei_a53cc;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -626,7 +634,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture  *prev = pic->prev;
 VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
 VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
-int i;
+int i, err;
+size_t sei_a53cc_len;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -700,6 +709,18 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+av_freep(&priv->sei_a53cc_data);
+err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, 
&sei_a53cc_len);
+if (err < 0)
+return err;
+if (priv->sei_a53cc_data != NULL) {
+priv->sei_a53cc.itu_t_t35_country_code = 181;
+priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+priv->sei_needed |= SEI_A53_CC;
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1245,6 +1266,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit);
 ff_cbs_close(&priv->cbc);
 av_freep(&priv->sei_identifier_string);
+av_freep(&priv->sei_a53cc_data);
 
 return ff_vaapi_encode_close(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 v3] avcodec/vaapi_encode_h264: add support for a/53 closed caption sei

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

Signed-off-by: Aman Gupta 
---
 libavcodec/vaapi_encode_h264.c | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index f4965d8b09..280bd4752b 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -39,6 +39,7 @@ enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
 SEI_RECOVERY_POINT = 0x04,
+SEI_A53_CC = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -72,6 +73,7 @@ typedef struct VAAPIEncodeH264Context {
 int sei;
 int profile;
 int level;
+bool enable_a53_cc;
 
 // Derived settings.
 int mb_width;
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIRecoveryPointsei_recovery_point;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
+H264RawSEIUserDataRegistered   sei_a53cc;
+void  *sei_a53cc_data;
 
 int aud_needed;
 int sei_needed;
@@ -251,6 +255,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_A53_CC) {
+sei->payload[i].payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED;
+sei->payload[i].payload.user_data_registered = priv->sei_a53cc;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -626,7 +635,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture  *prev = pic->prev;
 VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
 VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
-int i;
+int i, err;
+size_t sei_a53cc_len;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -700,6 +710,21 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+if (priv->enable_a53_cc) {
+av_freep(&priv->sei_a53cc_data);
+err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, 
&sei_a53cc_len);
+if (err < 0)
+return err;
+
+if (priv->sei_a53cc_data) {
+priv->sei_a53cc.itu_t_t35_country_code = 181;
+priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+priv->sei_needed |= SEI_A53_CC;
+}
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1245,6 +1270,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit);
 ff_cbs_close(&priv->cbc);
 av_freep(&priv->sei_identifier_string);
+av_freep(&priv->sei_a53cc_data);
 
 return ff_vaapi_encode_close(avctx);
 }
@@ -1321,6 +1347,8 @@ static const AVOption vaapi_encode_h264_options[] = {
 { LEVEL("6.2", 62) },
 #undef LEVEL
 
+{ "a53cc", "Use A53 Closed Captions (if available)", 
OFFSET(enable_a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
+
 { 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 v4] avcodec/vaapi_encode_h264: add support for a/53 closed caption sei

2019-08-06 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/vaapi_encode_h264.c | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index f4965d8b09..f3da3ee299 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -39,6 +39,7 @@ enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
 SEI_RECOVERY_POINT = 0x04,
+SEI_A53_CC = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -72,6 +73,7 @@ typedef struct VAAPIEncodeH264Context {
 int sei;
 int profile;
 int level;
+int enable_a53_cc;
 
 // Derived settings.
 int mb_width;
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIRecoveryPointsei_recovery_point;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
+H264RawSEIUserDataRegistered   sei_a53cc;
+void  *sei_a53cc_data;
 
 int aud_needed;
 int sei_needed;
@@ -251,6 +255,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_A53_CC) {
+sei->payload[i].payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED;
+sei->payload[i].payload.user_data_registered = priv->sei_a53cc;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -626,7 +635,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture  *prev = pic->prev;
 VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
 VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
-int i;
+int i, err;
+size_t sei_a53cc_len;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -700,6 +710,21 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+if (priv->enable_a53_cc) {
+av_freep(&priv->sei_a53cc_data);
+err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, 
&sei_a53cc_len);
+if (err < 0)
+return err;
+
+if (priv->sei_a53cc_data) {
+priv->sei_a53cc.itu_t_t35_country_code = 181;
+priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+priv->sei_needed |= SEI_A53_CC;
+}
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1245,6 +1270,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit);
 ff_cbs_close(&priv->cbc);
 av_freep(&priv->sei_identifier_string);
+av_freep(&priv->sei_a53cc_data);
 
 return ff_vaapi_encode_close(avctx);
 }
@@ -1321,6 +1347,8 @@ static const AVOption vaapi_encode_h264_options[] = {
 { LEVEL("6.2", 62) },
 #undef LEVEL
 
+{ "a53cc", "Use A53 Closed Captions (if available)", 
OFFSET(enable_a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
+
 { 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".

Re: [FFmpeg-devel] [PATCH 02/14] vaapi_encode: Convert to send/receive API

2019-08-07 Thread Aman Gupta
On Thu, Dec 20, 2018 at 12:46 PM Mark Thompson  wrote:

> This attaches the logic of picking the mode of for the next picture to
> the output, which simplifies some choices by removing the concept of
> the picture for which input is not yet available.  At the same time,
> we allow more complex reference structures and track more reference
> metadata (particularly the contents of the DPB) for use in the
> codec-specific code.
>
> It also adds flags to explicitly track the available features of the
> different codecs.  The new structure also allows open-GOP support, so
> that is now available for codecs which can do it.
> ---
> This change and related pieces (patches 1-6) have been hanging around for
> a while.  If there are no comments I'll commit it probably early next year.
>
>
>  libavcodec/vaapi_encode.c   | 635 +---
>  libavcodec/vaapi_encode.h   |  74 +++-
>  libavcodec/vaapi_encode_h264.c  |   7 +-
>  libavcodec/vaapi_encode_h265.c  |   7 +-
>  libavcodec/vaapi_encode_mjpeg.c |   9 +-
>  libavcodec/vaapi_encode_mpeg2.c |   5 +-
>  libavcodec/vaapi_encode_vp8.c   |   3 +-
>  libavcodec/vaapi_encode_vp9.c   |   5 +-
>  8 files changed, 419 insertions(+), 326 deletions(-)
>
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index d8bedbe162..eec083da4f 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -158,16 +158,10 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
>  av_log(avctx, AV_LOG_DEBUG, ".\n");
>  }
>
> -av_assert0(pic->input_available && !pic->encode_issued);
> +av_assert0(!pic->encode_issued);
>  for (i = 0; i < pic->nb_refs; i++) {
>  av_assert0(pic->refs[i]);
> -// If we are serialised then the references must have already
> -// completed.  If not, they must have been issued but need not
> -// have completed yet.
> -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING)
> -av_assert0(pic->refs[i]->encode_complete);
> -else
> -av_assert0(pic->refs[i]->encode_issued);
> +av_assert0(pic->refs[i]->encode_issued);
>  }
>
>  av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n",
> pic->input_surface);
> @@ -466,10 +460,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
>
>  pic->encode_issued = 1;
>
> -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING)
> -return vaapi_encode_wait(avctx, pic);
> -else
> -return 0;
> +return 0;
>
>  fail_with_picture:
>  vaEndPicture(ctx->hwctx->display, ctx->va_context);
> @@ -626,315 +617,330 @@ static int vaapi_encode_free(AVCodecContext *avctx,
>  return 0;
>  }
>
> -static int vaapi_encode_step(AVCodecContext *avctx,
> - VAAPIEncodePicture *target)
> +static void vaapi_encode_add_ref(AVCodecContext *avctx,
> + VAAPIEncodePicture *pic,
> + VAAPIEncodePicture *target,
> + int is_ref, int in_dpb, int prev)
>  {
> -VAAPIEncodeContext *ctx = avctx->priv_data;
> -VAAPIEncodePicture *pic;
> -int i, err;
> +int refs = 0;
>
> -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING ||
> -ctx->issue_mode == ISSUE_MODE_MINIMISE_LATENCY) {
> -// These two modes are equivalent, except that we wait for
> -// immediate completion on each operation if serialised.
> -
> -if (!target) {
> -// No target, nothing to do yet.
> -return 0;
> -}
> -
> -if (target->encode_complete) {
> -// Already done.
> -return 0;
> -}
> -
> -pic = target;
> -for (i = 0; i < pic->nb_refs; i++) {
> -if (!pic->refs[i]->encode_complete) {
> -err = vaapi_encode_step(avctx, pic->refs[i]);
> -if (err < 0)
> -return err;
> -}
> -}
> -
> -err = vaapi_encode_issue(avctx, pic);
> -if (err < 0)
> -return err;
> -
> -} else if (ctx->issue_mode == ISSUE_MODE_MAXIMISE_THROUGHPUT) {
> -int activity;
> -
> -// Run through the list of all available pictures repeatedly
> -// and issue the first one found which has all dependencies
> -// available (including previously-issued but not necessarily
> -// completed pictures).
> -do {
> -activity = 0;
> -for (pic = ctx->pic_start; pic; pic = pic->next) {
> -if (!pic->input_available || pic->encode_issued)
> -continue;
> -for (i = 0; i < pic->nb_refs; i++) {
> -if (!pic->refs[i]->encode_issued)
> -break;
> -}
> -if (i < pic->nb_refs)
> -continue;
> -err = vaapi_encode_issue(avctx, pic);
> -if (err < 0)

[FFmpeg-devel] [PATCH] avcodec/vaapi_encode: respect -force_key_frames setting

2019-08-07 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e69b59fa37..2fb43cf1a4 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1057,7 +1057,7 @@ int ff_vaapi_encode_send_frame(AVCodecContext *avctx, 
const AVFrame *frame)
 if (err < 0)
 goto fail;
 
-if (ctx->input_order == 0)
+if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
 pic->force_idr = 1;
 
 pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
-- 
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 2/2] vaapi_encode: work-around VBR driver bug in Intel Broxton/CherryView

2019-08-12 Thread Aman Gupta
From: Aman Gupta 

The hardware encoder on these chipsets produces very low bitrates
in VBR mode if it receives VAEncMiscParameterTypeRateControl more than once.

/cc intel/intel-vaapi-driver#480

Signed-off-by: Aman Gupta 
---
 libavcodec/vaapi_encode.c   |  8 +++-
 libavutil/hwcontext_vaapi.c | 10 ++
 libavutil/hwcontext_vaapi.h |  6 ++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 231efba6cc..a5f46cdee0 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -163,7 +163,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodeSlice *slice;
 VAStatus vas;
-int err, i;
+int err, i, send_global_params;
 char data[MAX_PARAM_BUFFER_SIZE];
 size_t bit_len;
 av_unused AVFrameSideData *sd;
@@ -236,6 +236,12 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 if (pic->type == PICTURE_TYPE_IDR) {
 for (i = 0; i < ctx->nb_global_params; i++) {
+if (pic->encode_order != 0 &&
+ctx->global_params_type[i] == 
VAEncMiscParameterTypeRateControl &&
+ctx->hwctx->driver_quirks & 
AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE) {
+// send VAEncMiscParameterTypeRateControl only once to 
affected drivers
+continue;
+}
 err = vaapi_encode_make_misc_param_buffer(avctx, pic,
   
ctx->global_params_type[i],
   ctx->global_params[i],
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index cf117640f2..a206ce8880 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -323,6 +323,16 @@ static const struct {
 "Splitted-Desktop Systems VDPAU backend for VA-API",
 AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
 },
+{
+"Intel Broxton",
+"Intel(R) Broxton",
+AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE,
+},
+{
+"Intel CherryView",
+"Intel(R) CherryView",
+AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE,
+},
 };
 
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..ea4181fab0 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,12 @@ enum {
  * and the results of the vaQuerySurfaceAttributes() call will be faked.
  */
 AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+/**
+ * The driver does not react well to receiving global parameters with
+ * every IDR frame.
+ */
+AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE = (1 << 4),
 };
 
 /**
-- 
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 1/2] vaapi_encode: ensure correct VBR bitrate is used in h264 SPS

2019-08-12 Thread Aman Gupta
From: Aman Gupta 

This is a regression from 2562dd9e7831743ba6dc5680501fb7d26a2ec62c
which surfaces a pathological bug in the Intel Broxton/CherryView
hardware encoders, causing very low bitrates to be generated
whenever VBR mode is used.

/cc intel/intel-vaapi-driver#480

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

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e69b59fa37..231efba6cc 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1665,6 +1665,9 @@ rc_mode_found:
 ctx->va_rc_mode  = rc_mode->va_mode;
 ctx->va_bit_rate = rc_bits_per_second;
 
+if (ctx->va_rc_mode == VA_RC_VBR)
+ctx->va_bit_rate = rc_bits_per_second * rc_target_percentage / 100;
+
 av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
 if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
 // This driver does not want the RC mode attribute to be set.
-- 
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 v2 2/2] vaapi_encode: fix VBR mode generating low bitrates

2019-08-12 Thread Aman Gupta
From: Aman Gupta 

On some Intel chips, sending VAEncMiscParameterTypeRateControl multiple
times causes the encoder to produce very low bitrates that do not match
the requested rate controls.

This is a regression as of af532c921575eb8ee805cc2c64a914f6302442e1. Prior
to that global params were sent only once at the start of the
encoding session.

The broken VBR behavior was observed on:

  - i5-7260U Kaby Lake
  - N3060 CherryView
  - N3710 CherryView
  - J3455 Broxton

/cc intel/intel-vaapi-driver#480

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

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 231efba6cc..960f8230de 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -236,6 +236,12 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 if (pic->type == PICTURE_TYPE_IDR) {
 for (i = 0; i < ctx->nb_global_params; i++) {
+if (pic->encode_order != 0 &&
+ctx->global_params_type[i] == 
VAEncMiscParameterTypeRateControl &&
+ctx->va_rc_mode == VA_RC_VBR) {
+// send VAEncMiscParameterTypeRateControl only once in VBR mode
+continue;
+}
 err = vaapi_encode_make_misc_param_buffer(avctx, pic,
   
ctx->global_params_type[i],
   ctx->global_params[i],
-- 
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 v2 1/2] vaapi_encode: ensure correct VBR bitrate is used in h264 SPS

2019-08-12 Thread Aman Gupta
From: Aman Gupta 

This is a regression from 2562dd9e7831743ba6dc5680501fb7d26a2ec62c
which surfaces a pathological bug in some Intel hardware encoders,
causing very low bitrates to be generated whenever VBR mode is used.

/cc intel/intel-vaapi-driver#480

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

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e69b59fa37..231efba6cc 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1665,6 +1665,9 @@ rc_mode_found:
 ctx->va_rc_mode  = rc_mode->va_mode;
 ctx->va_bit_rate = rc_bits_per_second;
 
+if (ctx->va_rc_mode == VA_RC_VBR)
+ctx->va_bit_rate = rc_bits_per_second * rc_target_percentage / 100;
+
 av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
 if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
 // This driver does not want the RC mode attribute to be set.
-- 
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] lavf/vf_deinterlace_vaapi: flush queued frame in field mode

2019-08-13 Thread Aman Gupta
On Tue, Aug 13, 2019 at 7:01 PM Fu, Linjie  wrote:

> > -Original Message-
> > From: Fu, Linjie
> > Sent: Friday, August 2, 2019 17:54
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Fu, Linjie 
> > Subject: [PATCH] lavf/vf_deinterlace_vaapi: flush queued frame in field
> > mode
> >
> > Add deint_vaapi_request_frame for deinterlace_vaapi, send NULL frame
> > to flush the queued frame.
> >
> > Fix the frame drop issue in field mode:
> >
> > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -v verbose -c:v
> > h264 -i ./input.h264 -vf 'format=nv12|vaapi,hwupload,
> > deinterlace_vaapi=mode=bob:rate=field,hwdownload,format=nv12'
> > -pix_fmt yuv420p -f rawvideo -vsync passthrough -y dump.yuv
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  libavfilter/vf_deinterlace_vaapi.c | 46
> > --
> >  1 file changed, 39 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavfilter/vf_deinterlace_vaapi.c
> > b/libavfilter/vf_deinterlace_vaapi.c
> > index 72d0349..c811327 100644
> > --- a/libavfilter/vf_deinterlace_vaapi.c
> > +++ b/libavfilter/vf_deinterlace_vaapi.c
> > @@ -48,6 +48,9 @@ typedef struct DeintVAAPIContext {
> >  intqueue_count;
> >  AVFrame   *frame_queue[MAX_REFERENCES];
> >  intextra_delay_for_timestamps;
> > +
> > +inteof;
> > +intprev_pts;
> >  } DeintVAAPIContext;
> >
> >  static const char *deint_vaapi_mode_name(int mode)
> > @@ -190,11 +193,16 @@ static int deint_vaapi_filter_frame(AVFilterLink
> > *inlink, AVFrame *input_frame)
> >  void *filter_params_addr = NULL;
> >  int err, i, field, current_frame_index;
> >
> > -av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u
> (%"PRId64").\n",
> > -   av_get_pix_fmt_name(input_frame->format),
> > -   input_frame->width, input_frame->height, input_frame->pts);
> > +// NULL frame is used to flush the queue in field mode
> > +if (input_frame)
> > +av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u
> > (%"PRId64").\n",
> > +av_get_pix_fmt_name(input_frame->format),
> > +input_frame->width, input_frame->height, input_frame->pts);
> > +else if (ctx->field_rate == 1) {
> > +return 0;
> > +}
> >
> > -if (ctx->queue_count < ctx->queue_depth) {
> > +if (input_frame && ctx->queue_count < ctx->queue_depth) {
> >  ctx->frame_queue[ctx->queue_count++] = input_frame;
> >  if (ctx->queue_count < ctx->queue_depth) {
> >  // Need more reference surfaces before we can continue.
> > @@ -291,6 +299,8 @@ static int deint_vaapi_filter_frame(AVFilterLink
> *inlink,
> > AVFrame *input_frame)
> >  if (ctx->field_rate == 2) {
> >  if (field == 0)
> >  output_frame->pts = 2 * input_frame->pts;
> > +else if (ctx->eof)
> > +output_frame->pts = 3 * input_frame->pts -
> ctx->prev_pts;
> >  else
> >  output_frame->pts = input_frame->pts +
> >  ctx->frame_queue[current_frame_index + 1]->pts;
> > @@ -306,6 +316,8 @@ static int deint_vaapi_filter_frame(AVFilterLink
> *inlink,
> > AVFrame *input_frame)
> >  break;
> >  }
> >
> > +ctx->prev_pts = input_frame->pts;
> > +
> >  return err;
> >
> >  fail:
> > @@ -315,6 +327,25 @@ fail:
> >  return err;
> >  }
> >
> > +static int deint_vaapi_request_frame(AVFilterLink *link)
> > +{
> > +AVFilterContext *avctx = link->src;
> > +DeintVAAPIContext *ctx   = avctx->priv;
> > +int ret;
> > +
> > +if (ctx->eof)
> > +return AVERROR_EOF;
> > +
> > +ret = ff_request_frame(link->src->inputs[0]);
> > +if (ret == AVERROR_EOF) {
> > +ctx->eof = 1;
> > +deint_vaapi_filter_frame(link->src->inputs[0], NULL);
> > +} else if (ret < 0)
> > +return ret;
> > +
> > +return 0;
> > +}
> > +
> >  static av_cold int deint_vaapi_init(AVFilterContext *avctx)
> >  {
> >  VAAPIVPPContext *vpp_ctx = avctx->priv;
> > @@ -376,9 +407,10 @@ static const AVFilterPad deint_vaapi_inputs[] = {
> >
> >  static const AVFilterPad deint_vaapi_outputs[] = {
> >  {
> > -.name = "default",
> > -.type = AVMEDIA_TYPE_VIDEO,
> > -.config_props = &deint_vaapi_config_output,
> > +.name   = "default",
> > +.type   = AVMEDIA_TYPE_VIDEO,
> > +.request_frame  = &deint_vaapi_request_frame,
> > +.config_props   = &deint_vaapi_config_output,
> >  },
> >  { NULL }
> >  };
> > --
> > 2.7.4
> Ping.
>

LGTM


> ___
> 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.or

[FFmpeg-devel] [PATCH] avcodec/omx: add support for -force_key_frames

2019-08-21 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index a1e5a46a54..8c722b573c 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -802,6 +802,26 @@ static int omx_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 // Convert the timestamps to microseconds; some encoders can ignore
 // the framerate and do VFR bit allocation based on timestamps.
 buffer->nTimeStamp = to_omx_ticks(av_rescale_q(frame->pts, 
avctx->time_base, AV_TIME_BASE_Q));
+if (frame->pict_type == AV_PICTURE_TYPE_I) {
+#if CONFIG_OMX_RPI
+OMX_CONFIG_BOOLEANTYPE config = {0, };
+INIT_STRUCT(config);
+config.bEnabled = OMX_TRUE;
+err = OMX_SetConfig(s->handle, 
OMX_IndexConfigBrcmVideoRequestIFrame, &config);
+if (err != OMX_ErrorNone) {
+av_log(avctx, AV_LOG_ERROR, "OMX_SetConfig(RequestIFrame) 
failed: %x\n", err);
+}
+#else
+OMX_CONFIG_INTRAREFRESHVOPTYPE config = {0, };
+INIT_STRUCT(config);
+config.nPortIndex = s->out_port;
+config.IntraRefreshVOP = OMX_TRUE;
+err = OMX_SetConfig(s->handle, 
OMX_IndexConfigVideoIntraVOPRefresh, &config);
+if (err != OMX_ErrorNone) {
+av_log(avctx, AV_LOG_ERROR, "OMX_SetConfig(IntraVOPRefresh) 
failed: %x\n", err);
+}
+#endif
+}
 err = OMX_EmptyThisBuffer(s->handle, buffer);
 if (err != OMX_ErrorNone) {
 append_buffer(&s->input_mutex, &s->input_cond, 
&s->num_free_in_buffers, s->free_in_buffers, buffer);
-- 
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 1/8] avcodec/v4l2_m2m: log planar mode used by driver

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 427e165f58..7d65747df2 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -76,7 +76,9 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s)
 if (ret < 0)
 return ret;
 
-av_log(s->avctx, AV_LOG_INFO, "driver '%s' on card '%s'\n", cap.driver, 
cap.card);
+av_log(s->avctx, AV_LOG_INFO, "driver '%s' on card '%s' in %s mode\n", 
cap.driver, cap.card,
+   v4l2_mplane_video(&cap) ? "mplane" :
+   v4l2_splane_video(&cap) ? "splane" : 
"unknown");
 
 if (v4l2_mplane_video(&cap)) {
 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
-- 
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 4/8] avcodec/v4l2_m2m: remove trailing whitespace in output identifier

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 334ba0a038..746ae96a21 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -67,7 +67,7 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 
 s->capture.done = s->output.done = 0;
 s->capture.name = "capture";
-s->output.name = "output ";
+s->output.name = "output";
 atomic_init(&s->refcount, 0);
 sem_init(&s->refsync, 0, 0);
 
-- 
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 3/8] avcodec/v4l2_m2m: log requested pixel formats

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index be13f68707..334ba0a038 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -135,6 +135,7 @@ static int v4l2_configure_contexts(V4L2m2mContext* s)
 {
 void *log_ctx = s->avctx;
 int ret;
+struct v4l2_format ofmt, cfmt;
 
 s->fd = open(s->devname, O_RDWR | O_NONBLOCK, 0);
 if (s->fd < 0)
@@ -144,6 +145,16 @@ static int v4l2_configure_contexts(V4L2m2mContext* s)
 if (ret < 0)
 goto error;
 
+ofmt = s->output.format;
+cfmt = s->capture.format;
+av_log(log_ctx, AV_LOG_INFO, "requesting formats: output=%s capture=%s\n",
+ 
av_fourcc2str(V4L2_TYPE_IS_MULTIPLANAR(ofmt.type) ?
+   ofmt.fmt.pix_mp.pixelformat :
+   ofmt.fmt.pix.pixelformat),
+ 
av_fourcc2str(V4L2_TYPE_IS_MULTIPLANAR(cfmt.type) ?
+   cfmt.fmt.pix_mp.pixelformat :
+   cfmt.fmt.pix.pixelformat));
+
 ret = ff_v4l2_context_set_format(&s->output);
 if (ret) {
 av_log(log_ctx, AV_LOG_ERROR, "can't set v4l2 output format\n");
-- 
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 2/8] avcodec/v4l2_m2m: disable info logging during device probe

2019-08-22 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 7d65747df2..be13f68707 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(&cap) ? "mplane" :
-   v4l2_splane_video(&cap) ? "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(&cap) ? "mplane" :
+ v4l2_splane_video(&cap) ? "splane" : "unknown");
 
 if (v4l2_mplane_video(&cap)) {
 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;
 
@@ -139,7 +140,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 5/8] avcodec/v4l2_context: log VIDIOC_REQBUFS failures

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index efcb0426e4..4958c634bf 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -678,8 +678,10 @@ int ff_v4l2_context_init(V4L2Context* ctx)
 req.memory = V4L2_MEMORY_MMAP;
 req.type = ctx->type;
 ret = ioctl(s->fd, VIDIOC_REQBUFS, &req);
-if (ret < 0)
+if (ret < 0) {
+av_log(logger(ctx), AV_LOG_ERROR, "%s VIDIOC_REQBUFS failed: %s\n", 
ctx->name, strerror(errno));
 return AVERROR(errno);
+}
 
 ctx->num_buffers = req.count;
 ctx->buffers = av_mallocz(ctx->num_buffers * sizeof(V4L2Buffer));
-- 
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 8/8] avcodec/v4l2_buffers: Add handling for NV21 and YUV420P

2019-08-22 Thread Aman Gupta
From: Dave Stevenson 

The single planar support was for NV21 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 3f9b8b5e31..efbd84b0b3 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -348,11 +348,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 7/8] avcodec/v4l2_buffers: teach ff_v4l2_buffer_avframe_to_buf about contiguous planar formats

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 4f889509f9..3f9b8b5e31 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,41 @@ 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 is_planar_format = ((pixel_format >> 8) & 0xFF) == 'M'; // YU12 vs 
YM12, NV12 vs NM12, etc
 
-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]);
+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 = frame->height;
+if (i == 1 || i == 2) {
+h = AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h);
+}
+size = frame->linesize[i] * FFALIGN(h, 16);
+ret = v4l2_bufref_to_buf(out, 0, frame->buf[i]->data, 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, 0, frame->buf[i]);
 if (ret)
 return ret;
 }
 
-v4l2_set_pts(out, frame->pts);
-
 return 0;
 }
 
@@ -381,7 +408,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 2/4] avcodec/omx: add support for -force_key_frames

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index a1e5a46a54..8c722b573c 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -802,6 +802,26 @@ static int omx_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 // Convert the timestamps to microseconds; some encoders can ignore
 // the framerate and do VFR bit allocation based on timestamps.
 buffer->nTimeStamp = to_omx_ticks(av_rescale_q(frame->pts, 
avctx->time_base, AV_TIME_BASE_Q));
+if (frame->pict_type == AV_PICTURE_TYPE_I) {
+#if CONFIG_OMX_RPI
+OMX_CONFIG_BOOLEANTYPE config = {0, };
+INIT_STRUCT(config);
+config.bEnabled = OMX_TRUE;
+err = OMX_SetConfig(s->handle, 
OMX_IndexConfigBrcmVideoRequestIFrame, &config);
+if (err != OMX_ErrorNone) {
+av_log(avctx, AV_LOG_ERROR, "OMX_SetConfig(RequestIFrame) 
failed: %x\n", err);
+}
+#else
+OMX_CONFIG_INTRAREFRESHVOPTYPE config = {0, };
+INIT_STRUCT(config);
+config.nPortIndex = s->out_port;
+config.IntraRefreshVOP = OMX_TRUE;
+err = OMX_SetConfig(s->handle, 
OMX_IndexConfigVideoIntraVOPRefresh, &config);
+if (err != OMX_ErrorNone) {
+av_log(avctx, AV_LOG_ERROR, "OMX_SetConfig(IntraVOPRefresh) 
failed: %x\n", err);
+}
+#endif
+}
 err = OMX_EmptyThisBuffer(s->handle, buffer);
 if (err != OMX_ErrorNone) {
 append_buffer(&s->input_mutex, &s->input_cond, 
&s->num_free_in_buffers, s->free_in_buffers, buffer);
-- 
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 1/4] MAINTAINERS: add myself to OMX

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
Signed-off-by: Martin Storsjö 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 84dcb411f1..7f60ef0021 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -213,6 +213,7 @@ Codecs:
   msvideo1.cMike Melanson
   nuv.c Reimar Doeffinger
   nvdec*, nvenc*Timo Rothenpieler
+  omx.c Martin Storsjo, Aman Gupta
   opus* Rostislav Pehlivanov
   paf.* Paul B Mahol
   pcx.c Ivo van Poorten
-- 
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 4/4] avcodec/omx: Fix handling of fragmented buffers

2019-08-22 Thread Aman Gupta
From: Dave Stevenson 

See https://trac.ffmpeg.org/ticket/7687

If an encoded frame is returned split over two or more
IL buffers due to the size, then there is a race between
whether get_buffer will fail, return NULL, and a truncated
frame is passed on, or IL will return the remaining part
of the encoded frame.
If get_buffer returns NULL, part of the frame is left behind
in the codec, and will be collected on the next call. That
then leaves a frame stuck in the codec. Repeat enough times
and the codec FIFO is full, and the pipeline stalls.

A performance improvement in the Raspberry Pi firmware means
that the timing has changed, and now frequently drops into the
case where get_buffer returns NULL.

Add code such that should a buffer be received without
OMX_BUFFERFLAG_ENDOFFRAME that get_buffer is called with wait
set, so we wait for the remainder of the frame.
This code has been made conditional on the Pi build in case
other IL implementations don't handle ENDOFFRAME correctly.

Signed-off-by: Dave Stevenson 
Signed-off-by: Aman Gupta 
---
 libavcodec/omx.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index 1a9a0715f8..837f5df666 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -735,6 +735,7 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 int ret = 0;
 OMX_BUFFERHEADERTYPE* buffer;
 OMX_ERRORTYPE err;
+int had_partial = 0;
 
 if (frame) {
 uint8_t *dst[4];
@@ -846,7 +847,7 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 // packet, or get EOS.
 buffer = get_buffer(&s->output_mutex, &s->output_cond,
 &s->num_done_out_buffers, s->done_out_buffers,
-!frame);
+!frame || had_partial);
 if (!buffer)
 break;
 
@@ -881,6 +882,9 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 s->output_buf = NULL;
 s->output_buf_size = 0;
 }
+#if CONFIG_OMX_RPI
+had_partial = 1;
+#endif
 } else {
 // End of frame, and the caller provided a preallocated frame
 if ((ret = ff_alloc_packet2(avctx, pkt, s->output_buf_size + 
buffer->nFilledLen, 0)) < 0) {
-- 
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 3/4] avcodec/omx: ensure zerocopy mode can be disabled on rpi builds

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

fixes https://trac.ffmpeg.org/ticket/6586

Signed-off-by: Aman Gupta 
---
 libavcodec/omx.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index 8c722b573c..1a9a0715f8 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -644,10 +644,6 @@ static av_cold int omx_encode_init(AVCodecContext *avctx)
 OMX_BUFFERHEADERTYPE *buffer;
 OMX_ERRORTYPE err;
 
-#if CONFIG_OMX_RPI
-s->input_zerocopy = 1;
-#endif
-
 s->omx_context = omx_init(avctx, s->libname, s->libprefix);
 if (!s->omx_context)
 return AVERROR_ENCODER_NOT_FOUND;
@@ -933,7 +929,7 @@ static av_cold int omx_encode_end(AVCodecContext *avctx)
 static const AVOption options[] = {
 { "omx_libname", "OpenMAX library name", OFFSET(libname), 
AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
 { "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), 
AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
-{ "zerocopy", "Try to avoid copying input frames if possible", 
OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+{ "zerocopy", "Try to avoid copying input frames if possible", 
OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = CONFIG_OMX_RPI }, 0, 1, VE },
 { "profile",  "Set the encoding profile", OFFSET(profile), 
AV_OPT_TYPE_INT,   { .i64 = FF_PROFILE_UNKNOWN },   FF_PROFILE_UNKNOWN, 
FF_PROFILE_H264_HIGH, VE, "profile" },
 { "baseline", "", 0,   
AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_H264_BASELINE }, 0, 0, VE, "profile" },
 { "main", "", 0,   
AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_H264_MAIN }, 0, 0, VE, "profile" },
-- 
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 6/8] avcodec/v4l2_buffers: fix minor typos and whitespace

2019-08-22 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 libavcodec/v4l2_buffers.c | 4 ++--
 libavcodec/v4l2_buffers.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index aef911f3bb..4f889509f9 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -282,11 +282,11 @@ static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, 
const uint8_t* data, i
 
 /**
  *
- *  V4L2uffer interface
+ *  V4L2Buffer interface
  *
  
**/
 
-int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer* out)
+int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
 {
 int i, ret;
 
diff --git a/libavcodec/v4l2_buffers.h b/libavcodec/v4l2_buffers.h
index 7a57caf949..8dbc7fc104 100644
--- a/libavcodec/v4l2_buffers.h
+++ b/libavcodec/v4l2_buffers.h
@@ -106,7 +106,7 @@ int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, 
V4L2Buffer *out);
  *
  * @returns 0 in case of success, a negative AVERROR code otherwise
  */
-int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer* out);
+int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out);
 
 /**
  * Initializes a V4L2Buffer
-- 
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/videotoolbox_hevc: avoid leaking cached_hw_frames_ctx

2019-08-23 Thread Aman Gupta
On Wed, Aug 14, 2019 at 3:53 AM Pavel Koshevoy  wrote:

> On Tue, Aug 6, 2019 at 8:50 PM Pavel Koshevoy  wrote:
> >
> > vtctx->cached_hw_frames_ctx is unref'd in videotoolbox_uninit,
> > but videotoolbox_hevc used ff_videotoolbox_uninit which
> > doesn't unref cache_hw_frames_ctx.
> > ---
> >  libavcodec/videotoolbox.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> > index c718e82cc5..acaeef77dd 100644
> > --- a/libavcodec/videotoolbox.c
> > +++ b/libavcodec/videotoolbox.c
> > @@ -1143,7 +1143,7 @@ const AVHWAccel ff_hevc_videotoolbox_hwaccel = {
> >  .end_frame  = videotoolbox_hevc_end_frame,
> >  .frame_params   = videotoolbox_frame_params,
> >  .init   = videotoolbox_common_init,
> > -.uninit = ff_videotoolbox_uninit,
> > +.uninit = videotoolbox_uninit,
> >  .priv_data_size = sizeof(VTContext),
> >  };
> >
> > --
> > 2.16.4
> >
>
>
> Ping.  It's a 1-line leak fix ... is there any reason this should not
> be applied?
>

LGTM. Feel free to push it.


>
> Thank you,
> 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".
___
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/avpacket: fix whitespace

2018-10-11 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 002fa0f513..e160ad3033 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -580,10 +580,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 dst->side_data= NULL;
 dst->side_data_elems  = 0;
 for (i = 0; i < src->side_data_elems; i++) {
- enum AVPacketSideDataType type = src->side_data[i].type;
- int size  = src->side_data[i].size;
- uint8_t *src_data = src->side_data[i].data;
- uint8_t *dst_data = av_packet_new_side_data(dst, type, size);
+enum AVPacketSideDataType type = src->side_data[i].type;
+int size  = src->side_data[i].size;
+uint8_t *src_data = src->side_data[i].data;
+uint8_t *dst_data = av_packet_new_side_data(dst, type, size);
 
 if (!dst_data) {
 av_packet_free_side_data(dst);
-- 
2.15.2 (Apple Git-101.1)

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


[FFmpeg-devel] [PATCH 4/5] avcodec/cbs: fix crash in sei_pic_timestamp

2018-10-11 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index 32e6acd68e..106da0630e 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -584,6 +584,12 @@ static int FUNC(sei_pic_timestamp)(CodedBitstreamContext 
*ctx, RWContext *rw,
 }
 
 sps = h264->active_sps;
+if (!sps) {
+av_log(ctx->log_ctx, AV_LOG_ERROR,
+   "No active SPS for pic_timestamp.\n");
+return AVERROR_INVALIDDATA;
+}
+
 if (sps->vui.nal_hrd_parameters_present_flag)
 time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length;
 else if (sps->vui.vcl_hrd_parameters_present_flag)
-- 
2.15.2 (Apple Git-101.1)

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


[FFmpeg-devel] [PATCH 5/5] avcodec/cbs: ensure user_data is padded for GBC parsing

2018-10-11 Thread Aman Gupta
From: Aman Gupta 

Fixes crash noticed in the cbs_metadata patchset.

ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60926c89 at 
pc 0x00010725d37b bp 0x7ffeea04e750 sp 0x7ffeea04e748
READ of size 4 at 0x60926c89 thread T0
#0 0x10725d37a in ff_cbs_read_unsigned get_bits.h:274
#1 0x1072d2767 in ff_cbs_read_a53_user_data cbs_misc_syntax_template.c:119
#2 0x1078251a7 in h264_metadata_filter h264_metadata_bsf.c:595
#3 0x105c1321d in output_packet ffmpeg.c:853

0x60926c89 is located 1 bytes to the right of 8-byte region 
[0x60926c80,0x60926c88)
allocated by thread T0 here:
#0 0x10aef08d7 in wrap_posix_memalign 
(libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x578d7)
#1 0x10aca95e6 in av_malloc mem.c:87
#2 0x10ac545fe in av_buffer_allocz buffer.c:72
#3 0x107263b27 in cbs_h264_read_nal_unit cbs_h264_syntax_template.c:722
#4 0x10725b688 in cbs_read_fragment_content cbs.c:155

Signed-off-by: Aman Gupta 
---
 libavcodec/cbs_h264_syntax_template.c  | 2 +-
 libavcodec/cbs_mpeg2_syntax_template.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index 106da0630e..1c8d7d5eae 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -725,7 +725,7 @@ static int 
FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext
 *payload_size = i + current->data_length;
 #endif
 
-allocate(current->data, current->data_length);
+allocate(current->data, current->data_length + 
AV_INPUT_BUFFER_PADDING_SIZE);
 for (j = 0; j < current->data_length; j++)
 xu(8, itu_t_t35_payload_byte[i], current->data[j], 0x00, 0xff, 1, i + 
j);
 
diff --git a/libavcodec/cbs_mpeg2_syntax_template.c 
b/libavcodec/cbs_mpeg2_syntax_template.c
index 8b5d35437e..88cf453b17 100644
--- a/libavcodec/cbs_mpeg2_syntax_template.c
+++ b/libavcodec/cbs_mpeg2_syntax_template.c
@@ -71,7 +71,7 @@ static int FUNC(user_data)(CodedBitstreamContext *ctx, 
RWContext *rw,
 av_assert0(k % 8 == 0);
 current->user_data_length = k /= 8;
 if (k > 0) {
-current->user_data_ref = av_buffer_alloc(k);
+current->user_data_ref = av_buffer_allocz(k + 
AV_INPUT_BUFFER_PADDING_SIZE);
 if (!current->user_data_ref)
 return AVERROR(ENOMEM);
 current->user_data = current->user_data_ref->data;
-- 
2.15.2 (Apple Git-101.1)

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


[FFmpeg-devel] [PATCH 2/5] avcodec/cbs_h2645: fix crash due to assert failure on empty nalu

2018-10-11 Thread Aman Gupta
From: Aman Gupta 

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

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index ab33cdb69b..13e4c1561c 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -521,7 +521,8 @@ static int 
cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
 // Remove trailing zeroes.
 while (size > 0 && nal->data[size - 1] == 0)
 --size;
-av_assert0(size > 0);
+if (size == 0)
+continue;
 
 data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!data)
-- 
2.15.2 (Apple Git-101.1)

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


[FFmpeg-devel] [PATCH 3/5] avcodec/cbs_h264: silence errors about end_of_seq nalus

2018-10-11 Thread Aman Gupta
From: Aman Gupta 

[ffmpeg] AVBSFContext: Decomposition unimplemented for unit 4 (type 10).

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

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 13e4c1561c..2c7faf36e7 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -872,6 +872,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 }
 break;
 
+case H264_NAL_END_SEQUENCE:
+return 0;
+
 default:
 return AVERROR(ENOSYS);
 }
-- 
2.15.2 (Apple Git-101.1)

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


Re: [FFmpeg-devel] [PATCH 3/3] cbs_h2645: Allocate all internal buffers with padding

2018-10-16 Thread Aman Gupta
On Tue, Oct 16, 2018 at 2:08 PM Mark Thompson  wrote:

> Any of these buffers (for both H.264 and H.265) might reasonably be
> parsed using the bitstream reader, so include padding on all of them.
> ---
> This seems simpler than adding it to specific cases as problems are found.
>
>
Entire patchset looks great to me. Thanks for cleaning up my mess.

Aman


>
>  libavcodec/cbs_h2645.c| 3 ++-
>  libavcodec/cbs_h264_syntax_template.c | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index a1b92c87ce..e55bd00183 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -319,7 +319,8 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext
> *gbc)
>  #define byte_alignment(rw) (get_bits_count(rw) % 8)
>
>  #define allocate(name, size) do { \
> -name ## _ref = av_buffer_allocz(size); \
> +name ## _ref = av_buffer_allocz(size + \
> +AV_INPUT_BUFFER_PADDING_SIZE); \
>  if (!name ## _ref) \
>  return AVERROR(ENOMEM); \
>  name = name ## _ref->data; \
> diff --git a/libavcodec/cbs_h264_syntax_template.c
> b/libavcodec/cbs_h264_syntax_template.c
> index 7d0ce5918a..9e29132fec 100644
> --- a/libavcodec/cbs_h264_syntax_template.c
> +++ b/libavcodec/cbs_h264_syntax_template.c
> @@ -718,7 +718,7 @@ static int
> FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext
>  *payload_size = i + current->data_length;
>  #endif
>
> -allocate(current->data, current->data_length +
> AV_INPUT_BUFFER_PADDING_SIZE);
> +allocate(current->data, current->data_length);
>  for (j = 0; j < current->data_length; j++)
>  xu(8, itu_t_t35_payload_byte[i], current->data[j], 0x00, 0xff, 1,
> i + j);
>
> --
> 2.19.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/5] avcodec/cbs_h2645: fix crash due to assert failure on empty nalu

2018-10-25 Thread Aman Gupta
On Thu, Oct 11, 2018 at 10:03 PM myp...@gmail.com  wrote:

> On Fri, Oct 12, 2018 at 12:02 PM Aman Gupta  wrote:
> >
> > From: Aman Gupta 
> >
> > Signed-off-by: Aman Gupta 
> > ---
> >  libavcodec/cbs_h2645.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> > index ab33cdb69b..13e4c1561c 100644
> > --- a/libavcodec/cbs_h2645.c
> > +++ b/libavcodec/cbs_h2645.c
> > @@ -521,7 +521,8 @@ static int
> cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
> >  // Remove trailing zeroes.
> >  while (size > 0 && nal->data[size - 1] == 0)
> >  --size;
> > -av_assert0(size > 0);
> > +if (size == 0)
> > +continue;
> >
>  I think about this fix have a discussion.
> https://patchwork.ffmpeg.org/patch/8919/


Thanks for the link. It looks like this issue was resolved
in 9a09f4c54ab829811c2dd041cfb7196000590b78

I will backport commit that to the release/4.0 branch.

<https://patchwork.ffmpeg.org/patch/8919/>
> >  data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
> >  if (!data)
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/mediacodec: add av_mediacodec_render_buffer_at_time()

2018-10-25 Thread Aman Gupta
On Tue, Jul 31, 2018 at 6:34 PM Aman Gupta  wrote:

> From: Aman Gupta 
>
> The existing av_mediacodec_release_buffer allows the user to render
> or discard the Surface-backed frame. This new method allows the user
> to control exactly when the frame will be rendered to it's SurfaceView.
>
> Available since Android API 21.
>
> Signed-off-by: Aman Gupta 
> ---
>  doc/APIchanges  |  3 +++
>  libavcodec/mediacodec.c | 21 +
>  libavcodec/mediacodec.h | 13 +
>  libavcodec/mediacodec_wrapper.c |  2 +-
>  libavcodec/version.h|  2 +-
>  5 files changed, 39 insertions(+), 2 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index efe15ba4e0..62394fd837 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>
>  API changes, most recent first:
>
> +2018-08-01 - xx - lavc 58.23.100 - mediacodec.h
> +  Add av_mediacodec_render_buffer_at_time().
> +
>  2018-05-xx - xx - lavf 58.15.100 - avformat.h
>Add pmt_version field to AVProgram
>
> diff --git a/libavcodec/mediacodec.c b/libavcodec/mediacodec.c
> index b0aae43a87..aa14624fd0 100644
> --- a/libavcodec/mediacodec.c
> +++ b/libavcodec/mediacodec.c
> @@ -102,6 +102,22 @@ int av_mediacodec_release_buffer(AVMediaCodecBuffer
> *buffer, int render)
>  return 0;
>  }
>
> +int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer,
> int64_t time)
> +{
> +MediaCodecDecContext *ctx = buffer->ctx;
> +int released = atomic_fetch_add(&buffer->released, 1);
> +
> +if (!released && (ctx->delay_flush || buffer->serial ==
> atomic_load(&ctx->serial))) {
> +atomic_fetch_sub(&ctx->hw_buffer_count, 1);
> +av_log(ctx->avctx, AV_LOG_DEBUG,
> +   "Rendering output buffer %zd (%p) ts=%"PRId64" with
> time=%"PRId64" [%d pending]\n",
> +   buffer->index, buffer, buffer->pts, time,
> atomic_load(&ctx->hw_buffer_count));
> +return ff_AMediaCodec_releaseOutputBufferAtTime(ctx->codec,
> buffer->index, time);
> +}
> +
> +return 0;
> +}
> +
>  #else
>
>  #include 
> @@ -125,4 +141,9 @@ int av_mediacodec_release_buffer(AVMediaCodecBuffer
> *buffer, int render)
>  return AVERROR(ENOSYS);
>  }
>
> +int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer,
> int64_t time)
> +{
> +return AVERROR(ENOSYS);
> +}
> +
>  #endif
> diff --git a/libavcodec/mediacodec.h b/libavcodec/mediacodec.h
> index 5606d24a1e..4c8545df03 100644
> --- a/libavcodec/mediacodec.h
> +++ b/libavcodec/mediacodec.h
> @@ -85,4 +85,17 @@ typedef struct MediaCodecBuffer AVMediaCodecBuffer;
>   */
>  int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render);
>
> +/**
> + * Release a MediaCodec buffer and render it at the given time to the
> surface
> + * that is associated with the decoder. The timestamp must be within one
> second
> + * of the current java/lang/System#nanoTime() (which is implemented using
> + * CLOCK_MONOTONIC on Android). See the Android MediaCodec documentation
> + * of android/media/MediaCodec#releaseOutputBuffer(int,long) for more
> details.
> + *
> + * @param buffer the buffer to render
> + * @param time timestamp in nanoseconds of when to render the buffer
> + * @return 0 on success, < 0 otherwise
> + */
> +int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer,
> int64_t time);
> +
>  #endif /* AVCODEC_MEDIACODEC_H */
> diff --git a/libavcodec/mediacodec_wrapper.c
> b/libavcodec/mediacodec_wrapper.c
> index c47c2c9a41..a024e3bdb1 100644
> --- a/libavcodec/mediacodec_wrapper.c
> +++ b/libavcodec/mediacodec_wrapper.c
> @@ -1432,7 +1432,7 @@ int
> ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, i
>
>  JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
>
> -(*env)->CallVoidMethod(env, codec->object,
> codec->jfields.release_output_buffer_at_time_id, (jint)idx, timestampNs);
> +(*env)->CallVoidMethod(env, codec->object,
> codec->jfields.release_output_buffer_at_time_id, (jint)idx,
> (jlong)timestampNs);
>  if (ff_jni_exception_check(env, 1, codec) < 0) {
>  ret = AVERROR_EXTERNAL;
>  goto fail;
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 3f0d98efdf..a91e5f01e6 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -28,7 +28,7 @@
>  #include "libavutil/version.h"
>
>  #define LIBAVCODEC_VERSION_MAJOR  58
> -#define LIBAVCODEC_VERSION_MINOR  22
> +#define LIBAVCODEC_VERSION_MINOR  23
>  #define LIBAVCODEC_VERSION_MICRO 100
>
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
>

Updated diff to use 58.33.100 and pushed to master.


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


Re: [FFmpeg-devel] [PATCH v2] avcodec: Add MediaFoundation encoder wrapper

2020-05-18 Thread Aman Gupta
On Fri, May 15, 2020 at 12:04 AM Martin Storsjö  wrote:

> On Tue, 12 May 2020, Martin Storsjö wrote:
>
> > From: wm4 
> >
> > This contains encoder wrappers for H264, HEVC, AAC, AC3 and MP3.
> >
> > This is based on top of an original patch by wm4
> > . The original patch supported both encoding
> > and decoding, but this patch only includes encoding.
> >
> > The patch contains further changes by Paweł Wegner
> >  (primarily for splitting out the encoding
> > parts of the original patch) and further cleanup, build compatibility
> > fixes and tweaks for use with Qualcomm encoders by Martin Storsjö.
> > ---
> > v2: Added AV_CODEC_CAP_HYBRID, removed a leftover unused AVBSFContext,
> > added changelog and encoders.text entries, renamed the configure option
> > and config item to "mediafoundation" instead of "mf", changed the
> > makefile to keep individual additions of object files for each
> > individual encoder (so that it isn't compiled if all encoders are
> > disabled, even if CONFIG_MEDIAFOUNDATION is enabled).
>
> Any further comments on this, or is it ok to be merged now?


+1 from me. We have been using the original patchset for quite a few years
now, and it will make things much easier if it is included upstream.

For encoding video, we found the mf apis work much more reliably across
different hardware (and versions of Windows) compared to using qsv directly.

Aman


>
> // Martin
> ___
> 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] [PATCH] MAINTAINERS: add myself to V4L2

2019-08-29 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
Signed-off-by: Jorge Ramirez-Ortiz 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7f60ef0021..f83d543321 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -243,7 +243,7 @@ Codecs:
   tta.c Alex Beregszaszi, Jaikrishnan Menon
   ttaenc.c  Paul B Mahol
   txd.c Ivo van Poorten
-  v4l2_*Jorge Ramirez-Ortiz
+  v4l2_*Jorge Ramirez-Ortiz, Aman Gupta
   vc2*  Rostislav Pehlivanov
   vcr1.cMichael Niedermayer
   videotoolboxenc.c Rick Kern, Aman Gupta
-- 
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] avcodec/omx: fix xFramerate calculation

2019-08-29 Thread Aman Gupta
From: Aman Gupta 

Integer overflow in the Q16 framerate calculation was sending
invalid values to the OMX encoder.

On the RPI4, this manifested as bitrate controls being ignored
on video streams with 6/1001 framerates. Video streams with
3/1001 framerates were not affected.

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

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index 837f5df666..c745860242 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -473,9 +473,9 @@ static av_cold int omx_component_init(AVCodecContext 
*avctx, const char *role)
 in_port_params.format.video.nFrameWidth  = avctx->width;
 in_port_params.format.video.nFrameHeight = avctx->height;
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0)
-in_port_params.format.video.xFramerate = (1 << 16) * 
avctx->framerate.num / avctx->framerate.den;
+in_port_params.format.video.xFramerate = (int64_t)(1 << 16) * 
avctx->framerate.num / avctx->framerate.den;
 else
-in_port_params.format.video.xFramerate = (1 << 16) * 
avctx->time_base.den / avctx->time_base.num;
+in_port_params.format.video.xFramerate = (int64_t)(1 << 16) * 
avctx->time_base.den / avctx->time_base.num;
 
 err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, 
&in_port_params);
 CHECK(err);
-- 
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/omx: fix xFramerate calculation

2019-08-29 Thread Aman Gupta
On Thu, Aug 29, 2019 at 5:56 PM Limin Wang  wrote:

> On Thu, Aug 29, 2019 at 05:30:25PM -0700, Aman Gupta wrote:
> > From: Aman Gupta 
> >
> > Integer overflow in the Q16 framerate calculation was sending
> > invalid values to the OMX encoder.
> >
> > On the RPI4, this manifested as bitrate controls being ignored
> > on video streams with 6/1001 framerates. Video streams with
> > 3/1001 framerates were not affected.
> >
> > Signed-off-by: Aman Gupta 
> > ---
> >  libavcodec/omx.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/omx.c b/libavcodec/omx.c
> > index 837f5df666..c745860242 100644
> > --- a/libavcodec/omx.c
> > +++ b/libavcodec/omx.c
> > @@ -473,9 +473,9 @@ static av_cold int omx_component_init(AVCodecContext
> *avctx, const char *role)
> >  in_port_params.format.video.nFrameWidth  = avctx->width;
> >  in_port_params.format.video.nFrameHeight = avctx->height;
> >  if (avctx->framerate.den > 0 && avctx->framerate.num > 0)
> > -in_port_params.format.video.xFramerate = (1 << 16) *
> avctx->framerate.num / avctx->framerate.den;
> > +in_port_params.format.video.xFramerate = (int64_t)(1 << 16) *
> avctx->framerate.num / avctx->framerate.den;
>
> change 1 > 1LL is more simple to solve the overflow.
>

Great, thank you for the tip! Updated my local patch accordingly.



>
>
> >  else
> > -in_port_params.format.video.xFramerate = (1 << 16) *
> avctx->time_base.den / avctx->time_base.num;
> > +in_port_params.format.video.xFramerate = (int64_t)(1 << 16) *
> avctx->time_base.den / avctx->time_base.num;
> >
> >  err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition,
> &in_port_params);
> >  CHECK(err);
> > --
> > 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".
___
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] MAINTAINERS: add myself to V4L2

2019-08-29 Thread Aman Gupta
On Thu, Aug 29, 2019 at 2:47 PM Jorge Ramirez 
wrote:

> On 8/29/19 22:23, Aman Gupta wrote:
> > From: Aman Gupta 
>
>
> lets discuss this a bit further. I havent been very active in the past
> due to personal reasons and there might be others willing to take on
> full maintanership with perhaps more experience or time to dedicate.
>

Sure. If anyone else has an interest in or is using v4l2, there are several
patches on the list (and in the libreelec fork) that could use review and
testing. If not, I am volunteering my time to getting these patches
upstreamed in a reasonable way.


>
> there is plenty to do on v4l2 (the pending DRM patch and the stateless
> API integration to name a couple).
>

I have rebased the DRM patch onto my current set, and adapted it to better
integrate with hwcontext here:
https://github.com/tmm1/FFmpeg/compare/v4l2-rpi-drm


>
>
> >
> > Signed-off-by: Aman Gupta 
>
> also please do not add my signoff (I can add it when needed)
>

Sorry about that. I only meant to indicate that we had discussed this
off-list and that you were open to help with maintenance.


> > Signed-off-by: Jorge Ramirez-Ortiz 
>
>
>
> > ---
> >  MAINTAINERS | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 7f60ef0021..f83d543321 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -243,7 +243,7 @@ Codecs:
> >tta.c Alex Beregszaszi, Jaikrishnan
> Menon
> >ttaenc.c  Paul B Mahol
> >txd.c Ivo van Poorten
> > -  v4l2_*Jorge Ramirez-Ortiz
> > +  v4l2_*Jorge Ramirez-Ortiz, Aman Gupta
> >vc2*      Rostislav Pehlivanov
> >vcr1.cMichael Niedermayer
> >videotoolboxenc.c Rick Kern, Aman Gupta
>
>
>
___
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/omx: fix xFramerate calculation

2019-08-30 Thread Aman Gupta
On Thu, Aug 29, 2019 at 10:30 PM Nicolas George  wrote:

> Aman Gupta (12019-08-29):
> > > > -in_port_params.format.video.xFramerate = (1 << 16) *
> > > avctx->framerate.num / avctx->framerate.den;
> > > > +in_port_params.format.video.xFramerate = (int64_t)(1 << 16)
> *
> > > avctx->framerate.num / avctx->framerate.den;
> > >
> > > change 1 > 1LL is more simple to solve the overflow.
> >
> > Great, thank you for the tip! Updated my local patch accordingly.
>
> This remark looks weird: using long long directly is almost never
> correct code.
>
> And in this particular case, av_rescale_q() seems the correct choice.
>

The OMX spec requires xFramerate in Q16 format, which is basically
(framerate<<16)

I'm not sure how I would use av_rescale_q to achieve this.


>
> Regards,
>
> --
>   Nicolas George
> ___
> 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] 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] [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 = &v4l2_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 = &v4l2_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".

[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, &frame->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, &frame->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 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 = &s->capture;
 V4L2Context *const output = &s->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(&s->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(&priv->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(&s->refcount))
+while(sem_wait(&s->refsync) == -1 && errno == EINTR);
+
+ret = ff_v4l2_context_set_status(&s->output, VIDIOC_STREAMOFF);
+if (ret)
+av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->output.name);
+
+ret = ff_v4l2_context_set_status(&s->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_

[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(&s->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 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 = &avbuf->drm_frame;
+AVDRMLayerDescriptor *layer;
+
+/* fill the DRM frame descriptor */
+drm_desc->nb_objects = avbuf->num_planes;
+drm_desc->nb_layers = 1;
+
+layer = &drm_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(&expbuf, 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, &expbuf);
+if (ret < 0)
+return AVERROR(errno);
+
+if (V4L2_TYPE_IS_MULTIPLANAR(avbuf->buf.ty

[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(&avpkt);
-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, &avpkt);
-if (ret < 0 && ret != AVERROR_EOF)
-return ret;
+if (s->buf_pkt.size) {
+avpkt = s->buf_pkt;
+memset(&s->buf_pkt, 0, sizeof(AVPacket));
+} else {
+ret = ff_decode_get_packet(avctx, &avpkt);
+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(&avpkt);
+if (!s->buf_pkt.size)
+av_packet_unref(&avpkt);
 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(&s->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(&in->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 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(&cropcap, 0, sizeof(cropcap));
+cropcap.type = ctx->type;
+
+ret = ioctl(ctx_to_m2mctx(ctx)->fd, VIDIOC_CROPCAP, &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 = &ctx->format;
@@ -177,12 +195,14 @@ static int v4l2_handle_event(V4L2Context *ctx)
 if (full_reinit) {
 s->output.height = v4l2_get_height(&out_fmt);
 s->output.width = v4l2_get_width(&out_fmt);
+s->output.sample_aspect_ratio = v4l2_get_sar(&s->output);
 }
 
 reinit = v4l2_resolution_changed(&s->capture, &cap_fmt);
 if (reinit) {
 s->capture.height = v4l2_get_height(&cap_fmt);
 s->capture.width = v4l2_get_width(&cap_fmt);
+s->capture.sample_aspect_ratio = v4l2_get_sar(&s->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 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,

[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 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 = &v4l2_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 = &v4l2_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 san

[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 = &s->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 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(&cap) ? "mplane" :
  v4l2_splane_video(&cap) ? "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(&s->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(&s->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(&s->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. 

[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, &fmt);
 
 /* 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(&s->output);
+ret = ff_v4l2_context_get_format(&s->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(&s->capture);
+ret = ff_v4l2_context_get_format(&s->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(&s->capture);
 
 /* 3. get the new capture format */
-ret = ff_v4l2_context_get_format(&s->capture);
+ret = ff_v4l2_context_get_format(&s->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(&s->output);
+ret = ff_v4l2_context_get_format(&s->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(&s->capture);
+ret = ff_v4l2_context_get_format(&s->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(&cap) ? "mplane" :
-   v4l2_splane_video(&cap) ? "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(&cap) ? "mplane" :
+ v4l2_splane_video(&cap) ? "splane" : "unknown");
 
 if (v4l2_mplane_video(&cap)) {
 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 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 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 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".

Re: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: fix encoding frame crash on iOS 11

2019-09-03 Thread Aman Gupta
On Mon, Aug 12, 2019 at 11:50 PM sharpbai  wrote:

> On iOS 11, encoding a frame may return error with log
> "Error encoding frame 0", which means vtenc_output_callback
> is called with status=0 and sample_buffer=NULL. Then the
> encoding session will be crashed on next callback wether or not
> closing the codec context.
>
> Let us look through the link below introducing VTCompressionOutputCallback,
>
>
> https://developer.apple.com/documentation/videotoolbox/vtcompressionoutputcallback?language=objc
>
> "status=0" (noErr) means compression was successful.
> "sampleBuffer=NULL" means the frame was dropped when compression
> was successful (status=0) or compression was not successful (status!=0).
>
> So we should not set AVERROR_EXTERNAL on "status=0" and
> "sample_buffer=NULL"
> as it is not a error.
>
> The fix is that we only set AVERROR_EXTERNAL with status value non zero.
> When sample_buffer is NULL and status value is zero, we simply return
> with no other operation.
>
> This crash often occurs on iOS 11 for example encoding 720p@25fps.
>

Is it fixed in iOS 12, or untested there?


>
> Signed-off-by: sharpbai 
> ---
>  libavcodec/videotoolboxenc.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index d76bb7f646..8afdd125d2 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -569,12 +569,16 @@ static void vtenc_output_callback(
>  return;
>  }
>
> -if (status || !sample_buffer) {
> +if (status) {
>  av_log(avctx, AV_LOG_ERROR, "Error encoding frame: %d\n",
> (int)status);
>  set_async_error(vtctx, AVERROR_EXTERNAL);
>  return;
>  }
>
> +if (!sample_buffer) {
> +return;
> +}
> +
>  if (!avctx->extradata && (avctx->flags &
> AV_CODEC_FLAG_GLOBAL_HEADER)) {
>  int set_status = set_extradata(avctx, sample_buffer);
>  if (set_status) {
> --
> 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".

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

2019-09-04 Thread Aman Gupta
On Wed, Sep 4, 2019 at 9:40 AM Alexis Ballier  wrote:

> On Mon,  2 Sep 2019 18:02:10 -0700
> Aman Gupta  wrote:
> [...]
> > @@ -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;
> > +}
>
>
> can't this be inlined as 'int is_planar_format =
> V4L2_TYPE_IS_MULTIPLANAR(fmt.type)' as done 2 lines above ?
>

Unfortunately not.

That macro differentiates between the original splane v4l2 api vs the newer
mplane api.

But even if you're using the newer api, it still support contiguous planar
formats (YUV420 vs YUV420M).

So the macro decides which fields in the struct to use (pix vs pix_mp), and
then the pixel format itself decides if the planes are contiguous in memory
or stored in separate buffers.

Aman




>
> [...]
>
>
> Alexis.
>
___
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 2/2] configure: fix --disable-v4l2-m2m can't work

2019-09-04 Thread Aman Gupta
On Wed, Sep 4, 2019 at 4:49 AM Jun Zhao  wrote:

> From: Jun Zhao 
>
> Use the command ./configure with/without --disable-v4l2-m2m test.
>
> Signed-off-by: Jun Zhao 
> ---
>  configure |   28 +++-
>  1 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/configure b/configure
> index 3ef8f4e..4141c1e 100755
> --- a/configure
> +++ b/configure
> @@ -6446,19 +6446,21 @@ pod2man --help > /dev/null 2>&1 && enable
> pod2man   || disable pod2man
>  rsync --help 2> /dev/null | grep -q 'contimeout' && enable
> rsync_contimeout || disable rsync_contimeout
>
>  # check V4L2 codecs available in the API
> -check_headers linux/fb.h
> -check_headers linux/videodev2.h
> -test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse;
> vfse.discrete.width = 0;" && enable_sanitized
> struct_v4l2_frmivalenum_discrete
> -check_cc v4l2_m2m linux/videodev2.h "int i = V4L2_CAP_VIDEO_M2M_MPLANE |
> V4L2_CAP_VIDEO_M2M | V4L2_BUF_FLAG_LAST;"
> -check_cc vc1_v4l2_m2m linux/videodev2.h "int i =
> V4L2_PIX_FMT_VC1_ANNEX_G;"
> -check_cc mpeg1_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG1;"
> -check_cc mpeg2_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG2;"
> -check_cc mpeg4_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG4;"
> -check_cc hevc_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_HEVC;"
> -check_cc h263_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H263;"
> -check_cc h264_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H264;"
> -check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
> -check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
> +if enabled v4l2_m2m; then
> +check_headers linux/fb.h
> +check_headers linux/videodev2.h
> +test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse;
> vfse.discrete.width = 0;" && enable_sanitized
> struct_v4l2_frmivalenum_discrete
> +check_cc v4l2_m2m linux/videodev2.h "int i =
> V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_VIDEO_M2M | V4L2_BUF_FLAG_LAST;"
> +check_cc vc1_v4l2_m2m linux/videodev2.h "int i =
> V4L2_PIX_FMT_VC1_ANNEX_G;"
> +check_cc mpeg1_v4l2_m2m linux/videodev2.h "int i =
> V4L2_PIX_FMT_MPEG1;"
> +check_cc mpeg2_v4l2_m2m linux/videodev2.h "int i =
> V4L2_PIX_FMT_MPEG2;"
> +check_cc mpeg4_v4l2_m2m linux/videodev2.h "int i =
> V4L2_PIX_FMT_MPEG4;"
> +check_cc hevc_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_HEVC;"
> +check_cc h263_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H263;"
> +check_cc h264_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_H264;"
> +check_cc vp8_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;"
> +check_cc vp9_v4l2_m2m linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;"
> +fi
>
>
Looks reasonable to me.


>  check_headers sys/videoio.h
>  test_code cc sys/videoio.h "struct v4l2_frmsizeenum vfse;
> vfse.discrete.width = 0;" && enable_sanitized
> struct_v4l2_frmivalenum_discrete
> --
> 1.7.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".

[FFmpeg-devel] [PATCH 4/6] avcodec/mediacodecdec_common: improve trace logging for end-of-stream

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

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

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index eae9c28d42..c538a00775 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -632,7 +632,7 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 }
 
 av_log(avctx, AV_LOG_TRACE,
-   "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, 
size, pts);
+   "Queued empty EOS input buffer %zd with flags=%d\n", index, 
flags);
 
 s->draining = 1;
 return 0;
-- 
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 6/6] avcodec/mediacodecdec_common: propagate EOF immediately when signaled by decoder

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

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

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index b9465244a3..ab8525fb14 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -693,6 +693,7 @@ int ff_mediacodec_dec_receive(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 
 if (info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec)) {
 s->eos = 1;
+return AVERROR_EOF;
 }
 
 if (info.size) {
-- 
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 2/6] avcodec/mediacodecdec: warn when input buffers are not configured with proper size

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

In rare circumstances, if the codec is not configured with the
proper parameters the input buffers can be allocated with a size
that's too small to hold an individual packet. Since MediaCodec
expects exactly one incoming buffer with a given PTS, it is not
valid to split data for a given PTS across two input buffers.

See 
https://developer.android.com/reference/android/media/MediaCodec#data-processing:

  > Do not submit multiple input buffers with the same timestamp

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

diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index e353e34bd5..f5771bffb1 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -440,8 +440,13 @@ static int mediacodec_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret >= 0) {
 s->buffered_pkt.size -= ret;
 s->buffered_pkt.data += ret;
-if (s->buffered_pkt.size <= 0)
+if (s->buffered_pkt.size <= 0) {
 av_packet_unref(&s->buffered_pkt);
+} else {
+av_log(avctx, AV_LOG_WARNING,
+   "could not send entire packet in single input 
buffer (%d < %d)\n",
+   ret, s->buffered_pkt.size+ret);
+}
 } else if (ret < 0 && ret != AVERROR(EAGAIN)) {
 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 3/6] avcodec/mediacodecdec_common: warn when PTS is missing

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

MediaCodec decoders require PTS for proper operation.

Signed-off-by: Aman Gupta 
---
 libavcodec/mediacodecdec_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index 1656cd6664..eae9c28d42 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -612,7 +612,11 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 }
 
 pts = pkt->pts;
-if (pts != AV_NOPTS_VALUE && avctx->pkt_timebase.num && 
avctx->pkt_timebase.den) {
+if (pts == AV_NOPTS_VALUE) {
+av_log(avctx, AV_LOG_WARNING, "Packet is missing PTS!\n");
+pts = 0;
+}
+if (pts && avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
 pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
 }
 
-- 
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 1/6] avcodec/mediacodec_surface: guard against NULL surface

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

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

diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
index aada1ecebe..efcc4dc63c 100644
--- a/libavcodec/mediacodec_surface.c
+++ b/libavcodec/mediacodec_surface.c
@@ -28,9 +28,11 @@
 void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
 {
 JNIEnv *env = NULL;
-
 void *reference = NULL;
 
+if (!surface)
+return NULL;
+
 env = ff_jni_get_env(log_ctx);
 if (!env) {
 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 5/6] avcodec/mediacodecdec_common: ensure current input buffer is always used correctly

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

The loop may mutate the input buffer, so re-fetch it to ensure
the current one is always used.

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

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index c538a00775..b9465244a3 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -569,7 +569,6 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 int offset = 0;
 int need_draining = 0;
 uint8_t *data;
-ssize_t index = s->current_input_buffer;
 size_t size;
 FFAMediaCodec *codec = s->codec;
 int status;
@@ -591,6 +590,7 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 }
 
 while (offset < pkt->size || (need_draining && !s->draining)) {
+ssize_t index = s->current_input_buffer;
 if (index < 0) {
 index = ff_AMediaCodec_dequeueInputBuffer(codec, 
input_dequeue_timeout_us);
 if (ff_AMediaCodec_infoTryAgainLater(codec, index)) {
-- 
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 1/2] avcodec/mediacodecdec_common: log codec name during configure/start failures

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

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

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index ab8525fb14..d200372dd4 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -525,8 +525,8 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 if (status < 0) {
 char *desc = ff_AMediaFormat_toString(format);
 av_log(avctx, AV_LOG_ERROR,
-"Failed to configure codec (status = %d) with format %s\n",
-status, desc);
+"Failed to configure codec %s (status = %d) with format %s\n",
+s->codec_name, status, desc);
 av_freep(&desc);
 
 ret = AVERROR_EXTERNAL;
@@ -537,8 +537,8 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 if (status < 0) {
 char *desc = ff_AMediaFormat_toString(format);
 av_log(avctx, AV_LOG_ERROR,
-"Failed to start codec (status = %d) with format %s\n",
-status, desc);
+"Failed to start codec %s (status = %d) with format %s\n",
+s->codec_name, status, desc);
 av_freep(&desc);
 ret = AVERROR_EXTERNAL;
 goto fail;
-- 
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 2/2] avcodec/mediacodec_surface: define and use FFANativeWindow to mimic NDK interface

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

This will make it easy to switch to ANativeWindow_fromSurface
and ANativeWindow_release in the future.

Signed-off-by: Aman Gupta 
---
 libavcodec/mediacodec_surface.c | 11 ---
 libavcodec/mediacodec_surface.h |  7 +--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
index efcc4dc63c..a292386e34 100644
--- a/libavcodec/mediacodec_surface.c
+++ b/libavcodec/mediacodec_surface.c
@@ -25,10 +25,9 @@
 #include "ffjni.h"
 #include "mediacodec_surface.h"
 
-void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
+FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
 {
 JNIEnv *env = NULL;
-void *reference = NULL;
 
 if (!surface)
 return NULL;
@@ -38,12 +37,10 @@ void *ff_mediacodec_surface_ref(void *surface, void 
*log_ctx)
 return NULL;
 }
 
-reference = (*env)->NewGlobalRef(env, surface);
-
-return reference;
+return (*env)->NewGlobalRef(env, surface);
 }
 
-int ff_mediacodec_surface_unref(void *surface, void *log_ctx)
+int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
 {
 JNIEnv *env = NULL;
 
@@ -52,7 +49,7 @@ int ff_mediacodec_surface_unref(void *surface, void *log_ctx)
 return AVERROR_EXTERNAL;
 }
 
-(*env)->DeleteGlobalRef(env, surface);
+(*env)->DeleteGlobalRef(env, window);
 
 return 0;
 }
diff --git a/libavcodec/mediacodec_surface.h b/libavcodec/mediacodec_surface.h
index 0178b8ae71..933dc2bf51 100644
--- a/libavcodec/mediacodec_surface.h
+++ b/libavcodec/mediacodec_surface.h
@@ -25,7 +25,10 @@
 
 #include "libavcodec/avcodec.h"
 
-void *ff_mediacodec_surface_ref(void *surface, void *log_ctx);
-int ff_mediacodec_surface_unref(void *surface, void *log_ctx);
+struct FFANativeWindow;
+typedef struct FFANativeWindow FFANativeWindow;
+
+FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *log_ctx);
+int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx);
 
 #endif /* AVCODEC_MEDIACODEC_SURFACE_H */
-- 
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] lavc/videotoolboxdec: fix crop handling when multithreaded

2019-09-06 Thread Aman Gupta
On Fri, Sep 6, 2019 at 8:37 PM Rodger Combs  wrote:

> This was partially fixed by 233cd89, but it made changes to AVFrame fields
> from within end_frame, which doesn't work consistently when multithreading
> is enabled. This is what the post_process function is for.


Looks good to me.


> ---
>  libavcodec/videotoolbox.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index c718e82cc5..7948d21bcc 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -91,6 +91,11 @@ static int videotoolbox_postproc_frame(void *avctx,
> AVFrame *frame)
>  return AVERROR_EXTERNAL;
>  }
>
> +frame->crop_right = 0;
> +frame->crop_left = 0;
> +frame->crop_top = 0;
> +frame->crop_bottom = 0;
> +
>  frame->data[3] = (uint8_t*)ref->pixbuf;
>
>  if (ref->hw_frames_ctx) {
> @@ -898,11 +903,6 @@ static int
> videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
>  AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
>  VTContext *vtctx = avctx->internal->hwaccel_priv_data;
>
> -frame->crop_right = 0;
> -frame->crop_left = 0;
> -frame->crop_top = 0;
> -frame->crop_bottom = 0;
> -
>  if (vtctx->reconfig_needed == true) {
>  vtctx->reconfig_needed = false;
>  av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox decoder needs
> reconfig, restarting..\n");
> --
> 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] [RFC PATCH] avfilter/fastdeint: import simple cpu-optimized deinterlacing algorithms from VLC

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

These are simple algorithms which can be run efficiently
on low powered devices to produce deinteraced images.

Signed-off-by: Aman Gupta 
---
 doc/filters.texi |  27 ++
 libavfilter/Makefile |   1 +
 libavfilter/aarch64/Makefile |   1 +
 libavfilter/aarch64/merge_neon.S |  98 ++
 libavfilter/allfilters.c |   1 +
 libavfilter/arm/Makefile |   3 +
 libavfilter/arm/merge_armv6.S|  70 
 libavfilter/arm/merge_neon.S | 109 ++
 libavfilter/vf_fastdeint.c   | 588 +++
 9 files changed, 898 insertions(+)
 create mode 100644 libavfilter/aarch64/merge_neon.S
 create mode 100644 libavfilter/arm/Makefile
 create mode 100644 libavfilter/arm/merge_armv6.S
 create mode 100644 libavfilter/arm/merge_neon.S
 create mode 100644 libavfilter/vf_fastdeint.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 6c81e1da40..55d9adeb81 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9796,6 +9796,33 @@ fade=t=in:st=5.5:d=0.5
 
 @end itemize
 
+@section fastdeint
+Fast deinterlacing algorithms.
+
+@table @option
+@item mode
+Deinterlacing algorithm to use.
+
+It accepts the following values:
+@table @samp
+@item discard
+Discard bottom frame.
+
+@item mean
+Half resolution blender.
+
+@item blend
+Full resolution blender.
+
+@item bob
+Bob doubler.
+
+@item linear
+Bob doubler with linear interpolation.
+@end table
+
+@end table
+
 @section fftdnoiz
 Denoise frames using 3D FFT (frequency domain filtering).
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 3ef4191d9a..a2b3566ec0 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -234,6 +234,7 @@ OBJS-$(CONFIG_EROSION_OPENCL_FILTER) += 
vf_neighbor_opencl.o opencl.o \
 opencl/neighbor.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)  += vf_extractplanes.o
 OBJS-$(CONFIG_FADE_FILTER)   += vf_fade.o
+OBJS-$(CONFIG_FASTDEINT_FILTER)  += vf_fastdeint.o
 OBJS-$(CONFIG_FFTDNOIZ_FILTER)   += vf_fftdnoiz.o
 OBJS-$(CONFIG_FFTFILT_FILTER)+= vf_fftfilt.o
 OBJS-$(CONFIG_FIELD_FILTER)  += vf_field.o
diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
index b58daa3a3f..2b0ad92893 100644
--- a/libavfilter/aarch64/Makefile
+++ b/libavfilter/aarch64/Makefile
@@ -1,3 +1,4 @@
 OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/vf_nlmeans_init.o
 
+NEON-OBJS-$(CONFIG_FASTDEINT_FILTER) += aarch64/merge_neon.o
 NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/vf_nlmeans_neon.o
diff --git a/libavfilter/aarch64/merge_neon.S b/libavfilter/aarch64/merge_neon.S
new file mode 100644
index 00..62377331a4
--- /dev/null
+++ b/libavfilter/aarch64/merge_neon.S
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2009-2016 Rémi Denis-Courmont, Janne Grunau, VLC authors
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+#define dest x0
+#define src1 x1
+#define src2 x2
+#define size x3
+
+.align 2
+// NOTE: Offset and pitch must be multiple of 16-bytes.
+function ff_merge8_neon, export=1
+andsx5, size, #~63
+b.eq2f
+mov x10, #64
+add x11, src1, #32
+add x12, src2, #32
+1:
+ld1 {v0.16b,v1.16b}, [src1], x10
+ld1 {v4.16b,v5.16b}, [src2], x10
+ld1 {v2.16b,v3.16b}, [x11], x10
+uhadd   v0.16b, v0.16b, v4.16b
+ld1 {v6.16b,v7.16b}, [x12], x10
+subsx5, x5, #64
+uhadd   v1.16b, v1.16b, v5.16b
+uhadd   v2.16b, v2.16b, v6.16b
+uhadd   v3.16b, v3.16b, v7.16b
+st1 {v0.16b,v1.16b}, [dest], #32
+st1 {v2.16b,v3.16b}, [dest], #32
+b.gt1b
+2:
+tbz size, #5,  3f
+ld1 {v0.16b,v1.16b}, [src1], #32
+ld1 {v4.16b,v5.16b}, [src2], #32
+uhadd   v0.16b, v0.16b, v4.16b
+uhadd   v1.16b, v1.16b, v5.16b
+st1 {v0.16b,v1.16b}, [

Re: [FFmpeg-devel] [RFC PATCH] avfilter/fastdeint: import simple cpu-optimized deinterlacing algorithms from VLC

2019-09-09 Thread Aman Gupta
On Mon, Sep 9, 2019 at 2:47 PM Carl Eugen Hoyos  wrote:

> Am Mo., 9. Sept. 2019 um 22:19 Uhr schrieb Aman Gupta :
> >
> > From: Aman Gupta 
> >
> > These are simple algorithms which can be run efficiently
> > on low powered devices to produce deinteraced images.
>
> Please provide some numbers about the performance
> (and subjective visual quality) of the new C code in
> comparison to existing deinterlacers in FFmpeg.
>

Comparison of visual quality can be seen on VLC's website:
https://wiki.videolan.org/Deinterlacing

Regarding performance- none of the filters currently available in ffmpeg
are fast enough to deinterlace video in real time on ARM chips used by
popular Android or iOS devices. They're all very computationally expensive,
and do not have any ARM SIMD implementations. The deinterlacers from VLC
use simple mathematical averages optimized by SIMD, and have been used by
VLC on such devices for many years. I don't have any hard numbers to share,
but in my experience I can decode+deinterlace video for real time playback
in VLC on any cheap Android phone, whereas other ffmpeg-based players
cannot.

Aman


> Carl Eugen
> ___
> 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] [RFC PATCH] avfilter/fastdeint: import simple cpu-optimized deinterlacing algorithms from VLC

2019-09-09 Thread Aman Gupta
On Mon, Sep 9, 2019 at 3:19 PM Hendrik Leppkes  wrote:

> On Tue, Sep 10, 2019 at 12:00 AM Aman Gupta  wrote:
> >
> > On Mon, Sep 9, 2019 at 2:47 PM Carl Eugen Hoyos 
> wrote:
> >
> > > Am Mo., 9. Sept. 2019 um 22:19 Uhr schrieb Aman Gupta  >:
> > > >
> > > > From: Aman Gupta 
> > > >
> > > > These are simple algorithms which can be run efficiently
> > > > on low powered devices to produce deinteraced images.
> > >
> > > Please provide some numbers about the performance
> > > (and subjective visual quality) of the new C code in
> > > comparison to existing deinterlacers in FFmpeg.
> > >
> >
> > Comparison of visual quality can be seen on VLC's website:
> > https://wiki.videolan.org/Deinterlacing
> >
> > Regarding performance- none of the filters currently available in ffmpeg
> > are fast enough to deinterlace video in real time on ARM chips used by
> > popular Android or iOS devices. They're all very computationally
> expensive,
> > and do not have any ARM SIMD implementations. The deinterlacers from VLC
> > use simple mathematical averages optimized by SIMD, and have been used by
> > VLC on such devices for many years. I don't have any hard numbers to
> share,
> > but in my experience I can decode+deinterlace video for real time
> playback
> > in VLC on any cheap Android phone, whereas other ffmpeg-based players
> > cannot.
> >
>
> None of those algorithms are really worth using, none are actual
> "deinterlacers". Blend and Mean are just plain out terrible, and the
> other options are just dumb bob'ers which you can do with avfilter
> as-is today with a combination of the separatefields filter (which is
> zero-copy based on frame metadata only) and optional scaling
> afterwards.
>

I don't disagree that many of them are overly simplistic. I only copied
them all for completeness sake.

However, as terrible as they may be they're not as bad as displaying
interlaced frames directly. Blend and Linear produce acceptable image
quality imho.

Linear averages lines from both fields to generate a new image. Is
something like this possible with any existing filter combined with
separatefields?

Aman


>
> - Hendrik
> ___
> 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] [PATCH 1/4] cbs: Add some common code for read/write of miscellaneous user data

2019-09-11 Thread Aman Gupta
From: Mark Thompson 

Supports closed captions, active format and bar data as defined by
SCTE 128 part 1 or A/53 part 4, suitable for use with both MPEG-2
and H.264.
---
 libavcodec/cbs_misc.c | 217 ++
 libavcodec/cbs_misc.h | 109 +
 libavcodec/cbs_misc_syntax_template.c | 150 ++
 3 files changed, 476 insertions(+)
 create mode 100644 libavcodec/cbs_misc.c
 create mode 100644 libavcodec/cbs_misc.h
 create mode 100644 libavcodec/cbs_misc_syntax_template.c

diff --git a/libavcodec/cbs_misc.c b/libavcodec/cbs_misc.c
new file mode 100644
index 00..d0ced562f5
--- /dev/null
+++ b/libavcodec/cbs_misc.c
@@ -0,0 +1,217 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_misc.h"
+
+#define CHECK(call) do { \
+err = (call); \
+if (err < 0) \
+return err; \
+} while (0)
+
+#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
+#define FUNC_MISC(rw, name) FUNC_NAME(rw, misc, name)
+#define FUNC(name) FUNC_MISC(READWRITE, name)
+
+
+#define READWRITE read
+#define RWContext GetBitContext
+
+#define xui(width, name, var) do { \
+uint32_t value = 0; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, NULL, \
+   &value, 0, MAX_UINT_BITS(width))); \
+var = value; \
+} while (0)
+
+#define ui(width, name) \
+xui(width, name, current->name)
+
+#define fixed(width, name, expected) do { \
+av_unused uint32_t value; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, NULL, \
+   &value, expected, expected)); \
+} while (0)
+
+#include "cbs_misc_syntax_template.c"
+
+#undef READWRITE
+#undef RWContext
+#undef xui
+#undef ui
+#undef fixed
+
+
+#define READWRITE write
+#define RWContext PutBitContext
+
+#define xui(width, name, var) do { \
+CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, NULL, \
+var, 0, MAX_UINT_BITS(width))); \
+} while (0)
+
+#define ui(width, name) \
+xui(width, name, current->name)
+
+#define fixed(width, name, value) do { \
+CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, NULL, \
+value, value, value)); \
+} while (0)
+
+#include "cbs_misc_syntax_template.c"
+
+#undef READWRITE
+#undef RWContext
+#undef xui
+#undef ui
+#undef fixed
+
+
+int ff_cbs_read_a53_user_data(CodedBitstreamContext *ctx,
+  A53UserData *data,
+  const uint8_t *read_buffer, size_t length)
+{
+GetBitContext gbc;
+int err;
+
+err = init_get_bits(&gbc, read_buffer, 8 * length);
+if (err < 0)
+return err;
+
+return cbs_misc_read_a53_user_data(ctx, &gbc, data);
+}
+
+int ff_cbs_write_a53_user_data(CodedBitstreamContext *ctx,
+   uint8_t *write_buffer, size_t *length,
+   A53UserData *data)
+{
+PutBitContext pbc;
+int err;
+
+init_put_bits(&pbc, write_buffer, *length);
+
+err = cbs_misc_write_a53_user_data(ctx, &pbc, data);
+if (err < 0) {
+// Includes AVERROR(ENOSPC).
+return err;
+}
+
+// That output must be aligned.
+av_assert0(put_bits_count(&pbc) % 8 == 0);
+
+*length = put_bits_count(&pbc) / 8;
+
+flush_put_bits(&pbc);
+
+return 0;
+}
+
+int ff_cbs_read_a53_cc_side_data(CodedBitstreamContext *ctx,
+ A53UserData *data,
+ const uint8_t *side_data,
+ size_t side_data_size)
+{
+GetBitContext gbc;
+CEA708CCData *cc;
+int err, i, cc_count;
+
+if (side_data_size % 3) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "A53 CC side data length must "
+   "be a multiple of 3 (got %zu).\n", side_data_size);
+return AVERROR(EINVAL);
+}
+cc_count = side_data_size / 3;
+if (cc_count > 31) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "A53 CC can only fit 31 packets "
+   "in a single user dat

[FFmpeg-devel] [PATCH 2/4] h264_metadata: Add support for A/53 closed captions

2019-09-11 Thread Aman Gupta
From: Mark Thompson 

Allows insertion (from side data), extraction (to side data), and removal
of closed captions in SEI messages.
---
 libavcodec/Makefile|   2 +-
 libavcodec/h264_metadata_bsf.c | 133 +
 2 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6bc4383c8f..b10064776c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1079,7 +1079,7 @@ OBJS-$(CONFIG_EAC3_CORE_BSF)  += 
eac3_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  av1_parse.o h2645_parse.o
 OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
-OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o h264_levels.o
+OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o h264_levels.o 
cbs_misc.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
 OBJS-$(CONFIG_HAPQA_EXTRACT_BSF)  += hapqa_extract_bsf.o hap.o
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 5de74be9d6..65c7b7b55e 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -24,6 +24,7 @@
 #include "bsf.h"
 #include "cbs.h"
 #include "cbs_h264.h"
+#include "cbs_misc.h"
 #include "h264.h"
 #include "h264_levels.h"
 #include "h264_sei.h"
@@ -84,6 +85,7 @@ typedef struct H264MetadataContext {
 int flip;
 
 int level;
+int a53_cc;
 } H264MetadataContext;
 
 
@@ -281,6 +283,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket 
*pkt)
 CodedBitstreamFragment *au = &ctx->access_unit;
 int err, i, j, has_sps;
 H264RawAUD aud;
+uint8_t *a53_side_data = NULL;
+size_t a53_side_data_size = 0;
 
 err = ff_bsf_get_packet_ref(bsf, pkt);
 if (err < 0)
@@ -556,6 +560,122 @@ static int h264_metadata_filter(AVBSFContext *bsf, 
AVPacket *pkt)
 }
 }
 
+if (ctx->a53_cc == INSERT) {
+uint8_t *data;
+int size;
+
+data = av_packet_get_side_data(pkt, AV_PKT_DATA_A53_CC, &size);
+if (data) {
+A53UserData a53_ud;
+
+err = ff_cbs_read_a53_cc_side_data(ctx->cbc, &a53_ud,
+   data, size);
+if (err < 0) {
+av_log(bsf, AV_LOG_WARNING, "Invalid A/53 closed captions "
+   "in packet side data dropped.\n");
+} else {
+H264RawSEIPayload payload = {
+.payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED,
+};
+H264RawSEIUserDataRegistered *udr =
+&payload.payload.user_data_registered;
+size_t size = 9 + 3 * a53_ud.atsc.cc_data.cc_count;
+
+udr->data_ref = av_buffer_alloc(2 + size);
+if (!udr->data_ref) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+udr->data = udr->data_ref->data;
+
+udr->itu_t_t35_country_code = 181;
+AV_WB16(udr->data, 49); // provider_code
+
+err = ff_cbs_write_a53_user_data(ctx->cbc, udr->data + 2,
+ &size, &a53_ud);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to write "
+   "A/53 user data.\n");
+av_buffer_unref(&udr->data_ref);
+goto fail;
+}
+udr->data_length = size + 2;
+
+err = ff_cbs_h264_add_sei_message(ctx->cbc, au, &payload);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to add A/53 user data "
+   "SEI message to access unit.\n");
+av_buffer_unref(&udr->data_ref);
+goto fail;
+}
+}
+}
+
+} else if (ctx->a53_cc == REMOVE || ctx->a53_cc == EXTRACT) {
+for (i = 0; i < au->nb_units; i++) {
+H264RawSEI *sei;
+if (au->units[i].type != H264_NAL_SEI)
+continue;
+sei = au->units[i].content;
+
+for (j = 0; j < sei->payload_count; j++) {
+H264RawSEIUserDataRegistered *udr;
+A53UserData a53_ud;
+
+if (sei->payload[j].payload_type !=
+H264_SEI_TYPE_USER_DATA_REGISTERED)
+continue;
+udr = &sei->payload[j].payload.user_data_registered;
+if (udr->data_length < 6) {
+// Can't be relevant.
+continue;
+}
+
+err = ff_cbs_read_a53_user_data(ctx->cbc, &a53_ud,
+udr->data + 2,
+   

[FFmpeg-devel] [PATCH 4/4] mpeg2_metadata: Add support for A/53 closed captions

2019-09-11 Thread Aman Gupta
From: Mark Thompson 

Allows extraction (to side data) and removal of closed captions in
user data blocks.
---
 doc/bitstream_filters.texi  | 12 ++
 libavcodec/Makefile |  2 +-
 libavcodec/mpeg2_metadata_bsf.c | 76 -
 3 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8e957ae4a8..05f88e466d 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,18 @@ table 6-6).
 Set the colour description in the stream (see H.262 section 6.3.6
 and tables 6-7, 6-8 and 6-9).
 
+@item a53_cc
+Modify A/53 closed captions in user data blocks.
+
+@table @samp
+@item remove
+Remove all closed caption data from the stream.
+
+@item extract
+Extract closed captions from the stream so that they are available as
+as packet side data.
+@end table
+
 @end table
 
 @section mpeg4_unpack_bframes
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b10064776c..e691181996 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1092,7 +1092,7 @@ OBJS-$(CONFIG_MPEG4_UNPACK_BFRAMES_BSF)   += 
mpeg4_unpack_bframes_bsf.o
 OBJS-$(CONFIG_MOV2TEXTSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
  mpegaudiodata.o
-OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
+OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o cbs_misc.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index 3f371a028d..e82758d2eb 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -22,9 +22,17 @@
 
 #include "bsf.h"
 #include "cbs.h"
+#include "cbs_misc.h"
 #include "cbs_mpeg2.h"
 #include "mpeg12.h"
 
+enum {
+PASS,
+INSERT,
+REMOVE,
+EXTRACT,
+};
+
 typedef struct MPEG2MetadataContext {
 const AVClass *class;
 
@@ -42,6 +50,8 @@ typedef struct MPEG2MetadataContext {
 int transfer_characteristics;
 int matrix_coefficients;
 
+int a53_cc;
+
 int mpeg1_warned;
 } MPEG2MetadataContext;
 
@@ -173,7 +183,9 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, 
AVPacket *pkt)
 {
 MPEG2MetadataContext *ctx = bsf->priv_data;
 CodedBitstreamFragment *frag = &ctx->fragment;
-int err;
+int err, i;
+uint8_t *a53_side_data = NULL;
+size_t a53_side_data_size = 0;
 
 err = ff_bsf_get_packet_ref(bsf, pkt);
 if (err < 0)
@@ -191,6 +203,57 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, 
AVPacket *pkt)
 goto fail;
 }
 
+if (ctx->a53_cc == REMOVE || ctx->a53_cc == EXTRACT) {
+for (i = 0; i < frag->nb_units; i++) {
+MPEG2RawUserData *ud;
+A53UserData a53_ud;
+
+if (frag->units[i].type != MPEG2_START_USER_DATA)
+continue;
+ud = frag->units[i].content;
+
+err = ff_cbs_read_a53_user_data(ctx->cbc, &a53_ud, ud->user_data,
+ud->user_data_length);
+if (err < 0) {
+// Invalid or something completely different.
+continue;
+}
+if (a53_ud.user_identifier != A53_USER_IDENTIFIER_ATSC ||
+a53_ud.atsc.user_data_type_code !=
+A53_USER_DATA_TYPE_CODE_CC_DATA) {
+// Valid but something else (e.g. AFD).
+continue;
+}
+
+if (ctx->a53_cc == REMOVE) {
+ff_cbs_delete_unit(ctx->cbc, frag, i);
+--i;
+break;
+} else if(ctx->a53_cc == EXTRACT) {
+err = ff_cbs_write_a53_cc_side_data(ctx->cbc,
+&a53_side_data,
+&a53_side_data_size,
+&a53_ud);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to write "
+   "A/53 user data for packet side data.\n");
+goto fail;
+}
+
+if (a53_side_data) {
+err = av_packet_add_side_data(pkt, AV_PKT_DATA_A53_CC,
+  a53_side_data, 
a53_side_data_size);
+if (err) {
+av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted 
A/53 "
+   "side data to packet.\n");
+goto fail;
+}
+a53_side_data = NULL;
+}
+}
+}
+}
+
 err = ff_cbs_write_packet(ctx->cbc, pkt, frag);
 if (err < 0) {
 av_lo

[FFmpeg-devel] [PATCH 3/4] h264_metadata: Update documentation

2019-09-11 Thread Aman Gupta
From: Mark Thompson 

Improve documentation for the delete_filler option, and add the
display_orientation and a53_cc options.
---
 doc/bitstream_filters.texi | 51 +-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 50a1679fc7..8e957ae4a8 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -274,7 +274,56 @@ For example, 
@samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
 insert the string ``hello'' associated with the given UUID.
 
 @item delete_filler
-Deletes both filler NAL units and filler SEI messages.
+Delete all filler in the stream: both filler data NAL units and
+filler payload SEI messages.
+
+Filler zero bytes between NAL units in Annex B format (leading_zero_8bits
+and trailing_zero_8bits) will be discarded from the stream with or
+without this option - as such, HRD parameters are not expected to be
+accurate after any rewriting transformation made by this filter.
+
+@item display_orientation
+Modify display orientation SEI messages.
+
+@table @samp
+@item insert
+Insert new display orientation messages, overwriting any currently in
+the stream.  The new value is taken from the packet side data, modified
+by the @option{rotate} and @option{flip} options.
+
+@item remove
+Remove all display orientation messages from the stream.
+
+@item extract
+Extract display orientation messages so that they are available as
+packet side data.
+@end table
+
+@item rotate
+Set the rotation angle in the display orientation data.  This is an
+anticlockwise rotation angle in degrees.
+@item flip
+Set the flip fields in the display orientation data.  This can be any
+combination of the flags:
+@table @samp
+@item horizontal
+@item vertical
+@end table
+
+@item a53_cc
+Modify A/53 closed caption data in SEI messages.
+
+@table @samp
+@item insert
+Insert closed captions taken from packet side data into the stream.
+
+@item remove
+Remove all closed caption data from the stream.
+
+@item extract
+Extract closed captions from the stream so that they are available as
+as packet side data.
+@end table
 
 @item level
 Set the level in the SPS.  Refer to H.264 section A.3 and tables A-1
-- 
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] avcodec/cbs_misc: remove anonymous union for gcc4.4 compat

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

Signed-off-by: Aman Gupta 
---
 libavcodec/cbs_misc.c | 14 +++---
 libavcodec/cbs_misc.h |  4 ++--
 libavcodec/cbs_misc_syntax_template.c |  8 
 libavcodec/h264_metadata_bsf.c|  4 ++--
 libavcodec/mpeg2_metadata_bsf.c   |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/cbs_misc.c b/libavcodec/cbs_misc.c
index d0ced562f5..09324949f6 100644
--- a/libavcodec/cbs_misc.c
+++ b/libavcodec/cbs_misc.c
@@ -150,10 +150,10 @@ int ff_cbs_read_a53_cc_side_data(CodedBitstreamContext 
*ctx,
 *data = (A53UserData) {
 .user_identifier = A53_USER_IDENTIFIER_ATSC,
 
-.atsc = {
+.u = { .atsc = {
 .user_data_type_code = A53_USER_DATA_TYPE_CODE_CC_DATA,
 
-.cc_data = {
+.u = { .cc_data = {
 .process_em_data_flag = 0,
 .process_cc_data_flag = 1,
 .additional_data_flag = 0,
@@ -161,10 +161,10 @@ int ff_cbs_read_a53_cc_side_data(CodedBitstreamContext 
*ctx,
 .em_data = 0,
 
 .cc_count = cc_count,
-},
-},
+} },
+} },
 };
-cc = &data->atsc.cc_data;
+cc = &data->u.atsc.u.cc_data;
 
 err = init_get_bits(&gbc, side_data, 8 * side_data_size);
 if (err < 0)
@@ -190,10 +190,10 @@ int ff_cbs_write_a53_cc_side_data(CodedBitstreamContext 
*ctx,
 int err, i;
 
 if (data->user_identifier != A53_USER_IDENTIFIER_ATSC ||
-data->atsc.user_data_type_code != A53_USER_DATA_TYPE_CODE_CC_DATA)
+data->u.atsc.user_data_type_code != A53_USER_DATA_TYPE_CODE_CC_DATA)
 return AVERROR(EINVAL);
 
-cc = &data->atsc.cc_data;
+cc = &data->u.atsc.u.cc_data;
 
 err = av_reallocp(side_data, *side_data_size + 3 * cc->cc_count);
 if (err < 0)
diff --git a/libavcodec/cbs_misc.h b/libavcodec/cbs_misc.h
index 0d7ab2c8e7..b434ab86cc 100644
--- a/libavcodec/cbs_misc.h
+++ b/libavcodec/cbs_misc.h
@@ -70,7 +70,7 @@ typedef struct A53ATSCUserData {
 union {
 CEA708CCData cc_data;
 A53BarData bar_data;
-};
+} u;
 } A53ATSCUserData;
 
 typedef struct A53AFDData {
@@ -83,7 +83,7 @@ typedef struct A53UserData {
 union {
 A53ATSCUserData atsc;
 A53AFDData afd;
-};
+} u;
 } A53UserData;
 
 
diff --git a/libavcodec/cbs_misc_syntax_template.c 
b/libavcodec/cbs_misc_syntax_template.c
index 7b98c7cc85..60ece42aef 100644
--- a/libavcodec/cbs_misc_syntax_template.c
+++ b/libavcodec/cbs_misc_syntax_template.c
@@ -99,9 +99,9 @@ static int FUNC(a53_atsc_user_data)(CodedBitstreamContext 
*ctx, RWContext *rw,
 
 switch (current->user_data_type_code) {
 case A53_USER_DATA_TYPE_CODE_CC_DATA:
-return FUNC(cea708_cc_data)(ctx, rw, ¤t->cc_data);
+return FUNC(cea708_cc_data)(ctx, rw, ¤t->u.cc_data);
 case A53_USER_DATA_TYPE_CODE_BAR_DATA:
-return FUNC(a53_bar_data)(ctx, rw, ¤t->bar_data);
+return FUNC(a53_bar_data)(ctx, rw, ¤t->u.bar_data);
 default:
 av_log(ctx->log_ctx, AV_LOG_WARNING,
"Unknown ATSC user data found: type code %#02x.\n",
@@ -137,9 +137,9 @@ static int FUNC(a53_user_data)(CodedBitstreamContext *ctx, 
RWContext *rw,
 
 switch (current->user_identifier) {
 case A53_USER_IDENTIFIER_ATSC:
-return FUNC(a53_atsc_user_data)(ctx, rw, ¤t->atsc);
+return FUNC(a53_atsc_user_data)(ctx, rw, ¤t->u.atsc);
 case A53_USER_IDENTIFIER_AFD:
-return FUNC(a53_afd_data)(ctx, rw, ¤t->afd);
+return FUNC(a53_afd_data)(ctx, rw, ¤t->u.afd);
 default:
 av_log(ctx->log_ctx, AV_LOG_WARNING,
"Unknown registered user data found: identifier %#08x.\n",
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 65c7b7b55e..7c890508dd 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -579,7 +579,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket 
*pkt)
 };
 H264RawSEIUserDataRegistered *udr =
 &payload.payload.user_data_registered;
-size_t size = 9 + 3 * a53_ud.atsc.cc_data.cc_count;
+size_t size = 9 + 3 * a53_ud.u.atsc.u.cc_data.cc_count;
 
 udr->data_ref = av_buffer_alloc(2 + size);
 if (!udr->data_ref) {
@@ -639,7 +639,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket 
*pkt)
 continue;
 }
 if (a53_ud.user_identifier != A53_USER_IDENTIFIER_ATSC ||
-a53_ud.atsc.user_data_type_code !=
+a53_ud.u.atsc.user_data_type_code !=
 A53_USER_DATA_TYPE_CODE_CC_DATA) {
 // Valid but something else (e.g. AFD).
  

[FFmpeg-devel] [PATCH] avcodec/v4l2_m2m_enc: check for V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME availability before using

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

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

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 4849bc26c5..474e6bef89 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -245,8 +245,10 @@ static int v4l2_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
 V4L2Context *const output = &s->output;
 
+#ifdef V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
 if (frame && frame->pict_type == AV_PICTURE_TYPE_I)
 v4l2_set_ext_ctrl(s, MPEG_CID(FORCE_KEY_FRAME), 0, "force key frame");
+#endif
 
 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".

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

2019-09-13 Thread Aman Gupta
On Thu, Sep 12, 2019 at 5:05 PM Mark Thompson  wrote:

> On 03/09/2019 02:02, Aman Gupta wrote:
> > 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);
> >
>
> This smells like a hack for making something work in the ffmpeg
> command-line utility.  Can you explain the use-case?  If necessary,
> modifying the behaviour of ffmpeg would probably be better than putting
> this sort of thing into the library.
>

Since this v4l2 decoder can output either software frames or DRM frames,
this allows using the CLI to switch between the two modes. i.e.:

ffmpeg -c:v h264_v4l2m2m -i sample.mpg
vs
./ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -c:v h264_v4l2m2m -i
sample.mpg

This is also why I made the decoder define itself
as AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, so it was possible to use the
CLI to trigger the DRM prime decoding mode.

It sounds like it might be better to define a new v4l2 hwaccel/hwdevice,
and maybe just return EINVAL from it's map/transfer methods since those are
not applicable?

Aman




>
> - Mark
> ___
> 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".

  1   2   3   4   5   6   >