1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-07-26 14:14:54 +02:00
Commit Graph

26 Commits

Author SHA1 Message Date
Andriy Gelman
5df9724e42 avcodec/v4l2_context: return EAGAIN to signal full buffers
Return proper error when frame buffers are full. This path is triggered
on the DragonBoard 410c since the encoding API change in commit
827d6fe73d.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Reviewed-by: Mark Thompson <sw@jkqxz.net>
2020-08-16 17:39:13 -04:00
Andriy Gelman
c76b2bf0b4 avcodec/v4l2_context: Finish draining if V4L2_BUF_FLAG_LAST is set
V4L2 api can indicate that flushing of the capture buffers is completed
by setting the V4L2_BUF_FLAG_LAST flag.
Use guards because the flag was only defined in Linux v4.2.

Reference:
linux/Documentation/media/uapi/v4l/dev-decoder.rst

    "The client must continue to handle both queues independently,
     similarly to normal decode operation. This includes:
     ...
     - queuing and dequeuing CAPTURE buffers, until a buffer marked with
       the V4L2_BUF_FLAG_LAST flag is dequeued"

Reviewed-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-05-09 19:35:05 -04:00
Andriy Gelman
e3b49aaa4e avcodec/v4l2_context: Drop empty packet while draining
v4l2_m2m devices may send an empty packet/frame while draining
to indicate that all capture buffers have been flushed.

Currently, the empty packet/frame is not handled correctly:
When encoding, the empty packet is forwarded to the muxer, usually
creating warnings.
When decoding, a reference to the memory is created anyway. Since in
the past this memory contained a decoded frame, it results in an extra
frame being decoded.

This commit discards the empty packet/frame.

References:
linux/Documentation/media/uapi/v4l/dev-decoder.rst:

    "The last buffer may be empty (with :c:type:`v4l2_buffer` bytesused = 0)
     and in that case it must be ignored by the client, as it does not
     contain a decoded frame."

linux/Documentation/media/uapi/media/v4l/vidioc-encoder-cmd.rst:

    "...This buffer may be empty, indicated by the
     driver setting the ``bytesused`` field to 0."

Reviewed-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-05-09 19:34:41 -04:00
Andriy Gelman
2a9d623561 avcodec/v4l2_context: Log warning when all capture buffers are in userspace
v4l2_m2m uses device memory mapped buffers to store dequeued
frames/packets (reference counted by AVBufferRef). When the reference
count drops to zero, the buffer ownership is returned back to the
device, so that they can re-filled with frames/packets.

There are some cases when all the capture buffers are in userspace
(i.e. due to internal buffering in ffmpeg). On the s5p-mfc this causes
an infinite wait when polling to dequeue the buffers, which can be
prevented by increasing the total number of buffers. This commit adds a
warning when all the capture buffers are dequeued.

Reviewed-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-04-30 11:00:15 -04:00
Ming Qian
8ac8e905e9 avcodec/v4l2_m2m: handle v4l2 end of stream event
When flushing the capture buffers, the driver may send a V4L2_EVENT_EOS
to notify that draining is completed. Currently, v4l2_m2m does not
subscribe to this event, which can cause some devices (i.e. imx8qm) to
hang at the end of encoding/decoding. Support for handling the event is
added in this commit.

Some devices may not signal V4L2_EVENT_EOS. This is logged as a warning
message during initialization and not treated as a fatal error.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-04-14 23:42:05 -04:00
Andriy Gelman
cd04bb4afe avcodec/v4l2_context: Use av_freep()
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-04-08 21:41:52 -04:00
Linjie Fu
dfa1fc17a5 lavc/v4l2_context: fix compile warning for incompatible pointer type
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-02-28 19:40:05 +01:00
Andriy Gelman
73e23b404c avcodec/v4l2_m2m: Use consistent logging context
Before this commit v4l2_m2m used two different logging contexts (from
V4L2m2mPriv and AVCodecContext). For consistency always use AVCodecContext.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-02-01 21:39:05 +00:00
Andriy Gelman
3905ecbc06 avcodec:v4l2_context: Remove NULL initialization
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-02-01 21:39:05 +00:00
Andriy Gelman
8a8966295f avcodec/v4l2_context: Use AVERROR macro
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-14 19:19:30 +01:00
Andriy Gelman
e759fbfbc4 avcodec/v4l2_context: Fix indentation
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-11-22 12:06:28 -08:00
Maxime Jourdan
b81a1c5bea avcodec/v4l2_context: set frame SAR using VIDIOC_CROPCAP
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-11 13:07:42 -07:00
Aman Gupta
fac834b2ae avcodec/v4l2_context: expose timeout for dequeue_frame
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-11 10:31:18 -07:00
Aman Gupta
c0c7946196 avcodec/v4l2_m2m: decouple v4l2_m2m helpers from AVCodecContext
This will allow re-use of the m2m backend with AVFilterContext

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 19:01:13 -07:00
Aman Gupta
7bb6898b16 avcodec/v4l2_m2m: fix av_pix_fmt changing when multiple /dev/video* devices are probed
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 <aman@tmm1.net>
2019-09-10 18:52:37 -07:00
Aman Gupta
c95b127733 avcodec/v4l2_context: use EAGAIN to signal when input buffers are unavailable
ENOMEM indicates an allocation failure, and there are no allocations
happening here. The buffers are pre-allocated and there are simply
none available at this time.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:08:34 -07:00
Jorge Ramirez-Ortiz
da45ad48f9 avcodec/v4l2m2m: fix error handling during buffer init
Signed-off-by: Jorge Ramirez-Ortiz <jramirez@baylibre.com>
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:08:34 -07:00
Aman Gupta
bad8365b2b avcodec/v4l2_context: return {decoder,encoder}_cmd errors
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:06:45 -07:00
Aman Gupta
87daee944b avcodec/v4l2_context: log VIDIOC_REQBUFS failures
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:06:22 -07:00
Jorge Ramirez-Ortiz
9b1ec24835 avcodec: v4l2_context: remove unnecessary code
Fixes CID 1418358

