org.red5.server.net.rtmp.event.AudioData Java Examples

The following examples show how to use org.red5.server.net.rtmp.event.AudioData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RTMPClientProtocolDecoderTest.java    From red5-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecodeBufferExTS() {
    //log.debug("\testDecodeBufferExTS");
    RTMPProtocolDecoder dec = new RTMPProtocolDecoder();
    RTMPConnection conn = new RTMPMinaConnection();
    Red5.setConnectionLocal(conn);
    RTMP rtmp = conn.getState();
    rtmp.setState(RTMP.STATE_CONNECTED);
    // lastHeader: Header [streamId=1, channelId=4, dataType=18, timerBase=0, timerDelta=0, size=309, extended=false]
    // get the local decode state
    RTMPDecodeState state = conn.getDecoderState();
    // meta and audio 4x chunks
    IoBuffer in = IoBuffer.wrap(IOUtils.hexStringToByteArray(
            "04000000000135120100000002000d40736574446174614672616d6502000a6f6e4d65746144617461080000000d00086475726174696f6e0040d518000000000000057769647468004064000000000000000668656967687400405e000000000000000d766964656f64617461726174650040686a000000000000096672616d657261746500403900000000c40000000c766964656f636f6465636964004000000000000000000d617564696f6461746172617465000000000000000000000f617564696f73616d706c65726174650040d5888000000000000f617564696f73616d706c6573697a65004030000000000000000673746572656f0100000c617564696f636f6465636964004000c40000000000000007656e636f64657202000d4c61766635362e31352e313032000866696c6573697a650000000000000000000000090400000000006908010000002afff340c400104002e62d4110009080200830107ea04cfa810710e0987f820ec130fc401897c1c0c70ff502008020eea04c1f0fe7fcb9fc10ff90d107c1f82008021feb07c1c04010041c20f89c1fff6b6edad93d99d8da6cd42a08e459095589d4b5fb9a4e679a1f4400001a00006a082afff342c41a19c91f225d89300055a47640c62cee7ccc85c08c42cadb6b56daebe65989f78c3ef3cfbd694ac0c34aa855ee0598a031f0a0686212d43631a4c59a926383c2d5201c5e9b7377"));
    Packet packet = null;
    do {
        packet = dec.decodePacket(conn, state, in);
    } while (packet == null);
    assertNotNull(packet);
    assertTrue(packet.getMessage() instanceof Notify);
    do {
        packet = dec.decodePacket(conn, state, in);
    } while (packet == null);
    assertNotNull(packet);
    assertTrue(packet.getMessage() instanceof AudioData);
}
 
Example #2
Source File: QueuedMediaData.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public QueuedMediaData(int timestamp, byte dataType, IStreamData streamData) {
    this.tag = ImmutableTag.build(dataType, timestamp, streamData.getData());
    if (streamData instanceof VideoData) {
        video = true;
        config = ((VideoData) streamData).isConfig();
        codecId = ((VideoData) streamData).getCodecId();
        frameType = ((VideoData) streamData).getFrameType();
    } else if (streamData instanceof AudioData) {
        audio = true;
        config = ((AudioData) streamData).isConfig();
    }
}
 
Example #3
Source File: RTMPProtocolEncoder.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Encode message.
 *
 * @param header
 *            RTMP message header
 * @param message
 *            RTMP message (event)
 * @return Encoded message data
 */
