在使用gst-rtsp-server开发rtsp 服务器时,有时候在服务端收到DESCRIBE命令之后,返回给客户端的sdp,需要进行定制。
但是,gst-rtsp-server并没有在发送sdp给客户端之前,给上层应用更改sdp信息的接口。
怎么办呢?
我们先看看gst-rtsp-server的源码中,从收到客户端的命令请求,到最终发送出去sdp信息,到底是怎么做的。
下面以gst-rtsp-server-1.10.5版本为例,其它更高版本实现差异并不大。
源码中如何发送sdp
gst-rtsp-server监听以后,每一个客户端连接上来,会挂接一个GstRTSPClient。
对这个GstRtspClient的挂接过程如下:
guint
gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
{
GstRTSPClientPrivate *priv;
guint res;
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
priv = client->priv;
g_return_val_if_fail (priv->connection != NULL, 0);
g_return_val_if_fail (priv->watch == NULL, 0);
/* make sure noone will free the context before the watch is destroyed */
priv->watch_context = g_main_context_ref (context);
/* create watch for the connection and attach */
priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
g_object_ref (client), (GDestroyNotify) client_watch_notify);
gst_rtsp_client_set_send_func (client, do_send_message, priv->watch,
(GDestroyNotify) gst_rtsp_watch_unref);
gst_rtsp_watch_set_send_backlog (priv->watch, 0, WATCH_BACKLOG_SIZE);
GST_INFO ("client %p: attaching to context %p", client, context);
res = gst_rtsp_watch_attach (priv->watch, context);
return res;
}
我们看到,在这个GstRTSPClient的Connection上,加了一个回调函数结构watch_funcs。
watch_funcs