summaryrefslogtreecommitdiffstats
path: root/coverage/bin/loc.txt
blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (plain)

5715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (C) 2017 Advanced Driver Information Technology GmbH, Robert Bosch GmbH, Robert Bosch Car Multimedia GmbH, DENSO Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include <gst/gst.h>
#include <gst/video/gstvideometa.h>
#include <gst/allocators/gstdmabuf.h>
#include <gst/app/gstappsrc.h>

#include <libweston/libweston.h>

#include "transmitter_api.h"
#include "waltham-renderer.h"
#include "plugin.h"

struct waltham_renderer {
	struct renderer base;
};

struct GstAppContext {
	GMainLoop *loop;
	GstBus *bus;
	GstElement *pipeline;
	GstElement *appsrc;
	GstBuffer *gstbuffer;
};

gboolean bus_message(GstBus *bus, GstMessage *message, gpointer p)
{
	struct GstAppContext *gstctx = p;

	switch( GST_MESSAGE_TYPE(message)) {
        case GST_MESSAGE_ERROR:
	{
		GError *err;
		gchar *debug;

		gst_message_parse_error(message, &err, &debug);
		g_print("ERROR: %s\n", err->message);

		g_error_free(err);
		g_free(debug);
		g_main_loop_quit(gstctx->loop);

		return false;
		break;
	}

	case GST_MESSAGE_STATE_CHANGED:
	{
		GstState oldstate, newstate;

		gst_message_parse_state_changed(message, &oldstate, &newstate, NULL);
		switch (newstate){
		case GST_STATE_PAUSED:
			fprintf(stderr, "%s: state is paused\n", GST_MESSAGE_SRC_NAME(message));
			break;
		case GST_STATE_READY:
			fprintf(stderr, "%s: state is ready\n", GST_MESSAGE_SRC_NAME(message));
			break;
		case GST_STATE_VOID_PENDING:
			fprintf(stderr, "%s: state is pending\n", GST_MESSAGE_SRC_NAME(message));
			break;
		case GST_STATE_NULL:
			fprintf(stderr, "%s: state is NULL\n", GST_MESSAGE_SRC_NAME(message));
			break;
		case GST_STATE_PLAYING:
			fprintf(stderr, "%s: state is playing\n", GST_MESSAGE_SRC_NAME(message));
			break;
		}
		break;
	}
        default:
		fprintf(stderr, "Unhandled message\n");
		break;
	}

	return true;
}

static int
gst_pipe_init(struct weston_transmitter_output *output, struct gst_settings *settings)
{
	struct GstAppContext *gstctx;
	GstCaps *caps;
	GError *gerror = NULL;
	FILE * pFile;
	size_t lSize;
	char * pipe = NULL;
	size_t res;

	gstctx=zalloc(sizeof (*gstctx));
	if(!gstctx){
		weston_log("Enable to allocate memory\n");
		return -1;
	}

	/* create gstreamer pipeline */
	gst_init(NULL, NULL);
	gstctx->loop = g_main_loop_new(NULL, FALSE);

	/* read pipeline from file */
	pFile = fopen("/etc/xdg/weston/transmitter_pipeline.cfg" , "rb");
	if (pFile==NULL) {
		weston_log("File open error\n");
		return -1;
	}

	/* obtain file size */
	fseek (pFile , 0 , SEEK_END);
	lSize = ftell (pFile);
	rewind (pFile);

	/* allocate memory to contain the whole file: */
	pipe = zalloc (sizeof(char) * lSize);
	if (pipe == NULL) {
		weston_log("Cannot allocate memory\n");
		return -1;
	}

	/* copy the file into the buffer: */
	res = fread (pipe,1,lSize,pFile);
	if (res != lSize)
	{
		weston_log("File read error\n");
		return -1;
	}

	/* close file */
	fclose(pFile);
	weston_log("Parsing GST pipeline:%s",pipe);
	gstctx->pipeline = gst_parse_launch(pipe, &gerror);
	free(pipe);
	if(!gstctx->pipeline)
		weston_log("Could not create gstreamer pipeline.\n");

	gstctx->bus = gst_pipeline_get_bus((GstPipeline*)((void*)gstctx->pipeline));
	gst_bus_add_watch(gstctx->bus, bus_message, &gstctx);

	//gstctx->appsrc = (GstAppSrc*) gst_bin_get_by_name(GST_BIN(gstctx->pipeline), "src");
	gstctx->appsrc = gst_bin_get_by_name(GST_BIN(gstctx->pipeline), "src");
	if (!gstctx->appsrc)
		return -1;

	caps = gst_caps_new_simple("video/x-raw",
				   "format", G_TYPE_STRING, "BGRx",
				   "width", G_TYPE_INT, settings->width,
				   "height", G_TYPE_INT, settings->height,
				   NULL);
	if (!caps)
		return -1;

	g_object_set(G_OBJECT(gstctx->appsrc),
		     "caps", caps,
		     "stream-type", 0,
		     "format", GST_FORMAT_TIME,
		     "is-live", TRUE,
		     NULL);
	gst_caps_unref(caps);

	gst_element_set_state((GstElement*)((void*)gstctx->pipeline), GST_STATE_PLAYING);
	output->renderer->ctx = gstctx;

	weston_log("Gstreamer pipeline inited\n");

	return 0;
}

