`

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.

分享到:
评论

相关推荐

    Android audioRecord录音Demo

    在Android平台上,音频录制是应用程序开发中的一个常见需求,`AudioRecord`类是Android SDK提供的一种用于低级音频数据录制的API。这个`Android audioRecord录音Demo`将向我们展示如何利用`AudioRecord`类来实现一个...

    android的AudioRecord

    在Android平台上,AudioRecord类是用于实现低级别音频录制的核心组件。它允许开发者直接与设备的音频硬件交互,提供了一种高效且灵活的方式来捕获声音数据。本文将深入解析AudioRecord的使用方法及其在语音质量评测...

    Android应用源码之AudioRecord.zip

    创建录音会话是通过调用AudioRecord构造函数完成的,需要提供上述参数。例如: ```java int sampleRate = 44100; int channelConfig = AudioFormat.CHANNEL_IN_MONO; int audioFormat = AudioFormat.ENCODING_...

    android使用audioRecord和audioTrack实现语音录音播放与即时播放

    在Android平台上,开发音频应用时,我们经常需要处理声音的录制和播放功能。`AudioRecord`和`AudioTrack`是Android SDK提供的一对关键类,分别用于录音和播放音频数据。这两个类允许开发者进行低级别的音频操作,...

    Android应用源码之AudioRecord.rar

    Android支持多个音频输入和输出设备,AudioRecord提供了查询和选择特定设备的功能。 10. **音频权限** 在Android 6.0(API级别23)及以上版本,需要在运行时请求录音权限(Manifest.permission.RECORD_AUDIO)。 ...

    AudioRecord.zip

    综上所述,"AudioRecord.zip"项目是一个实用的工具,它展示了如何利用Android的`AudioRecord`类实现灵活的音频录制和播放功能,同时提供了调整采样率和文件格式的选项,这对于音频应用开发者来说极具价值。...

    Android应用源码之AudioRecord-IT计算机-毕业设计.zip

    这个“Android应用源码之AudioRecord-IT计算机-毕业设计.zip”文件包含了一个使用AudioRecord API进行音频录制的示例项目,非常适合那些正在进行Android毕业设计或者想要深入理解Android音频处理的开发者。...

    Android录音--AudioRecord、MediaRecorder

    Android提供了两个API用于实现录音功能:android.media.AudioRecord、android.media.MediaRecorder。 网上有很多谈论这两个类的资料。现在大致总结下: 1、AudioRecord 主要是实现边录边播(AudioRecord+...

    安卓Android源码——AudioRecord.zip

    在Android操作系统中,AudioRecord是音频输入类,它允许开发者从设备的麦克风或其他音频输入源录制音频数据。这个类是Android SDK中的一个关键组件,用于实现各种与声音相关的应用程序,比如语音识别、录音机应用...

    Android多媒体功能开发-使用AudioRecord类录制音频的例子

    `AudioRecord`类是Android SDK提供的一个核心API,用于实现低级别的音频录制功能。本文将深入探讨如何使用`AudioRecord`类来录制音频,并提供相关的编程知识。 首先,我们要理解`AudioRecord`类的基本概念。`Audio...

    AudioRecord

    在Android平台上,AudioRecord是Android SDK提供的一种用于音频录制的核心类。它允许开发者直接与设备的音频硬件交互,实现高质量的音频数据录制功能。本文将深入探讨AudioRecord的相关知识点,包括其基本用法、参数...

    Android使用AudioRecord、MediaRecorder录制音频

    在Android平台上,音频录制是移动...总结,Android音频录制涉及到多个层次的技术,包括音频编码、数据处理和文件操作。理解这些概念并熟练运用`AudioRecord`和`MediaRecorder`可以让你在开发音频应用时更加得心应手。

    AudioRecord workflow learning.pdf

    在AudioRecord的工作流程中,应用程序通过调用AudioRecord类的构造函数来创建一个实例,指定音频源、采样率、通道数和数据格式。接着,调用`startRecording()`开始录音,此时,AudioRecord会与HAL层交互,打开音频...

    AudioRecord-master.zip

    在Android平台上,录音功能是应用程序开发中的一个常见需求,例如制作音乐应用、语音备忘录或者实时通信应用等。`AudioRecord`类是Android SDK提供的一套API,用于实现低级别的音频录制。这个"AudioRecord-master....

    Android利用AudioRecord类实现音频录制程序

    使用AudioRecord类实现音频录制需要实例化一个AudioRecord对象,创建一个文件,用于保存录制的内容,打开一个输出流,指向创建的文件,然后调用AudioRecord的startRecording方法开始录制。录制过程中需要创建一个...

    AudioRecord.rar

    《Android平台上的AudioRecord使用详解》 在Android开发中,我们常常需要处理音频录制与播放的任务,这涉及到Android系统中的一个重要类——AudioRecord。本文将深入探讨AudioRecord类的使用,帮助开发者理解如何在...

    AudioRecord lame

    本项目“AudioRecord lame”提供了一个完整的实例,演示了如何使用Android原生的`AudioRecord`类来录制音频,并结合lame库将录制的音频数据转换为MP3格式。以下是关于这个项目的详细知识点: 1. **Android Audio...

    AudioRecord学习指南.docx

    AudioRecord是Android录音功能的核心,其工作流程涵盖了对象创建、音频路由设置、数据读取等多个环节。理解这些细节对于开发高质量的录音应用至关重要。通过AudioRecord,开发者可以灵活地控制录音质量、设备选择...

Global site tag (gtag.js) - Google Analytics