ZLMediaKit/src/RtpCodec/RtpMaker.h

109 lines
2.9 KiB
C
Raw Normal View History

2017-10-09 22:11:01 +08:00
/*
2017-09-27 16:20:30 +08:00
* MIT License
2017-04-01 16:35:56 +08:00
*
2017-09-27 16:20:30 +08:00
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* 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.
2017-04-01 16:35:56 +08:00
*/
#ifndef RTP_RTPMAKER_H_
#define RTP_RTPMAKER_H_
#include "Rtsp/RtspMediaSource.h"
2018-07-05 18:48:08 +08:00
#include "Rtsp/Rtsp.h"
2017-04-01 16:35:56 +08:00
#include "Util/logger.h"
2017-04-25 11:35:41 +08:00
#include "Util/RingBuffer.h"
2017-04-01 16:35:56 +08:00
#include "Util/TimeTicker.h"
2017-04-25 11:35:41 +08:00
#include "Util/ResourcePool.h"
#include "Thread/ThreadPool.h"
2017-04-01 16:35:56 +08:00
using namespace ZL::Util;
using namespace ZL::Thread;
namespace ZL {
namespace Rtsp {
class RtpMaker {
public:
typedef function<void(const RtpPacket::Ptr &pPkt, bool bKeyPos)> onGetRTP;
2018-09-18 23:49:48 +08:00
typedef std::shared_ptr<RtpMaker> Ptr;
2017-04-01 16:35:56 +08:00
RtpMaker(const onGetRTP &cb, uint32_t ui32Ssrc, int iMtuSize,int iSampleRate,
uint8_t ui8PlayloadType, uint8_t ui8Interleaved) {
callBack = cb;
2018-10-24 15:43:52 +08:00
_ui32Ssrc = ui32Ssrc;
_ui32SampleRate = iSampleRate;
_iMtuSize = iMtuSize;
_ui8PlayloadType = ui8PlayloadType;
_ui8Interleaved = ui8Interleaved;
_pktPool.setSize(64);
2017-04-01 16:35:56 +08:00
}
virtual ~RtpMaker() {
}
virtual void makeRtp(const char *pcData, int iDataLen, uint32_t uiStamp)=0;
int getInterleaved() const {
2018-10-24 15:43:52 +08:00
return _ui8Interleaved;
2017-04-01 16:35:56 +08:00
}
int getPlayloadType() const {
2018-10-24 15:43:52 +08:00
return _ui8PlayloadType;
2017-04-01 16:35:56 +08:00
}
int getSampleRate() const {
2018-10-24 15:43:52 +08:00
return _ui32SampleRate;
2017-04-01 16:35:56 +08:00
}
uint32_t getSsrc() const {
2018-10-24 15:43:52 +08:00
return _ui32Ssrc;
2017-04-01 16:35:56 +08:00
}
uint16_t getSeqence() const {
2018-10-24 15:43:52 +08:00
return _ui16Sequence;
2017-04-01 16:35:56 +08:00
}
uint32_t getTimestamp() const {
2018-10-24 15:43:52 +08:00
return _ui32TimeStamp;
2017-04-01 16:35:56 +08:00
}
protected:
2018-10-24 15:43:52 +08:00
uint32_t _ui32Ssrc;
uint32_t _ui32SampleRate;
int _iMtuSize;
uint8_t _ui8PlayloadType;
uint8_t _ui8Interleaved;
uint16_t _ui16Sequence = 0;
uint32_t _ui32TimeStamp = 0;
2017-04-01 16:35:56 +08:00
virtual void onMakeRtp(const RtpPacket::Ptr &pkt, bool bKeyPos = true) {
callBack(pkt, bKeyPos);
}
inline RtpPacket::Ptr obtainPkt() {
2018-10-24 15:43:52 +08:00
return _pktPool.obtain();
2017-04-01 16:35:56 +08:00
}
private:
2018-10-24 15:43:52 +08:00
RtspMediaSource::PoolType _pktPool;
2017-04-01 16:35:56 +08:00
onGetRTP callBack;
};
} /* namespace RTP */
} /* namespace ZL */
#endif /* RTP_RTPMAKER_H_ */