Commit graph

190 commits

Author SHA1 Message Date
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
Guillaume Desmottes
542faf0f36 omxvideoenc: use gst_omx_video_enc_set_bitrate() when setting bitrate in set_format
We weren't using the usual pattern when re-setting the bitrate:
- get parameters from OMX
- update only the fields different from 0xffffffff (OMX defaults)
- set parameters

Also added a comment explaining why we re-set this param.

https://bugzilla.gnome.org/show_bug.cgi?id=794998
2018-04-23 10:35:48 +02:00
Guillaume Desmottes
256f77b621 omxvideoenc: factor out gst_omx_video_enc_set_bitrate()
No semantic change, I'm about to re-use this function in set_format().

https://bugzilla.gnome.org/show_bug.cgi?id=794998
2018-04-23 10:35:48 +02:00
Guillaume Desmottes
e1a149f3d5 omxvideoenc/dec: fix handling of component enabling failing
- Report the error from OMX if any (OMX_EventError)
- If not report the failing to the application (GST_ELEMENT_ERROR)
- return GST_FLOW_ERROR rather than FALSE
- don't leak @frame

https://bugzilla.gnome.org/show_bug.cgi?id=795352
2018-04-18 14:01:39 +02:00
Guillaume Desmottes
dec9c8c385 omxvideoenc: remove duplicated debug message
We already have the exact same message at the beginning of
gst_omx_video_enc_handle_frame(). Having it twice is confusing when
reading/grepping logs.

I kept the earlier one to keep the symetry with
gst_omx_video_dec_handle_frame().

https://bugzilla.gnome.org/show_bug.cgi?id=794897
2018-04-02 15:16:33 +02:00
Guillaume Desmottes
530a7537cf omxvideoenc: add 'roi' qp-mode on zynqultrascaleplus
New QP mode used to handle ROI metadata.

https://bugzilla.gnome.org/show_bug.cgi?id=793696
2018-03-28 10:09:20 +02:00
Nicolas Dufresne
4e9dca0761 omxvideoenc: Don't drop the frame on empty payload
This otherwise may lead to "No reference frame found" warning.
2018-03-05 13:50:08 -05:00
Guillaume Desmottes
f861ad2bc5 videoenc: don't set stride padding to 0 when copying frames
Padding can be left undefined there is no point filling it with 0.

https://bugzilla.gnome.org/show_bug.cgi?id=793694
2018-02-28 08:32:26 -05:00
Guillaume Desmottes
ea2df994f3 add support for NV12_10LE32 and NV16_10LE32 on zynqultrascaleplus
The encoder and decoder on zynqultrascaleplus support these new 10 bits
format.

https://bugzilla.gnome.org/show_bug.cgi?id=793694
2018-02-28 08:32:26 -05:00
Guillaume Desmottes
d1ffc97ddd omxvideoenc: factor out gst_omx_video_enc_nv12_manual_copy()
No semantic change, I'm going to re-use it to copy the NV12_10LE32
format.

https://bugzilla.gnome.org/show_bug.cgi?id=793694
2018-02-28 08:32:26 -05:00
Guillaume Desmottes
f2570512cf omxvideoenc: display the computed buffer size when configuring input
https://bugzilla.gnome.org/show_bug.cgi?id=793694
2018-02-28 08:32:15 -05:00
Guillaume Desmottes
6921568161 videoenc: implement ROI on zynqultrascaleplus
Check input buffers for ROI meta and pass them to the encoder by using
zynqultrascaleplus's custom OMX extension. Also add a new
"default-roi-quality" in order to tell the encoder what quality level
should be applied to ROI by default.

https://bugzilla.gnome.org/show_bug.cgi?id=793696
2018-02-21 12:31:39 -05:00
Guillaume Desmottes
a8c3996317 omxvideoenc: remove GST_PARAM_MUTABLE_PLAYING from 'max-bitrate' property
This property isn't actually mutable in the PLAYING state.

https://bugzilla.gnome.org/show_bug.cgi?id=793458
2018-02-21 11:31:13 +00:00
Guillaume Desmottes
2d3816fabc omxvideoenc: protect target_bitrate with the object lock
The 'target-bitrate' property can be changed while PLAYING
(GST_PARAM_MUTABLE_PLAYING). Make it thread-safe to prevent concurrent
accesses between the application and streaming thread.

https://bugzilla.gnome.org/show_bug.cgi?id=793458
2018-02-21 11:24:52 +00:00
Guillaume Desmottes
e3396210d2 omxvideoenc: add zynqultrascaleplus specific properties
https://bugzilla.gnome.org/show_bug.cgi?id=792528
2018-01-30 11:51:10 +00:00
Guillaume Desmottes
d14b9ffa64 omxvideoenc: document unit of target-bitrate property
nTargetBitrate and nEncodeBitrate are defined in bits per second in the
OMX spec.

https://bugzilla.gnome.org/show_bug.cgi?id=792528
2018-01-30 11:51:10 +00:00
Guillaume Desmottes
6c57d06ee1 omxvideoenc: expose chroma format and bit depth in output caps
As we added in the parser (bgo#792039) expose the chroma and bit
depth information in output caps.

https://bugzilla.gnome.org/show_bug.cgi?id=792040
2018-01-30 09:23:59 +00:00
Guillaume Desmottes
1990580d79 omxvideoenc: factor out get_output_caps()
No semantic change so far.

https://bugzilla.gnome.org/show_bug.cgi?id=792040
2018-01-30 09:23:59 +00:00
Guillaume Desmottes
9f87b987ef omxvideoenc: implement dmabuf import on zynqultrascaleplus
The Zynq UltraScale+ encoder implements a custom OMX extension to
directly import dmabuf saving the need of mapping input buffers.

This can be use with either 'v4l2src io-mode=dmabuf' or an OMX video
decoder upstream.

https://bugzilla.gnome.org/show_bug.cgi?id=792361
2018-01-29 15:21:02 +00:00
Guillaume Desmottes
0c5bbbb6ca omxvideoenc: drop late input frames if QoS is enabled
Make use of the new GstVideoEncoder QoS API to drop late input frames. This may
help a live pipeline to catch up if it's being late and all frames end up
being dropped at the sink.

https://bugzilla.gnome.org/show_bug.cgi?id=792783
2018-01-22 17:04:27 +00:00
Guillaume Desmottes
5fa96cab7b omxvideoenc: early return in fill_buffer() if something goes wrong
If something goes wrong while trying to manually copy the input buffer,
the 'break' was moving us out of the 'for' loop but not out of the switch block.
So we ended up calling gst_video_frame_unmap() a second time (raising
assertions) and returning TRUE rather than FALSE.

Reproduced with a WIP zynqultrascaleplus OMX branch reporting wrong
buffer sizes and so triggering this bug.

https://bugzilla.gnome.org/show_bug.cgi?id=792167
2018-01-07 14:20:56 +00:00
Guillaume Desmottes
533ee7fadc omxvideoenc: use dynamic buffer mode on input if possible
If the OMX component supports dynamic buffer mode and the input buffers
are properly aligned avoid copying each input frame between OMX and
GStreamer.

Tested on zynqultrascaleplus and rpi (without dynamic buffers).

https://bugzilla.gnome.org/show_bug.cgi?id=787093
2017-12-14 09:00:31 +00:00