Commit Graph

5809 Commits

Author SHA1 Message Date
Martin Pulec
d2f8f2df8b lavc video: avoid nullptr dereference
When `--param keep-pixfmt` is used but the encoder doesn't produce a
packet (AVPacket.size == 0), nullptr dereference can occur.

fixes CID 416601
2023-08-22 08:57:56 +02:00
Martin Pulec
4e16bab401 DELTACAST: VideoMaster 6.21 compat
VHD_BOARDTYPE_HDMI is neither deprecated in 6.21, nor
VHD_BOARDTYPE_HDMI_DEPRECATED is defined anymore.
2023-08-21 12:08:12 +02:00
Martin Pulec
989d732d80 lavd video: fixed parsing workflow
(see also previous 2 commits)

Fixed according to [FFmpeg decode video example] - the parser needs
final call with zero long buffer to flush the frame.

\+ prefix eventual parser error with identifying prefix

[FFmpeg decode video example]:
https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c
2023-08-21 11:34:48 +02:00
Martin Pulec
6e9a4142fd Revert "lavd video: don't print false positive errs"
This reverts commit d4be2d97b5.

The fix was not correct, because it just hided the root of the problem -
the av_parser_parse2 needs final call with buf_size == 0 to flush last
frame. Otherwise it will remain in the queue, effectivelly adding a
delay by one frame, because the particular frame will get flushed when
processing next frame.

See also:
<https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c>
2023-08-21 11:34:45 +02:00
Martin Piatka
94740e221c screen_pw: Fix out_ptr segv
g_variant_get is a varargs function, which doesn't seem to play well
with out_ptr. Call the type conversion operator explicitly
2023-08-18 15:33:14 +02:00
Martin Piatka
1e6bbbee9f screen_pw: Replace frame_wrapper by unique_ptr 2023-08-18 15:29:27 +02:00
Martin Pulec
d4be2d97b5 lavd video: don't print false positive errs
do not print errors like:

    uv -d dummy -t testcard -c libavcodec
    [lavd] Error while decoding frame (rc == 42836): Error number 42836 occurred.

when decoder returns empty packet ("error" code acutally indicated number
of consumed bytes).
2023-08-18 12:57:00 +02:00
Martin Pulec
732441f07a cineform dec.: removed needless frame_seq storing 2023-08-18 12:25:41 +02:00
Martin Pulec
12364a9025 lavd video: removed handling of dropped VP8 frms
removed skipping P frames after missing P frame in VP8

This doesn't seem to be needed anymore and removing it simplifies the
code a bit. Moreover, if frame drops was the case, now frames, that
have been skipped until now will be presented, potentially reducing
twitching.
2023-08-18 12:25:41 +02:00
Martin Pulec
2179179b77 video compress sync frame API: follow tile API
Updated sync frame API to match updated tile API as defined by the
commit  e9a407ad.

Note: none of 2 compression using this API currently need reading
additional frames.
2023-08-18 12:25:40 +02:00
Martin Pulec
3943cc739d video compress async tile: removed frame erasing
There was a comment that the frame is no longer valid, which was a bit
misleading, because the the tiles hold reference to that frame but do
not modify it in any way.

Also removed assigning NUL altogether - it was not much functional,
since it will be released soon thereafter, anyways, so it is possibly
not much needed.
2023-08-18 12:25:40 +02:00
Martin Pulec
c57f2fc57b lavc video: read frames consecutively
Read and send the frames consecutively, even though the encoder presents
them at once (see previous commit description).
2023-08-18 12:25:33 +02:00
Martin Pulec
690244686a Compress sync tile API: fetch additional frames
Modified the API in order to fetch additional frames from compression
with iterative passing NULL pointer (similarly as for audio).

This is particularly usefull when inter-frame compression outputs 2
frames at once, which can occur when B-frames would be enabled. It,
however sometimes happen even when B-frames are disbled, eg. with
h264/hevc_mf HW encoder on AMD (AMDh265Encoder; see commit d70e2fb3c).

Please note that semantic of passing NUL frame is different in this API
to that in async API, where it works as a poison pill.
2023-08-18 11:07:57 +02:00
Martin Pulec
f035e43ac5 lavc video: store/restore metadata reliably
In case that the encoder buffers frame for whatever reason (NVENC
with delay, hevc_mf sometimes batching 2 frames /returned frames count
0,1,2,0,1,2.../) so that output frame doesn't match the currently
enqueued onei, metadata would be incorrect (currently enqueued copied
to non-matching dequeued one).
2023-08-16 16:10:48 +02:00
Martin Pulec
ffa749eb4f lavd video: do not fail if parser init fails
some codecs (FFV1, HFYU) do not have parsers
2023-08-16 15:38:14 +02:00
Martin Pulec
e5b3f5ffa6 lavd video: do not crash if FFV1/HFYU init fails 2023-08-16 15:38:13 +02:00
Martin Pulec
d70e2fb3c1 lavd video: parse the received video buffer
use AVParser for the received compressed data

