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

Function d3d12va_encode_setup_roi

libavcodec/d3d12va_encode.c:166–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166static int d3d12va_encode_setup_roi(AVCodecContext *avctx,
167 D3D12VAEncodePicture *pic,
168 const uint8_t *data, size_t size)
169{
170 D3D12VAEncodeContext *ctx = avctx->priv_data;
171 const AVRegionOfInterest *roi;
172 uint32_t roi_size;
173 int nb_roi, i;
174 int block_width, block_height;
175 int block_size, qp_range;
176 int is_av1 = 0;
177
178 // Use the QP map region size reported by the driver
179 block_size = ctx->qp_map_region_size;
180
181 // Determine QP range and element size based on codec
182 switch (ctx->codec->d3d12_codec) {
183 case D3D12_VIDEO_ENCODER_CODEC_H264:
184 case D3D12_VIDEO_ENCODER_CODEC_HEVC:
185 qp_range = 51;
186 is_av1 = 0;
187 break;
188#if CONFIG_AV1_D3D12VA_ENCODER
189 case D3D12_VIDEO_ENCODER_CODEC_AV1:
190 qp_range = 255;
191 is_av1 = 1;
192 break;
193#endif
194 default:
195 av_log(avctx, AV_LOG_ERROR, "Unsupported codec for ROI.\n");
196 return AVERROR(EINVAL);
197 }
198
199 // Calculate map dimensions using ceil division as required by D3D12
200 block_width = (avctx->width + block_size - 1) / block_size;
201 block_height = (avctx->height + block_size - 1) / block_size;
202
203 // Allocate QP map with correct type based on codec
204 if (is_av1) {
205 pic->qp_map = av_calloc(block_width * block_height, sizeof(int16_t));
206 } else {
207 pic->qp_map = av_calloc(block_width * block_height, sizeof(int8_t));
208 }
209 if (!pic->qp_map)
210 return AVERROR(ENOMEM);
211
212 // Process ROI regions
213 roi = (const AVRegionOfInterest *)data;
214 roi_size = roi->self_size;
215 av_assert0(roi_size && size % roi_size == 0);
216 nb_roi = size / roi_size;
217
218 // Iterate in reverse for priority (first region in array takes priority on overlap)
219 for (i = nb_roi - 1; i >= 0; i--) {
220 int startx, endx, starty, endy;
221 int delta_qp;
222 int x, y;
223

Callers 1

d3d12va_encode_issueFunction · 0.85

Calls 3

av_logFunction · 0.85
av_callocFunction · 0.85
av_freepFunction · 0.85

Tested by

no test coverage detected