Dear all,
I have added variable text to GST-RTSP-SERVER by modifying file rtsp-media-factory.c and adding text/x-raw pad to element Textoverlay.It is supposed to read temperature value from file provided by temperature sensor in /proc The pipeline I am using for test-launch example is: videotestsrc ! textoverlay name=textoverlay ! omxh264enc ! video/x-h264, width=800, height=480, framerate=30/1, profile=high ! h264parse ! rtph264pay name=pay0 pt=96 It works but the stream is incredibly slow compared the raw server without such a modification. Please, could anyone help me resolve this issue or could anyone verify whether it is done in a correct way? I am enclosing methods added and modified in rtsp-media-factory.c #define O_RDONLY 00 void readTemperatureFromSensor(char* result) { g_print("reading temperature from sensor\r\n"); DIR *dir; struct dirent *dirent; char dev[16]; // Dev ID char devPath[128]; // Path to device char buf[256]; // Data from device char tmpData[6]; // Temp C * 1000 reported by device char path[] = "/sys/bus/w1/devices"; ssize_t numRead; dir = opendir(path); if (dir != NULL) { while ((dirent = readdir(dir))) // 1-wire devices are links beginning with 28- if (dirent->d_type == DT_LNK && strstr(dirent->d_name, "28-") != NULL) { strcpy(dev, dirent->d_name); printf("\nDevice: %s\n", dev); } (void) closedir(dir); } else { perror("Couldn't open the w1 devices directory"); return 1; } // Assemble path to OneWire device sprintf(devPath, "%s/%s/w1_slave", path, dev); // Read temp continuously // Opening the device's file triggers new reading int fd = open(devPath, O_RDONLY); if (fd == -1) { perror("Couldn't open the w1 device."); return 1; } while ((numRead = read(fd, buf, 256)) > 0) { strncpy(tmpData, strstr(buf, "t=") + 2, 5); float tempC = strtof(tmpData, NULL); printf("Device: %s - ", dev); printf("Temp: %.3f C ", tempC / 1000); printf("%.3f F\n\n", (tempC / 1000) * 9 / 5 + 32); snprintf(result, strlen(result), "%f", tempC); } g_print("finished reading temperature\r\n"); } #define APPSRC_CAPS "text/x-raw,format=(string)utf8" static gboolean read_data(GstElement * appsrc) { g_print("read data started\r\n"); int t = 0; GstFlowReturn ret; GstBuffer * buffer; //buffer = gst_buffer_new(); buffer = gst_buffer_new(); GstMemory *mem; char* temperature = NULL; temperature = malloc(10 * sizeof(char)); readTemperatureFromSensor(temperature); g_print("temperature variable content:%s\r\n", temperature); mem = gst_allocator_alloc(NULL, strlen(temperature), NULL); gst_buffer_append_memory(buffer, mem); g_print("buffer size:%d", strlen(temperature)); gst_buffer_fill(buffer, 0, temperature, strlen(temperature)); g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret); g_print("size:%d\r\n", gst_buffer_get_size(buffer)); gst_buffer_unref(buffer); g_free(temperature); g_print("read data stopped\r\n"); } static void start_feed(GstElement * pipeline, guint size, gpointer * appsrc) { g_print("feed started\r\n"); g_idle_add((GSourceFunc) read_data, appsrc); } static GstElement * default_create_element(GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { GstRTSPMediaFactoryPrivate *priv = factory->priv; GstElement *element; GError *error = NULL; GST_RTSP_MEDIA_FACTORY_LOCK(factory); /* we need a parse syntax */ if (priv->launch == NULL) goto no_launch; /* parse the user provided launch line */ element = gst_parse_launch_full(priv->launch, NULL, GST_PARSE_FLAG_PLACE_IN_BIN, &error); if (element == NULL) { goto parse_error; } else { GstElement* appsrc = gst_element_factory_make("appsrc", "appsrc"); GstCaps* caps = gst_caps_from_string(APPSRC_CAPS); g_object_set(appsrc, "caps", caps, NULL); gst_caps_unref(caps); g_object_set(G_OBJECT(appsrc), "stream-type", 0, // GST_APP_STREAM_TYPE_STREAM "format", GST_FORMAT_TIME, "is-live", TRUE, NULL); gst_bin_add(GST_BIN(element), appsrc); GstElement* textoverlay = gst_bin_get_by_name(GST_BIN(element), "textoverlay"); GstPad* srcpad = gst_element_get_static_pad(appsrc, "src"); GstPad* sinkpad = gst_element_get_static_pad(textoverlay, "text_sink"); GstPadLinkReturn ret = gst_pad_link(srcpad, sinkpad); g_signal_connect(appsrc, "need-data", G_CALLBACK(start_feed), appsrc); gst_element_sync_state_with_parent(appsrc); gst_element_sync_state_with_parent(textoverlay); g_print("finished adding textoverlay element"); } GST_RTSP_MEDIA_FACTORY_UNLOCK(factory); etc. Best regards, Ivo -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |