2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
2019-05-08 15:40:07 +08:00
|
|
|
|
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
|
2018-10-25 10:00:17 +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.
|
|
|
|
|
*/
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_RTPCODEC_H
|
|
|
|
|
#define ZLMEDIAKIT_RTPCODEC_H
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include "Util/RingBuffer.h"
|
|
|
|
|
#include "Player/PlayerBase.h"
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit{
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
class RtpRingInterface {
|
|
|
|
|
public:
|
|
|
|
|
typedef RingBuffer<RtpPacket::Ptr> RingType;
|
2018-10-23 18:39:17 +08:00
|
|
|
|
typedef std::shared_ptr<RtpRingInterface> Ptr;
|
2018-10-23 11:09:21 +08:00
|
|
|
|
|
|
|
|
|
RtpRingInterface(){}
|
|
|
|
|
virtual ~RtpRingInterface(){}
|
2018-10-23 18:39:17 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取rtp环形缓存
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2018-10-23 11:09:21 +08:00
|
|
|
|
virtual RingType::Ptr getRtpRing() const = 0;
|
2018-10-23 18:39:17 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置rtp环形缓存
|
|
|
|
|
* @param ring
|
|
|
|
|
*/
|
2018-10-23 11:09:21 +08:00
|
|
|
|
virtual void setRtpRing(const RingType::Ptr &ring) = 0;
|
2018-10-23 18:39:17 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入rtp包
|
|
|
|
|
* @param rtp rtp包
|
|
|
|
|
* @param key_pos 是否为关键帧第一个rtp包
|
|
|
|
|
* @return 是否为关键帧第一个rtp包
|
|
|
|
|
*/
|
|
|
|
|
virtual bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) = 0;
|
2018-10-23 11:09:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RtpRing : public RtpRingInterface {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<RtpRing> Ptr;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
RtpRing(){
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
2018-10-23 11:09:21 +08:00
|
|
|
|
virtual ~RtpRing(){}
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
RingType::Ptr getRtpRing() const override {
|
2018-10-18 23:48:00 +08:00
|
|
|
|
return _rtpRing;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
void setRtpRing(const RingType::Ptr &ring) override {
|
|
|
|
|
_rtpRing = ring;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
2018-10-23 11:09:21 +08:00
|
|
|
|
|
2018-10-23 18:39:17 +08:00
|
|
|
|
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) override{
|
2018-10-25 11:53:45 +08:00
|
|
|
|
if(_rtpRing){
|
|
|
|
|
_rtpRing->write(rtp,key_pos);
|
|
|
|
|
}
|
2018-10-23 18:39:17 +08:00
|
|
|
|
return key_pos;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
2018-10-23 11:09:21 +08:00
|
|
|
|
protected:
|
|
|
|
|
RingType::Ptr _rtpRing;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-10-31 09:36:12 +08:00
|
|
|
|
class RtpInfo : public ResourcePoolHelper<RtpPacket>{
|
2018-10-18 23:48:00 +08:00
|
|
|
|
public:
|
2018-10-21 21:45:44 +08:00
|
|
|
|
typedef std::shared_ptr<RtpInfo> Ptr;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-21 21:45:44 +08:00
|
|
|
|
RtpInfo(uint32_t ui32Ssrc,
|
2018-10-23 11:38:56 +08:00
|
|
|
|
uint32_t ui32MtuSize,
|
|
|
|
|
uint32_t ui32SampleRate,
|
|
|
|
|
uint8_t ui8PlayloadType,
|
|
|
|
|
uint8_t ui8Interleaved) {
|
|
|
|
|
if(ui32Ssrc == 0){
|
|
|
|
|
ui32Ssrc = ((uint64_t)this) & 0xFFFFFFFF;
|
|
|
|
|
}
|
2018-10-24 15:43:52 +08:00
|
|
|
|
_ui32Ssrc = ui32Ssrc;
|
|
|
|
|
_ui32SampleRate = ui32SampleRate;
|
|
|
|
|
_ui32MtuSize = ui32MtuSize;
|
|
|
|
|
_ui8PlayloadType = ui8PlayloadType;
|
|
|
|
|
_ui8Interleaved = ui8Interleaved;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-21 21:45:44 +08:00
|
|
|
|
virtual ~RtpInfo(){}
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
int getInterleaved() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui8Interleaved;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getPlayloadType() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui8PlayloadType;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getSampleRate() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui32SampleRate;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t getSsrc() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui32Ssrc;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t getSeqence() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui16Sequence;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
uint32_t getTimestamp() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui32TimeStamp;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
uint32_t getMtuSize() const {
|
2018-10-24 15:43:52 +08:00
|
|
|
|
return _ui32MtuSize;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
}
|
2018-10-31 09:36:12 +08:00
|
|
|
|
RtpPacket::Ptr makeRtp(TrackType type,const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
2018-10-18 23:48:00 +08:00
|
|
|
|
protected:
|
2018-10-24 15:43:52 +08:00
|
|
|
|
uint32_t _ui32Ssrc;
|
|
|
|
|
uint32_t _ui32SampleRate;
|
|
|
|
|
uint32_t _ui32MtuSize;
|
|
|
|
|
uint8_t _ui8PlayloadType;
|
|
|
|
|
uint8_t _ui8Interleaved;
|
|
|
|
|
uint16_t _ui16Sequence = 0;
|
|
|
|
|
uint32_t _ui32TimeStamp = 0;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-31 09:36:12 +08:00
|
|
|
|
class RtpCodec : public RtpRing, public FrameRingInterfaceDelegate , public CodecInfo{
|
2018-10-23 11:09:21 +08:00
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<RtpCodec> Ptr;
|
|
|
|
|
RtpCodec(){}
|
|
|
|
|
virtual ~RtpCodec(){}
|
|
|
|
|
};
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-23 11:38:56 +08:00
|
|
|
|
|
2018-10-18 23:48:00 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_RTPCODEC_H
|