I have seen a lot of posts related to audio streaming. I have an application that performs audio recording and playing using Input/Output Streaming APIs. It initializes both these objects in ConstructL(). It also initializes an Array(100 buffers) of TBuf8(each of max length 1024). It maintains 2 variables iRecordBufCnt and iSentBufCnt, both initialized to 0.
It then asks the user to enter IP Address and port to communicate with. The application makes a UDP connection with this destination. On the other side, the app displays a message to the user to Accept/Reject this connection. On sending the Accept response, the application opens the OutputStream for playing received audio data and on receiving an Accept response, the application opens the InputStream for recording and sending audio data.
Recording side - Receipt of the Accept response also starts a thread which calls a TimerExpired() after every 20msec. Now once the input stream is opened, I pass the first buffer in the array for recording and increment the iRecordBufCnt value. This is repeated in subsequent MaiscBufferCopied method calls. In every call to the TimerExpired() method, I take an already recorded buffer from the array (if available), add RTP headers to it and send it over UDP and increment the iSentBufCnt value. This is done in a cyclic manner in the array.
Playing side - Once the OutputStream is open, the app waits for an incoming RTP packet. When such a packet is received, I strip off the RTP headers and pass the resulting TBuf8 to outputstream.WriteL(); I need not do anything in the MaoscBufferCopied method.
Logically the above code seems alright and it also functions as desired. But whatever I speak at one end is not audible at the other end. There could be various reasons. After a lot of experimentation, I found that everything else seems to be alright except the call to the MaiscBufferCopied() method while recording. Although the buffer passed for recording is of length 1024 bytes, this method seems to get called arbitrarily, with the buffer length varying from 80 bytes to 320 bytes. I need to know exactly when is the MaiscBufferCopied() method called. Does it depend upon time, size of the buffer passed for recording or something else?
Note: With EChannelsMono and a sampling rate of 8KHz, 320 bytes of 16-bit raw PCM audio data corresponds to 20msec.
Can anyone help me out?