|
Hermes 0.7.0
Linux game streaming host
|
Definitions for video. More...
#include <atomic>#include <bitset>#include <list>#include <mutex>#include <thread>#include <boost/pointer_cast.hpp>#include <libavutil/imgutils.h>#include <libavutil/mastering_display_metadata.h>#include <libavutil/opt.h>#include <libavutil/pixdesc.h>#include "process.h"#include "annexb_filler.h"#include "cbs.h"#include "config.h"#include "display_device.h"#include "globals.h"#include "input.h"#include "logging.h"#include "nvenc/nvenc_base.h"#include "platform/common.h"#include "sync.h"#include "video.h"#include "platform/linux/misc.h"Go to the source code of this file.
Classes | |
| class | video::avcodec_software_encode_device_t |
| class | video::avcodec_encode_session_t |
| class | video::nvenc_encode_session_t |
| struct | video::sync_session_ctx_t |
| struct | video::sync_session_t |
| struct | video::capture_ctx_t |
| struct | video::capture_thread_async_ctx_t |
| struct | video::capture_thread_sync_ctx_t |
| struct | video::pipeline_metrics_accum_t |
Typedefs | |
| using | video::encode_session_ctx_queue_t = safe::queue_t<sync_session_ctx_t> |
| using | video::encode_e = platf::capture_e |
| typedef int(*) | video::vaapi_init_avcodec_hardware_input_buffer_fn(platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf) |
Enumerations | |
| enum class | video::nv::profile_h264_e : int { high = 2 , high_444p = 3 } |
| enum class | video::nv::profile_hevc_e : int { main = 0 , main_10 = 1 , rext = 2 } |
| enum | video::flag_e : uint32_t { video::DEFAULT = 0 , video::PARALLEL_ENCODING = 1 << 1 , video::H264_ONLY = 1 << 2 , video::LIMITED_GOP_SIZE = 1 << 3 , video::SINGLE_SLICE_ONLY = 1 << 4 , video::CBR_WITH_VBR = 1 << 5 , video::RELAXED_COMPLIANCE = 1 << 6 , video::NO_RC_BUF_LIMIT = 1 << 7 , video::REF_FRAMES_INVALIDATION = 1 << 8 , video::ALWAYS_REPROBE = 1 << 9 , video::YUV444_SUPPORT = 1 << 10 , video::ASYNC_TEARDOWN = 1 << 11 } |
| enum | video::validate_flag_e { video::VUI_PARAMS = 0x01 } |
Functions | |
| bool | video::display_present () |
| Whether the host has a display to capture without creating one. | |
| void | video::free_ctx (AVCodecContext *ctx) |
| void | video::free_frame (AVFrame *frame) |
| void | video::free_buffer (AVBufferRef *ref) |
| util::Either< avcodec_buffer_t, int > | video::vaapi_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| util::Either< avcodec_buffer_t, int > | video::cuda_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| std::size_t | video::pyrowave_frame_budget (const config_t &config) |
| The most bytes one PyroWave frame may take. | |
| bool | video::pyrowave_available () |
| int | video::start_capture_sync (capture_thread_sync_ctx_t &ctx) |
| void | video::end_capture_sync (capture_thread_sync_ctx_t &ctx) |
| int | video::start_capture_async (capture_thread_async_ctx_t &ctx) |
| int | video::start_capture_async_with_encoder (capture_thread_async_ctx_t &ctx, const encoder_t *encoder) |
| void | video::end_capture_async (capture_thread_async_ctx_t &ctx) |
| encoder_status_t | video::get_encoder_status () |
| Snapshot of the last encoder probe result (thread-safe copy). | |
| void | video::metrics_record_frame (double encode_ms, double capture_to_encode_ms, size_t packet_bytes) |
| Record one encoded frame's timings and output size. | |
| void | video::metrics_record_drop () |
| Record one dropped frame (encoder error/timeout). | |
| void | video::metrics_reset () |
| Reset pipeline metrics at the start of a streaming session. | |
| void | video::metrics_set_resolution (int width, int height) |
| Record the active stream resolution for diagnostics. | |
| pipeline_metrics_t | video::get_pipeline_metrics () |
| Snapshot of the live pipeline metrics (thread-safe copy). | |
| void | video::reset_display (std::shared_ptr< platf::display_t > &disp, const platf::mem_type_e &type, const std::string &display_name, const config_t &config) |
| void | video::refresh_displays (platf::mem_type_e dev_type, std::vector< std::string > &display_names, int ¤t_display_index, std::string &preferred_display_name) |
| Update the list of display names before or during a stream. | |
| void | video::refresh_displays (platf::mem_type_e dev_type, std::vector< std::string > &display_names, int ¤t_display_index) |
| void | video::captureThread (std::shared_ptr< safe::queue_t< capture_ctx_t > > capture_ctx_queue, sync_util::sync_t< std::weak_ptr< platf::display_t > > &display_wp, safe::signal_t &reinit_event, const encoder_t &encoder) |
| int | video::encode_avcodec (int64_t frame_nr, avcodec_encode_session_t &session, safe::mail_raw_t::queue_t< packet_t > &packets, void *channel_data, std::optional< std::chrono::steady_clock::time_point > frame_timestamp) |
| int | video::encode_nvenc (int64_t frame_nr, nvenc_encode_session_t &session, safe::mail_raw_t::queue_t< packet_t > &packets, void *channel_data, std::optional< std::chrono::steady_clock::time_point > frame_timestamp) |
| int | video::encode (int64_t frame_nr, encode_session_t &session, safe::mail_raw_t::queue_t< packet_t > &packets, void *channel_data, std::optional< std::chrono::steady_clock::time_point > frame_timestamp) |
| std::unique_ptr< avcodec_encode_session_t > | video::make_avcodec_encode_session (platf::display_t *disp, const encoder_t &encoder, const config_t &config, int width, int height, std::unique_ptr< platf::avcodec_encode_device_t > encode_device) |
| std::unique_ptr< nvenc_encode_session_t > | video::make_nvenc_encode_session (const config_t &client_config, std::unique_ptr< platf::nvenc_encode_device_t > encode_device) |
| std::unique_ptr< encode_session_t > | video::make_encode_session (platf::display_t *disp, const encoder_t &encoder, const config_t &config, int width, int height, std::unique_ptr< platf::encode_device_t > encode_device) |
| void | video::encode_run (int &frame_nr, safe::mail_t mail, img_event_t images, config_t config, std::shared_ptr< platf::display_t > disp, std::unique_ptr< platf::encode_device_t > encode_device, safe::signal_t &reinit_event, const encoder_t &encoder, void *channel_data) |
| input::touch_port_t | video::make_port (platf::display_t *display, const config_t &config) |
| std::unique_ptr< platf::encode_device_t > | video::make_encode_device (platf::display_t &disp, const encoder_t &encoder, const config_t &config) |
| std::optional< sync_session_t > | video::make_synced_session (platf::display_t *disp, const encoder_t &encoder, platf::img_t &img, sync_session_ctx_t &ctx) |
| encode_e | video::encode_run_sync (std::vector< std::unique_ptr< sync_session_ctx_t > > &synced_session_ctxs, encode_session_ctx_queue_t &encode_session_ctx_queue, std::vector< std::string > &display_names, int &display_p) |
| void | video::captureThreadSync () |
| void | video::capture_async_with_context (capture_thread_async_ctx_t &capture_context, safe::mail_t mail, config_t &config, void *channel_data) |
| void | video::capture_async (safe::mail_t mail, config_t &config, void *channel_data) |
| void | video::capture (safe::mail_t mail, config_t config, void *channel_data) |
| int | video::validate_config (std::shared_ptr< platf::display_t > disp, const encoder_t &encoder, const config_t &config) |
| bool | video::validate_encoder (encoder_t &encoder, bool expect_failure) |
| std::optional< capture_readiness_mode_t > | video::choose_capture_readiness_mode (bool client_hdr_requested, bool display_hdr, bool hevc_hdr_supported, bool av1_hdr_supported) |
| Choose a readiness mode without ever encoding PQ scanout as SDR. | |
| int | video::check_capture_path (const config_t &stream, std::string &failure, const std::string &client={}) |
| Run one real frame through the path a stream will use. | |
| capture_readiness_t | video::last_capture_readiness () |
| The result of the last check_capture_path(). | |
| void | video::forget_capture_readiness (const std::string &client) |
| Forget the last check if it was for client's launch: a later launch of theirs ran without one, so it says nothing about that stream. | |
| int | video::probe_encoders_without_display () |
| Probe encoders without opening any screen. | |
| int | video::probe_encoders () |
| Probe encoders and select the preferred encoder. This is called once at startup and each time a stream is launched to ensure the best encoder is selected. Encoder availability can change at runtime due to all sorts of things from driver updates to eGPUs. | |
| platf::mem_type_e | video::map_base_dev_type (AVHWDeviceType type) |
| platf::pix_fmt_e | video::map_pix_fmt (AVPixelFormat fmt) |
Variables | |
| auto | video::capture_thread_async = safe::make_shared<capture_thread_async_ctx_t>(start_capture_async, end_capture_async) |
| auto | video::capture_thread_sync = safe::make_shared<capture_thread_sync_ctx_t>(start_capture_sync, end_capture_sync) |
| encoder_t | video::nvenc |
| encoder_t | video::software |
| encoder_t | video::vaapi |
| int | video::active_hevc_mode |
| int | video::active_av1_mode |
| bool | video::last_encoder_probe_supported_ref_frames_invalidation = false |
| std::array< bool, 3 > | video::last_encoder_probe_supported_yuv444_for_codec |
| bool | video::probe_without_display = false |
Definitions for video.
Definition in file video.cpp.
| using video::encode_e = platf::capture_e |
| using video::encode_session_ctx_queue_t = safe::queue_t<sync_session_ctx_t> |
| typedef int(*) video::vaapi_init_avcodec_hardware_input_buffer_fn(platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf) |
| enum video::flag_e : uint32_t |
|
strong |
|
strong |
| void video::capture | ( | safe::mail_t | mail, |
| config_t | config, | ||
| void * | channel_data ) |
| void video::capture_async | ( | safe::mail_t | mail, |
| config_t & | config, | ||
| void * | channel_data ) |
| void video::capture_async_with_context | ( | capture_thread_async_ctx_t & | capture_context, |
| safe::mail_t | mail, | ||
| config_t & | config, | ||
| void * | channel_data ) |
| void video::captureThread | ( | std::shared_ptr< safe::queue_t< capture_ctx_t > > | capture_ctx_queue, |
| sync_util::sync_t< std::weak_ptr< platf::display_t > > & | display_wp, | ||
| safe::signal_t & | reinit_event, | ||
| const encoder_t & | encoder ) |
| int video::check_capture_path | ( | const config_t & | stream, |
| std::string & | failure, | ||
| const std::string & | client = {} ) |
Run one real frame through the path a stream will use.
Opens the display, captures a frame from it, converts it on the encoder's device and encodes it, with the encoder already chosen. Done before a client is told the stream is ready, so a broken step is named then rather than shown as a black stream.
| stream | The stream's capture settings: display_name (empty for the process-wide display), frame rate and client HDR request. The check chooses its own size and a codec matching the effective display color. |
| failure | Set to the failed step and its reason. |
| client | The paired client whose launch this check is for. |
| std::optional< capture_readiness_mode_t > video::choose_capture_readiness_mode | ( | bool | client_hdr_requested, |
| bool | display_hdr, | ||
| bool | hevc_hdr_supported, | ||
| bool | av1_hdr_supported ) |
| util::Either< avcodec_buffer_t, int > video::cuda_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
| bool video::display_present | ( | ) |
Whether the host has a display to capture without creating one.
False means a virtual display has to stand in, both to probe the encoders and to stream. The kernel reports whether any connector lights a monitor. This answers yes whenever no virtual display could stand in or one already does.
| int video::encode | ( | int64_t | frame_nr, |
| encode_session_t & | session, | ||
| safe::mail_raw_t::queue_t< packet_t > & | packets, | ||
| void * | channel_data, | ||
| std::optional< std::chrono::steady_clock::time_point > | frame_timestamp ) |
| int video::encode_avcodec | ( | int64_t | frame_nr, |
| avcodec_encode_session_t & | session, | ||
| safe::mail_raw_t::queue_t< packet_t > & | packets, | ||
| void * | channel_data, | ||
| std::optional< std::chrono::steady_clock::time_point > | frame_timestamp ) |
| int video::encode_nvenc | ( | int64_t | frame_nr, |
| nvenc_encode_session_t & | session, | ||
| safe::mail_raw_t::queue_t< packet_t > & | packets, | ||
| void * | channel_data, | ||
| std::optional< std::chrono::steady_clock::time_point > | frame_timestamp ) |
| void video::encode_run | ( | int & | frame_nr, |
| safe::mail_t | mail, | ||
| img_event_t | images, | ||
| config_t | config, | ||
| std::shared_ptr< platf::display_t > | disp, | ||
| std::unique_ptr< platf::encode_device_t > | encode_device, | ||
| safe::signal_t & | reinit_event, | ||
| const encoder_t & | encoder, | ||
| void * | channel_data ) |
| encode_e video::encode_run_sync | ( | std::vector< std::unique_ptr< sync_session_ctx_t > > & | synced_session_ctxs, |
| encode_session_ctx_queue_t & | encode_session_ctx_queue, | ||
| std::vector< std::string > & | display_names, | ||
| int & | display_p ) |
| void video::end_capture_async | ( | capture_thread_async_ctx_t & | ctx | ) |
| void video::end_capture_sync | ( | capture_thread_sync_ctx_t & | ctx | ) |
| void video::forget_capture_readiness | ( | const std::string & | client | ) |
| encoder_status_t video::get_encoder_status | ( | ) |
| pipeline_metrics_t video::get_pipeline_metrics | ( | ) |
| capture_readiness_t video::last_capture_readiness | ( | ) |
| std::unique_ptr< avcodec_encode_session_t > video::make_avcodec_encode_session | ( | platf::display_t * | disp, |
| const encoder_t & | encoder, | ||
| const config_t & | config, | ||
| int | width, | ||
| int | height, | ||
| std::unique_ptr< platf::avcodec_encode_device_t > | encode_device ) |
| std::unique_ptr< platf::encode_device_t > video::make_encode_device | ( | platf::display_t & | disp, |
| const encoder_t & | encoder, | ||
| const config_t & | config ) |
| std::unique_ptr< encode_session_t > video::make_encode_session | ( | platf::display_t * | disp, |
| const encoder_t & | encoder, | ||
| const config_t & | config, | ||
| int | width, | ||
| int | height, | ||
| std::unique_ptr< platf::encode_device_t > | encode_device ) |
| std::unique_ptr< nvenc_encode_session_t > video::make_nvenc_encode_session | ( | const config_t & | client_config, |
| std::unique_ptr< platf::nvenc_encode_device_t > | encode_device ) |
| input::touch_port_t video::make_port | ( | platf::display_t * | display, |
| const config_t & | config ) |
| std::optional< sync_session_t > video::make_synced_session | ( | platf::display_t * | disp, |
| const encoder_t & | encoder, | ||
| platf::img_t & | img, | ||
| sync_session_ctx_t & | ctx ) |
| platf::mem_type_e video::map_base_dev_type | ( | AVHWDeviceType | type | ) |
| platf::pix_fmt_e video::map_pix_fmt | ( | AVPixelFormat | fmt | ) |
| void video::metrics_record_drop | ( | ) |
| void video::metrics_record_frame | ( | double | encode_ms, |
| double | capture_to_encode_ms, | ||
| size_t | packet_bytes ) |
| void video::metrics_reset | ( | ) |
| void video::metrics_set_resolution | ( | int | width, |
| int | height ) |
Record the active stream resolution for diagnostics.
Called by the encode loop once the session resolution is known (after the RTSP layer has already reset the counters). Survives the per-window republish so it remains reported for the life of the session.
| width | Active stream width in pixels. |
| height | Active stream height in pixels. |
| int video::probe_encoders | ( | ) |
Probe encoders and select the preferred encoder. This is called once at startup and each time a stream is launched to ensure the best encoder is selected. Encoder availability can change at runtime due to all sorts of things from driver updates to eGPUs.
| int video::probe_encoders_without_display | ( | ) |
Probe encoders without opening any screen.
For when no screen can be captured - every monitor asleep, say. Creating a virtual output instead would wake every monitor the compositor has, so the encoders are validated on a display with nothing behind it.
| std::size_t video::pyrowave_frame_budget | ( | const config_t & | config | ) |
The most bytes one PyroWave frame may take.
PyroWave's rate control is a per-frame ceiling, so the client's bitrate is spread evenly over its frame rate. It never exceeds an uncompressed 4:2:0 frame, which the encoder has no use for, and never drops below 16 KiB, where every frame would be a smear.
| void video::refresh_displays | ( | platf::mem_type_e | dev_type, |
| std::vector< std::string > & | display_names, | ||
| int & | current_display_index ) |
| void video::refresh_displays | ( | platf::mem_type_e | dev_type, |
| std::vector< std::string > & | display_names, | ||
| int & | current_display_index, | ||
| std::string & | preferred_display_name ) |
Update the list of display names before or during a stream.
This will attempt to keep current_display_index pointing at the same display.
| dev_type | The encoder device type used for display lookup. |
| display_names | The list of display names to repopulate. |
| current_display_index | The current display index or -1 if not yet known. |
| void video::reset_display | ( | std::shared_ptr< platf::display_t > & | disp, |
| const platf::mem_type_e & | type, | ||
| const std::string & | display_name, | ||
| const config_t & | config ) |
| int video::start_capture_async | ( | capture_thread_async_ctx_t & | ctx | ) |
| int video::start_capture_async_with_encoder | ( | capture_thread_async_ctx_t & | ctx, |
| const encoder_t * | encoder ) |
| int video::start_capture_sync | ( | capture_thread_sync_ctx_t & | ctx | ) |
| util::Either< avcodec_buffer_t, int > video::vaapi_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
| int video::validate_config | ( | std::shared_ptr< platf::display_t > | disp, |
| const encoder_t & | encoder, | ||
| const config_t & | config ) |
| bool video::validate_encoder | ( | encoder_t & | encoder, |
| bool | expect_failure ) |
| auto video::capture_thread_async = safe::make_shared<capture_thread_async_ctx_t>(start_capture_async, end_capture_async) |
| auto video::capture_thread_sync = safe::make_shared<capture_thread_sync_ctx_t>(start_capture_sync, end_capture_sync) |
| bool video::last_encoder_probe_supported_ref_frames_invalidation = false |
| std::array< bool, 3 > video::last_encoder_probe_supported_yuv444_for_codec |