FFmpeg
Data Structures | Macros | Functions | Variables
vsrc_ddagrab.c File Reference
#include "config.h"
#include <windows.h>
#include <initguid.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "libavutil/avstring.h"
#include "libavutil/avassert.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_d3d11va.h"
#include "compat/w32dlfcn.h"
#include "avfilter.h"
#include "internal.h"
#include "video.h"
#include "vsrc_ddagrab_shaders.h"

Go to the source code of this file.

Data Structures

struct  DdagrabContext
 
struct  ConstBufferData
 

Macros

#define _WIN32_WINNT   0x0A00
 
#define COBJMACROS
 
#define TIMER_RES   1000000
 
#define TIMER_RES64   INT64_C(1000000)
 
#define OFFSET(x)   offsetof(DdagrabContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Functions

 AVFILTER_DEFINE_CLASS (ddagrab)
 
static void release_resource (void *resource)
 
static av_cold void ddagrab_uninit (AVFilterContext *avctx)
 
static av_cold int init_dxgi_dda (AVFilterContext *avctx)
 
static av_cold int init_render_resources (AVFilterContext *avctx)
 
static av_cold int ddagrab_init (AVFilterContext *avctx)
 
static int create_d3d11_pointer_tex (AVFilterContext *avctx, uint8_t *buf, DXGI_OUTDUPL_POINTER_SHAPE_INFO *shape_info, ID3D11Texture2D **out_tex, ID3D11ShaderResourceView **res_view)
 
static int convert_mono_buffer (uint8_t *input, uint8_t **rgba_out, uint8_t **xor_out, int *_width, int *_height, int *_pitch)
 
static int fixup_color_mask (uint8_t *input, uint8_t **rgba_out, uint8_t **xor_out, int width, int height, int pitch)
 
static int update_mouse_pointer (AVFilterContext *avctx, DXGI_OUTDUPL_FRAME_INFO *frame_info)
 
static int next_frame_internal (AVFilterContext *avctx, ID3D11Texture2D **desktop_texture, int need_frame)
 
static int probe_output_format (AVFilterContext *avctx)
 
static av_cold int init_hwframes_ctx (AVFilterContext *avctx)
 
static int ddagrab_config_props (AVFilterLink *outlink)
 
static int draw_mouse_pointer (AVFilterContext *avctx, AVFrame *frame)
 
static int ddagrab_request_frame (AVFilterLink *outlink)
 

Variables

static const AVOption ddagrab_options []
 
static const D3D11_INPUT_ELEMENT_DESC vertex_shader_input_layout []
 
static const AVFilterPad ddagrab_outputs []
 
const AVFilter ff_vsrc_ddagrab
 

Macro Definition Documentation

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0A00

Definition at line 23 of file vsrc_ddagrab.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 28 of file vsrc_ddagrab.c.

◆ TIMER_RES

#define TIMER_RES   1000000

Definition at line 51 of file vsrc_ddagrab.c.

◆ TIMER_RES64

#define TIMER_RES64   INT64_C(1000000)

Definition at line 52 of file vsrc_ddagrab.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(DdagrabContext, x)

Definition at line 106 of file vsrc_ddagrab.c.

◆ FLAGS

Definition at line 107 of file vsrc_ddagrab.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( ddagrab  )

◆ release_resource()

static void release_resource ( void *  resource)
inlinestatic

◆ ddagrab_uninit()

static av_cold void ddagrab_uninit ( AVFilterContext avctx)
static

Definition at line 141 of file vsrc_ddagrab.c.

◆ init_dxgi_dda()

static av_cold int init_dxgi_dda ( AVFilterContext avctx)
static

Definition at line 166 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ init_render_resources()

static av_cold int init_render_resources ( AVFilterContext avctx)
static

Definition at line 333 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ ddagrab_init()

static av_cold int ddagrab_init ( AVFilterContext avctx)
static

Definition at line 434 of file vsrc_ddagrab.c.

◆ create_d3d11_pointer_tex()

static int create_d3d11_pointer_tex ( AVFilterContext avctx,
uint8_t *  buf,
DXGI_OUTDUPL_POINTER_SHAPE_INFO *  shape_info,
ID3D11Texture2D **  out_tex,
ID3D11ShaderResourceView **  res_view 
)
static

Definition at line 448 of file vsrc_ddagrab.c.

Referenced by update_mouse_pointer().

◆ convert_mono_buffer()

static int convert_mono_buffer ( uint8_t *  input,
uint8_t **  rgba_out,
uint8_t **  xor_out,
int _width,
int _height,
int _pitch 
)
static

Definition at line 501 of file vsrc_ddagrab.c.

Referenced by update_mouse_pointer().

◆ fixup_color_mask()

static int fixup_color_mask ( uint8_t *  input,
uint8_t **  rgba_out,
uint8_t **  xor_out,
int  width,
int  height,
int  pitch 
)
static

Definition at line 562 of file vsrc_ddagrab.c.

Referenced by update_mouse_pointer().

◆ update_mouse_pointer()