static int
recorder_enable(struct weston_transmitter_output *output)
{
	struct gst_settings *settings;

	struct weston_transmitter_remote* remote = output->remote;

	/*
	 * Limitation:
	 * Hard coding bitrate and crop params.
	 * In case of gst-recorder case these were taken from weston.ini
	 */
	int32_t bitrate = 3000000;

	settings = malloc(sizeof(* settings));
	settings->ip = remote->addr;

	settings->port = atoi(remote->port);

	settings->bitrate = bitrate;
	settings->width = output->renderer->surface_width;
	settings->height = output->renderer->surface_height;

	weston_log("gst-setting are :-->\n");
	weston_log("ip = %s \n",settings->ip);
	weston_log("port = %d \n",settings->port);
	weston_log("bitrate = %d \n",settings->bitrate);
	weston_log("width = %d \n",settings->width);
	weston_log("height = %d \n",settings->height);

	gst_pipe_init(output, settings);

	weston_log("Enabling renderer display\n");

	return 0;
}

static void waltham_renderer_repaint_output(struct weston_transmitter_output *output)
{
	GstBuffer *gstbuffer;
	GstMemory *mem;
	GstAllocator *allocator;
	int stride = output->renderer->buf_stride;
	gsize offset = 0;

	if (!output->renderer->recorder_enabled) {
		recorder_enable(output);
		output->renderer->recorder_enabled = 1;
	}

	gstbuffer = gst_buffer_new();
	allocator = gst_dmabuf_allocator_new();
	mem = gst_dmabuf_allocator_alloc(allocator, output->renderer->dmafd,
					 stride * output->renderer->surface_height);
	gst_buffer_append_memory(gstbuffer, mem);
	gst_buffer_add_video_meta_full(gstbuffer,
				       GST_VIDEO_FRAME_FLAG_NONE,
				       GST_VIDEO_FORMAT_BGRx,
				       output->renderer->surface_width,
				       output->renderer->surface_height,
				       1,
				       &offset,
				       &stride);

	gst_app_src_push_buffer(GST_APP_SRC(output->renderer->ctx->appsrc), gstbuffer);
	gst_object_unref(allocator);
}

static int
waltham_renderer_display_create(struct weston_transmitter_output *output)
{
	struct waltham_renderer *wth_renderer;

	wth_renderer = zalloc(sizeof *wth_renderer);
	if (wth_renderer == NULL)
		return -1;

	wth_renderer->base.repaint_output = waltham_renderer_repaint_output;
	output->renderer = &wth_renderer->base;

	weston_log("Created renderer display\n");

	return 0;
}

WL_EXPORT struct waltham_renderer_interface waltham_renderer_interface = {
		.display_create = waltham_renderer_display_create
};