Example #1
0
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;
}
Example #2
0
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;
}