Search in sources :

Example 1 with TrackFrameDataMessage

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

the class RemoteNodeProcessor method handleResponseBody.

private boolean handleResponseBody(InputStream inputStream, TickBuilder tickBuilder) {
    CountingInputStream countingStream = new CountingInputStream(inputStream);
    DataInputStream input = new DataInputStream(countingStream);
    RemoteMessage message;
    try {
        while ((message = mapper.decode(input)) != null) {
            if (message instanceof TrackStartResponseMessage) {
                handleTrackStartResponse((TrackStartResponseMessage) message);
            } else if (message instanceof TrackFrameDataMessage) {
                handleTrackFrameData((TrackFrameDataMessage) message);
            } else if (message instanceof TrackExceptionMessage) {
                handleTrackException((TrackExceptionMessage) message);
            } else if (message instanceof NodeStatisticsMessage) {
                handleNodeStatistics((NodeStatisticsMessage) message);
            }
        }
    } catch (InterruptedException interruption) {
        log.error("Node {} processing thread was interrupted.", nodeAddress);
        Thread.currentThread().interrupt();
        return false;
    } catch (Throwable e) {
        log.error("Error when processing response from node {}.", nodeAddress, e);
        ExceptionTools.rethrowErrors(e);
    } finally {
        tickBuilder.responseSize = countingStream.getCount();
    }
    return true;
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) TrackExceptionMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage) TrackStartResponseMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DataInputStream(java.io.DataInputStream) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Example 2 with TrackFrameDataMessage

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

the class PlayingTrackManager method handleTrackDataRequest.

@MessageHandler
private void handleTrackDataRequest(TrackFrameRequestMessage message, MessageOutput output) {
    List<AudioFrame> frames = new ArrayList<>();
    PlayingTrack track = tracks.get(message.executorId);
    boolean finished = false;
    if (track != null) {
        submitPendingMessages(track, output);
        track.lastFrameRequestTime = System.currentTimeMillis();
        track.volume.set(message.volume);
        if (message.seekPosition >= 0) {
            track.audioTrack.setPosition(message.seekPosition);
        }
        if (message.maximumFrames > 0) {
            track.lastNonZeroFrameRequestTime = track.lastFrameRequestTime;
        }
        finished = consumeFramesFromTrack(frames, track.audioTrack, message.maximumFrames);
        if (finished) {
            log.info("Clearing ended track {} (context {})", track.audioTrack.getIdentifier(), message.executorId);
            tracks.remove(message.executorId);
        }
    }
    output.send(new TrackFrameDataMessage(message.executorId, frames, finished, message.seekPosition));
}
Also used : ArrayList(java.util.ArrayList) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame) MessageHandler(com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)

Aggregations

TrackFrameDataMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage)2 MessageHandler (com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)1 NodeStatisticsMessage (com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)1 RemoteMessage (com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage)1 TrackExceptionMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage)1 TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)1 AudioFrame (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1