ARTPConnection::addStream

==>
//新建消息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> &notify,
        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();
    }
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值