匹配H264 profile

This commit is contained in:
xiongziliang 2021-04-06 23:21:46 +08:00
parent a42b56ba94
commit 204ef6e204

View File

@ -1524,12 +1524,41 @@ void RtcConfigure::setPlayRtspInfo(const string &sdp){
} }
} }
static map<string, string, StrCaseCompare> toMap(const vector<std::pair<string/*key*/, string/*value*/> > &fmt) {
map<string, string, StrCaseCompare> ret;
for (auto &pr : fmt) {
ret.emplace(pr);
}
return ret;
}
static const string kProfile{"profile-level-id"};
static const string kMode{"packetization-mode"};
bool RtcConfigure::onMatchCodecPlan(const RtcCodecPlan &plan, CodecId codec){ bool RtcConfigure::onMatchCodecPlan(const RtcCodecPlan &plan, CodecId codec){
if (_rtsp_audio_plan && codec == getCodecId(_rtsp_audio_plan->codec)) { if (_rtsp_audio_plan && codec == getCodecId(_rtsp_audio_plan->codec)) {
if (plan.sample_rate != _rtsp_audio_plan->sample_rate || plan.channel != _rtsp_audio_plan->channel) { if (plan.sample_rate != _rtsp_audio_plan->sample_rate || plan.channel != _rtsp_audio_plan->channel) {
//音频采样率和通道数必须相同 //音频采样率和通道数必须相同
return false; return false;
} }
return true;
}
if (_rtsp_video_plan && codec == CodecH264 && getCodecId(_rtsp_video_plan->codec) == CodecH264) {
//h264时匹配packetization-mode和profile-level-id
auto rtc_fmt_map = toMap(plan.fmtp);
auto rtsp_fmt_map = toMap(_rtsp_video_plan->fmtp);
auto &profile = rtsp_fmt_map[kProfile];
if (!profile.empty() && profile != rtc_fmt_map[kProfile]) {
//profile-level-id 不匹配
return false;
}
auto &mode = rtsp_fmt_map[kMode];
if (!mode.empty() && mode != rtc_fmt_map[kMode]) {
//packetization-mode不匹配
return false;
} }
return true; return true;
} }
return true;
}