2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*/
|
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"
|
|
|
|
|
#include "Extension/H264.h"
|
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
|
|
|
|
*/
|
2021-02-05 11:51:16 +08:00
|
|
|
|
class H264RtmpDecoder : public RtmpCodec {
|
2018-10-24 12:01:40 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<H264RtmpDecoder>;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
|
|
|
|
|
H264RtmpDecoder();
|
|
|
|
|
~H264RtmpDecoder() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入264 Rtmp包
|
|
|
|
|
* @param rtmp Rtmp包
|
|
|
|
|
*/
|
2020-09-06 18:22:04 +08:00
|
|
|
|
void inputRtmp(const RtmpPacket::Ptr &rtmp) override;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
return CodecH264;
|
|
|
|
|
}
|
2020-09-06 18:22:04 +08:00
|
|
|
|
|
2018-10-24 14:21:59 +08:00
|
|
|
|
protected:
|
2022-01-08 16:21:00 +08:00
|
|
|
|
void onGetH264(const char *data, size_t len, uint32_t dts, uint32_t pts);
|
2018-10-24 12:01:40 +08:00
|
|
|
|
H264Frame::Ptr obtainFrame();
|
2020-09-06 18:22:04 +08:00
|
|
|
|
|
2018-10-24 14:21:59 +08:00
|
|
|
|
protected:
|
2018-10-24 15:43:52 +08:00
|
|
|
|
H264Frame::Ptr _h264frame;
|
2022-02-02 20:34:50 +08:00
|
|
|
|
std::string _sps;
|
|
|
|
|
std::string _pps;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 264 Rtmp打包类
|
|
|
|
|
*/
|
2021-02-04 17:58:51 +08:00
|
|
|
|
class H264RtmpEncoder : public H264RtmpDecoder{
|
2018-10-24 12:01:40 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<H264RtmpEncoder>;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
|
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);
|
2022-10-16 19:49:56 +08:00
|
|
|
|
~H264RtmpEncoder() = default;
|
2018-10-24 12:01:40 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2018-10-25 14:16:40 +08:00
|
|
|
|
* 输入264帧,可以不带sps pps
|
2018-10-24 12:01:40 +08:00
|
|
|
|
* @param frame 帧数据
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool inputFrame(const Frame::Ptr &frame) override;
|
2020-01-15 11:46:15 +08:00
|
|
|
|
|
2022-10-16 19:49:56 +08:00
|
|
|
|
/**
|
|
|
|
|
* 刷新输出所有frame缓存
|
|
|
|
|
*/
|
|
|
|
|
void flush() override;
|
|
|
|
|
|
2020-01-15 11:46:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 生成config包
|
|
|
|
|
*/
|
|
|
|
|
void makeConfigPacket() override;
|
2021-07-09 13:38:20 +08:00
|
|
|
|
|
2018-10-24 12:01:40 +08:00
|
|
|
|
private:
|
|
|
|
|
void makeVideoConfigPkt();
|
2021-07-09 13:38:20 +08:00
|
|
|
|
|
2018-10-25 14:16:40 +08:00
|
|
|
|
private:
|
2021-06-28 10:35:08 +08:00
|
|
|
|
bool _got_config_frame = false;
|
2018-10-25 14:16:40 +08:00
|
|
|
|
H264Track::Ptr _track;
|
2021-06-28 10:35:08 +08:00
|
|
|
|
RtmpPacket::Ptr _rtmp_packet;
|
2021-07-09 13:38:20 +08:00
|
|
|
|
FrameMerger _merger{FrameMerger::mp4_nal_size};
|
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
|