Lines Matching defs:ctx

112     AmfContext        *ctx = avctx->priv_data;
117 ctx->delayed_frame = av_frame_alloc();
118 if (!ctx->delayed_frame) {
122 ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, sizeof(int64_t),
124 if (!ctx->timestamp_list) {
127 ctx->dts_delay = 0;
130 ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
131 AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
134 init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
135 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);
137 version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, AMF_QUERY_VERSION_FUNCTION_NAME);
138 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);
140 res = version_fun(&ctx->version);
141 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
142 res = init_fun(AMF_FULL_VERSION, &ctx->factory);
143 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_INIT_FUNCTION_NAME, res);
144 res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
145 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() failed with error %d\n", res);
146 res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
147 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() failed with error %d\n", res);
154 AmfContext *ctx = avctx->priv_data;
157 res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, AMF_DX11_1);
173 AmfContext *ctx = avctx->priv_data;
200 res = ctx->context->pVtbl->InitDX9(ctx->context, device);
218 AmfContext *ctx = avctx->priv_data;
223 ctx->hwsurfaces_in_queue = 0;
224 ctx->hwsurfaces_in_queue_max = 16;
228 ctx->trace->pVtbl->EnableWriter(ctx->trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, ctx->log_to_dbg != 0 );
229 if (ctx->log_to_dbg)
230 ctx->trace->pVtbl->SetWriterLevel(ctx->trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, AMF_TRACE_TRACE);
231 ctx->trace->pVtbl->EnableWriter(ctx->trace, AMF_TRACE_WRITER_CONSOLE, 0);
232 ctx->trace->pVtbl->SetGlobalLevel(ctx->trace, AMF_TRACE_TRACE);
235 ctx->tracer.vtbl = &tracer_vtbl;
236 ctx->tracer.avctx = avctx;
237 ctx->trace->pVtbl->RegisterWriter(ctx->trace, FFMPEG_AMF_WRITER_ID,(AMFTraceWriter*)&ctx->tracer, 1);
238 ctx->trace->pVtbl->SetWriterLevel(ctx->trace, FFMPEG_AMF_WRITER_ID, AMF_TRACE_TRACE);
240 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
241 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() failed with error %d\n", res);
274 ctx->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
275 if (!ctx->hw_frames_ctx)
279 ctx->hwsurfaces_in_queue_max = frames_ctx->initial_pool_size - 1;
305 ctx->hw_device_ctx = av_buffer_ref(avctx->hw_device_ctx);
306 if (!ctx->hw_device_ctx)
310 res = ctx->context->pVtbl->InitDX11(ctx->context, NULL, AMF_DX11_1);
314 res = ctx->context->pVtbl->InitDX9(ctx->context, NULL);
319 res = ctx->context->pVtbl->QueryInterface(ctx->context, &guid, (void**)&context1);
320 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res);
340 AmfContext *ctx = avctx->priv_data;
355 AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id);
357 if (ctx->hw_frames_ctx)
358 pix_fmt = ((AVHWFramesContext*)ctx->hw_frames_ctx->data)->sw_format;
362 ctx->format = amf_av_to_amf_format(pix_fmt);
363 AMF_RETURN_IF_FALSE(ctx, ctx->format != AMF_SURFACE_UNKNOWN, AVERROR(EINVAL),
366 res = ctx->factory->pVtbl->CreateComponent(ctx->factory, ctx->context, codec_id, &ctx->encoder);
367 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res);
374 AmfContext *ctx = avctx->priv_data;
376 if (ctx->delayed_surface) {
377 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
378 ctx->delayed_surface = NULL;
381 if (ctx->encoder) {
382 ctx->encoder->pVtbl->Terminate(ctx->encoder);
383 ctx->encoder->pVtbl->Release(ctx->encoder);
384 ctx->encoder = NULL;
387 if (ctx->context) {
388 ctx->context->pVtbl->Terminate(ctx->context);
389 ctx->context->pVtbl->Release(ctx->context);
390 ctx->context = NULL;
392 av_buffer_unref(&ctx->hw_device_ctx);
393 av_buffer_unref(&ctx->hw_frames_ctx);
395 if (ctx->trace) {
396 ctx->trace->pVtbl->UnregisterWriter(ctx->trace, FFMPEG_AMF_WRITER_ID);
398 if (ctx->library) {
399 dlclose(ctx->library);
400 ctx->library = NULL;
402 ctx->trace = NULL;
403 ctx->debug = NULL;
404 ctx->factory = NULL;
405 ctx->version = 0;
406 ctx->delayed_drain = 0;
407 av_frame_free(&ctx->delayed_frame);
408 av_fifo_freep2(&ctx->timestamp_list);
439 AmfContext *ctx = avctx->priv_data;
472 AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, &timestamp, 1) >= 0,
476 if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
478 size_t can_read = av_fifo_can_read(ctx->timestamp_list);
480 AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN,
482 av_fifo_peek(ctx->timestamp_list, &timestamp_last, 1, can_read - 1);
486 ctx->dts_delay = timestamp_last - timestamp;
488 pkt->dts = timestamp - ctx->dts_delay;
580 AmfContext *ctx = avctx->priv_data;
586 AVFrame *frame = ctx->delayed_frame;
589 if (!ctx->encoder)
599 if (!ctx->eof) { // submit drain one time only
600 if (ctx->delayed_surface != NULL) {
601 ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in ff_amf_receive_packet
602 } else if(!ctx->delayed_drain) {
603 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
605 ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in ff_amf_receive_packet
608 ctx->eof = 1; // drain started
610 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Drain() failed with error %d\n", res);
614 } else if (!ctx->delayed_surface) { // submit frame
626 av_assert0(frame->hw_frames_ctx && ctx->hw_frames_ctx &&
627 frame->hw_frames_ctx->data == ctx->hw_frames_ctx->data);
631 res = ctx->context->pVtbl->CreateSurfaceFromDX11Native(ctx->context, texture, &surface, NULL); // wrap to AMF surface
632 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "CreateSurfaceFromDX11Native() failed with error %d\n", res);
643 res = ctx->context->pVtbl->CreateSurfaceFromDX9Native(ctx->context, texture, &surface, NULL); // wrap to AMF surface
644 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "CreateSurfaceFromDX9Native() failed with error %d\n", res);
652 res = ctx->context->pVtbl->AllocSurface(ctx->context, AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
653 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "AllocSurface() failed with error %d\n", res);
665 frame_ref_storage_buffer = amf_create_buffer_with_frame_ref(frame, ctx->context);
666 AMF_RETURN_IF_FALSE(ctx, frame_ref_storage_buffer != NULL, AVERROR(ENOMEM), "create_buffer_with_frame_ref() returned NULL\n");
669 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SetProperty failed for \"av_frame_ref\" with error %d\n", res);
670 ctx->hwsurfaces_in_queue++;
679 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_AUD, !!ctx->aud);
682 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_AUD, !!ctx->aud);
689 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)surface);
692 ctx->delayed_surface = surface;
696 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SubmitInput() failed with error %d\n", res);
699 ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
709 res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, &data);
722 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetProperty failed for \"av_frame_ref\" with error %d\n", res);
724 ctx->hwsurfaces_in_queue--;
729 AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret, "amf_copy_buffer() failed with error %d\n", ret);
731 if (ctx->delayed_surface != NULL) { // try to resubmit frame
732 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)ctx->delayed_surface);
734 int64_t pts = ctx->delayed_surface->pVtbl->GetPts(ctx->delayed_surface);
735 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
736 ctx->delayed_surface = NULL;
737 av_frame_unref(ctx->delayed_frame);
738 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Repeated SubmitInput() failed with error %d\n", res);
740 ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
746 } else if (ctx->delayed_drain) { // try to resubmit drain
747 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
749 ctx->delayed_drain = 0;
750 ctx->eof = 1; // drain started
751 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Repeated Drain() failed with error %d\n", res);
756 } else if (ctx->delayed_surface != NULL || ctx->delayed_drain || (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >= ctx->hwsurfaces_in_queue_max)) {