⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtcpreceiver.cpp

📁 symbian平台S60_2nd_FP2_SC rtp实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  //  cerr << "  NTP time: " << ntohl(p->ntpTimeSec) << " ";
//    cerr << ntohl(p->ntpTimeFrac) << endl;
//    cerr << "  RTP time: " << ntohl(p->rtpTime) << endl;
//    cerr << "  Packets sent: " << ntohl(p->packetCount);
 //   cerr << "    Payload sent: " << ntohl(p->octetCount) << endl;
}


void RtcpReceiver::printRR (RtcpReport* p)
{
//    cerr << "Got RR for " << ntohl(p->ssrc) << endl;
//    cerr << "  Lost Frac: " << p->fracLost;
    u_int32_t lost = (p->cumLost[0] << 16) | (p->cumLost[1] << 8) | p->cumLost[2];
    lost = lost & (0xffffff);
//    cerr << "  Lost count: " << lost;
 //   cerr << "  Cycles: " << ntohs(p->recvCycles);
 //   cerr << "  Last seq: " << ntohs(p->lastSeqRecv) << endl;
 //   cerr << "  Jitter: " << ntohl(p->jitter) << "  ";
 //   cerr << "Last SR: " << ntohl(p->lastSRDelay) << endl;
}



/* --- Read SDES packet -------------------------------------------- */

int RtcpReceiver::readSDES (RtcpPacket* p)
{
    RtcpHeader* head = findRTCP (p, rtcpTypeSDES);
    if (head == NULL) return -1;

    readSDES (head);

    // read next SDES packet if found
    // future: - ?

    return 0;
}


void RtcpReceiver::readSDES (RtcpHeader* head)
{
    char* begin = reinterpret_cast < char* > ((char*)head + sizeof(RtcpHeader));
    RtcpChunk* middle = reinterpret_cast < RtcpChunk* > (begin);

    RtcpSDESItem* item = NULL;
    RtcpSDESItem* nextitem = NULL;
    RtpSrc ssrc;

    for (int i = head->count; i > 0; i--)
    {
        ssrc = ntohl(middle->ssrc);

        for (item = &(middle->startOfItem); item->type; item = nextitem)
        {
            addSDESItem(ssrc, item);
            nextitem = reinterpret_cast < RtcpSDESItem* >
                       ((char*)item + sizeof(RtcpSDESItem) - 1 + item->length);
        }

        middle = reinterpret_cast < RtcpChunk* > (item);
    }
}



