使用android.net.rtp [英] using android.net.rtp

查看:447
本文介绍了使用android.net.rtp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的 android.net.rtp API。 在接收数据包,我想测试出android.net.rtp.AudioGroup

I'm trying to stream audio rtp packets on my tablet using the android.net.rtp api. Before receiving packets, I want to test out the android.net.rtp.AudioGroup

  • 在我创建的模式SEND_ONLY的AudioStream。
  • 创建于MODE_ECHO_SUP preSSION的AudioGroup
  • 音频流,然后加入Audiogroup。

不如果在AudioGroup从话筒接收,在扬声器上播放?我不关心它发送的数据包。我只是想测试通过在audiogroup扬声器功能从麦克风和回放录像。

Shouldnt the AudioGroup receive from the mic, play on the speaker? I am not concerned with it sending packets. I only want to test recording from mic and playback through the speaker functionality in the audiogroup.

在清单我确实有设置为使用互联网的权限,RECORD_AUDIO,modify_audio_settings(对于mode_in_communication)

In the MANIFEST I do have the permissions set to use Internet, Record_Audio, modify_audio_settings(for mode_in_communication)

在code是如下。         包rtp.stream;

The code is as follows. package rtp.stream;

    import android.app.Activity;
    import android.os.Bundle;
    import android.media.AudioManager;
    import android.net.rtp.*;

    import android.util.Log;

    import java.net.*;

    public class Rtpstream3_2 extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            // AudioManager
            AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
            audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

            // Initialize AudioStream and set codec
            AudioStream inRtpStream = null;
            try {
                inRtpStream = new AudioStream(createInet(127, 0, 0, 1));
            } catch (SocketException e) {
                Log.d("Quit", "Socket Error");
                System.exit(1);
            }
            inRtpStream.setMode(RtpStream.MODE_SEND_ONLY);
            inRtpStream.setCodec(AudioCodec.PCMU);
            inRtpStream.associate(createInet(10,2,0,165), 17222);

            // Initialize an AudioGroup and attach an AudioStream
            AudioGroup main_grp = new AudioGroup();
            main_grp.setMode(AudioGroup.MODE_ECHO_SUPPRESSION);
            inRtpStream.join(main_grp);
            Log.d("Log"," Group joined"+inRtpStream.getLocalPort());
        }

        private InetAddress createInet(int b1, int b2, int b3, int b4) {
            InetAddress addr = null;
            try {
                addr = InetAddress.getByAddress(new byte[] {(byte)b1, (byte)b2,
                                                            (byte)b4, (byte)b3
                                                            });
            } 
            catch (UnknownHostException e) {
                Log.d("Error", "Cannot create Inet address");
                System.exit(1);
            }
            return addr;
        }
    }

当我运行这在我的平板电脑上运行的版本的Andr​​oid 3.2 ,我不听自己的。我看到logcat的一个错误信息,告诉我,AudioGroup无法从AudioRecord(MIC)来读取。右在此之前,我看到来自AudioPolicyManager一个讯息,说已经有一个输入开始。但也有正在使用的麦克风没有其他应用程序。

When I run this on my tablet running version Android 3.2, I dont hear myself at all. I see a error message in logcat telling me that the AudioGroup is unable to read from the AudioRecord(mic). Right before this, I see a message from the AudioPolicyManager which says there is already in an input started. But there are no other application currently using the mic.

任何人看到类似之前的东西吗?任何想法都将AP preciated。

Anybody see something similar before? Any thoughts at all would be appreciated.

