Bug 818618: Honor (and emit) opus stereo fmtp param. r=jesup

MozReview-Commit-ID: IgA305eiu1s
This commit is contained in:
Byron Campen [:bwc] 2016-02-26 10:47:03 -06:00
parent 3219bbc79f
commit a70cee5b5c
6 changed files with 46 additions and 9 deletions

View File

@ -131,7 +131,8 @@ class JsepAudioCodecDescription : public JsepCodecDescription {
clock, channels, enabled),
mPacketSize(packetSize),
mBitrate(bitRate),
mMaxPlaybackRate(0)
mMaxPlaybackRate(0),
mForceMono(false)
{
}
@ -160,10 +161,16 @@ class JsepAudioCodecDescription : public JsepCodecDescription {
return;
}
if (mName == "opus" && mMaxPlaybackRate) {
if (mName == "opus") {
SdpFmtpAttributeList::OpusParameters opusParams(
GetOpusParameters(mDefaultPt, msection));
opusParams.maxplaybackrate = mMaxPlaybackRate;
if (mMaxPlaybackRate) {
opusParams.maxplaybackrate = mMaxPlaybackRate;
}
if (mChannels == 2 && !mForceMono) {
// We prefer to receive stereo, if available.
opusParams.stereo = 1;
}
msection.SetFmtp(SdpFmtpAttributeList::Fmtp(mDefaultPt, opusParams));
}
}
@ -178,6 +185,7 @@ class JsepAudioCodecDescription : public JsepCodecDescription {
GetOpusParameters(mDefaultPt, remoteMsection));
mMaxPlaybackRate = opusParams.maxplaybackrate;
mForceMono = !opusParams.stereo;
}
return true;
@ -186,6 +194,7 @@ class JsepAudioCodecDescription : public JsepCodecDescription {
uint32_t mPacketSize;
uint32_t mBitrate;
uint32_t mMaxPlaybackRate;
bool mForceMono;
};
class JsepVideoCodecDescription : public JsepCodecDescription {

View File

@ -72,7 +72,7 @@ JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec,
desc.mName,
desc.mClock,
desc.mPacketSize,
desc.mChannels,
desc.mForceMono ? 1 : desc.mChannels,
desc.mBitrate);
(*aConfig)->mMaxPlaybackRate = desc.mMaxPlaybackRate;

View File

@ -1239,10 +1239,12 @@ public:
class OpusParameters : public Parameters
{
public:
enum { kDefaultMaxPlaybackRate = 48000 };
enum { kDefaultMaxPlaybackRate = 48000,
kDefaultStereo = 0 };
OpusParameters() :
Parameters(SdpRtpmapAttributeList::kOpus),
maxplaybackrate(kDefaultMaxPlaybackRate)
maxplaybackrate(kDefaultMaxPlaybackRate),
stereo(kDefaultStereo)
{}
Parameters*
@ -1254,10 +1256,12 @@ public:
void
Serialize(std::ostream& os) const override
{
os << "maxplaybackrate=" << maxplaybackrate;
os << "maxplaybackrate=" << maxplaybackrate << ";"
<< "stereo=" << stereo;
}
unsigned int maxplaybackrate;
unsigned int stereo;
};
class Fmtp

View File

