==>
//新建消息msg,消息名为'accu',消息处理者为this,也即MyHandler
//该消息的引用最终会传递到ARTPConnection的容器mStreams的元素的mNotifyMsg域里
//该消息被用来通知成功接收到了一个accessUnit即一帧数据
sp<AMessage> notify = new AMessage('accu', this);
notify->setSize("track-index", trackIndex);
==>
mRTPConn->addStream(track->mRTPSocket, track->mRTCPSocket,
mSessionDesc, index,
notify, track->mUsingInterleavedTCP,
mConn->isIPV6());
==>
void ARTPConnection::addStream(
int rtpSocket, int rtcpSocket,
const sp<ASessionDescription> &sessionDesc,
size_t index,
const sp<AMessage> ¬ify,
bool injected,
bool isIPV6) {
//新建消息msg
//消息名为kWhatAddStream,消息处理者为this,也即ARTPConnection
sp<AMessage> msg = new AMessage(kWhatAddStream, this);
//将rtpSocket的值添加到"rtp-socket"字段
//将rtcpSocket的值添加到"rtcp-socket"字段
//将sessionDesc对象添加到"session-desc"字段
//将index添加到"index"字段
//将injected的值添加到"injected"字段
//将"isIPV6"值添加到"isIPV6"字段
msg->setInt32("rtp-socket", rtpSocket);
msg->setInt32("rtcp-socket", rtcpSocket);
msg->setObject("session-desc", sessionDesc);
msg->setSize("index", index);
msg->setMessage("notify", notify);
//injected的值为false
msg->setInt32("injected", injected);
msg->setInt32("isIPV6", isIPV6);
msg->post();
}
==>
void ARTPConnection::onMessageReceived(const sp<AMessage> &msg) {
switch (msg->what()) {
case kWhatAddStream:
{
//调用onAddStream(msg)函数对该消息进行处理
onAddStream(msg);
break;
}
case kWhatRemoveStream:
{
onRemoveStream(msg);
break;
}
case kWhatPollStreams:
{
onPollStreams();
break;
}
case kWhatInjectPacket:
{
onInjectPacket(msg);
break;
}
default:
{
TRESPASS();
break;
}
}
}
==>
void ARTPConnection::onAddStream(const sp<AMessage> &msg) {
//向mStreams添加一个类型为StreamInfo的元素
mStreams.push_back(StreamInfo());
StreamInfo *info = &*--mStreams.end();
//从消息msg的"rtp-socket"字段得到的值赋值给info->mRTPSocket
//从消息msg的"rtcp-socket"字段得到的值赋值给info->mRTCPSocket
int32_t s;
CHECK(msg->findInt32("rtp-socket", &s));
info->mRTPSocket = s;
CHECK(msg->findInt32("rtcp-socket", &s));
info->mRTCPSocket = s;
//从消息msg的字段"injected"得到的值赋值给info->mIsInjected
int32_t injected;
CHECK(msg->findInt32("injected", &injected));
info->mIsInjected = injected;
//从消息msg的字段"session-desc"得到的会话描述对象的引用赋值给info->mSessionDesc
sp<RefBase> obj;
CHECK(msg->findObject("session-desc", &obj));
info->mSessionDesc = static_cast<ASessionDescription *>(obj.get());
//从消息msg的"index"字段得到的值赋值给info->mIndex
//从消息msg的"notify"的通知消息的引用赋值给info->mNotifyMsg
CHECK(msg->findSize("index", &info->mIndex));
CHECK(msg->findMessage("notify", &info->mNotifyMsg));
//将info->mNumRTCPPacketsReceived初始化为0,该值计数收到的RTCP包的数目
//将info->mNumRTPPacketsReceived的值初始化为0,该值计数收到的RTP包的数目
info->mNumRTCPPacketsReceived = 0;
info->mNumRTPPacketsReceived = 0;
//将info->mRemoteRTCPAddr的内存清零
memset(&info->mRemoteRTCPAddr, 0, sizeof(info->mRemoteRTCPAddr));
if (!injected) {
//调用postPollEvent()函数开始循环接收RTCP包和RTP包
postPollEvent();
}
}
ARTPConnection::addStream
最新推荐文章于 2018-12-10 17:02:00 发布