|
Sunshine master
Self-hosted game stream host for Moonlight.
|
Definitions for video. More...
#include <array>#include <atomic>#include <bitset>#include <list>#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 "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 <libavutil/hwcontext_d3d11va.h>Classes | |
| class | video::avcodec_encode_session_t |
| FFmpeg AVCodec encode session and parameter-set rewriting state. More... | |
| class | video::avcodec_software_encode_device_t |
| FFmpeg software encode device used when no hardware frames are required. More... | |
| struct | video::capture_ctx_t |
| Capture thread context shared with the encoder session. More... | |
| struct | video::capture_thread_async_ctx_t |
| Asynchronous capture thread state. More... | |
| struct | video::capture_thread_sync_ctx_t |
| Synchronous capture thread state. More... | |
| class | video::nvenc_encode_session_t |
| NVENC encode session and device state for hardware encoding. More... | |
| struct | video::sync_session_ctx_t |
| Context object used while synchronizing encode sessions. More... | |
| struct | video::sync_session_t |
| Synchronization state for one encode session. More... | |
Typedefs | |
| using | video::encode_e = platf::capture_e |
| Platform capture status returned by encode operations. | |
| using | video::encode_session_ctx_queue_t = safe::queue_t<sync_session_ctx_t> |
| Queue of encode-session contexts waiting for capture work. | |
| typedef int(* | video::vaapi_init_avcodec_hardware_input_buffer_fn) (platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf) |
| Callback signature for VA-API AVCodec hardware input initialization. | |
Enumerations | |
| 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 , video::FIXED_GOP_SIZE = 1 << 12 } |
| Enumerates supported flag options. More... | |
| enum class | video::qsv::profile_av1_e : int { main = 1 , high = 2 } |
| Enumerates supported profile AV1 options. More... | |
| enum class | video::nv::profile_h264_e : int { high = 2 , high_444p = 3 } |
| Enumerates supported profile h264 options. More... | |
| enum class | video::qsv::profile_h264_e : int { high = 100 , high_444p = 244 } |
| Enumerates supported profile h264 options. More... | |
| enum class | video::nv::profile_hevc_e : int { main = 0 , main_10 = 1 , rext = 2 } |
| Enumerates supported profile HEVC options. More... | |
| enum class | video::qsv::profile_hevc_e : int { main = 1 , main_10 = 2 , rext = 4 } |
| Enumerates supported profile HEVC options. More... | |
| enum | video::validate_flag_e { video::VUI_PARAMS = 0x01 } |
| Enumerates supported validate flag options. More... | |
Functions | |
| void | video::capture (safe::mail_t mail, config_t config, void *channel_data) |
| Capture and encode video for a streaming session. | |
| void | video::capture_async (safe::mail_t mail, config_t &config, void *channel_data) |
| Capture and encode video using the asynchronous capture thread. | |
| 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) |
| Run the shared display capture thread for asynchronous encoding. | |
| void | video::captureThreadSync () |
| Run synchronous capture and encode work on the capture thread. | |
| util::Either< avcodec_buffer_t, int > | video::cuda_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| Create an FFmpeg hardware device buffer for CUDA input. | |
| void | do_nothing (void *) |
| No-op lock callback used when FFmpeg requires a D3D11VA lock function. | |
| util::Either< avcodec_buffer_t, int > | video::dxgi_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| Create an FFmpeg hardware device buffer for D3D11VA input. | |
| 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) |
| Encode one captured frame and queue packets for transmission. | |
| 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) |
| Drain encoded packets from an FFmpeg encoder session. | |
| 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) |
| Encode one frame through NVENC and queue the resulting packet. | |
| 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) |
| Run one encode loop for a display capture stream. | |
| 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) |
| Run synchronized capture and encoding. | |
| void | video::end_capture_async (capture_thread_async_ctx_t &ctx) |
| Stop capture async processing. | |
| void | video::end_capture_sync (capture_thread_sync_ctx_t &ctx) |
| Stop capture sync processing. | |
| void | video::free_buffer (AVBufferRef *ref) |
| Release a backend buffer allocated for capture or conversion. | |
| void | video::free_ctx (AVCodecContext *ctx) |
| Release context resources. | |
| void | video::free_frame (AVFrame *frame) |
| Release an FFmpeg frame allocated by the capture or conversion backend. | |
| 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) |
| Create an AVCodec encode session. | |
| std::unique_ptr< platf::encode_device_t > | video::make_encode_device (platf::display_t &disp, const encoder_t &encoder, const config_t &config) |
| Create 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) |
| Create encode session. | |
| 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) |
| Create NVENC encode session. | |
| input::touch_port_t | video::make_port (platf::display_t *display, const config_t &config) |
| Create a port object or message. | |
| 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) |
| Create synced session. | |
| platf::mem_type_e | video::map_base_dev_type (AVHWDeviceType type) |
| Map base dev type values. | |
| platf::pix_fmt_e | video::map_pix_fmt (AVPixelFormat fmt) |
| Map pix fmt values. | |
| 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. | |
| void | video::refresh_displays (platf::mem_type_e dev_type, std::vector< std::string > &display_names, int ¤t_display_index) |
| Update the list of display names before or during a stream. | |
| 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) |
| Recreate a display capture object after a capture failure. | |
| int | video::start_capture_async (capture_thread_async_ctx_t &ctx) |
| Start the asynchronous capture thread. | |
| int | video::start_capture_sync (capture_thread_sync_ctx_t &ctx) |
| Start the synchronous multi-client capture thread. | |
| util::Either< avcodec_buffer_t, int > | video::vaapi_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| Create an FFmpeg hardware device buffer for VA-API input. | |
| int | video::validate_config (std::shared_ptr< platf::display_t > disp, const encoder_t &encoder, const config_t &config) |
| Validate config before it is used. | |
| bool | video::validate_encoder (encoder_t &encoder, bool expect_failure) |
| Validate encoder before it is used. | |
| util::Either< avcodec_buffer_t, int > | video::vt_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| Create an FFmpeg hardware device buffer for VideoToolbox input. | |
| util::Either< avcodec_buffer_t, int > | video::vulkan_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *) |
| Create an FFmpeg hardware device buffer for Vulkan input. | |
Variables | |
| int | video::active_av1_mode |
| AV1 mode selected by the most recent encoder probe. | |
| int | video::active_hevc_mode |
| HEVC mode selected by the most recent encoder probe. | |
| encoder_t | video::amdvce |
| Amdvce. | |
| auto | video::capture_thread_async = safe::make_shared<capture_thread_async_ctx_t>(start_capture_async, end_capture_async) |
| Capture thread async. | |
| auto | video::capture_thread_sync = safe::make_shared<capture_thread_sync_ctx_t>(start_capture_sync, end_capture_sync) |
| Capture thread sync. | |
| bool | video::last_encoder_probe_supported_ref_frames_invalidation = false |
| Whether the last probe found reference-frame invalidation support. | |
| std::array< bool, 3 > | video::last_encoder_probe_supported_yuv444_for_codec = {} |
| YUV444 support discovered for each probed codec. | |
| encoder_t | video::mediafoundation |
| Mediafoundation. | |
| encoder_t | video::nvenc |
| NVENC. | |
| encoder_t | video::quicksync |
| Quicksync. | |
| encoder_t | video::software |
| Software. | |
| encoder_t | video::vaapi |
| VA-API. | |
| encoder_t | video::videotoolbox |
| Videotoolbox. | |
Definitions for video.
| enum video::flag_e : uint32_t |
Enumerates supported flag options.
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
| void video::capture | ( | safe::mail_t | mail, |
| config_t | config, | ||
| void * | channel_data ) |
Capture and encode video for a streaming session.
| Session mail bus. | |
| config | Video configuration. |
| channel_data | Opaque channel data passed to packets. |
| void video::capture_async | ( | safe::mail_t | mail, |
| config_t & | config, | ||
| void * | channel_data ) |
Capture and encode video using the asynchronous capture thread.
| Session mail bus. | |
| config | Video configuration. |
| channel_data | Opaque channel data passed to packets. |
| 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 ) |
Run the shared display capture thread for asynchronous encoding.
| capture_ctx_queue | Capture context queue. |
| display_wp | Weak pointer holder for the active display. |
| reinit_event | Signal raised while the display is being reinitialized. |
| encoder | Selected encoder. |
| util::Either< avcodec_buffer_t, int > video::cuda_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
Create an FFmpeg hardware device buffer for CUDA input.
Initialize AVCodec hardware input buffers for CUDA.
| encode_device | Encode device. |
| util::Either< avcodec_buffer_t, int > video::dxgi_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
Create an FFmpeg hardware device buffer for D3D11VA input.
Create an FFmpeg D3D11VA hardware device from Sunshine's DXGI device.
| encode_device | Encode device. |
| 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 ) |
Encode one captured frame and queue packets for transmission.
| frame_nr | Frame nr. |
| session | Active streaming or pairing session for the request. |
| packets | Packets queued or emitted by the stream. |
| channel_data | Channel data. |
| frame_timestamp | 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 ) |
Drain encoded packets from an FFmpeg encoder session.
| frame_nr | Monotonic frame index assigned by the video pipeline. |
| session | Active FFmpeg encoder session. |
| packets | Output queue that receives encoded packets. |
| channel_data | Platform or protocol state attached to each packet. |
| frame_timestamp | Capture timestamp associated with the encoded frame. |
| 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 ) |
Encode one frame through NVENC and queue the resulting packet.
| frame_nr | Monotonic frame index assigned by the video pipeline. |
| session | Active NVENC encoder session. |
| packets | Output queue that receives the encoded packet. |
| channel_data | Platform or protocol state attached to the packet. |
| frame_timestamp | Capture timestamp associated with the encoded frame. |
| 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 ) |
Run one encode loop for a display capture stream.
| frame_nr | Frame counter updated as frames are encoded. |
| Session mail bus. | |
| images | Captured image event source. |
| config | Video configuration. |
| disp | Display being encoded. |
| encode_device | Platform encode device. |
| reinit_event | Signal raised while the encoder/display is reinitializing. |
| encoder | Selected encoder. |
| channel_data | Opaque channel data passed to packets. |
| 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 ) |
Run synchronized capture and encoding.
| synced_session_ctxs | Active synchronized session contexts. |
| encode_session_ctx_queue | Pending synchronized session context queue. |
| display_names | Cached display names. |
| display_p | Active display index. |
| void video::end_capture_async | ( | capture_thread_async_ctx_t & | ctx | ) |
Stop capture async processing.
| ctx | Native context object used by the operation or callback. |
| void video::end_capture_sync | ( | capture_thread_sync_ctx_t & | ctx | ) |
Stop capture sync processing.
| ctx | Native context object used by the operation or callback. |
| void video::free_buffer | ( | AVBufferRef * | ref | ) |
Release a backend buffer allocated for capture or conversion.
| ref | FFmpeg buffer reference to unref and free. |
| void video::free_ctx | ( | AVCodecContext * | ctx | ) |
Release context resources.
Release an FFmpeg codec context.
| ctx | Codec context allocated by FFmpeg. |
| void video::free_frame | ( | AVFrame * | frame | ) |
Release an FFmpeg frame allocated by the capture or conversion backend.
| frame | Video or graphics frame being processed. |
| 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 ) |
Create an AVCodec encode session.
| disp | Display being encoded. |
| encoder | Selected encoder. |
| config | Video configuration. |
| width | Encoded frame width. |
| height | Encoded frame height. |
| encode_device | AVCodec 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 ) |
Create encode device.
| disp | Display connection or display handle. |
| encoder | Encoder configuration or encoder instance. |
| config | Configuration values to apply. |
| 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 ) |
Create encode session.
| disp | Display connection or display handle. |
| encoder | Encoder configuration or encoder instance. |
| config | Configuration values to apply. |
| width | Frame or display width in pixels. |
| height | Frame or display height in pixels. |
| encode_device | 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 ) |
Create NVENC encode session.
| client_config | Client stream configuration negotiated for this session. |
| encode_device | Encode device. |
| input::touch_port_t video::make_port | ( | platf::display_t * | display, |
| const config_t & | config ) |
Create a port object or message.
| display | Display object or identifier associated with the operation. |
| config | Configuration values to apply. |
| 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 ) |
Create synced session.
| disp | Display connection or display handle. |
| encoder | Encoder configuration or encoder instance. |
| img | Image or frame object to read from or populate. |
| ctx | Native context object used by the operation or callback. |
| platf::mem_type_e video::map_base_dev_type | ( | AVHWDeviceType | type | ) |
Map base dev type values.
Map an FFmpeg hardware device type to Sunshine's memory type.
| type | FFmpeg hardware device type reported by the encoder backend. |
| platf::pix_fmt_e video::map_pix_fmt | ( | AVPixelFormat | fmt | ) |
Map pix fmt values.
Map an FFmpeg pixel format to Sunshine's pixel format enum.
| fmt | FFmpeg pixel format to convert. |
| 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.
| void video::refresh_displays | ( | platf::mem_type_e | dev_type, |
| std::vector< std::string > & | display_names, | ||
| int & | current_display_index ) |
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 ) |
Recreate a display capture object after a capture failure.
| disp | Display connection or display handle. |
| type | Protocol, message, or resource type selector. |
| display_name | Display name. |
| config | Configuration values to apply. |
| int video::start_capture_async | ( | capture_thread_async_ctx_t & | ctx | ) |
Start the asynchronous capture thread.
Start capture async.
| ctx | Native context object used by the operation or callback. |
| int video::start_capture_sync | ( | capture_thread_sync_ctx_t & | ctx | ) |
Start the synchronous multi-client capture thread.
Start capture sync.
| ctx | Native context object used by the operation or callback. |
| util::Either< avcodec_buffer_t, int > video::vaapi_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
Create an FFmpeg hardware device buffer for VA-API input.
Initialize AVCodec hardware input buffers for VA-API.
| encode_device | Encode device. |
| int video::validate_config | ( | std::shared_ptr< platf::display_t > | disp, |
| const encoder_t & | encoder, | ||
| const config_t & | config ) |
Validate config before it is used.
| disp | Display connection or display handle. |
| encoder | Encoder configuration or encoder instance. |
| config | Configuration values to apply. |
| bool video::validate_encoder | ( | encoder_t & | encoder, |
| bool | expect_failure ) |
Validate encoder before it is used.
| encoder | Encoder configuration or encoder instance. |
| expect_failure | Expect failure. |
expect_failure. | util::Either< avcodec_buffer_t, int > video::vt_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | encode_device | ) |
Create an FFmpeg hardware device buffer for VideoToolbox input.
Initialize AVCodec hardware input buffers for VideoToolbox.
| encode_device | Encode device. |
| util::Either< avcodec_buffer_t, int > video::vulkan_init_avcodec_hardware_input_buffer | ( | platf::avcodec_encode_device_t * | ) |
Create an FFmpeg hardware device buffer for Vulkan input.