
#define CHECK_NULL(ptr) if (!(ptr)) return AVERROR(EINVAL)

int av_hwframe_ctx_init(AVBufferRef *ref)
{
    CHECK_NULL(ref);
    CHECK_NULL(ref->data);
    
    AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
    CHECK_NULL(ctx->internal);
    CHECK_NULL(ctx->internal->hw_type);
    
    // Rest of the function remains the same