从日志的摘录如下。

    03-15 20:06:00.820: I/AudioService(286):  AudioFocus  requestAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
    03-15 20:06:00.820: D/AudioHardwareMot(6337): setMode(IN_COMMUNICATION)
    03-15 20:06:00.820: D/AudioHardwareMot(6337): Putting streams to standby
    03-15 20:06:00.820: D/AudioHardwareMot(6337): AudioStreamOutMot::standby called
    03-15 20:06:00.820: D/AudioHardwareMot(6337): Input 0x849f8 entering standby
    03-15 20:06:00.820: D/AcousticsModule(6337): Acoustics close stub called.
    03-15 20:06:00.820: D/AudioHardwareMot(6337): setMode(): mode is MODE_IN_COMMUNICATION. Calling enableecns
    03-15 20:06:00.820: D/AudioPostProcessor(6337): Reading ecns param file from /system/bin
    03-15 20:06:00.820: D/AudioPostProcessor(6337): enableEcns() called: found param file. mEcnsEnabled value =0
    03-15 20:06:00.820: D/AudioPostProcessor(6337): enableEcns(true)
    03-15 20:06:00.820: **D/AudioHardwareInterface(6337): setMode(IN_COMMUNICATION)**
    03-15 20:06:00.820: D/AudioHardwareMot(6337): setMode END
    03-15 20:06:00.820: D/AudioHardwareMot(6337): Capture session will read from ECNS thread
    03-15 20:06:00.820: D/AudioHardwareMot(6337): AudioStreamOutMot::setParameters() routing=8
    **03-15 20:06:00.820: D/AudioHardwareMot(6337): Entering doALSAInputRouting
    03-15 20:06:00.820: D/AudioHardwareMot(6337): Enter doALSAOutputRouting**
    03-15 20:06:00.828: D/AudioHardwareMot(6337): Output gain set
    03-15 20:06:00.828: D/AudioHardwareMot(6337): doRouting(): Calling mapaccy with accy 9, mNrec 1
    03-15 20:06:00.828: D/AudioHardwareMot(6337): doRouting devs: stereo 0, mono 0, input 0. Chose speaker None (gain 0xb) mic None (gain 0x1c1c)
    03-15 20:06:00.828: I/dalvikvm(7385): threadid=1: recursive native library load attempt (/system/lib/librtp_jni.so)
    **03-15 20:06:00.835: D/AudioGroup(7385): stream[38] is configured as PCMU 8kHz 20ms mode 1
    03-15 20:06:00.835: D/AudioGroup(7385): stream[42] is configured as RAW 8kHz 32ms mode 0
    03-15 20:06:00.835: D/AudioGroup(7385): stream[42] joins group[41]
    03-15 20:06:00.835: D/AudioGroup(7385): group[41] switches from mode 0 to 3
    03-15 20:06:00.835: D/AudioGroup(7385): stream[38] joins group[41]**
    03-15 20:06:00.835: D/Log(7385):  Group joined55442
    03-15 20:06:00.835: D/AudioHardwareMot(6337): Output latency, using cached value = 99
    03-15 20:06:00.835: D/AudioGroup(7385): reported frame count: output 789, input 800
    03-15 20:06:00.835: D/AudioGroup(7385): adjusted frame count: output 789, input 800
    03-15 20:06:00.835: D/AudioHardwareMot(6337): Output latency, using cached value = 99
    03-15 20:06:00.843: D/AudioHardwareMot(6337): Output latency, using cached value = 99
    03-15 20:06:00.843: D/AudioHardwareMot(6337): AudioHardwareMot::openInputStream enter
    03-15 20:06:00.843: D/AudioHardwareMot(6337): AudioStreamInMot::set(0xf9e8, 40000, 1, 10, 8000)
    03-15 20:06:00.843: D/Omap4ALSA(6337): open called for devices 00040000 in mode 3...
    03-15 20:06:00.851: I/gralloc(416): Unregistered ID: 10 handle: 0x92a7b0 size: 1280 x 800 fmt: 5 usage: 0x1300
    03-15 20:06:00.851: D/Omap4ALSA(6337): setCodecDefaultControls
    03-15 20:06:00.851: I/Omap4ALSA(6337): **Initialized ALSA CAPTURE device hw:0,1**
    03-15 20:06:00.851: D/AcousticsModule(6337): Acoustics set_params stub called with 0.
    03-15 20:06:00.851: D/AcousticsModule(6337): Acoustics close stub called.
    03-15 20:06:00.851: I/gralloc(416): Unregistered ID: 9 handle: 0x94f0e8 size: 1280 x 800 fmt: 5 usage: 0x1300
    03-15 20:06:00.851: D/AudioPostProcessor(6337): **Disabling beamformer due to unsupported sample rate**
    03-15 20:06:00.851: D/AudioHardwareMot(6337): Input bufSize from ALSA = 352
    03-15 20:06:00.851: D/AudioHardwareMot(6337): Output latency, using cached value = 99
    03-15 20:06:00.859: D/AudioGroup(7385): latency: output 197, input 100
    03-15 20:06:00.859: W/AudioPolicyManagerBase(6337): startInput() input 1559 failed: other input already started
    03-15 20:06:00.882: E/AudioGroup(7385): **cannot read from AudioRecord**
    03-15 20:06:00.902: W/AudioPolicyManagerBase(89): startInput() input 10711 failed: other input already started

在所有的任何指针将大大AP preciated。

Any pointers at all would be greatly appreciated.

推荐答案

我想你应该设置!扬声器

I think you should set the speaker on!

也许你可以使用下面的方法:

Maybe you can use the following method:

audioManager.setSpeakerphoneOn(true);

这篇关于使用android.net.rtp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