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. Android中倒计时代码
  2. android mediaplayer 音效 代码
  3. android小游戏代码
  4. Android WebView文件上传(关键代码)
  5. android,java代码设置背景色
  6. 移动应用开发:如何创建自定义Android代码模板
  7. Android 用代码动态添加View(ViewGroup.addView()),并进行动态添加
  8. Android应用程序进程启动过程的源代码分析(1)

随机推荐

  1. android控件的对齐方式
  2. android平板上的GridView视图缓存优化
  3. Android开发之旅:活动与任务
  4. Android中的style&themes
  5. Android(安卓)Studio使用教程、工程目录
  6. 70个具有商业实战性的精品Android源码
  7. Android高斯模糊、高斯平滑(Gaussian Blur
  8. Android与H5相机、相册笔记
  9. JPCT-AE for Android(安卓)3D (一)------
  10. Android内存泄露调试分享