Commit graph

211 commits

Author SHA1 Message Date
Guillaume Desmottes
d3c2a7c8d1 omxvideoenc: remove unsupported formats from caps template
Our encoder implementation actually supports a small subset of the
formats supported by the decoder. Those are the formats for which we
have a copy path in gst_omx_video_enc_fill_buffer() and which are not
filtered out in filter_supported_formats().
2020-04-10 11:53:23 +02:00
Guillaume Desmottes
d5e278e362 omxvideoenc: add GRAY8 support
It's supported by Zynq encoder and was already in the sink caps
template.
2020-04-10 11:30:29 +02:00
Guillaume Desmottes
2a620d5bbd omxvideoenc: factor out gst_omx_video_enc_copy_plane()
No semantic change, I'm going to use it to copy GRAY8 buffers which is
actually a single plane 8-bits format.
2020-04-10 11:30:29 +02:00
Guillaume Desmottes
5e6090056d omxvideoenc: use gst_video_meta_get_plane_height() to compute slice height
This new API saves us from doing manual computation and actually work
with single planar formats, such as GRAY8.
2020-04-10 11:30:29 +02:00
Stéphane Cerveau
84e9906076 omxh26xenc: fix coverity with frame test
Coverity was complaining with:
Null pointer dereferences  (REVERSE_INULL) Null-checking "frame"
suggests that it may be null, but it has already been
dereferenced on all paths leading to the check.

The frame == NULL has been removed as 'frame' is actively used
in the code above without any change of dereferencing and setting
its value to NULL before the test.

CID: 1461287
2020-04-08 16:54:24 +02:00
Stéphane Cerveau
7d5175a80f gstomxvideoenc: fix subframe output_buffer
Using more than 1 subframes was failing with
frame->output_buffer = NULL
2020-03-19 16:24:44 +01:00
Guillaume Desmottes
1c3f39c4d7 omxvideoenc: add support of alternate interlace mode on zynq
It's only supported by the Zynq HEVC encoder for now.
2020-02-27 04:05:48 +00:00
Guillaume Desmottes
e616094a53 omxvideo(enc): use GST_VIDEO_INFO_FIELD_RATE_N()
Does not change anything for now but will be needed when we'll support
interlace-mode=alternate as the field rate will be twice the frame rate.

Made the code safe from division by 0 while I was on it.
2020-02-27 04:05:48 +00:00
Guillaume Desmottes
f14f5d9f70 omxvideo{enc,dec}: use GST_VIDEO_INFO_FIELD_HEIGHT()
Does not change anything for now but will be needed when we'll support
interlace-mode=alternate as the fields will have half the frame height.
2020-02-27 04:05:48 +00:00
Stéphane Cerveau
74812122d4 omxvideoenc: fix warning
Fix warning test when OMX_BUFFERFLAG_ENDOFFRAME
is not set.
2020-01-16 10:09:23 +01:00
Varunkumar Allagadapa
f35f312634 omxvideoenc: Add look-ahead property to ZYNQ_USCALE_PLUS encoder
This patch adds look-ahead property to encoder

The value indicates look ahead size in frames,
the number of frames processed ahead of second pass encoding.
Dual pass encoding is disabled if look-ahead
value is less than 2.
2020-01-09 11:44:55 +01:00
Varunkumar Allagadapa
bfd8306ef6 omxvideoenc: Add long-term-ref support to ZYNQ_USCALE_PLUS encoder
Custom API that upstream elements can use to notify encoders about
marking longterm ref. pictures or using longterm ref. pictures in
encoding process.

This patch adds below properties:

long-term-ref: Enable/Disable dynamically marking long-term
reference pictures in encoding process

long-term-freq: Periodicity of long-term reference picture
marking in encoding process.

If a picture is marked as long-term reference picture then it remains
in the DPB list for ever unless it overrides with new long-term pitcure with
same index. Encoder can use this long-term picture as refence for
encoding.

