另一个就是接收端,不停的接收发送出来的socket数据,这个socket数据就是实时的pcm流,接收方,在实时播放pcm流,就能实现音频的实时同步了。
关于视频流,是如何实现同步的,大家也可以猜猜?
1)AudioTrack.cpp中的代码实现
#define DEST_PORT 5046
#define DEST_IP_ADDRESS “192.168.7.6”
int mSocket;
bool mSocketHasInit;
bool mCurrentPlayMusicStream;
struct sockaddr_in mRemoteAddr;
ssize_t AudioTrack::write(const void* buffer, size_t userSize, bool blocking)
{
…
size_t toWrite = audioBuffer.size;
memcpy(audioBuffer.i8, buffer, toWrite);
mBuffer = malloc(toWrite);
memcpy(mBuffer,buffer,toWrite);
//我们添加的代码:把音频流实时的发送出去
if(mCurrentPlayMusicStream && mSocketHasInit){
onSocketSendData(toWrite);
}
…
}
int AudioTrack::onSocketSendData(uint32_t len){
assert(NULL != mBuffer);
as