FFmpeg
Data Structures | Macros | Enumerations | Functions
vsrc_gfxcapture_winrt.cpp File Reference
#include "vsrc_gfxcapture_winrt.hpp"
#include "vsrc_gfxcapture_shader.h"
#include <dwmapi.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#include <dispatcherqueue.h>
#include <windows.foundation.h>
#include <windows.graphics.capture.h>
#include <windows.graphics.capture.interop.h>
#include <windows.graphics.directx.direct3d11.h>
#include "libavutil/avassert.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "libavutil/pixdesc.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_d3d11va.h"
#include "avfilter.h"
#include "filters.h"
#include "video.h"
#include "vsrc_gfxcapture.h"
#include <cinttypes>
#include <condition_variable>
#include <cwchar>
#include <memory>
#include <mutex>
#include <regex>
#include <string>
#include <thread>
#include <type_traits>

Go to the source code of this file.

Data Structures

struct  GfxCaptureFunctions
 
struct  GfxCaptureContextWgc
 
struct  GfxCaptureContextD3D
 
struct  GfxCaptureContextCpp
 

Macros

#define TIMESPAN_RES   10000000
 
#define TIMESPAN_RES64   INT64_C(10000000)
 
#define CAPTURE_POOL_SIZE   2
 
#define CCTX(ctx)   static_cast<GfxCaptureContext*>(ctx)
 
#define CHECK_HR(fcall, action)
 
#define CHECK_HR_RET(...)   CHECK_HR((__VA_ARGS__), return AVERROR_EXTERNAL)
 
#define CHECK_HR_FAIL(...)   CHECK_HR((__VA_ARGS__), ret = AVERROR_EXTERNAL; goto fail)
 
#define CHECK_HR_LOG(...)   CHECK_HR((__VA_ARGS__), (void)0)
 
#define LOAD_DLL(handle, name)
 
#define LOAD_FUNC(handle, name)
 

Enumerations

enum  { WM_WGC_THREAD_SHUTDOWN = WM_APP + 1 }
 

Functions

template<typename T >
static HRESULT get_activation_factory (GfxCaptureContextCpp *ctx, PCWSTR clsid, T **factory)
 
static void wgc_frame_arrived_handler (const std::unique_ptr< GfxCaptureContextWgc > &wgctx)
 
static void wgc_closed_handler (const std::unique_ptr< GfxCaptureContextWgc > &wgctx)
 
static void wgc_stop_capture_session (AVFilterContext *avctx) noexcept
 
static int wgc_calculate_client_area (AVFilterContext *avctx)
 
static int wgc_setup_gfxcapture_session (AVFilterContext *avctx)
 
static int wgc_setup_gfxcapture_capture (AVFilterContext *avctx)
 
static int wgc_try_get_next_frame (AVFilterContext *avctx, ComPtr< IDirect3D11CaptureFrame > &capture_frame)
 
static int wgc_setup_winrt (AVFilterContext *avctx)
 
static void wgc_thread_uninit (AVFilterContext *avctx) noexcept
 
static int wgc_thread_init (AVFilterContext *avctx)
 
static int wgc_thread_worker (AVFilterContext *avctx)
 
static void wgc_thread_entry (AVFilterContext *avctx) noexcept
 
static int stop_wgc_thread (AVFilterContext *avctx)
 
static int start_wgc_thread (AVFilterContext *avctx)
 
template<typename F >
static int run_on_wgc_thread (AVFilterContext *avctx, F &&cb)
 
static int build_regex (AVFilterContext *avctx, const char *pattern, std::regex *out)
 
static int wstring_to_utf8 (const wchar_t *in, std::string *out)
 
static int get_window_exe_name (HWND hwnd, std::string *out)
 
static int find_capture_source (AVFilterContext *avctx)
 
static av_cold void gfxcapture_uninit (AVFilterContext *avctx)
 
template<typename T >
static av_cold void GetProcAddressTyped (const hmodule_ptr_t &hModule, LPCSTR lpProcName, T *out)
 
