From 19d6f1a0037cfdc1752c60fe5a9a8bb6c0b4171d Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Thu, 20 Jul 2023 17:13:26 +0800 Subject: [PATCH] FLV player avoid script data first element not string (#2679 #2680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容不规范的flv流,比如livegbs产生的flv流metadata flv tag解析异常 --- src/Rtmp/FlvSplitter.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Rtmp/FlvSplitter.cpp b/src/Rtmp/FlvSplitter.cpp index c2e21e6a..3e99d9ef 100644 --- a/src/Rtmp/FlvSplitter.cpp +++ b/src/Rtmp/FlvSplitter.cpp @@ -91,21 +91,26 @@ void FlvSplitter::onRecvContent(const char *data, size_t len) { case MSG_DATA3: { BufferLikeString buffer(string(data, len)); AMFDecoder dec(buffer, _type == MSG_DATA3 ? 3 : 0); - std::string type = dec.load(); + auto first = dec.load(); bool flag = true; - if (type == "@setDataFrame") { - std::string type = dec.load(); - if (type == "onMetaData") { + if (first.type() == AMFType::AMF_STRING) { + auto type = first.as_string(); + if (type == "@setDataFrame") { + type = dec.load(); + if (type == "onMetaData") { + flag = onRecvMetadata(dec.load()); + } else { + WarnL << "unknown type:" << type; + } + } else if (type == "onMetaData") { flag = onRecvMetadata(dec.load()); } else { - WarnL << "unknown type:" << type; + WarnL << "unknown notify:" << type; } - } else if (type == "onMetaData") { - flag = onRecvMetadata(dec.load()); } else { - WarnL << "unknown notify:" << type; + WarnL << "Parse flv script data failed, invalid amf value: " << first.to_string(); } - if(!flag){ + if (!flag) { throw std::invalid_argument("check rtmp metadata failed"); } return;