Search in sources :

Example 1 with RTMPMinaConnection

use of org.red5.server.net.rtmp.RTMPMinaConnection in project bigbluebutton by bigbluebutton.

the class NellySipToFlashTranscoderImp method transcode.

@Override
public void transcode(byte[] audioData) {
    if (audioData.length != ULAW_AUDIO_LENGTH) {
        if (log.isWarnEnabled())
            log.warn("Received corrupt audio. Got {}, expected {}.", audioData.length, ULAW_AUDIO_LENGTH);
        return;
    }
    // Convert Ulaw to L16
    audioCodec.codecToPcm(audioData, tempL16Buffer);
    // Store into the buffer
    l16Audio.put(tempL16Buffer);
    if ((l16Audio.position() - viewBuffer.position()) >= L16_AUDIO_LENGTH) {
        // We have enough L16 audio to generate a Nelly audio.
        // Get some L16 audio
        viewBuffer.get(tempNellyBuffer);
        // Convert it into Nelly
        encoderMap = CodecImpl.encode(encoderMap, tempNellyBuffer, nellyBytes);
        // Having done all of that, we now see if we need to send the audio or drop it.
        // We have to encode to build the encoderMap so that data from previous audio packet 
        // will be used for the next packet.			
        boolean sendPacket = true;
        IConnection conn = Red5.getConnectionLocal();
        if (conn instanceof RTMPMinaConnection) {
            long pendingMessages = ((RTMPMinaConnection) conn).getPendingMessages();
            if (pendingMessages > 25) {
                // Message backed up probably due to slow connection to client (25 messages * 20ms ptime = 500ms audio)
                sendPacket = false;
                if (log.isInfoEnabled())
                    log.info("Dropping packet. Connection {} congested with {} pending messages (~500ms worth of audio) .", conn.getClient().getId(), pendingMessages);
            }
        }
        if (sendPacket)
            transcodedAudioListener.handleTranscodedAudioData(nellyBytes, timestamp += TS_INCREMENT);
    }
    if (l16Audio.position() == l16Audio.capacity()) {
        // We've processed 8 Ulaw packets (5 Nelly packets), reset the buffers.
        l16Audio.clear();
        viewBuffer.clear();
    }
}
Also used : IConnection(org.red5.server.api.IConnection) RTMPMinaConnection(org.red5.server.net.rtmp.RTMPMinaConnection)

Aggregations

IConnection (org.red5.server.api.IConnection)1 RTMPMinaConnection (org.red5.server.net.rtmp.RTMPMinaConnection)1