MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / avcodec_get_hw_frames_parameters

Function avcodec_get_hw_frames_parameters

libavcodec/decode.c:1101–1161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1099}
1100
1101int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
1102 AVBufferRef *device_ref,
1103 enum AVPixelFormat hw_pix_fmt,
1104 AVBufferRef **out_frames_ref)
1105{
1106 AVBufferRef *frames_ref = NULL;
1107 const AVCodecHWConfigInternal *hw_config;
1108 const FFHWAccel *hwa;
1109 int i, ret;
1110 bool clean_priv_data = false;
1111
1112 for (i = 0;; i++) {
1113 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1114 if (!hw_config)
1115 return AVERROR(ENOENT);
1116 if (hw_config->public.pix_fmt == hw_pix_fmt)
1117 break;
1118 }
1119
1120 hwa = hw_config->hwaccel;
1121 if (!hwa || !hwa->frame_params)
1122 return AVERROR(ENOENT);
1123
1124 frames_ref = av_hwframe_ctx_alloc(device_ref);
1125 if (!frames_ref)
1126 return AVERROR(ENOMEM);
1127
1128 if (!avctx->internal->hwaccel_priv_data) {
1129 avctx->internal->hwaccel_priv_data =
1130 av_mallocz(hwa->priv_data_size);
1131 if (!avctx->internal->hwaccel_priv_data) {
1132 av_buffer_unref(&frames_ref);
1133 return AVERROR(ENOMEM);
1134 }
1135 clean_priv_data = true;
1136 }
1137
1138 ret = hwa->frame_params(avctx, frames_ref);
1139 if (ret >= 0) {
1140 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1141
1142 if (frames_ctx->initial_pool_size) {
1143 // If the user has requested that extra output surfaces be
1144 // available then add them here.
1145 if (avctx->extra_hw_frames > 0)
1146 frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1147
1148 // If frame threading is enabled then an extra surface per thread
1149 // is also required.
1150 if (avctx->active_thread_type & FF_THREAD_FRAME)
1151 frames_ctx->initial_pool_size += avctx->thread_count;
1152 }
1153
1154 *out_frames_ref = frames_ref;
1155 } else {
1156 if (clean_priv_data)
1157 av_freep(&avctx->internal->hwaccel_priv_data);
1158 av_buffer_unref(&frames_ref);

Callers 2

nvdec_init_hwframesFunction · 0.85

Calls 5

ffcodecFunction · 0.85
av_hwframe_ctx_allocFunction · 0.85
av_buffer_unrefFunction · 0.85
av_freepFunction · 0.85
av_malloczFunction · 0.50

Tested by

no test coverage detected