Skip to content
Commit 70c5d720 authored by John Cox's avatar John Cox Committed by Dom Cobley
Browse files

staging: media: rpivid: Add Raspberry Pi V4L2 H265 decoder



This driver is for the HEVC/H265 decoder block on the Raspberry
Pi 4, and conforms to the V4L2 stateless decoder API.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

staging: media: rpivid: Select MEDIA_CONTROLLER and MEDIA_CONTROLLER_REQUEST_API

MEDIA_CONTROLLER_REQUEST_API is a hidden option. If rpivid depends on it,
the user would need to first enable another driver that selects
MEDIA_CONTROLLER_REQUEST_API, and only then rpivid would become available.

By selecting it instead of depending on it, it becomes possible to enable
rpivid without having to enable other potentially unnecessary drivers.

Signed-off-by: default avatarHristo Venev <hristo@venev.name>

rpivid_h265: Fix width/height typo

Signed-off-by: default avatarpopcornmix <popcornmix@gmail.com>

rpivid_h625: Fix build warnings

Signed-off-by: default avatarPhil Elwell <phil@raspberrypi.com>

staging: rpivid: Fix crash when CMA alloc fails

If realloc to increase coeff size fails then attempt to re-allocate
the original size.  If that also fails then flag a fatal error to abort
all further decode.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

rpivid: Request maximum hevc clock

Query maximum and minimum clock from driver
and use those

Signed-off-by: default avatarDom Cobley <popcornmix@gmail.com>

rpivid: Switch to new clock api

Signed-off-by: default avatarDom Cobley <popcornmix@gmail.com>

rpivid: Only clk_request_done once

Fixes: 25486f49
Signed-off-by: default avatarDom Cobley <popcornmix@gmail.com>

media: rpivid: Remove the need to have num_entry_points set

VAAPI H265 has num entry points but never sets it. Allow a VAAPI
shim to work without requiring rewriting the VAAPI driver.
num_entry_points can be calculated from the slice_segment_addr
of the next slice so delay processing until we have that.

Also includes some minor cosmetics.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Convert to MPLANE

Use multi-planar interface rather than single plane interface. This
allows dmabufs holding compressed data to be resized.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Add an enable count to irq claim Qs

Add an enable count to the irq Q structures to allow the irq logic to
block further callbacks if resources associated with the irq are not
yet available.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Add a Pass0 to accumulate slices and rework job finish

Due to overheads in assembling controls and requests it is worth having
the slice assembly phase separate from the h/w pass1 processing. Create
a queue to service pass1 rather than have the pass1 finished callback
trigger the next slice job.

This requires a rework of the logic that splits up the buffer and
request done events. This code contains two ways of doing that, we use
Ezequiel Garcias <ezequiel@collabora.com> solution, but expect that
in the future this will be handled by the framework in a cleaner manner.

Fix up the handling of some of the memory exhaustion crashes uncovered
in the process of writing this code.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Map cmd buffer directly

It is unnecessary to have a separate dmabuf to hold the cmd buffer.
Map it directly from the kmalloc.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Improve values returned when setting output format

Guess a better value for the compressed bitstream buffer size

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Improve stream_on/off conformance & clock setup

Fix stream on & off such that failures leave the driver in the correct
state.  Ensure that the clock is on when we are streaming and off when
all contexts attached to this device have stopped streaming.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Improve SPS/PPS error handling/validation

Move size and width checking from bitstream processing to control
validation

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Fix H265 aux ent reuse of the same slot

It is legitimate, though unusual, for an aux ent associated with a slot
to be selected in phase 0 before a previous selection has been used and
released in phase 2. Fix such that if the slot is found to be in use
that the aux ent associated with it is reused rather than an new aux
ent being created. This fixes a problem where when the first aux ent
was released the second was lost track of.

This bug spotted in Nick's testing. It may explain some other occasional,
unreliable decode error reports where dmesg included "Missing DPB AUX
ent" logging.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Update to compile with new hevc decode params

DPB entries have moved from slice params to the new decode params
attribute - update to deal with this.  Also fixes fallthrough
warnings which seem to be new in 5.14.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Make slice ctrl dynamic

Allows the user to submit a whole frames worth of slice headers in
one lump along with a single bitstream dmabuf for the whole lot.
This saves potentially a lot of bitstream copying.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Only create aux entries for H265 if needed

Only create aux entries of mv info for frames where that info might
be used by a later frame.  This saves some memory bandwidth and
potentially some memory.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Avoid returning EINVAL to a G_FMT ioctl

V4L2 spec says that G/S/TRY_FMT IOCTLs should never return errors for
anything other than wrong buffer types. Improve the capture format
function such that this is so and unsupported values get converted
to supported ones properly.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Remove unused ctx state variable and defines

Remove unused ctx state tracking variable and associated defines.
Their presence implies they might be used, but they aren't.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Ensure IRQs have completed before uniniting context

Before uniniting the decode context sync with the IRQ queues to ensure
that decode no longer has any buffers in use.  This fixes a problem that
manifested as ffmpeg leaking CMA buffers when it did a stream off on
OUTPUT before CAPTURE, though in reality it was probably much more
dangerous than that.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: remove min_buffers_needed from src queue

Remove min_buffers_needed=1 from src queue init. Src buffers are bound
to media requests therefore this setting is not needed and generates
a WARN in kernel 5.16.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

rpivid: Use clk_get_max_rate()

The driver was using clk_round_rate() to figure out the maximum clock
rate that was allowed for the HEVC clock.

Since we have a function to return it directly now, let's use it.

Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>

media: rpivid: Apply V4L2 stateless API changes

media: rpivid: Fix fallthrough warning

Replace old-style /* FALLTHRU */ with fallthrough;

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Set min value as well as max for HEVC_DECODE_MODE

As only one value can be accepted set both min and max to that value.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

media: rpivid: Accept ANNEX_B start codes

Allow the START_CODE control to take ANNEX_B as a value. This makes no
difference to any part of the decode process as the added bytes are in
data that we ignore. This helps my testing and may help userland code
that expects to send those bytes.

Signed-off-by: default avatarJohn Cox <jc@kynesim.co.uk>

rpivid: Convert to new clock rate API

Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
parent 533ab7bc
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment