Package net.sf.fmj.media.codec.audio.gsm

Source Code of net.sf.fmj.media.codec.audio.gsm.DePacketizer

package net.sf.fmj.media.codec.audio.gsm;

import java.util.logging.Logger;

import javax.media.Format;
import javax.media.format.AudioFormat;

import net.sf.fmj.media.AbstractDePacketizer;
import net.sf.fmj.utility.LoggerSingleton;

/**
*
* DePacketizer for GSM/RTP.  Doesn't have to do much, just copies input to output.  Uses buffer-swapping observed in debugging
* and seen in other open-source DePacketizer implementations.
* @author Martin Harvan
*
*/
public class DePacketizer extends AbstractDePacketizer
{
  private static final Logger logger = LoggerSingleton.logger;

  @Override
  public String getName()
  {
    return "GSM DePacketizer";
  }

  public DePacketizer()
  {
    super();
    this.inputFormats = new Format[] {new AudioFormat(AudioFormat.GSM_RTP, 8000, 8, 1, -1, AudioFormat.SIGNED, 264, -1.0, Format.byteArray)};
  }

  // TODO: move to base class?
  protected Format[] outputFormats = new Format[] {new AudioFormat(AudioFormat.GSM, 8000, 8, 1, -1, AudioFormat.SIGNED, 264, -1.0, Format.byteArray)};

  @Override
  public Format[] getSupportedOutputFormats(Format input)
  {
    if (input == null)
      return outputFormats;
    else
    {            
      if (!(input instanceof AudioFormat))
      {  logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
        return new Format[] {null};
      }
      final AudioFormat inputCast = (AudioFormat) input;
      if (!inputCast.getEncoding().equals(AudioFormat.GSM_RTP))
      {
        logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
        return new Format[] {null};
      }
      final AudioFormat result = new AudioFormat(AudioFormat.GSM, inputCast.getSampleRate(), inputCast.getSampleSizeInBits(),
          inputCast.getChannels(), inputCast.getEndian(), inputCast.getSigned(), inputCast.getFrameSizeInBits(),
          inputCast.getFrameRate(), inputCast.getDataType());

      return new Format[] {result};
    }
  }

  @Override
  public void open()
  {
  }

  @Override
  public void close()
  {
  }


  @Override
  public Format setInputFormat(Format arg0)
  {
    return super.setInputFormat(arg0);
  }

  @Override
  public Format setOutputFormat(Format arg0)
  {
    return super.setOutputFormat(arg0);
  }


}
TOP

Related Classes of net.sf.fmj.media.codec.audio.gsm.DePacketizer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.