![]() |
UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
|
#include "rtp/video_decoders.h"#include <cassert>#include <chrono>#include <cstdlib>#include <cstring>#include <algorithm>#include <atomic>#include <condition_variable>#include <iterator>#include <map>#include <memory>#include <mutex>#include <set>#include <sstream>#include <string>#include <thread>#include <unordered_map>#include <utility>#include <vector>#include "compat/htonl.h"#include "crypto/openssl_decrypt.h"#include "crypto/openssl_encrypt.h"#include "debug.h"#include "host.h"#include "lib_common.h"#include "messaging.h"#include "module.h"#include "pixfmt_conv.h"#include "rtp/fec.h"#include "rtp/pbuf.h"#include "rtp/rtp.h"#include "rtp/rtp_types.h"#include "tv.h"#include "utils/color_out.h"#include "utils/macros.h"#include "utils/misc.h"#include "utils/synchronized_queue.h"#include "utils/thread.h"#include "utils/timed_message.h"#include "utils/worker.h"#include "video.h"#include "video_decompress.h"#include "video_display.h"
Go to the source code of this file.
Classes | |
| struct | decompress_data |
| struct | state_video_decoder |
| Decoder state. More... | |
Macros | |
| #define | ENCRYPTED_ERR |
| #define | ERROR_GOTO_CLEANUP ret = false; goto cleanup; |
| #define | FRAMEBUFFER_NOT_READY(decoder) |
| #define | max(a, b) |
| #define | MOD_NAME "[video dec.] " |
| #define | NOT_ENCRYPTED_ERR |
Typedefs | |
| typedef void(* | change_il_t) (char *dst, char *src, int linesize, int height, void **state) |
Functions | |
| ADD_TO_PARAM ("decoder-drop-policy", "* decoder-drop-policy=blocking|nonblock|<sec>\n" " Force specified blocking policy (default nonblock).\n" " <sec> - specifies frame timeout in seconds (can have suffixes, eg. \"20ms\")\n") | |
| ADD_TO_PARAM ("decoder-use-codec", "* decoder-use-codec=<codec>\n" " Use specified pixel format for decoding (eg. v210). This overrides automatic\n" " choice. The pixel format must be supported by the video display. Use 'help' to see\n" " available options for a display (eg.: 'uv -d gl --param decoder-use-codec=help').\n" "* decoder-use-codec=!<codec>\n" " Blacklist specified pixel format ('!<codec' may need to be quoted).\n") | |
| static bool | blacklist_current_out_codec (struct state_video_decoder *decoder) |
| static void | check_for_mode_change (struct state_video_decoder *decoder, const uint32_t *hdr) |
| static codec_t | choose_codec_and_decoder (struct state_video_decoder *decoder, struct video_desc desc, decoder_t *decode_line, struct pixfmt_desc comp_int_prop) |
| static void | cleanup (struct state_video_decoder *decoder) |
| static auto | codec_list_to_str (vector< codec_t > const &codecs) |
| int | decode_video_frame (struct coded_data *cdata, void *decoder_data, struct pbuf_stats *stats) |
| Decodes a participant buffer representing one video frame. | |
| static void | decoder_process_message (struct module *) |
| static void | decoder_set_video_mode (struct state_video_decoder *decoder, enum video_mode video_mode) |
| static void * | decompress_thread (void *args) |
| static void * | decompress_worker (void *data) |
| static void * | fec_thread (void *args) |
| bool | parse_video_hdr (const uint32_t *hdr, struct video_desc *desc) |
| static bool | reconfigure_decoder (struct state_video_decoder *decoder, struct video_desc desc, struct pixfmt_desc comp_int_desc) |
| static void | reconfigure_helper (struct state_video_decoder *decoder, struct video_desc network_desc, struct pixfmt_desc comp_int_desc) |
| static void | reconfigure_if_needed (struct state_video_decoder *decoder, struct video_desc network_desc, struct pixfmt_desc comp_int_desc) |
| static change_il_t | select_il_func (enum interlacing_t in_il, enum interlacing_t *supported, int il_out_cnt, enum interlacing_t *out_il) |
| static int | sum_map (map< int, int > const &m) |
| void | video_decoder_destroy (struct state_video_decoder *decoder) |
| Destroys decoder created with decoder_init() | |
| struct state_video_decoder * | video_decoder_init (struct module *parent, enum video_mode video_mode, struct display *display, const char *encryption) |
| Initializes video decompress state. | |
| static vector< pair< struct pixfmt_desc, codec_t > > | video_decoder_order_output_codecs (struct pixfmt_desc comp_int_prop, vector< codec_t > const &display_codecs) |
| bool | video_decoder_register_display (struct state_video_decoder *decoder, struct display *display) |
| Registers video display to be used for displaying decoded video frames. | |
| void | video_decoder_remove_display (struct state_video_decoder *decoder) |
| This removes display from current decoder. | |
| static void | video_decoder_start_threads (struct state_video_decoder *decoder) |
| starts decompress and ldmg threads | |
| static void | video_decoder_stop_threads (struct state_video_decoder *decoder) |
| This function stops running threads. | |
| static void | wait_for_framebuffer_swap (struct state_video_decoder *decoder) |
Variables | |
| constexpr int | PADDING = MAX_PADDING |
Normal workflow through threads is following:
In step one, the decoder is a linedecoder and framebuffer is the display framebuffer
Data is saved to decompress buffer. The decompression itself is done by decompress_thread().
Data is saved to FEC buffer. Decoded with fec_thread().
Prior to decoding, packet is decompressed.
After FEC decoding, the whole block is decompressed.
When video is received, it is probed for an internal format:
BUGS: usually multiple reconf messages are sent, decompress priority is evaluated only when there are multiple same (in_codec,internal_codec,out_codec) tuples.
Definition in file video_decoders.cpp.
| #define ENCRYPTED_ERR |
Definition at line 411 of file video_decoders.cpp.
Referenced by decode_video_frame().
| #define ERROR_GOTO_CLEANUP ret = false; goto cleanup; |
Definition at line 1490 of file video_decoders.cpp.
Referenced by decode_video_frame().
| #define FRAMEBUFFER_NOT_READY | ( | decoder | ) |
Definition at line 151 of file video_decoders.cpp.
Referenced by decode_video_frame(), and fec_thread().
| #define max | ( | a, | |
| b ) |
Definition at line 1491 of file video_decoders.cpp.
Referenced by decode_video_frame().
| #define MOD_NAME "[video dec.] " |
Definition at line 149 of file video_decoders.cpp.
Referenced by decode_video_frame(), decompress_thread(), parse_video_hdr(), and video_decoder_register_display().
| #define NOT_ENCRYPTED_ERR |
Definition at line 413 of file video_decoders.cpp.
Referenced by decode_video_frame().
| typedef void(* change_il_t) (char *dst, char *src, int linesize, int height, void **state) |
Interlacing changing function protoype. The function should be able to change buffer in place, that is when dst and src are the same.
Definition at line 179 of file video_decoders.cpp.
| ADD_TO_PARAM | ( | "decoder-drop-policy" | ) |
| ADD_TO_PARAM | ( | "decoder-use-codec" | ) |
|
static |
Definition at line 570 of file video_decoders.cpp.
References get_codec_name(), LOG_LEVEL_DEBUG, log_msg(), state_video_decoder::native_codecs, state_video_decoder::out_codec, and VIDEO_CODEC_NONE.
Referenced by decompress_thread().

