Http-FLV: http-flv直播采用绝对时间戳并支持las

This commit is contained in:
ziyue
2021-12-28 17:22:16 +08:00
parent 30b63ad656
commit dce6b27f4f
3 changed files with 16 additions and 14 deletions

View File

@@ -20,17 +20,17 @@ FlvMuxer::FlvMuxer(){
_packet_pool.setSize(64);
}
void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media) {
void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, uint32_t start_pts) {
if (!media) {
throw std::runtime_error("RtmpMediaSource 无效");
}
if (!poller->isCurrentThread()) {
weak_ptr<FlvMuxer> weakSelf = getSharedPtr();
//延时两秒启动录制目的是为了等待config帧收集完毕
poller->doDelayTask(2000, [weakSelf, poller, media]() {
poller->doDelayTask(2000, [weakSelf, poller, media, start_pts]() {
auto strongSelf = weakSelf.lock();
if (strongSelf) {
strongSelf->start(poller, media);
strongSelf->start(poller, media, start_pts);
}
return 0;
});
@@ -50,9 +50,8 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
strongSelf->onDetach();
});
//音频同步于视频
_stamp[0].syncTo(_stamp[1]);
_ring_reader->setReadCB([weakSelf](const RtmpMediaSource::RingDataType &pkt) {
bool check = start_pts > 0;
_ring_reader->setReadCB([weakSelf, start_pts, check](const RtmpMediaSource::RingDataType &pkt) mutable {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
@@ -61,6 +60,12 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
size_t i = 0;
auto size = pkt->size();
pkt->for_each([&](const RtmpPacket::Ptr &rtmp) {
if (check) {
if (rtmp->time_stamp < start_pts) {
return;
}
check = false;
}
strongSelf->onWriteRtmp(rtmp, ++i == size);
});
});
@@ -137,9 +142,7 @@ void FlvMuxer::onWriteFlvTag(uint8_t type, const Buffer::Ptr &buffer, uint32_t t
}
void FlvMuxer::onWriteRtmp(const RtmpPacket::Ptr &pkt, bool flush) {
int64_t dts_out;
_stamp[pkt->type_id % 2].revise(pkt->time_stamp, 0, dts_out, dts_out);
onWriteFlvTag(pkt, (uint32_t) dts_out, flush);
onWriteFlvTag(pkt, pkt->time_stamp, flush);
}
void FlvMuxer::stop() {