mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
完善获取flv是否包含音视频相关逻辑
This commit is contained in:
parent
fe42ea30fc
commit
c8f00cefa0
@ -67,7 +67,7 @@ BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) {
|
||||
void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &src) {
|
||||
//发送flv文件头
|
||||
auto buffer = BufferRaw::create();
|
||||
buffer->setCapacity(sizeof(FLVHeader));
|
||||
@ -80,15 +80,8 @@ void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) {
|
||||
header->flv[2] = 'V';
|
||||
header->version = 1;
|
||||
header->length = htonl(9);
|
||||
|
||||
mediaSrc->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
|
||||
if (pkt->type_id == MSG_VIDEO) {
|
||||
header->have_video = 1;
|
||||
}
|
||||
if (pkt->type_id == MSG_AUDIO) {
|
||||
header->have_audio = 1;
|
||||
}
|
||||
});
|
||||
header->have_video = src->haveVideo();
|
||||
header->have_audio = src->haveAudio();
|
||||
|
||||
//flv header
|
||||
onWrite(buffer, false);
|
||||
@ -97,7 +90,7 @@ void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) {
|
||||
auto size = htonl(0);
|
||||
onWrite(obtainBuffer((char *) &size, 4), false);
|
||||
|
||||
auto &metadata = mediaSrc->getMetaData();
|
||||
auto &metadata = src->getMetaData();
|
||||
if (metadata) {
|
||||
//在有metadata的情况下才发送metadata
|
||||
//其实metadata没什么用,有些推流器不产生metadata
|
||||
@ -107,7 +100,7 @@ void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) {
|
||||
}
|
||||
|
||||
//config frame
|
||||
mediaSrc->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
|
||||
src->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
|
||||
onWriteRtmp(pkt, true);
|
||||
});
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ protected:
|
||||
virtual std::shared_ptr<FlvMuxer> getSharedPtr() = 0;
|
||||
|
||||
private:
|
||||
void onWriteFlvHeader(const RtmpMediaSource::Ptr &media);
|
||||
void onWriteFlvHeader(const RtmpMediaSource::Ptr &src);
|
||||
void onWriteRtmp(const RtmpPacket::Ptr &pkt, bool flush);
|
||||
void onWriteFlvTag(const RtmpPacket::Ptr &pkt, uint32_t time_stamp, bool flush);
|
||||
void onWriteFlvTag(uint8_t type, const Buffer::Ptr &buffer, uint32_t time_stamp, bool flush);
|
||||
|
@ -102,6 +102,8 @@ public:
|
||||
virtual void setMetaData(const AMFValue &metadata) {
|
||||
_metadata = metadata;
|
||||
_metadata.set("server", SERVER_NAME);
|
||||
_have_video = _metadata["videocodecid"];
|
||||
_have_audio = _metadata["audiocodecid"];
|
||||
if (_ring) {
|
||||
regist();
|
||||
}
|
||||
@ -125,7 +127,7 @@ public:
|
||||
//保存当前时间戳
|
||||
switch (pkt->type_id) {
|
||||
case MSG_VIDEO : _track_stamps[TrackVideo] = pkt->time_stamp, _have_video = true; break;
|
||||
case MSG_AUDIO : _track_stamps[TrackAudio] = pkt->time_stamp; break;
|
||||
case MSG_AUDIO : _track_stamps[TrackAudio] = pkt->time_stamp, _have_audio = true; break;
|
||||
default : break;
|
||||
}
|
||||
|
||||
@ -187,6 +189,14 @@ public:
|
||||
_ring->clearCache();
|
||||
}
|
||||
|
||||
bool haveVideo() const {
|
||||
return _have_video;
|
||||
}
|
||||
|
||||
bool haveAudio() const {
|
||||
return _have_audio;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* 批量flush rtmp包时触发该函数
|
||||
@ -200,6 +210,7 @@ private:
|
||||
|
||||
private:
|
||||
bool _have_video = false;
|
||||
bool _have_audio = false;
|
||||
int _ring_size;
|
||||
uint32_t _track_stamps[TrackMax] = {0};
|
||||
AMFValue _metadata;
|
||||
|
Loading…
Reference in New Issue
Block a user