public IoBuffer encodeMessage(Header header, IRTMPEvent message) {
    IServiceCall call = null;
    switch (header.getDataType()) {
        case TYPE_CHUNK_SIZE:
            return encodeChunkSize((ChunkSize) message);
        case TYPE_INVOKE:
            log.trace("Invoke {}", message);
            call = ((Invoke) message).getCall();
            if (call != null) {
                log.debug("{}", call.toString());
                Object[] args = call.getArguments();
                if (args != null && args.length > 0) {
                    Object a0 = args[0];
                    if (a0 instanceof Status) {
                        Status status = (Status) a0;
                        //code: NetStream.Seek.Notify
                        if (StatusCodes.NS_SEEK_NOTIFY.equals(status.getCode())) {
                            //desc: Seeking 25000 (stream ID: 1).
                            int seekTime = Integer.valueOf(status.getDescription().split(" ")[1]);
                            log.trace("Seek to time: {}", seekTime);
                            // TODO make sure this works on stream ids > 1
                            //audio and video channels
                            int[] channels = new int[] { 5, 6 };
                            //if its a seek notification, reset the "mapping" for audio (5) and video (6)
                            RTMP rtmp = ((RTMPConnection) Red5.getConnectionLocal()).getState();
                            for (int channelId : channels) {
                                LiveTimestampMapping mapping = rtmp.getLastTimestampMapping(channelId);
                                if (mapping != null) {
                                    long timestamp = mapping.getClockStartTime() + (seekTime & 0xFFFFFFFFL);
                                    log.trace("Setting last stream time to: {}", timestamp);
                                    mapping.setLastStreamTime(timestamp);
                                } else {
                                    log.trace("No ts mapping for channel id: {}", channelId);
                                }
                            }
                        }
                    }
                }
            }
            return encodeInvoke((Invoke) message);
        case TYPE_NOTIFY:
            log.trace("Notify {}", message);
            call = ((Notify) message).getCall();
            if (call == null) {
                return encodeStreamMetadata((Notify) message);
            } else {
                return encodeNotify((Notify) message);
            }
        case TYPE_PING:
            if (message instanceof SetBuffer) {
                return encodePing((SetBuffer) message);
            } else if (message instanceof SWFResponse) {
                return encodePing((SWFResponse) message);
            } else {
                return encodePing((Ping) message);
            }
        case TYPE_BYTES_READ:
            return encodeBytesRead((BytesRead) message);
        case TYPE_AGGREGATE:
            log.trace("Encode aggregate message");
            return encodeAggregate((Aggregate) message);
        case TYPE_AUDIO_DATA:
            log.trace("Encode audio message");
            return encodeAudioData((AudioData) message);
        case TYPE_VIDEO_DATA:
            log.trace("Encode video message");
            return encodeVideoData((VideoData) message);
        case TYPE_FLEX_SHARED_OBJECT:
            return encodeFlexSharedObject((ISharedObjectMessage) message);
        case TYPE_SHARED_OBJECT:
            return encodeSharedObject((ISharedObjectMessage) message);
        case TYPE_SERVER_BANDWIDTH:
            return encodeServerBW((ServerBW) message);
        case TYPE_CLIENT_BANDWIDTH:
            return encodeClientBW((ClientBW) message);
        case TYPE_FLEX_MESSAGE:
            return encodeFlexMessage((FlexMessage) message);
        case TYPE_FLEX_STREAM_SEND:
            return encodeFlexStreamSend((FlexStreamSend) message);
        default:
            log.warn("Unknown object type: {}", header.getDataType());
    }
    return null;
}
 
Example #4
Source File: RTMPProtocolEncoder.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public IoBuffer encodeAudioData(AudioData audioData) {
    final IoBuffer result = audioData.getData();
    return result;
}
 
Example #5
Source File: RTMPProtocolDecoder.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public AudioData decodeAudioData(IoBuffer in) {
    return new AudioData(in.asReadOnlyBuffer());
}
 
Example #6
Source File: IEventDecoder.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Decodes audio data event.
 * 
 * @param in
 *            Byte buffer to decode
 * @return AudioData event
 */
public abstract AudioData decodeAudioData(IoBuffer in);
 
Example #7
Source File: IEventEncoder.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Encodes AudioData event to byte buffer.
 *
 * @param audioData
 *            AudioData event
 * @return Byte buffer
 */
public abstract IoBuffer encodeAudioData(AudioData audioData);