void texture_setimage(texture_t tex, const void *data, uint32_t linesize, bool flip) { if (!thread_graphics || !tex) return; void *ptr; uint32_t linesize_out; uint32_t row_copy; int32_t height = (int32_t)texture_getheight(tex); int32_t y; if (!texture_map(tex, &ptr, &linesize_out)) return; row_copy = (linesize < linesize_out) ? linesize : linesize_out; if (flip) { for (y = height-1; y >= 0; y--) memcpy((uint8_t*)ptr + (uint32_t)y * linesize_out, (uint8_t*)data + (uint32_t)y * linesize, row_copy); } else if (linesize == linesize_out) { memcpy(ptr, data, row_copy * height); } else { for (y = 0; y < height; y++) memcpy((uint8_t*)ptr + (uint32_t)y * linesize_out, (uint8_t*)data + (uint32_t)y * linesize, row_copy); } texture_unmap(tex); }
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; }
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; }
/* ...deallocate texture data */ static void __destroy_od_texture(gpointer data, GstMiniObject *obj) { GstBuffer *buffer = (GstBuffer *)obj; vsink_meta_t *vmeta = gst_buffer_get_vsink_meta(buffer); objdet_meta_t *ometa = gst_buffer_get_objdet_meta(buffer); TRACE(DEBUG, _b("destroy texture referenced by meta: %p:%p"), vmeta, vmeta->priv); /* ...destroy memory mapping */ texture_unmap(ometa->buf); /* ...destroy texture */ texture_destroy(vmeta->priv); }