static int update_mouse_pointer ( AVFilterContext avctx,
DXGI_OUTDUPL_FRAME_INFO *  frame_info 
)
static

Definition at line 592 of file vsrc_ddagrab.c.

Referenced by next_frame_internal().

◆ next_frame_internal()

static int next_frame_internal ( AVFilterContext avctx,
ID3D11Texture2D **  desktop_texture,
int  need_frame 
)
static

Definition at line 681 of file vsrc_ddagrab.c.

Referenced by ddagrab_request_frame(), and probe_output_format().

◆ probe_output_format()

static int probe_output_format ( AVFilterContext avctx)
static

Definition at line 732 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ init_hwframes_ctx()

static av_cold int init_hwframes_ctx ( AVFilterContext avctx)
static

Definition at line 760 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ ddagrab_config_props()

static int ddagrab_config_props ( AVFilterLink outlink)
static

Definition at line 808 of file vsrc_ddagrab.c.

◆ draw_mouse_pointer()

static int draw_mouse_pointer ( AVFilterContext avctx,
AVFrame frame 
)
static

Definition at line 883 of file vsrc_ddagrab.c.

Referenced by ddagrab_request_frame().

◆ ddagrab_request_frame()

static int ddagrab_request_frame ( AVFilterLink outlink)
static

Definition at line 1031 of file vsrc_ddagrab.c.

Variable Documentation

◆ ddagrab_options

const AVOption ddagrab_options[]
static
Initial value:
= {
{ "output_idx", "dda output index to capture", OFFSET(output_idx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "draw_mouse", "draw the mouse pointer", OFFSET(draw_mouse), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
{ "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, { .str = "30" }, 0, INT_MAX, FLAGS },
{ "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
{ "offset_x", "capture area x offset", OFFSET(offset_x), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
{ "offset_y", "capture area y offset", OFFSET(offset_y), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
{ "output_fmt", "desired output format", OFFSET(out_fmt), AV_OPT_TYPE_INT, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "auto", "let dda pick its preferred format", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "8bit", "only output default 8 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "bgra", "only output 8 Bit BGRA", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "10bit", "only output default 10 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "x2bgr10", "only output 10 Bit X2BGR10", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
{ "16bit", "only output default 16 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, "output_fmt" },
{ "rgbaf16", "only output 16 Bit RGBAF16", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, "output_fmt" },
{ "allow_fallback", "don't error on fallback to default 8 Bit format",
OFFSET(allow_fallback), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "force_fmt", "exclude BGRA from format list (experimental, discouraged by Microsoft)",
OFFSET(force_fmt), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
}

Definition at line 108 of file vsrc_ddagrab.c.

◆ vertex_shader_input_layout

const D3D11_INPUT_ELEMENT_DESC vertex_shader_input_layout[]
static
Initial value:
=
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
}

Definition at line 327 of file vsrc_ddagrab.c.

Referenced by init_render_resources().

◆ ddagrab_outputs

const AVFilterPad ddagrab_outputs[]
static
Initial value:
= {
{
.name = "default",
.request_frame = ddagrab_request_frame,
.config_props = ddagrab_config_props,
},
}

Definition at line 1187 of file vsrc_ddagrab.c.

◆ ff_vsrc_ddagrab

const AVFilter ff_vsrc_ddagrab
Initial value:
= {
.name = "ddagrab",
.description = NULL_IF_CONFIG_SMALL("Grab Windows Desktop images using Desktop Duplication API"),
.priv_size = sizeof(DdagrabContext),
.priv_class = &ddagrab_class,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}

Definition at line 1196 of file vsrc_ddagrab.c.

FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:364
DXGI_FORMAT_B8G8R8A8_UNORM
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition: dds.c:91
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
ddagrab_request_frame
static int ddagrab_request_frame(AVFilterLink *outlink)
Definition: vsrc_ddagrab.c:1031
width
#define width
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
framerate
float framerate
Definition: av1_levels.c:29
NULL
#define NULL
Definition: coverity.c:32
ddagrab_config_props
static int ddagrab_config_props(AVFilterLink *outlink)
Definition: vsrc_ddagrab.c:808
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
ddagrab_uninit
static av_cold void ddagrab_uninit(AVFilterContext *avctx)
Definition: vsrc_ddagrab.c:141
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:138
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:333
FLAGS
#define FLAGS
Definition: vsrc_ddagrab.c:107
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:182
DXGI_FORMAT_R16G16B16A16_FLOAT
@ DXGI_FORMAT_R16G16B16A16_FLOAT
Definition: dds.c:62
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
ddagrab_outputs
static const AVFilterPad ddagrab_outputs[]
Definition: vsrc_ddagrab.c:1187
ddagrab_init
static av_cold int ddagrab_init(AVFilterContext *avctx)
Definition: vsrc_ddagrab.c:434
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:285
DdagrabContext
Definition: vsrc_ddagrab.c:54
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
OFFSET
#define OFFSET(x)
Definition: vsrc_ddagrab.c:106