| 504 | } |
| 505 | |
| 506 | int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) |
| 507 | { |
| 508 | FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data; |
| 509 | AVHWFramesContext *ctx = &ctxi->p; |
| 510 | int ret; |
| 511 | |
| 512 | if (ctxi->source_frames) { |
| 513 | // This is a derived frame context, so we allocate in the source |
| 514 | // and map the frame immediately. |
| 515 | AVFrame *src_frame; |
| 516 | |
| 517 | frame->format = ctx->format; |
| 518 | frame->hw_frames_ctx = av_buffer_ref(hwframe_ref); |
| 519 | if (!frame->hw_frames_ctx) |
| 520 | return AVERROR(ENOMEM); |
| 521 | |
| 522 | src_frame = av_frame_alloc(); |
| 523 | if (!src_frame) |
| 524 | return AVERROR(ENOMEM); |
| 525 | |
| 526 | ret = av_hwframe_get_buffer(ctxi->source_frames, |
| 527 | src_frame, 0); |
| 528 | if (ret < 0) { |
| 529 | av_frame_free(&src_frame); |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | ret = av_hwframe_map(frame, src_frame, |
| 534 | ctxi->source_allocation_map_flags); |
| 535 | if (ret) { |
| 536 | av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived " |
| 537 | "frame context: %d.\n", ret); |
| 538 | av_frame_free(&src_frame); |
| 539 | return ret; |
| 540 | } |
| 541 | |
| 542 | // Free the source frame immediately - the mapped frame still |
| 543 | // contains a reference to it. |
| 544 | av_frame_free(&src_frame); |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | if (!ctxi->hw_type->frames_get_buffer) |
| 550 | return AVERROR(ENOSYS); |
| 551 | |
| 552 | if (!ctx->pool) |
| 553 | return AVERROR(EINVAL); |
| 554 | |
| 555 | frame->hw_frames_ctx = av_buffer_ref(hwframe_ref); |
| 556 | if (!frame->hw_frames_ctx) |
| 557 | return AVERROR(ENOMEM); |
| 558 | |
| 559 | ret = ctxi->hw_type->frames_get_buffer(ctx, frame); |
| 560 | if (ret < 0) { |
| 561 | av_buffer_unref(&frame->hw_frames_ctx); |
| 562 | return ret; |
| 563 | } |
no test coverage detected