gstreamer-devel Digest, Vol 95, Issue 16

Mario GarcĂ­a garciam4d at gmail.com
Wed Dec 12 15:17:52 UTC 2018


Hi all, I'm Mario again.

I did some changes:

   - Add some queues
   - Add some caps filters

The new code is:

#include <gst/gst.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <gst/app/gstappsrc.h>
#include <gst/app/gstappsink.h>
#include <malloc.h>
#include <unistd.h>
#define TOP 10
#define HEIGHTF 512
#define WIDTHF 640


int main(int argc, char *argv[])
{
  GstElement *pipeline, *source, *convert, *enc, *parse, *rtppay, *sink,
*capsFilter1, *capsFilter2, *queue1, *queue2;
        GstCaps *capsSource, *capsConvert, *capsEnc;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
GstFlowReturn Ret;
GstClockTime timestamp = 0;

/* Initialize GStreamer */
gst_init (&argc, &argv);

/* Create the elements */
//1-SOURCE
source = gst_element_factory_make ("appsrc", NULL);
//Source caps
        capsSource = gst_caps_new_simple ("video/x-raw",
          "format",  G_TYPE_STRING, "GRAY8",
          "width", G_TYPE_INT, 640,
          "height", G_TYPE_INT, 512,
  "framerate", GST_TYPE_FRACTION, 25, 1,
  "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
  "interlace-mode", G_TYPE_STRING, "progressive", NULL) ;
        gst_app_src_set_caps (GST_APP_SRC(source), capsSource);
//Set the block propierty to TRUE
g_object_set(source, "block", TRUE, NULL);
//Set the max-bytes propierty
g_object_set(source, "max-bytes", 655360, NULL);

//2-FIRST Queue
queue1 = gst_element_factory_make ("queue", NULL);

//3-CONVERSION
convert = gst_element_factory_make ("videoconvert", NULL);

//4-CAPS Filter1
capsFilter1 = gst_element_factory_make ("capsfilter", NULL);
capsConvert = gst_caps_new_simple ("video/x-raw",
  "format",  G_TYPE_STRING, "I420", NULL);
g_object_set(capsFilter1, "caps", capsConvert, NULL);

//5-SECOND queue
queue2 = gst_element_factory_make ("queue", NULL);

//6-CODEC
enc = gst_element_factory_make ("omxh264enc", "enc");
g_object_set(enc, "bitrate", 1000000, NULL);
g_object_set(enc, "profile", 1, NULL);
g_object_set(enc, "control-rate", 2, NULL);

//7-CAPS filter2
capsFilter2 = gst_element_factory_make ("capsfilter", NULL);
capsEnc = gst_caps_new_simple ("video/x-h264",
          "stream-format",  G_TYPE_STRING, "byte-stream", NULL);
g_object_set(capsFilter2, "caps", capsEnc, NULL);
//8-PARSSING
parse = gst_element_factory_make ("h264parse", "parse");
g_object_set (G_OBJECT (parse), "config-interval", 1,  NULL);

  //9-RTP PAYLOAD
rtppay = gst_element_factory_make ("rtph264pay", "rtppay");
g_object_set (G_OBJECT (rtppay), "ssrc", 575096457,  NULL);

//10-DESTINATION
sink = gst_element_factory_make ("udpsink", "sink");
g_object_set(G_OBJECT (sink), "host", "127.0.0.1", NULL );
g_object_set(G_OBJECT (sink), "port", 9078, NULL );
g_object_set(G_OBJECT (sink), "sync", FALSE, NULL );

/* Create the empty pipeline */
  pipeline = gst_pipeline_new ("test-pipeline");

if (!pipeline || !source || !queue1 || !convert ||  !capsFilter1 || !queue2
|| !enc || !capsFilter2 || !parse || !rtppay || !sink) {
  g_printerr ("Not all elements could be created.\n");
  return -1;
}

/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, queue1, convert, capsFilter1,
queue2, enc, capsFilter2, parse, rtppay, sink, NULL);
if (gst_element_link_many (source, queue1, convert, capsFilter1 , queue2,
enc, capsFilter2, parse, rtppay, sink, NULL) != TRUE) {
    g_printerr ("Elements could not be linked.\n");
    gst_object_unref (pipeline);
    return -1;
}
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (pipeline);
    return -1;
}

