From 5a2bf8d19678db1965e6f4c74b9af9d89af5e2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 29 Jul 2023 23:03:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AF=B9enhanced=20rtmp=20vi?= =?UTF-8?q?deocodecid=E7=9A=84=E5=85=BC=E5=AE=B9=20(#2718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 请查阅: https://github.com/veovera/enhanced-rtmp/issues/8 --- src/Extension/Factory.cpp | 3 +++ src/Rtmp/Rtmp.cpp | 8 ++++---- src/Rtmp/Rtmp.h | 13 ++++++------- src/Rtmp/RtmpDemuxer.cpp | 20 ++++---------------- src/Rtmp/RtmpDemuxer.h | 2 -- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index a19d0f66..63a2bbd5 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -204,7 +204,10 @@ static CodecId getVideoCodecIdByAmf(const AMFValue &val){ auto type_id = (RtmpVideoCodec)val.as_integer(); switch (type_id) { case RtmpVideoCodec::h264: return CodecH264; + case RtmpVideoCodec::fourcc_hevc: case RtmpVideoCodec::h265: return CodecH265; + case RtmpVideoCodec::fourcc_av1: return CodecAV1; + case RtmpVideoCodec::fourcc_vp9: return CodecVP9; default: WarnL << "暂不支持该视频Amf:" << (int)type_id; return CodecInvalid; } } diff --git a/src/Rtmp/Rtmp.cpp b/src/Rtmp/Rtmp.cpp index 95fe8fe7..140afeed 100644 --- a/src/Rtmp/Rtmp.cpp +++ b/src/Rtmp/Rtmp.cpp @@ -301,10 +301,10 @@ CodecId parseVideoRtmpPacket(const uint8_t *data, size_t size, RtmpPacketInfo *i info->video.frame_type = (RtmpFrameType)(enhanced_header->frame_type); info->video.pkt_type = (RtmpPacketType)(enhanced_header->pkt_type); - switch (ntohl(enhanced_header->fourcc)) { - case fourcc_av1: info->codec = CodecAV1; break; - case fourcc_vp9: info->codec = CodecVP9; break; - case fourcc_hevc: info->codec = CodecH265; break; + switch ((RtmpVideoCodec)ntohl(enhanced_header->fourcc)) { + case RtmpVideoCodec::fourcc_av1: info->codec = CodecAV1; break; + case RtmpVideoCodec::fourcc_vp9: info->codec = CodecVP9; break; + case RtmpVideoCodec::fourcc_hevc: info->codec = CodecH265; break; default: WarnL << "Rtmp video codec not supported: " << std::string((char *)data + 1, 4); } } else { diff --git a/src/Rtmp/Rtmp.h b/src/Rtmp/Rtmp.h index 28ba0ebe..30a56c74 100644 --- a/src/Rtmp/Rtmp.h +++ b/src/Rtmp/Rtmp.h @@ -264,7 +264,7 @@ enum class RtmpFrameType : uint8_t { }; // UB [4]; Codec Identifier. -enum class RtmpVideoCodec : uint8_t { +enum class RtmpVideoCodec : uint32_t { h263 = 2, // Sorenson H.263 screen_video = 3, // Screen video vp6 = 4, // On2 VP6 @@ -272,6 +272,11 @@ enum class RtmpVideoCodec : uint8_t { screen_video2 = 6, // Screen video version 2 h264 = 7, // avc h265 = 12, // 国内扩展 + + // 增强型rtmp FourCC + fourcc_vp9 = 'vp09', + fourcc_av1 = 'av01', + fourcc_hevc = 'hvc1' }; // UI8; @@ -357,12 +362,6 @@ struct RtmpPacketInfo { }; }; // https://github.com/veovera/enhanced-rtmp - -// 增强型rtmp FourCC -static constexpr uint32_t fourcc_vp9 = 'vp09'; -static constexpr uint32_t fourcc_av1 = 'av01'; -static constexpr uint32_t fourcc_hevc = 'hvc1'; - CodecId parseVideoRtmpPacket(const uint8_t *data, size_t size, RtmpPacketInfo *info = nullptr); }//namespace mediakit diff --git a/src/Rtmp/RtmpDemuxer.cpp b/src/Rtmp/RtmpDemuxer.cpp index e591acbf..20d8f052 100644 --- a/src/Rtmp/RtmpDemuxer.cpp +++ b/src/Rtmp/RtmpDemuxer.cpp @@ -75,19 +75,13 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val) { } if (key == "videodatarate") { videodatarate = val.as_integer(); - _videodatarate = videodatarate * 1024; return; } }); if (videocodecid) { // 有视频 ret = true; - if (videocodecid->type() == AMF_NUMBER && videocodecid->as_integer() == (int)RtmpVideoCodec::h264) { - // https://github.com/veovera/enhanced-rtmp/issues/8 - _complete_delay = true; - } else { - makeVideoTrack(*videocodecid, videodatarate * 1024); - } + makeVideoTrack(*videocodecid, videodatarate * 1024); } if (audiocodecid) { // 有音频 @@ -98,7 +92,7 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val) { WarnL << ex.what(); } - if (ret && !_complete_delay) { + if (ret) { // metadata中存在track相关的描述,那么我们根据metadata判断有多少个track addTrackCompleted(); } @@ -114,14 +108,8 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) { case MSG_VIDEO: { if (!_try_get_video_track) { _try_get_video_track = true; - RtmpPacketInfo info; - auto codec_id = parseVideoRtmpPacket((uint8_t *)pkt->data(), pkt->size(), &info); - if (codec_id != CodecInvalid) { - makeVideoTrack(Factory::getTrackByCodecId(codec_id), _videodatarate); - if (_complete_delay) { - addTrackCompleted(); - } - } + auto codec_id = parseVideoRtmpPacket((uint8_t *)pkt->data(), pkt->size()); + makeVideoTrack(Factory::getTrackByCodecId(codec_id), 0); } if (_video_rtmp_decoder) { _video_rtmp_decoder->inputRtmp(pkt); diff --git a/src/Rtmp/RtmpDemuxer.h b/src/Rtmp/RtmpDemuxer.h index df810652..4cf0412b 100644 --- a/src/Rtmp/RtmpDemuxer.h +++ b/src/Rtmp/RtmpDemuxer.h @@ -51,9 +51,7 @@ private: private: bool _try_get_video_track = false; bool _try_get_audio_track = false; - bool _complete_delay = false; float _duration = 0; - int _videodatarate = 0; AudioTrack::Ptr _audio_track; VideoTrack::Ptr _video_track; RtmpCodec::Ptr _audio_rtmp_decoder;