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-24 12:01:40 +08:00
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_H264RTMPCODEC_H
|
|
|
|
|
#define ZLMEDIAKIT_H264RTMPCODEC_H
|
|
|
|
|
|
2019-06-28 17:30:13 +08:00
|
|
|
|
#include "Rtmp/RtmpCodec.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
#include "Extension/Track.h"
|
2018-10-24 12:01:40 +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-24 12:01:40 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit{
|
2018-10-24 12:01:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* h264 Rtmp解码类
|
2019-08-30 11:17:27 +08:00
|
|
|
|
* 将 h264 over rtmp 解复用出 h264-Frame
|
2018-10-24 12:01:40 +08:00
|
|
|
|
*/
|
|
|
|
|
class H264RtmpDecoder : public RtmpCodec ,public ResourcePoolHelper<H264Frame> {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<H264RtmpDecoder> Ptr;
|
|
|
|
|
|
|
|
|
|
H264RtmpDecoder();
|
|
|
|
|
~H264RtmpDecoder() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入264 Rtmp包
|
|
|
|
|
* @param rtmp Rtmp包
|
|
|
|
|
* @param key_pos 此参数忽略之
|
|
|
|
|
*/
|
|
|
|
|
bool inputRtmp(const RtmpPacket::Ptr &rtmp, bool key_pos = true) override;
|
|
|
|
|
|
|
|
|
|
TrackType getTrackType() const override{
|
|
|
|
|
return TrackVideo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
return CodecH264;
|
|
|
|
|
}
|
2018-10-24 14:21:59 +08:00
|
|
|
|
protected:
|
2018-10-24 12:01:40 +08:00
|
|
|
|
bool decodeRtmp(const RtmpPacket::Ptr &Rtmp);
|
2018-11-17 17:47:43 +08:00
|
|
|
|
void onGetH264(const char *pcData, int iLen, uint32_t dts,uint32_t pts);
|
2018-10-24 12:01:40 +08:00
|
|
|
|
H264Frame::Ptr obtainFrame();
|
2018-10-24 14:21:59 +08:00
|
|
|
|
protected:
|
2018-10-24 15:43:52 +08:00
|
|
|
|
H264Frame::Ptr _h264frame;
|
|
|
|
|
string _sps;
|
|
|
|
|
string _pps;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 264 Rtmp打包类
|
|
|
|
|
*/
|
|
|
|
|
class H264RtmpEncoder : public H264RtmpDecoder, public ResourcePoolHelper<RtmpPacket> {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<H264RtmpEncoder> Ptr;
|
|
|
|
|
|
2018-10-25 14:16:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* 构造函数,track可以为空,此时则在inputFrame时输入sps pps
|
|
|
|
|
* 如果track不为空且包含sps pps信息,
|
|
|
|
|
* 那么inputFrame时可以不输入sps pps
|
|
|
|
|
* @param track
|
|
|
|
|
*/
|
|
|
|
|
H264RtmpEncoder(const Track::Ptr &track);
|
2018-10-24 12:01:40 +08:00
|
|
|
|
~H264RtmpEncoder() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-25 14:16:40 +08:00
|
|
|
|
* 输入264帧,可以不带sps pps
|
2018-10-24 12:01:40 +08:00
|
|
|
|
* @param frame 帧数据
|
|
|
|
|
*/
|
|
|
|
|
void inputFrame(const Frame::Ptr &frame) override;
|
2020-01-15 11:46:15 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成config包
|
|
|
|
|
*/
|
|
|
|
|
void makeConfigPacket() override;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
private:
|
|
|
|
|
void makeVideoConfigPkt();
|
2018-10-25 14:16:40 +08:00
|
|
|
|
private:
|
|
|
|
|
H264Track::Ptr _track;
|
2018-10-25 14:23:02 +08:00
|
|
|
|
bool _gotSpsPps = false;
|
2018-11-16 15:46:49 +08:00
|
|
|
|
RtmpPacket::Ptr _lastPacket;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
|
|
|
|
|
2018-10-24 12:01:40 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_H264RTMPCODEC_H
|