Android上多个应用不能同时调用AudioRecord

http://stackoverflow.com/questions/6646313/android-test-if-audio-record-focus-is-available

I am using AudioRecord to record audio for further proccessing. It seems that only one AudioRecord at a time can have access to the audio hardware. How can i check if the audio hardware is accessible, so that i can start recording? One possibility is to instantiate a AudioRecord instance and then check its state with AudioRecord.getState(). This will return, wether the AudioRecord-Instance was initialized properly. Is this the only way to do so? But there is another problem, which you have to address when doing audiorecording. What happens when another application wants to record? Is there any possibility to be notified if another application wants to record?

 

也就是说如果一个应用在使用音频输入,另一个应用就不能同时使用,否则,会返回错误,log如下:

failed: other input already started

 

看下代码就明白了:

/hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp

status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input) {
    ...
    // refuse 2 active AudioRecord clients at the same time
    if (getActiveInput() != 0) { 
        LOGW("startInput() input %d failed: other input already started", input);
        return INVALID_OPERATION;
    }
    ...
}

 

另外,AudioTrack有时候打印这样的log:

 
Underrun user: fb0, server: fb0, flags 0003

 下面是underrun和overrun的解释:

  • underrun

In computing, buffer underrun or buffer underflow is a state occurring when a buffer used to communicate between two devices or processes is fed with data at a lower speed than the data is being read from it. This requires the program or device reading from the buffer to pause its processing while the buffer refills. This can cause undesired and sometimes serious side effects because the data being buffered is generally not suited to stop-start access of this kind.

  • overrun

In computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer, overruns the buffer's boundary and overwrites adjacent memory. This is a special case of violation of memory safety.

Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program operates. This may result in erratic program behavior, including memory access errors, incorrect results, a crash, or a breach of system security. Thus, they are the basis of many software vulnerabilities and can be maliciously exploited.

Programming languages commonly associated with buffer overflows include C and C++, which provide no built-in protection against accessing or overwriting data in any part of memory and do not automatically check that data written to an array (the built-in buffer type) is within the boundaries of that array. Bounds checking can prevent buffer overflows.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值