Merge change 2331 into donut

* changes:
  Fix issue 1846343 - part 1
This commit is contained in:
Android (Google) Code Review
2009-05-26 10:04:50 -07:00
14 changed files with 131 additions and 75 deletions

View File

@@ -71065,6 +71065,17 @@
visibility="public"
>
</constructor>
<method name="getAudioSourceMax"
return="int"
abstract="false"
native="false"
synchronized="false"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getMaxAmplitude"
return="int"
abstract="false"
@@ -71466,6 +71477,39 @@
visibility="public"
>
</field>
<field name="VOICE_CALL"
type="int"
transient="false"
volatile="false"
value="4"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="VOICE_DOWNLINK"
type="int"
transient="false"
volatile="false"
value="3"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="VOICE_UPLINK"
type="int"
transient="false"
volatile="false"
value="2"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<interface name="MediaRecorder.OnErrorListener"
abstract="true"

View File

@@ -45,8 +45,6 @@ struct fields_t {
jmethodID postNativeEventInJava; //... event post callback method
int PCM16; //... format constants
int PCM8; //... format constants
int SOURCE_DEFAULT; //... record source constants
int SOURCE_MIC; //... record source constants
jfieldID nativeRecorderInJavaObj; // provides access to the C++ AudioRecord object
jfieldID nativeCallbackCookie; // provides access to the AudioRecord callback data
};
@@ -66,7 +64,7 @@ struct audiorecord_callback_cookie {
#define AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT -16
#define AUDIORECORD_ERROR_SETUP_INVALIDCHANNELCOUNT -17
#define AUDIORECORD_ERROR_SETUP_INVALIDFORMAT -18
#define AUDIORECORD_ERROR_SETUP_INVALIDSTREAMTYPE -19
#define AUDIORECORD_ERROR_SETUP_INVALIDSOURCE -19
#define AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED -20
jint android_media_translateRecorderErrorCode(int code) {
@@ -154,17 +152,16 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
int frameSize = nbChannels * bytesPerSample;
size_t frameCount = buffSizeInBytes / frameSize;
// compare the source against the Java constants
AudioRecord::stream_type arSource;
if (source == javaAudioRecordFields.SOURCE_DEFAULT) {
arSource = AudioRecord::DEFAULT_INPUT;
} else if (source == javaAudioRecordFields.SOURCE_MIC) {
arSource = AudioRecord::MIC_INPUT;
} else {
// convert and check input source value
// input_source values defined in AudioRecord.h are equal to
// JAVA MediaRecord.AudioSource values minus 1.
AudioRecord::input_source arSource = (AudioRecord::input_source)(source - 1);
if (arSource < AudioRecord::DEFAULT_INPUT ||
arSource >= AudioRecord::NUM_INPUT_SOURCES) {
LOGE("Error creating AudioRecord: unknown source.");
return AUDIORECORD_ERROR_SETUP_INVALIDSTREAMTYPE;
return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
}
audiorecord_callback_cookie *lpCallbackData = NULL;
AudioRecord* lpRecorder = NULL;
@@ -511,8 +508,6 @@ static JNINativeMethod gMethods[] = {
#define JAVA_POSTEVENT_CALLBACK_NAME "postEventFromNative"
#define JAVA_CONST_PCM16_NAME "ENCODING_PCM_16BIT"
#define JAVA_CONST_PCM8_NAME "ENCODING_PCM_8BIT"
#define JAVA_CONST_SOURCEDEFAULT_NAME "SOURCE_DEFAULT"
#define JAVA_CONST_SOURCEMIC_NAME "SOURCE_MIC"
#define JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME "mNativeRecorderInJavaObj"
#define JAVA_NATIVECALLBACKINFO_FIELD_NAME "mNativeCallbackCookie"
@@ -583,17 +578,6 @@ int register_android_media_AudioRecord(JNIEnv *env)
return -1;
}
// Get the recording source constants from the AudioRecord class
if ( !android_media_getIntConstantFromClass(env, javaAudioRecordFields.audioRecordClass,
kClassPathName,
JAVA_CONST_SOURCEDEFAULT_NAME, &(javaAudioRecordFields.SOURCE_DEFAULT))
|| !android_media_getIntConstantFromClass(env, javaAudioRecordFields.audioRecordClass,
kClassPathName,
JAVA_CONST_SOURCEMIC_NAME, &(javaAudioRecordFields.SOURCE_MIC)) ) {
// error log performed in getIntConstantFromClass()
return -1;
}
return AndroidRuntime::registerNativeMethods(env,
kClassPathName, gMethods, NELEM(gMethods));
}

View File

@@ -39,10 +39,15 @@ class AudioRecord
{
public:
enum stream_type {
// input sources values must always be defined in the range
// [AudioRecord::DEFAULT_INPUT, AudioRecord::NUM_INPUT_SOURCES[
enum input_source {
DEFAULT_INPUT =-1,
MIC_INPUT = 0,
NUM_STREAM_TYPES
VOICE_UPLINK_INPUT = 1,
VOICE_DOWNLINK_INPUT = 2,
VOICE_CALL_INPUT = 3,
NUM_INPUT_SOURCES
};
static const int DEFAULT_SAMPLE_RATE = 8000;
@@ -118,7 +123,7 @@ public:
*
* Parameters:
*
* streamType: Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
* inputSource: Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
* sampleRate: Track sampling rate in Hz.
* format: PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
* 16 bits per sample).
@@ -140,7 +145,7 @@ public:
RECORD_IIR_ENABLE = AudioSystem::TX_IIR_ENABLE
};
AudioRecord(int streamType,
AudioRecord(int inputSource,
uint32_t sampleRate = 0,
int format = 0,
int channelCount = 0,
@@ -165,7 +170,7 @@ public:
* - NO_INIT: audio server or audio hardware not initialized
* - PERMISSION_DENIED: recording is not allowed for the requesting process
* */
status_t set(int streamType = 0,
status_t set(int inputSource = 0,
uint32_t sampleRate = 0,
int format = 0,
int channelCount = 0,
@@ -197,6 +202,7 @@ public:
int channelCount() const;
uint32_t frameCount() const;
int frameSize() const;
int inputSource() const;
/* After it's created the track is not active. Call start() to
@@ -323,7 +329,8 @@ private:
audio_track_cblk_t* mCblk;
uint8_t mFormat;
uint8_t mChannelCount;
uint8_t mReserved[2];
uint8_t mInputSource;
uint8_t mReserved;
status_t mStatus;
uint32_t mLatency;

View File

@@ -54,7 +54,7 @@ public:
virtual sp<IAudioRecord> openRecord(
pid_t pid,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,

View File

@@ -35,6 +35,10 @@ typedef void (*media_completion_f)(status_t status, void *cookie);
enum audio_source {
AUDIO_SOURCE_DEFAULT = 0,
AUDIO_SOURCE_MIC = 1,
AUDIO_SOURCE_VOICE_UPLINK = 2,
AUDIO_SOURCE_VOICE_DOWNLINK = 3,
AUDIO_SOURCE_VOICE_CALL = 4,
AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_CALL
};
enum video_source {

View File

@@ -1553,7 +1553,6 @@ size_t AudioFlinger::MixerThread::getOutputFrameCount()
AudioFlinger::MixerThread::TrackBase::TrackBase(
const sp<MixerThread>& mixerThread,
const sp<Client>& client,
int streamType,
uint32_t sampleRate,
int format,
int channelCount,
@@ -1563,7 +1562,6 @@ AudioFlinger::MixerThread::TrackBase::TrackBase(
: RefBase(),
mMixerThread(mixerThread),
mClient(client),
mStreamType(streamType),
mFrameCount(0),
mState(IDLE),
mClientTid(-1),
@@ -1713,12 +1711,13 @@ AudioFlinger::MixerThread::Track::Track(
int channelCount,
int frameCount,
const sp<IMemory>& sharedBuffer)
: TrackBase(mixerThread, client, streamType, sampleRate, format, channelCount, frameCount, 0, sharedBuffer)
: TrackBase(mixerThread, client, sampleRate, format, channelCount, frameCount, 0, sharedBuffer)
{
mVolume[0] = 1.0f;
mVolume[1] = 1.0f;
mMute = false;
mSharedBuffer = sharedBuffer;
mStreamType = streamType;
}
AudioFlinger::MixerThread::Track::~Track()
@@ -1902,15 +1901,15 @@ void AudioFlinger::MixerThread::Track::setVolume(float left, float right)
AudioFlinger::MixerThread::RecordTrack::RecordTrack(
const sp<MixerThread>& mixerThread,
const sp<Client>& client,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
int frameCount,
uint32_t flags)
: TrackBase(mixerThread, client, streamType, sampleRate, format,
: TrackBase(mixerThread, client, sampleRate, format,
channelCount, frameCount, flags, 0),
mOverflow(false)
mOverflow(false), mInputSource(inputSource)
{
}
@@ -2235,7 +2234,7 @@ status_t AudioFlinger::TrackHandle::onTransact(
sp<IAudioRecord> AudioFlinger::openRecord(
pid_t pid,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -2258,7 +2257,7 @@ sp<IAudioRecord> AudioFlinger::openRecord(
goto Exit;
}
if (uint32_t(streamType) >= AudioRecord::NUM_STREAM_TYPES) {
if (uint32_t(inputSource) >= AudioRecord::NUM_INPUT_SOURCES) {
LOGE("invalid stream type");
lStatus = BAD_VALUE;
goto Exit;
@@ -2301,7 +2300,7 @@ sp<IAudioRecord> AudioFlinger::openRecord(
frameCount = ((frameCount - 1)/inFrameCount + 1) * inFrameCount;
// create new record track. The record track uses one track in mHardwareMixerThread by convention.
recordTrack = new MixerThread::RecordTrack(mHardwareMixerThread, client, streamType, sampleRate,
recordTrack = new MixerThread::RecordTrack(mHardwareMixerThread, client, inputSource, sampleRate,
format, channelCount, frameCount, flags);
}
if (recordTrack->getCblk() == NULL) {
@@ -2408,7 +2407,7 @@ bool AudioFlinger::AudioRecordThread::threadLoop()
LOGV("AudioRecordThread: loop starting");
if (mRecordTrack != 0) {
input = mAudioHardware->openInputStream(
mRecordTrack->type(),
mRecordTrack->inputSource(),
mRecordTrack->format(),
mRecordTrack->channelCount(),
mRecordTrack->sampleRate(),

View File

@@ -139,7 +139,7 @@ public:
// record interface
virtual sp<IAudioRecord> openRecord(
pid_t pid,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -232,7 +232,6 @@ private:
TrackBase(const sp<MixerThread>& mixerThread,
const sp<Client>& client,
int streamType,
uint32_t sampleRate,
int format,
int channelCount,
@@ -260,10 +259,6 @@ private:
return mCblk;
}
int type() const {
return mStreamType;
}
int format() const {
return mFormat;
}
@@ -293,7 +288,6 @@ private:
sp<Client> mClient;
sp<IMemory> mCblkMemory;
audio_track_cblk_t* mCblk;
int mStreamType;
void* mBuffer;
void* mBufferEnd;
uint32_t mFrameCount;
@@ -328,6 +322,11 @@ private:
void mute(bool);
void setVolume(float left, float right);
int type() const {
return mStreamType;
}
protected:
friend class MixerThread;
friend class AudioFlinger;
@@ -364,6 +363,7 @@ private:
int8_t mRetryCount;
sp<IMemory> mSharedBuffer;
bool mResetDone;
int mStreamType;
}; // end of Track
// record track
@@ -371,7 +371,7 @@ private:
public:
RecordTrack(const sp<MixerThread>& mixerThread,
const sp<Client>& client,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -385,6 +385,8 @@ private:
bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; }
bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; }
int inputSource() const { return mInputSource; }
private:
friend class AudioFlinger;
friend class AudioFlinger::RecordHandle;
@@ -397,6 +399,7 @@ private:
virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
bool mOverflow;
int mInputSource;
};
// playback track

View File

@@ -98,8 +98,8 @@ AudioStreamIn* AudioHardwareGeneric::openInputStream(
status_t *status, AudioSystem::audio_in_acoustics acoustics)
{
// check for valid input source
if ((inputSource != AudioRecord::DEFAULT_INPUT) &&
(inputSource != AudioRecord::MIC_INPUT)) {
if ((inputSource < AudioRecord::DEFAULT_INPUT) ||
(inputSource >= AudioRecord::NUM_INPUT_SOURCES)) {
return 0;
}

View File

@@ -61,8 +61,8 @@ AudioStreamIn* AudioHardwareStub::openInputStream(
status_t *status, AudioSystem::audio_in_acoustics acoustics)
{
// check for valid input source
if ((inputSource != AudioRecord::DEFAULT_INPUT) &&
(inputSource != AudioRecord::MIC_INPUT)) {
if ((inputSource < AudioRecord::DEFAULT_INPUT) ||
(inputSource >= AudioRecord::NUM_INPUT_SOURCES)) {
return 0;
}

View File

@@ -88,7 +88,7 @@ public class AudioRecord
private static final int AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT = -16;
private static final int AUDIORECORD_ERROR_SETUP_INVALIDCHANNELCOUNT = -17;
private static final int AUDIORECORD_ERROR_SETUP_INVALIDFORMAT = -18;
private static final int AUDIORECORD_ERROR_SETUP_INVALIDSTREAMTYPE = -19;
private static final int AUDIORECORD_ERROR_SETUP_INVALIDSOURCE = -19;
private static final int AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED = -20;
// Events:
@@ -113,13 +113,7 @@ public class AudioRecord
*/
@SuppressWarnings("unused")
private int mNativeRecorderInJavaObj;
/**
* Accessed by native methods: provides access to record source constants
*/
@SuppressWarnings("unused")
private final static int SOURCE_DEFAULT = MediaRecorder.AudioSource.DEFAULT;
@SuppressWarnings("unused")
private final static int SOURCE_MIC = MediaRecorder.AudioSource.MIC;
/**
* Accessed by native methods: provides access to the callback data.
*/
@@ -252,8 +246,8 @@ public class AudioRecord
//--------------
// audio source
if ( (audioSource != MediaRecorder.AudioSource.DEFAULT)
&& (audioSource != MediaRecorder.AudioSource.MIC) ) {
if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
(audioSource > MediaRecorder.getAudioSourceMax()) ) {
throw (new IllegalArgumentException("Invalid audio source."));
} else {
mRecordSource = audioSource;

View File

@@ -125,6 +125,15 @@ public class MediaRecorder
public static final int DEFAULT = 0;
/** Microphone audio source */
public static final int MIC = 1;
/** Voice call uplink (Tx) audio source */
public static final int VOICE_UPLINK = 2;
/** Voice call downlink (Rx) audio source */
public static final int VOICE_DOWNLINK = 3;
/** Voice call uplink + downlink audio source */
public static final int VOICE_CALL = 4;
}
/**
@@ -202,6 +211,12 @@ public class MediaRecorder
public native void setAudioSource(int audio_source)
throws IllegalStateException;
/**
* Gets the maximum value for audio sources.
* @see android.media.MediaRecorder.AudioSource
*/
public static final int getAudioSourceMax() { return AudioSource.VOICE_CALL; }
/**
* Sets the video source to be used for recording. If this method is not
* called, the output file will not contain an video track. The source needs

View File

@@ -177,7 +177,7 @@ static void
android_media_MediaRecorder_setAudioSource(JNIEnv *env, jobject thiz, jint as)
{
LOGV("setAudioSource(%d)", as);
if (as < AUDIO_SOURCE_DEFAULT || as > AUDIO_SOURCE_MIC) {
if (as < AUDIO_SOURCE_DEFAULT || as > AUDIO_SOURCE_MAX) {
jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio source");
return;
}

View File

@@ -50,7 +50,7 @@ AudioRecord::AudioRecord()
}
AudioRecord::AudioRecord(
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -61,7 +61,7 @@ AudioRecord::AudioRecord(
int notificationFrames)
: mStatus(NO_INIT)
{
mStatus = set(streamType, sampleRate, format, channelCount,
mStatus = set(inputSource, sampleRate, format, channelCount,
frameCount, flags, cbf, user, notificationFrames);
}
@@ -82,7 +82,7 @@ AudioRecord::~AudioRecord()
}
status_t AudioRecord::set(
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -104,8 +104,8 @@ status_t AudioRecord::set(
return NO_INIT;
}
if (streamType == DEFAULT_INPUT) {
streamType = MIC_INPUT;
if (inputSource == DEFAULT_INPUT) {
inputSource = MIC_INPUT;
}
if (sampleRate == 0) {
@@ -157,7 +157,7 @@ status_t AudioRecord::set(
// open record channel
status_t status;
sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), streamType,
sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), inputSource,
sampleRate, format,
channelCount,
frameCount,
@@ -201,6 +201,7 @@ status_t AudioRecord::set(
mMarkerReached = false;
mNewPosition = 0;
mUpdatePeriod = 0;
mInputSource = (uint8_t)inputSource;
return NO_ERROR;
}
@@ -242,6 +243,11 @@ int AudioRecord::frameSize() const
return channelCount()*((format() == AudioSystem::PCM_8_BIT) ? sizeof(uint8_t) : sizeof(int16_t));
}
int AudioRecord::inputSource() const
{
return (int)mInputSource;
}
// -------------------------------------------------------------------------
status_t AudioRecord::start()

View File

@@ -99,7 +99,7 @@ public:
virtual sp<IAudioRecord> openRecord(
pid_t pid,
int streamType,
int inputSource,
uint32_t sampleRate,
int format,
int channelCount,
@@ -110,7 +110,7 @@ public:
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(pid);
data.writeInt32(streamType);
data.writeInt32(inputSource);
data.writeInt32(sampleRate);
data.writeInt32(format);
data.writeInt32(channelCount);
@@ -384,14 +384,14 @@ status_t BnAudioFlinger::onTransact(
case OPEN_RECORD: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
pid_t pid = data.readInt32();
int streamType = data.readInt32();
int inputSource = data.readInt32();
uint32_t sampleRate = data.readInt32();
int format = data.readInt32();
int channelCount = data.readInt32();
size_t bufferCount = data.readInt32();
uint32_t flags = data.readInt32();
status_t status;
sp<IAudioRecord> record = openRecord(pid, streamType,
sp<IAudioRecord> record = openRecord(pid, inputSource,
sampleRate, format, channelCount, bufferCount, flags, &status);
reply->writeInt32(status);
reply->writeStrongBinder(record->asBinder());