| 217 | } |
| 218 | |
| 219 | static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) |
| 220 | { |
| 221 | AVCodecContext *avctx = s->avctx; |
| 222 | MPVPicture *pic = av_refstruct_pool_get(s->picture_pool); |
| 223 | int ret; |
| 224 | |
| 225 | if (!pic) |
| 226 | return AVERROR(ENOMEM); |
| 227 | |
| 228 | dst->ptr = pic; |
| 229 | |
| 230 | pic->reference = reference; |
| 231 | |
| 232 | /* WM Image / Screen codecs allocate internal buffers with different |
| 233 | * dimensions / colorspaces; ignore user-defined callbacks for these. */ |
| 234 | if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && |
| 235 | avctx->codec_id != AV_CODEC_ID_VC1IMAGE && |
| 236 | avctx->codec_id != AV_CODEC_ID_MSS2) { |
| 237 | ret = ff_thread_get_buffer(avctx, pic->f, |
| 238 | reference ? AV_GET_BUFFER_FLAG_REF : 0); |
| 239 | } else { |
| 240 | pic->f->width = avctx->width; |
| 241 | pic->f->height = avctx->height; |
| 242 | pic->f->format = avctx->pix_fmt; |
| 243 | ret = avcodec_default_get_buffer2(avctx, pic->f, 0); |
| 244 | } |
| 245 | if (ret < 0) |
| 246 | goto fail; |
| 247 | |
| 248 | ret = ff_mpv_pic_check_linesize(avctx, pic->f, &s->linesize, &s->uvlinesize); |
| 249 | if (ret < 0) |
| 250 | goto fail; |
| 251 | |
| 252 | ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); |
| 253 | if (ret < 0) |
| 254 | goto fail; |
| 255 | |
| 256 | av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width); |
| 257 | av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height || |
| 258 | FFALIGN(s->mb_height, 2) == s->buffer_pools.alloc_mb_height); |
| 259 | av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); |
| 260 | ret = ff_mpv_alloc_pic_accessories(s->avctx, dst, &s->sc, |
| 261 | &s->buffer_pools, s->mb_height); |
| 262 | if (ret < 0) |
| 263 | goto fail; |
| 264 | |
| 265 | return 0; |
| 266 | fail: |
| 267 | ff_mpv_unref_picture(dst); |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVWorkPicture *dst) |
| 272 | { |
no test coverage detected