1

I am trying to stream live audio from an Axis network security camera over a Multipart HTTP stream that is encoded in g711 ulaw 8 khz, 8 bit samples on an Android phone. It seems like this should be pretty straight forward, and this is the basis of my code. I reused some streaming code I had that grabbed JPEG frames from a MJPEG stream, and now it grabs 512 byte blocks of audio data and hands it down to the AudioTrack. The audio sounds all garbled and distorted though, am I missing something obvious?

@Override
public void onResume() {
    super.onResume();
    int bufferSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT);
    mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, bufferSize, AudioTrack.MODE_STREAM);
    mAudioTrack.play();
    thread.start();
}

class StreamThread extends Thread {
    public boolean running = true;

    public void run() {
        try {
            MjpegStreamer streamer = MjpegStreamer.read("/axis-cgi/audio/receive.cgi?httptype=multipart");

            while(running) {
                byte[] buf = streamer.readMjpegFrame();
                if(buf != null && mAudioTrack != null) {
                    mAudioTrack.write(buf, 0, buf.length);
                }
            }


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
steji113
  • 335
  • 4
  • 13
  • 2
    `AudioTrack` expects uncompressed linear PCM. Does your `streamer.readMjpegFrame` method return PCM or ulaw audio data? – Michael May 02 '13 at 05:33
  • it returns ulaw audio data. how can i convert it into uncompressed linear PCM? – steji113 May 02 '13 at 20:12
  • 1
    Michael, that was the problem, thanks so much! I followed the instructions posted here: http://stackoverflow.com/questions/3251782/decode-g711pcm-u-law If you want to make this an answer I will accept it! Thanks. – steji113 May 02 '13 at 20:21

0 Answers0