This feature is mostly useful to avoid visual artifacts propagation in streaming use cases
when packet loss happens. Instead of requesting for IDR, client can request for use long-term
reference picture for encoding.
2020-01-09 11:44:55 +01:00
Guillaume Desmottes
de83fbd3a3 omxvideoenc: use subframe base class API
Use subframe base class support.
2019-12-22 05:43:40 +00:00
Varunkumar Allagadapa
a51123eea0 omxvideoenc: update qp-mode settings
Adds load-qp-absolute and load-qp-relative qp-modes
2019-12-19 13:46:47 +05:30
Shinya Saito
847fc08824 omxvideoenc: Add stride check for input buffer extraction
Stride of input buffer may be different from
that of omx input port even if both sizes are the same.
2019-12-11 15:53:29 +09:00
Guillaume Desmottes
2939a46dd2 omxvideoenc: pass padding requirements to ALLOCATION query
By passing the expected video buffer layout, the upstream producer
may be able to produce buffers fitting those requierements allowing
gst-omx to use dynamic buffer mode rather than having to copy each input
buffer.

This is particularly useful with v4l2src as it can request the capture
driver to produce buffers with the required paddings.
2019-11-05 17:30:21 +05:30
Guillaume Desmottes
611f37c2ae omxvideoenc: fix buffer size in debug log
Use the actual OMX buffer size rather than the info.size as OMX
may require larger buffer if the port requires some padding.
2019-11-02 14:56:53 +01:00
Guillaume Desmottes
d0bc3ed840 omxvideoenc: revert draining on ALLOCATION and DRAIN query
My latest patch introduces some regressions which I have no time to
debug properly at the moment so just revert it for now.
2019-09-23 13:50:54 +05:30
Guillaume Desmottes
df8ba87025 omxvideoenc: let encoder base class handle ALLOCATION query
Fixing a regression introduced in my previous patch
(7c40a91c31).

The ALLOCATION query needs to be handled by GstVideoEncoder (to call
propose_allocation()) so chain up the query handling rather than early
returning.
2019-09-17 13:13:23 +05:30
Guillaume Desmottes
7c40a91c31 omxvideoenc: drain encoder on ALLOCATION and DRAIN queries
Ensure that the encoder releases all its input buffers when requested by
upstream. Encoder input buffers may be shared with downstreaming (when
using dmabuf), upstream may then request the encoder to
drain when reconfiguring before destroying its buffers.

Also drain on ALLOCATION query as we already do in kmssink as that
notify of a format change.

Fix "decoder ! encoder" pipeline when decoding a file with different
resolutions on Zynq.
2019-09-05 09:22:32 +05:30
Guillaume Desmottes
35ffd018e2 omxvideoenc: log the full input format
Make it easier to debug dynamic format changes.
2019-09-04 10:41:46 +00:00
Shinya Saito
8d4d697a58 omxvideoenc: Remove unnecessary gst_video_frame_unmap() 2019-08-22 18:01:56 +09:00
Shinya Saito
d8d23bbb3e omxvideoenc: Unref frame of codec config buffer
After handling codec config, codec frame should be unreffed.
2019-07-11 19:02:20 +09:00
Guillaume Desmottes
cfeeb15b1e omxvideo: add debug infos to find_nearest_frame()
Those debug infos have proved to be very helpful when debugging
timestamp issues. They are often linked to gst-omx picking the wrong
frame when trying to map from OMX.
2019-06-17 09:17:14 +05:30
George Kiagiadakis
783e58fc48 omxbufferpool: refactor to allow memory sharing
One big restriction of the OMX buffer pool has always been
that the GstMemory objects were flagged with NO_SHARE.
This was because the buffer pool needed to be sure that when
a buffer returned to the pool, it would be safe to release the
OMX buffer back to OpenMAX.

With this change, this is no longer a restriction. What this
commit introduces is a new allocator that allows us to track
the GstMemory objects independently. Now, when a buffer returns
to the pool, it is not necessary for the memory to be released
as well. We simply track the memory's ref count in the allocator
and we return the OMX buffer back when the memory's ref count
drops to 0.

The reason for doing this is to allow implementing zero-copy
transfers in situations where we may need to copy or map a
certain region of the buffer. For instance, omxh264enc ! h264parse
should be possible to be zero-copy by using an OMX buffer pool
between them.
2019-04-25 09:09:40 +05:30
Tim-Philipp Müller
6ce69859c5 omx: fix autotools build for generic target
gstomxvideoenc.c:2874:7: error: "USE_OMX_TARGET_ZYNQ_USCALE_PLUS" is not defined, evaluates to 0 [-Werror=undef]
 #elif USE_OMX_TARGET_ZYNQ_USCALE_PLUS