|
static |
Checks if network format has changed.
| decoder | decoder state |
| hdr | raw RTP payload header |
Definition at line 1474 of file video_decoders.cpp.
References LOG, LOG_LEVEL_NOTICE, PARAM_TILE_COUNT, parse_video_hdr(), state_video_decoder::received_vid_desc, reconfigure_helper(), and video_desc_eq_excl_param().
Referenced by decode_video_frame().

|
static |
This function selects, according to given video description, appropriate
| [in] | decoder | decoder to be taken parameters from (video mode, native codecs etc.) |
| [in] | desc | incoming video description |
| [out] | decode_line | If chosen decoder is a linedecoder, this variable contains the decoding function. |
DXT1 it is a exception, see vdec_note1
Definition at line 1073 of file video_decoders.cpp.
References codec_list_to_str(), video_desc::color_spec, state_video_decoder::decoder_type, decompress_init_multi(), state_video_decoder::decompress_state, pixfmt_desc::depth, desc, DXT1, DXT1_YUV, DXT5, get_best_decoder_from(), get_codec_name(), get_decoder_from_to(), get_pixdesc_desc(), LOG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, log_msg(), state_video_decoder::max_substreams, state_video_decoder::native_codecs, state_video_decoder::out_codec, RGB, RGBA, vc_memcpy, VIDEO_CODEC_END, VIDEO_CODEC_NONE, video_decoder_order_output_codecs(), state_video_decoder::video_mode, and VIDEO_NORMAL.
Referenced by reconfigure_decoder().

