mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-21 16:32:22 +08:00
Http-FLV: http-flv直播采用绝对时间戳并支持las
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user