This is particularly useful when encoder produces frames glued together -
it shouldn't be the case most of the times, since UG programmatically
disables B-frames but there can be some not handled encoders, notably
currently problematic _hevc_mf_ on AMD (AMDh265Encoder).

The FFmpeg native H.264 and HEVC decoders are particuraly sensitive to
passing 2 encoded frames at once, breaking the picture with errors like:

    [lavc hevc @ 0x61c590004d80] Two slices reporting being the first in the same frame.
    [lavc hevc @ 0x61c590004d80] Could not find ref with POC 7

or

     [lavc h264 @ 0x6ee80c004d80] Frame num change from 3 to 4
     [lavc h264 @ 0x6ee80c004d80] decode_slice_header error

After this fix, decoding is correct. Excess frames are dismissed but
decoding works and more importantly, user is informed what is the
problem.
2023-08-15 16:27:06 +02:00
Martin Pulec
4fbe76085e lavd_flush: print error msgs, not only numbers 2023-08-15 16:26:59 +02:00
Martin Pulec
aaf8ff9771 lavd decode: H.264/HEVC - read forced props early
Moved reading eventual forced props at the beginning. Previously, it
must have been waited until first IDR, which is unecessary, because the
custom NAL unit is appended to every frame.

Also it is not needed to read it in all compressions since it is
codec-specific and thus as implemented now, it is only applicable to
H.264/HEVC.
2023-08-15 15:39:35 +02:00
Martin Pulec
f36384247a lavd video: moved usable decoder select to func
Mostly refactor only (just changed bound-checking if-s to assert because
the condition should not happen - it is not depending on user input).
2023-08-15 15:39:31 +02:00
Martin Piatka
e58c6a98f0 conference: fps is optional 2023-08-15 13:08:13 +02:00
Martin Piatka
9e92834ea1 rpi4_out: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
6679bc7de1 conference: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
ddf64f32cf hd-rum-recompress: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
f6951ab4b3 audio/filter/playback: Use out_ptr 2023-08-15 13:08:11 +02:00
Martin Piatka
6be121097d screen_pw: Use unique GVariant insted of ScopeExit 2023-08-15 13:08:11 +02:00
Martin Piatka
f1f1b683d0 misc: Add out_ptr implementation
Useful for setting unique_ptr via plain ptr setters (setter(void **))
2023-08-15 13:08:11 +02:00
Martin Piatka
f1a6325b0d screen_pw: Replace custom instrumentation timer 2023-08-15 13:08:11 +02:00
Martin Pulec
199a67e98d export: small improvements
- simplified a bit
- create_anonymous_dir->create_implicit_dir (obviously, the name
_export.<date>_ is not much anonymous)
2023-08-15 09:05:56 +02:00
Martin Pulec
f0f7140e60 fixed Coverity ID 4165{59,60} 2023-08-15 08:25:49 +02:00
Martin Pulec
d035fcefdf platform_mkdir->mkdir: use POSIX syntax
Use rather defined function as mkdir(3p) is, even though there is needed
a compat for MSW.

+ removed some strtok_r undef, which should no longer be needed (see
also commit 6c6253c9)
2023-08-14 16:06:16 +02:00
Martin Pulec
1656f705e4 dump disp.: use date/time instead of timestamp
Use ISO 8601 date/time for dump directory name instead of seconds since
epoch. Basic format is used because in the extended, the colons delimiting
the time interfere with _export_ options delimiter.
2023-08-14 16:06:16 +02:00
Martin Pulec
08f083a107 NAL_(?!HEVC) -> NAL_H264
Since H.264 and HEVC uses different constants even for the same (named)
NAL type (eg. AUD has 9 in H.264 but 35 in HEVC), replace NAL_ prefix,
that were implilcitly meant or H.264 with NAL_H264.
2023-08-14 16:06:16 +02:00
Martin Pulec
5a9bfd1e53 video lavd: skip leading AUD NALU for HEVC
see the commit d2fedd72 for details
2023-08-14 16:06:16 +02:00
Martin Pulec
4f0fa9f5ab lavc video: small updates
- moved constexpr definitions to the (anonymous) namespace (allows
eg. detection of unused vars)
- do not import the whole std namespace
2023-08-14 16:06:16 +02:00
Martin Pulec
7e2d50af66 lavc video: set the preset threshold as px/sec
Set the threshold, that is used by some to select the preset, as a
constant in MPix/sec.
2023-08-14 16:06:16 +02:00
Martin Pulec
32b0f00e8f lavc video: removed explicit preset
removed explicit preset handling

