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/mem.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 "filters.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 52 of file vsrc_ddagrab.c.

◆ TIMER_RES64

#define TIMER_RES64   INT64_C(1000000)

Definition at line 53 of file vsrc_ddagrab.c.

◆ OFFSET

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

Definition at line 109 of file vsrc_ddagrab.c.

◆ FLAGS

Definition at line 110 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 146 of file vsrc_ddagrab.c.

◆ init_dxgi_dda()

static av_cold int init_dxgi_dda ( AVFilterContext avctx)
static

Definition at line 172 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 339 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ ddagrab_init()

static av_cold int ddagrab_init ( AVFilterContext avctx)
static

Definition at line 440 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 454 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 507 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 568 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 598 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 687 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 779 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 807 of file vsrc_ddagrab.c.

Referenced by ddagrab_config_props().

◆ ddagrab_config_props()

static int ddagrab_config_props ( AVFilterLink outlink)
static

Definition at line 855 of file vsrc_ddagrab.c.

◆ draw_mouse_pointer()

static int draw_mouse_pointer ( AVFilterContext avctx,
AVFrame frame 
)
static

Definition at line 931 of file vsrc_ddagrab.c.

Referenced by ddagrab_request_frame().

◆ ddagrab_request_frame()

static int ddagrab_request_frame ( AVFilterLink outlink)
static

Definition at line 1079 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, .unit = "output_fmt" },
{ "auto", "let dda pick its preferred format", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "8bit", "only output default 8 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "bgra", "only output 8 Bit BGRA", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "10bit", "only output default 10 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "x2bgr10", "only output 10 Bit X2BGR10", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "16bit", "only output default 16 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, .unit = "output_fmt" },
{ "rgbaf16", "only output 16 Bit RGBAF16", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, .unit = "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 },
{ "dup_frames", "duplicate frames to maintain framerate",
OFFSET(dup_frames), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
{ NULL }
}

Definition at line 111 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 333 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 1237 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 1246 of file vsrc_ddagrab.c.

DXGI_FORMAT_B8G8R8A8_UNORM
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition: dds.c:91
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition: opt.h:315
ddagrab_request_frame
static int ddagrab_request_frame(AVFilterLink *outlink)
Definition: vsrc_ddagrab.c:1079
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
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:855
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
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
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: filters.h:206
ddagrab_uninit
static av_cold void ddagrab_uninit(AVFilterContext *avctx)
Definition: vsrc_ddagrab.c:146
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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:94
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:173
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
FLAGS
#define FLAGS
Definition: vsrc_ddagrab.c:110
DXGI_FORMAT_R16G16B16A16_FLOAT
@ DXGI_FORMAT_R16G16B16A16_FLOAT
Definition: dds.c:62
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
ddagrab_outputs
static const AVFilterPad ddagrab_outputs[]
Definition: vsrc_ddagrab.c:1237
ddagrab_init
static av_cold int ddagrab_init(AVFilterContext *avctx)
Definition: vsrc_ddagrab.c:440
DdagrabContext
Definition: vsrc_ddagrab.c:55
width
#define width
Definition: dsp.h:85
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
OFFSET
#define OFFSET(x)
Definition: vsrc_ddagrab.c:109