
static int check_pointers(AVHWFramesContext *ctx)
{
    if (!ctx || !ctx->internal || !ctx->internal->hw_type)
        return AVERROR(EINVAL);
    return 0;
}

int av_hwframe_ctx_init(AVBufferRef *ref)
{
    if (!ref || !ref->data)
        return AVERROR(EINVAL);
    
    AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
    int ret = check_pointers(ctx);
    if (ret < 0)
        return ret;
    
    // Rest of the function remains the same
