FFmpeg
Loading...
Searching...
No Matches
amfenc.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "config.h"
20
21#include "libavutil/avassert.h"
22#include "libavutil/imgutils.h"
23#include "libavutil/hwcontext.h"
25#if CONFIG_D3D11VA
27#endif
28#if CONFIG_DXVA2
29#define COBJMACROS
31#endif
32#include "libavutil/mem.h"
33#include "libavutil/pixdesc.h"
34#include "libavutil/time.h"
35
36#include "amfenc.h"
37#include "encode.h"
38
39#include <AMF/components/PreAnalysis.h>
40
41#define AMF_AV_FRAME_REF L"av_frame_ref"
42#define PTS_PROP L"PtsProp"
43
44#if CONFIG_D3D11VA
45#include <d3d11.h>
46#endif
47
48#ifdef _WIN32
49#include "compat/w32dlfcn.h"
50#else
51#include <dlfcn.h>
52#endif
53
54#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
55
56
77
79
81{
83 const wchar_t *codec_id = NULL;
84 AMF_RESULT res;
86 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
87 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
88 int alloc_size;
89 wchar_t name[512];
90
91
92 alloc_size = swprintf(name, amf_countof(name), L"%s%lld",PTS_PROP, next_encoder_index) + 1;
93 ctx->pts_property_name = av_memdup(name, alloc_size * sizeof(wchar_t));
94 if(!ctx->pts_property_name)
95 return AVERROR(ENOMEM);
96
97 alloc_size = swprintf(name, amf_countof(name), L"%s%lld",AMF_AV_FRAME_REF, next_encoder_index) + 1;
98 ctx->av_frame_property_name = av_memdup(name, alloc_size * sizeof(wchar_t));
99 if(!ctx->av_frame_property_name)
100 return AVERROR(ENOMEM);
101
103
104 switch (avctx->codec->id) {
105 case AV_CODEC_ID_H264:
106 codec_id = AMFVideoEncoderVCE_AVC;
107 break;
108 case AV_CODEC_ID_HEVC:
109 codec_id = AMFVideoEncoder_HEVC;
110 break;
111 case AV_CODEC_ID_AV1 :
112 codec_id = AMFVideoEncoder_AV1;
113 break;
114 default:
115 break;
116 }
117 AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id);
118
119 if (avctx->hw_frames_ctx)
120 pix_fmt = ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format;
121 else
122 pix_fmt = avctx->pix_fmt;
123
124 if (pix_fmt == AV_PIX_FMT_P010) {
125 AMF_RETURN_IF_FALSE(ctx, amf_device_ctx->version >= AMF_MAKE_FULL_VERSION(1, 4, 32, 0), AVERROR_UNKNOWN, "10-bit encoder is not supported by AMD GPU drivers versions lower than 23.30.\n");
126 }
127
129 AMF_RETURN_IF_FALSE(ctx, ctx->format != AMF_SURFACE_UNKNOWN, AVERROR(EINVAL),
130 "Format %s is not supported\n", av_get_pix_fmt_name(pix_fmt));
131
132 res = amf_device_ctx->factory->pVtbl->CreateComponent(amf_device_ctx->factory, amf_device_ctx->context, codec_id, &ctx->encoder);
133 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res);
134
135 ctx->submitted_frame = 0;
136 ctx->encoded_frame = 0;
137 ctx->eof = 0;
138
139 return 0;
140}
141
143{
145
146 if (ctx->encoder) {
147 ctx->encoder->pVtbl->Terminate(ctx->encoder);
148 ctx->encoder->pVtbl->Release(ctx->encoder);
149 ctx->encoder = NULL;
150 }
151
152 av_buffer_unref(&ctx->device_ctx_ref);
153 av_fifo_freep2(&ctx->timestamp_list);
154
155 if (ctx->output_list) {
156 // release remaining AMF output buffers
157 while(av_fifo_can_read(ctx->output_list)) {
158 AMFBuffer* buffer = NULL;
159 av_fifo_read(ctx->output_list, &buffer, 1);
160 if(buffer != NULL)
161 buffer->pVtbl->Release(buffer);
162 }
163 av_fifo_freep2(&ctx->output_list);
164 }
165 av_freep(&ctx->pts_property_name);
166 av_freep(&ctx->av_frame_property_name);
167
168 return 0;
169}
170
171int ff_amf_get_lookahead_depth_max(AVCodecContext *avctx, AMFComponent *encoder, amf_uint64 runtime_version, amf_int64 *out_max)
172{
173 if (!encoder || !out_max)
174 return AVERROR(EINVAL);
175
176 *out_max = MAX_LOOKAHEAD_DEPTH;
177#if AMF_VERSION_ATLEAST(1, 5, 3)
178 const AMFPropertyInfo *prop_info = NULL;
179 AMF_RESULT res;
180
181 if (runtime_version >= AMF_MAKE_FULL_VERSION(1, 5, 3, 0)) {
182 res = encoder->pVtbl->GetPropertyInfo(encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH, &prop_info);
183 if (res == AMF_OK && prop_info && prop_info->type == AMF_VARIANT_INT64) {
184 *out_max = prop_info->maxValue.int64Value;
185 } else {
186 av_log(avctx, AV_LOG_DEBUG, "Failed to query maximum lookahead depth, using %d\n", MAX_LOOKAHEAD_DEPTH);
187 }
188 }
189#endif
190 return 0;
191}
192
194{
195 AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)ctx->device_ctx_ref->data;
196 AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
197 amf_int64 hw_max;
198 AMF_RESULT res;
199
200 if (ff_amf_get_lookahead_depth_max(avctx, ctx->encoder, amf_ctx->version, &hw_max) == 0 &&
201 ctx->pa_lookahead_buffer_depth > hw_max) {
202 av_log(avctx, AV_LOG_WARNING,
203 "pa_lookahead_buffer_depth %d exceeds supported maximum %lld, clamping\n",
204 ctx->pa_lookahead_buffer_depth, (long long)hw_max);
205 ctx->pa_lookahead_buffer_depth = (int)hw_max;
206 }
207
208 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH, ctx->pa_lookahead_buffer_depth);
209 if (res != AMF_OK)
210 av_log(avctx, AV_LOG_WARNING, "Setting lookahead buffer depth failed with error %d\n", res);
211}
212
214{
215 AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)ctx->device_ctx_ref->data;
216 AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
217 // Size async_depth to the lookahead window in two independent steps:
218 // - bump: widen async_depth to fit the lookahead depth read back from the
219 // encoder (the applied value; only present when preanalysis is enabled).
220 // - cap: limit async_depth to the reported maximum + 1 when it can be queried.
221 amf_int64 hw_max;
222 AMFVariantStruct var = { 0 };
223 AMF_RESULT res;
224
225 res = ctx->encoder->pVtbl->GetProperty(ctx->encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH, &var);
226 if (res == AMF_OK && var.int64Value >= ctx->hwsurfaces_in_queue_max) {
227 av_log(avctx, AV_LOG_WARNING,
228 "async_depth (%d) too small for lookahead (%lld), increasing to (%lld)\n",
229 ctx->hwsurfaces_in_queue_max, (long long)var.int64Value, (long long)(var.int64Value + 1));
230 ctx->hwsurfaces_in_queue_max = (int)(var.int64Value + 1);
231 }
232
233 if (ff_amf_get_lookahead_depth_max(avctx, ctx->encoder, amf_ctx->version, &hw_max) == 0 &&
234 ctx->hwsurfaces_in_queue_max > hw_max + 1) {
235 av_log(avctx, AV_LOG_WARNING,
236 "async_depth %d exceeds supported range, clamping to %lld\n",
237 ctx->hwsurfaces_in_queue_max, (long long)(hw_max + 1));
238 ctx->hwsurfaces_in_queue_max = (int)(hw_max + 1);
239 }
240}
241
243 AMFSurface* surface)
244{
245 AMFPlane *plane;
246 uint8_t *dst_data[4] = {0};
247 int dst_linesize[4] = {0};
248 int planes;
249 int i;
250
251 planes = (int)surface->pVtbl->GetPlanesCount(surface);
252 av_assert0(planes < FF_ARRAY_ELEMS(dst_data));
253
254 for (i = 0; i < planes; i++) {
255 plane = surface->pVtbl->GetPlaneAt(surface, i);
256 dst_data[i] = plane->pVtbl->GetNative(plane);
257 dst_linesize[i] = plane->pVtbl->GetHPitch(plane);
258 }
259 av_image_copy2(dst_data, dst_linesize,
260 frame->data, frame->linesize, frame->format,
261 avctx->width, avctx->height);
262
263 return 0;
264}
265
266static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer *buffer)
267{
269 int ret;
270 AMFVariantStruct var = {0};
271 int64_t timestamp = AV_NOPTS_VALUE;
272 int64_t size = buffer->pVtbl->GetSize(buffer);
273 enum AVPictureType pict_type = 0;
274 int average_qp = -1;
275
276 if ((ret = ff_get_encode_buffer(avctx, pkt, size, 0)) < 0) {
277 return ret;
278 }
279 memcpy(pkt->data, buffer->pVtbl->GetNative(buffer), size);
280
281 switch (avctx->codec->id) {
282 case AV_CODEC_ID_H264:
283 buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE, &var);
284 pkt->flags |= AV_PKT_FLAG_KEY * (var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_IDR);
285 pict_type = var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_IDR ? AV_PICTURE_TYPE_I :
286 var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_I ? AV_PICTURE_TYPE_I :
287 var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_P ? AV_PICTURE_TYPE_P :
288 var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_B ? AV_PICTURE_TYPE_B : 0;
289
290 var.int64Value = -1;
291 if ((buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_STATISTIC_AVERAGE_QP, &var)) == AMF_OK) {
292 average_qp = FFMAX((int)var.int64Value, -1);
293 }
294 break;
295 case AV_CODEC_ID_HEVC:
296 buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE, &var);
297 pkt->flags |= AV_PKT_FLAG_KEY * (var.int64Value == AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE_IDR);
298 pict_type = var.int64Value == AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE_IDR ? AV_PICTURE_TYPE_I :
299 var.int64Value == AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE_I ? AV_PICTURE_TYPE_I :
300 var.int64Value == AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE_P ? AV_PICTURE_TYPE_P : 0;
301
302 var.int64Value = -1;
303 if ((buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_HEVC_STATISTIC_AVERAGE_QP, &var)) == AMF_OK) {
304 average_qp = FFMAX((int)var.int64Value, -1);
305 }
306 break;
307 case AV_CODEC_ID_AV1:
308 buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE, &var);
309 pkt->flags |= AV_PKT_FLAG_KEY * (var.int64Value == AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE_KEY);
310 pict_type = var.int64Value == AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE_KEY ? AV_PICTURE_TYPE_I :
311 var.int64Value == AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE_INTRA_ONLY ? AV_PICTURE_TYPE_I :
312 var.int64Value == AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE_INTER ? AV_PICTURE_TYPE_P : 0;
313
314 var.int64Value = -1;
315 if ((buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_AV1_STATISTIC_AVERAGE_Q_INDEX, &var)) == AMF_OK) {
316 average_qp = FFMAX((int)var.int64Value, -1); // av1 qindex
317 if (average_qp >= 0) {
318 average_qp = (average_qp > 244) ? (average_qp <= 249 ? 62 : 63) : (average_qp + 3) >> 2; // av1 quantizer
319 }
320 }
321 break;
322 default:
323 break;
324 }
325
326 if (ctx->qp_stats && average_qp >= 0) {
327 ff_encode_add_stats_side_data(pkt, average_qp * FF_QP2LAMBDA, NULL, 0, pict_type);
328 }
329
330 buffer->pVtbl->GetProperty(buffer, ctx->pts_property_name, &var);
331
332 pkt->pts = var.int64Value; // original pts
333
334 AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, &timestamp, 1) >= 0,
335 AVERROR_UNKNOWN, "timestamp_list is empty\n");
336
337 // calc dts shift if max_b_frames > 0
338 if ((ctx->max_b_frames > 0 || ((ctx->pa_adaptive_mini_gop == 1) ? true : false)) && ctx->dts_delay == 0) {
339 int64_t timestamp_last = AV_NOPTS_VALUE;
340 size_t can_read = av_fifo_can_read(ctx->timestamp_list);
341
343 "timestamp_list is empty while max_b_frames = %d\n", avctx->max_b_frames);
344 av_fifo_peek(ctx->timestamp_list, &timestamp_last, 1, can_read - 1);
345 if (timestamp < 0 || timestamp_last < AV_NOPTS_VALUE) {
346 return AVERROR(ERANGE);
347 }
348 ctx->dts_delay = timestamp_last - timestamp;
349 }
350 pkt->dts = timestamp - ctx->dts_delay;
351 return 0;
352}
353
354// amfenc API implementation
356{
357 int ret;
359 AVHWDeviceContext *hwdev_ctx = NULL;
360
361 // hardcoded to current HW queue size - will auto-realloc if too small
362 ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, sizeof(int64_t),
364 if (!ctx->timestamp_list) {
365 return AVERROR(ENOMEM);
366 }
367 ctx->output_list = av_fifo_alloc2(2, sizeof(AMFBuffer*), AV_FIFO_FLAG_AUTO_GROW);
368 if (!ctx->output_list)
369 return AVERROR(ENOMEM);
370
371 ctx->dts_delay = 0;
372
373 ctx->hwsurfaces_in_queue = 0;
374
375 if (avctx->hw_device_ctx) {
376 hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
377 if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
378 {
379 ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx);
380 }
381 else {
383 AMF_RETURN_IF_FALSE(ctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
384 }
385 } else if (avctx->hw_frames_ctx) {
387 if (frames_ctx->device_ref ) {
388 if (frames_ctx->format == AV_PIX_FMT_AMF_SURFACE) {
389 ctx->device_ctx_ref = av_buffer_ref(frames_ctx->device_ref);
390 }
391 else {
392 ret = av_hwdevice_ctx_create_derived(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, frames_ctx->device_ref, 0);
393 AMF_RETURN_IF_FALSE(ctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
394 }
395 }
396 }
397 else {
399 AMF_RETURN_IF_FALSE(ctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret));
400 }
401
402 if ((ret = amf_init_encoder(avctx)) == 0) {
403 return 0;
404 }
405
406 ff_amf_encode_close(avctx);
407 return ret;
408}
409
410static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const wchar_t *name, AMFBuffer *val)
411{
412 AMF_RESULT res;
413 AMFVariantStruct var;
414 res = AMFVariantInit(&var);
415 if (res == AMF_OK) {
416 AMFGuid guid_AMFInterface = IID_AMFInterface();
417 AMFInterface *amf_interface;
418 res = val->pVtbl->QueryInterface(val, &guid_AMFInterface, (void**)&amf_interface);
419
420 if (res == AMF_OK) {
421 res = AMFVariantAssignInterface(&var, amf_interface);
422 amf_interface->pVtbl->Release(amf_interface);
423 }
424 if (res == AMF_OK) {
425 res = object->pVtbl->SetProperty(object, name, var);
426 }
427 AMFVariantClear(&var);
428 }
429 return res;
430}
431
432static AMF_RESULT amf_store_attached_frame_ref(AMFEncoderContext *ctx, const AVFrame *frame, AMFSurface *surface)
433{
434 AMF_RESULT res = AMF_FAIL;
437 if (frame_ref) {
438 memcpy(&data, &frame_ref, sizeof(frame_ref)); // store pointer in 8 bytes
439 AMF_ASSIGN_PROPERTY_INT64(res, surface, ctx->av_frame_property_name, data);
440 }
441 return res;
442}
443
445{
446 AMFVariantStruct var = {0};
447 AMF_RESULT res = buffer->pVtbl->GetProperty(buffer, ctx->av_frame_property_name, &var);
448 if(res == AMF_OK && var.int64Value){
450 memcpy(&frame_ref, &var.int64Value, sizeof(frame_ref));
452 }
453 return res;
454}
455
456static int amf_submit_frame(AVCodecContext *avctx, AVFrame *frame, AMFSurface **surface_resubmit)
457{
459 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
460 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
461 AMFSurface *surface;
462 AMF_RESULT res;
463 int ret;
464 int hw_surface = 0;
465 int output_delay = FFMAX(ctx->max_b_frames, 0) + ((avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 1);
466
467// prepare surface from frame
468 switch (frame->format) {
469#if CONFIG_D3D11VA
470 case AV_PIX_FMT_D3D11:
471 {
472 static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
473 ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // actual texture
474 int index = (intptr_t)frame->data[1]; // index is a slice in texture array is - set to tell AMF which slice to use
475 av_assert0(frame->hw_frames_ctx && avctx->hw_frames_ctx &&
476 frame->hw_frames_ctx->data == avctx->hw_frames_ctx->data);
477 texture->lpVtbl->SetPrivateData(texture, &AMFTextureArrayIndexGUID, sizeof(index), &index);
478 res = amf_device_ctx->context->pVtbl->CreateSurfaceFromDX11Native(amf_device_ctx->context, texture, &surface, NULL); // wrap to AMF surface
479 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "CreateSurfaceFromDX11Native() failed with error %d\n", res);
480 hw_surface = 1;
481 }
482 break;
483#endif
484#if CONFIG_DXVA2
486 {
487 IDirect3DSurface9 *texture = (IDirect3DSurface9 *)frame->data[3]; // actual texture
488 res = amf_device_ctx->context->pVtbl->CreateSurfaceFromDX9Native(amf_device_ctx->context, texture, &surface, NULL); // wrap to AMF surface
489 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "CreateSurfaceFromDX9Native() failed with error %d\n", res);
490 hw_surface = 1;
491 }
492 break;
493#endif
495 {
496 surface = (AMFSurface*)frame->data[0];
497 surface->pVtbl->Acquire(surface);
498 hw_surface = 1;
499 }
500 break;
501 default:
502 {
503 res = amf_device_ctx->context->pVtbl->AllocSurface(amf_device_ctx->context, AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
504 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "AllocSurface() failed with error %d\n", res);
505 amf_copy_surface(avctx, frame, surface);
506 }
507 break;
508 }
509 if (hw_surface) {
511 ctx->hwsurfaces_in_queue++;
512 // input HW surfaces can be vertically aligned by 16; tell AMF the real size
513 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, frame->height);
514 }
515 // HDR10 metadata
516 if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
517 AMFBuffer * hdrmeta_buffer = NULL;
518 res = amf_device_ctx->context->pVtbl->AllocBuffer(amf_device_ctx->context, AMF_MEMORY_HOST, sizeof(AMFHDRMetadata), &hdrmeta_buffer);
519 if (res == AMF_OK) {
520 AMFHDRMetadata * hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
521 if (av_amf_extract_hdr_metadata(frame, hdrmeta) == 0) {
522 switch (avctx->codec->id) {
523 case AV_CODEC_ID_H264:
524 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
525 case AV_CODEC_ID_HEVC:
526 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
527 case AV_CODEC_ID_AV1:
528 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break;
529 }
530 res = amf_set_property_buffer(surface, L"av_frame_hdrmeta", hdrmeta_buffer);
531 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
532 }
533 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
534 }
535 }
536 surface->pVtbl->SetPts(surface, frame->pts);
537
538 AMF_ASSIGN_PROPERTY_INT64(res, surface, ctx->pts_property_name, frame->pts);
539
540 switch (avctx->codec->id) {
541 case AV_CODEC_ID_H264:
542 if (ctx->qp_stats) {
543 AMF_ASSIGN_PROPERTY_BOOL(res, surface, AMF_VIDEO_ENCODER_STATISTICS_FEEDBACK, 1);
544 }
545 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_AUD, !!ctx->aud);
546 switch (frame->pict_type) {
548 if (ctx->forced_idr) {
549 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_SPS, 1);
550 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_PPS, 1);
551 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_IDR);
552 } else {
553 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_I);
554 }
555 break;
557 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_P);
558 break;
560 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_B);
561 break;
562 }
563 break;
564 case AV_CODEC_ID_HEVC:
565 if (ctx->qp_stats) {
566 AMF_ASSIGN_PROPERTY_BOOL(res, surface, AMF_VIDEO_ENCODER_HEVC_STATISTICS_FEEDBACK, 1);
567 }
568 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_AUD, !!ctx->aud);
569 switch (frame->pict_type) {
571 if (ctx->forced_idr) {
572 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_HEADER, 1);
573 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_IDR);
574 } else {
575 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_I);
576 }
577 break;
579 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_P);
580 break;
581 }
582 break;
583 case AV_CODEC_ID_AV1:
584 if (ctx->qp_stats) {
585 AMF_ASSIGN_PROPERTY_BOOL(res, surface, AMF_VIDEO_ENCODER_AV1_STATISTICS_FEEDBACK, 1);
586 }
587 if (frame->pict_type == AV_PICTURE_TYPE_I) {
588 if (ctx->forced_idr) {
589 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_INSERT_SEQUENCE_HEADER, 1);
590 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE_KEY);
591 } else {
592 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE_INTRA_ONLY);
593 }
594 }
595 break;
596 default:
597 break;
598 }
599 // submit surface
600 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)surface);
601 if (res == AMF_INPUT_FULL) { // handle full queue
602 //store surface for later submission
603 *surface_resubmit = surface;
604 } else {
605 surface->pVtbl->Release(surface);
606 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SubmitInput() failed with error %d\n", res);
607 ctx->submitted_frame++;
608 ret = av_fifo_write(ctx->timestamp_list, &frame->pts, 1);
609 if (ret < 0)
610 return ret;
611 if(ctx->submitted_frame <= ctx->encoded_frame + output_delay)
612 return AVERROR(EAGAIN); // too soon to poll or wait
613 }
614 return 0;
615}
616
617static int amf_submit_frame_locked(AVCodecContext *avctx, AVFrame *frame, AMFSurface **surface_resubmit)
618{
619 int ret;
621 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
622 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
623
624 if (amf_device_ctx->lock)
625 amf_device_ctx->lock(amf_device_ctx->lock_ctx);
626 ret = amf_submit_frame(avctx, frame, surface_resubmit);
627 if (amf_device_ctx->unlock)
628 amf_device_ctx->unlock(amf_device_ctx->lock_ctx);
629
630 return ret;
631}
632static AMF_RESULT amf_query_output(AVCodecContext *avctx, AMFBuffer **buffer)
633{
635 AMFData *data = NULL;
636 AMF_RESULT ret = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, &data);
637 *buffer = NULL;
638 if (data) {
639 AMFGuid guid = IID_AMFBuffer();
640 data->pVtbl->QueryInterface(data, &guid, (void**)buffer); // query for buffer interface
641 data->pVtbl->Release(data);
643 ctx->hwsurfaces_in_queue--;
644 ctx->encoded_frame++;
645 }
646 return ret;
647}
648
650{
652 AMFSurface *surface = NULL;
653 AMF_RESULT res;
654 int ret;
655 AMF_RESULT res_query;
656 AMFBuffer* buffer = NULL;
658 int block_and_wait;
659 int64_t pts = 0;
660 int output_delay = FFMAX(ctx->max_b_frames, 0) + ((avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 1);
661
662 if (!ctx->encoder){
664 return AVERROR(EINVAL);
665 }
666 // check if some outputs are available
667 av_fifo_read(ctx->output_list, &buffer, 1);
668 if (buffer != NULL) { // return already retrieved output
669 ret = amf_copy_buffer(avctx, avpkt, buffer);
670 buffer->pVtbl->Release(buffer);
671 return ret;
672 }
673
674 ret = ff_encode_get_frame(avctx, frame);
675 if(ret < 0){
676 if(ret != AVERROR_EOF){
678 if(ret == AVERROR(EAGAIN)){
679 if(ctx->submitted_frame <= ctx->encoded_frame + output_delay) // too soon to poll
680 return ret;
681 }
682 }
683 }
684 if(ret != AVERROR(EAGAIN)){
685 if (!frame->buf[0]) { // submit drain
686 if (!ctx->eof) { // submit drain one time only
687 if(!ctx->delayed_drain) {
688 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
689 if (res == AMF_INPUT_FULL) {
690 ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in receive loop
691 } else {
692 if (res == AMF_OK) {
693 ctx->eof = 1; // drain started
694 }
695 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Drain() failed with error %d\n", res);
696 }
697 }
698 }
699 } else { // submit frame
700 ret = amf_submit_frame_locked(avctx, frame, &surface);
701 if(ret < 0){
703 return ret;
704 }
705 pts = frame->pts;
706 }
707 }
709
710 do {
711 block_and_wait = 0;
712 // poll data
713 res_query = amf_query_output(avctx, &buffer);
714 if (buffer) {
715 ret = amf_copy_buffer(avctx, avpkt, buffer);
716 buffer->pVtbl->Release(buffer);
717
718 AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret, "amf_copy_buffer() failed with error %d\n", ret);
719
720 if (ctx->delayed_drain) { // try to resubmit drain
721 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
722 if (res != AMF_INPUT_FULL) {
723 ctx->delayed_drain = 0;
724 ctx->eof = 1; // drain started
725 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Repeated Drain() failed with error %d\n", res);
726 } else {
727 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed drain submission got AMF_INPUT_FULL- should not happen\n");
728 }
729 }
730 } else if (ctx->delayed_drain || (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >= ctx->hwsurfaces_in_queue_max) || surface) {
731 block_and_wait = 1;
732 // Only sleep if the driver doesn't support waiting in QueryOutput()
733 // or if we already have output data so we will skip calling it.
734 if (!ctx->query_timeout_supported || avpkt->data || avpkt->buf) {
735 av_usleep(1000);
736 }
737 }
738 } while (block_and_wait);
739
740 if (res_query == AMF_EOF) {
742 } else if (buffer == NULL) {
743 ret = AVERROR(EAGAIN);
744 } else {
745 if(surface) {
746 // resubmit surface
747 do {
748 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)surface);
749 if (res != AMF_INPUT_FULL)
750 break;
751
752 if (!ctx->query_timeout_supported)
753 av_usleep(1000);
754
755 // Need to free up space in the encoder queue.
756 // The number of retrieved outputs is limited currently to 21
757 amf_query_output(avctx, &buffer);
758 if (buffer != NULL) {
759 ret = av_fifo_write(ctx->output_list, &buffer, 1);
760 if (ret < 0)
761 return ret;
762 }
763 } while(res == AMF_INPUT_FULL);
764
765 surface->pVtbl->Release(surface);
766 if (res == AMF_INPUT_FULL) {
767 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed SubmitInput returned AMF_INPUT_FULL- should not happen\n");
768 } else {
769 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SubmitInput() failed with error %d\n", res);
770
771 ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
772
773 ctx->submitted_frame++;
774
775 if (ret < 0)
776 return ret;
777 }
778 }
779 ret = 0;
780 }
781 return ret;
782}
783
785#if CONFIG_D3D11VA
786 HW_CONFIG_ENCODER_FRAMES(D3D11, D3D11VA),
788#endif
789#if CONFIG_DXVA2
790 HW_CONFIG_ENCODER_FRAMES(DXVA2_VLD, DXVA2),
792#endif
793 HW_CONFIG_ENCODER_FRAMES(AMF_SURFACE, AMF),
795 NULL,
796};
static double val(void *priv, double ch)
Definition aeval.c:77
static int amf_submit_frame_locked(AVCodecContext *avctx, AVFrame *frame, AMFSurface **surface_resubmit)
Definition amfenc.c:617
int ff_amf_encode_init(AVCodecContext *avctx)
Common encoder initization function.
Definition amfenc.c:355
static AMF_RESULT amf_query_output(AVCodecContext *avctx, AMFBuffer **buffer)
Definition amfenc.c:632
void ff_amf_clamp_lookahead_depth(AVCodecContext *avctx, AMFEncoderContext *ctx)
Clamp pa_lookahead_buffer_depth to the AMF-reported maximum and assign it to the encoder.
Definition amfenc.c:193
const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[]
Definition amfenc.c:784
static AMF_RESULT amf_release_attached_frame_ref(AMFEncoderContext *ctx, AMFBuffer *buffer)
Definition amfenc.c:444
static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const wchar_t *name, AMFBuffer *val)
Definition amfenc.c:410
static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer *buffer)
Definition amfenc.c:266
int av_cold ff_amf_encode_close(AVCodecContext *avctx)
Common encoder termination function.
Definition amfenc.c:142
static int amf_submit_frame(AVCodecContext *avctx, AVFrame *frame, AMFSurface **surface_resubmit)
Definition amfenc.c:456
void ff_amf_fit_async_depth(AVCodecContext *avctx, AMFEncoderContext *ctx)
Size async_depth (hwsurfaces_in_queue_max) around the lookahead window: widen it to hold the lookahea...
Definition amfenc.c:213
#define AMF_AV_FRAME_REF
Definition amfenc.c:41
static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame, AMFSurface *surface)
Definition amfenc.c:242
static int amf_init_encoder(AVCodecContext *avctx)
Definition amfenc.c:80
static int64_t next_encoder_index
Definition amfenc.c:78
int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Ecoding one frame - common function for all AMF encoders.
Definition amfenc.c:649
enum AVPixelFormat ff_amf_pix_fmts[]
Supported formats.
Definition amfenc.c:57
#define PTS_PROP
Definition amfenc.c:42
static AMF_RESULT amf_store_attached_frame_ref(AMFEncoderContext *ctx, const AVFrame *frame, AMFSurface *surface)
Definition amfenc.c:432
int ff_amf_get_lookahead_depth_max(AVCodecContext *avctx, AMFComponent *encoder, amf_uint64 runtime_version, amf_int64 *out_max)
Query the maximum PA lookahead buffer depth (AMF_PA_LOOKAHEAD_BUFFER_DEPTH).
Definition amfenc.c:171
#define MAX_LOOKAHEAD_DEPTH
Definition amfenc.h:37
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
Definition amfenc.h:195
static AVFormatContext * ctx
#define L(x)
Definition vpx_arith.h:36
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:107
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition encode.c:220
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
Definition encode.c:1092
int ret
Definition ffplay.c:391
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
Definition avcodec.h:314
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition avutil.h:226
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition error.h:56
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition fifo.c:47
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition fifo.c:286
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition fifo.h:63
size_t av_fifo_can_read(const AVFifo *f)
Definition fifo.c:87
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
Definition fifo.c:255
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition fifo.c:188
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition fifo.c:240
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:486
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:408
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition imgutils.h:184
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
int index
Definition gxfenc.c:90
static AVBufferRef * hw_device_ctx
Definition hw_decode.c:45
#define HW_CONFIG_ENCODER_DEVICE(format, device_type_)
Definition hwconfig.h:97
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition hwconfig.h:100
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.
Definition hwcontext.c:673
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.
Definition hwcontext.c:776
@ AV_HWDEVICE_TYPE_AMF
Definition hwcontext.h:41
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
int av_amf_extract_hdr_metadata(const AVFrame *frame, AMFHDRMetadata *hdrmeta)
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
misc image utilities
#define av_cold
Definition attributes.h:117
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
const char data[16]
Definition mxf.c:155
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3404
#define AV_PIX_FMT_RGBAF16
Definition pixfmt.h:635
#define AV_PIX_FMT_P010
Definition pixfmt.h:613
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition pixfmt.h:134
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition pixfmt.h:336
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Definition pixfmt.h:477
#define AV_PIX_FMT_X2BGR10
Definition pixfmt.h:625
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition pixfmt.h:694
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
AMF encoder context.
Definition amfenc.h:43
This struct is allocated as AVHWDeviceContext.hwctx.
void(* lock)(void *lock_ctx)
AMFContext * context
void(* unlock)(void *lock_ctx)
AMFFactory * factory
int64_t version
version of AMF runtime
uint8_t * data
The data buffer.
Definition buffer.h:90
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition avcodec.h:1477
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition avcodec.h:785
const struct AVCodec * codec
Definition avcodec.h:452
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition avcodec.h:1499
void * priv_data
Definition avcodec.h:470
enum AVCodecID id
Definition codec.h:189
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition hwcontext.h:88
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition hwcontext.h:129
This structure stores compressed data.
Definition packet.h:587
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:593
uint8_t * data
Definition packet.h:610
static int frame_ref(AVFrame *dst, const AVFrame *src, const int plane_copy[4])
Definition swscale.c:1263
#define av_freep(p)
#define av_log(a,...)
static char buffer[20]
Definition seek.c:33
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
static int64_t pts
int size
enum AVCodecID codec_id
#define NONE
Definition vf_drawvg.c:262