static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height) { CUDAScaleContext *s = ctx->priv; AVHWFramesContext *in_frames_ctx; enum AVPixelFormat in_format; enum AVPixelFormat out_format; int ret; /* check that we have a hw context */ if (!ctx->inputs[0]->hw_frames_ctx) { av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n"); return AVERROR(EINVAL); } in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data; in_format = in_frames_ctx->sw_format; out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format; if (!format_is_supported(in_format)) { av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n", av_get_pix_fmt_name(in_format)); return AVERROR(ENOSYS); } if (!format_is_supported(out_format)) { av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n", av_get_pix_fmt_name(out_format)); return AVERROR(ENOSYS); } if (in_width == out_width && in_height == out_height) s->passthrough = 1; s->in_fmt = in_format; s->out_fmt = out_format; s->planes_in[0].width = in_width; s->planes_in[0].height = in_height; s->planes_out[0].width = out_width; s->planes_out[0].height = out_height; ret = init_stage(s, in_frames_ctx->device_ref); if (ret < 0) return ret; ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx); if (!ctx->outputs[0]->hw_frames_ctx) return AVERROR(ENOMEM); return 0; }
WL_EXPORT struct wl_shm_buffer * wl_shm_buffer_create(struct wl_client *client, uint32_t id, int32_t width, int32_t height, int32_t stride, uint32_t format) { struct wl_shm_buffer *buffer; if (!format_is_supported(client, format)) return NULL; buffer = malloc(sizeof *buffer + stride * height); if (buffer == NULL) return NULL; buffer->width = width; buffer->height = height; buffer->format = format; buffer->stride = stride; buffer->offset = 0; buffer->pool = NULL; buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id); if (buffer->resource == NULL) { free(buffer); return NULL; } wl_resource_set_implementation(buffer->resource, &shm_buffer_interface, buffer, destroy_buffer); return buffer; }
static void shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format) { struct wl_shm_pool *pool = wl_resource_get_user_data(resource); struct wl_shm_buffer *buffer; if (!format_is_supported(client, format)) { wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FORMAT, "invalid format 0x%x", format); return; } if (offset < 0 || width <= 0 || height <= 0 || stride < width || INT32_MAX / stride <= height || offset > pool->size - stride * height) { wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_STRIDE, "invalid width, height or stride (%dx%d, %u)", width, height, stride); return; } buffer = malloc(sizeof *buffer); if (buffer == NULL) { wl_client_post_no_memory(client); return; } buffer->width = width; buffer->height = height; buffer->format = format; buffer->stride = stride; buffer->offset = offset; buffer->pool = pool; pool->refcount++; buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id); if (buffer->resource == NULL) { wl_client_post_no_memory(client); shm_pool_unref(pool); free(buffer); return; } wl_resource_set_implementation(buffer->resource, &shm_buffer_interface, buffer, destroy_buffer); }