| 267 | } |
| 268 | |
| 269 | static int amf_decode_init(AVCodecContext *avctx) |
| 270 | { |
| 271 | AMFDecoderContext *ctx = avctx->priv_data; |
| 272 | int ret; |
| 273 | ctx->in_pkt = av_packet_alloc(); |
| 274 | if (!ctx->in_pkt) |
| 275 | return AVERROR(ENOMEM); |
| 276 | |
| 277 | if (avctx->hw_device_ctx) { |
| 278 | AVHWDeviceContext *hwdev_ctx; |
| 279 | hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data; |
| 280 | if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF) |
| 281 | { |
| 282 | ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx); |
| 283 | if (!avctx->hw_frames_ctx) { |
| 284 | avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx); |
| 285 | AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n"); |
| 286 | } |
| 287 | } else { |
| 288 | ret = av_hwdevice_ctx_create_derived(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, avctx->hw_device_ctx, 0); |
| 289 | AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret)); |
| 290 | } |
| 291 | } else { |
| 292 | ret = av_hwdevice_ctx_create(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, NULL, NULL, 0); |
| 293 | AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret)); |
| 294 | } |
| 295 | if ((ret = amf_init_decoder(avctx)) == 0) { |
| 296 | AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data; |
| 297 | AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx; |
| 298 | enum AVPixelFormat surf_pix_fmt = AV_PIX_FMT_NONE; |
| 299 | |
| 300 | if(amf_legacy_driver_no_bitness_detect(amf_device_ctx)){ |
| 301 | // if bitness detection is not supported in legacy driver use format from container |
| 302 | switch (avctx->pix_fmt) { |
| 303 | case AV_PIX_FMT_YUV420P: |
| 304 | case AV_PIX_FMT_YUVJ420P: |
| 305 | surf_pix_fmt = AV_PIX_FMT_NV12; break; |
| 306 | case AV_PIX_FMT_YUV420P10: |
| 307 | surf_pix_fmt = AV_PIX_FMT_P010; break; |
| 308 | } |
| 309 | }else{ |
| 310 | AMFVariantStruct format_var = {0}; |
| 311 | |
| 312 | ret = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var); |
| 313 | AMF_GOTO_FAIL_IF_FALSE(avctx, ret == AMF_OK, AVERROR(EINVAL), "Failed to get output format (AMF) : %d\n", ret); |
| 314 | |
| 315 | surf_pix_fmt = av_amf_to_av_format(format_var.int64Value); |
| 316 | } |
| 317 | if(avctx->hw_frames_ctx) |
| 318 | { |
| 319 | // this values should be set for avcodec_open2 |
| 320 | // will be updated after header decoded if not true. |
| 321 | if(surf_pix_fmt == AV_PIX_FMT_NONE) |
| 322 | surf_pix_fmt = AV_PIX_FMT_NV12; // for older drivers |
| 323 | if (!avctx->coded_width) |
| 324 | avctx->coded_width = 1280; |
| 325 | if (!avctx->coded_height) |
| 326 | avctx->coded_height = 720; |
nothing calls this directly
no test coverage detected