http-ts直播减少一次内存拷贝

This commit is contained in:
ziyue
2021-07-07 16:15:42 +08:00
parent 6220db77e8
commit 4b694ccde8
5 changed files with 20 additions and 18 deletions

View File

@@ -73,8 +73,12 @@ public:
}
private:
void onTs(const void *packet, size_t bytes, uint32_t timestamp, bool is_idr_fast_packet) override {
_hls->inputData((char *) packet, bytes, timestamp, is_idr_fast_packet);
void onTs(std::shared_ptr<Buffer> buffer, uint32_t timestamp, bool is_idr_fast_packet) override {
if (!buffer) {
_hls->inputData(nullptr, 0, timestamp, is_idr_fast_packet);
} else {
_hls->inputData(buffer->data(), buffer->size(), timestamp, is_idr_fast_packet);
}
}
private:

View File

@@ -133,7 +133,7 @@ void TsMuxer::inputFrame(const Frame::Ptr &frame) {
void TsMuxer::resetTracks() {
_have_video = false;
//通知片段中断
onTs(nullptr, 0, _timestamp, 0);
onTs(nullptr, _timestamp, 0);
uninit();
init();
}
@@ -160,12 +160,14 @@ void TsMuxer::init() {
}
void TsMuxer::onTs_l(const void *packet, size_t bytes) {
_cache.append((char *) packet, bytes);
if (!_cache) {
_cache = std::make_shared<BufferLikeString>();
}
_cache->append((char *) packet, bytes);
}
void TsMuxer::flushCache() {
onTs(_cache.data(), _cache.size(), _timestamp, _is_idr_fast_packet);
_cache.clear();
onTs(std::move(_cache), _timestamp, _is_idr_fast_packet);
_is_idr_fast_packet = false;
}

View File

@@ -45,12 +45,11 @@ public:
protected:
/**
* 输出mpegts数据回调
* @param packet mpegts数据
* @param bytes mpegts数据长度
* @param buffer mpegts数据
* @param timestamp 时间戳,单位毫秒
* @param is_idr_fast_packet 是否为关键帧的第一个TS包用于确保ts切片第一帧为关键帧
*/
virtual void onTs(const void *packet, size_t bytes,uint32_t timestamp,bool is_idr_fast_packet) = 0;
virtual void onTs(std::shared_ptr<Buffer> buffer, uint32_t timestamp,bool is_idr_fast_packet) = 0;
private:
void init();
@@ -72,7 +71,7 @@ private:
};
unordered_map<int, track_info> _codec_to_trackid;
FrameMerger _frame_merger{FrameMerger::h264_prefix};
BufferLikeString _cache;
std::shared_ptr<BufferLikeString> _cache;
};
}//namespace mediakit