完善ertmp相关代码 (#4505)

增加多种Codec支持,并修复一些bug:
- opus 非标准实现,不输出config frame,与旧的实现保持一致
- 添加RTMP_CODEC_MAP宏,精简代码
This commit is contained in:
mtdxc
2025-10-19 11:56:35 +08:00
committed by GitHub
parent 5c58f39046
commit f35771a83e
4 changed files with 87 additions and 41 deletions

View File

@@ -55,6 +55,33 @@ AudioMeta::AudioMeta(const AudioTrack::Ptr &audio) {
_metadata.set("audiocodecid", Factory::getAmfByCodecId(audio->getCodecId()));
}
uint8_t getCodecFlags(CodecId cid) {
switch(cid) {
#define XX(a, b, c) case a: return static_cast<uint8_t>(b);
RTMP_CODEC_MAP(XX)
#undef XX
}
return 0;
}
uint32_t getCodecFourCC(CodecId cid) {
switch(cid) {
#define XX(a, b, c) case a: return static_cast<uint32_t>(c);
RTMP_CODEC_MAP(XX)
#undef XX
}
return 0;
}
CodecId getFourccCodec(uint32_t id) {
switch(id) {
#define XX(a, b, c) case (uint32_t)c: return a;
RTMP_CODEC_MAP(XX)
#undef XX
}
return CodecInvalid;
}
uint8_t getAudioRtmpFlags(const Track::Ptr &track) {
track->update();
switch (track->getTrackType()) {
@@ -167,7 +194,13 @@ bool RtmpPacket::isVideoKeyFrame() const {
bool RtmpPacket::isConfigFrame() const {
switch (type_id) {
case MSG_AUDIO: {
return (RtmpAudioCodec)getRtmpCodecId() == RtmpAudioCodec::aac && (RtmpAACPacketType)buffer[1] == RtmpAACPacketType::aac_config_header;
switch ((RtmpAudioCodec)getRtmpCodecId()) {
case RtmpAudioCodec::aac:
return (RtmpAACPacketType)buffer[1] == RtmpAACPacketType::aac_config_header;
case RtmpAudioCodec::ex_header:
return (RtmpPacketType)(buffer[0] & 0x0f) == RtmpPacketType::PacketTypeSequenceStart;
}
return false;
}
case MSG_VIDEO: {
if (!isVideoKeyFrame()) {