10

live555 接收rtsp视频流流程分析

 3 years ago
source link: https://blog.csdn.net/china_video_expert/article/details/70164114
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

live555 接收rtsp视频流流程分析

live555 接收rtsp视频流流程分析

RTSP交互流程

C表示RTSP客户端,S表示RTSP服务端

① C->S: OPTIONrequest         //询问S有哪些方法可用

S->C: OPTION response      //S回应信息中包括提供的所有可用方法

② C->S: DESCRIBErequest     //要求得到S提供的媒体初始化描述信息

S->C: DESCRIBE response    //S回应媒体初始化描述信息,主要是sdp

③ C->S: SETUPrequest       //设置会话属性,以及传输模式,提醒S建立会话

S->C: SETUP response      //S建立会话,返回会话标识符及会话相关信息

④ C->S: PLAYrequest        //C请求播放

S->C: PLAY response       //S回应请求信息

S->C: 发送流媒体数据

⑤ C->S: TEARDOWNrequest    //C请求关闭会话

S->C: TEARDOWN response    //S回应请求

上述的过程是标准的RTSP流程,其中第3步和第4步是必需的。

OpenCore在执行完PLAYER_SET_DATASOURCE,prepare之后,执行PLAYER_INIT时,如果发现datasource是rtsp流,则进入rtsp模块。

OpenCore的RTSP模块实现在Pvrtsp_client_engine_node.cpp中,PVRTSPEngineNode::SendRtspDescribe()描述了连接建立过程中的状态变化过程。

需要注意的时,opencore在发出OPTION request后,并不会等着收response,而是直接发DESCRIBE request,然后才开始收OPTION response和DESCRIBE response。

Live555在RTSPServer.cpp中用RTSPServer::RTSPClientSession::incomingRequestHandler()来处理来自client端的request。

RTSP源码接收端使用样例:

//RtstClientTest.cpp

#include"stdafx.h"

#include"RtspRequest.h"

#include"Rtp.h"

RtspRequest g_RtspRequest;

int_tmain(int argc, _TCHAR* argv[])

  string url ="rtsp://192.168.1.1:554/aacAudioTest";

  string setupName ="aacAudioTest";

  INT rtpPort =8080;

  INT rtcpPort =rtpPort + 2;

  stringsdp;

  INT64sess;

 g_RtspRequest.Open(url.c_str(), "127.0.0.0", 0);

 g_RtspRequest.RequestOptions();

 g_RtspRequest.RequestDescribe(&sdp);

 g_RtspRequest.RequestSetup(setupName.c_str(), transportModeRtpUdp,rtpPort , rtcpPort , &sess);

 g_RtspRequest.RequestPlay();

  Rtp* pRtp = newRtp();

 pRtp->Open("127.0.0.0", rtpPort);

  PBYTE pBuffer =new BYTE[1024*1024*10];

  intiRead;

  INTpayloadType;

  WORDsequenceNumber;

  INT32timeStamp;

  INT32ssrc;

 while(TRUE)

     iRead = pRtp->Read(pBuffer, 1024*1024*10,&payloadType, &sequenceNumber,&timeStamp, &ssrc);

     if (iRead > 0)

         // save buff   

  deletepRtp;

 g_RtspRequest.RequestPause();

 g_RtspRequest.RequestTeardown();

 g_RtspRequest.Close();

  delete[]pBuffer;

  return0;


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK