经常用到将appsrc中填充数据后,以rtsp流的形式推出。和rtmp不同的是,rtmp需要用ngnix做为server,而rtsp就是通过代码自己搭建一个server,代码如下
static int need_data_rtsp (GstElement * appsrc, guint unused, data * ptr)
{
if(*(ptr->Stop))
{
cout<<"stop pushing"<<endl;
return 0;
}
GstBuffer *buffer;
guint size;
GstFlowReturn ret =GST_FLOW_OK;
size = (ptr->Input->size().width) * (ptr->Input->size().height) * 3;
buffer = gst_buffer_new_allocate (NULL, size, NULL);
GstMapInfo map;
gst_buffer_map(buffer,&map,GST_MAP_READ);
ptr->Mux->lock();
memcpy(map.data,ptr->Input->data,size);
ptr->Mux->unlock();
guint64 s = ( getTickCount() - ptr->t) * GST_SECOND / getTickFrequency();
ptr->t = getTickCount();
GST_BUFFER_PTS (buffer) = ptr->Timestamp;
GST_BUFFER_DURATION (buffer) = s;
ptr->Timestamp += GST_BUFFER_DURATION (buffer) ;
g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);
gst_buffer_unmap(buffer,&map);
std::cout<<"pushing"<<std::endl;
gst_buffer_unref (buffer);
if ( *(ptr->Stop) ) {
/* somet