ZLMediaKit/src/Rtsp/RtpReceiver.h

91 lines
2.9 KiB
C++
Raw Normal View History

2018-12-14 17:46:12 +08:00
/*
* MIT License
*
2019-05-08 15:40:07 +08:00
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
2018-12-14 17:46:12 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ZLMEDIAKIT_RTPRECEIVER_H
#define ZLMEDIAKIT_RTPRECEIVER_H
2018-12-14 18:13:05 +08:00
#include <map>
2018-12-14 17:46:12 +08:00
#include <string>
#include <memory>
2019-06-28 17:30:13 +08:00
#include "RtpCodec.h"
2018-12-14 17:46:12 +08:00
#include "RtspMediaSource.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
class RtpReceiver {
public:
RtpReceiver();
virtual ~RtpReceiver();
protected:
/**
* rtp包
2019-06-24 16:56:46 +08:00
* @param track_index track下标索引
2018-12-14 17:46:12 +08:00
* @param track sdp track相关信息
2019-06-24 16:56:46 +08:00
* @param rtp_raw_ptr rtp数据指针
* @param rtp_raw_len rtp数据指针长度
2018-12-14 17:46:12 +08:00
* @return true
*/
2019-06-24 16:56:46 +08:00
bool handleOneRtp(int track_index,SdpTrack::Ptr &track, unsigned char *rtp_raw_ptr, unsigned int rtp_raw_len);
2018-12-14 17:46:12 +08:00
/**
* rtp数据包排序后输出
2019-06-24 17:01:15 +08:00
* @param rtp rtp数据包
* @param track_index track索引
2018-12-14 17:46:12 +08:00
*/
2019-06-24 17:01:15 +08:00
virtual void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index){}
2018-12-14 17:46:12 +08:00
void clear();
void setPoolSize(int size);
2019-06-24 17:01:15 +08:00
int getJitterSize(int track_index);
int getCycleCount(int track_index);
2018-12-14 17:46:12 +08:00
private:
2019-06-24 16:56:46 +08:00
void sortRtp(const RtpPacket::Ptr &rtp , int track_index);
private:
//ssrc不匹配计数
uint32_t _ssrc_err_count[2] = { 0, 0 };
//上次seq
uint16_t _last_seq[2] = { 0 , 0 };
//seq连续次数计数
uint32_t _seq_ok_count[2] = { 0 , 0};
//seq回环次数计数
uint32_t _seq_cycle_count[2] = { 0 , 0};
//是否开始seq排序
bool _sort_started[2] = { 0 , 0};
//rtp排序缓存根据seq排序
map<uint16_t , RtpPacket::Ptr> _rtp_sort_cache_map[2];
//rtp循环池
RtspMediaSource::PoolType _rtp_pool;
2018-12-14 17:46:12 +08:00
};
}//namespace mediakit
#endif //ZLMEDIAKIT_RTPRECEIVER_H