| 1048 | } |
| 1049 | |
| 1050 | int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, |
| 1051 | enum AVHWDeviceType dev_type) |
| 1052 | { |
| 1053 | AVHWDeviceContext *device_ctx; |
| 1054 | AVHWFramesContext *frames_ctx; |
| 1055 | int ret; |
| 1056 | |
| 1057 | if (!avctx->hwaccel) |
| 1058 | return AVERROR(ENOSYS); |
| 1059 | |
| 1060 | if (avctx->hw_frames_ctx) |
| 1061 | return 0; |
| 1062 | if (!avctx->hw_device_ctx) { |
| 1063 | av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is " |
| 1064 | "required for hardware accelerated decoding.\n"); |
| 1065 | return AVERROR(EINVAL); |
| 1066 | } |
| 1067 | |
| 1068 | device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data; |
| 1069 | if (device_ctx->type != dev_type) { |
| 1070 | av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware " |
| 1071 | "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type), |
| 1072 | av_hwdevice_get_type_name(device_ctx->type)); |
| 1073 | return AVERROR(EINVAL); |
| 1074 | } |
| 1075 | |
| 1076 | ret = avcodec_get_hw_frames_parameters(avctx, |
| 1077 | avctx->hw_device_ctx, |
| 1078 | avctx->hwaccel->pix_fmt, |
| 1079 | &avctx->hw_frames_ctx); |
| 1080 | if (ret < 0) |
| 1081 | return ret; |
| 1082 | |
| 1083 | frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; |
| 1084 | |
| 1085 | |
| 1086 | if (frames_ctx->initial_pool_size) { |
| 1087 | // We guarantee 4 base work surfaces. The function above guarantees 1 |
| 1088 | // (the absolute minimum), so add the missing count. |
| 1089 | frames_ctx->initial_pool_size += 3; |
| 1090 | } |
| 1091 | |
| 1092 | ret = av_hwframe_ctx_init(avctx->hw_frames_ctx); |
| 1093 | if (ret < 0) { |
| 1094 | av_buffer_unref(&avctx->hw_frames_ctx); |
| 1095 | return ret; |
| 1096 | } |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | int avcodec_get_hw_frames_parameters(AVCodecContext *avctx, |
| 1102 | AVBufferRef *device_ref, |
no test coverage detected