参照openRTSP写的一个RTSP client 加了一些注解
来源:互联网 发布:结晶水含量的测定算法 编辑:程序博客网 时间:2024/05/22 09:49
#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#include "GroupsockHelper.hh"
UsageEnvironment* env;
portNumBits tunnelOverHTTPPortNum = 0;
const char * url="rtsp://127.0.0.1:1935/vod/Extremists.m4v";
#if defined(__WIN32__) || defined(_WIN32)
#define snprintf _snprintf
#endif
int main(int argc,const char ** argv)
{
//创建BasicTaskScheduler对象
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
//创建BisicUsageEnvironment对象
env = BasicUsageEnvironment::createNew(*scheduler);
//创建RTSPClient对象
RTSPClient * rtspClient= RTSPClient::createNew(*env);
//由RTSPClient对象向服务器发送OPTION消息并接受回应
char* optionsResponse=rtspClient->sendOptionsCmd(url);
delete [] optionsResponse;
//产生SDPDescription字符串(由RTSPClient对象向服务器发送DESCRIBE消息并接受回应,根据回应的信息产生SDPDescription字符串,其中包括视音频数据的协议和解码器类型)
char* sdpDescription =rtspClient->describeURL(url);
//创建MediaSession对象(根据SDPDescription在MediaSession中创建和初始化MediaSubSession子会话对象)
MediaSession* session = MediaSession::createNew(*env, sdpDescription);
delete[] sdpDescription;
/*
while循环中配置所有子会话对象
*/
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
while ((subsession = iter.next()) != NULL) {
// Creates a "RTPSource" for this subsession. (Has no effect if it's
// already been created.) Returns True iff this succeeds.
if (!subsession->initiate()) {
*env << "Unable to create receiver for /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession: " << env->getResultMsg() << "/n";
} else {
*env << "Created receiver for /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")/n";
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
// Set the RTP source's OS socket buffer size as appropriate - either if we were explicitly asked (using -B),
// or if the desired FileSink buffer size happens to be larger than the current OS socket buffer size.
// (The latter case is a heuristic, on the assumption that if the user asked for a large FileSink buffer size,
// then the input data rate may be large enough to justify increasing the OS socket buffer size also.)
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned curBufferSize = getReceiveBufferSize(*env, socketNum);
unsigned newBufferSize = setReceiveBufferTo(*env, socketNum, 100000);
}
}
}
//由RTSPClient对象向服务器发送SETUP消息并接受回应
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->clientPortNum() == 0) continue; // port # was not set
if (!rtspClient->setupMediaSubsession(*subsession)) {
*env << "Failed to setup /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession: " << env->getResultMsg() << "/n";
} else {
*env << "Setup /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")/n";
}
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
}
}
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->readSource() == NULL) continue; // was not initiated
char outFileName[1000];
static unsigned streamCounter = 0;
snprintf(outFileName, sizeof outFileName, "%s-%s-%d",
subsession->mediumName(),
subsession->codecName(), ++streamCounter);
FileSink* fileSink;
if (strcmp(subsession->mediumName(), "audio") == 0 &&
(strcmp(subsession->codecName(), "AMR") == 0 ||
strcmp(subsession->codecName(), "AMR-WB") == 0)) {
// For AMR audio streams, we use a special sink that inserts AMR frame hdrs:
fileSink = AMRAudioFileSink::createNew(*env, outFileName);
} else if (strcmp(subsession->mediumName(), "video") == 0 &&
(strcmp(subsession->codecName(), "H264") == 0)) {
// For H.264 video stream, we use a special sink that insert start_codes:
unsigned int num=0;
SPropRecord * sps=parseSPropParameterSets(subsession->fmtp_spropparametersets(),num);
fileSink = H264VideoFileSink::createNew(*env, outFileName,100000);
struct timeval tv={0,0};
unsigned char start_code[4] = {0x00, 0x00, 0x00, 0x01};
fileSink->addData(start_code, 4, tv);
fileSink->addData(sps[0].sPropBytes,sps[0].sPropLength,tv);
fileSink->addData(start_code, 4, tv);
fileSink->addData(sps[1].sPropBytes,sps[1].sPropLength,tv);
delete[] sps;
} else {
// Normal case:
fileSink = FileSink::createNew(*env, outFileName);
}
subsession->sink = fileSink;
subsession->sink->startPlaying(*(subsession->readSource()),NULL,NULL);
}
rtspClient->playMediaSession(*session, 0.0f, 0.0f, (float)1.0);
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}
#include "BasicUsageEnvironment.hh"
#include "GroupsockHelper.hh"
UsageEnvironment* env;
portNumBits tunnelOverHTTPPortNum = 0;
const char * url="rtsp://127.0.0.1:1935/vod/Extremists.m4v";
#if defined(__WIN32__) || defined(_WIN32)
#define snprintf _snprintf
#endif
int main(int argc,const char ** argv)
{
//创建BasicTaskScheduler对象
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
//创建BisicUsageEnvironment对象
env = BasicUsageEnvironment::createNew(*scheduler);
//创建RTSPClient对象
RTSPClient * rtspClient= RTSPClient::createNew(*env);
//由RTSPClient对象向服务器发送OPTION消息并接受回应
char* optionsResponse=rtspClient->sendOptionsCmd(url);
delete [] optionsResponse;
//产生SDPDescription字符串(由RTSPClient对象向服务器发送DESCRIBE消息并接受回应,根据回应的信息产生SDPDescription字符串,其中包括视音频数据的协议和解码器类型)
char* sdpDescription =rtspClient->describeURL(url);
//创建MediaSession对象(根据SDPDescription在MediaSession中创建和初始化MediaSubSession子会话对象)
MediaSession* session = MediaSession::createNew(*env, sdpDescription);
delete[] sdpDescription;
/*
while循环中配置所有子会话对象
*/
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
while ((subsession = iter.next()) != NULL) {
// Creates a "RTPSource" for this subsession. (Has no effect if it's
// already been created.) Returns True iff this succeeds.
if (!subsession->initiate()) {
*env << "Unable to create receiver for /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession: " << env->getResultMsg() << "/n";
} else {
*env << "Created receiver for /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")/n";
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
// Set the RTP source's OS socket buffer size as appropriate - either if we were explicitly asked (using -B),
// or if the desired FileSink buffer size happens to be larger than the current OS socket buffer size.
// (The latter case is a heuristic, on the assumption that if the user asked for a large FileSink buffer size,
// then the input data rate may be large enough to justify increasing the OS socket buffer size also.)
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned curBufferSize = getReceiveBufferSize(*env, socketNum);
unsigned newBufferSize = setReceiveBufferTo(*env, socketNum, 100000);
}
}
}
//由RTSPClient对象向服务器发送SETUP消息并接受回应
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->clientPortNum() == 0) continue; // port # was not set
if (!rtspClient->setupMediaSubsession(*subsession)) {
*env << "Failed to setup /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession: " << env->getResultMsg() << "/n";
} else {
*env << "Setup /"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "/" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")/n";
}
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
}
}
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->readSource() == NULL) continue; // was not initiated
char outFileName[1000];
static unsigned streamCounter = 0;
snprintf(outFileName, sizeof outFileName, "%s-%s-%d",
subsession->mediumName(),
subsession->codecName(), ++streamCounter);
FileSink* fileSink;
if (strcmp(subsession->mediumName(), "audio") == 0 &&
(strcmp(subsession->codecName(), "AMR") == 0 ||
strcmp(subsession->codecName(), "AMR-WB") == 0)) {
// For AMR audio streams, we use a special sink that inserts AMR frame hdrs:
fileSink = AMRAudioFileSink::createNew(*env, outFileName);
} else if (strcmp(subsession->mediumName(), "video") == 0 &&
(strcmp(subsession->codecName(), "H264") == 0)) {
// For H.264 video stream, we use a special sink that insert start_codes:
unsigned int num=0;
SPropRecord * sps=parseSPropParameterSets(subsession->fmtp_spropparametersets(),num);
fileSink = H264VideoFileSink::createNew(*env, outFileName,100000);
struct timeval tv={0,0};
unsigned char start_code[4] = {0x00, 0x00, 0x00, 0x01};
fileSink->addData(start_code, 4, tv);
fileSink->addData(sps[0].sPropBytes,sps[0].sPropLength,tv);
fileSink->addData(start_code, 4, tv);
fileSink->addData(sps[1].sPropBytes,sps[1].sPropLength,tv);
delete[] sps;
} else {
// Normal case:
fileSink = FileSink::createNew(*env, outFileName);
}
subsession->sink = fileSink;
subsession->sink->startPlaying(*(subsession->readSource()),NULL,NULL);
}
rtspClient->playMediaSession(*session, 0.0f, 0.0f, (float)1.0);
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}
0 0
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client 加了一些注解
- 参照openRTSP写的一个RTSP client
- 简单完整的一个 rtsp 交互过程 live555-openRTSP
- 参照网上自己写了一个Ajax.js文件
- 参照jquery_pagination写的一个生成html的类
- [RTSP]live555-openRTSP客户端流程
- 双色表格CSS实例,在网上找的,不过我加了一些注解
- 写了一个android上使用的基于http client的通信库
- RTSP协议,这个写的不错,赚了
- RTSP协议,这个写的不错,赚了
- 从头写一个rtsp服务器
- 写了一个自动加链接的工具, 关于SEO的,测试一下效果
- UNREFERENCED_PARAMETER(arg);的作用
- datetimepicker position位置问题bug修复
- android实现类似于支付宝余额快速闪动的效果
- 查询oracle约束所关联的表
- Core Animation
- 参照openRTSP写的一个RTSP client 加了一些注解
- OJ 45之分数求和
- Ubuntu12.04 adb无法连接手机
- git提交到github
- OC中私有变量的定义方式
- Lumia 920 升级失败 更新已下载 但无法打开 8018830f 的解决方案
- 页面遮罩
- TWaver GIS制作穹顶之下的雾霾地图
- Hadoop-2.3.0-cdh5.0.1分布式环境搭建