首页 > 代码库 > rtsp 格式学习

rtsp 格式学习

问题:RTSP/1.0 405 Method Not Allowed

主要是在进行OPTIONS指令包封装的时候,通过wireshark抓包进行编写,

查看大致内容为Request: OPTIONS rtsp:://192.168.1.88 RTSP/1.0\r\n

Method: OPTIONS

URL: rtsp:://192.168.1.88

以为信息的开头是Request,实际上这是解析的语句

错误:

request_stream << "REQUEST: " <<"OPTIONS " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";

request_stream << "CSeq: " << "2\r\n";

request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";


正确:



问题:RTSP/1.0 404 Stream Not Found

主要是在进行DESCRIBE的时候没有填写获取的视频流信息

request_stream << "DESCRIBE " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";//right

request_stream << "DESCRIBE " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";//error



测试代码

#include <iostream>

#include <fstream>

#include <string>

#include <sstream>

#include <boost/asio.hpp>

#include "socket.h"


using namespace std;

using namespace boost::asio;


const char pszRtspServerIP[32] = "192.168.0.114";

short sRtspServerPort = 8554;


void WriteFile(char* buf);

{

ofstream ofs;

ofs.open("rtspoption.txt");

ofs << buf << endl;

ofs.close();

}



int HandleOptionCommand(ip::tcp::socket &sock)

{

boost::system::error_code ec;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "OPTIONS " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";

request_stream << "CSeq: " << "2\r\n";

request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";


boost::asio::write(sock, request);


char buf[1024] = { 0 };

size_t len = sock.read_some(buffer(buf), ec);

return 0;

}


int HanleDescribeCommand(ip::tcp::socket &sock)

{

boost::system::error_code ec;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "DESCRIBE " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";

request_stream << "CSeq: " << "3\r\n";

request_stream << "Accept: " << "application/sdp\r\n";

request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";


boost::asio::write(sock, request);


char buf[1024] = { 0 };

size_t len = sock.read_some(buffer(buf), ec);

//a=control:track1

return 0;

}


int HandleSetupCommand(ip::tcp::socket &sock)

{

boost::system::error_code ec;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "SETUP " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";

request_stream << "CSeq: " << "3\r\n";

request_stream << "Transport: " << "RTP/AVP/TCP;unicast;interleaved=0-1\r\n";

request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";


boost::asio::write(sock, request);


char buf[1024] = { 0 };

size_t len = sock.read_some(buffer(buf), ec);

return 0;


}


int main(int argc, char* argv[])

{

io_service iosev;

ip::tcp::socket socket(iosev);

ip::tcp::endpoint ep(ip::address_v4::from_string(pszRtspServerIP), sRtspServerPort);

boost::system::error_code ec;

socket.connect(ep, ec);

if (ec) return -1;


HandleOptionCommand(socket);

HanleDescribeCommand(socket);

HandleSetupCommand(socket);


return 0;

}



参考

http://www.cnblogs.com/lidabo/p/3701068.html


rtsp 格式学习