From b4390a3f803df6932dc1b5e1271d0a2224eafb02 Mon Sep 17 00:00:00 2001
From: asavard <asavard@asavard-KT378AA-A2L-a6552f.(none)>
Date: Wed, 27 Oct 2010 11:52:10 -0400
Subject: [PATCH] [#4367] Refactor mic data encoding in rtp session

---
 .../audio/audiortp/AudioRtpRecordHandler.cpp   | 18 ++++++------------
 .../src/audio/audiortp/AudioRtpSession.cpp     | 11 ++++-------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp b/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp
index 7995247659..bdab551501 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp
@@ -405,26 +405,19 @@ int AudioRtpRecordHandler::processDataEncode(void)
     float fixedCodecFramesize = computeCodecFrameSize(getCodecFrameSize(), getCodecSampleRate());
 
     // compute nb of byte to get coresponding to 20 ms at audio layer frame size (44.1 khz)
-    int maxBytesToGet = computeNbByteAudioLayer(fixedCodecFramesize);
+    int bytesToGet = computeNbByteAudioLayer(fixedCodecFramesize);
+
+    _debug("    byte to get %d", bytesToGet);
 
     // available bytes inside ringbuffer
     int availBytesFromMic = audioLayer->getMainBuffer()->availForGet(_ca->getCallId());
     _debug("    avail byte from mic %d", availBytesFromMic);
 
-    if(!(availBytesFromMic > 320))
+    if(availBytesFromMic < bytesToGet)
     	return 0;
 
-    // set available byte to maxByteToGet
-    int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet;
-
-    if(bytesAvail == 0){
-    	memset(micDataEncoded, 0, sizeof (SFLDataFormat));
-    	return getCodecFrameSize();
-    }
-
     // Get bytes from micRingBuffer to data_from_mic
-    // int nbSample = audioLayer->getMainBuffer()->getData(micData, bytesAvail, 100, _ca->getCallId()) / sizeof (SFLDataFormat);
-    int nbSample = audioLayer->getMainBuffer()->getData(micData, 320, 100, _ca->getCallId()) / sizeof (SFLDataFormat);
+    int nbSample = audioLayer->getMainBuffer()->getData(micData, bytesToGet, 100, _ca->getCallId()) / sizeof (SFLDataFormat);
 
     // process mic fade in
     if(!_audioRtpRecord.getMicFadeInComplete())
@@ -453,6 +446,7 @@ int AudioRtpRecordHandler::processDataEncode(void)
     	// no resampling required
     	compSize = audioCodec->codecEncode(micDataEncoded, micData, nbSample * sizeof (SFLDataFormat));
     }
+
     return compSize;
 }
 
diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
index d80dde79f0..ea0a6529a8 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
@@ -235,7 +235,7 @@ bool AudioRtpSession::onRTPPacketRecv (ost::IncomingRTPPkt&)
 
 void AudioRtpSession::sendMicData()
 {
-    // _debug("============== sendMicData ===============");
+    _debug("============== sendMicData ===============");
 
     int compSize = processDataEncode();
 
@@ -246,8 +246,8 @@ void AudioRtpSession::sendMicData()
     // Increment timestamp for outgoing packet
     _timestamp += _timestampIncrement;
 
-    // _debug("    compSize: %d", compSize);
-    // _debug("    timestamp: %d", _timestamp);
+    _debug("    compSize: %d", compSize);
+    _debug("    timestamp: %d", _timestamp);
 
     // putData put the data on RTP queue, sendImmediate bypass this queue
     putData (_timestamp, getMicDataEncoded(), compSize);
@@ -357,10 +357,7 @@ void AudioRtpSession::run ()
 			sendMicData ();
 		}
 
-		// Recv session
-		// TODO should not be called here anymore
-//		receiveSpeakerData ();
-
+		// This also should be moved
 		notifyIncomingCall();
 
 		_manager->getAudioLayerMutex()->leave();
-- 
GitLab