This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: TDA4VM:Unable to use gst-rtsp-server to send H264 stream

Part Number: TDA4VM

Tool/software:

Here is my code,I set the H264 compressed data for each frame by calling the 【SendFrameData_H264】 function,bug the client Unable to Parsing data。

Is it my 【mysrc】 assignment error? or 【gst_rtsp_media_factory_det_launch】error?

ps:my H264 data able to Parse when i send by 【udpsink】.

void CFrameDataTransmitter::CreateTransmitH264_rtsp_Server()
{
std::unique_lock<std::mutex> lock(m_TransmitMutex);

m_pthread = new std::thread([this]{
GstRTSPServer *server = gst_rtsp_server_new();
gst_rtsp_server_set_service(server, std::to_string(m_ulPort).c_str());
GstRTSPMountPoints *mounts = gst_rtsp_server_get_mount_points(server);
GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();

gst_rtsp_media_factory_set_launch(factory, "( appsrc name=mysrc ! queue ! rtph264pay name=pay0 pt=96 )");
g_signal_connect(factory, "media-configure", (GCallback)media_configure, this);
gst_rtsp_mount_points_add_factory(mounts, "/test", factory);
g_object_unref(mounts);
gst_rtsp_server_attach(server, NULL);
g_print ("stream ready at rtsp://127.0.0.1:%lu/test\n", m_ulPort);
// 进入主循环
this->m_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(this->m_loop);
});
return;
}

void CFrameDataTransmitter::media_configure(GstRTSPMediaFactory *factory, GstRTSPMedia *media, gpointer user_data)
{
if(nullptr == user_data || nullptr == factory || nullptr == media){
return;
}
CFrameDataTransmitter* pDataTransmitter = (CFrameDataTransmitter*)user_data;
if(nullptr == pDataTransmitter){
return;
}
std::unique_lock<std::mutex> lock(pDataTransmitter->m_TransmitMutex);
GstElement *element = gst_rtsp_media_get_element(media);
pDataTransmitter->m_pTransmitSource = gst_bin_get_by_name_recurse_up(GST_BIN(element), "mysrc");
g_object_set(pDataTransmitter->m_pTransmitSource, "format", GST_FORMAT_TIME, "is-live", TRUE, NULL);
GstCaps *caps1 = gst_caps_new_simple("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "nal",
NULL);
g_object_set(pDataTransmitter->m_pTransmitSource, "caps", caps1, NULL);
gst_caps_unref(caps1);
g_print ("CFrameDataTransmitter::media_configure end!\n");
gst_object_unref(element);
}
void CFrameDataTransmitter::SendFrameData_H264(const std::vector<Frame_Value> &values)
{
std::unique_lock<std::mutex> lock(m_TransmitMutex);

if(nullptr != m_pTransmitSource){
for(std::vector<Frame_Value>::const_iterator Iter = values.begin(); Iter != values.end(); Iter++){
if(Iter->isValid){
// printf("CFrameDataTransmitter::SendFrameData_H264 data size:%lu\n", Iter->datasize);
GstBuffer *buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, (void*)(Iter->data), Iter->datasize, 0, Iter->datasize, NULL, NULL);
gst_app_src_push_buffer(GST_APP_SRC(m_pTransmitSource), buffer);
}
}
}
}