2 * This file is part of FFmpeg.
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.
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.
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
21 #include "libavutil/avassert.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/hwcontext.h"
25 #include "libavutil/hwcontext_d3d11va.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/time.h"
39 #include "compat/w32dlfcn.h"
44 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
46 #define PTS_PROP L"PtsProp"
48 const enum AVPixelFormat ff_amf_pix_fmts[] = {
57 typedef struct FormatMap {
58 enum AVPixelFormat av_format;
59 enum AMF_SURFACE_FORMAT amf_format;
62 static const FormatMap format_map[] =
64 { AV_PIX_FMT_NONE, AMF_SURFACE_UNKNOWN },
65 { AV_PIX_FMT_NV12, AMF_SURFACE_NV12 },
66 { AV_PIX_FMT_BGR0, AMF_SURFACE_BGRA },
67 { AV_PIX_FMT_RGB0, AMF_SURFACE_RGBA },
68 { AV_PIX_FMT_GRAY8, AMF_SURFACE_GRAY8 },
69 { AV_PIX_FMT_YUV420P, AMF_SURFACE_YUV420P },
70 { AV_PIX_FMT_YUYV422, AMF_SURFACE_YUY2 },
71 { AV_PIX_FMT_D3D11, AMF_SURFACE_NV12 },
75 static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
77 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
78 return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
82 static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
85 for (i = 0; i < amf_countof(format_map); i++) {
86 if (format_map[i].av_format == fmt) {
87 return format_map[i].amf_format;
90 return AMF_SURFACE_UNKNOWN;
93 static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
94 const wchar_t *scope, const wchar_t *message)
96 AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
97 av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is provided from AMF
100 static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
104 static AMFTraceWriterVtbl tracer_vtbl =
106 .Write = AMFTraceWriter_Write,
107 .Flush = AMFTraceWriter_Flush,
110 static int amf_load_library(AVCodecContext *avctx)
112 AmfContext *ctx = avctx->priv_data;
113 AMFInit_Fn init_fun = NULL;
114 AMFQueryVersion_Fn version_fun = NULL;
115 AMF_RESULT res = AMF_OK;
118 ctx->delayed_drain = 0;
119 ctx->hw_frames_ctx = NULL;
120 ctx->hw_device_ctx = NULL;
121 ctx->delayed_surface = NULL;
122 ctx->delayed_frame = av_frame_alloc();
123 if (!ctx->delayed_frame) {
124 return AVERROR(ENOMEM);
126 // hardcoded to current HW queue size - will realloc in timestamp_queue_enqueue() if too small
127 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * sizeof(int64_t));
128 if (!ctx->timestamp_list) {
129 return AVERROR(ENOMEM);
134 ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
135 AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
136 AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
138 init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
139 AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
141 version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, AMF_QUERY_VERSION_FUNCTION_NAME);
142 AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
144 res = version_fun(&ctx->version);
145 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
146 res = init_fun(AMF_FULL_VERSION, &ctx->factory);
147 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_INIT_FUNCTION_NAME, res);
148 res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
149 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() failed with error %d\n", res);
150 res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
151 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() failed with error %d\n", res);
155 static int amf_init_context(AVCodecContext *avctx)
157 AmfContext *ctx = avctx->priv_data;
158 AMF_RESULT res = AMF_OK;
160 // configure AMF logger
161 // the return of these functions indicates old state and do not affect behaviour
162 ctx->trace->pVtbl->EnableWriter(ctx->trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, ctx->log_to_dbg != 0 );
164 ctx->trace->pVtbl->SetWriterLevel(ctx->trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, AMF_TRACE_TRACE);
165 ctx->trace->pVtbl->EnableWriter(ctx->trace, AMF_TRACE_WRITER_CONSOLE, 0);
166 ctx->trace->pVtbl->SetGlobalLevel(ctx->trace, AMF_TRACE_TRACE);
168 // connect AMF logger to av_log
169 ctx->tracer.vtbl = &tracer_vtbl;
170 ctx->tracer.avctx = avctx;
171 ctx->trace->pVtbl->RegisterWriter(ctx->trace, FFMPEG_AMF_WRITER_ID,(AMFTraceWriter*)&ctx->tracer, 1);
172 ctx->trace->pVtbl->SetWriterLevel(ctx->trace, FFMPEG_AMF_WRITER_ID, AMF_TRACE_TRACE);
174 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
175 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() failed with error %d\n", res);
176 // try to reuse existing DX device
178 if (avctx->hw_frames_ctx) {
179 AVHWFramesContext *device_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
180 if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
181 if (amf_av_to_amf_format(device_ctx->sw_format) != AMF_SURFACE_UNKNOWN) {
182 if (device_ctx->device_ctx->hwctx) {
183 AVD3D11VADeviceContext *device_d3d11 = (AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
184 res = ctx->context->pVtbl->InitDX11(ctx->context, device_d3d11->device, AMF_DX11_1);
186 ctx->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
187 if (!ctx->hw_frames_ctx) {
188 return AVERROR(ENOMEM);
191 if(res == AMF_NOT_SUPPORTED)
192 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has D3D11 device which doesn't have D3D11VA interface, switching to default\n");
194 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has non-AMD device, switching to default\n");
198 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format not uspported by AMF, switching to default\n");
201 } else if (avctx->hw_device_ctx) {
202 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
203 if (device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
204 if (device_ctx->hwctx) {
205 AVD3D11VADeviceContext *device_d3d11 = (AVD3D11VADeviceContext *)device_ctx->hwctx;
206 res = ctx->context->pVtbl->InitDX11(ctx->context, device_d3d11->device, AMF_DX11_1);
208 ctx->hw_device_ctx = av_buffer_ref(avctx->hw_device_ctx);
209 if (!ctx->hw_device_ctx) {
210 return AVERROR(ENOMEM);
213 if (res == AMF_NOT_SUPPORTED)
214 av_log(avctx, AV_LOG_INFO, "avctx->hw_device_ctx has D3D11 device which doesn't have D3D11VA interface, switching to default\n");
216 av_log(avctx, AV_LOG_INFO, "avctx->hw_device_ctx has non-AMD device, switching to default\n");
222 if (!ctx->hw_frames_ctx && !ctx->hw_device_ctx) {
223 res = ctx->context->pVtbl->InitDX11(ctx->context, NULL, AMF_DX11_1);
225 res = ctx->context->pVtbl->InitDX9(ctx->context, NULL);
226 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "InitDX9() failed with error %d\n", res);
232 static int amf_init_encoder(AVCodecContext *avctx)
234 AmfContext *ctx = avctx->priv_data;
235 const wchar_t *codec_id = NULL;
236 AMF_RESULT res = AMF_OK;
238 switch (avctx->codec->id) {
239 case AV_CODEC_ID_H264:
240 codec_id = AMFVideoEncoderVCE_AVC;
242 case AV_CODEC_ID_HEVC:
243 codec_id = AMFVideoEncoder_HEVC;
248 AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id);
250 ctx->format = amf_av_to_amf_format(avctx->pix_fmt);
251 AMF_RETURN_IF_FALSE(ctx, ctx->format != AMF_SURFACE_UNKNOWN, AVERROR(EINVAL), "Format %d is not supported\n", avctx->pix_fmt);
253 res = ctx->factory->pVtbl->CreateComponent(ctx->factory, ctx->context, codec_id, &ctx->encoder);
254 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res);
259 int av_cold ff_amf_encode_close(AVCodecContext *avctx)
261 AmfContext *ctx = avctx->priv_data;
262 if (ctx->delayed_surface)
264 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
265 ctx->delayed_surface = NULL;
269 ctx->encoder->pVtbl->Terminate(ctx->encoder);
270 ctx->encoder->pVtbl->Release(ctx->encoder);
275 ctx->context->pVtbl->Terminate(ctx->context);
276 ctx->context->pVtbl->Release(ctx->context);
279 av_buffer_unref(&ctx->hw_device_ctx);
280 av_buffer_unref(&ctx->hw_frames_ctx);
283 ctx->trace->pVtbl->UnregisterWriter(ctx->trace, FFMPEG_AMF_WRITER_ID);
286 dlclose(ctx->library);
293 ctx->delayed_drain = 0;
294 av_frame_free(&ctx->delayed_frame);
295 av_fifo_freep(&ctx->timestamp_list);
300 static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
303 AVFrame *sw_frame = NULL;
304 AMFPlane *plane = NULL;
305 uint8_t *dst_data[4];
311 if (frame->hw_frames_ctx && is_hwaccel_pix_fmt(frame->format)) {
312 if (!(sw_frame = av_frame_alloc())) {
313 av_log(avctx, AV_LOG_ERROR, "Can not alloc frame\n");
314 ret = AVERROR(ENOMEM);
317 if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) < 0) {
318 av_log(avctx, AV_LOG_ERROR, "Error transferring the data to system memory\n");
323 planes = (int)surface->pVtbl->GetPlanesCount(surface);
324 if (planes > amf_countof(dst_data)) {
325 av_log(avctx, AV_LOG_ERROR, "Invalid number of planes %d in surface\n", planes);
326 ret = AVERROR(EINVAL);
330 for (i = 0; i < planes; i++) {
331 plane = surface->pVtbl->GetPlaneAt(surface, i);
332 dst_data[i] = plane->pVtbl->GetNative(plane);
333 dst_linesize[i] = plane->pVtbl->GetHPitch(plane);
335 av_image_copy(dst_data, dst_linesize,
336 (const uint8_t**)frame->data, frame->linesize, frame->format,
337 avctx->width, avctx->height);
341 av_frame_free(&sw_frame);
346 static inline int timestamp_queue_enqueue(AVCodecContext *avctx, int64_t timestamp)
348 AmfContext *ctx = avctx->priv_data;
349 if (av_fifo_space(ctx->timestamp_list) < sizeof(timestamp)) {
350 if (av_fifo_grow(ctx->timestamp_list, sizeof(timestamp)) < 0) {
351 return AVERROR(ENOMEM);
354 av_fifo_generic_write(ctx->timestamp_list, ×tamp, sizeof(timestamp), NULL);
358 static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer *buffer)
360 AmfContext *ctx = avctx->priv_data;
362 AMFVariantStruct var = {0};
363 int64_t timestamp = AV_NOPTS_VALUE;
364 int64_t size = buffer->pVtbl->GetSize(buffer);
366 if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) {
369 memcpy(pkt->data, buffer->pVtbl->GetNative(buffer), size);
371 switch (avctx->codec->id) {
372 case AV_CODEC_ID_H264:
373 buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE, &var);
374 if(var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_IDR) {
375 pkt->flags = AV_PKT_FLAG_KEY;
378 case AV_CODEC_ID_HEVC:
379 buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE, &var);
380 if (var.int64Value == AMF_VIDEO_ENCODER_HEVC_OUTPUT_DATA_TYPE_IDR) {
381 pkt->flags = AV_PKT_FLAG_KEY;
388 buffer->pVtbl->GetProperty(buffer, PTS_PROP, &var);
390 pkt->pts = var.int64Value; // original pts
393 AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, AVERROR_UNKNOWN, "timestamp_list is empty\n");
395 av_fifo_generic_read(ctx->timestamp_list, ×tamp, sizeof(timestamp), NULL);
397 // calc dts shift if max_b_frames > 0
398 if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
399 int64_t timestamp_last = AV_NOPTS_VALUE;
400 AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, AVERROR_UNKNOWN,
401 "timestamp_list is empty while max_b_frames = %d\n", avctx->max_b_frames);
402 av_fifo_generic_peek_at(
405 (av_fifo_size(ctx->timestamp_list) / sizeof(timestamp) - 1) * sizeof(timestamp_last),
406 sizeof(timestamp_last),
408 if (timestamp < 0 || timestamp_last < AV_NOPTS_VALUE) {
409 return AVERROR(ERANGE);
411 ctx->dts_delay = timestamp_last - timestamp;
413 pkt->dts = timestamp - ctx->dts_delay;
417 // amfenc API implementation
418 int ff_amf_encode_init(AVCodecContext *avctx)
420 AmfContext *ctx = avctx->priv_data;
432 ctx->tracer.vtbl = NULL;
433 ctx->tracer.avctx = NULL;
435 if ((ret = amf_load_library(avctx)) == 0) {
436 if ((ret = amf_init_context(avctx)) == 0) {
437 if ((ret = amf_init_encoder(avctx)) == 0) {
442 ff_amf_encode_close(avctx);
447 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
449 AMF_RESULT res = AMF_OK;
450 AmfContext *ctx = avctx->priv_data;
451 AMFSurface *surface = NULL;
455 return AVERROR(EINVAL);
457 if (!frame) { // submit drain
458 if (!ctx->eof) { // submit drain one time only
459 if (ctx->delayed_surface != NULL) {
460 ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in ff_amf_receive_packet
461 } else if(!ctx->delayed_drain) {
462 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
463 if (res == AMF_INPUT_FULL) {
464 ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in ff_amf_receive_packet
467 ctx->eof = 1; // drain started
469 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Drain() failed with error %d\n", res);
475 } else { // submit frame
476 if (ctx->delayed_surface != NULL) {
477 return AVERROR(EAGAIN); // should not happen when called from ffmpeg, other clients may resubmit
479 // prepare surface from frame
480 if (frame->hw_frames_ctx && ( // HW frame detected
481 // check if the same hw_frames_ctx as used in initialization
482 (ctx->hw_frames_ctx && frame->hw_frames_ctx->data == ctx->hw_frames_ctx->data) ||
483 // check if the same hw_device_ctx as used in initialization
484 (ctx->hw_device_ctx && ((AVHWFramesContext*)frame->hw_frames_ctx->data)->device_ctx ==
485 (AVHWDeviceContext*)ctx->hw_device_ctx->data)
488 static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
489 ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // actual texture
490 int index = (int)(size_t)frame->data[1]; // index is a slice in texture array is - set to tell AMF which slice to use
491 texture->lpVtbl->SetPrivateData(texture, &AMFTextureArrayIndexGUID, sizeof(index), &index);
493 res = ctx->context->pVtbl->CreateSurfaceFromDX11Native(ctx->context, texture, &surface, NULL); // wrap to AMF surface
494 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "CreateSurfaceFromDX11Native() failed with error %d\n", res);
496 // input HW surfaces can be vertically aligned by 16; tell AMF the real size
497 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, frame->height);
500 res = ctx->context->pVtbl->AllocSurface(ctx->context, AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
501 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "AllocSurface() failed with error %d\n", res);
502 amf_copy_surface(avctx, frame, surface);
504 surface->pVtbl->SetPts(surface, frame->pts);
505 AMF_ASSIGN_PROPERTY_INT64(res, surface, PTS_PROP, frame->pts);
507 switch (avctx->codec->id) {
508 case AV_CODEC_ID_H264:
509 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_AUD, !!ctx->aud);
511 case AV_CODEC_ID_HEVC:
512 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_AUD, !!ctx->aud);
520 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)surface);
521 if (res == AMF_INPUT_FULL) { // handle full queue
522 //store surface for later submission
523 ctx->delayed_surface = surface;
524 if (surface->pVtbl->GetMemoryType(surface) == AMF_MEMORY_DX11) {
525 av_frame_ref(ctx->delayed_frame, frame);
528 surface->pVtbl->Release(surface);
529 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SubmitInput() failed with error %d\n", res);
531 if ((ret = timestamp_queue_enqueue(avctx, frame->pts)) < 0) {
539 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
543 AMF_RESULT res_query;
544 AmfContext *ctx = avctx->priv_data;
545 AMFData *data = NULL;
549 return AVERROR(EINVAL);
554 res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, &data);
556 // copy data to packet
558 AMFGuid guid = IID_AMFBuffer();
559 data->pVtbl->QueryInterface(data, &guid, (void**)&buffer); // query for buffer interface
560 ret = amf_copy_buffer(avctx, avpkt, buffer);
562 buffer->pVtbl->Release(buffer);
563 data->pVtbl->Release(data);
565 AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret, "amf_copy_buffer() failed with error %d\n", ret);
567 if (ctx->delayed_surface != NULL) { // try to resubmit frame
568 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)ctx->delayed_surface);
569 if (res != AMF_INPUT_FULL) {
570 int64_t pts = ctx->delayed_surface->pVtbl->GetPts(ctx->delayed_surface);
571 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
572 ctx->delayed_surface = NULL;
573 av_frame_unref(ctx->delayed_frame);
574 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Repeated SubmitInput() failed with error %d\n", res);
576 if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
580 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed frame submission got AMF_INPUT_FULL- should not happen\n");
582 } else if (ctx->delayed_drain) { // try to resubmit drain
583 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
584 if (res != AMF_INPUT_FULL) {
585 ctx->delayed_drain = 0;
586 ctx->eof = 1; // drain started
587 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Repeated Drain() failed with error %d\n", res);
589 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed drain submission got AMF_INPUT_FULL- should not happen\n");
592 } else if (ctx->delayed_surface != NULL || ctx->delayed_drain || (ctx->eof && res_query != AMF_EOF)) {
594 av_usleep(1000); // wait and poll again
596 } while (block_and_wait);
598 if (res_query == AMF_EOF) {
600 } else if (data == NULL) {
601 ret = AVERROR(EAGAIN);