Starting the recvData Logic Thread
Application Scenario
Start the logic thread for receiving data in advance and register the audio callback object.
Prerequisites
A video stream engine object has been created.
Development Process
- Encapsulate the logic thread object UpstreamReceiveDispatcher and cyclically call the recvData interface function of the video stream engine.
- Registers the audio data callback function.
- Start the logic thread.
Encoding Instance
public class Activity implements BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
upstreamReceiveDispatcher = UpstreamReceiveDispatcher.getInstance();
upstreamReceiveDispatcher.setVideoEngine(engine);
// Audio data callback
audioPlayerCallback = new AudioPlayerCallback();
// Register the audio data callback function.
upstreamReceiveDispatcher.addNewPacketCallback((byte) VideoWrapper.AUDIO, audioPlayerCallback);
// Start the logic thread to receive audio data.
upstreamReceiveDispatcher.start();
}
}
public class UpstreamReceiveDispatcher {
@Override
public void run() {
byte[] recvBuf = new byte[MAX_BUF_LEN];
while (!stopFlag) {
// Call recvData cyclically to receive data.
int packetLen = engine.recvData(mtype, recvBuf, recvBuf.length);
if (packetLen > 0) {
byte[] copyData = new byte[packetLen];
System.arraycopy(recvBuf, 0, copyData, 0, packetLen);
// Call back the data to the hook function.
callback.onNewPacket(copyData);
continue;
}
}
}
}
Parent topic: Development Process of the Video Stream Engine Client