Android Open Source - voicelink Audio Recieve Manage






From Project

Back to project page voicelink.

License

The source code is released under:

Apache License

If you think the Android project voicelink listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.audio.recieve;
/*from w w  w . j  av  a 2  s .c  o m*/
import java.nio.ByteBuffer;

import android.annotation.SuppressLint;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;

public class AudioRecieveManage {

  public RecieveSocket recieveSocket;
  public AACLATMunPacketizer mAACLATMunPacketizer;

  public void initialize() {

    recieveSocket = new RecieveSocket();

    initializeMediaCodec();

    mAACLATMunPacketizer = new AACLATMunPacketizer();

    mAACLATMunPacketizer.inputDecoderBuffers = inputDecoderBuffers;
    mAACLATMunPacketizer.recieveSocket = recieveSocket;
    mAACLATMunPacketizer.decoder = decoder;

  }

  public void start() {
    recieveSocket.start();
    mAACLATMunPacketizer.start();
  }

  protected AudioQuality mRequestedQuality = AudioQuality.DEFAULT_AUDIO_QUALITY.clone();
  protected AudioQuality mQuality = mRequestedQuality.clone();

  public MediaCodecInputStream inputStream;

  public MediaCodec decoder;
  public ByteBuffer[] inputDecoderBuffers;
  public ByteBuffer[] outputDecoderBuffers;

  public int bufferSize;

  @SuppressLint({ "InlinedApi", "NewApi" })
  public void initializeMediaCodec() {

    bufferSize = AudioRecord.getMinBufferSize(mQuality.samplingRate, AudioFormat.CHANNEL_OUT_DEFAULT, AudioFormat.ENCODING_PCM_16BIT) * 2;

    decoder = MediaCodec.createDecoderByType("audio/mp4a-latm");
    MediaFormat format = new MediaFormat();
    format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
    format.setInteger(MediaFormat.KEY_BIT_RATE, mQuality.bitRate);
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, mQuality.samplingRate);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, bufferSize);
    decoder.configure(format, null, null, 0);

    decoder.start();

    inputDecoderBuffers = decoder.getInputBuffers();
    outputDecoderBuffers = decoder.getOutputBuffers();

  }

}




Java Source Code List

net.audio.example2.MainActivity.java
net.audio.example2.testActivity.java
net.audio.recieve.AACLATMunPacketizer.java
net.audio.recieve.AACStream.java
net.audio.recieve.AudioQuality.java
net.audio.recieve.AudioRecieveManage.java
net.audio.recieve.MediaCodecInputStream.java
net.audio.recieve.RecieveSocket.java
net.audio.send.AACLATMPacketizer.java
net.audio.send.AACStream.java
net.audio.send.AudioQuality.java
net.audio.send.AudioSendManage.java
net.audio.send.MediaCodecInputStream.java
net.audio.send.SendSocket.java