Beispiel #1
0
void RtspPlayer::onRecv(const Socket::Buffer::Ptr& pBuf) {
	const char *buf = pBuf->data();
	int size = pBuf->size();
	if (m_onHandshake) {
        int offset = 0;
        while(offset < size - 4){
            char *pos = (char *)memchr(buf + offset, 'R', size - offset);
            if(pos == NULL){
                break;
            }
            if(memcmp(pos, "RTSP", 4) == 0){
                try {
                    pos += onProcess(pos);
                } catch (std::exception &err) {
                    SockException ex(Err_other, err.what());
                    _onPlayResult(ex);
                    _onShutdown(ex);
                    teardown();
                    return;
                }
            }else{
                pos += 1;
            }
            offset = pos - buf;
        }
	}

	if (m_eType == RTP_TCP && m_pucRtpBuf) {
		//RTP data
		while (size > 0) {
			static uint32_t rtpSize = mINI::Instance()[Config::Rtp::kUdpBufSize].as<uint32_t>();
			int added = rtpSize - m_uiRtpBufLen;
			added = (added > size ? size : added);
			memcpy(m_pucRtpBuf + m_uiRtpBufLen, buf, added);
			m_uiRtpBufLen += added;
			size -= added;
			buf += added;
			splitRtp(m_pucRtpBuf, m_uiRtpBufLen);
		}
	}
}
	virtual void onRecv(const Socket::Buffer::Ptr &buf) override{
		//处理客户端发送过来的数据
		TraceL << buf->data();
		//把数据回显至客户端
		send(buf->data(),buf->size());
	}