Search in sources :

Example 1 with AudioData

use of org.red5.server.net.rtmp.event.AudioData 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)

Example 2 with AudioData

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

the class FlashToSipAudioStream method start.

public void start(IBroadcastStream broadcastStream, IScope scope) throws StreamException {
    if (log.isDebugEnabled())
        log.debug("startTranscodingStream({},{})", broadcastStream.getPublishedName(), scope.getName());
    mInputListener = new IStreamListener() {

        public void packetReceived(IBroadcastStream broadcastStream, IStreamPacket packet) {
            IoBuffer buf = packet.getData();
            if (buf != null)
                buf.rewind();
            if (buf == null || buf.remaining() == 0) {
                log.debug("skipping empty packet with no data");
                return;
            }
            if (packet instanceof AudioData) {
                byte[] data = SerializeUtils.ByteBufferToByteArray(buf);
                // Remove the first byte as it is the codec id.
                transcoder.handlePacket(data, 1, data.length - 1);
            }
        }
    };
    broadcastStream.addStreamListener(mInputListener);
    rtpSender = new RtpStreamSender(srcSocket, connInfo);
    rtpSender.connect();
    transcoder.start();
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) AudioData(org.red5.server.net.rtmp.event.AudioData) IBroadcastStream(org.red5.server.api.stream.IBroadcastStream) IStreamPacket(org.red5.server.api.stream.IStreamPacket) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 3 with AudioData

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

the class PcmToNellyTranscoder method pushAudio.

private void pushAudio(byte[] audio) {
    IoBuffer buffer = IoBuffer.allocate(1024);
    buffer.setAutoExpand(true);
    buffer.clear();
    buffer.put((byte) NELLYMOSER_CODEC_ID);
    byte[] copy = new byte[audio.length];
    System.arraycopy(audio, 0, copy, 0, audio.length);
    buffer.put(copy);
    buffer.flip();
    AudioData audioData = new AudioData(buffer);
    audioData.setTimestamp((int) (System.currentTimeMillis() - start));
    listener.handleTranscodedAudioData(audioData);
}
Also used : AudioData(org.red5.server.net.rtmp.event.AudioData) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 4 with AudioData

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

the class SpeexToSpeexTranscoder method pushAudio.

private void pushAudio(byte[] audio) {
    timestamp = timestamp + audio.length;
    IoBuffer buffer = IoBuffer.allocate(1024);
    buffer.setAutoExpand(true);
    buffer.clear();
    buffer.put((byte) SPEEX_CODEC);
    byte[] copy = new byte[audio.length];
    System.arraycopy(audio, 0, copy, 0, audio.length);
    buffer.put(copy);
    buffer.flip();
    AudioData audioData = new AudioData(buffer);
    audioData.setTimestamp((int) timestamp);
    listener.handleTranscodedAudioData(audioData);
}
Also used : AudioData(org.red5.server.net.rtmp.event.AudioData) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)3 AudioData (org.red5.server.net.rtmp.event.AudioData)3 IConnection (org.red5.server.api.IConnection)1 IBroadcastStream (org.red5.server.api.stream.IBroadcastStream)1 IStreamListener (org.red5.server.api.stream.IStreamListener)1 IStreamPacket (org.red5.server.api.stream.IStreamPacket)1 RTMPMinaConnection (org.red5.server.net.rtmp.RTMPMinaConnection)1