2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_H264RTPCODEC_H
|
|
|
|
|
#define ZLMEDIAKIT_H264RTPCODEC_H
|
|
|
|
|
|
|
|
|
|
#include "RtpCodec.h"
|
2018-10-21 21:21:14 +08:00
|
|
|
|
#include "Util/ResourcePool.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
#include "Extension/H264.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-21 21:21:14 +08:00
|
|
|
|
|
2018-10-21 22:24:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* h264 rtp解码类
|
|
|
|
|
*/
|
2018-10-24 12:01:40 +08:00
|
|
|
|
class H264RtpDecoder : public RtpCodec , public ResourcePoolHelper<H264Frame> {
|
2018-10-18 23:48:00 +08:00
|
|
|
|
public:
|
2018-10-23 18:39:17 +08:00
|
|
|
|
typedef std::shared_ptr<H264RtpDecoder> Ptr;
|
|
|
|
|
|
2018-10-21 22:24:24 +08:00
|
|
|
|
H264RtpDecoder();
|
2018-10-21 21:45:44 +08:00
|
|
|
|
~H264RtpDecoder() {}
|
|
|
|
|
|
2018-10-21 22:24:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 输入264 rtp包
|
|
|
|
|
* @param rtp rtp包
|
|
|
|
|
* @param key_pos 此参数忽略之
|
|
|
|
|
*/
|
2018-10-23 18:39:17 +08:00
|
|
|
|
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override;
|
2018-10-23 11:09:21 +08:00
|
|
|
|
|
|
|
|
|
TrackType getTrackType() const override{
|
|
|
|
|
return TrackVideo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
return CodecH264;
|
|
|
|
|
}
|
2018-10-18 23:48:00 +08:00
|
|
|
|
private:
|
2018-10-21 22:24:24 +08:00
|
|
|
|
bool decodeRtp(const RtpPacket::Ptr &rtp);
|
2018-10-21 21:21:14 +08:00
|
|
|
|
void onGetH264(const H264Frame::Ptr &frame);
|
2018-10-21 22:24:24 +08:00
|
|
|
|
H264Frame::Ptr obtainFrame();
|
2018-10-18 23:48:00 +08:00
|
|
|
|
private:
|
2018-10-24 15:43:52 +08:00
|
|
|
|
H264Frame::Ptr _h264frame;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-21 22:24:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 264 rtp打包类
|
|
|
|
|
*/
|
2018-10-23 11:38:56 +08:00
|
|
|
|
class H264RtpEncoder : public H264RtpDecoder ,public RtpInfo{
|
2018-10-21 21:45:44 +08:00
|
|
|
|
public:
|
2018-10-23 18:39:17 +08:00
|
|
|
|
typedef std::shared_ptr<H264RtpEncoder> Ptr;
|
2018-10-21 22:24:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ui32Ssrc ssrc
|
|
|
|
|
* @param ui32MtuSize mtu大小
|
|
|
|
|
* @param ui32SampleRate 采样率,强制为90000
|
|
|
|
|
* @param ui8PlayloadType pt类型
|
|
|
|
|
* @param ui8Interleaved rtsp interleaved
|
|
|
|
|
*/
|
2018-10-21 21:45:44 +08:00
|
|
|
|
H264RtpEncoder(uint32_t ui32Ssrc,
|
|
|
|
|
uint32_t ui32MtuSize = 1400,
|
|
|
|
|
uint32_t ui32SampleRate = 90000,
|
|
|
|
|
uint8_t ui8PlayloadType = 96,
|
|
|
|
|
uint8_t ui8Interleaved = TrackVideo * 2);
|
|
|
|
|
~H264RtpEncoder() {}
|
|
|
|
|
|
2018-10-21 22:24:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 输入264帧
|
|
|
|
|
* @param frame 帧数据,必须
|
|
|
|
|
*/
|
2018-10-23 21:41:45 +08:00
|
|
|
|
void inputFrame(const Frame::Ptr &frame) override;
|
2018-10-21 21:45:44 +08:00
|
|
|
|
private:
|
2018-10-31 09:36:12 +08:00
|
|
|
|
void makeH264Rtp(int nal_type,const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
2018-10-21 21:45:44 +08:00
|
|
|
|
private:
|
2018-10-24 15:43:52 +08:00
|
|
|
|
unsigned char _aucSectionBuf[1600];
|
2018-10-21 21:45:44 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit{
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
#endif //ZLMEDIAKIT_H264RTPCODEC_H
|