static av_cold int load_functions (AVFilterContext *avctx)
 
static av_cold int gfxcapture_init (AVFilterContext *avctx)
 
static int init_hwframes_ctx (AVFilterContext *avctx)
 
static int setup_gfxcapture_capture (AVFilterContext *avctx)
 
static int prepare_render_resources (AVFilterContext *avctx)
 
static int gfxcapture_config_props (AVFilterLink *outlink)
 
static int render_capture_to_frame (AVFilterContext *avctx, AVFrame *frame, const ComPtr< ID3D11Texture2D > &src_tex)
 
static int process_frame_if_exists (AVFilterLink *outlink)
 
static int gfxcapture_activate (AVFilterContext *avctx)
 
av_cold void ff_gfxcapture_uninit (AVFilterContext *avctx) noexcept
 
av_cold int ff_gfxcapture_init (AVFilterContext *avctx) noexcept
 
int ff_gfxcapture_activate (AVFilterContext *avctx) noexcept
 
int ff_gfxcapture_config_props (AVFilterLink *outlink) noexcept
 

Macro Definition Documentation

◆ TIMESPAN_RES

#define TIMESPAN_RES   10000000

Definition at line 70 of file vsrc_gfxcapture_winrt.cpp.

◆ TIMESPAN_RES64

#define TIMESPAN_RES64   INT64_C(10000000)

Definition at line 71 of file vsrc_gfxcapture_winrt.cpp.

◆ CAPTURE_POOL_SIZE

#define CAPTURE_POOL_SIZE   2

Definition at line 73 of file vsrc_gfxcapture_winrt.cpp.

◆ CCTX

#define CCTX (   ctx)    static_cast<GfxCaptureContext*>(ctx)

Definition at line 79 of file vsrc_gfxcapture_winrt.cpp.

◆ CHECK_HR

