Commit Graph

109 Commits

Author SHA1 Message Date
Martin Pulec
fc742b69de lavc_common.h: do not define R,G,B globally
When included prior to (Mingw-W64) windows.h, it causes compilation
fail, because "R" is used as a param name in transitively included
avx512fp16intrin.h.
2023-09-05 09:37:07 +02:00
Martin Pulec
4fbe76085e lavd_flush: print error msgs, not only numbers 2023-08-15 16:26:59 +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 Pulec
ef751e16ff print_decoder_error: no extra space after mod_name
mod_name usually already contains trailing space (eg. "[lavd] ") so do
not produce an extra one.

+ reindent
2023-06-15 11:29:58 +02:00
Martin Pulec
2961fe2f44 lavc video: print used thread count and mode 2023-05-17 11:48:08 +02:00
Martin Pulec
59a1cb1b24 lavc_common.h: removed further compat
AV_ prefix was added already in 2015 (FF commit def97856)
2023-05-05 11:34:13 +02:00
Martin Pulec
f7e29f1d81 remove more FFmpeg compat
according to FFmpeg commit 80154b1b, the current cut-off in UG was lavc
version 57.107.100 (incl), which corresponds to lavu 55.78.100 (incl).
2023-05-05 10:25:46 +02:00
Martin Pulec
3a8440a650 fixed build of blank without libavcodec 2023-05-05 08:50:09 +02:00
Martin Pulec
21ce56d42f lavc common: removed compat + moved func to .c
Removed some old FFmpeg compat functions that cannot be used, since UG
won't compile with that version anyways (even newer compat was already
removed).

+ moved some function definitions from header to implementation file
  (perhaps needlessly in header and it worsens readibility)
2023-05-02 15:22:57 +02:00
Martin Pulec
04a0bf581b removed ATTRIBUTE macros
This was unnecessary compat macro, since we always build with a compiler
that understands __attribute__ except of the AJA module in MSW, which
uses MSVC compiler
2023-05-02 15:22:55 +02:00
Martin Pulec
3ec7d9fd88 comparators: fix descending last-resort sorting
As a last resort sort tie-break, codec_t value was used but the sorting
was actually descending. It is perhaps more natural to have it ascending
(although not so important).
2023-03-07 08:28:24 +01:00
Martin Pulec
602d75e9cd from_lavc_vid_conv: fixed inverted operator 2023-03-02 11:13:59 +01:00
Martin Pulec
78000712b0 libavcodec: lavc_compare_convs - fixed ordering
Fixed wrong ordering in rare cases, eg.:

1. R10k->UYVY->yuv444p
2. R10k->UYVY->yuv422p

For both conversion chain, the same property 10b 4:2:2 is selected. But
as a tie-break, R10k is compared with resulting AVPixelFormat's
properties, winning #1 because seemingly keeping 4:4:4 subsampling, not
reflecting the degradation in chain.

To fix it up, use for the second comparison the minimum of src pixfmt
desc and the conversions' chain (for both are the same as mentioned in
previous paragraph).

+ improved debugging (in debug2, print comparison results & print
  property of the uv->uv-only conversions)
2023-02-23 09:06:48 +01:00
Martin Pulec
90aa548c02 lavc: allow also depth and rgb/yuv specification
This will allow user more control over compression if requiring a
different properties than would default sorting select.

This is mostly to avoid user specifying '--param lavc-use-codec', which
is not supported, anyways.
2023-02-22 10:57:39 +01:00
Martin Pulec
9c14552afd to_lavc_vid_conv: use struct for enforced params 2023-02-22 09:42:05 +01:00
Martin Pulec
717b575d87 qsort_s comparator compat macro
comparators can be defined utilizing the macro to avoid fiddling with
ifdefs

+ use it in lavc conversions
2023-02-21 10:46:47 +01:00
Martin Pulec
1f34ebc571 lavd: split convert (+sws) reconf and conv
configure av_to_uv_conversion and swscale only once if needed

This has on one hand performance advantages. More importantely,
from_lavc_vid_conv now generates a warning on depth/subsampling
degradation. If it is the case, without this change, output would be
spammed by that warning for every decoded frame.

Steps to reproduce the fixed behavior:

    uv -t testcard:codec=R10k -d dummy:codec=v210 -c libavcodec