|
static |
Definition at line 954 of file video_decoders.cpp.
References state_video_decoder::change_il_state, state_video_decoder::decoder_type, decompress_done(), state_video_decoder::decompress_state, and state_video_decoder::line_decoder.

|
static |
Definition at line 828 of file video_decoders.cpp.
References codecs, and get_codec_name().
Referenced by choose_codec_and_decoder(), reconfigure_decoder(), and video_decoder_register_display().

|
static |
Definition at line 1852 of file video_decoders.cpp.
References check_message(), free_message(), state_video_decoder::lock, msg, new_response(), module::priv_data, state_video_decoder::received_vid_desc, RESPONSE_NOT_FOUND, RESPONSE_OK, and msg_universal::text.
Referenced by state_video_decoder::state_video_decoder().

|
static |
Definition at line 743 of file video_decoders.cpp.
References get_video_mode_tiles_x(), get_video_mode_tiles_y(), state_video_decoder::max_substreams, and state_video_decoder::video_mode.
Referenced by decode_video_frame(), and video_decoder_init().

|
static |
Definition at line 614 of file video_decoders.cpp.
References blacklist_current_out_codec(), state_video_decoder::buffer_swapped, state_video_decoder::buffer_swapped_cv, state_video_decoder::change_il, state_video_decoder::change_il_state, commandline_params, tile::data, tile::data_len, DECODER_GOT_CODEC, DECODER_GOT_FRAME, video_frame::decoder_overrides_data_len, state_video_decoder::decoder_type, DECODER_UNSUPP_PIXFMT, state_video_decoder::decompress_queue, decompress_worker(), state_video_decoder::display, display_get_frame(), display_put_frame(), state_video_decoder::frame, get_pixdesc_desc(), get_video_mode_tiles_x(), get_video_mode_tiles_y(), tile::height, video_desc::height, state_video_decoder::lock, LOG, LOG_LEVEL_DEBUG, LOG_LEVEL_NOTICE, MAX_BPS, state_video_decoder::merged_fb, MOD_NAME, state_video_decoder::msg_queue, NS_IN_SEC, state_video_decoder::out_codec, PADDING, state_video_decoder::pitch, synchronized_queue< T, max_len >::pop(), synchronized_queue< T, max_len >::push(), PUTF_BLOCKING, PUTF_NONBLOCK, state_video_decoder::received_vid_desc, set_thread_name(), video_frame::ssrc, task_run_async(), video_frame::tile_count, video_frame::tiles, video_frame::timestamp, unit_evaluate_dbl(), vc_get_linesize(), vf_get_tile(), VIDEO_CODEC_END, state_video_decoder::video_mode, wait_task(), tile::width, and video_desc::width.
Referenced by video_decoder_start_threads().

|
static |
Definition at line 593 of file video_decoders.cpp.
References video_frame::callbacks, decompress_frame(), state_video_decoder::decompress_state, and state_video_decoder::frame.
Referenced by decompress_thread().

