Search in sources :

Example 1 with AudioFrameBuffer

use of com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer 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)

Example 2 with AudioFrameBuffer

use of com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method handleTrackFrameData.

private void handleTrackFrameData(TrackFrameDataMessage message) throws Exception {
    RemoteAudioTrackExecutor executor = playingTracks.get(message.executorId);
    if (executor != null) {
        if (message.seekedPosition >= 0) {
            executor.clearSeek(message.seekedPosition);
        }
        AudioFrameBuffer buffer = executor.getAudioBuffer();
        executor.receivedData();
        AudioDataFormat format = executor.getConfiguration().getOutputFormat();
        for (AudioFrame frame : message.frames) {
            buffer.consume(new AudioFrame(frame.timecode, frame.data, frame.volume, format));
        }
        if (message.finished) {
            buffer.setTerminateOnEmpty();
            trackEnded(executor, false);
        }
    }
}
Also used : AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat) AudioFrameBuffer(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)

Aggregations

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