2020-09-06 18:09:31 +08:00
|
|
|
|
/*
|
2020-09-06 17:56:05 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2020-09-06 17:56:05 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_PSENCODER_H
|
|
|
|
|
#define ZLMEDIAKIT_PSENCODER_H
|
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
#include "mpeg-ps.h"
|
|
|
|
|
#include "Common/MediaSink.h"
|
|
|
|
|
#include "Common/Stamp.h"
|
2020-10-24 23:33:13 +08:00
|
|
|
|
#include "Extension/CommonRtp.h"
|
2020-09-06 17:56:05 +08:00
|
|
|
|
namespace mediakit{
|
|
|
|
|
|
|
|
|
|
//该类实现mpeg-ps容器格式的打包
|
|
|
|
|
class PSEncoder : public MediaSinkInterface {
|
|
|
|
|
public:
|
|
|
|
|
PSEncoder();
|
|
|
|
|
~PSEncoder() override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加音视频轨道
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool addTrack(const Track::Ptr &track) override;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置音视频轨道
|
|
|
|
|
*/
|
|
|
|
|
void resetTracks() override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入帧数据
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool inputFrame(const Frame::Ptr &frame) override;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* 输出mpeg-ps的回调函数
|
|
|
|
|
* @param stamp 时间戳,毫秒
|
|
|
|
|
* @param packet 数据指针
|
|
|
|
|
* @param bytes 数据长度
|
|
|
|
|
*/
|
|
|
|
|
virtual void onPS(uint32_t stamp, void *packet, size_t bytes) = 0;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void init();
|
|
|
|
|
//音视频时间戳同步用
|
|
|
|
|
void stampSync();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct track_info {
|
|
|
|
|
int track_id = -1;
|
|
|
|
|
Stamp stamp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint32_t _timestamp = 0;
|
|
|
|
|
BufferRaw::Ptr _buffer;
|
|
|
|
|
std::shared_ptr<struct ps_muxer_t> _muxer;
|
|
|
|
|
unordered_map<int, track_info> _codec_to_trackid;
|
2021-04-26 18:26:07 +08:00
|
|
|
|
FrameMerger _frame_merger{FrameMerger::h264_prefix};
|
2020-09-06 17:56:05 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-10-24 23:33:13 +08:00
|
|
|
|
class PSEncoderImp : public PSEncoder{
|
|
|
|
|
public:
|
|
|
|
|
PSEncoderImp(uint32_t ssrc, uint8_t payload_type = 96);
|
|
|
|
|
~PSEncoderImp() override;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
//rtp打包后回调
|
|
|
|
|
virtual void onRTP(Buffer::Ptr rtp) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void onPS(uint32_t stamp, void *packet, size_t bytes) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<CommonRtpEncoder> _rtp_encoder;
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-06 17:56:05 +08:00
|
|
|
|
}//namespace mediakit
|
|
|
|
|
#endif //ENABLE_RTPPROXY
|
|
|
|
|
#endif //ZLMEDIAKIT_PSENCODER_H
|