Commit 9d79fe87 authored by Tristan Matthews's avatar Tristan Matthews

* #15528: audiortp: use separate variables for encoder and decoder payload types

They might be different.
parent 0b818437
......@@ -142,7 +142,7 @@ int AudioRtpFactory::getSessionMedia()
if (rtpSession_ == NULL)
throw AudioRtpFactoryException("RTP session was null when trying to get session media type");
return rtpSession_->getCodecPayloadType();
return rtpSession_->getEncoderPayloadType();
}
void AudioRtpFactory::updateSessionMedia(const std::vector<AudioCodec*> &audioCodecs)
......
......@@ -92,7 +92,8 @@ AudioRtpRecord::AudioRtpRecord() :
, dtmfQueue_()
, audioCodecs_()
, audioCodecMutex_()
, codecPayloadType_(0)
, encoderPayloadType_(0)
, decoderPayloadType_(0)
, hasDynamicPayloadType_(false)
, decData_() // std::tr1::arrays will be 0-initialized
, resampledData_()
......@@ -144,7 +145,7 @@ bool AudioRtpRecord::tryToSwitchPayloadTypes(int newPt)
{
for (std::vector<AudioCodec *>::iterator i = audioCodecs_.begin(); i != audioCodecs_.end(); ++i)
if (*i and (*i)->getPayloadType() == newPt) {
codecPayloadType_ = (*i)->getPayloadType();
decoderPayloadType_ = (*i)->getPayloadType();
codecSampleRate_ = (*i)->getClockRate();
codecFrameSize_ = (*i)->getFrameSize();
hasDynamicPayloadType_ = (*i)->hasDynamicPayload();
......@@ -204,7 +205,7 @@ void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCod
audioRtpRecord_.audioCodecs_ = audioCodecs;
audioRtpRecord_.currentCodecIndex_ = 0;
audioRtpRecord_.codecPayloadType_ = audioCodecs[0]->getPayloadType();
audioRtpRecord_.encoderPayloadType_ = audioRtpRecord_.decoderPayloadType_ = audioCodecs[0]->getPayloadType();
audioRtpRecord_.codecSampleRate_ = audioCodecs[0]->getClockRate();
audioRtpRecord_.codecFrameSize_ = audioCodecs[0]->getFrameSize();
audioRtpRecord_.hasDynamicPayloadType_ = audioCodecs[0]->hasDynamicPayload();
......@@ -316,12 +317,12 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
{
if (audioRtpRecord_.isDead())
return;
if (audioRtpRecord_.codecPayloadType_ != payloadType) {
if (audioRtpRecord_.decoderPayloadType_ != payloadType) {
const bool switched = audioRtpRecord_.tryToSwitchPayloadTypes(payloadType);
if (not switched) {
if (!warningInterval_) {
warningInterval_ = 250;
WARN("Invalid payload type %d, expected %d", payloadType, audioRtpRecord_.codecPayloadType_);
WARN("Invalid payload type %d, expected %d", payloadType, audioRtpRecord_.decoderPayloadType_);
}
warningInterval_--;
return;
......
......@@ -82,7 +82,10 @@ class AudioRtpRecord {
private:
std::vector<AudioCodec*> audioCodecs_;
ost::Mutex audioCodecMutex_;
int codecPayloadType_;
// these will have the same value unless we are sending
// a different codec than we are receiving (asymmetric RTP)
int encoderPayloadType_;
int decoderPayloadType_;
bool hasDynamicPayloadType_;
std::tr1::array<SFLDataFormat, DEC_BUFFER_SIZE> decData_;
// FIXME: resampledData should be resized as needed
......@@ -132,8 +135,8 @@ class AudioRtpRecordHandler {
return audioRtpRecord_.audioCodecs_[0];
}
int getCodecPayloadType() const {
return audioRtpRecord_.codecPayloadType_;
int getEncoderPayloadType() const {
return audioRtpRecord_.encoderPayloadType_;
}
int getCodecSampleRate() const {
......
......@@ -84,7 +84,7 @@ void AudioRtpSession::setSessionMedia(const std::vector<AudioCodec*> &audioCodec
setRtpMedia(audioCodecs);
// G722 requires timestamp to be incremented at 8kHz
const ost::PayloadType payloadType = getCodecPayloadType();
const ost::PayloadType payloadType = getEncoderPayloadType();
if (payloadType == ost::sptG722) {
const int G722_RTP_TIME_INCREMENT = 160;
timestampIncrement_ = G722_RTP_TIME_INCREMENT;
......@@ -134,7 +134,7 @@ void AudioRtpSession::sendDtmfEvent()
}
// restore the payload to audio
const ost::StaticPayloadFormat pf(static_cast<ost::StaticPayloadType>(getCodecPayloadType()));
const ost::StaticPayloadFormat pf(static_cast<ost::StaticPayloadType>(getEncoderPayloadType()));
queue_.setPayloadFormat(pf);
// decrease length remaining to process for this event
......
......@@ -287,7 +287,9 @@ void SDPTest::testReinvite()
CPPUNIT_ASSERT(session_->getLocalIP() == LOCALHOST);
CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
sfl::AudioCodec *codec = session_->getSessionAudioMedia();
std::vector<sfl::AudioCodec*> codecs;
session_->getSessionAudioMedia(codecs);
sfl::AudioCodec *codec = codecs[0];
CPPUNIT_ASSERT(codec and codec->getMimeSubtype() == "PCMU");
pjmedia_sdp_session *reinviteOffer;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment