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.

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. Android(安卓)ProgressBar简单使用
  6. android学习——android 常见的错误 和 解决方法
  7. Android-0 Android(安卓)studio编译报错相关
  8. android状态栏一体化
  9. 《Android(安卓)基础(三十三)》 TabHost ~ 仿微信底部菜单

随机推荐

  1. c语言起泡排序
  2. Linux:目录中的最新文件。
  3. 非阻塞 connect 的实现
  4. Linux随笔-鸟哥Linux服务器篇学习总结(全)
  5. Linux中的文件权限和用户组
  6. arm linux嵌入式开发入门与进阶---开发板
  7. linux--输入子系统
  8. linux usb枚举过程分析之守护进程及其唤
  9. 进程间通讯概述
  10. 字符串处理函数strcat和strtok