mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
完善rtmp关键帧与配置帧判断逻辑
This commit is contained in:
parent
a86398b6db
commit
780a1eb9fc
@ -21,9 +21,6 @@ static string getAacCfg(const RtmpPacket &thiz) {
|
||||
if ((RtmpAudioCodec)thiz.getRtmpCodecId() != RtmpAudioCodec::aac) {
|
||||
return ret;
|
||||
}
|
||||
if (!thiz.isCfgFrame()) {
|
||||
return ret;
|
||||
}
|
||||
if (thiz.buffer.size() < 4) {
|
||||
WarnL << "get aac config failed, rtmp packet is: " << hexdump(thiz.data(), thiz.size());
|
||||
return ret;
|
||||
|
@ -33,9 +33,6 @@ static bool getH264Config(const RtmpPacket &thiz, string &sps, string &pps) {
|
||||
if ((RtmpVideoCodec)thiz.getRtmpCodecId() != RtmpVideoCodec::h264) {
|
||||
return false;
|
||||
}
|
||||
if (!thiz.isCfgFrame()) {
|
||||
return false;
|
||||
}
|
||||
if (thiz.buffer.size() < 13) {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,9 +53,6 @@ static bool getH265ConfigFrame(const RtmpPacket &thiz, string &frame) {
|
||||
if ((RtmpVideoCodec)thiz.getRtmpCodecId() != RtmpVideoCodec::h265) {
|
||||
return false;
|
||||
}
|
||||
if (!thiz.isCfgFrame()) {
|
||||
return false;
|
||||
}
|
||||
if (thiz.buffer.size() < 6) {
|
||||
WarnL << "bad H265 cfg!";
|
||||
return false;
|
||||
|
@ -156,22 +156,36 @@ bool RtmpPacket::isVideoKeyFrame() const {
|
||||
if (type_id != MSG_VIDEO) {
|
||||
return false;
|
||||
}
|
||||
RtmpPacketInfo info;
|
||||
if (CodecInvalid == parseVideoRtmpPacket((uint8_t *)data(), size(), &info)) {
|
||||
return false;
|
||||
RtmpFrameType frame_type;
|
||||
if (buffer[0] >> 7 == 1) {
|
||||
// IsExHeader == 1
|
||||
frame_type = (RtmpFrameType)((buffer[0] >> 4) & 0x07);
|
||||
} else {
|
||||
// IsExHeader == 0
|
||||
frame_type = (RtmpFrameType)(buffer[0] >> 4);
|
||||
}
|
||||
if (info.is_enhanced) {
|
||||
return info.video.frame_type == RtmpFrameType::key_frame && info.video.pkt_type == RtmpPacketType::PacketTypeCodedFramesX;
|
||||
}
|
||||
return info.video.frame_type == RtmpFrameType::key_frame && info.video.h264_pkt_type == RtmpH264PacketType::h264_nalu;
|
||||
return frame_type == RtmpFrameType::key_frame;
|
||||
}
|
||||
|
||||
bool RtmpPacket::isCfgFrame() const {
|
||||
switch (type_id) {
|
||||
case MSG_VIDEO: return (RtmpH264PacketType)buffer[1] == RtmpH264PacketType::h264_config_header;
|
||||
case MSG_AUDIO: {
|
||||
switch ((RtmpAudioCodec)getRtmpCodecId()) {
|
||||
case RtmpAudioCodec::aac: return (RtmpAACPacketType)buffer[1] == RtmpAACPacketType::aac_config_header;
|
||||
return (RtmpAudioCodec)getRtmpCodecId() == RtmpAudioCodec::aac && (RtmpAACPacketType)buffer[1] == RtmpAACPacketType::aac_config_header;
|
||||
}
|
||||
case MSG_VIDEO: {
|
||||
if (!isVideoKeyFrame()) {
|
||||
return false;
|
||||
}
|
||||
if (buffer[0] >> 7 == 1) {
|
||||
// IsExHeader == 1
|
||||
return (RtmpPacketType)(buffer[0] & 0x0f) == RtmpPacketType::PacketTypeSequenceStart;
|
||||
}
|
||||
// IsExHeader == 0
|
||||
switch ((RtmpVideoCodec)getRtmpCodecId()) {
|
||||
case RtmpVideoCodec::h265:
|
||||
case RtmpVideoCodec::h264: {
|
||||
return (RtmpH264PacketType)buffer[1] == RtmpH264PacketType::h264_config_header;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,9 @@ public:
|
||||
}
|
||||
|
||||
void clear();
|
||||
// video config frame和key frame都返回true
|
||||
bool isVideoKeyFrame() const;
|
||||
// aac config或h264/h265 config
|
||||
bool isCfgFrame() const;
|
||||
int getRtmpCodecId() const;
|
||||
int getAudioSampleRate() const;
|
||||
|
Loading…
Reference in New Issue
Block a user