void owr_image_server_add_image_renderer(OwrImageServer *image_server, OwrImageRenderer *image_renderer, const gchar *tag) { OwrImageServerPrivate *priv; g_return_if_fail(OWR_IS_IMAGE_SERVER(image_server)); g_return_if_fail(OWR_IS_IMAGE_RENDERER(image_renderer)); g_return_if_fail(tag && tag[0]); priv = image_server->priv; g_mutex_lock(&priv->image_renderers_mutex); if (!g_hash_table_contains(priv->image_renderers, tag)) { g_hash_table_insert(priv->image_renderers, g_strdup(tag), image_renderer); g_object_ref(image_renderer); } else g_warning("Image renderer not added, an image renderer is already added for this tag"); g_mutex_unlock(&priv->image_renderers_mutex); if (!priv->socket_service_is_started) { g_socket_listener_add_address(G_SOCKET_LISTENER(priv->socket_service), g_inet_socket_address_new(g_inet_address_new_from_string("127.0.0.1"), (guint16)priv->port), G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, NULL, NULL, NULL); g_socket_service_start(priv->socket_service); priv->socket_service_is_started = TRUE; } }
/** * _owr_image_renderer_pull_bmp_image: * @image_renderer: * * Returns: (transfer full): */ GBytes * _owr_image_renderer_pull_bmp_image(OwrImageRenderer *image_renderer) { GstCaps *caps; GstSample *sample; GstBuffer *buf = NULL; GstMapInfo info; GstStructure *s; guint bufsize, total_size, src_rowsize, dest_rowsize, image_width, image_height; guint8 *image_data, *src_data, *srcpos, *destpos; gboolean ret, disabled = FALSE; g_return_val_if_fail(OWR_IS_IMAGE_RENDERER(image_renderer), NULL); if (!image_renderer->priv->appsink) return NULL; sample = gst_app_sink_pull_sample(GST_APP_SINK(image_renderer->priv->appsink)); if (!sample) return NULL; buf = gst_sample_get_buffer(sample); if (!buf) { gst_sample_unref(sample); return NULL; } caps = gst_sample_get_caps(sample); s = gst_caps_get_structure(caps, 0); ret = gst_structure_get_int(s, "width", (gint *)&image_width); ret |= gst_structure_get_int(s, "height", (gint *)&image_height); if (!ret) { g_critical("%s Could not get bmp video dimensions from configured caps on appsink", __FUNCTION__); image_width = 0; image_height = 0; } if (!gst_buffer_map(buf, &info, GST_MAP_READ)) g_assert_not_reached(); g_assert(info.data); g_object_get(image_renderer, "disabled", &disabled, NULL); bufsize = (guint) info.size; total_size = BMP_HEADER_SIZE + bufsize; image_data = disabled ? g_malloc0(total_size) : g_malloc(total_size); if (!image_data) { g_critical("%s Allocate mem failed (g_malloc(total_size))", __FUNCTION__); return NULL; } fill_bmp_header(image_data, image_width, image_height); src_rowsize = DIB_BITS_PER_PIXEL * image_width / 8; dest_rowsize = ((DIB_BITS_PER_PIXEL * image_width + 31) / 32) * 4; src_data = info.data; destpos = image_data + total_size; if (!disabled) { for (srcpos = src_data; srcpos < src_data + bufsize; srcpos += src_rowsize) { destpos -= dest_rowsize; memcpy(destpos, srcpos, src_rowsize); } } gst_buffer_unmap(buf, &info); gst_sample_unref(sample); return g_bytes_new_take(image_data, total_size); }