| 73 | } |
| 74 | |
| 75 | static int amf_init_decoder(AVCodecContext *avctx) |
| 76 | { |
| 77 | AMFDecoderContext *ctx = avctx->priv_data; |
| 78 | AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data; |
| 79 | AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx; |
| 80 | const wchar_t *codec_id = NULL; |
| 81 | AMF_RESULT res; |
| 82 | AMFBuffer *buffer; |
| 83 | amf_int64 color_profile; |
| 84 | int pool_size = 36; |
| 85 | // way-around for older drivers that don't support dynamic bitness detection - |
| 86 | // define HEVC and VP9 10-bit based on container info |
| 87 | int no_bitness_detect = amf_legacy_driver_no_bitness_detect(amf_device_ctx); |
| 88 | |
| 89 | ctx->drain = 0; |
| 90 | ctx->resolution_changed = 0; |
| 91 | |
| 92 | switch (avctx->codec->id) { |
| 93 | case AV_CODEC_ID_H264: |
| 94 | codec_id = AMFVideoDecoderUVD_H264_AVC; |
| 95 | break; |
| 96 | case AV_CODEC_ID_HEVC: { |
| 97 | codec_id = AMFVideoDecoderHW_H265_HEVC; |
| 98 | if(no_bitness_detect){ |
| 99 | if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10) |
| 100 | codec_id = AMFVideoDecoderHW_H265_MAIN10; |
| 101 | } |
| 102 | } break; |
| 103 | case AV_CODEC_ID_VP9: { |
| 104 | codec_id = AMFVideoDecoderHW_VP9; |
| 105 | if(no_bitness_detect){ |
| 106 | if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10) |
| 107 | codec_id = AMFVideoDecoderHW_VP9_10BIT; |
| 108 | } |
| 109 | } break; |
| 110 | case AV_CODEC_ID_AV1: |
| 111 | codec_id = AMFVideoDecoderHW_AV1; |
| 112 | break; |
| 113 | default: |
| 114 | break; |
| 115 | } |
| 116 | AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id); |
| 117 | |
| 118 | res = amf_device_ctx->factory->pVtbl->CreateComponent(amf_device_ctx->factory, amf_device_ctx->context, codec_id, &ctx->decoder); |
| 119 | AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res); |
| 120 | |
| 121 | // Color Metadata |
| 122 | /// Color Range (Support for older Drivers) |
| 123 | if (avctx->color_range == AVCOL_RANGE_JPEG) { |
| 124 | AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 1); |
| 125 | } else if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) { |
| 126 | AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 0); |
| 127 | } |
| 128 | color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN; |
| 129 | switch (avctx->colorspace) { |
| 130 | case AVCOL_SPC_SMPTE170M: |
| 131 | if (avctx->color_range == AVCOL_RANGE_JPEG) { |
| 132 | color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601; |
no test coverage detected