'Set and get the timestamp manually using appsrc/appsink in Gstreamer
gstreamer developpers. At sender,I use appsrc for abtaining outer YUV data,and then encode and transmit via rtph265pay and udpsink. At receiver,I use udpsrc and rtph265depay to receive H265 bitstream,and then I use appsink to extract YUV data.
In appsrc, I set timestamp like this: GST_BUFFER_PTS(buffer)=100;
In appsink,I get the timestamp like this: timestamp=GST_BUFFER_PTS(buffer);
But it comes the problem:the value of timestamp don't equal to 100(I set in appsrc). Why???
Actually,I just want to achieve this:
At sender, First,I obtain YUV data via appsrc. I want to write an ID into each frame of YUV(before encoding), and then I encode,and then I transmit them into Local Area Network via rtph265pay and udpsink.
At receiver, I receive them via udpsrc and rtph265depay,then I decode and get YUV data via appsink.
My main purpose is: At receiver,I can get the ID of each YUV data so that I can have the knowledge that if there exists a phenomenon of lossing data when transmitting by checking the continuous ID numbers.
Then I thought of a method: Using timestamp maybe can achieve my purpose.So I tried.
Now, I set "do-timestamp" as FALSE in appsrc, and I found that udpsrc also has the "do-timestamp" property,so I also set "do-timestamp" as FALSE in udpsrc. Then I set the rest properties of appsrc like this: g_object_set(G_OBJECT(appsrc), "stream-type",0, "is-live",TRUE, "format",GST_FORMAT_TIME, "max-bytes",FRAME_W*FRAME_H*3/2*100, "block",TRUE, "min-percent",50, NULL); Then I output the timestamp in appsink,but it doesn't equal to 100 which I set in appsrc.
Is there something else I don't realize? Please help me find the problem. Or if I set the timestamp in GstRtpBuffer(in this way,I can set timestamp as frame ID and I can get this timestamp before decoding.),how can I do?
static int cb_need_data (App * app,int num){
static GstClockTime timestamp = 0;
GstBuffer *buffer;
guint buffersize;
GstFlowReturn ret;
GstMapInfo info;
buffersize = FRAME_H * FRAME_W * 3/2;
m.lock();
buffer = gst_buffer_new_allocate(nullptr,buffersize,nullptr);
m.unlock();
gst_buffer_fill(buffer,0,Q3.DeQueue().data,buffersize);
//buffer = gst_buffer_copy(buffer);
GST_BUFFER_PTS(buffer) = 100;
//GST_BUFFER_DTS(buffer) = 100;
cout << endl << "GST_BUFFER_PTS_IS_VALID(buffer) is: " << GST_BUFFER_PTS_IS_VALID(buffer) << endl;
// Push the buffer into the appsrc
g_signal_emit_by_name (app->videosrc, "push-buffer", buffer, &ret);
//gst_app_src_push_buffer(GST_APP_SRC(app->videosrc),buffer);
}
gst_buffer_unref (buffer);
return 0;
}
static GstFlowReturn on_new_sample_from_sink (GstElement * pipeline, guint size, App * app) {
GstSample *sample;
GstBuffer *app_buffer, *buffer;
GstMapInfo map;
GstFlowReturn ret;
gboolean res;
guint buffersize;
GstClockTime timestamp;
buffersize = FRAME_H * FRAME_W * 3/2;
buffer = gst_buffer_new_and_alloc(buffersize);
gst_buffer_make_writable(buffer);
g_signal_emit_by_name (GST_APP_SINK (pipeline), "pull-sample", &sample, NULL);
if (sample){
GstCaps *caps;
GstStructure *s;
caps = gst_sample_get_caps(sample);
if (!caps){
g_print("could not get snapshot format.***\n");
exit(-1);
}
s = gst_caps_get_structure(caps,0);
// we need to get the final caps on the buffer to get the size
res = gst_structure_get_int(s,"width",&width);
res |= gst_structure_get_int (s, "height", &height);
if (!res){
g_print("could not get snapshot dimension.***\n");
exit(-1);
}else{
g_print("1:width=%d,height=%d\n",width,height);
}
}else{
g_print("Failed in if(sample).***\n");
}
buffer = gst_sample_get_buffer (sample);
timestamp = GST_BUFFER_PTS(buffer);
cout << "\n===timestamp is: " << timestamp << endl;
cout << endl << "GST_BUFFER_PTS_IS_VALID(buffer) is: " << GST_BUFFER_PTS_IS_VALID(buffer) << endl;
// Mapping a buffer
if (gst_buffer_map(buffer,&map,GST_MAP_READ)){
Q1.EnQueue(map.data);
++numOfEnqueue;
g_print("---numOfQueue is: %d.---\n\n\n",numOfEnqueue);
} else g_print("failed in gst_buffer_map.***\n");
//we don't need the appsink sample anymore
gst_sample_unref (sample);
return GST_FLOW_OK;
}
Solution 1:[1]
You probably solved that problem in the meantime, but just out of curiosity, would setting timestamp like the following help?
GST_BUFFER_TIMESTAMP(buffer) = 100;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tomaszmi |