|
static |
Definition at line 416 of file video_decoders.cpp.
References state_video_decoder::accepts_corrupted_frame, state_video_decoder::buffer_swapped, cleanup(), video_frame::color_spec, fec::create_from_desc(), tile::data, debug_msg, fec::decode(), state_video_decoder::decoder_type, state_video_decoder::decompress_queue, desc, exit_uv(), FEC_NONE, state_video_decoder::fec_queue, frame, state_video_decoder::frame, FRAMEBUFFER_NOT_READY, get_video_mode_tiles_x(), get_video_mode_tiles_y(), state_video_decoder::line_decoder, state_video_decoder::lock, LOG_LEVEL_FATAL, log_msg(), state_video_decoder::max_substreams, state_video_decoder::merged_fb, state_video_decoder::msg_queue, PARAM_TILE_COUNT, parse_video_hdr(), synchronized_queue< T, max_len >::pop(), synchronized_queue< T, max_len >::push(), state_video_decoder::received_vid_desc, set_thread_name(), sum_map(), vc_get_linesize(), verbose_msg, vf_alloc(), vf_get_tile(), video_desc_eq_excl_param(), state_video_decoder::video_mode, wait_for_framebuffer_swap(), and tile::width.
Referenced by video_decoder_start_threads().

|
static |
Reconfigures decoder if network received video data format has changed.
| decoder | the video decoder state |
| desc | new video description to be reconfigured to |
Definition at line 1206 of file video_decoders.cpp.
References state_video_decoder::accepts_corrupted_frame, state_video_decoder::change_il, state_video_decoder::change_il_state, choose_codec_and_decoder(), cleanup(), codec_list_to_str(), video_desc::color_spec, debug_msg, state_video_decoder::decoder_type, decompress_get_property(), DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME, decompress_reconfigure(), state_video_decoder::decompress_state, DEFAULT_RGB_SHIFT_INIT, desc, state_video_decoder::disp_supported_il, state_video_decoder::disp_supported_il_cnt, state_video_decoder::display, display_ctl_property(), state_video_decoder::display_desc, display_get_frame(), DISPLAY_PROPERTY_BUF_PITCH, DISPLAY_PROPERTY_RGB_SHIFT, DISPLAY_PROPERTY_VIDEO_MERGED, DISPLAY_PROPERTY_VIDEO_MODE, DISPLAY_PROPERTY_VIDEO_SEPARATE_3D, DISPLAY_PROPERTY_VIDEO_SEPARATE_TILES, display_put_frame(), display_reconfigure(), state_video_decoder::frame, free_response(), get_codec_name(), get_pf_block_bytes(), get_pf_block_pixels(), get_video_mode_tiles_x(), get_video_mode_tiles_y(), video_desc::height, video_desc::interlacing, len, state_video_decoder::line_decoder, LOG, LOG_LEVEL_ERROR, state_video_decoder::max_substreams, state_video_decoder::merged_fb, state_video_decoder::mod, state_video_decoder::native_codecs, new_message(), state_video_decoder::out_codec, module::parent, state_video_decoder::pitch, PITCH_DEFAULT, PROGRESSIVE, PUTF_DISCARD, state_video_decoder::received_vid_desc, RECEIVER_MSG_VIDEO_PROP_CHANGED, select_il_func(), send_message_to_receiver(), video_desc::tile_count, vc_get_linesize(), VIDEO_CODEC_END, VIDEO_CODEC_NONE, video_decoder_start_threads(), video_decoder_stop_threads(), video_desc_eq(), state_video_decoder::video_mode, VIDEO_NORMAL, and video_desc::width.
Referenced by reconfigure_helper().

|
static |
Definition at line 1439 of file video_decoders.cpp.
References state_video_decoder::frame, LOG_LEVEL_ERROR, log_msg(), state_video_decoder::out_codec, state_video_decoder::received_int_desc, state_video_decoder::received_vid_desc, reconfigure_decoder(), and VIDEO_CODEC_NONE.
Referenced by check_for_mode_change(), decode_video_frame(), and reconfigure_if_needed().