Works on meson because it doesn't use -Wundef
2019-04-10 00:20:37 +01:00
Guillaume Desmottes
9ff4dc533f omxvideo: use GST_VIDEO_CAPS_MAKE() for template caps
Simplify the code and so we advertise the formats actually supported by
gst-omx.
2019-01-25 23:48:11 +00:00
Guillaume Desmottes
09bc1d630f omxvideoenc: validate cpb-size and initial-delay
cpb-size cannot be smaller than initial-delay.
2019-01-25 11:48:44 +01:00
Varunkumar Allagadapa
150e7271ab omxvideoenc: add adaptive gop-mode option
Added adaptive gop-mode option to ZYNQ_USCALE_PLUS encoder properties
2019-01-25 00:49:22 +00:00
Nicolas Dufresne
4f6d788999 omxvideoenc: Add dynamic framerate support
Instead of going through a full reset, try and change the framerate
config on the encoder when only the framerate have change.
2019-01-25 00:47:45 +00:00
Varunkumar Allagadapa
09ad21b26c omxvideoenc: Add dynamic IDR insertion support on zynq
As the pi, the zynq has its own API to request keyframe.
2019-01-09 19:37:36 +00:00
Guillaume Desmottes
3828d9769c omxbufferpool: fix early input buffer release
We used to track the 'allocating' status on the pool. It is used while
allocating so output buffers aren't passed right away to OMX and input
ones are not re-added to the pending queue.

This was causing a bug when exporting buffers to v4l2src. On start
v4l2src acquires a buffer, read its stride and release it right away.
As no buffer was received by the encoder element at this point, 'allocating'
was still on TRUE and so the the buffer wasn't put back to the pending
queue and, as result, no longer available to the pool.

Fix this by checking the active status of the pool instead of manually
tracking it down. The pool is considered as active at the very end of
the activation process so we're good when buffers are released during
the activation.
2018-12-21 17:16:31 +01:00
Nicolas Dufresne
a84badc5c4 omxvideoenc: Remove spurious locking
The method we call in the context of pushing a buffer are all thread
safe. Holding a lock would prevent input buffers from being queued while
pushing.

https://bugzilla.gnome.org/show_bug.cgi?id=715192
2018-09-10 17:09:11 -04:00
Nicolas Dufresne
d80504afcc omxvideoenc: Remove unneeded size check
We only enter this branch if nFilledLen > 0, there is not need
to check again.

https://bugzilla.gnome.org/show_bug.cgi?id=715192
2018-09-10 17:09:11 -04:00
Guillaume Desmottes
7be54ad091 omxvideoenc: implement dmabuf export on input buffers
Propose pool upstream so input buffers can be allocated by the port and
exported as dmabuf.

The actual OMX buffers are allocated when the pool is activated, so we
don't end up doing useless allocations if the pool isn't used.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
34bc02e397 omx: allow gst_omx_port_acquire_buffer() to not wait for buffers
Will be needed to implement GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
8efa0951ff turn GstOMXComponent to a GstMiniObject
Will use it for refcounting.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
3b92b22554 omxvideo{enc,dec}: stop calling shutdown() in change_state
This is no longer needed since we implemented close() vfuncs as the
encoder/decoder base class already take care of calling close() (which
is calling shutdown()) in its own change_state implementation.

We also move the shut down of the component from PAUSED_TO_READY to READY_TO_NULL.
By doing so upstream will have already deactivated the pool from the
encoder and so won't be preventing the OMX state change as the buffers
will all be released.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
092788a968 omxvideoenc: factor out gst_omx_video_enc_set_to_idle()
No semantic change. We'll have to use this when the input pool is
activated so we can allocate buffers.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
7d3b0cd1e8 omxvideoenc: factor out gst_omx_video_enc_deallocate_in_buffers()
Will add extra code when adding input buffer pool.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
f0964dfbdb omx: factor out gst_omx_port_set_dmabuf()
No semantic change. I also made the debug message a bit clearer.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes
626a481e01 omxvideoenc: pause component when flushing
As stated in the spec ("6.1.3 Seek Event Sequence") we should pause
before flushing.
We were pausing the decoder but not the encoder so I just aligned the
two code paths.

