| @@ -210,7 +210,7 @@ static int get_video_buffer(AVFrame *frame, int align) · 209 unmodified lines |
| 210 | 210 | padded_height, linesizes)) < 0) |
| 211 | 211 | return ret; |
| 212 | 212 | |
| 213 | | − total_size = 4*plane_padding; |
| 213 | + total_size = 4 * plane_padding + 4 * align; |
| 214 | 214 | for (int i = 0; i < 4; i++) { |
| 215 | 215 | if (sizes[i] > SIZE_MAX - total_size) |
| 216 | 216 | return AVERROR(EINVAL); |
| @@ -230,6 +230,7 @@ static int get_video_buffer(AVFrame *frame, int align) · 13 unmodified lines |
| 230 | 230 | for (int i = 1; i < 4; i++) { |
| 231 | 231 | if (frame->data[i]) |
| 232 | 232 | frame->data[i] += i * plane_padding; |
| 233 | + frame->data[i] = (uint8_t *)FFALIGN((uintptr_t)frame->data[i], align); |
| 233 | 234 | } |
| 234 | 235 | |
| 235 | 236 | frame->extended_data = frame->data; |
| @@ -244,6 +245,7 @@ static int get_audio_buffer(AVFrame *frame, int align) · 8 unmodified lines |
| 244 | 245 | { |
| 245 | 246 | int planar = av_sample_fmt_is_planar(frame->format); |
| 246 | 247 | int channels, planes; |
| 248 | + size_t size; |
| 247 | 249 | int ret; |
| 248 | 250 | |
| 249 | 251 | channels = frame->ch_layout.nb_channels; |
| @@ -256,6 +258,9 @@ static int get_audio_buffer(AVFrame *frame, int align) · 6 unmodified lines |
| 256 | 258 | return ret; |
| 257 | 259 | } |
| 258 | 260 | |
| 261 | + if (align <= 0) |
| 262 | + align = ALIGN; |
| 263 | + |
| 259 | 264 | if (planes > AV_NUM_DATA_POINTERS) { |
| 260 | 265 | frame->extended_data = av_calloc(planes, |
| 261 | 266 | sizeof(*frame->extended_data)); |
| @@ -270,21 +275,27 @@ static int get_audio_buffer(AVFrame *frame, int align) · 8 unmodified lines |
| 270 | 275 | } else |
| 271 | 276 | frame->extended_data = frame->data; |
| 272 | 277 | |
| 278 | + if (frame->linesize[0] > SIZE_MAX - align) |
| 279 | + return AVERROR(EINVAL); |
| 280 | + size = frame->linesize[0] + (size_t)align; |
| 281 | + |
| 273 | 282 | for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { |
| 274 | | − frame->buf[i] = av_buffer_alloc(frame->linesize[0]); |
| 283 | + frame->buf[i] = av_buffer_alloc(size); |
| 275 | 284 | if (!frame->buf[i]) { |
| 276 | 285 | av_frame_unref(frame); |
| 277 | 286 | return AVERROR(ENOMEM); |
| 278 | 287 | } |
| 279 | | − frame->extended_data[i] = frame->data[i] = frame->buf[i]->data; |
| 288 | + frame->extended_data[i] = frame->data[i] = |
| 289 | + (uint8_t *)FFALIGN((uintptr_t)frame->buf[i]->data, align); |
| 280 | 290 | } |
| 281 | 291 | for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) { |
| 282 | | − frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]); |
| 292 | + frame->extended_buf[i] = av_buffer_alloc(size); |
| 283 | 293 | if (!frame->extended_buf[i]) { |
| 284 | 294 | av_frame_unref(frame); |
| 285 | 295 | return AVERROR(ENOMEM); |
| 286 | 296 | } |
| 287 | | − frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data; |
| 297 | + frame->extended_data[i + AV_NUM_DATA_POINTERS] = |
| 298 | + (uint8_t *)FFALIGN((uintptr_t)frame->extended_buf[i]->data, align); |
| 288 | 299 | } |
| 289 | 300 | return 0; |
| 290 | 301 | |