| 261 | } |
| 262 | |
| 263 | AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in) |
| 264 | { |
| 265 | FFHWDeviceContext *device_ctx = (FFHWDeviceContext*)device_ref_in->data; |
| 266 | const HWContextType *hw_type = device_ctx->hw_type; |
| 267 | FFHWFramesContext *ctxi; |
| 268 | AVHWFramesContext *ctx; |
| 269 | AVBufferRef *buf, *device_ref = NULL; |
| 270 | |
| 271 | ctxi = av_mallocz(sizeof(*ctxi)); |
| 272 | if (!ctxi) |
| 273 | return NULL; |
| 274 | ctx = &ctxi->p; |
| 275 | |
| 276 | if (hw_type->frames_hwctx_size) { |
| 277 | ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size); |
| 278 | if (!ctx->hwctx) |
| 279 | goto fail; |
| 280 | } |
| 281 | |
| 282 | device_ref = av_buffer_ref(device_ref_in); |
| 283 | if (!device_ref) |
| 284 | goto fail; |
| 285 | |
| 286 | buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx), |
| 287 | hwframe_ctx_free, NULL, |
| 288 | AV_BUFFER_FLAG_READONLY); |
| 289 | if (!buf) |
| 290 | goto fail; |
| 291 | |
| 292 | ctx->av_class = &hwframe_ctx_class; |
| 293 | ctx->device_ref = device_ref; |
| 294 | ctx->device_ctx = &device_ctx->p; |
| 295 | ctx->format = AV_PIX_FMT_NONE; |
| 296 | ctx->sw_format = AV_PIX_FMT_NONE; |
| 297 | |
| 298 | ctxi->hw_type = hw_type; |
| 299 | |
| 300 | return buf; |
| 301 | |
| 302 | fail: |
| 303 | av_buffer_unref(&device_ref); |
| 304 | av_freep(&ctx->hwctx); |
| 305 | av_freep(&ctx); |
| 306 | return NULL; |
| 307 | } |
| 308 | |
| 309 | static int hwframe_pool_prealloc(AVBufferRef *ref) |
| 310 | { |
no test coverage detected