https://bugzilla.gnome.org/show_bug.cgi?id=797038
2018-08-28 15:52:14 +02:00
Guillaume Desmottes
a863893842 omxvideoenc: fix vertical padding in NV16 formats
My previous patch to calculate the vertical padding was always halfing
the height of the chroma plane which is incorrect for NV16 formats.

https://bugzilla.gnome.org/show_bug.cgi?id=796749
2018-07-13 09:54:48 +02:00
Guillaume Desmottes
1e9d7a6a23 omxvideoenc: include vertical padding in nFilledLen when copying
According to the OMX spec (3.1.3.7.1) nFilledLen is meant to include any
padding. We use to include the horizontal one (stride) but not the
vertical one if nSliceHeight is bigger than the actual height.

The calculated nFilledLen was wrong as it didn't include the padding
between planes.

https://bugzilla.gnome.org/show_bug.cgi?id=796749
2018-07-05 16:08:03 +02:00
Guillaume Desmottes
c8969b0dbe omxvideoenc: implement decide_allocation
Increase the number of output buffers by the number of buffers requested
downstream.
Prevent buffers starvation if downstream is going to use dynamic buffer
mode on its input.

https://bugzilla.gnome.org/show_bug.cgi?id=795746
2018-06-08 09:53:01 +02:00
Guillaume Desmottes
84483f3d7a omxvideoenc: always signal drain cond when stopping streaming loop
Similar change as the one I just did in omxvideodec.

https://bugzilla.gnome.org/show_bug.cgi?id=796207
2018-06-08 09:47:32 +02:00
Guillaume Desmottes
9a8e863862 omxvideodec/enc: add hack updating nBufferCountActual before allocating
The OMX specs states that the nBufferCountActual of a port has to default
to its nBufferCountMin. If we don't change nBufferCountActual we purely rely
on this default. But in some cases, OMX may change nBufferCountMin before we
allocate buffers. Like for example when configuring the input ports with the
actual format, it may decrease the number of minimal buffers required.
This method checks this and update nBufferCountActual if needed so we'll use
less buffers than the worst case in such scenarios.

SetParameter() needs to be called when the port is either disabled or
the component in the Loaded state.

Don't do this for the decoder output as
gst_omx_video_dec_allocate_output_buffers() already check
nBufferCountMin when computing the number of output buffers.

On some platform, like rpi, the default nBufferCountActual is much
higher than nBufferCountMin so only enable this using a specific gst-omx
hack.

https://bugzilla.gnome.org/show_bug.cgi?id=791211
2018-06-08 09:44:49 +02:00
Guillaume Desmottes
338ff34e5e omxvidee{enc,dec}: refresh input port definition after setting format
Setting the input format and the associated encoder/decoder settings
may also affect the nBufferCountMin of the input port.
Refresh the input port so we'll use up to date values in propose/decide
allocation.

https://bugzilla.gnome.org/show_bug.cgi?id=796445
2018-06-08 09:38:57 +02:00
Guillaume Desmottes
dc0ed29a62 omxvideoenc: add NV16 support
NV16 format wasn't supported on encoder input while it was on decoder
output.

https://bugzilla.gnome.org/show_bug.cgi?id=794175
2018-04-25 09:15:38 +02:00
Guillaume Desmottes
72cb1943da omxvideoenc: restore OMX default target-bitrate if requested by user
0xffffffff is the magic number in gst-omx meaning 'the default value
defined in OMX'. This works fine with OMX parameters which are only set
once when starting the component but not with configs which can be
changed while PLAYING.
Save the actual OMX default bitrate so we can restore it later if user
sets back 0xffffffff on the property.

Added GST_OMX_PROP_OMX_DEFAULT so we stop hardcoding magic numbers
everywhere.

https://bugzilla.gnome.org/show_bug.cgi?id=794998
2018-04-23 10:41:10 +02:00