Search in sources :

Example 1 with TrackFrameRequestMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameRequestMessage in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method buildRequestBody.

private byte[] buildRequestBody() throws IOException {
    ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
    DataOutputStream output = new DataOutputStream(outputBytes);
    List<RemoteMessage> messages = new ArrayList<>();
    int queuedCount = queuedMessages.drainTo(messages);
    if (queuedCount > 0) {
        log.debug("Including {} queued messages in the request to {}.", queuedCount, nodeAddress);
    }
    for (RemoteAudioTrackExecutor executor : playingTracks.values()) {
        long pendingSeek = executor.getPendingSeek();
        AudioFrameBuffer buffer = executor.getAudioBuffer();
        int neededFrames = pendingSeek == -1 ? buffer.getRemainingCapacity() : buffer.getFullCapacity();
        messages.add(new TrackFrameRequestMessage(executor.getExecutorId(), neededFrames, executor.getVolume(), pendingSeek));
    }
    for (RemoteMessage message : messages) {
        mapper.encode(output, message);
    }
    mapper.endOutput(output);
    return outputBytes.toByteArray();
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TrackFrameRequestMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameRequestMessage) AudioFrameBuffer(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer)

Aggregations

RemoteMessage (com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage)1 TrackFrameRequestMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameRequestMessage)1 AudioFrameBuffer (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1