Actually with current encoder set, having the preset is rather exceptional
- some codecs to not recognize the presets with any encoder, eg. MJPEG,
Other have a different keyword like "usage" (VP9). Even with eg. H.265
different encoders use different keywords ("scenario" for QSV and MF) etc.

So give up explicit handling of presets - those (or those under different
names) can be configure in codec specific configure callbacks.

There is also a change that the default preset is always set, previously
not if _preset_ was detected in cmdline params. This doesn't seem to be
a problem, however. The user-specified options are set after the
codec-specific configure callback so that it should override the default.
2023-08-14 16:06:15 +02:00
Martin Pulec
2d0d292f1b lavc video: support for MS MFT
set default values

Seting hw_encoding=1 (force) - otherwise, the API seems to be using SW
encode. Moreover, using _hevc_mf_ fails to init (at least in some setups)
while the GPU supports that so that enforcing that makes it work.
2023-08-14 16:06:15 +02:00
Martin Pulec
7c44a85996 lavc video: do not try already tried AV pixfmts
When trying to init _any_ codec (for the further use with swscale), do not
try already tried pixfmts. Plus do not print that we will try with swscale
when there is no AV pixfmt left (it is a bit misleading in the UG output).
2023-08-14 16:06:15 +02:00
Martin Pulec
aed1af1c9c lavc video: refactor SWS fallback pixfmt select
Moved trying remaining pix_fmts to a sepaarate function.
2023-08-14 16:06:15 +02:00
Martin Pulec
0017e57134 compat/qsort_s.h: do not require include 1st
Do not enforce the file to be either included before stdlib.h or stdlib.h
to be using __STDC_WANT_LIB_EXT1__ = 1. The bound checking API is
currently nowhere implemented, anyways, and we may use system native secure
qsort implementation (qsort_r in *NIX, MS variant of qsort_s).
2023-08-14 16:06:15 +02:00
Martin Piatka
d20b99a8d5 lavd: Allow hw accel type to be explicitly specified 2023-08-14 10:27:33 +02:00
Martin Pulec
d2fedd724c video lavd: skip leading AUD NALU for H.264
H264_mf encoder (Windows) produces single byte AUD unit prior to SPS
NALU. Because only first NALU was evaluated to assess whether to pass
the frame further, it took 10 frames (+ additional 10 for probe) before
decoding started before it surrendered the checks.
2023-08-11 11:44:53 +02:00
Martin Pulec
72ab033473 rtpdec_h264: added function to get NALU name 2023-08-11 11:43:27 +02:00
Martin Pulec
8c5f0a6645 video lavd: refactor H264/HEVC decode wait 2023-08-11 10:21:20 +02:00
Martin Pulec
2afa6f2554 removed undefined HAVE_ALIGNED_ALLOC macros
Also do not include malloc.h for Windows - it is already there but it is
not a good practice to include headers in the config_*.h files, anyways
(the actual functions are declared if any of malloc.h or stdlib.h is
included, while the second should be included explicitly if wanting
dynamic memory management, anyways).
2023-08-10 12:04:09 +02:00
Martin Pulec
c0db7d1999 added strerror_s compat
Encounter using standard strerror_s() instead of home-grown
replacement. MSW already include C11-compatible strerror_s()
implementation (although it doesn't advertise __STDC_LIB_EXT1__).
XSI version of strerror_r() is mostly compatible (except of argument
order).

Using standard functions should be more convenient than custom workarounds
(even if there is needed a compat macro).
2023-08-10 12:04:03 +02:00
Martin Pulec
6c6253c9e2 removed strtok_r compat (Win)
Mingw-w64 implements strtok_r() and the macro was commented-out, anyways
2023-08-10 08:25:42 +02:00
Martin Pulec
34c48a15ca configure: remove check for if_nametoindex
if_nametoindex is present in both POSIX and Windows (since Vista)

+ print the error message as error_msg - debug_msg there was rather a mistake
2023-08-10 08:01:42 +02:00
Martin Pulec
eef553d9aa export create_anonymous_dir: small rewrite
removed non-thread safe functions + other small improvements
2023-08-10 08:01:36 +02:00