HTTP-FMP4: 修复http-fmp4直播秒开问题

This commit is contained in:
ziyue 2021-12-16 17:46:03 +08:00
parent 4291c31493
commit 120879df0f
4 changed files with 32 additions and 31 deletions

View File

@ -64,9 +64,7 @@ public:
*/
void setInitSegment(string str) {
_init_segment = std::move(str);
if (_ring) {
regist();
}
createRing();
}
/**

View File

@ -72,7 +72,7 @@ public:
}
protected:
void onSegmentData(const string &string, uint32_t stamp, bool key_frame) override {
void onSegmentData(string string, uint32_t stamp, bool key_frame) override {
if (string.empty()) {
return;
}

View File

@ -9,9 +9,11 @@
*/
#ifdef ENABLE_MP4
#include "MP4Muxer.h"
#include "Util/File.h"
#include "Extension/H264.h"
namespace mediakit {
MP4Muxer::MP4Muxer() {}
@ -84,7 +86,6 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) {
//mp4文件时间戳需要从0开始
auto &track_info = it->second;
int64_t dts_out, pts_out;
switch (frame->getCodecId()) {
case CodecH264:
case CodecH265: {
@ -319,22 +320,24 @@ bool MP4MuxerMemory::inputFrame(const Frame::Ptr &frame){
return false;
}
auto key_frame = frame->keyFrame();
auto data = _memory_file->getAndClearMemory();
if (!data.empty()) {
bool key_frame = frame->keyFrame();
//flush切片
saveSegment();
auto data = _memory_file->getAndClearMemory();
if (!data.empty()) {
//输出切片数据
onSegmentData(data, frame->dts(), _key_frame);
onSegmentData(std::move(data), frame->dts(), _key_frame);
_key_frame = false;
}
if (key_frame) {
_key_frame = true;
}
return MP4MuxerInterface::inputFrame(frame);
}
}//namespace mediakit
#endif//#ifdef ENABLE_MP4

View File

@ -134,7 +134,7 @@ protected:
* @param stamp
* @param key_frame
*/
virtual void onSegmentData(const string &string, uint32_t stamp, bool key_frame) = 0;
virtual void onSegmentData(string string, uint32_t stamp, bool key_frame) = 0;
protected:
MP4FileIO::Writer createWriter() override;