Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
video.h File Reference

Declarations for video. More...

#include <optional>
#include <string>
#include <vector>
#include "input.h"
#include "platform/common.h"
#include "thread_safe.h"
#include "video_colorspace.h"
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
Include dependency graph for video.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  video::config_t
struct  video::encoder_platform_formats_t
struct  video::encoder_platform_formats_avcodec
struct  video::encoder_platform_formats_nvenc
struct  video::encoder_t
struct  video::encoder_t::option_t
struct  video::encoder_t::codec_t
struct  video::encode_session_t
struct  video::packet_raw_t
struct  video::packet_raw_t::replace_t
struct  video::packet_raw_avcodec
struct  video::packet_raw_generic
struct  video::hdr_info_raw_t
struct  video::capture_readiness_mode_t
 Codec and color depth for a capture readiness check. More...
struct  video::capture_readiness_t
 What the last capture-path check found, for a client to show. More...
struct  video::encoder_attempt_t
 Result of the last encoder probe, for diagnostics/metrics. More...
struct  video::encoder_status_t
struct  video::pipeline_metrics_t
 Live per-frame pipeline metrics, for diagnostics/metrics. More...

Macros

#define _CONVERT(x)

Typedefs

using video::avcodec_ctx_t = util::safe_ptr<AVCodecContext, free_ctx>
using video::avcodec_frame_t = util::safe_ptr<AVFrame, free_frame>
using video::avcodec_buffer_t = util::safe_ptr<AVBufferRef, free_buffer>
using video::sws_t = util::safe_ptr<SwsContext, sws_freeContext>
using video::img_event_t = std::shared_ptr<safe::event_t<std::shared_ptr<platf::img_t>>>
using video::packet_t = std::unique_ptr<packet_raw_t>
using video::hdr_info_t = std::unique_ptr<hdr_info_raw_t>

Functions

platf::mem_type_e video::map_base_dev_type (AVHWDeviceType type)
platf::pix_fmt_e video::map_pix_fmt (AVPixelFormat fmt)
void video::free_ctx (AVCodecContext *ctx)
void video::free_frame (AVFrame *frame)
void video::free_buffer (AVBufferRef *ref)
bool video::pyrowave_available ()
std::size_t video::pyrowave_frame_budget (const config_t &config)
 The most bytes one PyroWave frame may take.
void video::capture (safe::mail_t mail, config_t config, void *channel_data)
bool video::validate_encoder (encoder_t &encoder, bool expect_failure)
bool video::display_present ()
 Whether the host has a display to capture without creating one.
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.
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.
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).

Variables

constexpr int video::PYROWAVE_VIDEO_FORMAT = 64
constexpr uint32_t video::PYROWAVE_SERVER_CODEC_MODE = 0x40000000

Detailed Description

Declarations for video.

Definition in file video.h.

Macro Definition Documentation

◆ _CONVERT