2023-02-21 10:28:05 +01:00
Martin Pulec
11fe526619 from_lavc_vid_conv.c: memcpy_data can be unused 2023-02-21 10:28:04 +01:00
Martin Pulec
f943807b66 lavd: also check if we are not degrading
Similarly to lavc, print warning if we are degrading format somewhere in
chain.
2023-02-21 10:28:04 +01:00
Martin Pulec
e720acba5e lavc: print a warning if there is quality degradation 2023-02-21 10:28:04 +01:00
Martin Pulec
e9d91e778f to_lavc_vid_comp: improved av pixfmt comparison
Improved/fixed AV pixfmt comparison algorighm (get_available_pix_fmts).

If UV->UV->AV is involved, the lower bound of properties (bitrate,
subsampling) is used for the comparison. This would prevent eg.
conversion chain v210->UYVY->10b to be incorrectly treated as 10 bit
(because there is 8 bit format in the chain).
2023-02-21 10:28:04 +01:00
Martin Pulec
014279af62 pixfmt_desc + compare_pixdesc: removed identity
removed .id member from struct pixfmt_desc and the comparator

compare_pixfmt is not usually used directly as a comparator itself but
called from within another comparator. If 2 pixels format have the same
properties, the caller should rather decide by itself if there is some
other metrics to conside or just compare according to identity in the
end.
2023-02-21 10:28:04 +01:00
Martin Pulec
f7a070f899 to_lavc_vid_conv: small improvements
- renamed in_frame - now it is actually out_frame from our perspective
- same_linesizes - exit early + doxy documentation
- other docuementation improvements
2023-02-21 10:28:04 +01:00
Martin Pulec
c4c3ffd5dc lavc: fixed test
changed prototype of some functions:

- to_lavc_vid_conv - accept (char *) instead of (struct video_frame)
- get_av_pixfmt_details - (enum AVPixelFormat) instead of int

+ make to_lavc_vid_conv.c partially C++ compatible (I attempted first to
  include it as was it libavcodec.cpp), so leave it (just in case)
2023-02-21 10:28:04 +01:00
Martin Pulec
bd994f4bfd lavc: encapsulate input conversion
Handle conversion to codec supported input pixel format entirely in
to_lavc_vid_conv.

+ removed AVPixelFormats (both codec input and sws input) from struct
  (no longer needed)
+ cleanup - set sws pointer to NULL (prevent potential double free)
2023-02-21 10:28:04 +01:00
Martin Pulec
67e6326434 simplify get_av_pixfmt_details
YUV is always limited rante BT.709, RGB full range. Thus it doesn't need
to be in the conversion table for every one pixfmt. Also UG pixfmt was
actually useless in the prototype.
2023-02-21 10:28:03 +01:00
Martin Pulec
710c667f88 to_lavc_vid_conv.c: removed no longer used func 2023-02-21 10:27:47 +01:00
Martin Pulec
1b0a28cd09 lavc: refactor
- moved conversion related functions to to_lavd_vid_conv.c
- removed struct uv_to_av_conversion from to_lavd_vid_conv API
2023-02-21 10:07:04 +01:00
Martin Pulec
240f512b7e from_lavc_vid_conv: removed unneeded memsets
The relevant members are already empty-initialized by the caller.

For some reason, this fixes the test crash:

     https://github.com/CESNET/UltraGrid/actions/runs/4220022764/jobs/7325933580
2023-02-20 14:34:23 +01:00
Martin Pulec
467056530c lavd vid conv: added some mappings
FFmpeg's Y210 and Y212 can be directly mapped to UG Y216 (have
just lower bits unused). This shouldn't, however, be given directly to
uv_to_av_pixfmts, because the mapping isn't 1:1. If it would, for
encoder, eg. the conversion Y216->Y210 will be considered as lossless
but it is reducing depth 16->10 b. So added just dummy conversions for
them.

Also removed RG48 and RGB dummy conversions to corresponding AV pixel
formats. This is the opposite case as mentioned in previous paragraph,
the correspondence is 1:1. Also the conversion/memcpy is dispatched
directly in av_to_uv_convert().
2023-02-10 10:02:34 +01:00
Martin Pulec
b7af377936 lavd: accept EAGAIN as success when flushing
this is consistent with FFmpeg examples