void RtcpReceiver::addSDESItem (RtpSrc src, RtcpSDESItem* item)
{
    RtpTranInfo* s = findTranInfo(src);

    switch (item->type)
    {
        case rtcpSdesCname:
        strncpy ((s->SDESInfo).cname, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesName:
        strncpy ((s->SDESInfo).name, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesEmail:
        strncpy ((s->SDESInfo).email, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesPhone:
        strncpy ((s->SDESInfo).phone, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesLoc:
        strncpy ((s->SDESInfo).loc, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesTool:
        strncpy ((s->SDESInfo).tool, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesNote:
        strncpy ((s->SDESInfo).note, &(item->startOfText), item->length + 1);
        break;
        case rtcpSdesPriv:
        // future: not implemented
        default:
        cpLog (LOG_ERR, "RtcpReceiver: SDES type unknown");
        break;
    }

    /*
    // - debug
    cerr <<"Update "<<src<<" with "<< (int) item->type <<" "<< (int) item->length;
    char output [255];
    memset (output, 0, 255);
    strncpy (output, &(item->startOfText), item->length+1);
    cerr << endl <<output<<endl;
    cerr <<"_SDES_";
    */
}



/* --- Read BYE packet --------------------------------------------- */

int RtcpReceiver::readBYE (RtcpPacket* p)
{
    RtcpHeader* head = findRTCP (p, rtcpTypeBYE);
    if (head == NULL) return -1;

    readBYE (head);

    // read next BYE packet if found
    // future: - ?

    return 0;
}


int RtcpReceiver::readBYE (RtcpHeader* head)
{

    //    char* end = reinterpret_cast<char*>
    //                ((char*)head + sizeof(RtpSrc) * (ntohs(head->length) + 1));
    RtpSrc* src = reinterpret_cast < RtpSrc* >
                  ((char*)head + sizeof(RtcpHeader));


    for (int i = head->count; i > 0; i--)
    {
        cpLog( LOG_DEBUG_STACK, "readRtcpBye for %d", ntohl(*src) );
        //       cerr << "readRtcpBye for " << ntohl(*src) << endl;
        removeTranInfo (ntohl(*src++));
    }

    return 0;

    //TODO Convert this to cpLog if necessary
#if 0
    // print reason
    char* middle = reinterpret_cast < char* > (src);
    //    if (middle != end)
    {
        RtcpBye* reason = reinterpret_cast < RtcpBye* > (middle);
        cerr << "   Reason: ";    // - debug
        cerr.write(&(reason->startOfText), (int) reason->length);    // - debug
        cerr << endl;    // - debug
    }
    //cerr <<"_BYE_";  // - debug

#endif
}



/* --- Read APP packet --------------------------------------------- */

int RtcpReceiver::readAPP (RtcpPacket* p)
{
    RtcpHeader* head = findRTCP (p, rtcpTypeAPP);
    if (head == NULL) return -1;

    readAPP (head);

    // read next APP packet if found
    // future: - ?

    return 0;
}


void RtcpReceiver::readAPP (RtcpHeader* head)
{
    // future: not implemented
    assert (0);
}



/* --- known transmitter list functions ---------------------------- */

RtpTranInfo* RtcpReceiver::addTranInfo (RtpSrc src, RtpReceiver* recv)
{

    //    cout << "adding: " << src << endl;

    if (recv) assert (src == recv->ssrc);

    RtpTranInfo* s = new RtpTranInfo;
    s->recv = recv;
    s->ssrc = src;
    s->expectedPrior = 0;
    s->receivedPrior = 0;

    //    cout << "adding ptr: " << s << endl;

    if (addTranFinal (s))
    {
        delete s;  // - ?
        s = findTranInfo (src);
        assert (s->recv == NULL);  // - ?
        s->recv = recv;
    }
    return s;
}


int RtcpReceiver::addTranFinal (RtpTranInfo* s)
{
    // add transmitter to listing
//    pair < map < RtpSrc, RtpTranInfo* > ::iterator, bool > result =
//        tranInfoList.insert (pair < RtpSrc, RtpTranInfo* >
//                             (s->ssrc, s));
//    if (!result.second)
//    {
//        //transmitter already in listing
//        return 1;
//    }

	RtpSrc assrs = s->ssrc;
	for ( TInt i =0; i< tranInfoList.Count(); i++)
	{
		if( assrs == tranInfoList[i]->iSRC)
			return 1;
	}
	RTPTran *aTran = new (ELeave)RTPTran;
	aTran->iSRC = s->ssrc;
	aTran->iTranInfo = s;
	tranInfoList.Append(aTran);
    //cpLog (LOG_DEBUG_STACK, "RTCP: Transmitter add: %d", s->ssrc);
    return 0;
}



int RtcpReceiver::removeTranInfo (RtpSrc src, int flag)
{
    //    cout << "RTCP: removing: " << src << endl;

//    map < RtpSrc, RtpTranInfo* > ::iterator p = tranInfoList.find(src);
//    if (p == tranInfoList.end())
//    {
//        // src not found
//        assert (0);
//    }
//
//    RtpTranInfo* info = p->second;

	RTPTran *aTran = NULL;
	RtpTranInfo* info =  NULL;
	TInt  nIndex = 0;
	for( nIndex ;nIndex<tranInfoList.Count() ;nIndex ++)
	{
		if( src == tranInfoList[nIndex]->iSRC)
		{
			info = tranInfoList[nIndex]->iTranInfo;
			aTran = tranInfoList[nIndex];
		}
	}

    //    cout << "RTCP: removing ptr: " << info << endl;

    // remove from RTP stack
    if (info->recv && !flag)
        (info->recv)->removeSource(info->ssrc, 1);
    info->recv = NULL;
    delete info; 
	info = NULL;

    //    cout << "RTCP: done removing\n";

    // remove from receiver list
 //   tranInfoList.erase (p);
	if(nIndex >0)
		tranInfoList.Remove(nIndex);

    //cpLog (LOG_DEBUG_STACK, "RTCP: Transmitter removed: %d", src);
    return 0;
}



RtpTranInfo* RtcpReceiver::findTranInfo (RtpSrc src)
{
    RtpTranInfo* info = NULL;

//    map < RtpSrc, RtpTranInfo* > ::iterator p = tranInfoList.find(src);
//    if (p == tranInfoList.end())
//        // receiver not found, so add it
//        info = addTranInfo(src);
//    else
//        info = p->second;

	for( TInt i=0 ;i<tranInfoList.Count(); i++)
	{
		if( src == tranInfoList[i]->iSRC)
			info = tranInfoList[i]->iTranInfo;
	}
    return info;
}


RtpTranInfo* RtcpReceiver::getTranInfoList (int index)
{
    assert (index >= 0);
    assert (index < getTranInfoCount());

//    map < RtpSrc, RtpTranInfo* > ::iterator p = tranInfoList.begin();
//    for (int i = 0; i < index; i++)
//        ++p;
//
//    assert (p != tranInfoList.end());
//    return p->second;

	RtpTranInfo* aInfo =  tranInfoList[index]->iTranInfo;
	assert(aInfo);
	return aInfo;
}


int RtcpReceiver::getTranInfoCount()
{
  //  return tranInfoList.size();
	return tranInfoList.Count();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -