![]() |
UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
|
#include <assert.h>#include <limits.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include "debug.h"#include "host.h"#include "lib_common.h"#include "libavcodec/from_lavc_vid_conv.h"#include "libavcodec/lavc_common.h"#include "libavcodec/lavc_video.h"#include "rtp/rtpdec_h264.h"#include "rtp/rtpenc_h264.h"#include "tv.h"#include "utils/macros.h"#include "video.h"#include "video_codec.h"#include "video_decompress.h"#include "hwaccel_libav_common.h"#include "hwaccel_vaapi.h"#include "hwaccel_vdpau.h"#include "hwaccel_videotoolbox.h"
Go to the source code of this file.
Classes | |
| struct | decoder_info |
| struct | state_libavcodec_decompress |
| struct | state_libavcodec_decompress::state_libavcodec_decompress_sws |
Macros | |
| #define | MOD_NAME "[lavd] " |
| #define | SELECT_PIXFMT(pixfmt) |
Enumerations | |
| enum | { MAX_PREFERED = 10 , MAX_DECODERS = MAX_PREFERED + 1 + 1 , DEC_LEN = MAX_DECODERS + 1 } |
Functions | |
| ADD_TO_PARAM ("force-lavd-decoder", "* force-lavd-decoder=<decoder>[:<decoder2>...]\n" " Forces specified Libavcodec decoder. If more need to be specified, use colon as a delimiter.\n" " Use '-c libavcodec:help' to see available decoders.\n") | |
| ADD_TO_PARAM ("lavd-accept-corrupted", "* lavd-accept-corrupted[=no]\n" " Pass corrupted frames to decoder. If decoder isn't error-resilient,\n" " may crash! Use \"no\" to disable even if enabled by default.\n") | |
| ADD_TO_PARAM ("lavd-thread-count", "* lavd-thread-count=<thread_count>[F][S][n][d]\n" " Use <thread_count> decoding threads (0 is usually auto).\n" " Flag 'F' enables frame parallelism (disabled by default), 'S' slice based, can be both (default slice), 'n' for none; 'd' - disable low delay\n") | |
| ADD_TO_PARAM ("use-hw-accel", "* use-hw-accel[=<api>|help]\n" " Try to use hardware accelerated decoding with lavd " "(NVDEC/VAAPI/VDPAU/VideoToolbox).\n" " Optionally with enforced API option.\n") | |
| static void | change_pixfmt (AVFrame *frame, unsigned char *dst, av_to_uv_convert_t *convert, codec_t out_codec, int width, int height, int pitch, int rgb_shift[static restrict 3], struct state_libavcodec_decompress_sws *sws) |
| static int | check_av_opt_set (void *state, const char *key, const char *val) |
| static void | check_duration (struct state_libavcodec_decompress *s, double duration_total_sec, double duration_pixfmt_change_sec) |
| print hint to improve performance if not making it | |
| static _Bool | check_first_sps_vps (struct state_libavcodec_decompress *s, unsigned char *src, unsigned int src_len) |
| static bool | configure_with (struct state_libavcodec_decompress *s, struct video_desc desc, void *extradata, int extradata_size) |
| static bool | decode_frame (struct state_libavcodec_decompress *s, unsigned char *src, int src_len) |
| static void | deconfigure (struct state_libavcodec_decompress *s) |
| static int | drm_prime_init (struct AVCodecContext *s, struct hw_accel_state *state, codec_t out_codec) |
| static enum AVPixelFormat | get_format_callback (struct AVCodecContext *s, const enum AVPixelFormat *fmt) |
| static bool | get_usable_decoders (enum AVCodecID avcodec_id, const char *const preferred_decoders[static MAX_PREFERED+1], const AVCodec *usable_decoders[static DEC_LEN]) |
| static void | handle_lavd_error (const char *prefix, struct state_libavcodec_decompress *s, int ret) |
| static void | jpeg_callback (void) |
| static decompress_status | libavcodec_decompress (void *state, unsigned char *dst, unsigned char *src, unsigned int src_len, int frame_seq, struct video_frame_callbacks *callbacks, struct pixfmt_desc *internal_props) |
| static void | libavcodec_decompress_done (void *state) |
| static int | libavcodec_decompress_get_priority (codec_t compression, struct pixfmt_desc internal, codec_t ugc) |
| static int | libavcodec_decompress_get_property (void *state, int property, void *val, size_t *len) |
| static void * | libavcodec_decompress_init (void) |
| static int | libavcodec_decompress_reconfigure (void *state, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec) |
| static bool | read_forced_pixfmt (codec_t compress, const unsigned char *src, unsigned int src_len, struct pixfmt_desc *internal_props) |
| static _Bool | reconfigure_convert_if_needed (struct state_libavcodec_decompress *s, enum AVPixelFormat av_codec, codec_t out_codec, int width, int height) |
| REGISTER_MODULE (libavcodec, &libavcodec_info, LIBRARY_CLASS_VIDEO_DECOMPRESS, VIDEO_DECOMPRESS_ABI_VERSION) | |
| static void | set_codec_context_params (struct state_libavcodec_decompress *s) |
| static bool | validate_hwacc_param (void) |
Variables | |
| static const struct decoder_info | decoders [] |
| static const struct video_decompress_info | libavcodec_info |
Definition in file libavcodec.c.
| #define MOD_NAME "[lavd] " |
Definition at line 70 of file libavcodec.c.
| #define SELECT_PIXFMT | ( | pixfmt | ) |
Referenced by get_format_callback().
| anonymous enum |
| Enumerator | |
|---|---|
| MAX_PREFERED | |
| MAX_DECODERS |
|
| DEC_LEN |
|
Definition at line 215 of file libavcodec.c.
| ADD_TO_PARAM | ( | "force-lavd-decoder" | , |
| "* force-lavd- | decoder = <decoder>[:<decoder2>...]\n" " Forces specified Libavcodec decoder. If more need to be specified, | ||
| use colon as a delimiter.\n" " Use '-c libavcodec:help' to see available decoders.\n" | ) |
| ADD_TO_PARAM | ( | "lavd-accept-corrupted" | , |
| "* lavd-accept-corrupted\n" " Pass corrupted frames to decoder. If decoder isn't error- | resilient[=no], | ||
| \n" " may crash! Use \"no\" to disable even if enabled by default.\n" | ) |
| ADD_TO_PARAM | ( | "lavd-thread-count" | , |
| "* lavd-thread- | count = <thread_count>[F][S][n][d]\n" " Use <thread_count> decoding threads (0 is usually auto).\n" " Flag 'F' enables frame parallelism (disabled by default), | ||
| 'S' slice | based, | ||
| can be | bothdefault slice, | ||
| 'n' for none; 'd' - disable low delay\n" | ) |
| ADD_TO_PARAM | ( | "use-hw-accel" | , |
| "* use-hw-accel\n" " Try to use hardware accelerated decoding with lavd " "(NVDEC/VAAPI/VDPAU/VideoToolbox).\n" " Optionally with enforced API option.\n" | [=< api >|help] ) |
|
static |
Changes pixel format from frame to native
| frame | video frame returned from libavcodec decompress |
| dst | destination buffer where data will be stored |
| av_codec | libav pixel format |
| out_codec | requested output codec |
| width | frame width |
| height | frame height |
Definition at line 823 of file libavcodec.c.
References av_to_uv_convert(), convert, debug_file_dump, frame, get_ug_to_av_pixfmt(), and serialize_video_avframe().
Referenced by libavcodec_decompress().

|
static |
Definition at line 134 of file libavcodec.c.
References key, LOG_LEVEL_WARNING, MOD_NAME, printf_libav_error(), state, and val.
Referenced by set_codec_context_params().

|
static |
print hint to improve performance if not making it
Definition at line 898 of file libavcodec.c.
References AV_CODEC_CAP_OTHER_THREADS, state_libavcodec_decompress::codec_ctx, codec_is_a_rgb(), state_libavcodec_decompress::convert_in, state_libavcodec_decompress::desc, state_libavcodec_decompress::duration_warn_last_print, video_desc::fps, get_time_in_ns(), LOG_LEVEL_WARNING, log_msg(), MOD_NAME, state_libavcodec_decompress::mov_avg_comp_duration, state_libavcodec_decompress::mov_avg_frames, MS_IN_SEC, MSG, NS_IN_SEC, and state_libavcodec_decompress::out_codec.
Referenced by libavcodec_decompress().

|
static |
This function handles beginning of H.264 stream that usually floods terminal output with errors because it usually doesn't start with IDR frame (even if it does, codec probing swallows this). As a workaround, we wait until first SPS NAL unit to avoid initial decoding errors.
A drawback may be that it can in theory happen that the SPS NAL unit is not at the beginning of the buffer, but it is not the case of libx264 and hopefully neither other decoders (if so, it needs to be reworked/removed).
Definition at line 860 of file libavcodec.c.
References video_desc::color_spec, state_libavcodec_decompress::desc, get_nalu_name(), get_time_in_ns(), H265, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, NAL_H264_SPS, NAL_HEVC_VPS, NALU_HDR_GET_TYPE, NS_IN_SEC, rtpenc_get_first_nal(), and state_libavcodec_decompress::sps_vps_found.
Referenced by libavcodec_decompress().

|
static |
Definition at line 336 of file libavcodec.c.
References state_libavcodec_decompress::codec_ctx, video_desc::color_spec, state_libavcodec_decompress::consecutive_failed_decodes, DEC_LEN, decoders, desc, state_libavcodec_decompress::frame, get_codec_name(), get_fourcc(), get_usable_decoders(), video_desc::height, LOG_LEVEL_ERROR, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, state_libavcodec_decompress::pkt, PRORES, PRORES_422_LT, set_codec_context_params(), state_libavcodec_decompress::tmp_frame, ug_codec, and video_desc::width.
Referenced by handle_lavd_error(), libavcodec_decompress(), and libavcodec_decompress_reconfigure().

|
static |
Definition at line 1003 of file libavcodec.c.
References state_libavcodec_decompress::codec_ctx, state_libavcodec_decompress::frame, handle_lavd_error(), LOG_LEVEL_WARNING, log_msg(), MOD_NAME, state_libavcodec_decompress::pkt, SWAP_PTR, and state_libavcodec_decompress::tmp_frame.
Referenced by libavcodec_decompress().

|
static |
Definition at line 108 of file libavcodec.c.
References av_to_uv_conversion_destroy(), state_libavcodec_decompress::codec_ctx, state_libavcodec_decompress::convert, state_libavcodec_decompress::convert_in, state_libavcodec_decompress::state_libavcodec_decompress_sws::ctx, state_libavcodec_decompress::frame, state_libavcodec_decompress::state_libavcodec_decompress_sws::frame, state_libavcodec_decompress::hwaccel, hwaccel_state_reset(), lavd_flush(), state_libavcodec_decompress::pkt, state_libavcodec_decompress::sws, and state_libavcodec_decompress::tmp_frame.
Referenced by handle_lavd_error(), libavcodec_decompress_done(), and libavcodec_decompress_reconfigure().

|
static |
Definition at line 490 of file libavcodec.c.
References DRM_PRIME, HWACCEL_DRM_PRIME, state_libavcodec_decompress::out_codec, state, and UNUSED.
Referenced by get_format_callback().
|
static |
Definition at line 596 of file libavcodec.c.
References AV_PIX_FMT_VULKAN, drm_prime_init(), fmt, get_avpixfmts_names(), get_best_ug_codec_to_av(), get_commandline_param(), hw_accel_from_pixfmt(), hw_accel_from_str(), HW_VDPAU, state_libavcodec_decompress::hwaccel, HWACCEL_NONE, hwaccel_state_reset(), lavd_get_av_to_ug_codec(), LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, MSG, SELECT_PIXFMT, state, vaapi_init(), vdpau_init(), VIDEO_CODEC_NONE, and videotoolbox_init().
Referenced by set_codec_context_params().

|
static |
Definition at line 259 of file libavcodec.c.
References decoder_info::avcodec_id, exit_uv(), get_commandline_param(), LOG_LEVEL_ERROR, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARNING, log_msg(), MAX_DECODERS, MOD_NAME, param, decoder_info::preferred_decoders, and val.
Referenced by configure_with().

|
static |
Definition at line 954 of file libavcodec.c.
References state_libavcodec_decompress::block_accel, state_libavcodec_decompress::codec_ctx, configure_with(), state_libavcodec_decompress::consecutive_failed_decodes, deconfigure(), state_libavcodec_decompress::desc, state_libavcodec_decompress::hwaccel, LOG_LEVEL_ERROR, log_msg(), MOD_NAME, print_decoder_error(), and hw_accel_state::type.
Referenced by decode_frame().

|
static |
Definition at line 209 of file libavcodec.c.
References LOG_LEVEL_WARNING, and log_msg().

|
static |
Definition at line 1030 of file libavcodec.c.
References pixfmt_desc::accel_type, av_pixfmt_get_desc(), change_pixfmt(), check_duration(), check_first_sps_vps(), state_libavcodec_decompress::codec_ctx, video_desc::color_spec, configure_with(), state_libavcodec_decompress::consecutive_failed_decodes, state_libavcodec_decompress::convert, hw_accel_state::copy, decode_frame(), DECODER_GOT_CODEC, DECODER_GOT_FRAME, DECODER_NO_FRAME, DECODER_UNSUPP_PIXFMT, state_libavcodec_decompress::desc, state_libavcodec_decompress::frame, get_time_in_ns(), H264, H265, video_desc::height, hw_accel_from_pixfmt(), state_libavcodec_decompress::hwaccel, libav_codec_has_extradata(), LOG_LEVEL_DEBUG, LOG_LEVEL_VERBOSE, log_msg(), MOD_NAME, NS_IN_SEC_DBL, NS_TO_MS, state_libavcodec_decompress::out_codec, state_libavcodec_decompress::pitch, read_forced_pixfmt(), reconfigure_convert_if_needed(), state_libavcodec_decompress::rgb_shift, state, state_libavcodec_decompress::sws, UNUSED, VIDEO_CODEC_NONE, and video_desc::width.

|
static |
Definition at line 1135 of file libavcodec.c.
References deconfigure(), and state.

|
static |
Definition at line 1149 of file libavcodec.c.
References codec_is_a_rgb(), decoders, get_codec_name(), hw_accel_to_ug_pixfmt(), HWACCEL_NONE, MSG, R10k, R12L, RG48, RGB, RGBA, ug_codec, UYVY, v210, VDEC_PRIO_LOW, VDEC_PRIO_NA, VDEC_PRIO_NORMAL, VDEC_PRIO_NOT_PREFERRED, VDEC_PRIO_PREFERRED, VDEC_PRIO_PROBE_LO, VIDEO_CODEC_NONE, and Y416.

|
static |
Definition at line 1107 of file libavcodec.c.
References state_libavcodec_decompress::codec_ctx, DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME, get_commandline_param(), len, property, state, and val.

|
static |
Definition at line 442 of file libavcodec.c.
References state_libavcodec_decompress::hwaccel, hwaccel_state_init(), ug_set_av_logging(), and validate_hwacc_param().

|
static |
Definition at line 464 of file libavcodec.c.
References B_SHIFT_IDX, state_libavcodec_decompress::block_accel, video_desc::color_spec, configure_with(), deconfigure(), desc, state_libavcodec_decompress::desc, G_SHIFT_IDX, get_commandline_param(), HWACCEL_COUNT, libav_codec_has_extradata(), state_libavcodec_decompress::out_codec, state_libavcodec_decompress::pitch, R_SHIFT_IDX, state_libavcodec_decompress::rgb_shift, and state.

|
static |
Definition at line 976 of file libavcodec.c.
References pixfmt_desc::depth, H264, H264_NAL_SEI_PREFIX, H265, HEVC_NAL_SEI_PREFIX, LOG_LEVEL_VERBOSE, log_msg(), MOD_NAME, pixfmt_desc::rgb, START_CODE_3B, pixfmt_desc::subsampling, and UG_ORIG_FORMAT_ISO_IEC_11578_GUID.
Referenced by libavcodec_decompress().

|
static |
Definition at line 772 of file libavcodec.c.
References av_to_uv_conversion_destroy(), state_libavcodec_decompress::convert, state_libavcodec_decompress::convert_in, get_av_to_uv_conversion(), get_ug_to_av_pixfmt(), LOG_LEVEL_ERROR, log_msg(), MOD_NAME, pick_av_convertible_to_ug(), state_libavcodec_decompress::sws, and UNUSED.
Referenced by libavcodec_decompress().

| REGISTER_MODULE | ( | libavcodec | , |
| & | libavcodec_info, | ||
| LIBRARY_CLASS_VIDEO_DECOMPRESS | , | ||
| VIDEO_DECOMPRESS_ABI_VERSION | ) |
|
static |
< decoder may use <cpu_count> frame threads with AV_CODEC_CAP_OTHER_THREADS (latency)
Definition at line 145 of file libavcodec.c.
References check_av_opt_set(), state_libavcodec_decompress::codec_ctx, cuda_devices, get_commandline_param(), get_format_callback(), lavc_thread_type_to_str(), LOG_LEVEL_INFO, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, and val.
Referenced by configure_with().

|
static |
| false | if 1. hwacc not enabled; 2. help; 3. incorect hwacc spec |
Definition at line 418 of file libavcodec.c.
References exit_uv(), get_commandline_param(), hw_accel_from_str(), HWACCEL_NONE, and MSG.
Referenced by libavcodec_decompress_init().

|
static |
Definition at line 237 of file libavcodec.c.
|
static |
Definition at line 1195 of file libavcodec.c.