#define CHECK_HR (   fcall,
  action 
)
Value:
do { \
HRESULT fhr = fcall; \
if (FAILED(fhr)) { \
av_log(avctx, AV_LOG_ERROR, #fcall " failed: 0x%08lX\n", fhr); \
action; \
} \
} while (0)

Definition at line 181 of file vsrc_gfxcapture_winrt.cpp.

◆ CHECK_HR_RET

#define CHECK_HR_RET (   ...)    CHECK_HR((__VA_ARGS__), return AVERROR_EXTERNAL)

Definition at line 189 of file vsrc_gfxcapture_winrt.cpp.

◆ CHECK_HR_FAIL

#define CHECK_HR_FAIL (   ...)    CHECK_HR((__VA_ARGS__), ret = AVERROR_EXTERNAL; goto fail)

Definition at line 190 of file vsrc_gfxcapture_winrt.cpp.

◆ CHECK_HR_LOG

#define CHECK_HR_LOG (   ...)    CHECK_HR((__VA_ARGS__), (void)0)

Definition at line 191 of file vsrc_gfxcapture_winrt.cpp.

◆ LOAD_DLL

#define LOAD_DLL (   handle,
  name 
)
Value:
handle = hmodule_ptr_t(LoadLibraryExW(L##name, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)); \
if (!handle) { \
av_log(avctx, AV_LOG_ERROR, "Failed opening " #name "\n"); \
return AVERROR(ENOSYS); \
}

◆ LOAD_FUNC

#define LOAD_FUNC (   handle,
  name 
)
Value:
GetProcAddressTyped(handle, #name, &ctx->fn.name); \
if (!ctx->fn.name) { \
av_log(avctx, AV_LOG_ERROR, "Failed loading " #name "\n"); \
return AVERROR(ENOSYS); \
}

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
WM_WGC_THREAD_SHUTDOWN 

Definition at line 75 of file vsrc_gfxcapture_winrt.cpp.

Function Documentation

◆ get_activation_factory()

template<typename T >
static HRESULT get_activation_factory ( GfxCaptureContextCpp ctx,
PCWSTR  clsid,
T **  factory 
)
static

Definition at line 170 of file vsrc_gfxcapture_winrt.cpp.

◆ wgc_frame_arrived_handler()

static void wgc_frame_arrived_handler ( const std::unique_ptr< GfxCaptureContextWgc > &  wgctx)
static

Definition at line 198 of file vsrc_gfxcapture_winrt.cpp.

◆ wgc_closed_handler()

static void wgc_closed_handler ( const std::unique_ptr< GfxCaptureContextWgc > &  wgctx)
static

Definition at line 206 of file vsrc_gfxcapture_winrt.cpp.

◆ wgc_stop_capture_session()

static void wgc_stop_capture_session ( AVFilterContext avctx)
staticnoexcept

Definition at line 214 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_uninit(), and wgc_thread_worker().

◆ wgc_calculate_client_area()

static int wgc_calculate_client_area ( AVFilterContext avctx)
static

◆ wgc_setup_gfxcapture_session()

static int wgc_setup_gfxcapture_session ( AVFilterContext avctx)
static

Definition at line 324 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_setup_gfxcapture_capture().

◆ wgc_setup_gfxcapture_capture()

static int wgc_setup_gfxcapture_capture ( AVFilterContext avctx)
static

Definition at line 405 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_init().

◆ wgc_try_get_next_frame()

static int wgc_try_get_next_frame ( AVFilterContext avctx,
ComPtr< IDirect3D11CaptureFrame > &  capture_frame 
)
static

Definition at line 445 of file vsrc_gfxcapture_winrt.cpp.

Referenced by process_frame_if_exists().

◆ wgc_setup_winrt()

static int wgc_setup_winrt ( AVFilterContext avctx)
static

Definition at line 479 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_init().

◆ wgc_thread_uninit()

static void wgc_thread_uninit ( AVFilterContext avctx)
staticnoexcept

Definition at line 500 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_entry(), and wgc_thread_init().

◆ wgc_thread_init()

static int wgc_thread_init ( AVFilterContext avctx)
static

Definition at line 511 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_entry().

◆ wgc_thread_worker()

static int wgc_thread_worker ( AVFilterContext avctx)
static

Definition at line 548 of file vsrc_gfxcapture_winrt.cpp.

Referenced by wgc_thread_entry().

◆ wgc_thread_entry()

static void wgc_thread_entry ( AVFilterContext avctx)
staticnoexcept

Definition at line 598 of file vsrc_gfxcapture_winrt.cpp.

Referenced by start_wgc_thread().

◆ stop_wgc_thread()

static int stop_wgc_thread ( AVFilterContext avctx)
static

Definition at line 655 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_uninit(), and setup_gfxcapture_capture().

◆ start_wgc_thread()

static int start_wgc_thread ( AVFilterContext avctx)
static

Definition at line 674 of file vsrc_gfxcapture_winrt.cpp.

Referenced by setup_gfxcapture_capture().

◆ run_on_wgc_thread()

template<typename F >
static int run_on_wgc_thread ( AVFilterContext avctx,
F &&  cb 
)
static

Definition at line 705 of file vsrc_gfxcapture_winrt.cpp.

Referenced by process_frame_if_exists().

◆ build_regex()

static int build_regex ( AVFilterContext avctx,
const char *  pattern,
std::regex *  out 
)
static

Definition at line 774 of file vsrc_gfxcapture_winrt.cpp.

Referenced by find_capture_source().

◆ wstring_to_utf8()

static int wstring_to_utf8 ( const wchar_t *  in,
std::string *  out 
)
static

Definition at line 801 of file vsrc_gfxcapture_winrt.cpp.

Referenced by find_capture_source(), and get_window_exe_name().

◆ get_window_exe_name()

static int get_window_exe_name ( HWND  hwnd,
std::string *  out 
)
static

Definition at line 816 of file vsrc_gfxcapture_winrt.cpp.

Referenced by find_capture_source().

◆ find_capture_source()

static int find_capture_source ( AVFilterContext avctx)
static

Definition at line 856 of file vsrc_gfxcapture_winrt.cpp.

Referenced by setup_gfxcapture_capture().

◆ gfxcapture_uninit()

static av_cold void gfxcapture_uninit ( AVFilterContext avctx)
static

Definition at line 970 of file vsrc_gfxcapture_winrt.cpp.

Referenced by ff_gfxcapture_uninit(), and gfxcapture_init().

◆ GetProcAddressTyped()

template<typename T >
static av_cold void GetProcAddressTyped ( const hmodule_ptr_t hModule,
LPCSTR  lpProcName,
T out 
)
static

Definition at line 990 of file vsrc_gfxcapture_winrt.cpp.

◆ load_functions()

static av_cold int load_functions ( AVFilterContext avctx)
static

Definition at line 994 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_init().

◆ gfxcapture_init()

static av_cold int gfxcapture_init ( AVFilterContext avctx)
static

Definition at line 1046 of file vsrc_gfxcapture_winrt.cpp.

Referenced by ff_gfxcapture_init().

◆ init_hwframes_ctx()

static int init_hwframes_ctx ( AVFilterContext avctx)
static

Definition at line 1067 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_config_props().

◆ setup_gfxcapture_capture()

static int setup_gfxcapture_capture ( AVFilterContext avctx)
static

Definition at line 1100 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_config_props().

◆ prepare_render_resources()

static int prepare_render_resources ( AVFilterContext avctx)
static

Definition at line 1142 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_config_props().

◆ gfxcapture_config_props()

static int gfxcapture_config_props ( AVFilterLink outlink)
static

Definition at line 1197 of file vsrc_gfxcapture_winrt.cpp.

Referenced by ff_gfxcapture_config_props().

◆ render_capture_to_frame()

static int render_capture_to_frame ( AVFilterContext avctx,
AVFrame frame,
const ComPtr< ID3D11Texture2D > &  src_tex 
)
static

Definition at line 1270 of file vsrc_gfxcapture_winrt.cpp.

Referenced by process_frame_if_exists().

◆ process_frame_if_exists()

static int process_frame_if_exists ( AVFilterLink outlink)
static

Definition at line 1396 of file vsrc_gfxcapture_winrt.cpp.

Referenced by gfxcapture_activate().

◆ gfxcapture_activate()

static int gfxcapture_activate ( AVFilterContext avctx)
static

Definition at line 1461 of file vsrc_gfxcapture_winrt.cpp.

Referenced by ff_gfxcapture_activate().

◆ ff_gfxcapture_uninit()

av_cold void ff_gfxcapture_uninit ( AVFilterContext avctx)
noexcept

Definition at line 1500 of file vsrc_gfxcapture_winrt.cpp.

◆ ff_gfxcapture_init()

av_cold int ff_gfxcapture_init ( AVFilterContext avctx)
noexcept

Definition at line 1511 of file vsrc_gfxcapture_winrt.cpp.

◆ ff_gfxcapture_activate()

int ff_gfxcapture_activate ( AVFilterContext avctx)
noexcept

Definition at line 1526 of file vsrc_gfxcapture_winrt.cpp.

◆ ff_gfxcapture_config_props()

int ff_gfxcapture_config_props ( AVFilterLink outlink)
noexcept

Definition at line 1541 of file vsrc_gfxcapture_winrt.cpp.

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
ctx
AVFormatContext * ctx
Definition: movenc.c:49
NULL
#define NULL
Definition: coverity.c:32
GetProcAddressTyped
static av_cold void GetProcAddressTyped(const hmodule_ptr_t &hModule, LPCSTR lpProcName, T *out)
Definition: vsrc_gfxcapture_winrt.cpp:990
hmodule_ptr_t
std::unique_ptr< HMODULE, HMODULEDeleter > hmodule_ptr_t
Definition: vsrc_gfxcapture_winrt.hpp:200
L
#define L(x)
Definition: vpx_arith.h:36