Signed-off-by: Jorge Ramirez-Ortiz <jramirez@baylibre.com>
2018-01-23 09:56:08 +01:00
Jorge Ramirez-Ortiz
0b9b7f0b46 avcodec: v4l2_m2m: context: fix raising warning on POLLERR
During the initialization stage, the codec attempts to get free
buffers from the driver before any have been queued (this is to keep
the code simple and generic)

When the kernel driver detects this situation, it returns POLLERR in
revents and ffmpeg therefore raises a warning.

This commit disables the warning since no buffers were queued to the
driver yet.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
2018-01-21 00:37:35 +00:00
Jorge Ramirez-Ortiz
5d5de3eba4 avcodec: v4l2_m2m: remove unnecessary timeout.
Qualcomm's db410c/db820 Venus driver currently present in mainline
kernel has a bug which mishandles the CMD_STOP requests causing the
decoder to block while draining [1].

This patch removes the workaround that was used to prevent that
situation.

Encoding/Decoding tested on db820c.

[1] on CMD_STOP, the driver is flushing all buffers and never raising
IPIPE which ends up in blocking on poll.
2018-01-21 00:37:35 +00:00
Carl Eugen Hoyos
2cc51d5025 lavc/v4l2_context: Change the type of the ioctl cmd to uint32_t.
Fixes a warning on recent Linux:
libavcodec/v4l2_context.c: In function 'ff_v4l2_context_set_status':
libavcodec/v4l2_context.c:496:26: warning: comparison is always false due to limited range of data type
2017-11-05 19:25:29 +01:00
Jorge Ramirez-Ortiz
44188993a1 avcodec/v4l2: set sizeimage param for non-raw buffers [fixes #6716]
Some V4L2 drivers fail to allocate buffers when sizeimage is not set
to a max value. This is indeed the case for s5p-mfc [1]

Most drivers should be able to calculate this value from the frame
dimensions and format - or at least have their own default.

However since this work around should not impact those drivers doing
the "right thing" this commit just provides such a default.

The calculations were extracted from the v4l2 driver used to develop
the ffmpeg v4l2_m2m support [2]. See venc.c and vdec.c

[1] linux.git/drivers/media/platform/s5p-mfc
[2] linux.git/drivers/media/platform/qcom/venus/
2017-10-04 23:14:37 +01:00
Michael Niedermayer
b81b8a76b5 avcodec/v4l2_context: Reduce spelling variations
Reviewed-by: Lou Logan <lou@lrcd.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-10-01 02:37:57 +02:00
Jorge Ramirez-Ortiz
1ef7752d64 libavcodec: v4l2: add support for v4l2 mem2mem codecs
This patchset enhances Alexis Ballier's original patch and validates
    it using Qualcomm's Venus hardware (driver recently landed upstream
    [1]).

    This has been tested on Qualcomm's DragonBoard 410c and 820c
    Configure/make scripts have been validated on Ubuntu 10.04 and
    16.04.

    Tested decoders:
           - h264
           - h263
           - mpeg4
           - vp8
           - vp9
           - hevc

    Tested encoders:
           - h264
           - h263
           - mpeg4

    Tested transcoding (concurrent encoding/decoding)

    Some of the changes introduced:
        - v4l2: code cleanup and abstractions added
        - v4l2: follow the new encode/decode api.
        - v4l2: fix display size for NV12 output pool.
        - v4l2: handle EOS (EPIPE and draining)
        - v4l2: vp8 and mpeg4 decoding and encoding.
        - v4l2: hevc and vp9 support.
        - v4l2: generate EOF on dequeue errors.
        - v4l2: h264_mp4toannexb filtering.
        - v4l2: fixed make install and fate issues.
        - v4l2: codecs enabled/disabled depending on pixfmt defined
        - v4l2: pass timebase/framerate to the context
        - v4l2: runtime decoder reconfiguration.
        - v4l2: add more frame information
        - v4l2: free hardware resources on last reference being released
        - v4l2: encoding: disable b-frames for upstreaming (patch required)

    [1] https://lwn.net/Articles/697956/

    System Level view:
        v42l_m2m_enc/dec --> v4l2_m2m --> v4l2_context --> v4l2_buffers

    Reviewed-by: Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
    Reviewed-by: Alexis Ballier <aballier@gentoo.org>
    Tested-by: Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2017-09-23 08:47:52 +02:00