Go to the documentation of this file.
35 #include <AMF/core/Factory.h>
36 #include <AMF/core/Surface.h>
37 #include <AMF/components/ColorSpace.h>
38 #include <AMF/components/DisplayCapture.h>
57 #define OFFSET(x) offsetof(AMFGrabContext, x)
58 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
63 {
"duplicate_output",
"Use display output duplication for screen capture",
OFFSET(duplicate_output),
AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1,
FLAGS },
65 {
"capture_mode",
"Capture synchronization mode",
OFFSET(capture_mode),
AV_OPT_TYPE_INT, {.i64 = AMF_DISPLAYCAPTURE_MODE_KEEP_FRAMERATE}, 0, 2,
FLAGS,
"mode" },
66 {
"keep_framerate",
"Capture component maintains the frame rate", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_DISPLAYCAPTURE_MODE_KEEP_FRAMERATE}, 0, 0,
FLAGS,
"mode" },
67 {
"wait_for_present",
"Capture component waits for flip (present) event", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_DISPLAYCAPTURE_MODE_WAIT_FOR_PRESENT}, 0, 0,
FLAGS,
"mode" },
68 {
"get_current",
"Returns current visible surface immediately", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_DISPLAYCAPTURE_MODE_GET_CURRENT_SURFACE}, 0, 0,
FLAGS,
"mode" },
79 typedef WINMMAPI MMRESULT (WINAPI *timeBeginPeriod_fn)( UINT uPeriod);
80 typedef WINMMAPI MMRESULT (WINAPI *timeEndPeriod_fn)(UINT uPeriod);
84 ctx->winmmdll = dlopen(
"Winmm.dll", 0);
86 timeBeginPeriod_fn
fn = (timeBeginPeriod_fn)dlsym(
ctx->winmmdll,
"timeBeginPeriod");
88 ctx->timerPrecision = 1;
89 while (
fn(
ctx->timerPrecision) == TIMERR_NOCANDO)
91 ++
ctx->timerPrecision;
99 timeEndPeriod_fn
fn = (timeEndPeriod_fn)dlsym(
ctx->winmmdll,
"timeEndPeriod");
101 fn(
ctx->timerPrecision);
102 dlclose(
ctx->winmmdll);
112 AMFInterface *surface = (AMFInterface*)(
data);
113 if (surface && surface->pVtbl)
114 ref = surface->pVtbl->Release(surface);
123 ctx->capture->pVtbl->Drain(
ctx->capture);
124 ctx->capture->pVtbl->Terminate(
ctx->capture);
125 ctx->capture->pVtbl->Release(
ctx->capture);
131 amf_restore_timer_precision(
ctx);
139 amf_increase_timer_precision(
ctx);
156 AMFVariantStruct var = {0};
159 res = amf_device_ctx->factory->pVtbl->CreateComponent(amf_device_ctx->factory,
160 amf_device_ctx->context,
165 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->capture, AMF_DISPLAYCAPTURE_MONITOR_INDEX,
ctx->monitor_index);
171 if (
ctx->framerate.num > 0 &&
ctx->framerate.den > 0)
176 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->capture, AMF_DISPLAYCAPTURE_DUPLICATEOUTPUT,
ctx->duplicate_output);
178 av_log(avctx,
AV_LOG_ERROR,
"Failed to set AMF_DISPLAYCAPTURE_DUPLICATEOUTPUT: %d\n", res);
182 AMF_ASSIGN_PROPERTY_RATE(res,
ctx->capture, AMF_DISPLAYCAPTURE_FRAMERATE,
framerate);
188 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->capture, AMF_DISPLAYCAPTURE_MODE,
ctx->capture_mode);
193 res =
ctx->capture->pVtbl->Init(
ctx->capture, AMF_SURFACE_UNKNOWN, 0, 0);
199 res =
ctx->capture->pVtbl->GetProperty(
ctx->capture, AMF_DISPLAYCAPTURE_RESOLUTION, &var);
200 if (res == AMF_OK && var.type == AMF_VARIANT_SIZE) {
206 outlink->
w, outlink->
h);
209 AMFVariantClear(&var);
213 res =
ctx->capture->pVtbl->GetProperty(
ctx->capture, AMF_DISPLAYCAPTURE_FORMAT, &var);
214 if (res == AMF_OK && var.type == AMF_VARIANT_INT64) {
215 ctx->format = (AMF_SURFACE_FORMAT)var.int64Value;
218 ctx->format = AMF_SURFACE_BGRA;
225 AMFVariantClear(&var);
267 frames_ctx->
width = outlink->
w;
268 frames_ctx->
height = outlink->
h;
292 AMFSurface *surface =
NULL;
295 AMFData *data_out =
NULL;
305 res =
ctx->capture->pVtbl->QueryOutput(
ctx->capture, &data_out);
307 if (res == AMF_REPEAT) {
312 if (res == AMF_EOF) {
318 if (res != AMF_OK || !data_out) {
325 AMFGuid guid = IID_AMFSurface();
326 ret = data_out->pVtbl->QueryInterface(data_out, &guid, (
void**)&surface);
327 data_out->pVtbl->Release(data_out);
328 if (
ret != AMF_OK || !surface) {
335 surface->pVtbl->Release(surface);
339 frame->width = outlink->
w;
340 frame->height = outlink->
h;
343 amf_pts
pts = surface->pVtbl->GetPts(surface);
348 frame->data[0] = (uint8_t*)surface;
352 if (!
frame->buf[0]) {
354 surface->pVtbl->Release(surface);
358 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
361 for (
i = 0;
i < surface->pVtbl->GetPlanesCount(surface);
i++) {
362 plane = surface->pVtbl->GetPlaneAt(surface,
i);
363 frame->data[
i] = plane->pVtbl->GetNative(plane);
364 frame->linesize[
i] = plane->pVtbl->GetHPitch(plane);
372 format_amf = surface->pVtbl->GetFormat(surface);
389 .
p.
name =
"vsrc_amf",
391 .p.priv_class = &amf_capture_class,
#define AV_LOG_WARNING
Something somehow does not look correct.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
amf_uint32 timerPrecision
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int amf_config_props(AVFilterLink *outlink)
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Link properties exposed to filter code, but not external callers.
void * priv
private data for use by the filter
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted then it is pulled from the input slice through the input converter and horizontal scaler The result is also stored in the ring buffer to serve future vertical scaler requests When no more output can be generated because lines from a future slice would be then all remaining lines in the current slice are horizontally scaled and put in the ring buffer[This is done for luma and chroma, each with possibly different numbers of lines per picture.] Input to YUV Converter When the input to the main path is not planar bits per component YUV or bit it is converted to planar bit YUV Two sets of converters exist for this the other leaves the full chroma resolution
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
int extra_hw_frames
Sets the number of extra hardware frames which the filter will allocate on its output links for use i...
static int amf_capture_frame(AVFilterLink *outlink)
static const AVFilterPad amf_outputs[]
A filter pad used for either input or output.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
AVBufferRef * device_ctx_ref
static int amf_init_vsrc(AVFilterLink *outlink)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value,...)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_OUTPUTS(array)
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 link
amf_bool duplicate_output
Describe the class of an AVClass context structure.
AMF_SURFACE_FORMAT format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
static FilterLink * ff_filter_link(AVFilterLink *link)
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int(* init)(AVBSFContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFILTER_DEFINE_CLASS(amf_capture)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
int format
agreed upon media format
This struct is allocated as AVHWDeviceContext.hwctx.
AVFilterContext * src
source filter
#define AVERROR_EXTERNAL
Generic error in an external library.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
#define AV_LOG_INFO
Standard information.
static av_cold void amf_uninit(AVFilterContext *avctx)
static void uninit(AVBSFContext *ctx)
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
#define i(width, name, range_min, range_max)
static AVBufferRef * hw_device_ctx
int w
agreed upon image width
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static av_cold int amf_init(AVFilterContext *avctx)
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
int initial_pool_size
Initial size of the frame pool.
AVFilter p
The public AVFilter.
A reference to a data buffer.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static void amf_release_surface(void *opaque, uint8_t *data)
const FFFilter ff_vsrc_amf_capture
static const AVOption amf_capture_options[]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)