[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "jitterbuffer" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Oct 17 13:46:14 CDT 2011
branch "jitterbuffer" has been updated
via 6905d722c0c98250cb314b56d544102fcb40f2b3 (commit)
from 9ba0da005d0586fc14b49a664b906420cf21ffa3 (commit)
Summary of changes:
src/JitterBufferOperation.cpp | 55 +++++++++++++++++++---------------------
1 files changed, 26 insertions(+), 29 deletions(-)
- Log -----------------------------------------------------------------
commit 6905d722c0c98250cb314b56d544102fcb40f2b3
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Oct 17 15:47:31 2011 -0300
Add working code for placing payloads into the jitterbuffer and for scheduling.
diff --git a/src/JitterBufferOperation.cpp b/src/JitterBufferOperation.cpp
index 3e2a570..bf7c058 100644
--- a/src/JitterBufferOperation.cpp
+++ b/src/JitterBufferOperation.cpp
@@ -15,6 +15,7 @@
*/
#include <boost/thread.hpp>
+#include <boost/asio/detail/socket_ops.hpp>
#include <IceUtil/UUID.h>
#include <IceUtil/Timer.h>
@@ -54,12 +55,14 @@ private:
const AudioFormatPtr& inFormat,
const AudioFormatPtr& outFormat,
boost::shared_mutex& mutex,
- int numFramesToPush)
+ int numFramesToPush,
+ const NetEqWrapperPtr& netEqWrapper)
: mSource(source),
mOutFormat(outFormat),
mInFormat(inFormat),
mLock(mutex),
- mNumFramesToPush(numFramesToPush)
+ mNumFramesToPush(numFramesToPush),
+ mNetEq(netEqWrapper)
{
}
@@ -103,12 +106,12 @@ private:
private:
TranslatorSourcePtr mSource;
- NetEqWrapperPtr mNetEq;
AudioFormatPtr mOutFormat;
AudioFormatPtr mInFormat;
long mSeqNumber;
boost::shared_mutex &mLock;
int mNumFramesToPush;
+ NetEqWrapperPtr mNetEq;
};
class JitterBuffer : public BufferedTranslator
@@ -122,8 +125,8 @@ private:
: BufferedTranslator(source, inputFormat, outputFormat, logger),
mNetEq(netEqWrapper),
mSsrc(rand()),
- mFrameCount(0),
- mBufferSending(false)
+ mBufferSending(false),
+ mTimer(new IceUtil::Timer())
{
mInAudioFormat = AudioFormatPtr::dynamicCast(inputFormat);
mOutAudioFormat = AudioFormatPtr::dynamicCast(outputFormat);
@@ -158,7 +161,12 @@ private:
rtpInfo.timeStamp = (WebRtc_UWord32)streamFrame->timestamp;
//rtpInfo.markerBit = // Assuming this one is safe to leave unset.
+ // WebRTC expects the payload to come straight from the network so we need to put it back in that state
ShortSeqPayloadPtr inPayload = ShortSeqPayloadPtr::dynamicCast(inFrame->payload);
+ std::transform(inPayload->payload.begin(), inPayload->payload.end(),
+ inPayload->payload.begin(), boost::asio::detail::socket_ops::host_to_network_short);
+ Ice::ByteSeq bytes((Ice::Byte*) &inPayload->payload.front(),
+ (Ice::Byte*) &inPayload->payload[inPayload->payload.size()]);
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
@@ -166,33 +174,23 @@ private:
// Buffer the frame.
WebRtcNetEQ_RecInRTPStruct(netEqInstance,
&rtpInfo,
- (WebRtc_UWord8*)&inPayload->payload.front(),
- (WebRtc_Word16)mInAudioFormat->frameSize,
+ &bytes.front(),
+ (WebRtc_Word16)bytes.size(),
(WebRtc_UWord32)IceUtil::Time::now().toMilliSeconds());
}
- mFrameCount++;
- if (!mBufferSending)
+ if (mBufferSending == false)
{
- int framesToBuffer = mNetEq->getBufferSizeInBytes() / mInAudioFormat->frameSize;
- if (mFrameCount >= framesToBuffer)
- {
- mBufferSending = true;
-
- // Compute the timer period, and use a configurable number of frames so
- // that the timer task isn't pushing single frames.
- const int framesToPush(10); // TBD... config item
-
- int frameDuration = mOutAudioFormat->sampleRate / mOutAudioFormat->frameSize;
-
- // Start a timer to push buffered frames.
- IceUtil::TimerTaskPtr sendTask = new JitterBufferSendTask(mSource,
- mInAudioFormat,
- mOutAudioFormat,
- mLock,
- framesToPush);
- mTimer->scheduleRepeated(sendTask, IceUtil::Time::milliSeconds(frameDuration * framesToPush));
- }
+ mBufferSending = true;
+
+ // Start a timer to push buffered frames.
+ IceUtil::TimerTaskPtr sendTask = new JitterBufferSendTask(mSource,
+ mInAudioFormat,
+ mOutAudioFormat,
+ mLock,
+ 1,
+ mNetEq);
+ mTimer->scheduleRepeated(sendTask, IceUtil::Time::milliSeconds(mOutAudioFormat->frameSize / (mOutAudioFormat->sampleRate / 1000)));
}
}
@@ -202,7 +200,6 @@ private:
AudioFormatPtr mOutAudioFormat;
NetEqWrapperPtr mNetEq;
WebRtc_UWord32 mSsrc;
- int mFrameCount;
bool mBufferSending;
IceUtil::TimerPtr mTimer;
};
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_operations_core.git
More information about the asterisk-scf-commits
mailing list