+ move common audio and video code to lavc_common.c
2023-02-09 11:50:31 +01:00
Martin Pulec
cac1d11190 updated copyrights of files changed in 2023 2023-02-09 09:19:50 +01:00
Martin Pulec
566cb53bcf added gbrp1{0,2,6}le_to_rg48
closes GH-290
2023-02-06 09:42:18 +01:00
Martin Pulec
508224ee78 av_to_uv_convert: added debug timers
Until now only aggregate time of pixfmt change was printed. But when
there will be more indirect conversions (eg. XV30->Y416->R12L), it would
be useful to eventually split the decode times to assess a bottleneck.
2023-02-03 16:10:52 +01:00
Martin Pulec
68f462e600 swscale: option thread is actually threads
Fixed incorrect option name when settin thread mode to swscale.
2023-02-03 09:23:44 +01:00
Martin Pulec
efb1e7a222 added y210_to_{uyvy,v210,y416}
+ fixes
2023-02-01 17:10:18 +01:00
Martin Pulec
2e5efa86ab added v210_to_y210 2023-02-01 15:50:05 +01:00
Martin Pulec
14a4532588 from_lavc_vid_conv: added from vuy[ax] convs 2023-02-01 13:55:35 +01:00
Martin Pulec
d00b53ef12 reverted back wrong change from HEAD^^
the pitch should be actually the linesize
2023-01-31 13:47:39 +01:00
Martin Pulec
9e1df595e1 fixed a crash when R10k % 64 != 0
fixed crashing:

    uv -t testcard:codec=R10k:size=3600x2160 -d dummy -c \
        libavcode:encoder=libx265:disable_intra_refresh --param \
        force-lavd-decoder=hevc_qsv,decoder-use-codec=R10k

The problem was that 3600 width rounds up to 3648 pixel for which there
was not allocated enough space (even with MAX_PADDING, which doesn't
protect against such cases).

vc_get_size() should be used instead of vc_get_linesize in all this
cases.
2023-01-31 12:23:56 +01:00
Martin Pulec
c87e9a335e lavd: allow AV and UV conversions
Allow to use AV conversion and consequently UG pixfmt conversion.

This should avoid using falling back to swscale conversion in most of
the cases. Moreover, it can be not only a fallback behavior but also a
generailzation reducing the need to write AV conversion to plenty of UG
pixfmts.
2023-01-30 16:11:44 +01:00
Martin Pulec
596703395b av_to_uv_conversions: do not NULL terminate 2023-01-30 16:09:16 +01:00
Martin Pulec
787c03abd5 removed av_to_uv_conversion::native 2023-01-30 14:53:20 +01:00
Martin Pulec
c3bd845ef8 pick_av_convertible_to_ug: rewritten
Default to UG-mapped pixel formats if there are decoder. If not, pick
any conversion (but without respect to "native" attribute now).
2023-01-30 14:53:20 +01:00
Martin Pulec
44e3a17d48 pick_av_convertible_to_ug: consider mapped formats
If UG pixel format happens to be eg. UYVY, swscale could convert
directly to that.
2023-01-30 14:53:20 +01:00
Martin Pulec
189eb74093 from_lavc_vid_conv: avoid av_to_uv_conversions::native
Do not use av_to_uv_conversions::native to select best ultragrid codec_t
matching AVPixelFormat.

This will allow deploy policies (to keep color space or bit depth) and
doesn't require developer to pick one <codec_t,AVPixelFormat> pair as
"privileged".
2023-01-30 14:53:20 +01:00
Martin Pulec
f7009a7316 lavc: AVPixelFormat subs. getter to lavc_common
Renamed get_subsampling to av_pixfmt_get_subsampling (the former
overloaded the function for codec_t) and moved to lavc_common.
2023-01-30 14:53:19 +01:00
Martin Pulec
a22ae3e6b0 don't wrap av_to_uv_conversions with function
The structure is no longer part of the API and the indirection is
unneeded. On the other hand, its size could not have been possible to
query.

+ use enum AVPixelFormat in the struct instead of int
+ removed unneeded headers from module header
2023-01-30 14:53:19 +01:00
Martin Pulec
f42ad235e2 from_lavc_vid_conv: enable mapped+uv conversion 2023-01-30 14:53:19 +01:00
Martin Pulec
95549473ac lavd: moved memcpy handling 2023-01-30 14:53:19 +01:00