[FFmpeg-cvslog] avcodec/omx: Fix handling of fragmented buffers

2019-08-23 Thread Dave Stevenson
ffmpeg | branch: master | Dave Stevenson  | Thu 
Jan 17 17:39:34 2019 +| [3d857f219eb972fb345e784d17268e16b6dec6f0] | 
committer: Aman Gupta

avcodec/omx: Fix handling of fragmented buffers

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 
Signed-off-by: Martin Storsjö 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d857f219eb972fb345e784d17268e16b6dec6f0
---

 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) {

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

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

[FFmpeg-cvslog] avcodec/omx: Fix handling of fragmented buffers

2019-08-23 Thread Dave Stevenson
ffmpeg | branch: release/4.2 | Dave Stevenson  
| Thu Jan 17 17:39:34 2019 +| [3dd3e8e24ac93f40f21ef281c25907dd12780e73] | 
committer: Aman Gupta

avcodec/omx: Fix handling of fragmented buffers

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 
Signed-off-by: Martin Storsjö 
(cherry picked from commit 3d857f219eb972fb345e784d17268e16b6dec6f0)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3dd3e8e24ac93f40f21ef281c25907dd12780e73
---

 libavcodec/omx.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index 3128abd5ec..20869c0f44 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];
@@ -826,7 +827,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;
 
@@ -861,6 +862,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) {

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

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

[FFmpeg-cvslog] avcodec/v4l2_buffers: Add handling for NV21 and YUV420P

2019-09-10 Thread Dave Stevenson
ffmpeg | branch: master | Dave Stevenson  | Thu 
Mar 22 16:01:35 2018 +| [d61cf1b1ebc2477749d7d7825a072400ed24af9f] | 
committer: Aman Gupta

avcodec/v4l2_buffers: Add handling for NV21 and YUV420P

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

Signed-off-by: Aman Gupta 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d61cf1b1ebc2477749d7d7825a072400ed24af9f
---

 libavcodec/v4l2_buffers.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 51b0d25cad..de72b7f80c 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -321,11 +321,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;
 }

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

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