mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-02-27 18:50:52 +08:00
优化ertmp对opus的支持
This commit is contained in:
Submodule 3rdpart/ZLToolKit updated: 6e727443e6...94af13d4d0
@@ -25,7 +25,7 @@ void OpusRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
|||||||
auto codec = (RtmpAudioCodec)(flags >> 4);
|
auto codec = (RtmpAudioCodec)(flags >> 4);
|
||||||
auto type = flags & 0x0F;
|
auto type = flags & 0x0F;
|
||||||
data++; size--;
|
data++; size--;
|
||||||
if (codec == RtmpAudioCodec::FOURCC) {
|
if (codec == RtmpAudioCodec::ex_header) {
|
||||||
// @todo parse enhance audio header and check fourcc
|
// @todo parse enhance audio header and check fourcc
|
||||||
data += 4;
|
data += 4;
|
||||||
size -= 4;
|
size -= 4;
|
||||||
@@ -51,9 +51,10 @@ OpusRtmpEncoder::OpusRtmpEncoder(const Track::Ptr &track) : RtmpCodec(track) {
|
|||||||
bool OpusRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
bool OpusRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||||
auto packet = RtmpPacket::create();
|
auto packet = RtmpPacket::create();
|
||||||
if (_enhanced) {
|
if (_enhanced) {
|
||||||
uint8_t flags = ((uint8_t)RtmpAudioCodec::FOURCC << 4) | (uint8_t)RtmpPacketType::PacketTypeCodedFrames;
|
uint8_t flags = ((uint8_t)RtmpAudioCodec::ex_header << 4) | (uint8_t)RtmpPacketType::PacketTypeCodedFrames;
|
||||||
packet->buffer.push_back(flags);
|
packet->buffer.push_back(flags);
|
||||||
packet->buffer.append("Opus", 4);
|
uint32_t fourcc = static_cast<uint32_t>(RtmpAudioCodec::fourcc_opus);
|
||||||
|
packet->buffer.append(reinterpret_cast<char *>(&fourcc), 4);
|
||||||
} else {
|
} else {
|
||||||
uint8_t flags = getAudioRtmpFlags(getTrack());
|
uint8_t flags = getAudioRtmpFlags(getTrack());
|
||||||
packet->buffer.push_back(flags);
|
packet->buffer.push_back(flags);
|
||||||
@@ -75,9 +76,10 @@ void OpusRtmpEncoder::makeConfigPacket() {
|
|||||||
return;
|
return;
|
||||||
auto pkt = RtmpPacket::create();
|
auto pkt = RtmpPacket::create();
|
||||||
if (_enhanced) {
|
if (_enhanced) {
|
||||||
uint8_t flags = ((uint8_t)RtmpAudioCodec::FOURCC << 4) | (uint8_t)RtmpPacketType::PacketTypeSequenceStart;
|
uint8_t flags = ((uint8_t)RtmpAudioCodec::ex_header << 4) | (uint8_t)RtmpPacketType::PacketTypeSequenceStart;
|
||||||
pkt->buffer.push_back(flags);
|
pkt->buffer.push_back(flags);
|
||||||
pkt->buffer.append("Opus", 4);
|
uint32_t fourcc = static_cast<uint32_t>(RtmpAudioCodec::fourcc_opus);
|
||||||
|
pkt->buffer.append(reinterpret_cast<char *>(&fourcc), 4);
|
||||||
} else {
|
} else {
|
||||||
uint8_t flags = getAudioRtmpFlags(getTrack());
|
uint8_t flags = getAudioRtmpFlags(getTrack());
|
||||||
pkt->buffer.push_back(flags);
|
pkt->buffer.push_back(flags);
|
||||||
|
|||||||
@@ -88,10 +88,10 @@ bool VpxRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
|||||||
header->enhanced = 1;
|
header->enhanced = 1;
|
||||||
header->frame_type = frame->keyFrame() ? (int)RtmpFrameType::key_frame : (int)RtmpFrameType::inter_frame;
|
header->frame_type = frame->keyFrame() ? (int)RtmpFrameType::key_frame : (int)RtmpFrameType::inter_frame;
|
||||||
switch (frame->getCodecId()) {
|
switch (frame->getCodecId()) {
|
||||||
case CodecVP8: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp8); break;
|
case CodecVP8: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp8); break;
|
||||||
case CodecVP9: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp9); break;
|
case CodecVP9: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp9); break;
|
||||||
case CodecAV1: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_av1); break;
|
case CodecAV1: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_av1); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
buff += RtmpPacketInfo::kEnhancedRtmpHeaderSize;
|
buff += RtmpPacketInfo::kEnhancedRtmpHeaderSize;
|
||||||
if (cts) {
|
if (cts) {
|
||||||
@@ -105,10 +105,10 @@ bool VpxRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
|||||||
// flags
|
// flags
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
switch (getTrack()->getCodecId()) {
|
switch (getTrack()->getCodecId()) {
|
||||||
case CodecVP8: flags = (uint8_t)RtmpVideoCodec::vp8; break;
|
case CodecVP8: flags = (uint8_t)RtmpVideoCodec::vp8; break;
|
||||||
case CodecVP9: flags = (uint8_t)RtmpVideoCodec::vp9; break;
|
case CodecVP9: flags = (uint8_t)RtmpVideoCodec::vp9; break;
|
||||||
case CodecAV1: flags = (uint8_t)RtmpVideoCodec::av1; break;
|
case CodecAV1: flags = (uint8_t)RtmpVideoCodec::av1; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
flags |= (uint8_t)(frame->keyFrame() ? RtmpFrameType::key_frame : RtmpFrameType::inter_frame) << 4;
|
flags |= (uint8_t)(frame->keyFrame() ? RtmpFrameType::key_frame : RtmpFrameType::inter_frame) << 4;
|
||||||
|
|
||||||
@@ -145,18 +145,18 @@ void VpxRtmpEncoder::makeConfigPacket() {
|
|||||||
header->pkt_type = (int)RtmpPacketType::PacketTypeSequenceStart;
|
header->pkt_type = (int)RtmpPacketType::PacketTypeSequenceStart;
|
||||||
header->frame_type = (int)RtmpFrameType::key_frame;
|
header->frame_type = (int)RtmpFrameType::key_frame;
|
||||||
switch (getTrack()->getCodecId()) {
|
switch (getTrack()->getCodecId()) {
|
||||||
case CodecVP8: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp8); break;
|
case CodecVP8: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp8); break;
|
||||||
case CodecVP9: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp9); break;
|
case CodecVP9: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_vp9); break;
|
||||||
case CodecAV1: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_av1); break;
|
case CodecAV1: header->fourcc = htonl((uint32_t)RtmpVideoCodec::fourcc_av1); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
switch (getTrack()->getCodecId()) {
|
switch (getTrack()->getCodecId()) {
|
||||||
case CodecVP8: flags = (uint8_t)RtmpVideoCodec::vp8; break;
|
case CodecVP8: flags = (uint8_t)RtmpVideoCodec::vp8; break;
|
||||||
case CodecVP9: flags = (uint8_t)RtmpVideoCodec::vp9; break;
|
case CodecVP9: flags = (uint8_t)RtmpVideoCodec::vp9; break;
|
||||||
case CodecAV1: flags = (uint8_t)RtmpVideoCodec::av1; break;
|
case CodecAV1: flags = (uint8_t)RtmpVideoCodec::av1; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
flags |= ((uint8_t)RtmpFrameType::key_frame << 4);
|
flags |= ((uint8_t)RtmpFrameType::key_frame << 4);
|
||||||
buff[0] = flags;
|
buff[0] = flags;
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ static CodecId getAudioCodecIdByAmf(const AMFValue &val) {
|
|||||||
case RtmpAudioCodec::adpcm: return CodecADPCM;
|
case RtmpAudioCodec::adpcm: return CodecADPCM;
|
||||||
case RtmpAudioCodec::g711a: return CodecG711A;
|
case RtmpAudioCodec::g711a: return CodecG711A;
|
||||||
case RtmpAudioCodec::g711u: return CodecG711U;
|
case RtmpAudioCodec::g711u: return CodecG711U;
|
||||||
case RtmpAudioCodec::opus: return CodecOpus;
|
case RtmpAudioCodec::opus:
|
||||||
|
case RtmpAudioCodec::fourcc_opus: return CodecOpus;
|
||||||
default: WarnL << "Unsupported codec: " << (int)type_id; return CodecInvalid;
|
default: WarnL << "Unsupported codec: " << (int)type_id; return CodecInvalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,7 +203,7 @@ AMFValue Factory::getAmfByCodecId(CodecId codecId) {
|
|||||||
case CodecH265: return enhanced ? AMFValue((int)RtmpVideoCodec::fourcc_hevc) : AMFValue((int)RtmpVideoCodec::h265);
|
case CodecH265: return enhanced ? AMFValue((int)RtmpVideoCodec::fourcc_hevc) : AMFValue((int)RtmpVideoCodec::h265);
|
||||||
case CodecG711A: return AMFValue((int)RtmpAudioCodec::g711a);
|
case CodecG711A: return AMFValue((int)RtmpAudioCodec::g711a);
|
||||||
case CodecG711U: return AMFValue((int)RtmpAudioCodec::g711u);
|
case CodecG711U: return AMFValue((int)RtmpAudioCodec::g711u);
|
||||||
case CodecOpus: return AMFValue((int)RtmpAudioCodec::opus);
|
case CodecOpus: return enhanced ? AMFValue((int)RtmpAudioCodec::fourcc_opus) : AMFValue((int)RtmpAudioCodec::opus);
|
||||||
case CodecADPCM: return AMFValue((int)RtmpAudioCodec::adpcm);
|
case CodecADPCM: return AMFValue((int)RtmpAudioCodec::adpcm);
|
||||||
case CodecMP3: return AMFValue((int)RtmpAudioCodec::mp3);
|
case CodecMP3: return AMFValue((int)RtmpAudioCodec::mp3);
|
||||||
case CodecAV1: return enhanced ? AMFValue((int)RtmpVideoCodec::fourcc_av1) : AMFValue((int)RtmpVideoCodec::av1);
|
case CodecAV1: return enhanced ? AMFValue((int)RtmpVideoCodec::fourcc_av1) : AMFValue((int)RtmpVideoCodec::av1);
|
||||||
|
|||||||
@@ -306,9 +306,9 @@ enum class RtmpVideoCodec : uint32_t {
|
|||||||
screen_video2 = 6, // Screen video version 2
|
screen_video2 = 6, // Screen video version 2
|
||||||
h264 = 7, // avc
|
h264 = 7, // avc
|
||||||
h265 = 12, // 国内扩展
|
h265 = 12, // 国内扩展
|
||||||
av1 = 13,
|
av1 = 13, // 国内扩展
|
||||||
vp8 = 14,
|
vp8 = 14, // 国内扩展
|
||||||
vp9 = 15,
|
vp9 = 15, // 国内扩展
|
||||||
// 增强型rtmp FourCC [AUTO-TRANSLATED:442b77fb]
|
// 增强型rtmp FourCC [AUTO-TRANSLATED:442b77fb]
|
||||||
// Enhanced rtmp FourCC
|
// Enhanced rtmp FourCC
|
||||||
fourcc_vp8 = MKBETAG('v', 'p', '0', '8'),
|
fourcc_vp8 = MKBETAG('v', 'p', '0', '8'),
|
||||||
@@ -358,7 +358,7 @@ enum class RtmpPacketType : uint8_t {
|
|||||||
//https://rtmp.veriskope.com/pdf/video_file_format_spec_v10_1.pdf
|
//https://rtmp.veriskope.com/pdf/video_file_format_spec_v10_1.pdf
|
||||||
|
|
||||||
// UB [4]; Format of SoundData
|
// UB [4]; Format of SoundData
|
||||||
enum class RtmpAudioCodec : uint8_t {
|
enum class RtmpAudioCodec : uint32_t {
|
||||||
/**
|
/**
|
||||||
0 = Linear PCM, platform endian
|
0 = Linear PCM, platform endian
|
||||||
1 = ADPCM
|
1 = ADPCM
|
||||||
@@ -379,9 +379,10 @@ enum class RtmpAudioCodec : uint8_t {
|
|||||||
mp3 = 2,
|
mp3 = 2,
|
||||||
g711a = 7,
|
g711a = 7,
|
||||||
g711u = 8,
|
g711u = 8,
|
||||||
FOURCC = 9, // Enhanced audio
|
ex_header = 9, // Enhanced audio; new, used to signal FOURCC mode
|
||||||
aac = 10,
|
aac = 10,
|
||||||
opus = 13 // 国内扩展
|
opus = 13, // 国内扩展
|
||||||
|
fourcc_opus = MKBETAG('O', 'p', 'u', 's')
|
||||||
};
|
};
|
||||||
|
|
||||||
// UI8;
|
// UI8;
|
||||||
|
|||||||
Reference in New Issue
Block a user