How to get Android RTP audio stream?

I use Java to stream rtp sound from a microphone to my Android phone app, but I don’t hear any sound. There are no errors when setting up AudioGroup and AudioStream, so I assume that everything is going right. Here is the application side code:

    AudioStream audioStream;
    AudioGroup audioGroup;
    AudioCodec codec = AudioCodec.PCMU;
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    AudioManager audio = (AudioManager)getSystemService(AUDIO_SERVICE);
    audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
    audioGroup = new AudioGroup();
    audioGroup.setMode(AudioGroup.MODE_NORMAL);
    InetAddress inetAddress;
    try {
        inetAddress = InetAddress.getByName("163.11.62.208");
        audioStream = new AudioStream(inetAddress);
        audioStream.setMode(RtpStream.MODE_RECEIVE_ONLY);
        audioStream.setCodec(codec);


        InetAddress inetAddressRemote = InetAddress.getByName("163.11.169.206");
        audioStream.associate(inetAddressRemote, 5004);
        audioStream.join(audioGroup);
    }

The ffmpeg stream test I am using (which works on vlc Android player)

ffmpeg -f lavfi -i aevalsrc="sin(400*2*PI*t)" -ar 8000 -vcodec pcm_u8 -f rtp rtp://163.11.62.208:5004

Again .. This works in a VLC android, but not in my application. No mistakes. There is simply no sound.

Ok, I just noticed in LogCat that I am getting messages that it works. Here are some of the magazines.

stream[59] is configured as RAW 8kHz 32ms mode 0
D/AudioGroup﹕ stream[59] joins group[56]
group[56] switches from mode 0 to 1
stream[54] joins group[56]
getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioTrack﹕ getMinFrameCount=1280: afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
D/AudioGroup﹕ reported frame count: output 1280, input 320
D/AudioGroup﹕ adjusted frame count: output 1280, input 512
V/AudioTrack﹕ sampleRate 8000, channelMask 0x1, format 1
V/AudioTrack﹕ streamType 0
V/AudioTrack﹕ set() streamType 0, sampleRate 8000, format 1, frameCount 1280, flags 0000
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioTrack﹕ createTrack_l() output 2 afLatency 160
V/AudioTrack﹕ afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
V/AudioTrack﹕ minFrameCount: 1280, afFrameCount=960, minBufCount=8, sampleRate=8000, afSampleRate=48000, afLatency=160
V/AudioRecord﹕ sampleRate 8000, channelMask 0x10, format 1
V/AudioRecord﹕ inputSource 7
V/AudioRecord﹕ set(): sampleRate 8000, channelMask 0x10, frameCount 512
D/AudioRecord﹕ set(): voiceActivationState 0
D/AudioRecord﹕ Keep input Source type.
V/AudioRecord﹕ AudioRecord::set() minFrameCount = 320
V/AudioRecord﹕ set(): mSessionId 1827
V/AudioSystem﹕ ioConfigChanged() event 3, ioHandle 1828

: , . , , , /, . , .

+4
1

, <uses-permission android:name="android.permission.RECORD_AUDIO" /> .

, , , , Settings -> Apps -> (Click the Gear) -> App Permissions -> Microphone , .

, , .

+1

All Articles