| 184 | } |
| 185 | |
| 186 | static int vaapi_encode_make_row_slice(AVCodecContext *avctx, |
| 187 | VAAPIEncodePicture *pic) |
| 188 | { |
| 189 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 190 | VAAPIEncodeSlice *slice; |
| 191 | int i, rounding; |
| 192 | |
| 193 | for (i = 0; i < pic->nb_slices; i++) |
| 194 | pic->slices[i].row_size = ctx->slice_size; |
| 195 | |
| 196 | rounding = ctx->slice_block_rows - ctx->nb_slices * ctx->slice_size; |
| 197 | if (rounding > 0) { |
| 198 | // Place rounding error at top and bottom of frame. |
| 199 | av_assert0(rounding < pic->nb_slices); |
| 200 | // Some Intel drivers contain a bug where the encoder will fail |
| 201 | // if the last slice is smaller than the one before it. Since |
| 202 | // that's straightforward to avoid here, just do so. |
| 203 | if (rounding <= 2) { |
| 204 | for (i = 0; i < rounding; i++) |
| 205 | ++pic->slices[i].row_size; |
| 206 | } else { |
| 207 | for (i = 0; i < (rounding + 1) / 2; i++) |
| 208 | ++pic->slices[pic->nb_slices - i - 1].row_size; |
| 209 | for (i = 0; i < rounding / 2; i++) |
| 210 | ++pic->slices[i].row_size; |
| 211 | } |
| 212 | } else if (rounding < 0) { |
| 213 | // Remove rounding error from last slice only. |
| 214 | av_assert0(rounding < ctx->slice_size); |
| 215 | pic->slices[pic->nb_slices - 1].row_size += rounding; |
| 216 | } |
| 217 | |
| 218 | for (i = 0; i < pic->nb_slices; i++) { |
| 219 | slice = &pic->slices[i]; |
| 220 | slice->index = i; |
| 221 | if (i == 0) { |
| 222 | slice->row_start = 0; |
| 223 | slice->block_start = 0; |
| 224 | } else { |
| 225 | const VAAPIEncodeSlice *prev = &pic->slices[i - 1]; |
| 226 | slice->row_start = prev->row_start + prev->row_size; |
| 227 | slice->block_start = prev->block_start + prev->block_size; |
| 228 | } |
| 229 | slice->block_size = slice->row_size * ctx->slice_block_cols; |
| 230 | |
| 231 | av_log(avctx, AV_LOG_DEBUG, "Slice %d: %d-%d (%d rows), " |
| 232 | "%d-%d (%d blocks).\n", i, slice->row_start, |
| 233 | slice->row_start + slice->row_size - 1, slice->row_size, |
| 234 | slice->block_start, slice->block_start + slice->block_size - 1, |
| 235 | slice->block_size); |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int vaapi_encode_make_tile_slice(AVCodecContext *avctx, |
| 242 | VAAPIEncodePicture *pic) |
no test coverage detected