#define _CONVERT ( x)
Value:
case flag_e::x: \
return std::string_view(#x)

Typedef Documentation

◆ avcodec_buffer_t

using video::avcodec_buffer_t = util::safe_ptr<AVBufferRef, free_buffer>

Definition at line 84 of file video.h.

◆ avcodec_ctx_t

using video::avcodec_ctx_t = util::safe_ptr<AVCodecContext, free_ctx>

Definition at line 82 of file video.h.

◆ avcodec_frame_t

using video::avcodec_frame_t = util::safe_ptr<AVFrame, free_frame>

Definition at line 83 of file video.h.

◆ hdr_info_t

using video::hdr_info_t = std::unique_ptr<hdr_info_raw_t>

Definition at line 366 of file video.h.

◆ img_event_t

using video::img_event_t = std::shared_ptr<safe::event_t<std::shared_ptr<platf::img_t>>>

Definition at line 86 of file video.h.

◆ packet_t

using video::packet_t = std::unique_ptr<packet_raw_t>

Definition at line 352 of file video.h.

◆ sws_t

using video::sws_t = util::safe_ptr<SwsContext, sws_freeContext>

Definition at line 85 of file video.h.

Function Documentation

◆ capture()

void video::capture ( safe::mail_t mail,
config_t config,
void * channel_data )

Definition at line 2713 of file video.cpp.

◆ check_capture_path()

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.

Parameters
streamThe 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.
failureSet to the failed step and its reason.
clientThe paired client whose launch this check is for.
Returns
0 when a frame went all the way through, or when the display produced no new frame in time (logged; a static screen may not); -1 when a step failed.

Definition at line 3199 of file video.cpp.

◆ choose_capture_readiness_mode()

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.

Returns
No mode when an SDR client encounters HDR output, or when the encoder has no supported HDR codec for an HDR output.

Definition at line 3001 of file video.cpp.

◆ display_present()

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.

Definition at line 52 of file video.cpp.

◆ forget_capture_readiness()

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.

Definition at line 3217 of file video.cpp.

◆ free_buffer()

void video::free_buffer ( AVBufferRef * ref)

Definition at line 74 of file video.cpp.

◆ free_ctx()

void video::free_ctx ( AVCodecContext * ctx)

Definition at line 66 of file video.cpp.

◆ free_frame()

void video::free_frame ( AVFrame * frame)

Definition at line 70 of file video.cpp.

◆ get_encoder_status()

encoder_status_t video::get_encoder_status ( )

Snapshot of the last encoder probe result (thread-safe copy).

Definition at line 852 of file video.cpp.

◆ get_pipeline_metrics()

pipeline_metrics_t video::get_pipeline_metrics ( )

Snapshot of the live pipeline metrics (thread-safe copy).

Definition at line 926 of file video.cpp.

◆ last_capture_readiness()

capture_readiness_t video::last_capture_readiness ( )

The result of the last check_capture_path().

Definition at line 3212 of file video.cpp.

◆ map_base_dev_type()

platf::mem_type_e video::map_base_dev_type ( AVHWDeviceType type)

Definition at line 3537 of file video.cpp.

◆ map_pix_fmt()

platf::pix_fmt_e video::map_pix_fmt ( AVPixelFormat fmt)

Definition at line 3552 of file video.cpp.

◆ metrics_record_drop()

void video::metrics_record_drop ( )

Record one dropped frame (encoder error/timeout).

Definition at line 904 of file video.cpp.

◆ metrics_record_frame()

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.

Parameters
encode_msTime spent in the encoder for this frame.
capture_to_encode_msLatency from capture to encode start.
packet_bytesEncoded packet size, for the measured bitrate.

Definition at line 874 of file video.cpp.

◆ metrics_reset()

void video::metrics_reset ( )

Reset pipeline metrics at the start of a streaming session.

Definition at line 910 of file video.cpp.

◆ metrics_set_resolution()

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.

Parameters
widthActive stream width in pixels.
heightActive stream height in pixels.

Definition at line 915 of file video.cpp.

◆ probe_encoders()

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.

Warning
This is only safe to call when there is no client actively streaming.

Definition at line 3232 of file video.cpp.

◆ probe_encoders_without_display()

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.

Returns
0 on success, -1 if no encoder works.

Definition at line 3224 of file video.cpp.

◆ pyrowave_available()

bool video::pyrowave_available ( )

Definition at line 363 of file video.cpp.

◆ pyrowave_frame_budget()

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.

Definition at line 355 of file video.cpp.

◆ validate_encoder()

bool video::validate_encoder ( encoder_t & encoder,
bool expect_failure )

Definition at line 2803 of file video.cpp.

Variable Documentation

◆ PYROWAVE_SERVER_CODEC_MODE

uint32_t video::PYROWAVE_SERVER_CODEC_MODE = 0x40000000
inlineconstexpr

Definition at line 34 of file video.h.

◆ PYROWAVE_VIDEO_FORMAT

int video::PYROWAVE_VIDEO_FORMAT = 64
inlineconstexpr

Definition at line 33 of file video.h.