//CREATE AND FEED BUFFER
GstBuffer *buf;
GstMapInfo map;
int imageCount=0;

while (imageCount<TOP){
//Allocate and create Buffer
buf=gst_buffer_new_and_alloc(HEIGHTF*WIDTHF);
//To avoid coping in memory
gst_buffer_map(buf, &map, GST_MAP_WRITE);
// We set the buffer to values from 0 (black) to 234 (almost white)
memset (map.data, 26*imageCount, HEIGHTF*WIDTHF);
//Unmap
gst_buffer_unmap(buf, &map);

//Timestamps
//Set frame timestamp
    GST_BUFFER_PTS      (buf) = timestamp;
    GST_BUFFER_DTS      (buf) = timestamp;
    GST_BUFFER_DURATION (buf) = gst_util_uint64_scale_int (1, GST_SECOND,
1);
    timestamp += GST_BUFFER_DURATION (buf);
    printf("Frame is at %lu\n", timestamp);

//Push
Ret=gst_app_src_push_buffer(GST_APP_SRC(source), buf);
if (Ret!=GST_FLOW_OK)
printf ("\nError pushing buffer");
//keep the loop alive
imageCount++;
if(imageCount==10)
imageCount=0;
usleep(20000);
}

gst_app_src_end_of_stream (GST_APP_SRC (source));
printf("End Program.\n");
usleep(100000);

/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;

switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME
(msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info :
"none");
g_clear_error (&err);
g_free (debug_info);
break;
      case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
      default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}

/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");



return 0;
}

It still compile without errors but the new warnings are:

(ALLIMAGESMEM:7075): GLib-GObject-WARNING **: g_object_set_valist: object
class 'GstAppSrc' has no property named 'width'
0:00:00.080860250  7075   0x1523a0 WARN                     omx
/dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomx.c:2814:plugin_init:
Failed to load configuration file: Valid key file could not be found in
search dirs (searched in:
/home/ubuntu/.config:/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg as
per GST_OMX_CONFIG_DIR environment variable, the xdg user config directory
(or XDG_CONFIG_HOME) and the system config directory (or XDG_CONFIG_DIRS)
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set
DPB and MjstreamingFrame is at 0
0:00:00.131855000  7075   0x1508c0 FIXME                default
gstutils.c:3648:gst_pad_create_stream_id_printf_valist:<appsrc0:src>
Creating random stream-id, consider implementing a deterministic way of
creating a stream-id
0:00:00.150974000  7075   0x150a90 FIXME           videoencoder
gstvideoencoder.c:591:gst_video_encoder_setcaps:<enc>
GstVideoEncoder::reset() is deprecated
Framerate set to : 25 at NvxVideoEncoderSetParameter0:00:00.151198417
7075   0x150a90 WARN              omxh264enc
/dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomxh264enc.c:252:gst_omx_h264_enc_set_format:<enc>
Setting profile/level not supported by component
NvMMLiteOpen : Block : BlockType = 4
Frame is at 0
===== MSENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
===== MSENC blits (mode: 1) into tiled surfaces =====
Frame is at 0
0:00:00.172950750  7075 0xb3605350 DEBUG             omxh264enc
/dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomxh264enc.c:565:gst_omx_h264_enc_handle_output_frame:<enc>
got codecconfig in byte-stream format
0:00:00.177570500  7075 0xb3605350 ERROR            omxvideoenc
/dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomxvideoenc.c:982:gst_omx_video_enc_handle_output_frame:<enc>
No corresponding frame found
0:00:00.188272417  7075 0xb3605350 WARN               h264parse
gsth264parse.c:957:gst_h264_parse_handle_frame:<parse> no SPS/PPS yet, nal
Type: 1 Slice, Size: 1462 will be dropped
Frame is at 0

Any help is welcome.

Thanks in advance.

Mario.

>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20181212/f3a21974/attachment-0001.html>


More information about the gstreamer-devel mailing list