コード例 #1
0
ファイル: obs-source.c プロジェクト: BraginWoW/obs-studio
static bool upload_frame(texture_t tex, const struct source_frame *frame)
{
    void *ptr;
    uint32_t row_bytes;
    enum convert_type type = get_convert_type(frame->format);

    if (type == CONVERT_NONE) {
        texture_setimage(tex, frame->data, frame->row_bytes, false);
        return true;
    }

    if (!texture_map(tex, &ptr, &row_bytes))
        return false;

    if (type == CONVERT_420)
        decompress_420(frame->data, frame->width, frame->height,
                       frame->row_bytes, 0, frame->height, ptr);

    else if (type == CONVERT_NV12)
        decompress_nv12(frame->data, frame->width, frame->height,
                        frame->row_bytes, 0, frame->height, ptr);

    else if (type == CONVERT_422_Y)
        decompress_422(frame->data, frame->width, frame->height,
                       frame->row_bytes, 0, frame->height, ptr, true);

    else if (type == CONVERT_422_U)
        decompress_422(frame->data, frame->width, frame->height,
                       frame->row_bytes, 0, frame->height, ptr, false);

    texture_unmap(tex);
    return true;
}
コード例 #2
0
ファイル: obs-source.c プロジェクト: Christicles/obs-studio
static inline bool set_async_texture_size(struct obs_source *source,
		struct source_frame *frame)
{
	enum convert_type prev, cur;
	prev = get_convert_type(source->async_format);
	cur  = get_convert_type(frame->format);
	if (source->async_texture) {
		if (source->async_width  == frame->width &&
		    source->async_height == frame->height &&
		    prev == cur)
			return true;
	}

	texture_destroy(source->async_texture);
	texrender_destroy(source->async_convert_texrender);
	source->async_convert_texrender = NULL;

	if (cur != CONVERT_NONE && init_gpu_conversion(source, frame)) {
		source->async_gpu_conversion = true;

		source->async_convert_texrender =
			texrender_create(GS_RGBA, GS_ZS_NONE);

		source->async_texture = gs_create_texture(
				source->async_convert_width,
				source->async_convert_height,
				GS_RGBA, 1, NULL, GS_DYNAMIC);

	} else {
		source->async_gpu_conversion = false;

		source->async_texture = gs_create_texture(
				frame->width, frame->height,
				GS_RGBA, 1, NULL, GS_DYNAMIC);
	}

	if (!source->async_texture)
		return false;

	source->async_width  = frame->width;
	source->async_height = frame->height;
	return true;
}
コード例 #3
0
ファイル: obs-source.c プロジェクト: Christicles/obs-studio
static bool update_async_texture(struct obs_source *source,
		const struct source_frame *frame)
{
	texture_t         tex       = source->async_texture;
	texrender_t       texrender = source->async_convert_texrender;
	enum convert_type type      = get_convert_type(frame->format);
	void              *ptr;
	uint32_t          linesize;

	source->async_format     = frame->format;
	source->async_flip       = frame->flip;
	source->async_full_range = frame->full_range;
	memcpy(source->async_color_matrix, frame->color_matrix,
			sizeof(frame->color_matrix));
	memcpy(source->async_color_range_min, frame->color_range_min,
			sizeof frame->color_range_min);
	memcpy(source->async_color_range_max, frame->color_range_max,
			sizeof frame->color_range_max);

	if (source->async_gpu_conversion && texrender)
		return update_async_texrender(source, frame);

	if (type == CONVERT_NONE) {
		texture_setimage(tex, frame->data[0], frame->linesize[0],
				false);
		return true;
	}

	if (!texture_map(tex, &ptr, &linesize))
		return false;

	if (type == CONVERT_420)
		decompress_420((const uint8_t* const*)frame->data,
				frame->linesize,
				0, frame->height, ptr, linesize);

	else if (type == CONVERT_NV12)
		decompress_nv12((const uint8_t* const*)frame->data,
				frame->linesize,
				0, frame->height, ptr, linesize);

	else if (type == CONVERT_422_Y)
		decompress_422(frame->data[0], frame->linesize[0],
				0, frame->height, ptr, linesize, true);

	else if (type == CONVERT_422_U)
		decompress_422(frame->data[0], frame->linesize[0],
				0, frame->height, ptr, linesize, false);

	texture_unmap(tex);
	return true;
}
コード例 #4
0
ファイル: obs-source.c プロジェクト: Christicles/obs-studio
static void upload_raw_frame(texture_t tex, const struct source_frame *frame)
{
	switch (get_convert_type(frame->format)) {
		case CONVERT_422_U:
		case CONVERT_422_Y:
			texture_setimage(tex, frame->data[0],
					frame->linesize[0], false);
			break;

		case CONVERT_NV12:
		case CONVERT_420:
			assert(false && "Conversion not yet implemented");
			break;

		case CONVERT_NONE:
			assert(false && "No conversion requested");
			break;
	}
}
コード例 #5
0
ファイル: obs-source.c プロジェクト: Christicles/obs-studio
static inline bool init_gpu_conversion(struct obs_source *source,
		struct source_frame *frame)
{
	switch (get_convert_type(frame->format)) {
		case CONVERT_422_Y:
		case CONVERT_422_U:
			return set_packed422_sizes(source, frame);

		case CONVERT_NV12:
		case CONVERT_420:
			/* TODO: implement conversion */
			break;

		case CONVERT_NONE:
			assert(false && "No conversion requested");
			break;

	}
	return false;
}