Java Code Examples for org.red5.io.IoConstants#TYPE_AUDIO

The following examples show how to use org.red5.io.IoConstants#TYPE_AUDIO . 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: M4AReader.java    From red5-io with Apache License 2.0 6 votes vote down vote up
/**
 * Tag sequence MetaData, Audio config, remaining audio
 * 
 * Packet prefixes: af 00 ... 06 = Audio extra data (first audio packet) af 01 = Audio frame
 * 
 * Audio extra data(s): af 00 = Prefix 11 90 4f 14 = AAC Main = aottype 0 12 10 = AAC LC = aottype 1 13 90 56 e5 a5 48 00 = HE-AAC SBR =
 * aottype 2 06 = Suffix
 * 
 * Still not absolutely certain about this order or the bytes - need to verify later
 */
private void createPreStreamingTags() {
    log.debug("Creating pre-streaming tags");
    if (audioDecoderBytes != null) {
        IoBuffer body = IoBuffer.allocate(audioDecoderBytes.length + 3);
        body.put(new byte[] { (byte) 0xaf, (byte) 0 }); //prefix
        if (log.isDebugEnabled()) {
            log.debug("Audio decoder bytes: {}", HexDump.byteArrayToHexString(audioDecoderBytes));
        }
        body.put(audioDecoderBytes);
        body.put((byte) 0x06); //suffix
        ITag tag = new Tag(IoConstants.TYPE_AUDIO, 0, body.position(), null, prevFrameSize);
        body.flip();
        tag.setBody(body);
        //add tag
        firstTags.add(tag);
    } else {
        //default to aac-lc when the esds doesnt contain descripter bytes
        log.warn("Audio decoder bytes were not available");
    }
}
 
Example 2
Source File: GenericWriterPostProcessor.java    From red5-io with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (file != null) {
        try {
            FLVReader reader = new FLVReader(file);
            ITag tag = null;
            int audio = 0, video = 0, meta = 0;
            while (reader.hasMoreTags()) {
                tag = reader.readTag();
                if (tag != null) {
                    switch (tag.getDataType()) {
                        case IoConstants.TYPE_AUDIO:
                            audio++;
                            break;
                        case IoConstants.TYPE_VIDEO:
                            video++;
                            break;
                        case IoConstants.TYPE_METADATA:
                            meta++;
                            break;
                    }
                }
            }
            reader.close();
            log.info("Data type counts - audio: {} video: {} metadata: {}", audio, video, meta);
        } catch (Exception e) {
            log.error("Exception reading: {}", file.getName(), e);
        }
    } else {
        log.warn("File for parsing was not found");
    }
}
 
Example 3
Source File: MP4Reader.java    From red5-io with Apache License 2.0 4 votes vote down vote up
/**
 * Tag sequence MetaData, Video config, Audio config, remaining audio and video
 * 
 * Packet prefixes: 17 00 00 00 00 = Video extra data (first video packet) 17 01 00 00 00 = Video keyframe 27 01 00 00 00 = Video
 * interframe af 00 ... 06 = Audio extra data (first audio packet) af 01 = Audio frame
 * 
 * Audio extra data(s): af 00 = Prefix 11 90 4f 14 = AAC Main = aottype 0 // 11 90 12 10 = AAC LC = aottype 1 13 90 56 e5 a5 48 00 =
 * HE-AAC SBR = aottype 2 06 = Suffix
 * 
 * Still not absolutely certain about this order or the bytes - need to verify later
 */
private void createPreStreamingTags(int timestamp, boolean clear) {
    log.debug("Creating pre-streaming tags");
    if (clear) {
        firstTags.clear();
    }
    ITag tag = null;
    IoBuffer body = null;
    if (hasVideo) {
        //video tag #1
        body = IoBuffer.allocate(41);
        body.setAutoExpand(true);
        body.put(PREFIX_VIDEO_CONFIG_FRAME); //prefix
        if (videoDecoderBytes != null) {
            //because of other processing we do this check
            if (log.isDebugEnabled()) {
                log.debug("Video decoder bytes: {}", HexDump.byteArrayToHexString(videoDecoderBytes));
            }
            body.put(videoDecoderBytes);
        }
        tag = new Tag(IoConstants.TYPE_VIDEO, timestamp, body.position(), null, 0);
        body.flip();
        tag.setBody(body);
        //add tag
        firstTags.add(tag);
    }
    // TODO: Handle other mp4 container audio codecs like mp3
    // mp3 header magic number ((int & 0xffe00000) == 0xffe00000) 
    if (hasAudio) {
        //audio tag #1
        if (audioDecoderBytes != null) {
            //because of other processing we do this check
            if (log.isDebugEnabled()) {
                log.debug("Audio decoder bytes: {}", HexDump.byteArrayToHexString(audioDecoderBytes));
            }
            body = IoBuffer.allocate(audioDecoderBytes.length + 3);
            body.setAutoExpand(true);
            body.put(PREFIX_AUDIO_CONFIG_FRAME); //prefix
            body.put(audioDecoderBytes);
            body.put((byte) 0x06); //suffix
            tag = new Tag(IoConstants.TYPE_AUDIO, timestamp, body.position(), null, 0);
            body.flip();
            tag.setBody(body);
            //add tag
            firstTags.add(tag);
        } else {
            log.info("Audio decoder bytes were not available");
        }
    }
}