18 Commits

Author SHA1 Message Date
Andriy Gelman
1aec1183f3 avcodec/v4l2_buffers: Fix infinite loop
This part of the code counts the number of planes returned by the v4l2
device for each queried capture/output buffer.
When testing the GPU h264 encoder on Nvidia's Jetson Nano, this caused an
infinite loop because avbuf->buf.length included some empty buffers (i.e.
where avbuf->buf.m.planes[i].length = 0), meaning that the counter was
never incremented and break was never reached.
This is fixed in the commit by using a well defined iteration range.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-11-01 15:19:55 -07:00
Aman Gupta
81abf90aea avcodec/v4l2: fix compile with older videodev2.h
Some of these symbols are only defined in newer kernel releases.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-15 11:10:09 -07: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
0085c4d478 avcodec/v4l2_buffers: use correct timebase for encoder/decoder
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-11 13:07:42 -07:00
Aman Gupta
3475758a37 avcodec/v4l2_m2m_dec: set pkt_dts on decoded frames to NOPTS
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 <aman@tmm1.net>
2019-09-11 10:28:56 -07:00
Aman Gupta
8dc973dc89 avcodec/v4l2_buffers: read height/width from the proper context
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 <aman@tmm1.net>
2019-09-11 10:28:56 -07:00
Lukas Rusak
40a433e34b avcodec/v4l2_buffers: split out v4l2_buf_increase_ref helper
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 19:12:47 -07:00
Aman Gupta
d620b1f9de avcodec/v4l2_buffers: split out V4L2Buffer generation into helper method
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 19:12:47 -07:00
Aman Gupta
2b21bb4a87 avcodec/v4l2_buffers: split out AVFrame generation into helper method
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 19:12:47 -07:00
Aman Gupta
b3b958c19e avcodec/v4l2_buffers: teach ff_v4l2_buffer_avframe_to_buf about contiguous planar formats
This fixes h264_v4l2m2m encoding on the Raspberry Pi

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 19:05:31 -07:00
Dave Stevenson
d61cf1b1eb 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 <aman@tmm1.net>
2019-09-10 18:56:40 -07:00
Lukas Rusak
1d36b7b47a avcodec/v4l2_buffers: return int64_t in v4l2_get_pts
v4l2_pts is type int64_t we should return that instead of uint64_t

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:08:29 -07:00
Aman Gupta
5e2436c6de avcodec/v4l2_buffers: fix minor typos and whitespace
Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-02 15:06:28 -07:00
Mark Thompson
2e96f52780 v4l2_m2m: Fix integer overflow in timestamp handling 2018-01-22 17:24:36 +01: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
Mark Thompson
a0c624e299 avcodec: v4l2_m2m: fix races around freeing data on close
Refcount all of the context information. This also fixes a potential
segmentation fault when accessing freed memory  (buffer returned after
the codec has been closed).

Tested-by: Jorge Ramirez-Ortiz <jorge.ramirez.ortiz@gmail.com>
2018-01-21 00:37:35 +00:00
Jorge Ramirez-Ortiz
2a31ad7d60 avcodec/v4l2: fix single plane decoding 2017-10-06 23:36:21 +01: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