|
static |
Definition at line 1454 of file video_decoders.cpp.
References PARAM_TILE_COUNT, pixdesc_equals(), state_video_decoder::received_int_desc, state_video_decoder::received_vid_desc, reconfigure_helper(), and video_desc_eq_excl_param().
Referenced by decode_video_frame().

|
static |
This function finds interlacing mode changing function.
| [in] | in_il | input_interlacing |
| [in] | supported | list of supported output interlacing modes |
| [in] | il_out_cnt | count of supported items |
| [out] | out_il | selected output interlacing |
Definition at line 1161 of file video_decoders.cpp.
References il_lower_to_merged(), il_merged_to_upper(), il_upper_to_merged(), INTERLACED_MERGED, LOG_LEVEL_WARNING, log_msg(), LOWER_FIELD_FIRST, and UPPER_FIELD_FIRST.
Referenced by reconfigure_decoder().

|
static |
Definition at line 191 of file video_decoders.cpp.
Referenced by fec_thread().
| struct state_video_decoder * video_decoder_init | ( | struct module * | parent, |
| enum video_mode video_mode | , | ||
| struct display * | display, | ||
| const char * | encryption ) |
Initializes video decompress state.
| video_mode | video_mode expected to be received from network |
| display | Video display that is supposed to be controlled from decoder. display_get_frame(), display_put_frame(), display_get_propert() and display_reconfigure() functions may be used. If set to NULL, no decoding will take place. |
| encryption | Encryption config string. Currently, this is a passphrase to be used. This may change eventually. |
Definition at line 761 of file video_decoders.cpp.
References state_video_decoder::state_video_decoder(), state_video_decoder::dec_funcs, decoder_set_video_mode(), state_video_decoder::decrypt, openssl_decrypt_info::init, LIBRARY_CLASS_UNDEFINED, load_library(), LOG_LEVEL_FATAL, log_msg(), OPENSSL_DECRYPT_ABI_VERSION, parent, and video_decoder_register_display().
Referenced by ultragrid_rtp_video_rxtx::new_video_decoder().

|
static |
Reorders display codecs to match compression internal format.
First try to add HW-accelerated codecs, then exactly comp_int_fmt (if available) and then sort the rest - matching color-space first, higher bit depths first.
Always first try "native" than generic decoder (native is the one matching comp_int_fmt, generic should be catch-all allowing decompression of arbitrary compressed stream of received codec).
Definition at line 1005 of file video_decoders.cpp.
References codec_is_hw_accelerated(), pixfmt_desc::depth, get_codec_name(), get_pixdesc_desc(), get_pixfmt_desc(), LOG, log_level, LOG_LEVEL_VERBOSE, and pixdesc_equals().
Referenced by choose_codec_and_decoder().

|
static |
starts decompress and ldmg threads
Called from video_decoder_register_display(). It is also called after video_decoder_stop_threads() in reconfiguration.
Definition at line 803 of file video_decoders.cpp.
References decompress_thread(), state_video_decoder::decompress_thread_id, state_video_decoder::display, fec_thread(), and state_video_decoder::fec_thread_id.
Referenced by reconfigure_decoder(), and video_decoder_register_display().

|
static |
This function stops running threads.
Definition at line 817 of file video_decoders.cpp.
References state_video_decoder::control, state_video_decoder::decompress_thread_id, state_video_decoder::display, state_video_decoder::fec_queue, state_video_decoder::fec_thread_id, msg, synchronized_queue< T, max_len >::push(), and state_video_decoder::stats.
Referenced by reconfigure_decoder(), and video_decoder_remove_display().

|
static |
This function blocks until video frame is displayed and decoder::frame can be filled with new data. Until this point, the video frame is not considered valid.
Definition at line 406 of file video_decoders.cpp.
References state_video_decoder::buffer_swapped, state_video_decoder::buffer_swapped_cv, and state_video_decoder::lock.
Referenced by decode_video_frame(), and fec_thread().
|
constexpr |
Definition at line 146 of file video_decoders.cpp.
Referenced by decode_video_frame(), and decompress_thread().