@ -724,6 +724,7 @@ SipccSdpAttributeList::LoadFmtp(sdp_t* sdp, uint16_t level)
SdpFmtpAttributeList::OpusParameters* opusParameters(
new SdpFmtpAttributeList::OpusParameters);
opusParameters->maxplaybackrate = fmtp->maxplaybackrate;
opusParameters->stereo = fmtp->stereo;
parameters.reset(opusParameters);
} break;
default: {

View File

@ -481,6 +481,21 @@ TEST_F(JsepTrackTest, SimulcastAnswerer)
}; \
}
#define VERIFY_OPUS_FORCE_MONO(track, expected) \
{ \
JsepTrack& copy(track); \
ASSERT_TRUE(copy.GetNegotiatedDetails()); \
ASSERT_TRUE(copy.GetNegotiatedDetails()->GetEncodingCount()); \
for (auto codec : copy.GetNegotiatedDetails()->GetEncoding(0).GetCodecs()) {\
if (codec->mName == "opus") { \
JsepAudioCodecDescription* audioCodec = \
static_cast<JsepAudioCodecDescription*>(codec); \
/* gtest has some compiler warnings when using ASSERT_EQ with booleans. */ \
ASSERT_EQ((int)(expected), (int)audioCodec->mForceMono); \
} \
}; \
}
TEST_F(JsepTrackTest, DefaultOpusParameters)
{
Init(SdpMediaSection::kAudio);
@ -491,7 +506,9 @@ TEST_F(JsepTrackTest, DefaultOpusParameters)
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mSendAns,
SdpFmtpAttributeList::OpusParameters::kDefaultMaxPlaybackRate);
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mRecvOff, 0U);
VERIFY_OPUS_FORCE_MONO(*mRecvOff, false);
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mRecvAns, 0U);
VERIFY_OPUS_FORCE_MONO(*mRecvAns, false);
}
TEST_F(JsepTrackTest, NonDefaultOpusParameters)
@ -502,6 +519,7 @@ TEST_F(JsepTrackTest, NonDefaultOpusParameters)
JsepAudioCodecDescription* audioCodec =
static_cast<JsepAudioCodecDescription*>(codec);
audioCodec->mMaxPlaybackRate = 16000;
audioCodec->mForceMono = true;
}
}
InitTracks(SdpMediaSection::kAudio);
@ -509,10 +527,14 @@ TEST_F(JsepTrackTest, NonDefaultOpusParameters)
OfferAnswer();
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mSendOff, 16000U);
VERIFY_OPUS_FORCE_MONO(*mSendOff, true);
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mSendAns,
SdpFmtpAttributeList::OpusParameters::kDefaultMaxPlaybackRate);
VERIFY_OPUS_FORCE_MONO(*mSendAns, false);
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mRecvOff, 0U);
VERIFY_OPUS_FORCE_MONO(*mRecvOff, false);
VERIFY_OPUS_MAX_PLAYBACK_RATE(*mRecvAns, 16000U);
VERIFY_OPUS_FORCE_MONO(*mRecvAns, true);
}
} // namespace mozilla

View File

@ -1143,7 +1143,7 @@ const std::string kBasicAudioVideoOffer =
"c=IN IP4 0.0.0.0" CRLF
"a=mid:first" CRLF
"a=rtpmap:109 opus/48000/2" CRLF
"a=fmtp:109 maxplaybackrate=32000" CRLF
"a=fmtp:109 maxplaybackrate=32000;stereo=1" CRLF
"a=ptime:20" CRLF
"a=maxptime:20" CRLF
"a=rtpmap:9 G722/8000" CRLF
@ -1505,7 +1505,7 @@ const std::string kH264AudioVideoOffer =
"a=rtpmap:0 PCMU/8000" CRLF
"a=rtpmap:8 PCMA/8000" CRLF
"a=rtpmap:101 telephone-event/8000" CRLF
"a=fmtp:109 maxplaybackrate=32000" CRLF
"a=fmtp:109 maxplaybackrate=32000;stereo=1" CRLF
"a=ice-ufrag:00000000" CRLF
"a=ice-pwd:0000000000000000000000000000000" CRLF
"a=sendonly" CRLF
@ -1566,6 +1566,7 @@ TEST_P(NewSdpTest, CheckFormatParameters) {
static_cast<SdpFmtpAttributeList::OpusParameters*>(
audio_format_params[0].parameters.get());
ASSERT_EQ(32000U, opus_parameters->maxplaybackrate);
ASSERT_EQ(1U, opus_parameters->stereo);
ASSERT_TRUE(mSdp->GetMediaSection(1).GetAttributeList().HasAttribute(
SdpAttribute::kFmtpAttribute));