Bonjour a tous,
Je cherche à transférer un flux audio en utilisant des sockets en UDP.
Le flux est déjà subdivisé en plusieurs petits paquets UDP que j'envoie
en permanence du Client vers le Serveur, les données envoyées sont de
type byte[].
Cependant je me demande si les objets Datagrampacket peuvent être
identifiés par un numéro de séquence (méthode renvoyant le num du
paquet) ou si je dois moi-même donner un numéro de séquence (en byte
toujours) pour chaque paquet transmis, dans ce cas comment puis-je
fusionner deux arrays byte[] (un pour le numéro de séquence et un pour
les données audio) dans un seul que je transmettrai dans le
Datagrampacket?
Merci d'avance pour vos réponses.
Si jamais voilà le bout de code pour l'applic client:
tout se passe dans la classe audioInputBlockReady qui reçoit ce bout de
flux audio (inputbuffer) et qui le convertit en paquet UDP.
public void audioInputBlockReady(AudioThread audiothread, byte[] inputbuffer){
/*
* TODO
*
* When the AudioThread is running, this method is periodically called
* by the AudioThread to indicate that new block of audio data is ready.
* Note that this method is actually executed within the AudioThread
* thread - don't forget to synchronize your objects.
*
* Imagine you are using audio block of 800 bytes (=400 samples). Since
* we are sampling at 8000 samples per second (given by AudioThread),
* such a block would correspond to 50 ms. Hence, this method would be
* called 20 times per second with an "inputbuffer" containing 800
* bytes.
*
* In this method you may process, package and send these samples. Note
* that you should not use the inputbuffer object outside of this
* function. If you want to send its contents in a UDP datagram, for
* instance, you should rather copy the buffer to a new buffer, i.e.
*
* System.arraycopy(inputbuffer, 0, udpdatagram.getData(), ...,
* inputbuffer.length);
*/
InetAddress IPAddress = null;
//byte[] sequenceNumber = new byte[2];
try {
clientSocket = new DatagramSocket();
} catch (SocketException e) {
e.printStackTrace();
}
try {
IPAddress = InetAddress.getByName("host");
} catch (UnknownHostException e) {
e.printStackTrace();
}
byte[] sendData = new byte[inputbuffer.length]; //data ready to send
System.arraycopy(inputbuffer, 0, sendData, 0, inputbuffer.length);
/*Question: est ce que je dois faire le seqNumber moi-même ou est-ce
* que c'est déjà compris dans l'objet Socket??*/
byte[] receiveData = new byte[1024];
DatagramPacket sendPacket = new DatagramPacket(sendData,
sendData.length, IPAddress, portNumber);
try {
clientSocket.send(sendPacket);
countSentPackets++;
} catch (IOException e) {
e.printStackTrace();
}
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
try {
clientSocket.receive(receivePacket);
} catch (IOException e) {
e.printStackTrace();
}
LogSink.defaultLog.println("New input block of " + String.valueOf(inputbuffer.length) + " bytes available!");
}