RtpReceiver.h 2.15 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
xiongziliang committed
9 10 11 12 13 14
 */

#ifndef ZLMEDIAKIT_RTPRECEIVER_H
#define ZLMEDIAKIT_RTPRECEIVER_H


xiongziliang committed
15
#include <map>
xiongziliang committed
16 17
#include <string>
#include <memory>
xiongziliang committed
18
#include "RtpCodec.h"
xiongziliang committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include "RtspMediaSource.h"

using namespace std;
using namespace toolkit;

namespace mediakit {

class RtpReceiver {
public:
    RtpReceiver();
    virtual ~RtpReceiver();
protected:

    /**
     * 输入数据指针生成并排序rtp包
34
     * @param track_index track下标索引
xiongziliang committed
35 36
     * @param type track类型
     * @param samplerate rtp时间戳基准时钟,视频为90000,音频为采样率
37 38
     * @param rtp_raw_ptr rtp数据指针
     * @param rtp_raw_len rtp数据指针长度
xiongziliang committed
39 40
     * @return 解析成功返回true
     */
xiongziliang committed
41
    bool handleOneRtp(int track_index, TrackType type, int samplerate, unsigned char *rtp_raw_ptr, unsigned int rtp_raw_len);
xiongziliang committed
42 43 44

    /**
     * rtp数据包排序后输出
xiongziliang committed
45 46
     * @param rtp rtp数据包
     * @param track_index track索引
xiongziliang committed
47
     */
xiongziliang committed
48
    virtual void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index){}
xiongziliang committed
49 50
    void clear();
    void setPoolSize(int size);
xiongziliang committed
51 52
    int getJitterSize(int track_index);
    int getCycleCount(int track_index);
xiongziliang committed
53

xiongziliang committed
54
private:
55
    void sortRtp(const RtpPacket::Ptr &rtp , int track_index);
xiongziliang committed
56

57
private:
xiongziliang committed
58
    uint32_t _ssrc[2] = { 0, 0 };
59 60 61 62 63 64 65 66 67 68 69 70 71 72
    //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;
xiongziliang committed
73 74 75 76 77 78
};

}//namespace mediakit


#endif //ZLMEDIAKIT_RTPRECEIVER_H