Commit 5a2bf8d1 by 夏楚 Committed by GitHub

完成对enhanced rtmp videocodecid的兼容 (#2718)

请查阅: https://github.com/veovera/enhanced-rtmp/issues/8
parent bd8ad2ea
......@@ -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;
}
}
......
......@@ -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 {
......
......@@ -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
......
......@@ -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);
......
......@@ -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;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论