Commit dce6b27f by ziyue

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

parent 30b63ad6
......@@ -332,7 +332,8 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
//http-flv 链接格式:http://vhost-url:port/app/streamid.flv?key1=value1&key2=value2
bool HttpSession::checkLiveStreamFlv(const function<void()> &cb){
return checkLiveStream(RTMP_SCHEMA, ".flv", [this, cb](const MediaSource::Ptr &src) {
auto start_pts = atoll(_parser.getUrlArgs()["starPts"].data());
return checkLiveStream(RTMP_SCHEMA, ".flv", [this, cb, start_pts](const MediaSource::Ptr &src) {
auto rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(src);
assert(rtmp_src);
if (!cb) {
......@@ -359,7 +360,7 @@ bool HttpSession::checkLiveStreamFlv(const function<void()> &cb){
}
}
start(getPoller(), rtmp_src);
start(getPoller(), rtmp_src, start_pts);
});
}
......
......@@ -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() {
......
......@@ -28,7 +28,7 @@ public:
void stop();
protected:
void start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media);
void start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, uint32_t start_pts = 0);
virtual void onWrite(const Buffer::Ptr &data, bool flush) = 0;
virtual void onDetach() = 0;
virtual std::shared_ptr<FlvMuxer> getSharedPtr() = 0;
......@@ -43,8 +43,6 @@ private:
private:
ResourcePool<BufferRaw> _packet_pool;
//时间戳修整器
Stamp _stamp[2];
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论