Skip to content

Commit c32345d

Browse files
authored
media_engine: Properly return codec when not negotiated (#595)
* test: media_engine: Add Ambiguous payload type test Ported from pion * media_engine: Properly return codec when not negotiated
1 parent 4bb9614 commit c32345d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

webrtc/src/api/media_engine/media_engine_test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ a=fmtp:112 minptime=10; useinbandfec=1
123123
assert_eq!(opus_codec.capability.mime_type, MIME_TYPE_OPUS);
124124
}
125125

126+
//"Ambiguous Payload Type"
127+
{
128+
const OPUS_AMBIGUOUS_PAYLOAD: &str = "v=0
129+
o=- 4596489990601351948 2 IN IP4 127.0.0.1
130+
s=-
131+
t=0 0
132+
m=audio 9 UDP/TLS/RTP/SAVPF 96
133+
a=rtpmap:96 opus/48000/2
134+
a=fmtp:96 minptime=10; useinbandfec=1
135+
";
136+
137+
let mut m = MediaEngine::default();
138+
m.register_default_codecs()?;
139+
m.update_from_remote_description(&must_parse(OPUS_AMBIGUOUS_PAYLOAD)?)
140+
.await?;
141+
142+
assert!(!m.negotiated_video.load(Ordering::SeqCst));
143+
assert!(m.negotiated_audio.load(Ordering::SeqCst));
144+
145+
let (opus_codec, _) = m.get_codec_by_payload(96).await?;
146+
assert_eq!(opus_codec.capability.mime_type, MIME_TYPE_OPUS);
147+
}
148+
126149
//"Case Insensitive"
127150
{
128151
const OPUS_UPCASE: &str = "v=0

webrtc/src/api/media_engine/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,22 +465,36 @@ impl MediaEngine {
465465
&self,
466466
payload_type: PayloadType,
467467
) -> Result<(RTCRtpCodecParameters, RTPCodecType)> {
468-
{
468+
if self.negotiated_video.load(Ordering::SeqCst) {
469469
let negotiated_video_codecs = self.negotiated_video_codecs.lock();
470470
for codec in &*negotiated_video_codecs {
471471
if codec.payload_type == payload_type {
472472
return Ok((codec.clone(), RTPCodecType::Video));
473473
}
474474
}
475475
}
476-
{
476+
if self.negotiated_audio.load(Ordering::SeqCst) {
477477
let negotiated_audio_codecs = self.negotiated_audio_codecs.lock();
478478
for codec in &*negotiated_audio_codecs {
479479
if codec.payload_type == payload_type {
480480
return Ok((codec.clone(), RTPCodecType::Audio));
481481
}
482482
}
483483
}
484+
if !self.negotiated_video.load(Ordering::SeqCst) {
485+
for codec in &self.video_codecs {
486+
if codec.payload_type == payload_type {
487+
return Ok((codec.clone(), RTPCodecType::Video));
488+
}
489+
}
490+
}
491+
if !self.negotiated_audio.load(Ordering::SeqCst) {
492+
for codec in &self.audio_codecs {
493+
if codec.payload_type == payload_type {
494+
return Ok((codec.clone(), RTPCodecType::Audio));
495+
}
496+
}
497+
}
484498

485499
Err(Error::ErrCodecNotFound)
486500
}

0 commit comments

Comments
 (0)