mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 22:55:52 +08:00
兼容无metadata的rtmp流
This commit is contained in:
parent
9d43c38e09
commit
8da9aee11a
@ -106,10 +106,15 @@ void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) {
|
|||||||
//PreviousTagSize0 Always 0
|
//PreviousTagSize0 Always 0
|
||||||
onWrite(std::make_shared<BufferRaw>((char *)&size,4));
|
onWrite(std::make_shared<BufferRaw>((char *)&size,4));
|
||||||
|
|
||||||
//metadata
|
|
||||||
|
auto &metadata = mediaSrc->getMetaData();
|
||||||
|
if(metadata){
|
||||||
|
//在有metadata的情况下才发送metadata
|
||||||
|
//其实metadata没什么用,有些推流器不产生metadata
|
||||||
AMFEncoder invoke;
|
AMFEncoder invoke;
|
||||||
invoke << "onMetaData" << mediaSrc->getMetaData();
|
invoke << "onMetaData" << metadata;
|
||||||
onWriteFlvTag(MSG_DATA, std::make_shared<BufferString>(invoke.data()), 0);
|
onWriteFlvTag(MSG_DATA, std::make_shared<BufferString>(invoke.data()), 0);
|
||||||
|
}
|
||||||
|
|
||||||
//config frame
|
//config frame
|
||||||
mediaSrc->getConfigFrame([&](const RtmpPacket::Ptr &pkt){
|
mediaSrc->getConfigFrame([&](const RtmpPacket::Ptr &pkt){
|
||||||
|
@ -262,10 +262,16 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr
|
|||||||
status.set("clientid", "0");
|
status.set("clientid", "0");
|
||||||
sendReply("onStatus", nullptr, status);
|
sendReply("onStatus", nullptr, status);
|
||||||
|
|
||||||
|
auto &metadata = src->getMetaData();
|
||||||
|
if(metadata){
|
||||||
|
//在有metadata的情况下才发送metadata
|
||||||
|
//其实metadata没什么用,有些推流器不产生metadata
|
||||||
// onMetaData
|
// onMetaData
|
||||||
invoke.clear();
|
invoke.clear();
|
||||||
invoke << "onMetaData" << src->getMetaData();
|
invoke << "onMetaData" << metadata;
|
||||||
sendResponse(MSG_DATA, invoke.data());
|
sendResponse(MSG_DATA, invoke.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
src->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
|
src->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
|
||||||
//DebugP(this)<<"send initial frame";
|
//DebugP(this)<<"send initial frame";
|
||||||
@ -423,7 +429,9 @@ void RtmpSession::setMetaData(AMFDecoder &dec) {
|
|||||||
if (type != "onMetaData") {
|
if (type != "onMetaData") {
|
||||||
throw std::runtime_error("can only set metadata");
|
throw std::runtime_error("can only set metadata");
|
||||||
}
|
}
|
||||||
_pPublisherSrc->onGetMetaData(dec.load<AMFValue>());
|
auto metadata = dec.load<AMFValue>();
|
||||||
|
//dumpMetadata(metadata);
|
||||||
|
_pPublisherSrc->onGetMetaData(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtmpSession::onProcessCmd(AMFDecoder &dec) {
|
void RtmpSession::onProcessCmd(AMFDecoder &dec) {
|
||||||
@ -542,4 +550,16 @@ void RtmpSession::setSocketFlags(){
|
|||||||
(*this) << SocketFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
(*this) << SocketFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtmpSession::dumpMetadata(const AMFValue &metadata) {
|
||||||
|
if(metadata.type() != AMF_OBJECT && metadata.type() != AMF_ECMA_ARRAY){
|
||||||
|
WarnL << "invalid metedata type:" << metadata.type();
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
_StrPrinter printer;
|
||||||
|
metadata.object_for_each([&](const string &key, const AMFValue &val){
|
||||||
|
printer << "\r\n" << key << "\t:" << val.to_string() ;
|
||||||
|
});
|
||||||
|
InfoL << _mediaInfo._vhost << " " << _mediaInfo._app << " " << _mediaInfo._streamid << (string)printer;
|
||||||
|
}
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -87,6 +87,7 @@ private:
|
|||||||
void onNoneReader(MediaSource &sender) override;
|
void onNoneReader(MediaSource &sender) override;
|
||||||
void setSocketFlags();
|
void setSocketFlags();
|
||||||
string getStreamId(const string &str);
|
string getStreamId(const string &str);
|
||||||
|
void dumpMetadata(const AMFValue &metedata);
|
||||||
private:
|
private:
|
||||||
std::string _strTcUrl;
|
std::string _strTcUrl;
|
||||||
MediaInfo _mediaInfo;
|
MediaInfo _mediaInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user